Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 630692 | Differences between
and this patch

Collapse All | Expand All

(-)a/libtransmission/crypto-utils-openssl.c (-5 / +69 lines)
Lines 229-234 tr_rc4_process (tr_rc4_ctx_t handle, Link Here
229
****
229
****
230
***/
230
***/
231
231
232
#if OPENSSL_VERSION_NUMBER < 0x10100000
233
static inline int
234
DH_set0_pqg (DH     * dh,
235
             BIGNUM * p,
236
             BIGNUM * q,
237
             BIGNUM * g)
238
{
239
  /* If the fields p and g in d are NULL, the corresponding input
240
   * parameters MUST be non-NULL.  q may remain NULL.
241
   */
242
  if ((dh->p == NULL && p == NULL)
243
      || (dh->g == NULL && g == NULL))
244
    return 0;
245
246
  if (p != NULL) {
247
    BN_free (dh->p);
248
    dh->p = p;
249
  }
250
  if (q != NULL) {
251
    BN_free (dh->q);
252
    dh->q = q;
253
  }
254
  if (g != NULL) {
255
    BN_free (dh->g);
256
    dh->g = g;
257
  }
258
259
  if (q != NULL) {
260
    dh->length = BN_num_bits (q);
261
  }
262
263
  return 1;
264
}
265
266
static inline int
267
DH_set_length (DH   * dh,
268
               long   length)
269
{
270
	dh->length = length;
271
	return 1;
272
}
273
274
static inline void
275
DH_get0_key(const DH      * dh,
276
            const BIGNUM ** pub_key,
277
            const BIGNUM ** priv_key)
278
{
279
  if (pub_key != NULL)
280
    *pub_key = dh->pub_key;
281
  if (priv_key != NULL)
282
    *priv_key = dh->priv_key;
283
}
284
285
#endif
286
232
tr_dh_ctx_t
287
tr_dh_ctx_t
233
tr_dh_new (const uint8_t * prime_num,
288
tr_dh_new (const uint8_t * prime_num,
234
           size_t          prime_num_length,
289
           size_t          prime_num_length,
Lines 236-248 tr_dh_new (const uint8_t * prime_num, Link Here
236
           size_t          generator_num_length)
291
           size_t          generator_num_length)
237
{
292
{
238
  DH * handle = DH_new ();
293
  DH * handle = DH_new ();
294
  BIGNUM * p, * g;
239
295
240
  assert (prime_num != NULL);
296
  assert (prime_num != NULL);
241
  assert (generator_num != NULL);
297
  assert (generator_num != NULL);
298
  p = BN_bin2bn (prime_num, prime_num_length, NULL);
299
  g = BN_bin2bn (generator_num, generator_num_length, NULL);
242
300
243
  if (!check_pointer (handle->p = BN_bin2bn (prime_num, prime_num_length, NULL)) ||
301
  if (!check_pointer (p) ||
244
      !check_pointer (handle->g = BN_bin2bn (generator_num, generator_num_length, NULL)))
302
      !check_pointer (g) ||
303
      !DH_set0_pqg (handle, p, NULL, g))
245
    {
304
    {
305
      BN_free (p);
306
      BN_free (g);
246
      DH_free (handle);
307
      DH_free (handle);
247
      handle = NULL;
308
      handle = NULL;
248
    }
309
    }
Lines 267-282 tr_dh_make_key (tr_dh_ctx_t raw_handle, Link Here
267
{
328
{
268
  DH * handle = raw_handle;
329
  DH * handle = raw_handle;
269
  int dh_size, my_public_key_length;
330
  int dh_size, my_public_key_length;
331
  const BIGNUM * hand_pub_key;
270
332
271
  assert (handle != NULL);
333
  assert (handle != NULL);
272
  assert (public_key != NULL);
334
  assert (public_key != NULL);
273
335
274
  handle->length = private_key_length * 8;
336
337
  DH_set_length(handle, private_key_length * 8);
275
338
276
  if (!check_result (DH_generate_key (handle)))
339
  if (!check_result (DH_generate_key (handle)))
277
    return false;
340
    return false;
278
341
279
  my_public_key_length = BN_bn2bin (handle->pub_key, public_key);
342
  DH_get0_key (handle, &hand_pub_key, NULL);
343
344
  my_public_key_length = BN_bn2bin (hand_pub_key, public_key);
280
  dh_size = DH_size (handle);
345
  dh_size = DH_size (handle);
281
346
282
  tr_dh_align_key (public_key, my_public_key_length, dh_size);
347
  tr_dh_align_key (public_key, my_public_key_length, dh_size);
283
--
284
libtransmission/crypto-utils-openssl.c | 60 +++++++++++++++++++---------------
348
libtransmission/crypto-utils-openssl.c | 60 +++++++++++++++++++---------------
285
1 file changed, 33 insertions(+), 27 deletions(-)
349
1 file changed, 33 insertions(+), 27 deletions(-)
(-)a/libtransmission/crypto-utils-openssl.c (-27 / +33 lines)
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);

Return to bug 630692