Commit 6608eea9e1a25783079087d18f66e102ff4677a5

czurnieden 2019-03-23T19:45:32

bugfix in final fips loop II: alternative version

diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c
index 5efab41..b9cb396 100644
--- a/bn_mp_prime_is_prime.c
+++ b/bn_mp_prime_is_prime.c
@@ -332,11 +332,11 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
          }
          /*
           * 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;
             }
@@ -346,11 +346,6 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
             ix--;
             continue;
          }
-         /* Witness and test subject must not be equal */
-         if ( (size_a ==  mp_count_bits(&b)) && (mp_cmp(a, &b) == MP_EQ) ) {
-            ix--;
-            continue;
-         }
          if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
             goto LBL_B;
          }