diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2019-01-10 18:19:50 -0800 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2019-01-16 16:34:57 -0800 |
commit | cddb31bb0a132afa50b5350196cf26f0064fe3e2 (patch) | |
tree | 216523d5bfa9047b8955396fa056876b0d0762ac | |
parent | 152146e782d401aa1ce7d989d62306aabc85f22e (diff) |
Encapsulate RNGState better
-rw-r--r-- | src/random.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/random.cpp b/src/random.cpp index f52b5837aa..fe5341ba5f 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -278,13 +278,14 @@ void LockingCallbackOpenSSL(int mode, int i, const char* file, int line); namespace { -struct RNGState { +class RNGState { Mutex m_mutex; unsigned char m_state[32] GUARDED_BY(m_mutex) = {0}; uint64_t m_counter GUARDED_BY(m_mutex) = 0; bool m_strongly_seeded GUARDED_BY(m_mutex) = false; std::unique_ptr<Mutex[]> m_mutex_openssl; +public: RNGState() noexcept { InitHardwareRand(); @@ -342,6 +343,8 @@ struct RNGState { memory_cleanse(buf, 64); return ret; } + + Mutex& GetOpenSSLMutex(int i) { return m_mutex_openssl[i]; } }; RNGState& GetRNGState() noexcept @@ -358,9 +361,9 @@ void LockingCallbackOpenSSL(int mode, int i, const char* file, int line) NO_THRE RNGState& rng = GetRNGState(); if (mode & CRYPTO_LOCK) { - rng.m_mutex_openssl[i].lock(); + rng.GetOpenSSLMutex(i).lock(); } else { - rng.m_mutex_openssl[i].unlock(); + rng.GetOpenSSLMutex(i).unlock(); } } |