Expand description
§Authenticated encryption with additional data
DryocAead implements libsodium’s XChaCha20-Poly1305-IETF AEAD
construction. The chacha20poly1305_ietf module provides the RFC 8439
ChaCha20-Poly1305-IETF variant with 96-bit nonces. Both encrypt messages,
authenticate optional additional data, and use libsodium-compatible wire
formats.
Use DryocAead when you already manage nonces and need libsodium’s
ciphertext || tag wire format. Use DryocAeadEnvelope when you want
dryoc to generate a random XChaCha nonce and store it with the ciphertext as
nonce || ciphertext || tag.
XChaCha20 nonces are public, but a nonce must never repeat with the same
key. DryocAeadEnvelope generates and stores a nonce for each message;
callers using DryocAead must manage this uniqueness themselves.
If the serde feature is enabled,
serde::Deserialize and
serde::Serialize are implemented
for AeadBox and AeadEnvelope.
If the wincode feature is enabled,
wincode::SchemaRead and
wincode::SchemaWrite are
implemented for VecBox and VecEnvelope.
§Rustaceous API example
use dryoc::dryocaead::*;
let key = Key::generate();
let nonce = Nonce::generate();
let message = b"Arbitrary data to encrypt";
let aad = b"metadata";
let dryocaead =
DryocAead::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());§Generated nonce envelope example
use dryoc::dryocaead::*;
let key = Key::generate();
let message = b"Arbitrary data to encrypt";
let aad = b"metadata";
let envelope = DryocAeadEnvelope::seal_to_vec(message, Some(aad), &key).expect("seal failed");
let bytes = envelope.to_vec();
let envelope = VecEnvelope::from_bytes(&bytes).expect("from bytes");
let decrypted = envelope.open_to_vec(Some(aad), &key).expect("open failed");
assert_eq!(message, decrypted.as_slice());Re-exports§
pub use crate::types::*;
Modules§
- chacha20poly1305_
ietf - ChaCha20-Poly1305-IETF Rustaceous AEAD API.
- protected
protected - Protected memory type aliases for
AeadBoxandAeadEnvelope - xchacha20poly1305_
ietf - Algorithm-specific aliases for XChaCha20-Poly1305-IETF.
Structs§
- AeadBox
- Authenticated encrypted data for a concrete AEAD algorithm.
- Aead
Envelope - Authenticated encrypted data with its nonce stored alongside it.
- ChaCha20
Poly1305 Ietf - ChaCha20-Poly1305-IETF AEAD algorithm marker.
- XCha
Cha20 Poly1305 Ietf - XChaCha20-Poly1305-IETF AEAD algorithm marker.
Traits§
- Aead
Algorithm - Marker trait for AEAD algorithms supported by dryoc.
Type Aliases§
- Dryoc
Aead - XChaCha20-Poly1305-IETF AEAD box.
- Dryoc
Aead Envelope - XChaCha20-Poly1305-IETF AEAD envelope with stored nonce.
- Key
- Stack-allocated secret key for XChaCha20-Poly1305-IETF AEAD.
- Mac
- Stack-allocated authentication tag for XChaCha20-Poly1305-IETF AEAD.
- Nonce
- Stack-allocated public nonce for XChaCha20-Poly1305-IETF AEAD.
- VecBox
Vec-based XChaCha20-Poly1305-IETF AEAD box.- VecEnvelope
Vec-based XChaCha20-Poly1305-IETF AEAD envelope.