forked from mirage/mirage-crypto
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add /dev/urandom and getentropy RNG generators
Provide guidance to use these by default, document that Fortuna is not thread-safe. As suggested in mirage#249
- Loading branch information
Showing
11 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
external getrandom_buf : bytes -> int -> int -> unit = "mc_getrandom" [@@noalloc] | ||
|
||
type g = unit | ||
|
||
let block = 256 | ||
|
||
let create ?time:_ () = () | ||
|
||
let generate_into ~g:_ buf ~off len = | ||
getrandom_buf buf off len | ||
|
||
let reseed ~g:_ _data = () | ||
|
||
let accumulate ~g:_ _source = | ||
`Acc (fun _data -> ()) | ||
|
||
let seeded ~g:_ = true | ||
|
||
let pools = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
type g = In_channel.t * Mutex.t | ||
|
||
let block = 2048 | ||
|
||
let create ?time:_ () = | ||
let ic = In_channel.open_bin "/dev/urandom" | ||
and mutex = Mutex.create () | ||
in | ||
(ic, mutex) | ||
|
||
let generate_into ~g:(ic, m) buf ~off len = | ||
let finally () = Mutex.unlock m in | ||
Mutex.lock m; | ||
Fun.protect ~finally (fun () -> | ||
match In_channel.really_input ic buf off len with | ||
| None -> failwith "couldn't read enough bytes from /dev/urandom" | ||
| Some () -> ()) | ||
|
||
let reseed ~g:_ _data = () | ||
|
||
let accumulate ~g:_ _source = | ||
`Acc (fun _data -> ()) | ||
|
||
let seeded ~g:_ = true | ||
|
||
let pools = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters