use crate::{
Public, Secret,
errors::UnknownCryptoError,
generics::sealed::Sealed,
hazardous::{
aead::chacha20poly1305::ChaCha20Poly1305,
hpke::suite::private::HpkeAead,
mac::poly1305,
stream::chacha20::{self, ChaCha20Key, ChaCha20Nonce},
},
};
impl Sealed for ChaCha20Poly1305 {}
impl HpkeAead for ChaCha20Poly1305 {
const AEAD_ID: [u8; 2] = 0x0003u16.to_be_bytes();
const NK: usize = chacha20::CHACHA_KEYSIZE;
const NN: usize = chacha20::IETF_CHACHA_NONCESIZE;
const NT: usize = poly1305::POLY1305_OUTSIZE;
type Key = ChaCha20Key;
type Nonce = ChaCha20Nonce;
const KEY_INIT: Secret<Self::Key> = Self::Key::zero();
const NONCE_INIT: Public<Self::Nonce> = Self::Nonce::zero();
fn seal(
key: &Secret<Self::Key>,
nonce: &Public<Self::Nonce>,
plaintext: &[u8],
aad: &[u8],
out: &mut [u8],
) -> Result<(), UnknownCryptoError> {
ChaCha20Poly1305::seal(key, nonce, plaintext, Some(aad), out)
}
fn open(
key: &Secret<Self::Key>,
nonce: &Public<Self::Nonce>,
ciphertext: &[u8],
aad: &[u8],
out: &mut [u8],
) -> Result<(), UnknownCryptoError> {
ChaCha20Poly1305::open(key, nonce, ciphertext, Some(aad), out)
}
}