1 /* $NetBSD: bn_mp_prime_rabin_miller_trials.c,v 1.2 2017/01/28 21:31:47 christos Exp $ */
2
3 #include <tommath.h>
4 #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C
5 /* LibTomMath, multiple-precision integer library -- Tom St Denis
6 *
7 * LibTomMath is a library that provides multiple-precision
8 * integer arithmetic as well as number theoretic functionality.
9 *
10 * The library was designed directly after the MPI library by
11 * Michael Fromberger but has been written from scratch with
12 * additional optimizations in place.
13 *
14 * The library is free for all purposes without any express
15 * guarantee it works.
16 *
17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
18 */
19
20
21 static const struct {
22 int k, t;
23 } sizes[] = {
24 { 128, 28 },
25 { 256, 16 },
26 { 384, 10 },
27 { 512, 7 },
28 { 640, 6 },
29 { 768, 5 },
30 { 896, 4 },
31 { 1024, 4 }
32 };
33
34 /* returns # of RM trials required for a given bit size */
mp_prime_rabin_miller_trials(int size)35 int mp_prime_rabin_miller_trials(int size)
36 {
37 int x;
38
39 for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) {
40 if (sizes[x].k == size) {
41 return sizes[x].t;
42 } else if (sizes[x].k > size) {
43 return (x == 0) ? sizes[0].t : sizes[x - 1].t;
44 }
45 }
46 return sizes[x-1].t + 1;
47 }
48
49
50 #endif
51
52 /* Source: /cvs/libtom/libtommath/bn_mp_prime_rabin_miller_trials.c,v */
53 /* Revision: 1.4 */
54 /* Date: 2006/12/28 01:25:13 */
55