From 0a924af89435e628ddecdfc658fa088a6acfb8f6 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 22 Nov 2019 10:01:21 -0800 Subject: [PATCH] Maintenance: Prime 1. Prime test should return NO for 1. (sp math) --- wolfcrypt/src/sp_int.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index 9e9b99530..422614e3d 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -1703,6 +1703,11 @@ int sp_prime_is_prime(sp_int *a, int t, int* result) err = MP_VAL; } + if (sp_isone(a)) { + *result = MP_NO; + return MP_OKAY; + } + if (err == MP_OKAY && a->used == 1) { /* check against primes table */ for (i = 0; i < SP_PRIME_SIZE; i++) { @@ -1783,6 +1788,11 @@ int sp_prime_is_prime_ex(sp_int* a, int t, int* result, WC_RNG* rng) if (a == NULL || result == NULL || rng == NULL) err = MP_VAL; + if (sp_isone(a)) { + *result = MP_NO; + return MP_OKAY; + } + if (err == MP_OKAY && a->used == 1) { /* check against primes table */ for (i = 0; i < SP_PRIME_SIZE; i++) {