Skip to content

Commit

Permalink
mirage-crypto-rng-mirage: provide a module type S (to overcome the mi…
Browse files Browse the repository at this point in the history
…rage-random opam package)
  • Loading branch information
hannesm committed Jun 9, 2024
1 parent 448ad35 commit 7df685a
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions rng/mirage/mirage_crypto_rng_mirage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,49 @@
* 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
[generator] and sets up periodic entropy feeding for that rng. This
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

0 comments on commit 7df685a

Please sign in to comment.