From 7df685a68c17a90528e899e7efc2416ca3bb0e55 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Sun, 9 Jun 2024 18:14:15 +0200 Subject: [PATCH] mirage-crypto-rng-mirage: provide a module type S (to overcome the mirage-random opam package) --- rng/mirage/mirage_crypto_rng_mirage.mli | 39 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/rng/mirage/mirage_crypto_rng_mirage.mli b/rng/mirage/mirage_crypto_rng_mirage.mli index 7bc83b8f..87b60208 100644 --- a/rng/mirage/mirage_crypto_rng_mirage.mli +++ b/rng/mirage/mirage_crypto_rng_mirage.mli @@ -26,7 +26,44 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *) +module type S = sig + type g = Mirage_crypto_rng.g + (** A generator (PRNG) with its state. *) + + (** Entropy sources and collection *) + module Entropy : + sig + (** Entropy sources. *) + type source = Mirage_crypto_rng.Entropy.source + + val sources : unit -> source list + (** [sources ()] returns the list of available sources. *) + + val pp_source : Format.formatter -> source -> unit + (** [pp_source ppf source] pretty-prints the entropy [source] on [ppf]. *) + + val register_source : string -> source + (** [register_source name] registers [name] as entropy source. *) + + val feed_pools : g option -> source -> (unit -> string) -> unit + (** [feed_pools g source f] feeds all pools of [g] using [source] by executing + [f] for each pool. *) + end + + val generate_into : ?g:g -> bytes -> ?off:int -> int -> unit + (** [generate_into ~g buf ~off len] invokes + {{!Generator.generate_into}generate_into} on [g] or + {{!generator}default generator}. The random data is put into [buf] starting + at [off] (defaults to 0) with [len] bytes. *) + + val generate : ?g:g -> int -> string + (** Invoke {!generate_into} on [g] or {{!generator}default generator} and a + freshly allocated string. *) +end + module Make (T : Mirage_time.S) (M : Mirage_clock.MCLOCK) : sig + include S + val initialize : ?g:'a -> ?sleep:int64 -> 'a Mirage_crypto_rng.generator -> unit Lwt.t (** [initialize ~g ~sleep generator] sets the default generator to the @@ -34,6 +71,4 @@ module Make (T : Mirage_time.S) (M : Mirage_clock.MCLOCK) : sig function fails ([Lwt.fail]) if it is called a second time. The argument [~sleep] is measured in ns, and used as sleep between cpu assisted random number collection. It defaults to one second. *) - - include module type of Mirage_crypto_rng end