Changeset 33025


Ignore:
Timestamp:
Aug 6, 2017, 4:23:13 PM (2 weeks ago)
Author:
brainslayer
Message:

openssl 1.1 update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/transmission/libtransmission/crypto-utils-openssl.c

    r29221 r33025  
    1616
    1717#include <openssl/bn.h>
     18#include <openssl/crypto.h>
    1819#include <openssl/dh.h>
    1920#include <openssl/err.h>
     
    5051      if (!strings_loaded)
    5152        {
     53#if OPENSSL_VERSION_NUMBER < 0x10100000
    5254          ERR_load_crypto_strings ();
     55#else
     56          OPENSSL_init_crypto (OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
     57#endif
     58
    5359          strings_loaded = true;
    5460        }
     
    231237***/
    232238
     239#if OPENSSL_VERSION_NUMBER < 0x10100000
     240
     241static inline int
     242DH_set0_pqg (DH     * dh,
     243             BIGNUM * p,
     244             BIGNUM * q,
     245             BIGNUM * g)
     246{
     247  /* If the fields p and g in d are NULL, the corresponding input
     248   * parameters MUST be non-NULL. q may remain NULL.
     249   */
     250  if ((dh->p == NULL && p == NULL) || (dh->g == NULL && g == NULL))
     251    return 0;
     252
     253  if (p != NULL)
     254    {
     255      BN_free (dh->p);
     256      dh->p = p;
     257    }
     258  if (q != NULL)
     259    {
     260      BN_free (dh->q);
     261      dh->q = q;
     262    }
     263  if (g != NULL)
     264    {
     265      BN_free (dh->g);
     266      dh->g = g;
     267    }
     268
     269  if (q != NULL)
     270    dh->length = BN_num_bits (q);
     271
     272  return 1;
     273}
     274
     275static inline int
     276DH_set_length (DH   * dh,
     277               long   length)
     278{
     279  dh->length = length;
     280  return 1;
     281}
     282
     283static inline void
     284DH_get0_key(const DH      * dh,
     285            const BIGNUM ** pub_key,
     286            const BIGNUM ** priv_key)
     287{
     288  if (pub_key != NULL)
     289    *pub_key = dh->pub_key;
     290  if (priv_key != NULL)
     291    *priv_key = dh->priv_key;
     292}
     293
     294#endif
     295
    233296tr_dh_ctx_t
    234297tr_dh_new (const uint8_t * prime_num,
     
    238301{
    239302  DH * handle = DH_new ();
     303  BIGNUM * p, * g;
    240304
    241305  assert (prime_num != NULL);
    242306  assert (generator_num != NULL);
    243307
    244   if (!check_pointer (handle->p = BN_bin2bn (prime_num, prime_num_length, NULL)) ||
    245       !check_pointer (handle->g = BN_bin2bn (generator_num, generator_num_length, NULL)))
    246     {
     308  p = BN_bin2bn (prime_num, prime_num_length, NULL);
     309  g = BN_bin2bn (generator_num, generator_num_length, NULL);
     310
     311  if (!check_pointer (p) || !check_pointer (g) || !DH_set0_pqg (handle, p, NULL, g))
     312    {
     313      BN_free (p);
     314      BN_free (g);
    247315      DH_free (handle);
    248316      handle = NULL;
     
    269337  DH * handle = raw_handle;
    270338  int dh_size, my_public_key_length;
     339  const BIGNUM * my_public_key;
    271340
    272341  assert (handle != NULL);
    273342  assert (public_key != NULL);
    274343
    275   handle->length = private_key_length * 8;
     344  DH_set_length(handle, private_key_length * 8);
    276345
    277346  if (!check_result (DH_generate_key (handle)))
    278347    return false;
    279348
    280   my_public_key_length = BN_bn2bin (handle->pub_key, public_key);
     349  DH_get0_key (handle, &my_public_key, NULL);
     350
     351  my_public_key_length = BN_bn2bin (my_public_key, public_key);
    281352  dh_size = DH_size (handle);
    282353
Note: See TracChangeset for help on using the changeset viewer.