comparison genrsa.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 750ec4ec4cbe
children 1051e4eea25a
comparison
equal deleted inserted replaced
1654:cc0fc5131c5c 1655:f52919ffd3b1
93 /* return a prime suitable for p or q */ 93 /* return a prime suitable for p or q */
94 static void getrsaprime(mp_int* prime, mp_int *primeminus, 94 static void getrsaprime(mp_int* prime, mp_int *primeminus,
95 mp_int* rsa_e, unsigned int size_bytes) { 95 mp_int* rsa_e, unsigned int size_bytes) {
96 96
97 unsigned char *buf; 97 unsigned char *buf;
98 int trials;
98 DEF_MP_INT(temp_gcd); 99 DEF_MP_INT(temp_gcd);
99 100
100 buf = (unsigned char*)m_malloc(size_bytes); 101 buf = (unsigned char*)m_malloc(size_bytes);
101 102
102 m_mp_init(&temp_gcd); 103 m_mp_init(&temp_gcd);
106 genrandom(buf, size_bytes); 107 genrandom(buf, size_bytes);
107 buf[0] |= 0x80; 108 buf[0] |= 0x80;
108 109
109 bytes_to_mp(prime, buf, size_bytes); 110 bytes_to_mp(prime, buf, size_bytes);
110 111
111 /* find the next integer which is prime, 8 round of miller-rabin */ 112 /* find the next integer which is prime */
112 if (mp_prime_next_prime(prime, 8, 0) != MP_OKAY) { 113 trials = mp_prime_rabin_miller_trials(mp_count_bits(prime));
114 if (mp_prime_next_prime(prime, trials, 0) != MP_OKAY) {
113 fprintf(stderr, "RSA generation failed\n"); 115 fprintf(stderr, "RSA generation failed\n");
114 exit(1); 116 exit(1);
115 } 117 }
116 118
117 /* subtract one to get p-1 */ 119 /* subtract one to get p-1 */