annotate bn_mp_prime_rabin_miller_trials.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 d29b64170cf0
children 97db060d0ef5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
142
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #include <tommath.h>
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 *
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * LibTomMath is a library that provides multiple-precision
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 * integer arithmetic as well as number theoretic functionality.
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 *
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 * The library was designed directly after the MPI library by
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * Michael Fromberger but has been written from scratch with
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * additional optimizations in place.
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 *
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * The library is free for all purposes without any express
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 * guarantee it works.
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 *
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 * Tom St Denis, [email protected], http://math.libtomcrypt.org
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 static const struct {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 int k, t;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 } sizes[] = {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 { 128, 28 },
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 { 256, 16 },
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 { 384, 10 },
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 { 512, 7 },
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 { 640, 6 },
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 { 768, 5 },
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 { 896, 4 },
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 { 1024, 4 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 };
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 /* returns # of RM trials required for a given bit size */
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 int mp_prime_rabin_miller_trials(int size)
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 int x;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 if (sizes[x].k == size) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 return sizes[x].t;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 } else if (sizes[x].k > size) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 return (x == 0) ? sizes[0].t : sizes[x - 1].t;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 return sizes[x-1].t + 1;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 #endif