libsodium_crypto_aead_aegis256 (libsodium v3.0.1)
View SourceAEGIS-256 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 (32) bytes and nonces npubbytes/0 (32) bytes. The
nonce is long enough to be generated at random for every message (for
example with libsodium_randombytes:buf/1) without practical risk of
collision, though a nonce must still never be reused with the same key.
Key = libsodium_crypto_aead_aegis256:keygen(),
Nonce = libsodium_randombytes:buf(libsodium_crypto_aead_aegis256:npubbytes()),
Ciphertext = libsodium_crypto_aead_aegis256:encrypt(<<"message">>, <<"header">>, Nonce, Key),
<<"message">> = libsodium_crypto_aead_aegis256:decrypt(Ciphertext, <<"header">>, Nonce, Key).
Summary
Types
A crypto_aead_aegis256_KEYBYTES (32-byte) binary.
A crypto_aead_aegis256_ABYTES (32-byte) binary.
A crypto_aead_aegis256_NPUBBYTES (32-byte) binary.
Functions
Return crypto_aead_aegis256_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_aegis256_keybytes(), in bytes.
Generate a random keybytes/0 byte key.
Return crypto_aead_aegis256_messagebytes_max(), in bytes.
Return crypto_aead_aegis256_npubbytes(), in bytes.
Return crypto_aead_aegis256_nsecbytes(), in bytes.
Types
Functions
-spec abytes() -> Result when Result :: 32.
Return crypto_aead_aegis256_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 :: 32.
Return crypto_aead_aegis256_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_aegis256_messagebytes_max(), in bytes.
-spec npubbytes() -> Result when Result :: 32.
Return crypto_aead_aegis256_npubbytes(), in bytes.
-spec nsecbytes() -> Result when Result :: 0.
Return crypto_aead_aegis256_nsecbytes(), in bytes.