Skip to content

Commit

Permalink
mirage-crypto-rng-eio: use monotonic clock from eio's environment ins…
Browse files Browse the repository at this point in the history
…tead of mtime (#176)

mirage-crypto-rng-eio: use eio environment's clock

instead of mtime.clock.os
  • Loading branch information
TheLortex authored Jul 31, 2023
1 parent 1b16de5 commit d496d32
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## dev

* mirage-crypto-rng-eio: improve portability by using eio 0.7's monotonic clock
interface instead of mtime.clock.os. (@TheLortex)

## v0.11.1 (2023-03-09)

* BUGFIX Chacha20 decrypt and encrypt with empty data (previously lead to
Expand Down
2 changes: 1 addition & 1 deletion mirage-crypto-rng-eio.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ build: [ ["dune" "subst"] {dev}
depends: [
"ocaml" {>= "5.0.0"}
"dune" {>= "2.7"}
"eio" {>= "0.3"}
"eio" {>= "0.7"}
"cstruct" {>= "6.0.0"}
"logs"
"mirage-crypto-rng" {=version}
Expand Down
2 changes: 1 addition & 1 deletion rng/eio/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name mirage_crypto_rng_eio)
(public_name mirage-crypto-rng-eio)
(libraries eio cstruct logs mirage-crypto-rng duration mtime.clock.os))
(libraries eio cstruct logs mirage-crypto-rng duration mtime))
6 changes: 5 additions & 1 deletion rng/eio/mirage_crypto_rng_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ open Mirage_crypto_rng

type env = <
clock: Eio.Time.clock;
mono_clock: Eio.Time.Mono.t;
secure_random: Eio.Flow.source;
>

Expand Down Expand Up @@ -75,7 +76,10 @@ let run
Entropy.[ bootstrap ; whirlwind_bootstrap ; bootstrap ; getrandom_init env ] in
List.mapi (fun i f -> f i) init |> Cstruct.concat
in
let rng = create ?g ~seed ~time:Mtime_clock.elapsed_ns generator in
let time () =
Eio.Stdenv.mono_clock env |> Eio.Time.Mono.now |> Mtime.to_uint64_ns
in
let rng = create ?g ~seed ~time generator in
set_default_generator rng;
let source = Entropy.register_source "getrandom" in
let feed_entropy () = periodically_feed_entropy env (Int64.mul sleep 10L) source in
Expand Down
1 change: 1 addition & 0 deletions rng/eio/mirage_crypto_rng_eio.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

type env = <
clock: Eio.Time.clock;
mono_clock: Eio.Time.Mono.t;
secure_random: Eio.Flow.source;
>

Expand Down

0 comments on commit d496d32

Please sign in to comment.