package mirage-crypto

  1. Overview
  2. Docs
val digest_size : int

Size of digests (in bytes).

Core operations

type t

Represents a running hash computation in a way suitable for appending inputs.

val empty : t

empty is the hash of the empty string.

val feed : t -> Cstruct.t -> t

feed t msg adds the information in msg to t.

feed is analogous to appending: feed (feed t msg1) msg2 = feed t (Cstruct.append msg1 msg2).

val get : t -> digest

get t is the digest corresponding to t.

HMAC operations

type hmac

Represents a running hmac computation in a way suitable for appending inputs.

val hmac_empty : key:Cstruct.t -> hmac

hmac ~key is the hmac of the empty string using key key.

val hmac_feed : hmac -> Cstruct.t -> hmac

feed hmac msg is analogous to feed.

val hmac_get : hmac -> digest

hmac_get hmac is the hmac corresponding to hmac.

All-in-one

Functions that operate on data stored in a single chunk.

val digest : Cstruct.t -> digest

digest msg is the digest of msg.

digest msg = get (feed empty msg)

val hmac : key:Cstruct.t -> Cstruct.t -> digest

hmac ~key bytes is the authentication code for bytes under the secret key, generated using the standard HMAC construction over this hash algorithm.

Functions over iterators

Functions that operate on arbitrary iterators. They can serve as a basis for other, more specialized aggregate hashing operations.

These functions are a little faster than using feed directly.

val feedi : t -> Cstruct.t iter -> t

feedi t iter = (let r = ref t in iter (fun msg -> r := feed !r msg); !r)

val digesti : Cstruct.t iter -> digest

digesti iter = feedi empty iter |> get

val hmaci : key:Cstruct.t -> Cstruct.t iter -> digest

See hmac.

OCaml

Innovation. Community. Security.