1 From b3747e625780be90dcff11c2d9e91048016bb4d0 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
3 Date: Thu, 13 Oct 2016 18:14:17 +0200
4 Subject: [PATCH] Adapt to OpenSSL 1.1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 OpenSSL 1.1.0 hid structure internals and provided methods for getting
10 and settting the internal values. This patch modifes the code so that
11 it can be built with OpenSSL 1.1.0 as well as with the older one.
15 Signed-off-by: Petr Písař <ppisar@redhat.com>
17 RSA.xs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
18 1 file changed, 73 insertions(+), 16 deletions(-)
20 diff --git a/RSA.xs b/RSA.xs
21 index de512e7..9bf6f01 100644
24 @@ -49,7 +49,13 @@ void croakSsl(char* p_file, int p_line)
26 char _is_private(rsaData* p_rsa)
28 - return(p_rsa->rsa->d != NULL);
30 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
33 + RSA_get0_key(p_rsa->rsa, NULL, NULL, &d);
38 SV* make_rsa_obj(SV* p_proto, RSA* p_rsa)
39 @@ -136,7 +142,7 @@ unsigned char* get_message_digest(SV* text_SV, int hash_method)
43 -SV* bn2sv(BIGNUM* p_bn)
44 +SV* bn2sv(const BIGNUM* p_bn)
47 ? sv_2mortal(newSViv((IV) BN_dup(p_bn)))
48 @@ -317,6 +323,9 @@ _new_key_from_parameters(proto, n, e, d, p, q)
50 BIGNUM* p_minus_1 = NULL;
51 BIGNUM* q_minus_1 = NULL;
52 + BIGNUM* dmp1 = NULL;
53 + BIGNUM* dmq1 = NULL;
54 + BIGNUM* iqmp = NULL;
58 @@ -325,8 +334,10 @@ _new_key_from_parameters(proto, n, e, d, p, q)
59 croak("At least a modulous and public key must be provided");
61 CHECK_OPEN_SSL(rsa = RSA_new());
62 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
69 @@ -341,8 +352,12 @@ _new_key_from_parameters(proto, n, e, d, p, q)
71 THROW(BN_div(q, NULL, n, p, ctx));
73 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
77 + THROW(RSA_set0_factors(rsa, p, q));
79 THROW(p_minus_1 = BN_new());
80 THROW(BN_sub(p_minus_1, p, BN_value_one()));
81 THROW(q_minus_1 = BN_new());
82 @@ -353,17 +368,32 @@ _new_key_from_parameters(proto, n, e, d, p, q)
83 THROW(BN_mul(d, p_minus_1, q_minus_1, ctx));
84 THROW(BN_mod_inverse(d, e, d, ctx));
86 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
88 - THROW(rsa->dmp1 = BN_new());
89 - THROW(BN_mod(rsa->dmp1, d, p_minus_1, ctx));
90 - THROW(rsa->dmq1 = BN_new());
91 - THROW(BN_mod(rsa->dmq1, d, q_minus_1, ctx));
92 - THROW(rsa->iqmp = BN_new());
93 - THROW(BN_mod_inverse(rsa->iqmp, q, p, ctx));
95 + THROW(RSA_set0_key(rsa, n, e, d));
97 + THROW(dmp1 = BN_new());
98 + THROW(BN_mod(dmp1, d, p_minus_1, ctx));
99 + THROW(dmq1 = BN_new());
100 + THROW(BN_mod(dmq1, d, q_minus_1, ctx));
101 + THROW(iqmp = BN_new());
102 + THROW(BN_mod_inverse(iqmp, q, p, ctx));
103 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
108 + THROW(RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp));
110 + dmp1 = dmq1 = iqmp = NULL;
111 THROW(RSA_check_key(rsa) == 1);
113 if (p_minus_1) BN_clear_free(p_minus_1);
114 if (q_minus_1) BN_clear_free(q_minus_1);
115 + if (dmp1) BN_clear_free(dmp1);
116 + if (dmq1) BN_clear_free(dmq1);
117 + if (iqmp) BN_clear_free(iqmp);
118 if (ctx) BN_CTX_free(ctx);
121 @@ -373,7 +403,11 @@ _new_key_from_parameters(proto, n, e, d, p, q)
125 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
128 + CHECK_OPEN_SSL(RSA_set0_key(rsa, n, e, d));
131 RETVAL = make_rsa_obj(proto, rsa);
133 @@ -383,18 +417,41 @@ _new_key_from_parameters(proto, n, e, d, p, q)
135 _get_key_parameters(p_rsa)
143 + const BIGNUM* dmp1;
144 + const BIGNUM* dmq1;
145 + const BIGNUM* iqmp;
150 - XPUSHs(bn2sv(rsa->n));
151 - XPUSHs(bn2sv(rsa->e));
152 - XPUSHs(bn2sv(rsa->d));
153 - XPUSHs(bn2sv(rsa->p));
154 - XPUSHs(bn2sv(rsa->q));
155 - XPUSHs(bn2sv(rsa->dmp1));
156 - XPUSHs(bn2sv(rsa->dmq1));
157 - XPUSHs(bn2sv(rsa->iqmp));
158 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
168 + RSA_get0_key(rsa, &n, &e, &d);
169 + RSA_get0_factors(rsa, &p, &q);
170 + RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
177 + XPUSHs(bn2sv(dmp1));
178 + XPUSHs(bn2sv(dmq1));
179 + XPUSHs(bn2sv(iqmp));