Skip to content

Commit c062eec

Browse files
author
Catherine Garabedian
authored
Patching rsa-sign to be compatible with OpenSSL v1.1+
Patching rsa-sign to be compatible with OpenSSL v1.1+
2 parents 595ec31 + 1cf0947 commit c062eec

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

lib/rsa/rsa-sign.c

+34-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
#define HAVE_ERR_REMOVE_THREAD_STATE
2020
#endif
2121

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+
2235
static int rsa_err(const char *msg)
2336
{
2437
unsigned long sslErr = ERR_get_error();
@@ -134,22 +147,29 @@ static int rsa_init(void)
134147
{
135148
int ret;
136149

150+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
137151
ret = SSL_library_init();
152+
#else
153+
ret = OPENSSL_init_ssl(0, NULL);
154+
#endif
138155
if (!ret) {
139156
fprintf(stderr, "Failure to init SSL library\n");
140157
return -1;
141158
}
159+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
142160
SSL_load_error_strings();
143161

144162
OpenSSL_add_all_algorithms();
145163
OpenSSL_add_all_digests();
146164
OpenSSL_add_all_ciphers();
165+
#endif
147166

148167
return 0;
149168
}
150169

151170
static void rsa_remove(void)
152171
{
172+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
153173
CRYPTO_cleanup_all_ex_data();
154174
ERR_free_strings();
155175
#ifdef HAVE_ERR_REMOVE_THREAD_STATE
@@ -158,6 +178,7 @@ static void rsa_remove(void)
158178
ERR_remove_state(0);
159179
#endif
160180
EVP_cleanup();
181+
#endif
161182
}
162183

163184
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,
210231
ret = rsa_err("Could not obtain signature");
211232
goto err_sign;
212233
}
234+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
213235
EVP_MD_CTX_cleanup(context);
236+
#else
237+
EVP_MD_CTX_reset(context);
238+
#endif
214239
EVP_MD_CTX_destroy(context);
215240
EVP_PKEY_free(key);
216241

@@ -268,6 +293,7 @@ static int rsa_get_exponent(RSA *key, uint64_t *e)
268293
{
269294
int ret;
270295
BIGNUM *bn_te;
296+
const BIGNUM *key_e;
271297
uint64_t te;
272298

273299
ret = -EINVAL;
@@ -276,17 +302,18 @@ static int rsa_get_exponent(RSA *key, uint64_t *e)
276302
if (!e)
277303
goto cleanup;
278304

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)
280307
goto cleanup;
281308

282-
*e = BN_get_word(key->e);
309+
*e = BN_get_word(key_e);
283310

284-
if (BN_num_bits(key->e) < 33) {
311+
if (BN_num_bits(key_e) < 33) {
285312
ret = 0;
286313
goto cleanup;
287314
}
288315

289-
bn_te = BN_dup(key->e);
316+
bn_te = BN_dup(key_e);
290317
if (!bn_te)
291318
goto cleanup;
292319

@@ -316,6 +343,7 @@ int rsa_get_params(RSA *key, uint64_t *exponent, uint32_t *n0_invp,
316343
{
317344
BIGNUM *big1, *big2, *big32, *big2_32;
318345
BIGNUM *n, *r, *r_squared, *tmp;
346+
const BIGNUM *key_n;
319347
BN_CTX *bn_ctx = BN_CTX_new();
320348
int ret = 0;
321349

@@ -337,7 +365,8 @@ int rsa_get_params(RSA *key, uint64_t *exponent, uint32_t *n0_invp,
337365
if (0 != rsa_get_exponent(key, exponent))
338366
ret = -1;
339367

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) ||
341370
!BN_set_word(big2, 2L) || !BN_set_word(big32, 32L))
342371
ret = -1;
343372

0 commit comments

Comments
 (0)