comparison bn_prime_sizes_tab.c @ 2:86e0b50a9b58 libtommath-orig ltm-0.30-orig

ltm 0.30 orig import
author Matt Johnston <matt@ucc.asn.au>
date Mon, 31 May 2004 18:25:22 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 2:86e0b50a9b58
1 /* LibTomMath, multiple-precision integer library -- Tom St Denis
2 *
3 * LibTomMath is a library that provides multiple-precision
4 * integer arithmetic as well as number theoretic functionality.
5 *
6 * The library was designed directly after the MPI library by
7 * Michael Fromberger but has been written from scratch with
8 * additional optimizations in place.
9 *
10 * The library is free for all purposes without any express
11 * guarantee it works.
12 *
13 * Tom St Denis, [email protected], http://math.libtomcrypt.org
14 */
15 #include <tommath.h>
16
17 /* this table gives the # of rabin miller trials for a prob of failure lower than 2^-96 */
18 static const struct {
19 int k, t;
20 } sizes[] = {
21 { 128, 28 },
22 { 256, 16 },
23 { 384, 10 },
24 { 512, 7 },
25 { 640, 6 },
26 { 768, 5 },
27 { 896, 4 },
28 { 1024, 4 },
29 { 1152, 3 },
30 { 1280, 3 },
31 { 1408, 3 },
32 { 1536, 3 },
33 { 1664, 3 },
34 { 1792, 2 } };
35
36 /* returns # of RM trials required for a given bit size */
37 int mp_prime_rabin_miller_trials(int size)
38 {
39 int x;
40
41 for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) {
42 if (sizes[x].k == size) {
43 return sizes[x].t;
44 } else if (sizes[x].k > size) {
45 return (x == 0) ? sizes[0].t : sizes[x - 1].t;
46 }
47 }
48 return 1;
49 }
50
51