BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
MWCryptRand Class Reference

Public Member Functions

 realWasStrong ()
 
 realGenerate ($bytes, $forceStrong=false)
 
 realGenerateHex ($chars, $forceStrong=false)
 

Static Public Member Functions

static wasStrong ()
 
static generate ($bytes, $forceStrong=false)
 
static generateHex ($chars, $forceStrong=false)
 

Public Attributes

const MIN_ITERATIONS = 1000
 
const MSEC_PER_BYTE = 0.5
 

Protected Member Functions

 initialRandomState ()
 
 driftHash ($data)
 
 randomState ()
 

Static Protected Member Functions

static singleton ()
 

Protected Attributes

 $strong = null
 

Static Protected Attributes

static $singleton = null
 

Member Function Documentation

MWCryptRand::driftHash (   $data)
protected

Randomly hash data while mixing in clock drift data for randomness

Parameters
string$dataThe data to randomly hash.
Returns
string The hashed bytes
Author
Tim Starling
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.

Parameters
int$bytesThe number of bytes of random data to generate
bool$forceStrongPass 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.
Returns
string Raw binary random data
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.

Parameters
int$charsThe number of hex chars of random data to generate
bool$forceStrongPass 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.
Returns
string Hexadecimal random data
MWCryptRand::initialRandomState ( )
protected

Initialize an initial random state based off of whatever we can find

Returns
string
MWCryptRand::randomState ( )
protected

Return a rolling random state initially build using data from unstable sources

Returns
string A new weak random state
MWCryptRand::realGenerate (   $bytes,
  $forceStrong = false 
)
See Also
self::generate()
MWCryptRand::realGenerateHex (   $chars,
  $forceStrong = false 
)
See Also
self::generateHex()
MWCryptRand::realWasStrong ( )
See Also
self::wasStrong()
static MWCryptRand::singleton ( )
staticprotected

Publicly exposed static methods Return a singleton instance of MWCryptRand

Returns
MWCryptRand
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.

Returns
bool Returns true if the source was strong, false if not.

Member Data Documentation

MWCryptRand::$singleton = null
staticprotected

Singleton instance for public use

MWCryptRand::$strong = null
protected

A boolean indicating whether the previous random generation was done using cryptographically strong random number generator or not.

const MWCryptRand::MIN_ITERATIONS = 1000

Minimum number of iterations we want to make in our drift calculations.

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.


The documentation for this class was generated from the following file: