Changeset View
Changeset View
Standalone View
Standalone View
src/random.cpp
Show First 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void LockingCallbackOpenSSL(int mode, int i, const char *file, int line); | void LockingCallbackOpenSSL(int mode, int i, const char *file, int line); | ||||
namespace { | namespace { | ||||
class RNGState { | class RNGState { | ||||
Mutex m_mutex; | Mutex m_mutex; | ||||
/** | |||||
* The RNG state consists of 256 bits of entropy, taken from the output of | |||||
* one operation's SHA512 output, and fed as input to the next one. | |||||
* Carrying 256 bits of entropy should be sufficient to guarantee | |||||
* unpredictability as long as any entropy source was ever unpredictable | |||||
* to an attacker. To protect against situations where an attacker might | |||||
* observe the RNG's state, fresh entropy is always mixed when | |||||
* GetStrongRandBytes is called. | |||||
*/ | |||||
uint8_t m_state[32] GUARDED_BY(m_mutex) = {0}; | uint8_t 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: | public: | ||||
RNGState() noexcept { | RNGState() noexcept { | ||||
InitHardwareRand(); | InitHardwareRand(); | ||||
▲ Show 20 Lines • Show All 360 Lines • Show Last 20 Lines |