···1414(** Type of tasks seeding the RNG. *)
15151616val initialize : ?g:'a -> ?sleep:int64 -> 'a Mirage_crypto_rng.generator -> rng
1717-[@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
1817(** [initialize ?g ?sleep (module Generator)] will allow the RNG to operate in a
1918 returned task. This task periodically launches sub-tasks that seed the
2019 engine (using [getrandom()], [getentropy()] or [BCryptGenRandom()] depending
+12
rng/mirage_crypto_rng.mli
···3030 Fortuna and producing random numbers is not thread-safe} (it is on Miou_unix
3131 via Pfortuna).
32323333+ Suitable entropy feeding of generators are provided by other libraries
3434+ {{!Mirage_crypto_rng_mirage}mirage-crypto-rng-mirage} (for MirageOS),
3535+ and {{!Mirage_crypto_rng_miou_unix}mirage-crypto-miou-unix} (for Miou_unix).
3636+3737+ The intention is that "initialize" in the respective sub-library is called
3838+ once, which sets the default generator and registers entropy
3939+ harvesting asynchronous tasks. The semantics is that the entropy is always
4040+ fed to the {{!default_generator}default generator}, which is not necessarily
4141+ the one set by "initialize". The reasoning behind this is that the default
4242+ generator should be used in most setting, and that should be fed a constant
4343+ stream of entropy.
4444+3345 The RNGs here are merely the deterministic part of a full random number
3446 generation suite. For proper operation, they need to be seeded with a
3547 high-quality entropy source.
+4-1
rng/rng.ml
···1515 following:\
1616 \n If you are using MirageOS, use the random device in config.ml: \
1717 `let main = Mirage.main \"Unikernel.Main\" (random @-> job)`, \
1818- and `let () = register \"my_unikernel\" [main $ default_random]`."
1818+ and `let () = register \"my_unikernel\" [main $ default_random]`. \
1919+ \n If you are using miou, execute \
2020+ `Mirage_crypto_rng_miou_unix.initialize (module Mirage_crypto_rng.Fortuna)` \
2121+ at startup."
19222023let () = Printexc.register_printer (function
2124 | Unseeded_generator ->
+1-5
tests/test_miou_entropy_collection.ml
···20202121let () =
2222 Miou_unix.run @@ fun () ->
2323- let rng =
2424- begin[@alert "-deprecated"]
2525- Mirage_crypto_rng_miou_unix.initialize (module Printing_rng)
2626- end
2727- in
2323+ let rng = Mirage_crypto_rng_miou_unix.initialize (module Printing_rng) in
2824 Format.printf "entropy sources: %a@,%!"
2925 (fun ppf -> List.iter (fun x ->
3026 Mirage_crypto_rng.Entropy.pp_source ppf x;
+1-5
tests/test_miou_rng.ml
···11let () = Miou_unix.run @@ fun () ->
22- let rng =
33- begin[@alert "-deprecated"]
44- Mirage_crypto_rng_miou_unix.(initialize (module Pfortuna))
55- end
66- in
22+ let rng = Mirage_crypto_rng_miou_unix.(initialize (module Pfortuna)) in
73 let random_num = Mirage_crypto_rng.generate 32 in
84 assert (String.length random_num = 32);
95 Printf.printf "32 bit random number: %s\n%!" (Ohex.encode random_num);