upstream: https://github.com/mirage/mirage-crypto
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

remove now superfluous mirage-crypto-rng-{lwt,eio,async} (#256)

* remove now superfluous mirage-crypto-rng-{lwt,eio,async}

we have Mirage_crypto_rng_unix.use_default () now, and by default use getrandom

* remove these packages from CI

* fix enabled_if condition

authored by

Hannes Mehnert and committed by
GitHub
0a7e5727 fe7bad77

+13 -543
+2 -2
.cirrus.yml
··· 13 13 - opam env 14 14 15 15 pin_packages_script: 16 - - opam install -y --deps-only -t ./mirage-crypto.opam ./mirage-crypto-rng.opam ./mirage-crypto-rng-lwt.opam ./mirage-crypto-rng-mirage.opam ./mirage-crypto-ec.opam ./mirage-crypto-pk.opam 16 + - opam install -y --deps-only -t ./mirage-crypto.opam ./mirage-crypto-rng.opam ./mirage-crypto-rng-mirage.opam ./mirage-crypto-ec.opam ./mirage-crypto-pk.opam 17 17 18 - test_script: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-lwt,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec 18 + test_script: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec 19 19 20 20 test_mirage_script: eval `opam env` && ./.test-mirage.sh
+6 -8
.github/workflows/test.yml
··· 23 23 with: 24 24 opam-local-packages: | 25 25 *.opam 26 - !mirage-crypto-rng-eio.opam 27 26 !mirage-crypto-rng-miou-unix.opam 28 27 ocaml-compiler: ${{ matrix.ocaml-version }} 29 28 30 29 - name: Install dependencies 31 - run: opam install --deps-only -t mirage-crypto mirage-crypto-rng mirage-crypto-rng-lwt mirage-crypto-rng-mirage mirage-crypto-pk mirage-crypto-ec mirage-crypto-rng-async 30 + run: opam install --deps-only -t mirage-crypto mirage-crypto-rng mirage-crypto-rng-mirage mirage-crypto-pk mirage-crypto-ec 32 31 33 32 - name: Build 34 - run: opam exec -- dune build -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-lwt,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec,mirage-crypto-rng-async 33 + run: opam exec -- dune build -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec 35 34 36 35 - name: Test 37 - run: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-lwt,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec,mirage-crypto-rng-async 36 + run: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec 38 37 39 38 build-test-ocaml-5: 40 39 name : Tests with OCaml 5 ··· 57 56 opam-local-packages: | 58 57 mirage-crypto.opam 59 58 mirage-crypto-rng.opam 60 - mirage-crypto-rng-eio.opam 61 59 mirage-crypto-rng-miou-unix.opam 62 60 ocaml-compiler: ${{ matrix.ocaml-version }} 63 61 64 62 - name: Install dependencies 65 - run: opam install --deps-only -t mirage-crypto mirage-crypto-rng mirage-crypto-rng-eio mirage-crypto-rng-miou-unix 63 + run: opam install --deps-only -t mirage-crypto mirage-crypto-rng mirage-crypto-rng-miou-unix 66 64 67 65 - name: Build 68 - run: opam exec -- dune build -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-eio,mirage-crypto-rng-miou-unix 66 + run: opam exec -- dune build -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-miou-unix 69 67 70 68 - name: Test 71 - run: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-eio,mirage-crypto-rng-miou-unix 69 + run: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-miou-unix
+3 -5
.github/workflows/windows.yml
··· 26 26 default: https://github.com/ocaml/opam-repository.git 27 27 opam-local-packages: | 28 28 *.opam 29 - !mirage-crypto-rng-async.opam 30 - !mirage-crypto-rng-eio.opam 31 29 !mirage-crypto-rng-miou-unix.opam 32 30 ocaml-compiler: ${{ matrix.ocaml-version }} 33 31 34 32 - name: Install dependencies 35 - run: opam install --deps-only -t mirage-crypto mirage-crypto-rng mirage-crypto-rng-lwt mirage-crypto-rng-mirage mirage-crypto-pk mirage-crypto-ec 33 + run: opam install --deps-only -t mirage-crypto mirage-crypto-rng mirage-crypto-rng-mirage mirage-crypto-pk mirage-crypto-ec 36 34 37 35 - name: Build 38 - run: opam exec -- dune build -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-lwt,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec 36 + run: opam exec -- dune build -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec 39 37 40 38 - name: Test 41 - run: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-lwt,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec 39 + run: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec
+1 -1
ci/build-test.sh
··· 81 81 # Build logic 82 82 # 2024-02-09: Remove mirage-crypto-pk on Windows since no portable GMP library (used by Zarith). 83 83 # 2024-02-24: Remove mirage-crypto-ec on Windows since it results in test failures. 84 - packages_TOPOLOGICALSORT="mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-lwt,mirage-crypto-rng-mirage" 84 + packages_TOPOLOGICALSORT="mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-mirage" 85 85 case "$dkml_host_abi" in 86 86 windows_*) 87 87 packages_TOPOLOGICALSORT="$packages_TOPOLOGICALSORT"
-31
mirage-crypto-rng-async.opam
··· 1 - opam-version: "2.0" 2 - homepage: "https://github.com/mirage/mirage-crypto" 3 - dev-repo: "git+https://github.com/mirage/mirage-crypto.git" 4 - bug-reports: "https://github.com/mirage/mirage-crypto/issues" 5 - doc: "https://mirage.github.io/mirage-crypto/doc" 6 - authors: ["David Kaloper <dk505@cam.ac.uk>" "Hannes Mehnert <hannes@mehnert.org>" ] 7 - maintainer: "Hannes Mehnert <hannes@mehnert.org>" 8 - license: "ISC" 9 - synopsis: "Feed the entropy source in an Async-friendly way" 10 - 11 - build: [ ["dune" "subst"] {dev} 12 - ["dune" "build" "-p" name "-j" jobs ] 13 - ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] 14 - 15 - depends: [ 16 - "ocaml" {>= "4.13.0"} 17 - "dune" {>= "2.7"} 18 - "dune-configurator" {>= "2.0.0"} 19 - "async" {>= "v0.14"} 20 - "logs" 21 - "mirage-crypto-rng" {=version} 22 - "ohex" {with-test & >= "0.2.0"} 23 - ] 24 - available: os != "win32" 25 - description: """ 26 - 27 - Mirage-crypto-rng-async feeds the entropy source for Mirage_crypto_rng-based 28 - random number generator implementations, in an Async-friendly way. 29 - """ 30 - 31 - x-maintenance-intent: [ "(latest)" ]
-31
mirage-crypto-rng-eio.opam
··· 1 - opam-version: "2.0" 2 - homepage: "https://github.com/mirage/mirage-crypto" 3 - dev-repo: "git+https://github.com/mirage/mirage-crypto.git" 4 - bug-reports: "https://github.com/mirage/mirage-crypto/issues" 5 - doc: "https://mirage.github.io/mirage-crypto/doc" 6 - authors: ["Bikal Gurung <gbikal@gmail.com>" ] 7 - maintainer: "Bikal Gurung <gbikal@gmail.com>" 8 - license: "ISC" 9 - synopsis: "Feed the entropy source in an eio-friendly way" 10 - 11 - build: [ ["dune" "subst"] {dev} 12 - ["dune" "build" "-p" name "-j" jobs ] 13 - ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] 14 - 15 - depends: [ 16 - "ocaml" {>= "5.0.0"} 17 - "dune" {>= "2.7"} 18 - "eio" {>= "0.12"} 19 - "logs" 20 - "mirage-crypto-rng" {=version} 21 - "duration" 22 - "mtime" 23 - "cstruct" {>= "6.1.0"} 24 - "eio_main" {with-test} 25 - "ohex" {with-test & >= "0.2.0"} 26 - ] 27 - description: """ 28 - Mirage-crypto-rng-eio feeds the entropy source for Mirage_crypto_rng-based 29 - random number generator implementations, in an eio-friendly way. 30 - """ 31 - x-maintenance-intent: [ "(latest)" ]
-27
mirage-crypto-rng-lwt.opam
··· 1 - opam-version: "2.0" 2 - homepage: "https://github.com/mirage/mirage-crypto" 3 - dev-repo: "git+https://github.com/mirage/mirage-crypto.git" 4 - bug-reports: "https://github.com/mirage/mirage-crypto/issues" 5 - doc: "https://mirage.github.io/mirage-crypto/doc" 6 - authors: ["David Kaloper <dk505@cam.ac.uk>" "Hannes Mehnert <hannes@mehnert.org>" ] 7 - maintainer: "Hannes Mehnert <hannes@mehnert.org>" 8 - license: "ISC" 9 - synopsis: "A cryptographically secure PRNG" 10 - 11 - build: [ ["dune" "subst"] {dev} 12 - ["dune" "build" "-p" name "-j" jobs ] 13 - ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] 14 - 15 - depends: [ 16 - "ocaml" {>= "4.13.0"} 17 - "dune" {>= "2.7"} 18 - "duration" 19 - "logs" 20 - "mirage-crypto-rng" {=version} 21 - "mtime" {>= "1.0.0"} 22 - "lwt" {>= "4.0.0"} 23 - ] 24 - description: """ 25 - Mirage-crypto-rng-lwt provides entropy collection code for the RNG using Lwt. 26 - """ 27 - x-maintenance-intent: [ "(latest)" ]
-5
rng/async/dune
··· 1 - (library 2 - (name mirage_crypto_rng_async) 3 - (public_name mirage-crypto-rng-async) 4 - (modules mirage_crypto_rng_async) 5 - (libraries async mirage-crypto-rng mirage-crypto-rng.unix logs))
-84
rng/async/mirage_crypto_rng_async.ml
··· 1 - open Core 2 - open Async 3 - 4 - open Mirage_crypto_rng 5 - 6 - let src = Logs.Src.create "mirage-crypto-rng-async" ~doc:"Mirage crypto RNG Async" 7 - module Log = (val Logs.src_log src : Logs.LOG) 8 - 9 - let running = ref false 10 - 11 - let ns_since_epoch time_source () = 12 - Synchronous_time_source.now time_source 13 - |> Time_ns.to_int_ns_since_epoch 14 - |> Int64.of_int 15 - 16 - let periodically_collect_cpu_entropy time_source span = 17 - match Entropy.cpu_rng with 18 - | Error `Not_supported -> () 19 - | Ok cpu_rng -> 20 - Synchronous_time_source.run_at_intervals 21 - time_source 22 - span 23 - (cpu_rng None) 24 - 25 - let periodically_collect_getrandom_entropy time_source span = 26 - let source = Entropy.register_source "getrandom" in 27 - Synchronous_time_source.run_at_intervals 28 - time_source 29 - span 30 - (fun () -> 31 - let per_pool = 8 in 32 - let size = per_pool * pools None in 33 - let random = Mirage_crypto_rng_unix.getrandom size in 34 - let idx = ref 0 in 35 - let f () = 36 - incr idx; 37 - Ok (String.sub random ~pos:(per_pool * (pred !idx)) ~len:per_pool) 38 - in 39 - Entropy.feed_pools None source f) 40 - 41 - let read_cpu_counter_at_the_start_of_every_cycle () = 42 - Scheduler.Expert.run_every_cycle_start 43 - (Entropy.timer_accumulator None) 44 - 45 - let getrandom_init i = 46 - let data = Mirage_crypto_rng_unix.getrandom 128 in 47 - Entropy.header i data 48 - 49 - let initialize ?g ?time_source ?(sleep = Time_ns.Span.of_int_sec 1) generator = 50 - let time_source = 51 - Option.value ~default:(Synchronous_time_source.wall_clock ()) time_source 52 - in 53 - if !running then 54 - Log.debug 55 - (fun m -> m "Mirage_crypto_rng_async.initialize has already been called, \ 56 - ignoring this call.") 57 - else begin 58 - (try 59 - let _ = default_generator () in 60 - Log.warn (fun m -> m "Mirage_crypto_rng.default_generator has already \ 61 - been set (but not via \ 62 - Mirage_crypto_rng_async.initialize). Please check \ 63 - that this is intentional"); 64 - with 65 - No_default_generator -> ()); 66 - running := true; 67 - let seed = 68 - (* getrandom_init might block, but this is initialization so prima facie, it 69 - doesn't matter. *) 70 - let init = 71 - Entropy.[ bootstrap ; whirlwind_bootstrap ; bootstrap ; getrandom_init ] 72 - in 73 - List.mapi ~f:(fun i f -> f i) init |> String.concat ~sep:"" 74 - in 75 - let rng = 76 - create ?g ~seed ~time:(ns_since_epoch time_source) generator 77 - in 78 - set_default_generator rng; 79 - periodically_collect_cpu_entropy time_source sleep; 80 - periodically_collect_getrandom_entropy 81 - time_source 82 - (Time_ns.Span.scale_int sleep 10); 83 - read_cpu_counter_at_the_start_of_every_cycle (); 84 - end
-19
rng/async/mirage_crypto_rng_async.mli
··· 1 - open! Core 2 - open! Async 3 - 4 - (** {b RNG} seeding on {b Async}. 5 - 6 - This module initializes a Fortuna RNG with [getrandom()], and CPU RNG. 7 - *) 8 - 9 - (** [initialize ~sleep generator] will bring the RNG into a working state. The 10 - argument [sleep] is measured in ns (default 1s), and used to sleep between 11 - collection of entropy from the CPU RNG, every [10 * sleep] getrandom is used 12 - to collect entropy. *) 13 - val initialize 14 - : ?g:'a 15 - -> ?time_source:Synchronous_time_source.t 16 - -> ?sleep:Time_ns.Span.t 17 - -> 'a Mirage_crypto_rng.generator 18 - -> unit 19 - [@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
-4
rng/eio/dune
··· 1 - (library 2 - (name mirage_crypto_rng_eio) 3 - (public_name mirage-crypto-rng-eio) 4 - (libraries eio logs mirage-crypto-rng duration mtime cstruct))
-87
rng/eio/mirage_crypto_rng_eio.ml
··· 1 - open Mirage_crypto_rng 2 - 3 - type 'a env = < 4 - clock: [> ] Eio.Time.clock; 5 - mono_clock: [> ] Eio.Time.Mono.t; 6 - secure_random: [> ] Eio.Flow.source; 7 - .. 8 - > as 'a 9 - 10 - let src = Logs.Src.create "mirage-crypto-rng-eio" ~doc:"Mirage crypto RNG Eio" 11 - module Log = (val Logs.src_log src: Logs.LOG) 12 - 13 - let getrandom env i = 14 - let buf = Cstruct.create i in 15 - Eio.Flow.read_exact env#secure_random buf; 16 - Cstruct.to_string buf 17 - 18 - let getrandom_init env i = 19 - let data = getrandom env 128 in 20 - Entropy.header i data 21 - 22 - let rec periodic env f delta = 23 - f (); 24 - Eio.Time.sleep env#clock (Duration.to_f delta); 25 - periodic env f delta 26 - 27 - let periodically_feed_entropy env delta source = 28 - let task () = 29 - let per_pool = 8 in 30 - let size = per_pool * pools None in 31 - let random = getrandom env size in 32 - let idx = ref 0 in 33 - let f () = 34 - incr idx; 35 - Ok (String.sub random (per_pool * (pred !idx)) per_pool) 36 - in 37 - Entropy.feed_pools None source f 38 - in 39 - periodic env task delta 40 - 41 - let rdrand_task env delta = 42 - match Entropy.cpu_rng with 43 - | Error `Not_supported -> [] 44 - | Ok cpu_rng -> [ fun () -> periodic env (cpu_rng None) delta ] 45 - 46 - let running = ref false 47 - 48 - let run 49 - ?g 50 - ?(sleep = Duration.of_sec 1) 51 - generator 52 - env 53 - fn 54 - = 55 - if !running then begin 56 - Log.debug 57 - (fun m -> m "Mirage_crypto_rng_eio.initialize has already been called, \ 58 - ignoring this call."); 59 - fn () 60 - end 61 - else begin 62 - running := true; 63 - Fun.protect 64 - ~finally:(fun () -> 65 - running := false; 66 - unset_default_generator ()) 67 - (fun () -> 68 - (try 69 - let _ = default_generator () in 70 - Log.warn (fun m -> m "Mirage_crypto_rng.default_generator has already \ 71 - been set, check that this call is intentional"); 72 - with 73 - No_default_generator -> ()); 74 - let seed = 75 - let init = 76 - Entropy.[ bootstrap ; whirlwind_bootstrap ; bootstrap ; getrandom_init env ] in 77 - List.mapi (fun i f -> f i) init |> String.concat "" 78 - in 79 - let time () = 80 - Eio.Stdenv.mono_clock env |> Eio.Time.Mono.now |> Mtime.to_uint64_ns 81 - in 82 - let rng = create ?g ~seed ~time generator in 83 - set_default_generator rng; 84 - let source = Entropy.register_source "getrandom" in 85 - let feed_entropy () = periodically_feed_entropy env (Int64.mul sleep 10L) source in 86 - Eio.Fiber.any (rdrand_task env sleep @ [feed_entropy ; fn])) 87 - end
-42
rng/eio/mirage_crypto_rng_eio.mli
··· 1 - (** {b RNG} seeding on {b Eio backends}. 2 - 3 - This module initializes a given random number generator with [getrandom()] and a CPU RNG. 4 - [Eio.Stdenv.secure_random] is used as the [getrandom()] implementation. 5 - *) 6 - 7 - type 'a env = < 8 - clock: [> ]Eio.Time.clock; 9 - mono_clock: [> ]Eio.Time.Mono.t; 10 - secure_random: [> ] Eio.Flow.source; 11 - .. 12 - > as 'a 13 - 14 - (** [run ~g ~sleep gen env fn] will bring the RNG into a working state. The argument 15 - [sleep] is measured in ns (default 1s), and is used to sleep between collection 16 - of entropy from the CPU RNG. Every [10 * sleep] getrandom is used to collect 17 - entropy. 18 - 19 - {b Note} In a multi-domain setting [run] ensures that entropy collection, feeding 20 - and RNG setup are limited to one domain. 21 - 22 - [fn] is the main function that will have access to a running RNG. 23 - 24 - [g] [gen] denotes random number generator scheme to be used, eg [Mirage_crypto_rng.Fortuna]. 25 - 26 - [[ 27 - open Mirage_crypto_rng 28 - 29 - let () = 30 - Eio_main.run @@ fun env -> 31 - Mirage_crypto_rng_eio.run (module Fortuna) env @@ fun () -> 32 - let random_num = Mirage_crypto_rng.generate 32 in 33 - Printf.printf "Random number: %S%!" (Cstruct.to_string random_num) 34 - ]] 35 - *) 36 - val run 37 - : ?g:'a 38 - -> ?sleep:int64 39 - -> 'a Mirage_crypto_rng.generator 40 - -> _ env 41 - -> (unit -> 'b) -> 'b 42 - [@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
-6
rng/lwt/dune
··· 1 - (library 2 - (name mirage_crypto_rng_lwt) 3 - (public_name mirage-crypto-rng-lwt) 4 - (modules mirage_crypto_rng_lwt) 5 - (libraries lwt lwt.unix mirage-crypto-rng mirage-crypto-rng.unix duration 6 - mtime.clock.os logs))
-69
rng/lwt/mirage_crypto_rng_lwt.ml
··· 1 - open Mirage_crypto_rng 2 - 3 - let src = Logs.Src.create "mirage-crypto-rng-lwt" ~doc:"Mirage crypto RNG Lwt" 4 - module Log = (val Logs.src_log src : Logs.LOG) 5 - 6 - let periodic f delta = 7 - let open Lwt.Infix in 8 - Lwt.async (fun () -> 9 - let rec one () = 10 - f (); Lwt_unix.sleep (Duration.to_f delta) >>= one 11 - in 12 - one ()) 13 - 14 - let getrandom_task delta source = 15 - let task () = 16 - let per_pool = 8 in 17 - let size = per_pool * pools None in 18 - let random = Mirage_crypto_rng_unix.getrandom size in 19 - let idx = ref 0 in 20 - let f () = 21 - incr idx; 22 - Ok (String.sub random (per_pool * (pred !idx)) per_pool) 23 - in 24 - Entropy.feed_pools None source f 25 - in 26 - periodic task delta 27 - 28 - let rdrand_task delta = 29 - match Entropy.cpu_rng with 30 - | Error `Not_supported -> () 31 - | Ok cpu_rng -> periodic (cpu_rng None) delta 32 - 33 - let running = ref false 34 - 35 - let getrandom_init i = 36 - let data = Mirage_crypto_rng_unix.getrandom 128 in 37 - Entropy.header i data 38 - 39 - let initialize (type a) ?g ?(sleep = Duration.of_sec 1) (rng : a generator) = 40 - if !running then 41 - Log.debug 42 - (fun m -> m "Mirage_crypto_rng_lwt.initialize has already been called, \ 43 - ignoring this call.") 44 - else begin 45 - (try 46 - let _ = default_generator () in 47 - Log.warn (fun m -> m "Mirage_crypto_rng.default_generator has already \ 48 - been set (but not via \ 49 - Mirage_crypto_rng_lwt.initialize). Please check \ 50 - that this is intentional"); 51 - with 52 - No_default_generator -> ()); 53 - running := true; 54 - let seed = 55 - let init = 56 - Entropy.[ bootstrap ; whirlwind_bootstrap ; bootstrap ; getrandom_init ] 57 - in 58 - List.mapi (fun i f -> f i) init |> String.concat "" 59 - in 60 - let rng = create ?g ~seed ~time:Mtime_clock.elapsed_ns rng in 61 - set_default_generator rng; 62 - rdrand_task sleep; 63 - let source = Entropy.register_source "getrandom" in 64 - getrandom_task (Int64.mul sleep 10L) source; 65 - let _ = 66 - Lwt_main.Enter_iter_hooks.add_first (Entropy.timer_accumulator None) 67 - in 68 - () 69 - end
-12
rng/lwt/mirage_crypto_rng_lwt.mli
··· 1 - (** {b RNG} seeding on {b Lwt}. 2 - 3 - This module initializes a Fortuna RNG with [getrandom()], and CPU RNG. 4 - *) 5 - 6 - (** [initialize ~g ~sleep generator] will bring the RNG into a working state. 7 - The argument [sleep] is measured in ns (default 1s), and used to sleep 8 - between collection of entropy from the CPU RNG, every [10 * sleep] getrandom 9 - is used to collect entropy. 10 - *) 11 - val initialize : ?g:'a -> ?sleep:int64 -> 'a Mirage_crypto_rng.generator -> unit 12 - [@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
+1 -13
tests/dune
··· 32 32 mirage-clock-unix duration ohex)) 33 33 34 34 (test 35 - (name test_entropy_collection_async) 36 - (modules test_entropy_collection_async) 37 - (package mirage-crypto-rng-async) 38 - (libraries mirage-crypto-rng-async ohex)) 39 - 40 - (test 41 35 (name test_entropy) 42 36 (modules test_entropy) 43 37 (package mirage-crypto-rng) 44 38 (libraries mirage-crypto-rng ohex) 45 - (enabled_if (or (<> %{architecture} "arm64") (<> %{architecture} "riscv64")))) 39 + (enabled_if (and (<> %{architecture} "arm64") (<> %{architecture} "riscv64")))) 46 40 ; see https://github.com/mirage/mirage-crypto/issues/216 47 41 48 42 (test ··· 61 55 x25519_test.json eddsa_test.json) 62 56 (libraries alcotest mirage-crypto-ec wycheproof digestif asn1-combinators) 63 57 (package mirage-crypto-ec)) 64 - 65 - (tests 66 - (names test_eio_rng test_eio_entropy_collection) 67 - (modules test_eio_rng test_eio_entropy_collection) 68 - (libraries mirage-crypto-rng-eio duration eio_main ohex) 69 - (package mirage-crypto-rng-eio)) 70 58 71 59 (tests 72 60 (names test_miou_rng test_miou_entropy_collection)
-38
tests/test_eio_entropy_collection.ml
··· 1 - module Printing_rng = struct 2 - type g = unit 3 - 4 - let block = 16 5 - let create ?time:_ () = () 6 - let generate_into ~g:_ _buf ~off:_ _len = assert false 7 - let seeded ~g:_ = true 8 - let pools = 1 9 - 10 - let reseed ~g:_ data = 11 - Format.printf "reseeding:@.%a@.%!" (Ohex.pp_hexdump ()) data 12 - 13 - let accumulate ~g:_ source = 14 - let print data = 15 - Format.printf "accumulate: (src: %a) %a@.%!" 16 - Mirage_crypto_rng.Entropy.pp_source source Ohex.pp data 17 - in 18 - `Acc print 19 - end 20 - 21 - let () = 22 - Eio_main.run @@ fun env -> 23 - begin[@alert "-deprecated"] 24 - Mirage_crypto_rng_eio.run (module Printing_rng) env @@ fun () -> 25 - Eio.Fiber.both 26 - begin fun () -> 27 - let sleep = Duration.(of_sec 2 |> to_f) in 28 - Eio.Time.sleep env#clock sleep 29 - end 30 - begin fun () -> 31 - Format.printf "entropy sources: %a@,%!" 32 - (fun ppf -> List.iter (fun x -> 33 - Mirage_crypto_rng.Entropy.pp_source ppf x; 34 - Format.pp_print_space ppf ())) 35 - (Mirage_crypto_rng.Entropy.sources ()) 36 - end 37 - end 38 -
-13
tests/test_eio_rng.ml
··· 1 - open Mirage_crypto_rng 2 - 3 - let () = 4 - Eio_main.run @@ fun env -> 5 - begin[@alert "-deprecated"] 6 - Mirage_crypto_rng_eio.run (module Fortuna) env @@ fun () -> 7 - let random_num = Mirage_crypto_rng.generate 32 in 8 - assert (String.length random_num = 32); 9 - Printf.printf "32 bit random number: %S\n%!" random_num; 10 - let random_num = Mirage_crypto_rng.generate 16 in 11 - assert (String.length random_num = 16); 12 - Printf.printf "16 bit random number: %S\n%!" random_num; 13 - end
-46
tests/test_entropy_collection_async.ml
··· 1 - open Core 2 - open Async 3 - 4 - module Printing_rng = struct 5 - type g = unit 6 - 7 - let block = 16 8 - 9 - let create ?time:_ () = () 10 - 11 - let generate_into ~g:_ _buf ~off:_ _len = assert false 12 - 13 - let reseed ~g:_ data = 14 - Format.printf "reseeding:@.%a@.%!" (Ohex.pp_hexdump ()) data 15 - 16 - let accumulate ~g:_ source = 17 - let print data = 18 - Format.printf "accumulate: (src: %a) %a@.%!" 19 - Mirage_crypto_rng.Entropy.pp_source source Ohex.pp data 20 - in 21 - `Acc print 22 - 23 - let seeded ~g:_ = true 24 - let pools = 1 25 - end 26 - 27 - module E = Mirage_crypto_rng_async 28 - 29 - 30 - let main () = 31 - begin[@alert "-deprecated"] 32 - E.initialize (module Printing_rng); 33 - end; 34 - Format.printf "entropy sources: %a@,%!" 35 - (fun ppf -> List.iter ~f:(fun x -> 36 - Mirage_crypto_rng.Entropy.pp_source ppf x; 37 - Format.pp_print_space ppf ())) 38 - (Mirage_crypto_rng.Entropy.sources ()); 39 - don't_wait_for ( 40 - Time_source.after 41 - (Time_source.wall_clock ()) 42 - (Time_ns.Span.of_int_sec 10) 43 - >>= fun () -> 44 - Shutdown.exit 0) 45 - 46 - let () = ignore (Scheduler.go_main ~main () : never_returns)