44/* SPDX-License-Identifier: Unlicense */
55
66static const struct {
7- int k , t ;
7+ int k , t , e ;
88} 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 */
2929};
3030
3131/* returns # of RM trials required for a given bit size */
3232int mp_prime_rabin_miller_trials (int size )
3333{
3434 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
3647 for (x = 0 ; x < (int )(sizeof (sizes )/(sizeof (sizes [0 ]))); x ++ ) {
3748 if (sizes [x ].k == size ) {
3849 return sizes [x ].t ;
@@ -42,6 +53,7 @@ int mp_prime_rabin_miller_trials(int size)
4253 }
4354 }
4455 return sizes [x - 1 ].t ;
56+ #endif
4557}
4658
4759
0 commit comments