pub struct ChaCha20Blake3 { /* private fields */ }Expand description
ChaCha20-BLAKE3 AEAD (encrypt-then-MAC).
The master key and nonce are fed through a BLAKE3-based KDF to derive a ChaCha20 encryption key, a ChaCha20 nonce, and an authentication key. The plaintext is encrypted with ChaCha20 and then MACed with BLAKE3(keyed, aad || len(aad) || ciphertext || len(ciphertext)).
§Parameters
- Key: 256 bits (32 bytes)
- Nonce: 256 bits (32 bytes)
- Tag: 256 bits (32 bytes)
§Panics
encrypt_in_place and
decrypt_in_place panic if the nonce is
not exactly 32 bytes.
§Example
use crypto::{Aead, chacha::ChaCha20Blake3};
let key = [0xab; 32];
let nonce = [0xcd; 32];
let aad = b"associated data";
let plaintext = b"hello world";
let cipher = ChaCha20Blake3::new(&key);
let mut buf = plaintext.to_vec();
let tag = cipher.encrypt_in_place(&mut buf, &nonce, aad);
// buf now holds the ciphertext; tag is the 32-byte authentication tag.
cipher.decrypt_in_place(&mut buf, &nonce, aad, tag.as_ref())
.expect("decryption failed");
assert_eq!(&buf, plaintext);Implementations§
Trait Implementations§
Source§impl Aead for ChaCha20Blake3
impl Aead for ChaCha20Blake3
const TAG_SIZE: usize = 32
const NONCE_SIZE: usize = 32
fn encrypt_in_place(&self, in_out: &mut [u8], nonce: &[u8], aad: &[u8]) -> Hash
fn decrypt_in_place( &self, in_out: &mut [u8], nonce: &[u8], aad: &[u8], tag: &[u8], ) -> Result<(), AeadError>
fn encrypt(&self, plaintext: &[u8], nonce: &[u8], aad: &[u8]) -> Vec<u8> ⓘ
fn decrypt( &self, ciphertext: &[u8], nonce: &[u8], aad: &[u8], ) -> Result<Vec<u8>, AeadError>
Source§impl Drop for ChaCha20Blake3
impl Drop for ChaCha20Blake3
Auto Trait Implementations§
impl Freeze for ChaCha20Blake3
impl RefUnwindSafe for ChaCha20Blake3
impl Send for ChaCha20Blake3
impl Sync for ChaCha20Blake3
impl Unpin for ChaCha20Blake3
impl UnsafeUnpin for ChaCha20Blake3
impl UnwindSafe for ChaCha20Blake3
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more