···11-module Main (R : Mirage_random.S) = struct
11+module Main (R : Mirage_crypto_rng_mirage.S) = struct
22 let start _r =
33 Logs.info (fun m -> m "using Fortuna, entropy sources: %a"
44 Fmt.(list ~sep:(any ", ") Mirage_crypto_rng.Entropy.pp_source)
+16
rng/mirage/mirage_crypto_rng_mirage.ml
···2727 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828 *)
29293030+module type S = sig
3131+ type g = Mirage_crypto_rng.g
3232+ module Entropy :
3333+ sig
3434+ type source = Mirage_crypto_rng.Entropy.source
3535+ val sources : unit -> source list
3636+ val pp_source : Format.formatter -> source -> unit
3737+ val register_source : string -> source
3838+ end
3939+4040+ val generate_into : ?g:g -> bytes -> ?off:int -> int -> unit
4141+ val generate : ?g:g -> int -> string
4242+4343+ val accumulate : g option -> Entropy.source -> [`Acc of string -> unit]
4444+end
4545+3046let src = Logs.Src.create "mirage-crypto-rng-mirage" ~doc:"Mirage crypto RNG mirage"
3147module Log = (val Logs.src_log src : Logs.LOG)
3248
+37-2
rng/mirage/mirage_crypto_rng_mirage.mli
···2626 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727 *)
28282929+module type S = sig
3030+ type g = Mirage_crypto_rng.g
3131+ (** A generator (PRNG) with its state. *)
3232+3333+ (** Entropy sources and collection *)
3434+ module Entropy :
3535+ sig
3636+ (** Entropy sources. *)
3737+ type source = Mirage_crypto_rng.Entropy.source
3838+3939+ val sources : unit -> source list
4040+ (** [sources ()] returns the list of available sources. *)
4141+4242+ val pp_source : Format.formatter -> source -> unit
4343+ (** [pp_source ppf source] pretty-prints the entropy [source] on [ppf]. *)
4444+4545+ val register_source : string -> source
4646+ (** [register_source name] registers [name] as entropy source. *)
4747+ end
4848+4949+ val generate_into : ?g:g -> bytes -> ?off:int -> int -> unit
5050+ (** [generate_into ~g buf ~off len] invokes
5151+ {{!Generator.generate_into}generate_into} on [g] or
5252+ {{!generator}default generator}. The random data is put into [buf] starting
5353+ at [off] (defaults to 0) with [len] bytes. *)
5454+5555+ val generate : ?g:g -> int -> string
5656+ (** Invoke {!generate_into} on [g] or {{!generator}default generator} and a
5757+ freshly allocated string. *)
5858+5959+ val accumulate : g option -> Entropy.source -> [`Acc of string -> unit]
6060+ (** [accumulate g source] is a function [data -> unit] to feed entropy to the
6161+ RNG. This is useful if your system has a special entropy source. *)
6262+end
6363+2964module Make (T : Mirage_time.S) (M : Mirage_clock.MCLOCK) : sig
6565+ include S
6666+3067 val initialize :
3168 ?g:'a -> ?sleep:int64 -> 'a Mirage_crypto_rng.generator -> unit Lwt.t
3269 (** [initialize ~g ~sleep generator] sets the default generator to the
···3471 function fails ([Lwt.fail]) if it is called a second time. The argument
3572 [~sleep] is measured in ns, and used as sleep between cpu assisted random
3673 number collection. It defaults to one second. *)
3737-3838- include module type of Mirage_crypto_rng
3974end