From fd876e4a7f565603245a0c595da03ee64973b4b2 Mon Sep 17 00:00:00 2001 From: czurnieden Date: Fri, 4 May 2018 17:58:56 +0200 Subject: [PATCH] bugfix in mp_prime_is_prime for small input --- bn_mp_prime_is_prime.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c index 8775bf1..e9cadc2 100644 --- a/bn_mp_prime_is_prime.c +++ b/bn_mp_prime_is_prime.c @@ -275,8 +275,9 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result) fips_rand |= (unsigned int) b.dp[0]; } #endif - len = (int) ((fips_rand & mask)/ DIGIT_BIT); - // Unlikely, but still possible. + // Ceil, because small numbers have a right to live, too, + len = (int) ( ((fips_rand & mask) + DIGIT_BIT) / DIGIT_BIT); + // Unlikely. if(len < 0){ ix--; continue;