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> | ||||
#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 <crypto/sha512.h> | #include <crypto/sha512.h> | ||||
#include <logging.h> // for LogPrint() | #include <logging.h> // for LogPrintf() | ||||
#include <support/allocators/secure.h> | #include <support/allocators/secure.h> | ||||
#include <support/cleanse.h> | #include <support/cleanse.h> | ||||
#include <sync.h> // for WAIT_LOCK | #include <sync.h> // for Mutex | ||||
#include <util/time.h> // for GetTime() | #include <util/time.h> // for GetTime() | ||||
#include <openssl/conf.h> | #include <openssl/conf.h> | ||||
#include <openssl/err.h> | #include <openssl/err.h> | ||||
#include <openssl/rand.h> | #include <openssl/rand.h> | ||||
#include <chrono> | #include <chrono> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
▲ Show 20 Lines • Show All 746 Lines • ▼ Show 20 Lines | FastRandomContext::FastRandomContext(const uint256 &seed) noexcept | ||||
rng.SetKey(seed.begin(), 32); | rng.SetKey(seed.begin(), 32); | ||||
} | } | ||||
bool Random_SanityCheck() { | bool Random_SanityCheck() { | ||||
uint64_t start = GetPerformanceCounter(); | uint64_t start = GetPerformanceCounter(); | ||||
/** | /** | ||||
* This does not measure the quality of randomness, but it does test that | * This does not measure the quality of randomness, but it does test that | ||||
* OSRandom() overwrites all 32 bytes of the output given a maximum number | * GetOSRand() overwrites all 32 bytes of the output given a maximum number | ||||
* of tries. | * of tries. | ||||
*/ | */ | ||||
static const ssize_t MAX_TRIES = 1024; | static const ssize_t MAX_TRIES = 1024; | ||||
uint8_t data[NUM_OS_RANDOM_BYTES]; | uint8_t data[NUM_OS_RANDOM_BYTES]; | ||||
/* Tracks which bytes have been overwritten at least once */ | /* Tracks which bytes have been overwritten at least once */ | ||||
bool overwritten[NUM_OS_RANDOM_BYTES] = {}; | bool overwritten[NUM_OS_RANDOM_BYTES] = {}; | ||||
int num_overwritten; | int num_overwritten; | ||||
int tries = 0; | int tries = 0; | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |