From 3432a8a1fc7c79559abcb687332e91d74730214a Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 22 Nov 2019 13:02:59 -0800 Subject: [PATCH] Maintenance: Prime 1. Prime test should return NO for 1. (ex function, normal math and fast math) 2. Call mp_init() on the k value for the primality test case in the wolfCrypt test. --- wolfcrypt/src/integer.c | 5 +++++ wolfcrypt/src/tfm.c | 5 +++++ wolfcrypt/test/test.c | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index 12b5b8059..fad07663e 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -4783,6 +4783,11 @@ int mp_prime_is_prime_ex (mp_int * a, int t, int *result, WC_RNG *rng) return MP_VAL; } + if (mp_isone(a)) { + *result = MP_NO; + 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) { diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index 2f7d347fa..c4a79f451 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -4129,6 +4129,11 @@ int mp_prime_is_prime_ex(mp_int* a, int t, int* result, WC_RNG* rng) if (a == NULL || result == NULL || rng == NULL) return FP_VAL; + if (fp_isone(a)) { + *result = FP_NO; + return FP_OKAY; + } + if (ret == FP_YES) { fp_digit d; int r; diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index ab3324219..b329cefeb 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -24631,7 +24631,9 @@ static int GenerateNextP(mp_int* p1, mp_int* p2, int k) int ret; mp_int ki; - ret = mp_set(&ki, k); + ret = mp_init(&ki); + if (ret == 0) + ret = mp_set(&ki, k); if (ret == 0) ret = mp_sub_d(p1, 1, p2); if (ret == 0)