diff 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
line wrap: on
line diff
--- a/libtommath/bn_mp_prime_is_prime.c	Mon Sep 16 15:50:38 2019 +0200
+++ b/libtommath/bn_mp_prime_is_prime.c	Tue Sep 17 16:11:09 2019 +0200
@@ -332,16 +332,15 @@
          }
          /*
           * That number might got too big and the witness has to be
-          * smaller than or equal to "a"
+          * smaller than "a"
           */
          len = mp_count_bits(&b);
-         if (len > size_a) {
-            len = len - size_a;
+         if (len >= size_a) {
+            len = (len - size_a) + 1;
             if ((err = mp_div_2d(&b, len, &b, NULL)) != MP_OKAY) {
                goto LBL_B;
             }
          }
-
          /* Although the chance for b <= 3 is miniscule, try again. */
          if (mp_cmp_d(&b, 3uL) != MP_GT) {
             ix--;