Expand description
§ChaCha20-Poly1305-IETF authenticated encryption
Implements libsodium’s crypto_aead_chacha20poly1305_ietf_* functions.
This construction authenticates optional additional data, appends the
authentication tag in combined mode, and uses 96-bit public nonces as
specified by RFC 8439. This is not the legacy 64-bit-nonce construction.
§Classic API example
use dryoc::classic::crypto_aead_chacha20poly1305_ietf::*;
use dryoc::constants::{
CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES, CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES,
};
use dryoc::types::*;
let key = crypto_aead_chacha20poly1305_ietf_keygen();
// This 96-bit nonce must be unique for every message encrypted with `key`.
let nonce = [0u8; CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES];
let message =
b"Our doubts are traitors, and make us lose the good we oft might win, by fearing to attempt.";
let aad = b"metadata";
let mut ciphertext = vec![0u8; message.len() + CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES];
crypto_aead_chacha20poly1305_ietf_encrypt(&mut ciphertext, message, Some(aad), &nonce, &key)
.expect("encrypt failed");
let mut decrypted = vec![0u8; message.len()];
crypto_aead_chacha20poly1305_ietf_decrypt(&mut decrypted, &ciphertext, Some(aad), &nonce, &key)
.expect("decrypt failed");
assert_eq!(message, decrypted.as_slice());Functions§
- crypto_
aead_ chacha20poly1305_ ietf_ decrypt - Decrypts
ciphertextwithnonce,key, and optional associated data. - crypto_
aead_ chacha20poly1305_ ietf_ decrypt_ detached - Detached version of
crypto_aead_chacha20poly1305_ietf_decrypt. - crypto_
aead_ chacha20poly1305_ ietf_ decrypt_ detached_ inplace - In-place detached variant of
crypto_aead_chacha20poly1305_ietf_decrypt_detached. - crypto_
aead_ chacha20poly1305_ ietf_ decrypt_ inplace - Decrypts
datain place after verifying the appended authentication tag. - crypto_
aead_ chacha20poly1305_ ietf_ encrypt - Encrypts
messagewithnonce,key, and optional associated data. - crypto_
aead_ chacha20poly1305_ ietf_ encrypt_ detached - Detached version of
crypto_aead_chacha20poly1305_ietf_encrypt. - crypto_
aead_ chacha20poly1305_ ietf_ encrypt_ detached_ inplace - In-place detached variant of
crypto_aead_chacha20poly1305_ietf_encrypt_detached. - crypto_
aead_ chacha20poly1305_ ietf_ encrypt_ inplace - Encrypts
datain place and appends the authentication tag. - crypto_
aead_ chacha20poly1305_ ietf_ keygen - Generates a random key using
copy_randombytes. - crypto_
aead_ chacha20poly1305_ ietf_ keygen_ inplace - In-place variant of
crypto_aead_chacha20poly1305_ietf_keygen.