HAP.Crypto.ChaCha20 (HAP v0.1.0) View Source
Functions to encrypt/tag and decrypt/verify using the chacha20_poly1305 cipher
Link to this section Summary
Functions
Takes a binary containing encrypted data followed by a 16 byte tag, verifies the tag and decrypts the resultant data using the given key and nonce. Can take optional AAD data which is authenticated under the auth_tag but not encrypted.
Takes a plaintext binary and encrypts & tags it using the given key & nonce. Optionally takes AAD data which is authenticated under the auth tag but not included in the returned binary (it is up to the caller to convey the AAD to their counterparty).
Link to this section Types
Link to this section Functions
Specs
decrypt_and_verify(ciphertext_with_authdata(), key(), nonce(), aad()) :: {:ok, plaintext()} | {:error, String.t()}
Takes a binary containing encrypted data followed by a 16 byte tag, verifies the tag and decrypts the resultant data using the given key and nonce. Can take optional AAD data which is authenticated under the auth_tag but not encrypted.
Returns {:ok, plaintext}
or {:error, message}
Specs
encrypt_and_tag(plaintext(), key(), nonce(), aad()) :: {:ok, ciphertext_with_authdata()}
Takes a plaintext binary and encrypts & tags it using the given key & nonce. Optionally takes AAD data which is authenticated under the auth tag but not included in the returned binary (it is up to the caller to convey the AAD to their counterparty).
Returns {:ok, encrypted_data <> auth_tag}