]>
Commit | Line | Data |
---|---|---|
7e63e4f8 MT |
1 | From f91cf5ad8c677b61ceb0bf5877b87f9e93256dd7 Mon Sep 17 00:00:00 2001 |
2 | From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc> | |
3 | Date: Mon, 5 Sep 2016 21:49:07 +0000 | |
4 | Subject: [PATCH] transmission: build against openssl 1.1.0 | |
5 | ||
6 | Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc> | |
7 | --- | |
8 | libtransmission/crypto-utils-openssl.c | 73 ++++++++++++++++++++++++++++++++-- | |
9 | 1 file changed, 69 insertions(+), 4 deletions(-) | |
10 | ||
11 | diff --git a/libtransmission/crypto-utils-openssl.c b/libtransmission/crypto-utils-openssl.c | |
12 | index c4539dc..972e24a 100644 | |
13 | --- a/libtransmission/crypto-utils-openssl.c | |
14 | +++ b/libtransmission/crypto-utils-openssl.c | |
15 | @@ -229,6 +229,61 @@ tr_rc4_process (tr_rc4_ctx_t handle, | |
16 | **** | |
17 | ***/ | |
18 | ||
19 | +#if OPENSSL_VERSION_NUMBER < 0x10100000 | |
20 | +static inline int | |
21 | +DH_set0_pqg (DH * dh, | |
22 | + BIGNUM * p, | |
23 | + BIGNUM * q, | |
24 | + BIGNUM * g) | |
25 | +{ | |
26 | + /* If the fields p and g in d are NULL, the corresponding input | |
27 | + * parameters MUST be non-NULL. q may remain NULL. | |
28 | + */ | |
29 | + if ((dh->p == NULL && p == NULL) | |
30 | + || (dh->g == NULL && g == NULL)) | |
31 | + return 0; | |
32 | + | |
33 | + if (p != NULL) { | |
34 | + BN_free (dh->p); | |
35 | + dh->p = p; | |
36 | + } | |
37 | + if (q != NULL) { | |
38 | + BN_free (dh->q); | |
39 | + dh->q = q; | |
40 | + } | |
41 | + if (g != NULL) { | |
42 | + BN_free (dh->g); | |
43 | + dh->g = g; | |
44 | + } | |
45 | + | |
46 | + if (q != NULL) { | |
47 | + dh->length = BN_num_bits (q); | |
48 | + } | |
49 | + | |
50 | + return 1; | |
51 | +} | |
52 | + | |
53 | +static inline int | |
54 | +DH_set_length (DH * dh, | |
55 | + long length) | |
56 | +{ | |
57 | + dh->length = length; | |
58 | + return 1; | |
59 | +} | |
60 | + | |
61 | +static inline void | |
62 | +DH_get0_key(const DH * dh, | |
63 | + const BIGNUM ** pub_key, | |
64 | + const BIGNUM ** priv_key) | |
65 | +{ | |
66 | + if (pub_key != NULL) | |
67 | + *pub_key = dh->pub_key; | |
68 | + if (priv_key != NULL) | |
69 | + *priv_key = dh->priv_key; | |
70 | +} | |
71 | + | |
72 | +#endif | |
73 | + | |
74 | tr_dh_ctx_t | |
75 | tr_dh_new (const uint8_t * prime_num, | |
76 | size_t prime_num_length, | |
77 | @@ -236,13 +291,19 @@ tr_dh_new (const uint8_t * prime_num, | |
78 | size_t generator_num_length) | |
79 | { | |
80 | DH * handle = DH_new (); | |
81 | + BIGNUM * p, * g; | |
82 | ||
83 | assert (prime_num != NULL); | |
84 | assert (generator_num != NULL); | |
85 | + p = BN_bin2bn (prime_num, prime_num_length, NULL); | |
86 | + g = BN_bin2bn (generator_num, generator_num_length, NULL); | |
87 | ||
88 | - if (!check_pointer (handle->p = BN_bin2bn (prime_num, prime_num_length, NULL)) || | |
89 | - !check_pointer (handle->g = BN_bin2bn (generator_num, generator_num_length, NULL))) | |
90 | + if (!check_pointer (p) || | |
91 | + !check_pointer (g) || | |
92 | + !DH_set0_pqg (handle, p, NULL, g)) | |
93 | { | |
94 | + BN_free (p); | |
95 | + BN_free (g); | |
96 | DH_free (handle); | |
97 | handle = NULL; | |
98 | } | |
99 | @@ -267,16 +328,20 @@ tr_dh_make_key (tr_dh_ctx_t raw_handle, | |
100 | { | |
101 | DH * handle = raw_handle; | |
102 | int dh_size, my_public_key_length; | |
103 | + const BIGNUM * hand_pub_key; | |
104 | ||
105 | assert (handle != NULL); | |
106 | assert (public_key != NULL); | |
107 | ||
108 | - handle->length = private_key_length * 8; | |
109 | + | |
110 | + DH_set_length(handle, private_key_length * 8); | |
111 | ||
112 | if (!check_result (DH_generate_key (handle))) | |
113 | return false; | |
114 | ||
115 | - my_public_key_length = BN_bn2bin (handle->pub_key, public_key); | |
116 | + DH_get0_key (handle, &hand_pub_key, NULL); | |
117 | + | |
118 | + my_public_key_length = BN_bn2bin (hand_pub_key, public_key); | |
119 | dh_size = DH_size (handle); | |
120 | ||
121 | tr_dh_align_key (public_key, my_public_key_length, dh_size); | |
122 | From 8c8386a7f3f482a9c917f51d28e0042e55f56b3e Mon Sep 17 00:00:00 2001 | |
123 | From: Mike Gelfand <mikedld@mikedld.com> | |
124 | Date: Wed, 7 Sep 2016 01:09:04 +0300 | |
125 | Subject: [PATCH] Fix coding style and building with !TR_LIGHTWEIGHT | |
126 | ||
127 | --- | |
128 | libtransmission/crypto-utils-openssl.c | 60 +++++++++++++++++++--------------- | |
129 | 1 file changed, 33 insertions(+), 27 deletions(-) | |
130 | ||
131 | diff --git a/libtransmission/crypto-utils-openssl.c b/libtransmission/crypto-utils-openssl.c | |
132 | index 972e24a..9fd2c58 100644 | |
133 | --- a/libtransmission/crypto-utils-openssl.c | |
134 | +++ b/libtransmission/crypto-utils-openssl.c | |
135 | @@ -14,6 +14,7 @@ | |
136 | #include <assert.h> | |
137 | ||
138 | #include <openssl/bn.h> | |
139 | +#include <openssl/crypto.h> | |
140 | #include <openssl/dh.h> | |
141 | #include <openssl/err.h> | |
142 | #include <openssl/evp.h> | |
143 | @@ -48,7 +49,12 @@ log_openssl_error (const char * file, | |
144 | static bool strings_loaded = false; | |
145 | if (!strings_loaded) | |
146 | { | |
147 | +#if OPENSSL_VERSION_NUMBER < 0x10100000 | |
148 | ERR_load_crypto_strings (); | |
149 | +#else | |
150 | + OPENSSL_init_crypto (OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); | |
151 | +#endif | |
152 | + | |
153 | strings_loaded = true; | |
154 | } | |
155 | #endif | |
156 | @@ -230,6 +236,7 @@ tr_rc4_process (tr_rc4_ctx_t handle, | |
157 | ***/ | |
158 | ||
159 | #if OPENSSL_VERSION_NUMBER < 0x10100000 | |
160 | + | |
161 | static inline int | |
162 | DH_set0_pqg (DH * dh, | |
163 | BIGNUM * p, | |
164 | @@ -237,28 +244,29 @@ DH_set0_pqg (DH * dh, | |
165 | BIGNUM * g) | |
166 | { | |
167 | /* If the fields p and g in d are NULL, the corresponding input | |
168 | - * parameters MUST be non-NULL. q may remain NULL. | |
169 | + * parameters MUST be non-NULL. q may remain NULL. | |
170 | */ | |
171 | - if ((dh->p == NULL && p == NULL) | |
172 | - || (dh->g == NULL && g == NULL)) | |
173 | + if ((dh->p == NULL && p == NULL) || (dh->g == NULL && g == NULL)) | |
174 | return 0; | |
175 | ||
176 | - if (p != NULL) { | |
177 | - BN_free (dh->p); | |
178 | - dh->p = p; | |
179 | - } | |
180 | - if (q != NULL) { | |
181 | - BN_free (dh->q); | |
182 | - dh->q = q; | |
183 | - } | |
184 | - if (g != NULL) { | |
185 | - BN_free (dh->g); | |
186 | - dh->g = g; | |
187 | - } | |
188 | - | |
189 | - if (q != NULL) { | |
190 | + if (p != NULL) | |
191 | + { | |
192 | + BN_free (dh->p); | |
193 | + dh->p = p; | |
194 | + } | |
195 | + if (q != NULL) | |
196 | + { | |
197 | + BN_free (dh->q); | |
198 | + dh->q = q; | |
199 | + } | |
200 | + if (g != NULL) | |
201 | + { | |
202 | + BN_free (dh->g); | |
203 | + dh->g = g; | |
204 | + } | |
205 | + | |
206 | + if (q != NULL) | |
207 | dh->length = BN_num_bits (q); | |
208 | - } | |
209 | ||
210 | return 1; | |
211 | } | |
212 | @@ -267,8 +275,8 @@ static inline int | |
213 | DH_set_length (DH * dh, | |
214 | long length) | |
215 | { | |
216 | - dh->length = length; | |
217 | - return 1; | |
218 | + dh->length = length; | |
219 | + return 1; | |
220 | } | |
221 | ||
222 | static inline void | |
223 | @@ -295,12 +303,11 @@ tr_dh_new (const uint8_t * prime_num, | |
224 | ||
225 | assert (prime_num != NULL); | |
226 | assert (generator_num != NULL); | |
227 | + | |
228 | p = BN_bin2bn (prime_num, prime_num_length, NULL); | |
229 | g = BN_bin2bn (generator_num, generator_num_length, NULL); | |
230 | ||
231 | - if (!check_pointer (p) || | |
232 | - !check_pointer (g) || | |
233 | - !DH_set0_pqg (handle, p, NULL, g)) | |
234 | + if (!check_pointer (p) || !check_pointer (g) || !DH_set0_pqg (handle, p, NULL, g)) | |
235 | { | |
236 | BN_free (p); | |
237 | BN_free (g); | |
238 | @@ -328,20 +335,19 @@ tr_dh_make_key (tr_dh_ctx_t raw_handle, | |
239 | { | |
240 | DH * handle = raw_handle; | |
241 | int dh_size, my_public_key_length; | |
242 | - const BIGNUM * hand_pub_key; | |
243 | + const BIGNUM * my_public_key; | |
244 | ||
245 | assert (handle != NULL); | |
246 | assert (public_key != NULL); | |
247 | ||
248 | - | |
249 | DH_set_length(handle, private_key_length * 8); | |
250 | ||
251 | if (!check_result (DH_generate_key (handle))) | |
252 | return false; | |
253 | ||
254 | - DH_get0_key (handle, &hand_pub_key, NULL); | |
255 | + DH_get0_key (handle, &my_public_key, NULL); | |
256 | ||
257 | - my_public_key_length = BN_bn2bin (hand_pub_key, public_key); | |
258 | + my_public_key_length = BN_bn2bin (my_public_key, public_key); | |
259 | dh_size = DH_size (handle); | |
260 | ||
261 | tr_dh_align_key (public_key, my_public_key_length, dh_size); |