|
Lines 14-19
Link Here
|
| 14 |
#include <assert.h> |
14 |
#include <assert.h> |
| 15 |
|
15 |
|
| 16 |
#include <openssl/bn.h> |
16 |
#include <openssl/bn.h> |
|
|
17 |
#include <openssl/crypto.h> |
| 17 |
#include <openssl/dh.h> |
18 |
#include <openssl/dh.h> |
| 18 |
#include <openssl/err.h> |
19 |
#include <openssl/err.h> |
| 19 |
#include <openssl/evp.h> |
20 |
#include <openssl/evp.h> |
|
Lines 48-54
log_openssl_error (const char * file,
Link Here
|
| 48 |
static bool strings_loaded = false; |
49 |
static bool strings_loaded = false; |
| 49 |
if (!strings_loaded) |
50 |
if (!strings_loaded) |
| 50 |
{ |
51 |
{ |
|
|
52 |
#if OPENSSL_VERSION_NUMBER < 0x10100000 |
| 51 |
ERR_load_crypto_strings (); |
53 |
ERR_load_crypto_strings (); |
|
|
54 |
#else |
| 55 |
OPENSSL_init_crypto (OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); |
| 56 |
#endif |
| 57 |
|
| 52 |
strings_loaded = true; |
58 |
strings_loaded = true; |
| 53 |
} |
59 |
} |
| 54 |
#endif |
60 |
#endif |
|
Lines 230-235
tr_rc4_process (tr_rc4_ctx_t handle,
Link Here
|
| 230 |
***/ |
236 |
***/ |
| 231 |
|
237 |
|
| 232 |
#if OPENSSL_VERSION_NUMBER < 0x10100000 |
238 |
#if OPENSSL_VERSION_NUMBER < 0x10100000 |
|
|
239 |
|
| 233 |
static inline int |
240 |
static inline int |
| 234 |
DH_set0_pqg (DH * dh, |
241 |
DH_set0_pqg (DH * dh, |
| 235 |
BIGNUM * p, |
242 |
BIGNUM * p, |
|
Lines 237-264
DH_set0_pqg (DH * dh,
Link Here
|
| 237 |
BIGNUM * g) |
244 |
BIGNUM * g) |
| 238 |
{ |
245 |
{ |
| 239 |
/* If the fields p and g in d are NULL, the corresponding input |
246 |
/* If the fields p and g in d are NULL, the corresponding input |
| 240 |
* parameters MUST be non-NULL. q may remain NULL. |
247 |
* parameters MUST be non-NULL. q may remain NULL. |
| 241 |
*/ |
248 |
*/ |
| 242 |
if ((dh->p == NULL && p == NULL) |
249 |
if ((dh->p == NULL && p == NULL) || (dh->g == NULL && g == NULL)) |
| 243 |
|| (dh->g == NULL && g == NULL)) |
|
|
| 244 |
return 0; |
250 |
return 0; |
| 245 |
|
251 |
|
| 246 |
if (p != NULL) { |
252 |
if (p != NULL) |
| 247 |
BN_free (dh->p); |
253 |
{ |
| 248 |
dh->p = p; |
254 |
BN_free (dh->p); |
| 249 |
} |
255 |
dh->p = p; |
| 250 |
if (q != NULL) { |
256 |
} |
| 251 |
BN_free (dh->q); |
257 |
if (q != NULL) |
| 252 |
dh->q = q; |
258 |
{ |
| 253 |
} |
259 |
BN_free (dh->q); |
| 254 |
if (g != NULL) { |
260 |
dh->q = q; |
| 255 |
BN_free (dh->g); |
261 |
} |
| 256 |
dh->g = g; |
262 |
if (g != NULL) |
| 257 |
} |
263 |
{ |
| 258 |
|
264 |
BN_free (dh->g); |
| 259 |
if (q != NULL) { |
265 |
dh->g = g; |
|
|
266 |
} |
| 267 |
|
| 268 |
if (q != NULL) |
| 260 |
dh->length = BN_num_bits (q); |
269 |
dh->length = BN_num_bits (q); |
| 261 |
} |
|
|
| 262 |
|
270 |
|
| 263 |
return 1; |
271 |
return 1; |
| 264 |
} |
272 |
} |
|
Lines 267-274
static inline int
Link Here
|
| 267 |
DH_set_length (DH * dh, |
275 |
DH_set_length (DH * dh, |
| 268 |
long length) |
276 |
long length) |
| 269 |
{ |
277 |
{ |
| 270 |
dh->length = length; |
278 |
dh->length = length; |
| 271 |
return 1; |
279 |
return 1; |
| 272 |
} |
280 |
} |
| 273 |
|
281 |
|
| 274 |
static inline void |
282 |
static inline void |
|
Lines 295-306
tr_dh_new (const uint8_t * prime_num,
Link Here
|
| 295 |
|
303 |
|
| 296 |
assert (prime_num != NULL); |
304 |
assert (prime_num != NULL); |
| 297 |
assert (generator_num != NULL); |
305 |
assert (generator_num != NULL); |
|
|
306 |
|
| 298 |
p = BN_bin2bn (prime_num, prime_num_length, NULL); |
307 |
p = BN_bin2bn (prime_num, prime_num_length, NULL); |
| 299 |
g = BN_bin2bn (generator_num, generator_num_length, NULL); |
308 |
g = BN_bin2bn (generator_num, generator_num_length, NULL); |
| 300 |
|
309 |
|
| 301 |
if (!check_pointer (p) || |
310 |
if (!check_pointer (p) || !check_pointer (g) || !DH_set0_pqg (handle, p, NULL, g)) |
| 302 |
!check_pointer (g) || |
|
|
| 303 |
!DH_set0_pqg (handle, p, NULL, g)) |
| 304 |
{ |
311 |
{ |
| 305 |
BN_free (p); |
312 |
BN_free (p); |
| 306 |
BN_free (g); |
313 |
BN_free (g); |
|
Lines 328-347
tr_dh_make_key (tr_dh_ctx_t raw_handle,
Link Here
|
| 328 |
{ |
335 |
{ |
| 329 |
DH * handle = raw_handle; |
336 |
DH * handle = raw_handle; |
| 330 |
int dh_size, my_public_key_length; |
337 |
int dh_size, my_public_key_length; |
| 331 |
const BIGNUM * hand_pub_key; |
338 |
const BIGNUM * my_public_key; |
| 332 |
|
339 |
|
| 333 |
assert (handle != NULL); |
340 |
assert (handle != NULL); |
| 334 |
assert (public_key != NULL); |
341 |
assert (public_key != NULL); |
| 335 |
|
342 |
|
| 336 |
|
|
|
| 337 |
DH_set_length(handle, private_key_length * 8); |
343 |
DH_set_length(handle, private_key_length * 8); |
| 338 |
|
344 |
|
| 339 |
if (!check_result (DH_generate_key (handle))) |
345 |
if (!check_result (DH_generate_key (handle))) |
| 340 |
return false; |
346 |
return false; |
| 341 |
|
347 |
|
| 342 |
DH_get0_key (handle, &hand_pub_key, NULL); |
348 |
DH_get0_key (handle, &my_public_key, NULL); |
| 343 |
|
349 |
|
| 344 |
my_public_key_length = BN_bn2bin (hand_pub_key, public_key); |
350 |
my_public_key_length = BN_bn2bin (my_public_key, public_key); |
| 345 |
dh_size = DH_size (handle); |
351 |
dh_size = DH_size (handle); |
| 346 |
|
352 |
|
| 347 |
tr_dh_align_key (public_key, my_public_key_length, dh_size); |
353 |
tr_dh_align_key (public_key, my_public_key_length, dh_size); |