From a224c804621e2efec5bee8e08c011471c7208ec4 Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Mon, 2 Jul 2018 10:50:47 +0200 Subject: [PATCH] Hacl: refactoring --- vendors/ocaml-hacl/src/hacl.ml | 31 +++++++++++++++++++++++++++++-- vendors/ocaml-hacl/src/hacl.mli | 30 +++--------------------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/vendors/ocaml-hacl/src/hacl.ml b/vendors/ocaml-hacl/src/hacl.ml index 61f2a789f..f908ce296 100644 --- a/vendors/ocaml-hacl/src/hacl.ml +++ b/vendors/ocaml-hacl/src/hacl.ml @@ -32,7 +32,7 @@ module Rand = struct end module Hash = struct - module type S = sig + module type HASH = sig val init : Bigstring.t -> unit val update : Bigstring.t -> Bigstring.t -> unit val update_last : Bigstring.t -> Bigstring.t -> int -> unit @@ -43,7 +43,7 @@ module Hash = struct val statebytes : int end - module Make(S: S) = struct + module Make(S: HASH) = struct type state = { state : Bigstring.t ; buf : Bigstring.t ; @@ -87,6 +87,33 @@ module Hash = struct finish st end + module type S = sig + type state + + val bytes : int + val blockbytes : int + val statebytes : int + + (** Incremental Interface *) + + val init : unit -> state + val update : state -> Bigstring.t -> unit + val finish : state -> Bigstring.t + + (** Direct Interface *) + + val digest : Bigstring.t -> Bigstring.t + + module HMAC : sig + val write : + key:Bigstring.t -> msg:Bigstring.t -> Bigstring.t -> unit + (** @raise [Invalid_argument] if argument is less than 32 bytes long *) + + val digest : + key:Bigstring.t -> msg:Bigstring.t -> Bigstring.t + end + end + module SHA256 = struct module H = Make(struct (* state -> unit *) diff --git a/vendors/ocaml-hacl/src/hacl.mli b/vendors/ocaml-hacl/src/hacl.mli index 7559c3013..c95a53709 100644 --- a/vendors/ocaml-hacl/src/hacl.mli +++ b/vendors/ocaml-hacl/src/hacl.mli @@ -28,7 +28,7 @@ module Rand : sig end module Hash : sig - module SHA256 : sig + module type S = sig type state val bytes : int @@ -55,32 +55,8 @@ module Hash : sig end end - module SHA512 : sig - type state - - val bytes : int - val blockbytes : int - val statebytes : int - - (** Incremental Interface *) - - val init : unit -> state - val update : state -> Bigstring.t -> unit - val finish : state -> Bigstring.t - - (** Direct Interface *) - - val digest : Bigstring.t -> Bigstring.t - - module HMAC : sig - val write : - key:Bigstring.t -> msg:Bigstring.t -> Bigstring.t -> unit - (** @raise [Invalid_argument] if argument is less than 32 bytes long *) - - val digest : - key:Bigstring.t -> msg:Bigstring.t -> Bigstring.t - end - end + module SHA256 : S + module SHA512 : S end module Nonce : sig