Skip to main content

Module crypto_aead_xchacha20poly1305_ietf

Module crypto_aead_xchacha20poly1305_ietf 

Source
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 ciphertext with nonce, 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 data in place after verifying the appended authentication tag.
crypto_aead_xchacha20poly1305_ietf_encrypt
Encrypts message with nonce, 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 data in 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.

Type Aliases§

Key
Secret key for XChaCha20-Poly1305-IETF AEAD.
Mac
Authentication tag for XChaCha20-Poly1305-IETF AEAD.
Nonce
Public nonce for XChaCha20-Poly1305-IETF AEAD.