Changeset 14440


Ignore:
Timestamp:
Jan 7, 2015, 1:13:19 PM (6 years ago)
Author:
mikedld
Message:

#4400: Access CyaSSL RNG in thread-safe manner

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/crypto-utils-cyassl.c

    r14436 r14440  
    2020#include "crypto-utils.h"
    2121#include "log.h"
     22#include "platform.h"
    2223#include "utils.h"
    2324
     
    9091}
    9192
     93static tr_lock *
     94get_rng_lock (void)
     95{
     96  static tr_lock * lock = NULL;
     97
     98  if (lock == NULL)
     99    lock = tr_lockNew ();
     100
     101  return lock;
     102}
     103
    92104/***
    93105****
     
    232244  struct tr_dh_ctx * handle = raw_handle;
    233245  word32 my_private_key_length, my_public_key_length;
     246  tr_lock * rng_lock = get_rng_lock ();
    234247
    235248  assert (handle != NULL);
     
    238251  if (handle->private_key == NULL)
    239252    handle->private_key = tr_malloc (handle->key_length);
     253
     254  tr_lockLock (rng_lock);
    240255
    241256  if (!check_result (DhGenerateKeyPair (&handle->dh, get_rng (),
    242257                                        handle->private_key, &my_private_key_length,
    243258                                        public_key, &my_public_key_length)))
    244     return false;
     259    {
     260      tr_lockUnlock (rng_lock);
     261      return false;
     262    }
     263
     264  tr_lockUnlock (rng_lock);
    245265
    246266  tr_dh_align_key (public_key, my_public_key_length, handle->key_length);
     
    292312                size_t   length)
    293313{
     314  bool ret;
     315  tr_lock * rng_lock = get_rng_lock ();
     316
    294317  assert (buffer != NULL);
    295318
    296   return check_result (RNG_GenerateBlock (get_rng (), buffer, length));
    297 }
     319  tr_lockLock (rng_lock);
     320  ret = check_result (RNG_GenerateBlock (get_rng (), buffer, length));
     321  tr_lockUnlock (rng_lock);
     322
     323  return ret;
     324}
Note: See TracChangeset for help on using the changeset viewer.