use crate::error::{check, WolfCryptError};
pub fn aes_eax_encrypt(
key: &[u8],
nonce: &[u8],
aad: &[u8],
plaintext: &[u8],
ciphertext: &mut [u8],
tag: &mut [u8],
) -> Result<(), WolfCryptError> {
if ciphertext.len() < plaintext.len() {
return Err(WolfCryptError::InvalidInput);
}
if tag.is_empty() {
return Err(WolfCryptError::InvalidInput);
}
let rc = unsafe {
wolfcrypt_rs::wc_AesEaxEncryptAuth(
key.as_ptr(),
key.len() as u32,
ciphertext.as_mut_ptr(),
plaintext.as_ptr(),
plaintext.len() as u32,
nonce.as_ptr(),
nonce.len() as u32,
tag.as_mut_ptr(),
tag.len() as u32,
aad.as_ptr(),
aad.len() as u32,
)
};
check(rc, "wc_AesEaxEncryptAuth")?;
Ok(())
}
pub fn aes_eax_decrypt(
key: &[u8],
nonce: &[u8],
aad: &[u8],
ciphertext: &[u8],
plaintext: &mut [u8],
tag: &[u8],
) -> Result<(), WolfCryptError> {
if plaintext.len() < ciphertext.len() {
return Err(WolfCryptError::InvalidInput);
}
if tag.is_empty() {
return Err(WolfCryptError::InvalidInput);
}
let rc = unsafe {
wolfcrypt_rs::wc_AesEaxDecryptAuth(
key.as_ptr(),
key.len() as u32,
plaintext.as_mut_ptr(),
ciphertext.as_ptr(),
ciphertext.len() as u32,
nonce.as_ptr(),
nonce.len() as u32,
tag.as_ptr(),
tag.len() as u32,
aad.as_ptr(),
aad.len() as u32,
)
};
check(rc, "wc_AesEaxDecryptAuth")?;
Ok(())
}