corrected preprocessor branch in bn_mp_montgomery_setup.c
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
diff --git a/bn_mp_montgomery_setup.c b/bn_mp_montgomery_setup.c
index 8ad19c4..ad245eb 100644
--- a/bn_mp_montgomery_setup.c
+++ b/bn_mp_montgomery_setup.c
@@ -25,7 +25,7 @@ mp_err mp_montgomery_setup(const mp_int *n, mp_digit *rho)
x = (((b + 2u) & 4u) << 1) + b; /* here x*a==1 mod 2**4 */
x *= 2u - (b * x); /* here x*a==1 mod 2**8 */
x *= 2u - (b * x); /* here x*a==1 mod 2**16 */
-#if (defined(MP_64BIT) || defined(MP_16BIT))
+#if defined(MP_64BIT) || !(defined(MP_16BIT))
x *= 2u - (b * x); /* here x*a==1 mod 2**32 */
#endif
#ifdef MP_64BIT
diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c
index 678eae4..1afa1ae 100644
--- a/bn_mp_prime_is_prime.c
+++ b/bn_mp_prime_is_prime.c
@@ -100,7 +100,12 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
*/
#ifndef LTM_USE_ONLY_MR
if (t >= 0) {
-#ifdef LTM_USE_FROBENIUS_TEST
+ /*
+ * Use a Frobenius-Underwood test instead of the Lucas-Selfridge test for
+ * MP_8BIT (It is unknown if the Lucas-Selfridge test works with 16-bit
+ * integers but the necesssary analysis is on the todo-list).
+ */
+#ifdef (LTM_USE_FROBENIUS_TEST)
err = mp_prime_frobenius_underwood(a, &res);
if ((err != MP_OKAY) && (err != MP_ITER)) {
goto LBL_B;
@@ -228,7 +233,6 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
* an unsigned int and "mask" on the other side is most probably not.
*/
fips_rand = (unsigned int)(b.dp[0] & (mp_digit) mask);
-
if (fips_rand > (unsigned int)(INT_MAX - MP_DIGIT_BIT)) {
len = INT_MAX / MP_DIGIT_BIT;
} else {
diff --git a/bn_mp_prime_strong_lucas_selfridge.c b/bn_mp_prime_strong_lucas_selfridge.c
index 0f03792..a5ea16d 100644
--- a/bn_mp_prime_strong_lucas_selfridge.c
+++ b/bn_mp_prime_strong_lucas_selfridge.c
@@ -278,6 +278,5 @@ LBL_LS_ERR:
mp_clear_multi(&Q2kdz, &T4z, &T3z, &T2z, &T1z, &Qkdz, &Q2mz, &Qmz, &V2mz, &U2mz, &Vz, &Uz, &Np1, &gcd, &Dz, NULL);
return err;
}
-
#endif
#endif