Changeset View
Changeset View
Standalone View
Standalone View
src/random.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "random.h" | #include <random.h> | ||||
#include "crypto/sha512.h" | |||||
#include "support/cleanse.h" | |||||
#ifdef WIN32 | #ifdef WIN32 | ||||
#include "compat.h" // for Windows API | #include <compat.h> // for Windows API | ||||
#include <wincrypt.h> | #include <wincrypt.h> | ||||
#endif | #endif | ||||
#include "logging.h" // for LogPrint() | #include <crypto/sha512.h> | ||||
#include "sync.h" // for WAIT_LOCK | #include <logging.h> // for LogPrint() | ||||
#include "utiltime.h" // for GetTime() | #include <support/cleanse.h> | ||||
#include <sync.h> // for WAIT_LOCK | |||||
#include <utiltime.h> // for GetTime() | |||||
#include <openssl/err.h> | |||||
#include <openssl/rand.h> | |||||
#include <chrono> | #include <chrono> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <limits> | #include <limits> | ||||
#include <mutex> | |||||
#include <thread> | #include <thread> | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#endif | #endif | ||||
#ifdef HAVE_SYS_GETRANDOM | #ifdef HAVE_SYS_GETRANDOM | ||||
#include <linux/random.h> | #include <linux/random.h> | ||||
#include <sys/syscall.h> | #include <sys/syscall.h> | ||||
#endif | #endif | ||||
#if defined(HAVE_GETENTROPY) || \ | #if defined(HAVE_GETENTROPY) || \ | ||||
(defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)) | (defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)) | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#endif | #endif | ||||
#if defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) | #if defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) | ||||
#include <sys/random.h> | #include <sys/random.h> | ||||
#endif | #endif | ||||
#ifdef HAVE_SYSCTL_ARND | #ifdef HAVE_SYSCTL_ARND | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <utilstrencodings.h> // for ARRAYLEN | #include <utilstrencodings.h> // for ARRAYLEN | ||||
#endif | #endif | ||||
#include <mutex> | |||||
#if defined(__x86_64__) || defined(__amd64__) || defined(__i386__) | #if defined(__x86_64__) || defined(__amd64__) || defined(__i386__) | ||||
#include <cpuid.h> | #include <cpuid.h> | ||||
#endif | #endif | ||||
#include <openssl/err.h> | |||||
#include <openssl/rand.h> | |||||
[[noreturn]] static void RandFailure() { | [[noreturn]] static void RandFailure() { | ||||
LogPrintf("Failed to read randomness, aborting\n"); | LogPrintf("Failed to read randomness, aborting\n"); | ||||
std::abort(); | std::abort(); | ||||
} | } | ||||
static inline int64_t GetPerformanceCounter() { | static inline int64_t GetPerformanceCounter() { | ||||
// Read the hardware time stamp counter when available. | // Read the hardware time stamp counter when available. | ||||
// See https://en.wikipedia.org/wiki/Time_Stamp_Counter for more information. | // See https://en.wikipedia.org/wiki/Time_Stamp_Counter for more information. | ||||
▲ Show 20 Lines • Show All 425 Lines • Show Last 20 Lines |