comparison libtommath/bn_mp_prime_rabin_miller_trials.c @ 1655:f52919ffd3b1

update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79) * make key-generation compliant to FIPS 186.4 * fix includes in tommath_class.h * update fuzzcorpus instead of error-out * fixup fuzzing make-targets * update Makefile.in * apply necessary patches to ltm sources * clean-up not required ltm files * update to vanilla ltm 1.1.0 this already only contains the required files * remove set/get double
author Steffen Jaeckel <s_jaeckel@gmx.de>
date Mon, 16 Sep 2019 15:50:38 +0200
parents 8bba51a55704
children a36e545fb43d
comparison
equal deleted inserted replaced
1654:cc0fc5131c5c 1655:f52919ffd3b1
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 *
5 * LibTomMath is a library that provides multiple-precision 5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality. 6 * integer arithmetic as well as number theoretic functionality.
7 * 7 *
8 * The library was designed directly after the MPI library by 8 * The library was designed directly after the MPI library by
9 * Michael Fromberger but has been written from scratch with 9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place. 10 * additional optimizations in place.
11 * 11 *
12 * The library is free for all purposes without any express 12 * SPDX-License-Identifier: Unlicense
13 * guarantee it works.
14 *
15 * Tom St Denis, [email protected], http://libtom.org
16 */ 13 */
17 14
18 15
19 static const struct { 16 static const struct {
20 int k, t; 17 int k, t;
21 } sizes[] = { 18 } sizes[] = {
22 { 128, 28 }, 19 { 80, -1 }, /* Use deterministic algorithm for size <= 80 bits */
23 { 256, 16 }, 20 { 81, 39 },
24 { 384, 10 }, 21 { 96, 37 },
25 { 512, 7 }, 22 { 128, 32 },
26 { 640, 6 }, 23 { 160, 27 },
27 { 768, 5 }, 24 { 192, 21 },
28 { 896, 4 }, 25 { 256, 16 },
29 { 1024, 4 } 26 { 384, 10 },
27 { 512, 7 },
28 { 640, 6 },
29 { 768, 5 },
30 { 896, 4 },
31 { 1024, 4 },
32 { 2048, 2 },
33 { 4096, 1 },
30 }; 34 };
31 35
32 /* returns # of RM trials required for a given bit size */ 36 /* returns # of RM trials required for a given bit size and max. error of 2^(-96)*/
33 int mp_prime_rabin_miller_trials(int size) 37 int mp_prime_rabin_miller_trials(int size)
34 { 38 {
35 int x; 39 int x;
36 40
37 for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) { 41 for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) {
38 if (sizes[x].k == size) { 42 if (sizes[x].k == size) {
39 return sizes[x].t; 43 return sizes[x].t;
40 } else if (sizes[x].k > size) { 44 } else if (sizes[x].k > size) {
41 return (x == 0) ? sizes[0].t : sizes[x - 1].t; 45 return (x == 0) ? sizes[0].t : sizes[x - 1].t;
42 } 46 }
43 } 47 }
44 return sizes[x-1].t + 1; 48 return sizes[x-1].t + 1;
45 } 49 }
46 50
47 51
48 #endif 52 #endif
49 53
50 /* ref: $Format:%D$ */ 54 /* ref: HEAD -> master, tag: v1.1.0 */
51 /* git commit: $Format:%H$ */ 55 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
52 /* commit time: $Format:%ai$ */ 56 /* commit time: 2019-01-28 20:32:32 +0100 */