Blake2B: export kmac function.

This commit is contained in:
Arthur B 2018-03-15 13:25:38 -04:00 committed by Grégoire Henry
parent 15955dcbae
commit f98ed35583
4 changed files with 12 additions and 10 deletions

View File

@ -16,8 +16,8 @@ module Raw = struct
let extract bh =
MBytes.substring (Block_hash.to_bytes bh) 0 4
let hash_bytes l = extract (Block_hash.hash_bytes l)
let hash_string l = extract (Block_hash.hash_string l)
let hash_bytes ?key l = extract (Block_hash.hash_bytes ?key l)
let hash_string ?key l = extract (Block_hash.hash_string ?key l)
let size = 4

View File

@ -73,13 +73,15 @@ module Make_minimal (K : Name) = struct
let read src off = of_bytes_exn @@ MBytes.sub src off size
let write dst off h = MBytes.blit (to_bytes h) 0 dst off size
let hash_bytes l =
let state = Blake2b.init size in
let hash_bytes ?key l =
let key = Option.map ~f:Cstruct.of_bigarray key in
let state = Blake2b.init ?key size in
List.iter (fun b -> Blake2b.update state (Cstruct.of_bigarray b)) l ;
Blake2b.final state
let hash_string l =
let state = Blake2b.init size in
let hash_string ?key l =
let key = Option.map ~f:Cstruct.of_string key in
let state = Blake2b.init ?key size in
List.iter (fun s -> Blake2b.update state (Cstruct.of_string s)) l ;
Blake2b.final state

View File

@ -23,8 +23,8 @@ module type MINIMAL_HASH = sig
val name: string
val title: string
val hash_bytes: Cstruct.buffer list -> t
val hash_string: string list -> t
val hash_bytes: ?key:Cstruct.buffer -> Cstruct.buffer list -> t
val hash_string: ?key:string -> string list -> t
val size: int (* in bytes *)
val compare: t -> t -> int
val equal: t -> t -> bool

View File

@ -49,8 +49,8 @@ module type MINIMAL_HASH = sig
val name: string
val title: string
val hash_bytes: MBytes.t list -> t
val hash_string: string list -> t
val hash_bytes: ?key:MBytes.t -> MBytes.t list -> t
val hash_string: ?key:string -> string list -> t
val size: int (* in bytes *)
val compare: t -> t -> int
val equal: t -> t -> bool