Skip to content

Commit

Permalink
bench/speed: use Urandom and Getentropy generators
Browse files Browse the repository at this point in the history
since the pfortuna benchmark has been moved to bench/speed, remove bench/miou

Mirage_crypto_rng_unix: remove getrandom_into
  • Loading branch information
hannesm committed Dec 6, 2024
1 parent 03d3e92 commit 3abb84a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 115 deletions.
9 changes: 1 addition & 8 deletions bench/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,4 @@
(names speed)
(modules speed)
(libraries mirage-crypto mirage-crypto-rng mirage-crypto-rng.unix
mirage-crypto-pk mirage-crypto-ec mirage-crypto-rng-miou-unix threads.posix))

; marking as "(optional)" leads to OCaml-CI failures
; marking with "(package mirage-crypto-rng-miou-unix)" only has an effect with a "public_name"
;(executables
; (names miou)
; (modules miou)
; (libraries mirage-crypto-rng-miou-unix))
mirage-crypto-pk mirage-crypto-ec mirage-crypto-rng-miou-unix))
91 changes: 0 additions & 91 deletions bench/miou.ml

This file was deleted.

20 changes: 8 additions & 12 deletions bench/speed.ml
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,10 @@ let benchmarks = [
throughput_into name (fun dst cs -> DES.ECB.unsafe_encrypt_into ~key cs ~src_off:0 dst ~dst_off:0 (String.length cs))) ;

bm "fortuna" (fun name ->
let open Mirage_crypto_rng.Fortuna in
let g = create () in
reseed ~g "abcd" ;
Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna);
throughput name (fun buf ->
let buf = Bytes.unsafe_of_string buf in
generate_into ~g buf ~off:0 (Bytes.length buf))) ;
Mirage_crypto_rng.generate_into buf ~off:0 (Bytes.length buf))) ;

bm "pfortuna" (fun name ->
let open Mirage_crypto_rng_miou_unix.Pfortuna in
Expand All @@ -498,19 +496,17 @@ let benchmarks = [
generate_into ~g buf ~off:0 (Bytes.length buf));
Mirage_crypto_rng_miou_unix.kill rng) ;

bm "getrandom" (fun name ->
bm "getentropy" (fun name ->
Mirage_crypto_rng_unix.use_getentropy ();
throughput name (fun buf ->
let buf = Bytes.unsafe_of_string buf in
Mirage_crypto_rng_unix.getrandom_into buf ~off:0 ~len:(Bytes.length buf))) ;
Mirage_crypto_rng.generate_into buf ~off:0 (Bytes.length buf))) ;

bm "urandom-channel" (fun name ->
In_channel.with_open_bin "/dev/urandom" @@ fun ic ->
let m = Mutex.create () in
let finally () = Mutex.unlock m in
bm "urandom" (fun name ->
Mirage_crypto_rng_unix.use_dev_urandom ();
throughput name (fun buf ->
let buf = Bytes.unsafe_of_string buf in
Mutex.lock m;
Fun.protect ~finally (fun () -> really_input ic buf 0 (Bytes.length buf))));
Mirage_crypto_rng.generate_into buf ~off:0 (Bytes.length buf))) ;
]

let help () =
Expand Down
4 changes: 0 additions & 4 deletions rng/unix/mirage_crypto_rng_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ val initialize : ?g:'a -> 'a Mirage_crypto_rng.generator -> unit
(** [getrandom size] returns a buffer of [size] filled with random bytes. *)
val getrandom : int -> string

(** [getrandom_into buf ~off ~len] fills [buf] with random data ([len] octets),
starting at [off]. *)
val getrandom_into : bytes -> off:int -> len:int -> unit

module Urandom : Mirage_crypto_rng.Generator

module Getentropy : Mirage_crypto_rng.Generator
Expand Down

0 comments on commit 3abb84a

Please sign in to comment.