Changeset View
Changeset View
Standalone View
Standalone View
src/random.cpp
Show All 11 Lines | |||||
#include <compat/cpuid.h> | #include <compat/cpuid.h> | ||||
#include <crypto/sha256.h> | #include <crypto/sha256.h> | ||||
#include <crypto/sha512.h> | #include <crypto/sha512.h> | ||||
#include <logging.h> // for LogPrintf() | #include <logging.h> // for LogPrintf() | ||||
#include <randomenv.h> | #include <randomenv.h> | ||||
#include <support/allocators/secure.h> | #include <support/allocators/secure.h> | ||||
#include <support/cleanse.h> | #include <support/cleanse.h> | ||||
#include <sync.h> // for Mutex | #include <sync.h> // for Mutex | ||||
#include <util/time.h> // for GetTime() | #include <util/time.h> // for GetTimeMicros() | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <memory> | #include <memory> | ||||
#include <thread> | #include <thread> | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <sys/time.h> | #include <sys/time.h> | ||||
▲ Show 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | #elif defined(HAVE_GETENTROPY) && defined(__OpenBSD__) | ||||
* The call cannot return less than the requested number of bytes. | * The call cannot return less than the requested number of bytes. | ||||
* getentropy is explicitly limited to openbsd here, as a similar (but not | * getentropy is explicitly limited to openbsd here, as a similar (but not | ||||
* the same) function may exist on other platforms via glibc. | * the same) function may exist on other platforms via glibc. | ||||
*/ | */ | ||||
if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { | if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { | ||||
RandFailure(); | RandFailure(); | ||||
} | } | ||||
#elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) | #elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) | ||||
// We need a fallback for OSX < 10.12 | /** | ||||
if (&getentropy != nullptr) { | * getentropy() is available on macOS 10.12 and later. | ||||
*/ | |||||
if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { | if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { | ||||
RandFailure(); | RandFailure(); | ||||
} | } | ||||
} else { | |||||
GetDevURandom(ent32); | |||||
} | |||||
#elif defined(HAVE_SYSCTL_ARND) | #elif defined(HAVE_SYSCTL_ARND) | ||||
/** | /** | ||||
* FreeBSD and similar. It is possible for the call to return less bytes | * FreeBSD and similar. It is possible for the call to return less bytes | ||||
* than requested, so need to read in a loop. | * than requested, so need to read in a loop. | ||||
*/ | */ | ||||
static const int name[2] = {CTL_KERN, KERN_ARND}; | static const int name[2] = {CTL_KERN, KERN_ARND}; | ||||
int have = 0; | int have = 0; | ||||
do { | do { | ||||
▲ Show 20 Lines • Show All 414 Lines • Show Last 20 Lines |