Module Webs_kit.Sha_256
SHA-256 hashes, HMAC-SHA-256 and PBKDF2-HMAC-SHA-256
Hash values
val length : t -> int
length h
is the length ofh
in bytes (i.e. 32)
val hash : string -> t
hash s
is the SHA-256 hash ofs
.
HMAC-SHA-256
PBKDF2-HMAC-SHA-256
val pbkdf2_hmac : key_len:int -> count:int -> pass:string -> salt:string -> unit -> string
pbkdf2_hmac ~key_len ~count ~pass ~salt ()
derives a key for passwordpass
with a saltsalt
and countcount
iterations (use at least100_000
) to generate a key of lengthkey_len
using RFC 8018's PBKFD2-HMAC-SHA-256.Raises
Invalid_argument
ifkey_len
orcount
are smaller or equal to0
or ifkey_len
is greater than 232 - 1 * 32 ormax_int
.
Predicates and comparisons
Converting
val to_bytes : t -> string
to_bytes h
is the sequence of bytes ofh
.
val of_bytes : string -> (t, unit) Stdlib.result
of_bytes s
is the sequence of bytes ofs
as a hash value. An error is returned if the length ofs
in not 32.
val to_hex : t -> string
to_ascii_hex h
is the sequence of bytes ofh
as US-ASCII lowercase hexadecimal digits.
val of_hex : string -> (t, int) Stdlib.result
of_hex s
parses a sequence of US-ASCII (lower or upper cased) hexadecimal digits to its hash value. Errors with an offending index or the length of the string in cases
was not exactly made of 64 US-ASCII hex digits.