123456789_123456789_123456789_123456789_123456789_

Module: OpenSSL::Random

Relationships & Source Files
Namespace Children
Exceptions:
Defined in: ext/openssl/ossl_rand.c

Class Attribute Summary

  • .status? ⇒ Boolean readonly mod_func

    Return true if the PRNG has been seeded with enough data, false otherwise.

Class Method Summary

Class Attribute Details

.status?Boolean (readonly, mod_func)

Return true if the PRNG has been seeded with enough data, false otherwise.

Class Method Details

.egd(filename) ⇒ true (mod_func)

Same as .egd_bytes but queries 255 bytes by default.

.egd_bytes(filename, length) ⇒ true (mod_func)

Queries the entropy gathering daemon EGD on socket path given by filename.

Fetches length number of bytes and uses .add to seed the ::OpenSSL built-in PRNG.

.load_random_file(filename) ⇒ true (mod_func)

Reads bytes from filename and adds them to the PRNG.

.pseudo_bytes(length) ⇒ String (mod_func)

Generates string with length number of pseudo-random bytes.

Pseudo-random byte sequences generated by .pseudo_bytes will be unique if they are of sufficient length, but are not necessarily unpredictable.

Example

OpenSSL::Random.pseudo_bytes(12)
#=> "..."

.add(str, entropy) ⇒ self (mod_func)

Mixes the bytes from str into the Pseudo Random Number Generator(PRNG) state.

Thus, if the data from str are unpredictable to an adversary, this increases the uncertainty about the state and makes the PRNG output less predictable.

The entropy argument is (the lower bound of) an estimate of how much randomness is contained in str, measured in bytes.

Example

pid = $$
now = Time.now
ary = [now.to_i, now.nsec, 1000, pid]
OpenSSL::Random.add(ary.join, 0.0)
OpenSSL::Random.seed(ary.join)

.random_bytes(length) ⇒ String (mod_func)

Generates string with length number of cryptographically strong pseudo-random bytes.

Example

OpenSSL::Random.random_bytes(12)
#=> "..."

.seed(str) ⇒ String (mod_func)

.seed is equivalent to .add where entropy is length of str.

.write_random_file(filename) ⇒ true (mod_func)

Writes a number of random generated bytes (currently 1024) to filename which can be used to initialize the PRNG by calling .load_random_file in a later session.