Encapsulate RNGState better
This commit is contained in:
parent
152146e782
commit
cddb31bb0a
1 changed files with 6 additions and 3 deletions
|
@ -278,13 +278,14 @@ void LockingCallbackOpenSSL(int mode, int i, const char* file, int line);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct RNGState {
|
class RNGState {
|
||||||
Mutex m_mutex;
|
Mutex m_mutex;
|
||||||
unsigned char m_state[32] GUARDED_BY(m_mutex) = {0};
|
unsigned char m_state[32] GUARDED_BY(m_mutex) = {0};
|
||||||
uint64_t m_counter GUARDED_BY(m_mutex) = 0;
|
uint64_t m_counter GUARDED_BY(m_mutex) = 0;
|
||||||
bool m_strongly_seeded GUARDED_BY(m_mutex) = false;
|
bool m_strongly_seeded GUARDED_BY(m_mutex) = false;
|
||||||
std::unique_ptr<Mutex[]> m_mutex_openssl;
|
std::unique_ptr<Mutex[]> m_mutex_openssl;
|
||||||
|
|
||||||
|
public:
|
||||||
RNGState() noexcept
|
RNGState() noexcept
|
||||||
{
|
{
|
||||||
InitHardwareRand();
|
InitHardwareRand();
|
||||||
|
@ -342,6 +343,8 @@ struct RNGState {
|
||||||
memory_cleanse(buf, 64);
|
memory_cleanse(buf, 64);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mutex& GetOpenSSLMutex(int i) { return m_mutex_openssl[i]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
RNGState& GetRNGState() noexcept
|
RNGState& GetRNGState() noexcept
|
||||||
|
@ -358,9 +361,9 @@ void LockingCallbackOpenSSL(int mode, int i, const char* file, int line) NO_THRE
|
||||||
RNGState& rng = GetRNGState();
|
RNGState& rng = GetRNGState();
|
||||||
|
|
||||||
if (mode & CRYPTO_LOCK) {
|
if (mode & CRYPTO_LOCK) {
|
||||||
rng.m_mutex_openssl[i].lock();
|
rng.GetOpenSSLMutex(i).lock();
|
||||||
} else {
|
} else {
|
||||||
rng.m_mutex_openssl[i].unlock();
|
rng.GetOpenSSLMutex(i).unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue