-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use defunctorised version of the rng (#257)
* add next generation mirage-crypto-rng-mirage * Defunctorise mirage-crypto-rng-mirage, use mirage-sleep and mirage-mtime instead * fix test * adapt to mirage how it'll be in the future (no functor)
- Loading branch information
Showing
8 changed files
with
76 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
module Main (R : Mirage_crypto_rng_mirage.S) = struct | ||
let start _r = | ||
Logs.info (fun m -> m "using Fortuna, entropy sources: %a" | ||
Fmt.(list ~sep:(any ", ") Mirage_crypto_rng.Entropy.pp_source) | ||
(Mirage_crypto_rng.Entropy.sources ())) ; | ||
Logs.info (fun m -> m "64 byte random:@ %a" (Ohex.pp_hexdump ()) | ||
(R.generate 64)) ; | ||
let n = Bytes.(unsafe_to_string (create 32)) in | ||
let key = Mirage_crypto.Chacha20.of_secret n | ||
and nonce = Bytes.(unsafe_to_string (create 12)) | ||
in | ||
Logs.info (fun m -> m "Chacha20/Poly1305 of 32*0, key 32*0, nonce 12*0: %a" | ||
(Ohex.pp_hexdump ()) | ||
(Mirage_crypto.Chacha20.authenticate_encrypt ~key ~nonce n)); | ||
let key = Mirage_crypto_pk.Rsa.generate ~bits:4096 () in | ||
let signature = | ||
Mirage_crypto_pk.Rsa.PKCS1.sign ~hash:`SHA256 ~key (`Message n) | ||
in | ||
let verified = | ||
let key = Mirage_crypto_pk.Rsa.pub_of_priv key in | ||
let hashp = function `SHA256 -> true | _ -> false in | ||
Mirage_crypto_pk.Rsa.PKCS1.verify ~hashp ~key ~signature (`Message n) | ||
in | ||
Logs.info (fun m -> m "Generated a RSA key of %d bits (sign + verify %B)" | ||
(Mirage_crypto_pk.Rsa.priv_bits key) verified); | ||
Lwt.return_unit | ||
end | ||
let start () = | ||
Logs.info (fun m -> m "using Fortuna, entropy sources: %a" | ||
Fmt.(list ~sep:(any ", ") Mirage_crypto_rng.Entropy.pp_source) | ||
(Mirage_crypto_rng.Entropy.sources ())) ; | ||
Logs.info (fun m -> m "64 byte random:@ %a" (Ohex.pp_hexdump ()) | ||
(Mirage_crypto_rng.generate 64)) ; | ||
let n = Bytes.(unsafe_to_string (create 32)) in | ||
let key = Mirage_crypto.Chacha20.of_secret n | ||
and nonce = Bytes.(unsafe_to_string (create 12)) | ||
in | ||
Logs.info (fun m -> m "Chacha20/Poly1305 of 32*0, key 32*0, nonce 12*0: %a" | ||
(Ohex.pp_hexdump ()) | ||
(Mirage_crypto.Chacha20.authenticate_encrypt ~key ~nonce n)); | ||
let key = Mirage_crypto_pk.Rsa.generate ~bits:4096 () in | ||
let signature = | ||
Mirage_crypto_pk.Rsa.PKCS1.sign ~hash:`SHA256 ~key (`Message n) | ||
in | ||
let verified = | ||
let key = Mirage_crypto_pk.Rsa.pub_of_priv key in | ||
let hashp = function `SHA256 -> true | _ -> false in | ||
Mirage_crypto_pk.Rsa.PKCS1.verify ~hashp ~key ~signature (`Message n) | ||
in | ||
Logs.info (fun m -> m "Generated a RSA key of %d bits (sign + verify %B)" | ||
(Mirage_crypto_pk.Rsa.priv_bits key) verified); | ||
Lwt.return_unit |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
(library | ||
(name mirage_crypto_rng_mirage) | ||
(public_name mirage-crypto-rng-mirage) | ||
(libraries lwt mirage-runtime mirage-crypto-rng mirage-time mirage-clock | ||
(libraries lwt mirage-runtime mirage-crypto-rng mirage-sleep mirage-mtime | ||
duration logs)) |
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