Blake2B: export kmac
function.
This commit is contained in:
parent
15955dcbae
commit
f98ed35583
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user