MediaWiki REL1_31
|
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. | |
generateHex ( $chars, $forceStrong=false) | |
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format. | |
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. | |
Public Attributes | |
const | MIN_ITERATIONS = 1000 |
Minimum number of iterations we want to make in our drift calculations. | |
const | MSEC_PER_BYTE = 0.5 |
Number of milliseconds we want to spend generating each separate byte of the final generated bytes. | |
Protected Member Functions | |
driftHash ( $data) | |
Randomly hash data while mixing in clock drift data for randomness. | |
initialRandomState () | |
Initialize an initial random state based off of whatever we can find. | |
randomState () | |
Return a rolling random state initially build using data from unstable sources. | |
Protected Attributes | |
LoggerInterface | $logger |
string[] | $randomFiles = [] |
List of files to generate some random state from. | |
callable[] | $randomFuncs = [] |
List of functions to call to generate some random state. | |
$strong = null | |
A boolean indicating whether the previous random generation was done using cryptographically strong random number generator or not. | |
Definition at line 28 of file CryptRand.php.
CryptRand::__construct | ( | array | $randomFuncs, |
array | $randomFiles, | ||
LoggerInterface | $logger ) |
Definition at line 67 of file CryptRand.php.
|
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(), and MWCryptHash\hashLength().
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 384 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, 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.
|
protected |
Definition at line 65 of file CryptRand.php.
|
protected |
List of files to generate some random state from.
Definition at line 60 of file CryptRand.php.
|
protected |
List of functions to call to generate some random state.
Definition at line 53 of file CryptRand.php.
|
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.
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.
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.