Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
#include <random.h>
#include <crypto/sha512.h>
#include <support/cleanse.h>
#include <util.h>
#include <utilstrencodings.h>
#include <stdlib.h>
#include <limits>
#include <chrono>
#include <thread>
#include <sys/time.h>
#include <mutex>
#include <openssl/err.h>
#include <openssl/rand.h>
Go to the source code of this file.
Functions | |
static void | RandFailure () |
static int64_t | GetPerformanceCounter () |
static void | RDRandInit () |
static bool | GetHWRand (unsigned char *ent32) |
void | RandAddSeed () |
static void | RandAddSeedPerfmon () |
void | GetDevURandom (unsigned char *ent32) |
Fallback: get 32 bytes of system entropy from /dev/urandom. More... | |
void | GetOSRand (unsigned char *ent32) |
Get 32 bytes of system entropy. More... | |
void | GetRandBytes (unsigned char *buf, int num) |
Functions to gather random data via the OpenSSL PRNG. More... | |
static void | AddDataToRng (void *data, size_t len) |
void | RandAddSeedSleep () |
Add a little bit of randomness to the output of GetStrongRangBytes. More... | |
void | GetStrongRandBytes (unsigned char *out, int num) |
Function to gather random data from multiple sources, failing whenever any of those source fail to provide a result. More... | |
uint64_t | GetRand (uint64_t nMax) |
std::chrono::microseconds | GetRandMicros (std::chrono::microseconds duration_max) noexcept |
int | GetRandInt (int nMax) |
uint256 | GetRandHash () |
bool | GetRandBool (double rate) |
bool | Random_SanityCheck () |
Check that OS randomness is available and returning the requested number of bytes. More... | |
void | RandomInit () |
Initialize the RNG. More... | |
Variables | |
static std::mutex | cs_rng_state |
static unsigned char | rng_state [32] = {0} |
static uint64_t | rng_counter = 0 |
bool | g_mock_deterministic_tests {false} |
Function Documentation
◆ AddDataToRng()
|
static |
Definition at line 301 of file random.cpp.
References cs_rng_state, CSHA512::Finalize(), memcpy(), memory_cleanse(), rng_counter, rng_state, and CSHA512::Write().
Referenced by RandAddSeedSleep().
◆ GetDevURandom()
void GetDevURandom | ( | unsigned char * | ent32 | ) |
Fallback: get 32 bytes of system entropy from /dev/urandom.
The most compatible way to get cryptographic randomness on UNIX-ish platforms.
Definition at line 182 of file random.cpp.
References NUM_OS_RANDOM_BYTES, and RandFailure().
Referenced by GetOSRand().
◆ GetHWRand()
|
static |
Definition at line 93 of file random.cpp.
References WriteLE32(), and WriteLE64().
Referenced by GetStrongRandBytes().
◆ GetOSRand()
void GetOSRand | ( | unsigned char * | ent32 | ) |
Get 32 bytes of system entropy.
Definition at line 202 of file random.cpp.
References ARRAYLEN, GetDevURandom(), name, NUM_OS_RANDOM_BYTES, and RandFailure().
Referenced by GetStrongRandBytes(), and Random_SanityCheck().
◆ GetPerformanceCounter()
|
inlinestatic |
Definition at line 55 of file random.cpp.
Referenced by RandAddSeed(), RandAddSeedSleep(), and Random_SanityCheck().
◆ GetRand()
uint64_t GetRand | ( | uint64_t | nMax | ) |
Definition at line 354 of file random.cpp.
References g_mock_deterministic_tests, GetRandBytes(), and FastRandomContext::randrange().
Referenced by AdvertiseLocal(), AppInitMain(), CTxMemPool::check(), CConnman::ConnectNode(), convertSeed6(), GetRandBool(), GetRandInt(), GetRandMicros(), PoissonNextSend(), ProcessMessage(), CWallet::ResendWalletTransactions(), CRollingBloomFilter::reset(), and CConnman::ThreadDNSAddressSeed().
◆ GetRandBool()
bool GetRandBool | ( | double | rate | ) |
Definition at line 391 of file random.cpp.
References GetRand().
Referenced by llmq::ShouldSimulateError().
◆ GetRandBytes()
void GetRandBytes | ( | unsigned char * | buf, |
int | num | ||
) |
Functions to gather random data via the OpenSSL PRNG.
Definition at line 273 of file random.cpp.
References RandFailure().
Referenced by BOOST_AUTO_TEST_CASE(), CDBWrapper::CreateObfuscateKey(), ECC_Start(), GenerateAuthCookie(), GetRand(), GetRandHash(), GetStrongRandBytes(), TorController::protocolinfo_cb(), PeerLogicValidation::SendMessages(), and CKey::VerifyPubKey().
◆ GetRandHash()
uint256 GetRandHash | ( | ) |
Definition at line 384 of file random.cpp.
References GetRandBytes().
Referenced by AddTx(), BLSSign_Normal(), BOOST_AUTO_TEST_CASE(), BuildTestVectors(), llmq::CLLMQUtils::CalcDeterministicWatchConnections(), CAddrMan::Clear(), CWallet::InitPrivateSendSalt(), LimitOrphanTxSize(), and FastRandomContext::RandomSeed().
◆ GetRandInt()
int GetRandInt | ( | int | nMax | ) |
Definition at line 379 of file random.cpp.
References GetRand().
Referenced by DKG::Bench_VerifyContributionShares(), BLSVerify_LargeAggregatedBlock1000PreVerified(), CPrivateSendServer::ChargeFees(), CPrivateSendServer::ChargeRandomFees(), CPrivateSendServer::CreateNewSession(), CWallet::CreateTransaction(), CPrivateSendClientManager::DoMaintenance(), CWallet::GetCollateralTxDSIn(), CPrivateSendClientSession::PrepareDenominate(), CAddrMan::RandomInt(), CGovernanceManager::RequestGovernanceObject(), CWallet::SelectCoinsMinConf(), CWallet::SelectPSInOutPairsByDenominations(), llmq::CDKGSession::SendCommitment(), CPrivateSendClientSession::StartNewQueue(), CConnman::ThreadOpenConnections(), and CConnman::ThreadOpenMasternodeConnections().
◆ GetRandMicros()
|
noexcept |
Definition at line 374 of file random.cpp.
References GetRand().
Referenced by GetObjectRandomDelay(), and PeerLogicValidation::SendMessages().
◆ GetStrongRandBytes()
void GetStrongRandBytes | ( | unsigned char * | out, |
int | num | ||
) |
Function to gather random data from multiple sources, failing whenever any of those source fail to provide a result.
Definition at line 317 of file random.cpp.
References cs_rng_state, CSHA512::Finalize(), GetHWRand(), GetOSRand(), GetRandBytes(), memcpy(), memory_cleanse(), RandAddSeedPerfmon(), rng_counter, rng_state, and CSHA512::Write().
Referenced by CBLSIESEncryptedBlob::Encrypt(), CWallet::EncryptWallet(), CMnemonic::Generate(), CKeePassIntegrator::generateRandomKey(), CBLSIESMultiRecipientBlobs::InitEncrypt(), CKey::MakeNewKey(), and CBLSSecretKey::MakeNewKey().
◆ RandAddSeed()
void RandAddSeed | ( | ) |
Definition at line 130 of file random.cpp.
References GetPerformanceCounter(), and memory_cleanse().
Referenced by CInit::CInit(), and RandAddSeedPerfmon().
◆ RandAddSeedPerfmon()
|
static |
Definition at line 138 of file random.cpp.
References GetTime(), LogPrint, LogPrintf, memory_cleanse(), RandAddSeed(), and BCLog::RANDOM.
Referenced by GetStrongRandBytes().
◆ RandAddSeedSleep()
void RandAddSeedSleep | ( | ) |
Add a little bit of randomness to the output of GetStrongRangBytes.
This sleeps for a millisecond, so should only be called when there is no other work to be done.
Definition at line 282 of file random.cpp.
References AddDataToRng(), GetPerformanceCounter(), and memory_cleanse().
Referenced by CScheduler::serviceQueue().
◆ RandFailure()
|
static |
Definition at line 49 of file random.cpp.
References LogPrintf.
Referenced by GetDevURandom(), GetOSRand(), and GetRandBytes().
◆ Random_SanityCheck()
bool Random_SanityCheck | ( | ) |
Check that OS randomness is available and returning the requested number of bytes.
Definition at line 434 of file random.cpp.
References GetOSRand(), GetPerformanceCounter(), NUM_OS_RANDOM_BYTES, and stop().
Referenced by InitSanityCheck().
◆ RandomInit()
void RandomInit | ( | ) |
Initialize the RNG.
Definition at line 487 of file random.cpp.
References RDRandInit().
Referenced by AppInitSanityChecks(), and main().
◆ RDRandInit()
|
static |
Definition at line 90 of file random.cpp.
Referenced by RandomInit().
Variable Documentation
◆ cs_rng_state
|
static |
Definition at line 297 of file random.cpp.
Referenced by AddDataToRng(), and GetStrongRandBytes().
◆ g_mock_deterministic_tests
bool g_mock_deterministic_tests {false} |
Definition at line 352 of file random.cpp.
Referenced by GetRand().
◆ rng_counter
|
static |
Definition at line 299 of file random.cpp.
Referenced by AddDataToRng(), and GetStrongRandBytes().
◆ rng_state
|
static |
Definition at line 298 of file random.cpp.
Referenced by AddDataToRng(), and GetStrongRandBytes().