Mercurial > dropbear
comparison libtommath/bn_mp_prime_is_prime.c @ 1656:a36e545fb43d
Prime-related bugfixes (#81)
* Merge pull request #180 from czurnieden/isprimeerror
Fixed bug in mp_prime_isprime
(cherry picked from commit f3ff7064f3301a2fc11b84d389fd67769862d437)
* do 2 MR rounds for numbers >=2048bits
* back-port modified mp_prime_next_prime()
author | Steffen Jaeckel <s@jaeckel.eu> |
---|---|
date | Tue, 17 Sep 2019 16:11:09 +0200 |
parents | f52919ffd3b1 |
children | 1051e4eea25a |
comparison
equal
deleted
inserted
replaced
1655:f52919ffd3b1 | 1656:a36e545fb43d |
---|---|
330 if ((err = mp_rand(&b, len)) != MP_OKAY) { | 330 if ((err = mp_rand(&b, len)) != MP_OKAY) { |
331 goto LBL_B; | 331 goto LBL_B; |
332 } | 332 } |
333 /* | 333 /* |
334 * That number might got too big and the witness has to be | 334 * That number might got too big and the witness has to be |
335 * smaller than or equal to "a" | 335 * smaller than "a" |
336 */ | 336 */ |
337 len = mp_count_bits(&b); | 337 len = mp_count_bits(&b); |
338 if (len > size_a) { | 338 if (len >= size_a) { |
339 len = len - size_a; | 339 len = (len - size_a) + 1; |
340 if ((err = mp_div_2d(&b, len, &b, NULL)) != MP_OKAY) { | 340 if ((err = mp_div_2d(&b, len, &b, NULL)) != MP_OKAY) { |
341 goto LBL_B; | 341 goto LBL_B; |
342 } | 342 } |
343 } | 343 } |
344 | |
345 /* Although the chance for b <= 3 is miniscule, try again. */ | 344 /* Although the chance for b <= 3 is miniscule, try again. */ |
346 if (mp_cmp_d(&b, 3uL) != MP_GT) { | 345 if (mp_cmp_d(&b, 3uL) != MP_GT) { |
347 ix--; | 346 ix--; |
348 continue; | 347 continue; |
349 } | 348 } |