Usage notes
Interface
A generator (PRNG) with its state.
exception Unseeded_generator
Thrown when using an uninitialized generator.
exception No_default_generator
Thrown when set_generator
has not been called.
Entropy sources and collection
type 'a generator = (module Generator with type g = 'a)
HMAC_DRBG: A NIST-specified RNG based on HMAC construction over the provided hash.
val create : ?g:'a -> ?seed:Cstruct.t -> ?strict:bool -> ?time:(unit -> int64) -> (module Generator with type g = 'a) -> g
create ~g ~seed ~strict ~time module
uses a module conforming to the Generator signature to instantiate the generic generator g.
g
is the state to use, otherwise a fresh one is created.
seed
can be provided to immediately reseed the generator with.
strict
puts the generator into a more standards-conformant, but slighty slower mode. Useful if the outputs need to match published test-vectors.
time
is used to limit the amount of reseedings. Fortuna uses at most once every second.
val default_generator : unit -> g
default_generator ()
is the default generator. Functions in this module use this generator when not explicitly supplied one.
- raises No_default_generator
if set_generator
has not been called.
val set_default_generator : g -> unit
set_default_generator g
sets the default generator to g
. This function must be called once.
val block : g option -> int
Examples