class Prng

Defined at line 28 of file ../../zircon/kernel/lib/crypto/include/lib/crypto/prng.h

This exposes a (optionally-)thread-safe cryptographically secure PRNG.

This PRNG must be seeded with at least 256 bits of "real" entropy before

being used for cryptographic applications.

Public Members

static const uint64_t kMinEntropy
static const uint64_t kMaxEntropy
static const uint64_t kMaxDrawLen

Public Methods

void Prng (const void * data, size_t size)

Construct a thread-safe instance of the PRNG with the byte array at

|data| as the initial seed. |size| is the length of |data| in bytes.

Defined at line 35 of file ../../zircon/kernel/lib/crypto/prng.cc

void Prng (EntropyPool pool)

Construct a thread-safe instance of the PRNG with the input pool. The pool provides must

provide at least 256 bits of entropy.

Defined at line 35 of file ../../zircon/kernel/lib/crypto/include/lib/crypto/prng.h

void Prng (const void * data, size_t size, NonThreadSafeTag )

Construct a non-thread-safe instance of the PRNG with the byte array at

|data| as the initial seed. |size| is the length of |data| in bytes.

Defined at line 39 of file ../../zircon/kernel/lib/crypto/prng.cc

void ~Prng ()

Defined at line 43 of file ../../zircon/kernel/lib/crypto/prng.cc

void AddEntropy (const void * data, size_t size)

Re-seed the PRNG by mixing-in new entropy. |size| is in bytes.

|size| MUST NOT be greater than kMaxEntropy.

If size is 0, only hash of the current key is used to re-seed.

Defined at line 48 of file ../../zircon/kernel/lib/crypto/prng.cc

void SelfReseed ()

AddEntropy() with NULL input effectively reseeds with hash of current key.

Defined at line 75 of file ../../zircon/kernel/lib/crypto/prng.cc

void Draw (void * out, size_t size)

Get pseudo-random output of |size| bytes. Blocks until at least

kMinEntropy bytes of entropy have been added to this PRNG. |size| MUST

NOT be greater than kMaxDrawLen. Identical PRNGs are only guaranteed to

produce identical output when given identical inputs.

Defined at line 77 of file ../../zircon/kernel/lib/crypto/prng.cc

uint64_t RandInt (uint64_t exclusive_upper_bound)

Return an integer in the range [0, exclusive_upper_bound) chosen

uniformly at random. This is a wrapper for Draw(), and so has the same

caveats.

Defined at line 105 of file ../../zircon/kernel/lib/crypto/prng.cc

void BecomeThreadSafe ()

It is safe to call this function from PRNG's constructor provided

|ready_| and |accumulated_| initialized.

Defined at line 128 of file ../../zircon/kernel/lib/crypto/prng.cc

bool is_thread_safe ()

Inspect if this PRNG is thread-safe.

Defined at line 134 of file ../../zircon/kernel/lib/crypto/prng.cc

Records