Expand description
§XChaCha20-Poly1305-IETF authenticated encryption
Implements libsodium’s crypto_aead_xchacha20poly1305_ietf_* functions.
This construction authenticates optional additional data, appends the
authentication tag in combined mode, and uses 192-bit public nonces.
§Compatibility note
This module follows libsodium’s XChaCha20-Poly1305-IETF API and message
size limit. The _ietf suffix refers to the RFC 8439 AEAD layout and
Poly1305 input format; libsodium’s XChaCha implementation uses an
extended-counter XChaCha20 stream so it can support larger individual
messages than plain ChaCha20-Poly1305-IETF.
§Classic API example
use dryoc::classic::crypto_aead_xchacha20poly1305_ietf::*;
use dryoc::constants::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES;
use dryoc::types::*;
let key = crypto_aead_xchacha20poly1305_ietf_keygen();
let nonce = Nonce::generate();
let message = b"hello";
let aad = b"metadata";
let mut ciphertext = vec![0u8; message.len() + CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES];
crypto_aead_xchacha20poly1305_ietf_encrypt(&mut ciphertext, message, Some(aad), &nonce, &key)
.expect("encrypt failed");
let mut decrypted = vec![0u8; message.len()];
crypto_aead_xchacha20poly1305_ietf_decrypt(
&mut decrypted,
&ciphertext,
Some(aad),
&nonce,
&key,
)
.expect("decrypt failed");
assert_eq!(message, decrypted.as_slice());Functions§
- crypto_
aead_ xchacha20poly1305_ ietf_ decrypt - Decrypts
ciphertextwithnonce,key, and optional associated data. - crypto_
aead_ xchacha20poly1305_ ietf_ decrypt_ detached - Detached version of
crypto_aead_xchacha20poly1305_ietf_decrypt. - crypto_
aead_ xchacha20poly1305_ ietf_ decrypt_ detached_ inplace - In-place detached variant of
crypto_aead_xchacha20poly1305_ietf_decrypt_detached. - crypto_
aead_ xchacha20poly1305_ ietf_ decrypt_ inplace - Decrypts
datain place after verifying the appended authentication tag. - crypto_
aead_ xchacha20poly1305_ ietf_ encrypt - Encrypts
messagewithnonce,key, and optional associated data. - crypto_
aead_ xchacha20poly1305_ ietf_ encrypt_ detached - Detached version of
crypto_aead_xchacha20poly1305_ietf_encrypt. - crypto_
aead_ xchacha20poly1305_ ietf_ encrypt_ detached_ inplace - In-place detached variant of
crypto_aead_xchacha20poly1305_ietf_encrypt_detached. - crypto_
aead_ xchacha20poly1305_ ietf_ encrypt_ inplace - Encrypts
datain place and appends the authentication tag. - crypto_
aead_ xchacha20poly1305_ ietf_ keygen - Generates a random key using
copy_randombytes. - crypto_
aead_ xchacha20poly1305_ ietf_ keygen_ inplace - In-place variant of
crypto_aead_xchacha20poly1305_ietf_keygen.