comparison bn_prime_sizes_tab.c @ 145:a96ff234ff19 libtommath

propagate of fc94c38452d9fd684a8e1eb9e3a73120aac0d38f and 3e4de4cbef3d9035a7b2f0c25e9f86e297f9f6d1 from branch 'au.asn.ucc.matt.ltm-orig' to 'au.asn.ucc.matt.ltm-db'
author Matt Johnston <matt@ucc.asn.au>
date Sun, 19 Dec 2004 15:57:19 +0000
parents 22d5cf7d4b1a
children
comparison
equal deleted inserted replaced
142:d29b64170cf0 145:a96ff234ff19
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