archrelease: copy trunk to extra-x86_64
[arch-packages.git] / perl-crypt-openssl-rsa / trunk / 0001-Adapt-to-OpenSSL-1.1.0.patch
blob748271d4b357f7b96a02c106e0e7c89f8d1a7ca5
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
5 MIME-Version: 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.
13 CPAN RT#117481
15 Signed-off-by: Petr Písař <ppisar@redhat.com>
16 ---
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
22 --- a/RSA.xs
23 +++ b/RSA.xs
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);
29 + const BIGNUM *d;
30 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
31 + d = p_rsa->rsa->d;
32 +#else
33 + RSA_get0_key(p_rsa->rsa, NULL, NULL, &d);
34 +#endif
35 + return(d != NULL);
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)
46 return p_bn != NULL
47 ? sv_2mortal(newSViv((IV) BN_dup(p_bn)))
48 @@ -317,6 +323,9 @@ _new_key_from_parameters(proto, n, e, d, p, q)
49 BN_CTX* ctx;
50 BIGNUM* p_minus_1 = NULL;
51 BIGNUM* q_minus_1 = NULL;
52 + BIGNUM* dmp1 = NULL;
53 + BIGNUM* dmq1 = NULL;
54 + BIGNUM* iqmp = NULL;
55 int error;
56 CODE:
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
63 rsa->n = n;
64 rsa->e = e;
65 +#endif
66 if (p || q)
68 error = 0;
69 @@ -341,8 +352,12 @@ _new_key_from_parameters(proto, n, e, d, p, q)
70 q = BN_new();
71 THROW(BN_div(q, NULL, n, p, ctx));
73 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
74 rsa->p = p;
75 rsa->q = q;
76 +#else
77 + THROW(RSA_set0_factors(rsa, p, q));
78 +#endif
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
87 rsa->d = d;
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));
94 +#else
95 + THROW(RSA_set0_key(rsa, n, e, d));
96 +#endif
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
104 + rsa->dmp1 = dmp1;
105 + rsa->dmq1 = dmq1;
106 + rsa->iqmp = iqmp;
107 +#else
108 + THROW(RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp));
109 +#endif
110 + dmp1 = dmq1 = iqmp = NULL;
111 THROW(RSA_check_key(rsa) == 1);
112 err:
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);
119 if (error)
121 @@ -373,7 +403,11 @@ _new_key_from_parameters(proto, n, e, d, p, q)
123 else
125 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
126 rsa->d = d;
127 +#else
128 + CHECK_OPEN_SSL(RSA_set0_key(rsa, n, e, d));
129 +#endif
131 RETVAL = make_rsa_obj(proto, rsa);
133 @@ -383,18 +417,41 @@ _new_key_from_parameters(proto, n, e, d, p, q)
134 void
135 _get_key_parameters(p_rsa)
136 rsaData* p_rsa;
137 +PREINIT:
138 + const BIGNUM* n;
139 + const BIGNUM* e;
140 + const BIGNUM* d;
141 + const BIGNUM* p;
142 + const BIGNUM* q;
143 + const BIGNUM* dmp1;
144 + const BIGNUM* dmq1;
145 + const BIGNUM* iqmp;
146 PPCODE:
148 RSA* rsa;
149 rsa = p_rsa->rsa;
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
159 + n = rsa->n;
160 + e = rsa->e;
161 + d = rsa->d;
162 + p = rsa->p;
163 + q = rsa->q;
164 + dmp1 = rsa->dmp1;
165 + dmq1 = rsa->dmq1;
166 + iqmp = rsa->iqmp;
167 +#else
168 + RSA_get0_key(rsa, &n, &e, &d);
169 + RSA_get0_factors(rsa, &p, &q);
170 + RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
171 +#endif
172 + XPUSHs(bn2sv(n));
173 + XPUSHs(bn2sv(e));
174 + XPUSHs(bn2sv(d));
175 + XPUSHs(bn2sv(p));
176 + XPUSHs(bn2sv(q));
177 + XPUSHs(bn2sv(dmp1));
178 + XPUSHs(bn2sv(dmq1));
179 + XPUSHs(bn2sv(iqmp));
184 2.7.4