MediaWiki
REL1_22
|
Public Member Functions | |
realGenerate ($bytes, $forceStrong=false) | |
realGenerateHex ($chars, $forceStrong=false) | |
realWasStrong () | |
Static Public Member Functions | |
static | generate ($bytes, $forceStrong=false) |
Generate a run of (ideally) cryptographically random data and return it in raw binary form. | |
static | generateHex ($chars, $forceStrong=false) |
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format. | |
static | 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. | |
hash ($data) | |
Generate an acceptably unstable one-way-hash of some text making use of the best hash algorithm that we have available. | |
hashAlgo () | |
Decide on the best acceptable hash algorithm we have available for hash() | |
hashLength () | |
Return the byte-length output of the hash algorithm we are using in self::hash and self::hmac. | |
hmac ($data, $key) | |
Generate an acceptably unstable one-way-hmac of some text making use of the best hash algorithm that we have available. | |
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. | |
Static Protected Member Functions | |
static | singleton () |
Publicly exposed static methods. | |
Protected Attributes | |
$algo = null | |
The hash algorithm being used. | |
$hashLength = null | |
The number of bytes outputted by the hash algorithm. | |
$strong = null | |
A boolean indicating whether the previous random generation was done using cryptographically strong random number generator or not. | |
Static Protected Attributes | |
static | $singleton = null |
Singleton instance for public use. |
Definition at line 27 of file MWCryptRand.php.
MWCryptRand::driftHash | ( | $ | data | ) | [protected] |
Randomly hash data while mixing in clock drift data for randomness.
string | $data | The data to randomly hash. |
Definition at line 155 of file MWCryptRand.php.
References hash(), hashLength(), MIN_ITERATIONS, and wfDebug().
Referenced by randomState().
static MWCryptRand::generate | ( | $ | bytes, |
$ | forceStrong = false |
||
) | [static] |
Generate a run of (ideally) cryptographically random data and return it in raw binary form.
You can use MWCryptRand::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 477 of file MWCryptRand.php.
References singleton().
Referenced by realGenerateHex().
static MWCryptRand::generateHex | ( | $ | chars, |
$ | forceStrong = false |
||
) | [static] |
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format.
You can use MWCryptRand::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 493 of file MWCryptRand.php.
References singleton().
Referenced by UIDGenerator\__construct(), wfFixSessionID(), and wfResetSessionID().
MWCryptRand::hash | ( | $ | data | ) | [protected] |
Generate an acceptably unstable one-way-hash of some text making use of the best hash algorithm that we have available.
$data | string |
Definition at line 262 of file MWCryptRand.php.
References hashAlgo().
Referenced by driftHash(), hashLength(), and randomState().
MWCryptRand::hashAlgo | ( | ) | [protected] |
Decide on the best acceptable hash algorithm we have available for hash()
MWException |
Definition at line 218 of file MWCryptRand.php.
MWCryptRand::hashLength | ( | ) | [protected] |
Return the byte-length output of the hash algorithm we are using in self::hash and self::hmac.
Definition at line 248 of file MWCryptRand.php.
References hash().
Referenced by driftHash().
MWCryptRand::hmac | ( | $ | data, |
$ | key | ||
) | [protected] |
Generate an acceptably unstable one-way-hmac of some text making use of the best hash algorithm that we have available.
$data | string |
$key | string |
Definition at line 274 of file MWCryptRand.php.
References $key, and hashAlgo().
Referenced by realGenerate().
MWCryptRand::initialRandomState | ( | ) | [protected] |
Initialize an initial random state based off of whatever we can find.
Definition at line 66 of file MWCryptRand.php.
References $file, $files, $path, array(), as, global, wfHostname(), wfRestoreWarnings(), wfSuppressWarnings(), and wfWikiID().
Referenced by randomState().
MWCryptRand::randomState | ( | ) | [protected] |
Return a rolling random state initially build using data from unstable sources.
Definition at line 199 of file MWCryptRand.php.
References driftHash(), hash(), and initialRandomState().
Referenced by realGenerate().
MWCryptRand::realGenerate | ( | $ | bytes, |
$ | forceStrong = false |
||
) |
Definition at line 291 of file MWCryptRand.php.
References hmac(), randomState(), wfDebug(), wfGetAllCallers(), wfIsWindows(), wfProfileIn(), wfProfileOut(), wfRestoreWarnings(), and wfSuppressWarnings().
MWCryptRand::realGenerateHex | ( | $ | chars, |
$ | forceStrong = false |
||
) |
Definition at line 281 of file MWCryptRand.php.
static MWCryptRand::singleton | ( | ) | [static, protected] |
Publicly exposed static methods.
Return a singleton instance of MWCryptRand
Definition at line 447 of file MWCryptRand.php.
References $singleton.
Referenced by generate(), generateHex(), and wasStrong().
static MWCryptRand::wasStrong | ( | ) | [static] |
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 461 of file MWCryptRand.php.
References singleton().
MWCryptRand::$algo = null [protected] |
The hash algorithm being used.
Definition at line 50 of file MWCryptRand.php.
MWCryptRand::$hashLength = null [protected] |
The number of bytes outputted by the hash algorithm.
Definition at line 55 of file MWCryptRand.php.
MWCryptRand::$singleton = null [static, protected] |
Singleton instance for public use.
Definition at line 45 of file MWCryptRand.php.
Referenced by singleton().
MWCryptRand::$strong = null [protected] |
A boolean indicating whether the previous random generation was done using cryptographically strong random number generator or not.
Definition at line 61 of file MWCryptRand.php.
const MWCryptRand::MIN_ITERATIONS = 1000 |
Minimum number of iterations we want to make in our drift calculations.
Definition at line 32 of file MWCryptRand.php.
Referenced by driftHash().
const MWCryptRand::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 MWCryptRand.php.