xref: /minix3/crypto/external/bsd/heimdal/dist/lib/hcrypto/libtommath/bn_mp_find_prime.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1 /*	$NetBSD: bn_mp_find_prime.c,v 1.1.1.2 2014/04/24 12:45:31 pettai Exp $	*/
2 
3 /* TomsFastMath, a fast ISO C bignum library.
4  *
5  * This project is public domain and free for all purposes.
6  *
7  * Love Hornquist Astrand <lha@h5l.org>
8  */
9 #include <tommath.h>
10 
mp_find_prime(mp_int * a)11 int mp_find_prime(mp_int *a)
12 {
13   int res;
14 
15   if (mp_iseven(a))
16     mp_add_d(a, 1, a);
17 
18   do {
19 
20     if ((res = mp_isprime(a)) == MP_NO) {
21       mp_add_d(a, 2, a);
22       continue;
23     }
24 
25   } while (res != MP_YES);
26 
27   return res;
28 }
29