MediaWiki
1.29.1
|
Public Member Functions | |
__construct (array $randomFuncs, array $randomFiles, LoggerInterface $logger) | |
generate ( $bytes, $forceStrong=false) | |
Generate a run of (ideally) cryptographically random data and return it in raw binary form. More... | |
generateHex ( $chars, $forceStrong=false) | |
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format. More... | |
wasStrong () | |
Return a boolean indicating whether or not the source used for cryptographic random bytes generation in the previously run generate* call was cryptographically strong. More... | |
Public Attributes | |
const | MIN_ITERATIONS = 1000 |
Minimum number of iterations we want to make in our drift calculations. More... | |
const | MSEC_PER_BYTE = 0.5 |
Number of milliseconds we want to spend generating each separate byte of the final generated bytes. More... | |
Protected Member Functions | |
driftHash ( $data) | |
Randomly hash data while mixing in clock drift data for randomness. More... | |
initialRandomState () | |
Initialize an initial random state based off of whatever we can find. More... | |
randomState () | |
Return a rolling random state initially build using data from unstable sources. More... | |
Protected Attributes | |
LoggerInterface | $logger |
string[] | $randomFiles = [] |
List of files to generate some random state from. More... | |
callable[] | $randomFuncs = [] |
List of functions to call to generate some random state. More... | |
$strong = null | |
A boolean indicating whether the previous random generation was done using cryptographically strong random number generator or not. More... | |
Definition at line 28 of file CryptRand.php.
Definition at line 67 of file CryptRand.php.
References $logger, $randomFiles, and $randomFuncs.
|
protected |
Randomly hash data while mixing in clock drift data for randomness.
string | $data | The data to randomly hash. |
Definition at line 148 of file CryptRand.php.
References $buffer, MWCryptHash\hash(), MWCryptHash\hashLength(), and MIN_ITERATIONS.
Referenced by randomState().
CryptRand::generate | ( | $bytes, | |
$forceStrong = false |
|||
) |
Generate a run of (ideally) cryptographically random data and return it in raw binary form.
You can use CryptRand::wasStrong() if you wish to know if the source used was cryptographically strong.
int | $bytes | The number of bytes of random data to generate |
bool | $forceStrong | Pass true if you want generate to prefer cryptographically strong sources of entropy even if reading from them may steal more entropy from the system than optimal. |
Definition at line 236 of file CryptRand.php.
References $buffer, MWCryptHash\hmac(), and randomState().
Referenced by generateHex().
CryptRand::generateHex | ( | $chars, | |
$forceStrong = false |
|||
) |
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format.
You can use CryptRand::wasStrong() if you wish to know if the source used was cryptographically strong.
int | $chars | The number of hex chars of random data to generate |
bool | $forceStrong | Pass true if you want generate to prefer cryptographically strong sources of entropy even if reading from them may steal more entropy from the system than optimal. |
Definition at line 388 of file CryptRand.php.
References generate().
|
protected |
Initialize an initial random state based off of whatever we can find.
Definition at line 77 of file CryptRand.php.
References $path, $randomFiles, as, and serialize().
Referenced by randomState().
|
protected |
Return a rolling random state initially build using data from unstable sources.
Definition at line 194 of file CryptRand.php.
References driftHash(), MWCryptHash\hash(), and initialRandomState().
Referenced by generate().
CryptRand::wasStrong | ( | ) |
Return a boolean indicating whether or not the source used for cryptographic random bytes generation in the previously run generate* call was cryptographically strong.
Definition at line 216 of file CryptRand.php.
References $strong.
|
protected |
Definition at line 65 of file CryptRand.php.
Referenced by __construct().
|
protected |
List of files to generate some random state from.
Definition at line 60 of file CryptRand.php.
Referenced by __construct(), and initialRandomState().
|
protected |
List of functions to call to generate some random state.
Definition at line 53 of file CryptRand.php.
Referenced by __construct().
|
protected |
A boolean indicating whether the previous random generation was done using cryptographically strong random number generator or not.
Definition at line 46 of file CryptRand.php.
Referenced by wasStrong().
const CryptRand::MIN_ITERATIONS = 1000 |
Minimum number of iterations we want to make in our drift calculations.
Definition at line 32 of file CryptRand.php.
Referenced by driftHash().
const CryptRand::MSEC_PER_BYTE = 0.5 |
Number of milliseconds we want to spend generating each separate byte of the final generated bytes.
This is used in combination with the hash length to determine the duration we should spend doing drift calculations.
Definition at line 40 of file CryptRand.php.