Hacl: refactoring

This commit is contained in:
Vincent Bernardoff 2018-07-02 10:50:47 +02:00 committed by Grégoire Henry
parent 928ee9d3a0
commit a224c80462
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2
2 changed files with 32 additions and 29 deletions

View File

@ -32,7 +32,7 @@ module Rand = struct
end end
module Hash = struct module Hash = struct
module type S = sig module type HASH = sig
val init : Bigstring.t -> unit val init : Bigstring.t -> unit
val update : Bigstring.t -> Bigstring.t -> unit val update : Bigstring.t -> Bigstring.t -> unit
val update_last : Bigstring.t -> Bigstring.t -> int -> unit val update_last : Bigstring.t -> Bigstring.t -> int -> unit
@ -43,7 +43,7 @@ module Hash = struct
val statebytes : int val statebytes : int
end end
module Make(S: S) = struct module Make(S: HASH) = struct
type state = { type state = {
state : Bigstring.t ; state : Bigstring.t ;
buf : Bigstring.t ; buf : Bigstring.t ;
@ -87,6 +87,33 @@ module Hash = struct
finish st finish st
end 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 SHA256 = struct
module H = Make(struct module H = Make(struct
(* state -> unit *) (* state -> unit *)

View File

@ -28,7 +28,7 @@ module Rand : sig
end end
module Hash : sig module Hash : sig
module SHA256 : sig module type S = sig
type state type state
val bytes : int val bytes : int
@ -55,32 +55,8 @@ module Hash : sig
end end
end end
module SHA512 : sig module SHA256 : S
type state module SHA512 : S
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
end end
module Nonce : sig module Nonce : sig