BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
CryptRand Class Reference
Collaboration diagram for CryptRand:

Public Member Functions

 __construct (array $randomFuncs, array $randomFiles, LoggerInterface $logger)
 
 wasStrong ()
 
 generate ($bytes, $forceStrong=false)
 
 generateHex ($chars, $forceStrong=false)
 

Public Attributes

const MIN_ITERATIONS = 1000
 
const MSEC_PER_BYTE = 0.5
 

Protected Member Functions

 initialRandomState ()
 
 driftHash ($data)
 
 randomState ()
 

Protected Attributes

 $strong = null
 
 $randomFuncs = []
 
 $randomFiles = []
 
 $logger
 

Member Function Documentation

CryptRand::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
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.

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

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
CryptRand::initialRandomState ( )
protected

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

Returns
string
CryptRand::randomState ( )
protected

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

Returns
string A new weak random state
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.

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

Member Data Documentation

CryptRand::$strong = null
protected

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

const CryptRand::MIN_ITERATIONS = 1000

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

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.


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