Skip to main content

Module chacha20poly1305_ietf

Module chacha20poly1305_ietf 

Source
Expand description

ChaCha20-Poly1305-IETF Rustaceous AEAD API.

A nonce must never repeat with the same key. RFC 8439 requires callers to manage these 96-bit nonces uniquely, typically with a counter, rather than generate them randomly. Accordingly, this variant does not provide the generated-nonce AeadEnvelope::seal convenience available to XChaCha20. Use AeadBox::encrypt with an explicitly managed nonce; an AeadEnvelope can store that nonce via AeadEnvelope::from_parts.

§Rustaceous API example

use dryoc::dryocaead::chacha20poly1305_ietf::*;

let key = Key::generate();
// This 96-bit nonce must be unique for every message encrypted with `key`.
let nonce = Nonce::from([0u8; 12]);
let message = b"Better three hours too soon than a minute too late.";
let aad = b"metadata";

let dryocaead =
    VecBox::encrypt_to_vecbox(message, Some(aad), &nonce, &key).expect("encrypt failed");
let bytes = dryocaead.to_vec();
let dryocaead = VecBox::from_bytes(&bytes).expect("from bytes");
let decrypted = dryocaead
    .decrypt_to_vec(Some(aad), &nonce, &key)
    .expect("decrypt failed");

assert_eq!(message, decrypted.as_slice());

Re-exports§

pub use super::AeadAlgorithm;
pub use super::AeadBox;
pub use super::AeadEnvelope;
pub use super::ChaCha20Poly1305Ietf;
pub use crate::types::*;

Modules§

protectedprotected
Protected-memory aliases for ChaCha20-Poly1305-IETF.

Type Aliases§

DryocAead
ChaCha20-Poly1305-IETF AEAD box.
DryocAeadEnvelope
ChaCha20-Poly1305-IETF AEAD envelope with stored nonce.
Key
Stack-allocated secret key.
Mac
Stack-allocated authentication tag.
Nonce
Stack-allocated public nonce.
VecBox
Vec-based ChaCha20-Poly1305-IETF AEAD box.
VecEnvelope
Vec-based ChaCha20-Poly1305-IETF AEAD envelope.