Debian Codegraph @

lib/hcrypto/libtommath/bn_mp_find_prime.c

raw
1 /* TomsFastMath, a fast ISO C bignum library.
2 *
3 * This project is public domain and free for all purposes.
4 *
5 * Love Hornquist Astrand <[email protected]>
6 */
7 #include <tommath.h>
8 #ifdef BN_MP_FIND_PRIME_C
9 int mp_find_prime(mp_int *a, int t)
10 {
11 int res = MP_NO;
12
13 /* valid value of t? */
14 if (t <= 0 || t > PRIME_SIZE) {
15 return MP_VAL;
16 }
17
18 if (mp_iseven(a))
19 mp_add_d(a, 1, a);
20
21 do {
22 if (mp_prime_is_prime(a, t, &res) != 0) {
23 res = MP_VAL;
24 break;
25 }
26
27 if (res == MP_NO) {
28 mp_add_d(a, 2, a);
29 continue;
30 }
31
32 } while (res != MP_YES);
33
34 return res;
35 }
36 #endif