Skip to content

Commit

Permalink
Allow the nature of the entropy device to be specified in the device
Browse files Browse the repository at this point in the history
We classify this into `Strongest` for the best one, and `Strong`
and `Weak` if one is to be specifically selected.  The default is
`Strongest`, which maps to `/dev/random` on Unix and currently a
weak (but functioning) source on Xen.
  • Loading branch information
avsm committed Jul 6, 2014
1 parent 1be9fba commit b872b93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
23 changes: 17 additions & 6 deletions lib/mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,17 @@ let default_random: random impl =

module Entropy = struct

type t = unit
type t = [ `Strongest | `Strong | `Weak ]

let name _ =
"entropy"

let module_name _ =
match !mode with
| `Unix -> "Entropy_unix"
| `Xen -> "Entropy_xen"
let module_name t =
match !mode, t with
| `Unix, (`Strongest | `Strong) -> "Entropy_unix"
| `Unix, `Weak -> "Entropy_unix_weak"
| `Xen, (`Strongest | `Weak) -> "Entropy_xen_weak"
| `Xen, `Strong -> "Entropy_xen"

let packages _ =
match !mode with
Expand All @@ -464,7 +466,16 @@ type entropy = ENTROPY
let entropy = Type ENTROPY

let default_entropy: entropy impl =
impl entropy () (module Entropy)
impl entropy `Strongest (module Entropy)

let strongest_entropy: entropy impl =
impl entropy `Strongest (module Entropy)

let strong_entropy: entropy impl =
impl entropy `Strong (module Entropy)

let weak_entropy: entropy impl =
impl entropy `Weak (module Entropy)

module Console = struct

Expand Down
9 changes: 8 additions & 1 deletion lib/mirage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,16 @@ val entropy: entropy typ
(** The [V1.ENTROPY] module signature. *)

val default_entropy: entropy impl
(** Passthrough to the OCaml random. *)
(** Pick the strongest entropy source available. *)

val strongest_entropy: entropy impl
(** Pick the strongest entropy source available. *)

val strong_entropy: entropy impl
(** Pick only a strong entropy source, and fail if one is not available. *)

val weak_entropy: entropy impl
(** Pick only a weak entropy source (most likely only for testing). *)

(** {2 Consoles} *)

Expand Down

0 comments on commit b872b93

Please sign in to comment.