pub mod cmac;
pub mod hash;
pub mod prf;
pub mod prp;
pub mod simd;
pub(crate) mod stack;
use aes::cipher::{consts::U16, generic_array::GenericArray};
use aes::Block;
use thiserror::Error;
use zeroize::ZeroizeOnDrop;
const _: fn() = || {
fn assert_zeroize_on_drop<T: ZeroizeOnDrop>() {}
assert_zeroize_on_drop::<aes::Aes128Enc>();
};
pub type AesBlock = Block;
pub type PrfKey = GenericArray<u8, U16>;
pub type HashKey = GenericArray<u8, U16>;
pub const NONCE_SIZE: usize = 16;
pub trait Prf {
fn new(key: &PrfKey) -> Self;
fn encrypt_all(&self, data: &mut [AesBlock]);
}
pub trait Hash {
fn new(key: &HashKey) -> Self;
fn hash(&self, data: &[u8; 16]) -> u8;
fn hash_all_into<const D: usize, const B: usize>(
&self,
input: &mut [AesBlock; D],
out: &mut [u8; B],
);
}
pub(crate) struct Packed<const D: usize, const B: usize>;
impl<const D: usize, const B: usize> Packed<D, B> {
pub(crate) const OK: () = assert!(D == 8 * B, "Packed: D values need exactly D / 8 bytes");
}
#[derive(Debug, Error)]
#[error("PRP Error")]
pub struct PrpError;
pub type PrpResult<T> = Result<T, PrpError>;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Symbol<const D: usize>(u8);
impl<const D: usize> Symbol<D> {
const DOMAIN_OK: () = assert!(
D.is_power_of_two() && D <= 256,
"Symbol: the domain must be a power of two no larger than 256"
);
#[inline]
#[allow(clippy::let_unit_value)]
pub fn from_low_bits(b: u8) -> Self {
let () = Self::DOMAIN_OK;
Self(b & (D - 1) as u8)
}
#[inline]
pub fn get(self) -> u8 {
self.0
}
}
impl From<u8> for Symbol<256> {
#[inline]
fn from(b: u8) -> Self {
Self(b)
}
}
pub trait Prp<S>: Sized {
fn new(key: &[u8]) -> PrpResult<Self>;
fn permute(&self, data: S) -> S;
#[allow(dead_code)]
fn invert(&self, data: S) -> S;
type Mask;
fn indicator_mask_xor(&self, data: S, out: &mut Self::Mask);
}