Module EverCrypt.AEAD
Agile, multiplexing AEAD interface exposing AES128-GCM, AES256-GCM, and Chacha20-Poly1305
To use the agile AEAD interface, users first need to initialise an internal state using init
. This state will then need to be passed to every call to encrypt
and decrypt
. It can be reused as many times as needed. Users are not required to manually free the state.
The tag
buffer must be 16 bytes long. For key
and iv
, each algorithm has different constraints:
- AES128-GCM:
key
= 16 bytes ,iv
> 0 bytes - AES256-GCM:
key
= 32 bytes,iv
> 0 bytes - Chacha20-Poly1305:
key
= 32 bytes,iv
= 12 bytes
val init : alg:SharedDefs.AEADDefs.alg -> key:bytes -> t Error.result
init alg key
tries to allocate the internal state for algorithmalg
withkey
and returns at
if successful or anError.error_code
otherwise.
val encrypt : st:t -> iv:bytes -> ad:bytes -> pt:bytes -> (bytes * bytes) Error.result
encrypt key iv ad pt
takes akey
, an initial valueiv
, additional dataad
, and plaintextpt
and, if successful, returns a tuple containing the encryptedpt
and the authentication tag for the plaintext and the associated data.
val decrypt : st:t -> iv:bytes -> ad:bytes -> ct:bytes -> tag:bytes -> bytes Error.result
decrypt key iv ad ct tag
takes akey
, the initial valueiv
, additional dataad
, ciphertextct
, and authentication tagtag
, and, if successful, returns the decryptedct
.
module Noalloc : sig ... end
Versions of these functions which write their output in a buffer passed in as an argument