1/*	$NetBSD: bn_mp_find_prime.c,v 1.2 2017/01/28 21:31:47 christos 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#ifdef BN_MP_FIND_PRIME_C
11int mp_find_prime(mp_int *a, int t)
12{
13  int res = MP_NO;
14
15  /* valid value of t? */
16  if (t <= 0 || t > PRIME_SIZE) {
17    return MP_VAL;
18  }
19
20  if (mp_iseven(a))
21    mp_add_d(a, 1, a);
22
23  do {
24    if (mp_prime_is_prime(a, t, &res) != 0) {
25      res = MP_VAL;
26      break;
27    }
28
29    if (res == MP_NO) {
30      mp_add_d(a, 2, a);
31      continue;
32    }
33
34  } while (res != MP_YES);
35
36  return res;
37}
38#endif
39