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.
This commit is contained in:
John Safranek
2019-11-22 13:02:59 -08:00
parent 481da3dcc1
commit 3432a8a1fc
3 changed files with 13 additions and 1 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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)