File: test_miou_entropy_collection.ml

package info (click to toggle)
ocaml-mirage-crypto 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,524 kB
  • sloc: ansic: 91,925; ml: 9,700; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Printing_rng = struct
  type g = unit

  let block = 16
  let create ?time:_ () = ()
  let generate_into ~g:_ _buf ~off:_ _len = assert false
  let seeded ~g:_ = true
  let pools = 1

  let reseed ~g:_ data =
    Format.printf "reseeding:@.%a@.%!" (Ohex.pp_hexdump ()) data

  let accumulate ~g:_ source =
    let print data =
      Format.printf "accumulate: (src: %a) %a@.%!"
        Mirage_crypto_rng.Entropy.pp_source source Ohex.pp data
    in
    `Acc print
end

let () =
  Miou_unix.run @@ fun () ->
  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;
         Format.pp_print_space ppf ()))
    (Mirage_crypto_rng.Entropy.sources ());
  let sleep = Duration.(of_sec 2 |> to_f) in
  Miou_unix.sleep sleep;
  Mirage_crypto_rng_miou_unix.kill rng