Skip to content

Commit 437c202

Browse files
author
Andras Fekete
committed
Add in another clamp to prevent infinite loops
M = i - 1 would make it 2^0. Anything above that would be negative powers which don't make sense.
1 parent d3d131d commit 437c202

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14749,6 +14749,11 @@ int mp_sqrtmod_prime(mp_int* n, mp_int* prime, mp_int* ret)
1474914749
if (mp_cmp_d(t1, 1) == MP_EQ)
1475014750
break;
1475114751
res = mp_exptmod(t1, two, prime, t1);
14752+
if ((res == MP_OKAY) && (mp_cmp_d(M,i) == MP_EQ)) {
14753+
/* This is to clamp the loop in case 'prime' is not really prime */
14754+
res = MP_VAL;
14755+
break;
14756+
}
1475214757
if (res == MP_OKAY)
1475314758
i++;
1475414759
}

0 commit comments

Comments
 (0)