Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
KECCAK 256 hash algorithm.
val empty : ctx
An empty hash context.
val init : unit -> ctx
Create a new hash state.
feed_bytes msg t
adds informations in msg
to t
. feed
is analogous to appending: feed (feed t msg1) msg2 = feed t (append msg1 msg2)
Same as feed_bytes
but for String.t
.
Same as feed_bytes
but for bigstring
.
feedi_bytes t iter = let r = ref t in iter (fun msg -> r := feed !r msg);
!r
Same as feed_bytes
but for String.t
.
val digest_bytes : ?off:int -> ?len:int -> Stdlib.Bytes.t -> t
digest_bytes msg
is the digest of msg
.
digest_bytes msg = get (feed_bytes empty msg)
.
val digest_string : ?off:int -> ?len:int -> Stdlib.String.t -> t
Same as digest_bytes
but for a String.t
.
Same as digest_bytes
but for a bigstring
.
Same as digesti_bytes
but for String.t
.
Same as digesti_bigstring
but for bigstring
.
val digestv_bytes : Stdlib.Bytes.t list -> t
Specialization of digesti_bytes
with a list of Bytes.t
(see iter
).
val digestv_string : Stdlib.String.t list -> t
Same as digestv_bytes
but for String.t
.
Same as digestv_bytes
but for bigstring
.
val hmac_bytes : key:string -> ?off:int -> ?len:int -> Stdlib.Bytes.t -> t
hmac_bytes ~key bytes
is the authentication code for Bytes.t
under the secret key
, generated using the standard HMAC construction over this hash algorithm.
val hmac_string : key:string -> ?off:int -> ?len:int -> Stdlib.String.t -> t
Same as hmac_bytes
but for String.t
.
Same as hmac_bytes
but for bigstring
.
Authentication code under the secret key
over a collection of Bytes.t
.
Same as hmaci_bytes
but for String.t
.
Same as hmaci_bytes
but for bigstring
.
val hmacv_bytes : key:string -> Stdlib.Bytes.t list -> t
Specialization of hmaci_bytes
with a list of Bytes.t
(see iter
).
val hmacv_string : key:string -> Stdlib.String.t list -> t
Same as hmacv_bytes
but for String.t
.
Same as hmacv_bigstring
but for bigstring
.
unsafe_compare
function returns 0
on equality and a negative/positive int
depending on the difference (like String.compare
). This is usually OK, but this is not constant time, so in some cases it could leak some information.
val of_hex : string -> t
of_hex
tries to parse an hexadecimal representation of t
. of_hex
raises an invalid_argument
when input is malformed. We take only firsts digest_size
hexadecimal values and ignore rest of input. If it has not enough hexadecimal values, trailing values of the output hash are zero (\x00
),
val of_hex_opt : string -> t option
of_hex
tries to parse an hexadecimal representation of t
. of_hex
returns None
when input is malformed. We take only first digest_size
hexadecimal values and ignore rest of input. If it has not enough hexadecimal values, trailing values of the output hash are zero (\x00
).
val consistent_of_hex : string -> t
val consistent_of_hex_opt : string -> t option
val of_raw_string : string -> t
of_raw_string s
see s
as a hash. Useful when reading serialized hashes.
val of_raw_string_opt : string -> t option
of_raw_string_opt s
see s
as a hash. Useful when reading serialized hashes. Returns None
if s
is not the digest_size
bytes long.
val to_raw_string : t -> string
to_raw_string s
is (s :> string)
.
val get_into_bytes : ctx -> ?off:int -> bytes -> unit
get_into_bytes ctx ?off buf
writes the result into the given buf
at off
(defaults to 0
).
It's equivalent to:
let get_into_bytes ctx ?(off = 0) buf =
let t = get ctx in
let str = to_raw_string t in
Bytes.blit_string str 0 buf off digest_size
except get_into_bytes
does not allocate an intermediate string.