Maintenance: Prime

1. Prime test should return NO for 1. (normal math and fast math)
This commit is contained in:
John Safranek
2019-11-21 13:47:43 -08:00
parent edb07cf68e
commit 452ba5b502
2 changed files with 10 additions and 0 deletions

View File

@ -4715,6 +4715,11 @@ int mp_prime_is_prime (mp_int * a, int t, int *result)
return MP_VAL;
}
if (mp_isone(a)) {
*result = 0;
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

@ -4074,6 +4074,11 @@ int fp_isprime_ex(fp_int *a, int t, int* result)
return FP_VAL;
}
if (fp_isone(a)) {
*result = FP_NO;
return FP_OKAY;
}
/* check against primes table */
for (r = 0; r < FP_PRIME_SIZE; r++) {
if (fp_cmp_d(a, primes[r]) == FP_EQ) {