Skip to content

Commit

Permalink
de-deprecate miou-unix
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Jan 8, 2025
1 parent ef34dc8 commit 688cc6d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
1 change: 0 additions & 1 deletion rng/miou/mirage_crypto_rng_miou_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type rng
(** Type of tasks seeding the RNG. *)

val initialize : ?g:'a -> ?sleep:int64 -> 'a Mirage_crypto_rng.generator -> rng
[@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
(** [initialize ?g ?sleep (module Generator)] will allow the RNG to operate in a
returned task. This task periodically launches sub-tasks that seed the
engine (using [getrandom()], [getentropy()] or [BCryptGenRandom()] depending
Expand Down
12 changes: 12 additions & 0 deletions rng/mirage_crypto_rng.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
Fortuna and producing random numbers is not thread-safe} (it is on Miou_unix
via Pfortuna).
Suitable entropy feeding of generators are provided by other libraries
{{!Mirage_crypto_rng_mirage}mirage-crypto-rng-mirage} (for MirageOS),
and {{!Mirage_crypto_rng_miou_unix}mirage-crypto-miou-unix} (for Miou_unix).
The intention is that "initialize" in the respective sub-library is called
once, which sets the default generator and registers entropy
harvesting asynchronous tasks. The semantics is that the entropy is always
fed to the {{!default_generator}default generator}, which is not necessarily
the one set by "initialize". The reasoning behind this is that the default
generator should be used in most setting, and that should be fed a constant
stream of entropy.
The RNGs here are merely the deterministic part of a full random number
generation suite. For proper operation, they need to be seeded with a
high-quality entropy source.
Expand Down
5 changes: 4 additions & 1 deletion rng/rng.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ let setup_rng =
following:\
\n If you are using MirageOS, use the random device in config.ml: \
`let main = Mirage.main \"Unikernel.Main\" (random @-> job)`, \
and `let () = register \"my_unikernel\" [main $ default_random]`."
and `let () = register \"my_unikernel\" [main $ default_random]`. \
\n If you are using miou, execute \
`Mirage_crypto_rng_miou_unix.initialize (module Mirage_crypto_rng.Fortuna)` \
at startup."

let () = Printexc.register_printer (function
| Unseeded_generator ->
Expand Down
6 changes: 1 addition & 5 deletions tests/test_miou_entropy_collection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ end

let () =
Miou_unix.run @@ fun () ->
let rng =
begin[@alert "-deprecated"]
Mirage_crypto_rng_miou_unix.initialize (module Printing_rng)
end
in
let rng = Mirage_crypto_rng_miou_unix.initialize (module Printing_rng) in
Format.printf "entropy sources: %a@,%!"
(fun ppf -> List.iter (fun x ->
Mirage_crypto_rng.Entropy.pp_source ppf x;
Expand Down
6 changes: 1 addition & 5 deletions tests/test_miou_rng.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
let () = Miou_unix.run @@ fun () ->
let rng =
begin[@alert "-deprecated"]
Mirage_crypto_rng_miou_unix.(initialize (module Pfortuna))
end
in
let rng = Mirage_crypto_rng_miou_unix.(initialize (module Pfortuna)) in
let random_num = Mirage_crypto_rng.generate 32 in
assert (String.length random_num = 32);
Printf.printf "32 bit random number: %s\n%!" (Ohex.encode random_num);
Expand Down

0 comments on commit 688cc6d

Please sign in to comment.