Skip to content

Commit

Permalink
mirage-crypto: skip Cipher_block / Cipher_stream module indirection
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Apr 10, 2024
1 parent 5f2d718 commit e194153
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 194 deletions.
4 changes: 1 addition & 3 deletions bench/speed.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
open Mirage_crypto

open Cipher_block

module Time = struct

let time ~n f a =
Expand Down Expand Up @@ -418,7 +416,7 @@ let runv fs =
(fun ppf -> List.iter @@ fun x ->
Format.fprintf ppf "%s " @@
match x with `XOR -> "XOR" | `AES -> "AES" | `GHASH -> "GHASH")
Cipher_block.accelerated;
accelerated;
Time.warmup () ;
List.iter (fun f -> f ()) fs

Expand Down
2 changes: 1 addition & 1 deletion rng/fortuna.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Mirage_crypto
open Mirage_crypto.Uncommon

module AES_CTR = Cipher_block.AES.CTR
module AES_CTR = AES.CTR

module SHAd256 = struct
open Digestif
Expand Down
18 changes: 9 additions & 9 deletions src/cipher_block.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Uncommon

module S = struct
module Block = struct

module type Core = sig

Expand Down Expand Up @@ -127,7 +127,7 @@ module Counters = struct
end

module Modes = struct
module ECB_of (Core : S.Core) : S.ECB = struct
module ECB_of (Core : Block.Core) : Block.ECB = struct

type key = Core.ekey * Core.dkey

Expand All @@ -148,7 +148,7 @@ module Modes = struct

end

module CBC_of (Core : S.Core) : S.CBC = struct
module CBC_of (Core : Block.Core) : Block.CBC = struct

type key = Core.ekey * Core.dkey

Expand Down Expand Up @@ -193,8 +193,8 @@ module Modes = struct

end

module CTR_of (Core : S.Core) (Ctr : Counters.S) :
S.CTR with type key = Core.ekey and type ctr = Ctr.ctr =
module CTR_of (Core : Block.Core) (Ctr : Counters.S) :
Block.CTR with type key = Core.ekey and type ctr = Ctr.ctr =
struct
(* FIXME: CTR has more room for speedups. Like stitching. *)

Expand Down Expand Up @@ -252,7 +252,7 @@ module Modes = struct
Bytes.unsafe_to_string res
end

module GCM_of (C : S.Core) : S.GCM = struct
module GCM_of (C : Block.Core) : Block.GCM = struct

let _ = assert (C.block = 16)
module CTR = CTR_of (C) (Counters.C128be32)
Expand Down Expand Up @@ -324,7 +324,7 @@ module Modes = struct
authenticate_decrypt_tag ~key ~nonce ?adata ~tag cipher
end

module CCM16_of (C : S.Core) : S.CCM16 = struct
module CCM16_of (C : Block.Core) : Block.CCM16 = struct

let _ = assert (C.block = 16)

Expand Down Expand Up @@ -365,7 +365,7 @@ end

module AES = struct

module Core : S.Core = struct
module Core : Block.Core = struct

let key = [| 16; 24; 32 |]
let block = 16
Expand Down Expand Up @@ -413,7 +413,7 @@ end

module DES = struct

module Core : S.Core = struct
module Core : Block.Core = struct

let key = [| 24 |]
let block = 8
Expand Down
2 changes: 1 addition & 1 deletion src/cipher_stream.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Uncommon

module type S = sig
module type Stream = sig
type key
type result = { message : string ; key : key }
val of_secret : string -> key
Expand Down
4 changes: 2 additions & 2 deletions src/mirage_crypto.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Uncommon = Uncommon
module Poly1305 = Poly1305.It
module type AEAD = Aead.AEAD
module Cipher_block = Cipher_block
include Cipher_block
module Chacha20 = Chacha20
module Cipher_stream = Cipher_stream
include Cipher_stream
Loading

0 comments on commit e194153

Please sign in to comment.