Convert mp_find_prime to use mp_prime_is_prime

Modify the signature of mp_find_prime() to permit the number of
Miller-Rabin rounds to be specified.  In addition, valid responses
now include MP_NO, MP_YES, and MP_VAL which is returned when
mp_prime_is_prime() fails.

Change-Id: I0195129a4dd75875e6dddb6d49a5ceb30afb1a17
This commit is contained in:
Jeffrey Altman
2013-10-07 15:13:18 -05:00
parent 1859a85350
commit 28051fa99c
3 changed files with 15 additions and 6 deletions

View File

@@ -6,16 +6,25 @@
*/
#include <tommath.h>
#ifdef BN_MP_FIND_PRIME_C
int mp_find_prime(mp_int *a)
int mp_find_prime(mp_int *a, int t)
{
int res;
int res = MP_NO;
/* valid value of t? */
if (t <= 0 || t > PRIME_SIZE) {
return MP_VAL;
}
if (mp_iseven(a))
mp_add_d(a, 1, a);
do {
if (mp_prime_is_prime(a, t, &res) != 0) {
res = MP_VAL;
break;
}
if ((res = mp_isprime(a)) == MP_NO) {
if (res == MP_NO) {
mp_add_d(a, 2, a);
continue;
}