exchanged direct call to Miller-Rabin in mp_prime_next_prime with mp_prime_is_prime
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c
index e309bae..6ed5d62 100644
--- a/bn_mp_prime_is_prime.c
+++ b/bn_mp_prime_is_prime.c
@@ -35,7 +35,6 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
/* valid value of t? */
if (t > PRIME_SIZE) {
- puts("t > PRIME_SIZE");
return MP_VAL;
}
@@ -54,7 +53,6 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
/* N must be odd */
if (mp_iseven(a) == MP_YES) {
- *result = 0;
return MP_OKAY;
}
/* N is not a perfect square: floor(sqrt(N))^2 != N */
@@ -62,14 +60,13 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
return err;
}
if (res != 0) {
- *result = 0;
return MP_OKAY;
}
/* is the input equal to one of the primes in the table? */
for (ix = 0; ix < PRIME_SIZE; ix++) {
if (mp_cmp_d(a, ltm_prime_tab[ix]) == MP_EQ) {
- *result = 1;
+ *result = MP_YES;
return MP_OKAY;
}
}
@@ -126,14 +123,14 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
}
//#endif
// commented out for testing purposes
-//#ifdef LTM_USE_FROBENIUS_UNDERWOOD_TEST
+#ifdef LTM_USE_FROBENIUS_UNDERWOOD_TEST
if ((err = mp_prime_frobenius_underwood(a, &res)) != MP_OKAY) {
goto LBL_B;
}
if (res == MP_NO) {
goto LBL_B;
}
-//#endif
+#endif
#endif
/*
diff --git a/bn_mp_prime_next_prime.c b/bn_mp_prime_next_prime.c
index 89e2841..44ab116 100644
--- a/bn_mp_prime_next_prime.c
+++ b/bn_mp_prime_next_prime.c
@@ -24,11 +24,6 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
mp_digit res_tab[PRIME_SIZE], step, kstep;
mp_int b;
- /* ensure t is valid */
- if ((t <= 0) || (t > PRIME_SIZE)) {
- return MP_VAL;
- }
-
/* force positive */
a->sign = MP_ZPOS;
@@ -141,17 +136,9 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
continue;
}
- /* is this prime? */
- for (x = 0; x < t; x++) {
- mp_set(&b, ltm_prime_tab[x]);
- if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
- goto LBL_ERR;
- }
- if (res == MP_NO) {
- break;
- }
+ if ((err = mp_prime_is_prime(a, t, &res)) != MP_OKAY) {
+ goto LBL_ERR;
}
-
if (res == MP_YES) {
break;
}