Generated by JsDoc Toolkit 2.3.3-beta on Wed Nov 06 2013 17:43:38 GMT+0100 (MEZ)
HTML template: Codeview

Class sjcl.prng

Random number generator
Defined in: random.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
sjcl.prng(defaultParanoia)
Use sjcl.random as a singleton for this class!

This random number generator is a derivative of Ferguson and Schneier's generator Fortuna.

Method Summary
Method Attributes Method Name and Description
 
addEntropy(data, estimatedEntropy, source)
Add entropy to the pools.
 
addEventListener(name, callback)
add an event listener for progress or seeded-ness.
 
getProgress(paranoia)
Get the generator's progress toward readiness, as a fraction
 
isReady(paranoia)
Is the generator ready?
 
randomWords(nwords, paranoia)
Generate several random words, and return them in an array.
 
remove an event listener for progress or seeded-ness
 
start the built-in entropy collectors
 
stop the built-in entropy collectors
Class Detail
sjcl.prng(defaultParanoia)
Use sjcl.random as a singleton for this class!

This random number generator is a derivative of Ferguson and Schneier's generator Fortuna. It collects entropy from various events into several pools, implemented by streaming SHA-256 instances. It differs from ordinary Fortuna in a few ways, though.

Most importantly, it has an entropy estimator. This is present because there is a strong conflict here between making the generator available as soon as possible, and making sure that it doesn't "run on empty". In Fortuna, there is a saved state file, and the system is likely to have time to warm up.

Second, because users are unlikely to stay on the page for very long, and to speed startup time, the number of pools increases logarithmically: a new pool is created when the previous one is actually used for a reseed. This gives the same asymptotic guarantees as Fortuna, but gives more entropy to early reseeds.

The entire mechanism here feels pretty klunky. Furthermore, there are several improvements that should be made, including support for dedicated cryptographic functions that may be present in some browsers; state files in local storage; cookies containing randomness; etc. So look for improvements in future versions.

Parameters:
defaultParanoia
Method Detail
addEntropy(data, estimatedEntropy, source)
Add entropy to the pools.
Parameters:
data
The entropic value. Should be a 32-bit integer, array of 32-bit integers, or string
{Number} estimatedEntropy
The estimated entropy of data, in bits
{String} source
The source of the entropy, eg "mouse"
addEventListener(name, callback)
add an event listener for progress or seeded-ness.
Parameters:
name
callback
getProgress(paranoia)
Get the generator's progress toward readiness, as a fraction
Parameters:
paranoia
isReady(paranoia)
Is the generator ready?
Parameters:
paranoia
randomWords(nwords, paranoia)
Generate several random words, and return them in an array. A word consists of 32 bits (4 bytes)
Parameters:
{Number} nwords
The number of words to generate.
paranoia
removeEventListener(name, cb)
remove an event listener for progress or seeded-ness
Parameters:
name
cb
startCollectors()
start the built-in entropy collectors
stopCollectors()
stop the built-in entropy collectors