Changeset View
Changeset View
Standalone View
Standalone View
src/random.cpp
Show First 20 Lines • Show All 289 Lines • ▼ Show 20 Lines | static void Strengthen(const uint8_t (&seed)[32], int microseconds, | ||||
inner_hasher.Reset(); | inner_hasher.Reset(); | ||||
memory_cleanse(buffer, sizeof(buffer)); | memory_cleanse(buffer, sizeof(buffer)); | ||||
} | } | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
/** | /** | ||||
* Fallback: get 32 bytes of system entropy from /dev/urandom. The most | * Fallback: get 32 bytes of system entropy from /dev/urandom. The most | ||||
* compatible way to get cryptographic randomness on UNIX-ish platforms. | * compatible way to get cryptographic randomness on UNIX-ish platforms. | ||||
* | |||||
* This function is defined but unused on OpenBSD, MAC_OSX and FreeBSD. | |||||
*/ | */ | ||||
static void GetDevURandom(uint8_t *ent32) { | [[maybe_unused]] static void GetDevURandom(uint8_t *ent32) { | ||||
int f = open("/dev/urandom", O_RDONLY); | int f = open("/dev/urandom", O_RDONLY); | ||||
if (f == -1) { | if (f == -1) { | ||||
RandFailure(); | RandFailure(); | ||||
} | } | ||||
int have = 0; | int have = 0; | ||||
do { | do { | ||||
ssize_t n = read(f, ent32 + have, NUM_OS_RANDOM_BYTES - have); | ssize_t n = read(f, ent32 + have, NUM_OS_RANDOM_BYTES - have); | ||||
if (n <= 0 || n + have > NUM_OS_RANDOM_BYTES) { | if (n <= 0 || n + have > NUM_OS_RANDOM_BYTES) { | ||||
▲ Show 20 Lines • Show All 477 Lines • Show Last 20 Lines |