diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-05-14 22:08:10 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-05-15 00:05:59 +0100 |
commit | d539be33590f7dfb0013187502744286f2959ee3 (patch) | |
tree | 8964a9107f7171cdbc0f490e581d92918462ed65 /src/crypto/crypto.h | |
parent | Merge pull request #826 (diff) | |
download | monero-d539be33590f7dfb0013187502744286f2959ee3.tar.xz |
crypto: make clear generate_random_bytes is not thread safe
And add a thread safe version to encourage proper use
Diffstat (limited to '')
-rw-r--r-- | src/crypto/crypto.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index 883aa521a..fa55c2aab 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -117,13 +117,20 @@ namespace crypto { const public_key *const *, std::size_t, const signature *); }; + /* Generate N random bytes + */ + inline void rand(size_t N, uint8_t *bytes) { + boost::lock_guard<boost::mutex> lock(random_lock); + generate_random_bytes_not_thread_safe(N, bytes); + } + /* Generate a value filled with random bytes. */ template<typename T> typename std::enable_if<std::is_pod<T>::value, T>::type rand() { typename std::remove_cv<T>::type res; boost::lock_guard<boost::mutex> lock(random_lock); - generate_random_bytes(sizeof(T), &res); + generate_random_bytes_not_thread_safe(sizeof(T), &res); return res; } |