File: bn_mp_find_prime.c

package info (click to toggle)
heimdal 7.7.0%2Bdfsg-2%2Bdeb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 42,764 kB
  • sloc: ansic: 355,654; sh: 12,015; javascript: 6,382; makefile: 4,359; yacc: 1,786; perl: 1,572; lex: 732; python: 725; java: 119; awk: 41
file content (36 lines) | stat: -rw-r--r-- 605 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* TomsFastMath, a fast ISO C bignum library.
 *
 * This project is public domain and free for all purposes.
 *
 * Love Hornquist Astrand <lha@h5l.org>
 */
#include <tommath.h>
#ifdef BN_MP_FIND_PRIME_C
int mp_find_prime(mp_int *a, int t)
{
  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_NO) {
      mp_add_d(a, 2, a);
      continue;
    }

  } while (res != MP_YES);

  return res;
}
#endif