Line data Source code
1 : #include "tommath_private.h"
2 : #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C
3 : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 : /* SPDX-License-Identifier: Unlicense */
5 :
6 : static const struct {
7 : int k, t;
8 : } sizes[] = {
9 : { 80, -1 }, /* Use deterministic algorithm for size <= 80 bits */
10 : { 81, 37 }, /* max. error = 2^(-96)*/
11 : { 96, 32 }, /* max. error = 2^(-96)*/
12 : { 128, 40 }, /* max. error = 2^(-112)*/
13 : { 160, 35 }, /* max. error = 2^(-112)*/
14 : { 256, 27 }, /* max. error = 2^(-128)*/
15 : { 384, 16 }, /* max. error = 2^(-128)*/
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 */
29 : };
30 :
31 : /* returns # of RM trials required for a given bit size */
32 0 : int mp_prime_rabin_miller_trials(int size)
33 : {
34 0 : int x;
35 :
36 0 : for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) {
37 0 : if (sizes[x].k == size) {
38 0 : return sizes[x].t;
39 0 : } else if (sizes[x].k > size) {
40 0 : return (x == 0) ? sizes[0].t : sizes[x - 1].t;
41 : }
42 : }
43 0 : return sizes[x-1].t;
44 : }
45 :
46 :
47 : #endif
|