upstream: https://github.com/mirage/mirage-crypto

Merge pull request #234 from hannesm/mirage-rng

mirage-crypto-rng-mirage: provide a module type S (to overcome the mirage-random opam package)

authored by

Hannes Mehnert and committed by
GitHub
85e7809e a5fec37e

+54 -3
+1 -1
mirage/unikernel.ml
··· 1 - module Main (R : Mirage_random.S) = struct 1 + module Main (R : Mirage_crypto_rng_mirage.S) = struct 2 2 let start _r = 3 3 Logs.info (fun m -> m "using Fortuna, entropy sources: %a" 4 4 Fmt.(list ~sep:(any ", ") Mirage_crypto_rng.Entropy.pp_source)
+16
rng/mirage/mirage_crypto_rng_mirage.ml
··· 27 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 28 *) 29 29 30 + module type S = sig 31 + type g = Mirage_crypto_rng.g 32 + module Entropy : 33 + sig 34 + type source = Mirage_crypto_rng.Entropy.source 35 + val sources : unit -> source list 36 + val pp_source : Format.formatter -> source -> unit 37 + val register_source : string -> source 38 + end 39 + 40 + val generate_into : ?g:g -> bytes -> ?off:int -> int -> unit 41 + val generate : ?g:g -> int -> string 42 + 43 + val accumulate : g option -> Entropy.source -> [`Acc of string -> unit] 44 + end 45 + 30 46 let src = Logs.Src.create "mirage-crypto-rng-mirage" ~doc:"Mirage crypto RNG mirage" 31 47 module Log = (val Logs.src_log src : Logs.LOG) 32 48
+37 -2
rng/mirage/mirage_crypto_rng_mirage.mli
··· 26 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 *) 28 28 29 + module type S = sig 30 + type g = Mirage_crypto_rng.g 31 + (** A generator (PRNG) with its state. *) 32 + 33 + (** Entropy sources and collection *) 34 + module Entropy : 35 + sig 36 + (** Entropy sources. *) 37 + type source = Mirage_crypto_rng.Entropy.source 38 + 39 + val sources : unit -> source list 40 + (** [sources ()] returns the list of available sources. *) 41 + 42 + val pp_source : Format.formatter -> source -> unit 43 + (** [pp_source ppf source] pretty-prints the entropy [source] on [ppf]. *) 44 + 45 + val register_source : string -> source 46 + (** [register_source name] registers [name] as entropy source. *) 47 + end 48 + 49 + val generate_into : ?g:g -> bytes -> ?off:int -> int -> unit 50 + (** [generate_into ~g buf ~off len] invokes 51 + {{!Generator.generate_into}generate_into} on [g] or 52 + {{!generator}default generator}. The random data is put into [buf] starting 53 + at [off] (defaults to 0) with [len] bytes. *) 54 + 55 + val generate : ?g:g -> int -> string 56 + (** Invoke {!generate_into} on [g] or {{!generator}default generator} and a 57 + freshly allocated string. *) 58 + 59 + val accumulate : g option -> Entropy.source -> [`Acc of string -> unit] 60 + (** [accumulate g source] is a function [data -> unit] to feed entropy to the 61 + RNG. This is useful if your system has a special entropy source. *) 62 + end 63 + 29 64 module Make (T : Mirage_time.S) (M : Mirage_clock.MCLOCK) : sig 65 + include S 66 + 30 67 val initialize : 31 68 ?g:'a -> ?sleep:int64 -> 'a Mirage_crypto_rng.generator -> unit Lwt.t 32 69 (** [initialize ~g ~sleep generator] sets the default generator to the ··· 34 71 function fails ([Lwt.fail]) if it is called a second time. The argument 35 72 [~sleep] is measured in ns, and used as sleep between cpu assisted random 36 73 number collection. It defaults to one second. *) 37 - 38 - include module type of Mirage_crypto_rng 39 74 end