Mercurial > dropbear
comparison libtommath/bn_mp_prime_rabin_miller_trials.c @ 1739:13d834efc376 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 15 Oct 2020 19:55:15 +0800 |
parents | 1051e4eea25a |
children |
comparison
equal
deleted
inserted
replaced
1562:768ebf737aa0 | 1739:13d834efc376 |
---|---|
1 #include <tommath_private.h> | 1 #include "tommath_private.h" |
2 #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C | 2 #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C |
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis | 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */ |
4 * | 4 /* SPDX-License-Identifier: Unlicense */ |
5 * LibTomMath is a library that provides multiple-precision | |
6 * integer arithmetic as well as number theoretic functionality. | |
7 * | |
8 * The library was designed directly after the MPI library by | |
9 * Michael Fromberger but has been written from scratch with | |
10 * additional optimizations in place. | |
11 * | |
12 * The library is free for all purposes without any express | |
13 * guarantee it works. | |
14 * | |
15 * Tom St Denis, [email protected], http://libtom.org | |
16 */ | |
17 | |
18 | 5 |
19 static const struct { | 6 static const struct { |
20 int k, t; | 7 int k, t; |
21 } sizes[] = { | 8 } sizes[] = { |
22 { 128, 28 }, | 9 { 80, -1 }, /* Use deterministic algorithm for size <= 80 bits */ |
23 { 256, 16 }, | 10 { 81, 37 }, /* max. error = 2^(-96)*/ |
24 { 384, 10 }, | 11 { 96, 32 }, /* max. error = 2^(-96)*/ |
25 { 512, 7 }, | 12 { 128, 40 }, /* max. error = 2^(-112)*/ |
26 { 640, 6 }, | 13 { 160, 35 }, /* max. error = 2^(-112)*/ |
27 { 768, 5 }, | 14 { 256, 27 }, /* max. error = 2^(-128)*/ |
28 { 896, 4 }, | 15 { 384, 16 }, /* max. error = 2^(-128)*/ |
29 { 1024, 4 } | 16 { 512, 18 }, /* max. error = 2^(-160)*/ |
17 { 768, 11 }, /* max. error = 2^(-160)*/ | |
18 { 896, 10 }, /* max. error = 2^(-160)*/ | |
19 { 1024, 12 }, /* max. error = 2^(-192)*/ | |
20 { 1536, 8 }, /* max. error = 2^(-192)*/ | |
21 { 2048, 6 }, /* max. error = 2^(-192)*/ | |
22 { 3072, 4 }, /* max. error = 2^(-192)*/ | |
23 { 4096, 5 }, /* max. error = 2^(-256)*/ | |
24 { 5120, 4 }, /* max. error = 2^(-256)*/ | |
25 { 6144, 4 }, /* max. error = 2^(-256)*/ | |
26 { 8192, 3 }, /* max. error = 2^(-256)*/ | |
27 { 9216, 3 }, /* max. error = 2^(-256)*/ | |
28 { 10240, 2 } /* For bigger keysizes use always at least 2 Rounds */ | |
30 }; | 29 }; |
31 | 30 |
32 /* returns # of RM trials required for a given bit size */ | 31 /* returns # of RM trials required for a given bit size */ |
33 int mp_prime_rabin_miller_trials(int size) | 32 int mp_prime_rabin_miller_trials(int size) |
34 { | 33 { |
35 int x; | 34 int x; |
36 | 35 |
37 for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) { | 36 for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) { |
38 if (sizes[x].k == size) { | 37 if (sizes[x].k == size) { |
39 return sizes[x].t; | 38 return sizes[x].t; |
40 } else if (sizes[x].k > size) { | 39 } else if (sizes[x].k > size) { |
41 return (x == 0) ? sizes[0].t : sizes[x - 1].t; | 40 return (x == 0) ? sizes[0].t : sizes[x - 1].t; |
42 } | 41 } |
43 } | 42 } |
44 return sizes[x-1].t + 1; | 43 return sizes[x-1].t; |
45 } | 44 } |
46 | 45 |
47 | 46 |
48 #endif | 47 #endif |
49 | |
50 /* ref: $Format:%D$ */ | |
51 /* git commit: $Format:%H$ */ | |
52 /* commit time: $Format:%ai$ */ |