1 From 59be82ef7e7ec4be6e1597d8aef65dd3d8c3a0d9 Mon Sep 17 00:00:00 2001
2 From: Jelle van der Waa <jelle@vdwaa.nl>
3 Date: Mon, 8 May 2017 21:31:19 +0200
4 Subject: [PATCH 1/2] rsa: Fix build with OpenSSL 1.1.x
6 The rsa_st struct has been made opaque in 1.1.x, add forward compatible
7 code to access the n, e, d members of rsa_struct.
9 EVP_MD_CTX_cleanup has been removed in 1.1.x and EVP_MD_CTX_reset should be
10 called to reinitialise an already created structure.
12 lib/rsa/rsa-sign.c | 44 ++++++++++++++++++++++++++++++++++++++------
13 1 file changed, 38 insertions(+), 6 deletions(-)
15 --- a/lib/rsa/rsa-sign.c
16 +++ b/lib/rsa/rsa-sign.c
21 +#include <openssl/bn.h>
22 #include <openssl/rsa.h>
23 #include <openssl/pem.h>
24 #include <openssl/err.h>
26 #define HAVE_ERR_REMOVE_THREAD_STATE
29 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
30 +static void RSA_get0_key(const RSA *r,
31 + const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
42 static int rsa_err(const char *msg)
44 unsigned long sslErr = ERR_get_error();
45 @@ -286,16 +300,22 @@ static int rsa_init(void)
49 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
50 ret = SSL_library_init();
52 + ret = OPENSSL_init_ssl(0, NULL);
55 fprintf(stderr, "Failure to init SSL library\n");
58 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
59 SSL_load_error_strings();
61 OpenSSL_add_all_algorithms();
62 OpenSSL_add_all_digests();
63 OpenSSL_add_all_ciphers();
68 @@ -335,12 +355,15 @@ err_set_rsa:
72 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
78 static void rsa_remove(void)
80 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
81 CRYPTO_cleanup_all_ex_data();
83 #ifdef HAVE_ERR_REMOVE_THREAD_STATE
84 @@ -349,6 +372,7 @@ static void rsa_remove(void)
91 static void rsa_engine_remove(ENGINE *e)
92 @@ -409,7 +433,11 @@ static int rsa_sign_with_key(RSA *rsa, s
93 ret = rsa_err("Could not obtain signature");
96 - EVP_MD_CTX_cleanup(context);
97 + #if OPENSSL_VERSION_NUMBER < 0x10100000L
98 + EVP_MD_CTX_cleanup(context);
100 + EVP_MD_CTX_reset(context);
102 EVP_MD_CTX_destroy(context);
105 @@ -479,6 +507,7 @@ static int rsa_get_exponent(RSA *key, ui
109 + const BIGNUM *key_e;
113 @@ -487,17 +516,18 @@ static int rsa_get_exponent(RSA *key, ui
117 - if (BN_num_bits(key->e) > 64)
118 + RSA_get0_key(key, NULL, &key_e, NULL);
119 + if (BN_num_bits(key_e) > 64)
122 - *e = BN_get_word(key->e);
123 + *e = BN_get_word(key_e);
125 - if (BN_num_bits(key->e) < 33) {
126 + if (BN_num_bits(key_e) < 33) {
131 - bn_te = BN_dup(key->e);
132 + bn_te = BN_dup(key_e);
136 @@ -527,6 +557,7 @@ int rsa_get_params(RSA *key, uint64_t *e
138 BIGNUM *big1, *big2, *big32, *big2_32;
139 BIGNUM *n, *r, *r_squared, *tmp;
140 + const BIGNUM *key_n;
141 BN_CTX *bn_ctx = BN_CTX_new();
144 @@ -548,7 +579,8 @@ int rsa_get_params(RSA *key, uint64_t *e
145 if (0 != rsa_get_exponent(key, exponent))
148 - if (!BN_copy(n, key->n) || !BN_set_word(big1, 1L) ||
149 + RSA_get0_key(key, &key_n, NULL, NULL);
150 + if (!BN_copy(n, key_n) || !BN_set_word(big1, 1L) ||
151 !BN_set_word(big2, 2L) || !BN_set_word(big32, 32L))