Skip to content

Commit

Permalink
Mark the initialize functions as deprecated.
Browse files Browse the repository at this point in the history
Instead, advertise the use of the default Unix generator based on
getrandom/getentropy. This is thread-safe and allows to remove the
mirage-crypto-rng-{lwt,miou-unix,eio,async} packages in the future.
  • Loading branch information
hannesm committed Jan 8, 2025
1 parent c52a56a commit a2e976d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bench/speed.ml
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,12 @@ 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 ->
Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna);
throughput name (fun buf ->
let buf = Bytes.unsafe_of_string buf in
Mirage_crypto_rng.generate_into buf ~off:0 (Bytes.length buf))) ;
begin[@alert "-deprecated"]
Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna);
throughput name (fun buf ->
let buf = Bytes.unsafe_of_string buf in
Mirage_crypto_rng.generate_into buf ~off:0 (Bytes.length buf))
end);

bm "getentropy" (fun name ->
Mirage_crypto_rng_unix.use_getentropy ();
Expand Down
1 change: 1 addition & 0 deletions rng/async/mirage_crypto_rng_async.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ val initialize
-> ?sleep:Time_ns.Span.t
-> 'a Mirage_crypto_rng.generator
-> unit
[@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
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 @@ -39,3 +39,4 @@ val run
-> 'a Mirage_crypto_rng.generator
-> _ env
-> (unit -> 'b) -> 'b
[@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
1 change: 1 addition & 0 deletions rng/lwt/mirage_crypto_rng_lwt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
is used to collect entropy.
*)
val initialize : ?g:'a -> ?sleep:int64 -> 'a Mirage_crypto_rng.generator -> unit
[@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
1 change: 1 addition & 0 deletions rng/miou/mirage_crypto_rng_miou_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type rng
(** Type of tasks seeding the RNG. *)

val initialize : ?g:'a -> ?sleep:int64 -> 'a Mirage_crypto_rng.generator -> rng
[@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]
(** [initialize ?g ?sleep (module Generator)] will allow the RNG to operate in a
returned task. This task periodically launches sub-tasks that seed the
engine (using [getrandom()], [getentropy()] or [BCryptGenRandom()] depending
Expand Down
1 change: 1 addition & 0 deletions rng/unix/mirage_crypto_rng_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

(** [initialize ~g rng] will bring the RNG into a working state. *)
val initialize : ?g:'a -> 'a Mirage_crypto_rng.generator -> unit
[@@deprecated "Use 'Mirage_crypto_rng_unix.use_default ()' instead."]

(** [getrandom size] returns a buffer of [size] filled with random bytes. *)
val getrandom : int -> string
Expand Down

0 comments on commit a2e976d

Please sign in to comment.