19
19
#define HAVE_ERR_REMOVE_THREAD_STATE
20
20
#endif
21
21
22
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
23
+ static void RSA_get0_key (const RSA * r ,
24
+ const BIGNUM * * n , const BIGNUM * * e , const BIGNUM * * d )
25
+ {
26
+ if (n != NULL )
27
+ * n = r -> n ;
28
+ if (e != NULL )
29
+ * e = r -> e ;
30
+ if (d != NULL )
31
+ * d = r -> d ;
32
+ }
33
+ #endif
34
+
22
35
static int rsa_err (const char * msg )
23
36
{
24
37
unsigned long sslErr = ERR_get_error ();
@@ -134,22 +147,29 @@ static int rsa_init(void)
134
147
{
135
148
int ret ;
136
149
150
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
137
151
ret = SSL_library_init ();
152
+ #else
153
+ ret = OPENSSL_init_ssl (0 , NULL );
154
+ #endif
138
155
if (!ret ) {
139
156
fprintf (stderr , "Failure to init SSL library\n" );
140
157
return -1 ;
141
158
}
159
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
142
160
SSL_load_error_strings ();
143
161
144
162
OpenSSL_add_all_algorithms ();
145
163
OpenSSL_add_all_digests ();
146
164
OpenSSL_add_all_ciphers ();
165
+ #endif
147
166
148
167
return 0 ;
149
168
}
150
169
151
170
static void rsa_remove (void )
152
171
{
172
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
153
173
CRYPTO_cleanup_all_ex_data ();
154
174
ERR_free_strings ();
155
175
#ifdef HAVE_ERR_REMOVE_THREAD_STATE
@@ -158,6 +178,7 @@ static void rsa_remove(void)
158
178
ERR_remove_state (0 );
159
179
#endif
160
180
EVP_cleanup ();
181
+ #endif
161
182
}
162
183
163
184
static int rsa_sign_with_key (RSA * rsa , struct checksum_algo * checksum_algo ,
@@ -210,7 +231,11 @@ static int rsa_sign_with_key(RSA *rsa, struct checksum_algo *checksum_algo,
210
231
ret = rsa_err ("Could not obtain signature" );
211
232
goto err_sign ;
212
233
}
234
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
213
235
EVP_MD_CTX_cleanup (context );
236
+ #else
237
+ EVP_MD_CTX_reset (context );
238
+ #endif
214
239
EVP_MD_CTX_destroy (context );
215
240
EVP_PKEY_free (key );
216
241
@@ -268,6 +293,7 @@ static int rsa_get_exponent(RSA *key, uint64_t *e)
268
293
{
269
294
int ret ;
270
295
BIGNUM * bn_te ;
296
+ const BIGNUM * key_e ;
271
297
uint64_t te ;
272
298
273
299
ret = - EINVAL ;
@@ -276,17 +302,18 @@ static int rsa_get_exponent(RSA *key, uint64_t *e)
276
302
if (!e )
277
303
goto cleanup ;
278
304
279
- if (BN_num_bits (key -> e ) > 64 )
305
+ RSA_get0_key (key , NULL , & key_e , NULL );
306
+ if (BN_num_bits (key_e ) > 64 )
280
307
goto cleanup ;
281
308
282
- * e = BN_get_word (key -> e );
309
+ * e = BN_get_word (key_e );
283
310
284
- if (BN_num_bits (key -> e ) < 33 ) {
311
+ if (BN_num_bits (key_e ) < 33 ) {
285
312
ret = 0 ;
286
313
goto cleanup ;
287
314
}
288
315
289
- bn_te = BN_dup (key -> e );
316
+ bn_te = BN_dup (key_e );
290
317
if (!bn_te )
291
318
goto cleanup ;
292
319
@@ -316,6 +343,7 @@ int rsa_get_params(RSA *key, uint64_t *exponent, uint32_t *n0_invp,
316
343
{
317
344
BIGNUM * big1 , * big2 , * big32 , * big2_32 ;
318
345
BIGNUM * n , * r , * r_squared , * tmp ;
346
+ const BIGNUM * key_n ;
319
347
BN_CTX * bn_ctx = BN_CTX_new ();
320
348
int ret = 0 ;
321
349
@@ -337,7 +365,8 @@ int rsa_get_params(RSA *key, uint64_t *exponent, uint32_t *n0_invp,
337
365
if (0 != rsa_get_exponent (key , exponent ))
338
366
ret = -1 ;
339
367
340
- if (!BN_copy (n , key -> n ) || !BN_set_word (big1 , 1L ) ||
368
+ RSA_get0_key (key , & key_n , NULL , NULL );
369
+ if (!BN_copy (n , key_n ) || !BN_set_word (big1 , 1L ) ||
341
370
!BN_set_word (big2 , 2L ) || !BN_set_word (big32 , 32L ))
342
371
ret = -1 ;
343
372
0 commit comments