4
4
/* SPDX-License-Identifier: Unlicense */
5
5
6
6
static const struct {
7
- int k , t ;
7
+ int k , t , e ;
8
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 */
9
+ { 80 , -1 , 96 }, /* Use deterministic algorithm for size <= 80 bits */
10
+ { 81 , 37 , 96 }, /* max. error = 2^(-96)*/
11
+ { 96 , 32 , 96 }, /* max. error = 2^(-96)*/
12
+ { 128 , 40 , 112 }, /* max. error = 2^(-112)*/
13
+ { 160 , 35 , 112 }, /* max. error = 2^(-112)*/
14
+ { 256 , 27 , 128 }, /* max. error = 2^(-128)*/
15
+ { 384 , 16 , 128 }, /* max. error = 2^(-128)*/
16
+ { 512 , 18 , 160 }, /* max. error = 2^(-160)*/
17
+ { 768 , 11 , 160 }, /* max. error = 2^(-160)*/
18
+ { 896 , 10 , 160 }, /* max. error = 2^(-160)*/
19
+ { 1024 , 12 , 192 }, /* max. error = 2^(-192)*/
20
+ { 1536 , 8 , 192 }, /* max. error = 2^(-192)*/
21
+ { 2048 , 6 , 192 }, /* max. error = 2^(-192)*/
22
+ { 3072 , 4 , 192 }, /* max. error = 2^(-192)*/
23
+ { 4096 , 5 , 256 }, /* max. error = 2^(-256)*/
24
+ { 5120 , 4 , 256 }, /* max. error = 2^(-256)*/
25
+ { 6144 , 4 , 256 }, /* max. error = 2^(-256)*/
26
+ { 8192 , 3 , 256 }, /* max. error = 2^(-256)*/
27
+ { 9216 , 3 , 256 }, /* max. error = 2^(-256)*/
28
+ { 10240 , 2 , 256 } /* For bigger keysizes use always at least 2 Rounds */
29
29
};
30
30
31
31
/* returns # of RM trials required for a given bit size */
32
32
int mp_prime_rabin_miller_trials (int size )
33
33
{
34
34
int x ;
35
-
35
+ #ifdef LTM_USE_ONLY_MR
36
+ for (x = 0 ; x < (int )(sizeof (sizes )/(sizeof (sizes [0 ]))); x ++ ) {
37
+ if (sizes [x ].k == size ) {
38
+ return mp_prime_rabin_miller_trials_dea (sizes [x ].e );
39
+ }
40
+ if (sizes [x ].k > size ) {
41
+ return (x == 0 ) ? mp_prime_rabin_miller_trials_dea (sizes [0 ].e ) :
42
+ mp_prime_rabin_miller_trials_dea (sizes [x - 1 ].e );
43
+ }
44
+ }
45
+ return mp_prime_rabin_miller_trials_dea (sizes [x - 1 ].e );
46
+ #else
36
47
for (x = 0 ; x < (int )(sizeof (sizes )/(sizeof (sizes [0 ]))); x ++ ) {
37
48
if (sizes [x ].k == size ) {
38
49
return sizes [x ].t ;
@@ -42,6 +53,7 @@ int mp_prime_rabin_miller_trials(int size)
42
53
}
43
54
}
44
55
return sizes [x - 1 ].t ;
56
+ #endif
45
57
}
46
58
47
59
0 commit comments