···99 is used to collect entropy.
1010*)
1111val initialize : ?g:'a -> ?sleep:int64 -> 'a Mirage_crypto_rng.generator -> unit
1212+[@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
+7-14
rng/mirage_crypto_rng.mli
···2323 Please ensure to call [Mirage_crypto_rng_unix.use_default], or
2424 [Mirage_crypto_rng_unix.use_dev_urandom] (if you only want to use
2525 /dev/urandom), or [Mirage_crypto_rng_unix.use_getentropy] (if you only want
2626- to use getentropy).
2626+ to use getrandom/getentropy/BCryptGenRandom).
27272828 For fine-grained control (doing entropy harvesting, etc.), please continue
2929- reading the documentation below. {b Please be aware that the feeding of Fortuna
3030- and producing random numbers is not thread-safe} (it is on Miou_unix via Pfortuna).
3131-3232- The RNGs here are merely the deterministic part of a full random number
3333- generation suite. For proper operation, they need to be seeded with a
3434- high-quality entropy source.
2929+ reading the documentation below. {b Please be aware that the feeding of
3030+ Fortuna and producing random numbers is not thread-safe} (it is on Miou_unix
3131+ via Pfortuna).
35323633 Suitable entropy feeding of generators are provided by other libraries
3737- {{!Mirage_crypto_rng_lwt}mirage-crypto-rng-lwt} (for Lwt),
3838- {{!Mirage_crypto_rng_async}mirage-crypto-rng-async} (for Async),
3934 {{!Mirage_crypto_rng_mirage}mirage-crypto-rng-mirage} (for MirageOS),
4040- {{!Mirage_crypto_rng_unix}mirage-crypto-rng.unix},
4141- {{!Mirage_crypto_rng_eio}mirage-crypto-rng-eio} (for Eio),
4235 and {{!Mirage_crypto_rng_miou_unix}mirage-crypto-miou-unix} (for Miou_unix).
43364437 The intention is that "initialize" in the respective sub-library is called
···4942 generator should be used in most setting, and that should be fed a constant
5043 stream of entropy.
51445252- [mirage-crypto-rng-eio] package differs slightly from other rng packages.
5353- Instead of the [initialize] function a [run] function is provided with
5454- similar behaviour, i.e. RNG setup, entropy collection and periodic reseeding.
4545+ The RNGs here are merely the deterministic part of a full random number
4646+ generation suite. For proper operation, they need to be seeded with a
4747+ high-quality entropy source.
55485649 Although this module exposes a more fine-grained interface, e.g. allowing
5750 manual seeding of generators, this is intended either for implementing
+3-13
rng/rng.ml
···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]`. \
1919- \n If you are using Lwt, execute \
2020- `Mirage_crypto_rng_lwt.initialize (module Mirage_crypto_rng.Fortuna)` \
2121- at startup. \
2222- \n If you are using Async, execute \
2323- `Mirage_crypto_rng_async.initialize (module Mirage_crypto_rng.Fortuna)` \
2424- at startup. \
2525- \n If you are using Eio, execute in one of the fibers \
2626- `Mirage_crypto_rng_eio.run (module Fortuna) env` (`env` from `Eio_main.run`).
2727- \n Otherwise, there is no periodic reseeding. For an initial seed from \
2828- getrandom(), execute \
2929- `Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna)`. \
3030- You can use `Mirage_crypto_rng.accumulate` and `Mirage_crypto_rng.reseed` \
3131- to reseed the RNG manually."
1919+ \n If you are using miou, execute \
2020+ `Mirage_crypto_rng_miou_unix.initialize (module Mirage_crypto_rng.Fortuna)` \
2121+ at startup."
32223323let () = Printexc.register_printer (function
3424 | Unseeded_generator ->
+1
rng/unix/mirage_crypto_rng_unix.mli
···8899(** [initialize ~g rng] will bring the RNG into a working state. *)
1010val initialize : ?g:'a -> 'a Mirage_crypto_rng.generator -> unit
1111+[@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
11121213(** [getrandom size] returns a buffer of [size] filled with random bytes. *)
1314val getrandom : int -> string
+15-13
tests/test_eio_entropy_collection.ml
···20202121let () =
2222 Eio_main.run @@ fun env ->
2323- Mirage_crypto_rng_eio.run (module Printing_rng) env @@ fun () ->
2424- Eio.Fiber.both
2525- begin fun () ->
2626- let sleep = Duration.(of_sec 2 |> to_f) in
2727- Eio.Time.sleep env#clock sleep
2828- end
2929- begin fun () ->
3030- Format.printf "entropy sources: %a@,%!"
3131- (fun ppf -> List.iter (fun x ->
3232- Mirage_crypto_rng.Entropy.pp_source ppf x;
3333- Format.pp_print_space ppf ()))
3434- (Mirage_crypto_rng.Entropy.sources ())
3535- end
2323+ begin[@alert "-deprecated"]
2424+ Mirage_crypto_rng_eio.run (module Printing_rng) env @@ fun () ->
2525+ Eio.Fiber.both
2626+ begin fun () ->
2727+ let sleep = Duration.(of_sec 2 |> to_f) in
2828+ Eio.Time.sleep env#clock sleep
2929+ end
3030+ begin fun () ->
3131+ Format.printf "entropy sources: %a@,%!"
3232+ (fun ppf -> List.iter (fun x ->
3333+ Mirage_crypto_rng.Entropy.pp_source ppf x;
3434+ Format.pp_print_space ppf ()))
3535+ (Mirage_crypto_rng.Entropy.sources ())
3636+ end
3737+ end
3638
+9-7
tests/test_eio_rng.ml
···2233let () =
44 Eio_main.run @@ fun env ->
55- Mirage_crypto_rng_eio.run (module Fortuna) env @@ fun () ->
66- let random_num = Mirage_crypto_rng.generate 32 in
77- assert (String.length random_num = 32);
88- Printf.printf "32 bit random number: %S\n%!" random_num;
99- let random_num = Mirage_crypto_rng.generate 16 in
1010- assert (String.length random_num = 16);
1111- Printf.printf "16 bit random number: %S\n%!" random_num;
55+ begin[@alert "-deprecated"]
66+ Mirage_crypto_rng_eio.run (module Fortuna) env @@ fun () ->
77+ let random_num = Mirage_crypto_rng.generate 32 in
88+ assert (String.length random_num = 32);
99+ Printf.printf "32 bit random number: %S\n%!" random_num;
1010+ let random_num = Mirage_crypto_rng.generate 16 in
1111+ assert (String.length random_num = 16);
1212+ Printf.printf "16 bit random number: %S\n%!" random_num;
1313+ end