libsodium_crypto_aead_aegis128l (libsodium v3.0.1)
View SourceAEGIS-128L authenticated encryption with additional data. AEGIS is very
fast on CPUs with AES instructions (libsodium falls back to a portable
implementation elsewhere) and produces abytes/0 (32) byte tags.
Keys are keybytes/0 (16) bytes and nonces npubbytes/0 (16) bytes. A
nonce must never be reused with the same key; random nonces (for example
from libsodium_randombytes:buf/1) are safe for a large number of
messages, but libsodium_crypto_aead_aegis256 has a longer nonce and
is the better choice when many messages are encrypted under one key.
Key = libsodium_crypto_aead_aegis128l:keygen(),
Nonce = libsodium_randombytes:buf(libsodium_crypto_aead_aegis128l:npubbytes()),
Ciphertext = libsodium_crypto_aead_aegis128l:encrypt(<<"message">>, <<"header">>, Nonce, Key),
<<"message">> = libsodium_crypto_aead_aegis128l:decrypt(Ciphertext, <<"header">>, Nonce, Key).
Summary
Types
A crypto_aead_aegis128l_KEYBYTES (16-byte) binary.
A crypto_aead_aegis128l_ABYTES (32-byte) binary.
A crypto_aead_aegis128l_NPUBBYTES (16-byte) binary.
Functions
Return crypto_aead_aegis128l_abytes(), in bytes.
Verify and decrypt the ciphertext C with the additional data AD
(default empty), nonce NPub, and key K.
Verify and decrypt the ciphertext C with the additional data AD
(default empty), nonce NPub, and key K.
Verify the detached abytes/0 byte tag MAC and decrypt C with the
additional data AD (default empty), nonce NPub, and key K.
Returns the plaintext, or -1 when verification fails.
Verify the detached abytes/0 byte tag MAC and decrypt C with the
additional data AD (default empty), nonce NPub, and key K.
Returns the plaintext, or -1 when verification fails.
Encrypt and authenticate M together with the additional data AD
(default empty) using the npubbytes/0 byte nonce NPub and the
keybytes/0 byte key K.
Encrypt and authenticate M together with the additional data AD
(default empty) using the npubbytes/0 byte nonce NPub and the
keybytes/0 byte key K.
Encrypt and authenticate M with the additional data AD (default
empty), nonce NPub, and key K, returning the ciphertext and the
abytes/0 byte authentication tag separately as {C, MAC}, or -1
on failure.
Encrypt and authenticate M with the additional data AD (default
empty), nonce NPub, and key K, returning the ciphertext and the
abytes/0 byte authentication tag separately as {C, MAC}, or -1
on failure.
Return crypto_aead_aegis128l_keybytes(), in bytes.
Generate a random keybytes/0 byte key.
Return crypto_aead_aegis128l_messagebytes_max(), in bytes.
Return crypto_aead_aegis128l_npubbytes(), in bytes.
Return crypto_aead_aegis128l_nsecbytes(), in bytes.
Types
Functions
-spec abytes() -> Result when Result :: 32.
Return crypto_aead_aegis128l_abytes(), in bytes.
-spec decrypt(C, NPub, K) -> Result when C :: binary(), NPub :: npub(), K :: k(), Result :: binary() | -1.
Verify and decrypt the ciphertext C with the additional data AD
(default empty), nonce NPub, and key K.
Returns the plaintext, or -1 when verification fails.
-spec decrypt(C, AD, NPub, K) -> Result when C :: binary(), AD :: binary(), NPub :: npub(), K :: k(), Result :: binary() | -1.
Verify and decrypt the ciphertext C with the additional data AD
(default empty), nonce NPub, and key K.
Returns the plaintext, or -1 when verification fails.
-spec decrypt_detached(C, MAC, NPub, K) -> Result when C :: binary(), MAC :: mac(), NPub :: npub(), K :: k(), Result :: binary() | -1.
Verify the detached abytes/0 byte tag MAC and decrypt C with the
additional data AD (default empty), nonce NPub, and key K.
Returns the plaintext, or -1 when verification fails.
-spec decrypt_detached(C, MAC, AD, NPub, K) -> Result when C :: binary(), MAC :: mac(), AD :: binary(), NPub :: npub(), K :: k(), Result :: binary() | -1.
Verify the detached abytes/0 byte tag MAC and decrypt C with the
additional data AD (default empty), nonce NPub, and key K.
Returns the plaintext, or -1 when verification fails.
-spec encrypt(M, NPub, K) -> Result when M :: binary(), NPub :: npub(), K :: k(), Result :: binary() | -1.
Encrypt and authenticate M together with the additional data AD
(default empty) using the npubbytes/0 byte nonce NPub and the
keybytes/0 byte key K.
Returns the ciphertext followed by an abytes/0 byte authentication
tag, or -1 on failure.
-spec encrypt(M, AD, NPub, K) -> Result when M :: binary(), AD :: binary(), NPub :: npub(), K :: k(), Result :: binary() | -1.
Encrypt and authenticate M together with the additional data AD
(default empty) using the npubbytes/0 byte nonce NPub and the
keybytes/0 byte key K.
Returns the ciphertext followed by an abytes/0 byte authentication
tag, or -1 on failure.
-spec encrypt_detached(M, NPub, K) -> Result when M :: binary(), NPub :: npub(), K :: k(), Result :: {binary(), mac()} | -1.
Encrypt and authenticate M with the additional data AD (default
empty), nonce NPub, and key K, returning the ciphertext and the
abytes/0 byte authentication tag separately as {C, MAC}, or -1
on failure.
-spec encrypt_detached(M, AD, NPub, K) -> Result when M :: binary(), AD :: binary(), NPub :: npub(), K :: k(), Result :: {binary(), mac()} | -1.
Encrypt and authenticate M with the additional data AD (default
empty), nonce NPub, and key K, returning the ciphertext and the
abytes/0 byte authentication tag separately as {C, MAC}, or -1
on failure.
-spec keybytes() -> Result when Result :: 16.
Return crypto_aead_aegis128l_keybytes(), in bytes.
-spec keygen() -> Result when Result :: k().
Generate a random keybytes/0 byte key.
-spec messagebytes_max() -> Result when Result :: non_neg_integer().
Return crypto_aead_aegis128l_messagebytes_max(), in bytes.
-spec npubbytes() -> Result when Result :: 16.
Return crypto_aead_aegis128l_npubbytes(), in bytes.
-spec nsecbytes() -> Result when Result :: 0.
Return crypto_aead_aegis128l_nsecbytes(), in bytes.