Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

random.h File Reference
#include <crypto/chacha20.h>
#include <crypto/common.h>
#include <uint256.h>
#include <chrono>
#include <cstdint>
+ Include dependency graph for random.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  FastRandomContext
 Fast randomness source. More...
 

Functions

void RandAddSeed ()
 
void GetRandBytes (unsigned char *buf, int num)
 Functions to gather random data via the OpenSSL PRNG. 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)
 
void RandAddSeedSleep ()
 Add a little bit of randomness to the output of GetStrongRangBytes. More...
 
void GetStrongRandBytes (unsigned char *buf, int num)
 Function to gather random data from multiple sources, failing whenever any of those source fail to provide a result. More...
 
void GetOSRand (unsigned char *ent32)
 Get 32 bytes of system entropy. More...
 
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 const int NUM_OS_RANDOM_BYTES = 32
 

Function Documentation

◆ GetOSRand()

void GetOSRand ( unsigned char *  ent32)

Get 32 bytes of system entropy.

Do not use this in application code: use GetStrongRandBytes instead.

Definition at line 202 of file random.cpp.

References ARRAYLEN, GetDevURandom(), name, NUM_OS_RANDOM_BYTES, and RandFailure().

Referenced by GetStrongRandBytes(), and Random_SanityCheck().

◆ GetRand()

◆ 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 
)

◆ GetRandHash()

◆ GetRandInt()

◆ GetRandMicros()

std::chrono::microseconds GetRandMicros ( std::chrono::microseconds  duration_max)
noexcept

Definition at line 374 of file random.cpp.

References GetRand().

Referenced by GetObjectRandomDelay(), and PeerLogicValidation::SendMessages().

◆ GetStrongRandBytes()

void GetStrongRandBytes ( unsigned char *  buf,
int  num 
)

◆ RandAddSeed()

void RandAddSeed ( )

Definition at line 130 of file random.cpp.

References GetPerformanceCounter(), and memory_cleanse().

Referenced by CInit::CInit(), and RandAddSeedPerfmon().

◆ 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().

◆ 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().

Variable Documentation

◆ NUM_OS_RANDOM_BYTES

const int NUM_OS_RANDOM_BYTES = 32
static

Definition at line 143 of file random.h.

Referenced by GetDevURandom(), GetOSRand(), and Random_SanityCheck().

Released under the MIT license