#[cfg(all(
target_feature = "pclmulqdq",
target_feature = "sse2",
target_feature = "sse4.1",
any(target_arch = "x86", target_arch = "x86_64")
))]
mod pclmulqdq;
mod u32_soft;
mod u64_soft;
#[allow(unused_imports)]
use cfg_if::cfg_if;
use core::ops::{Add, Mul};
#[cfg(all(
target_feature = "pclmulqdq",
target_feature = "sse2",
target_feature = "sse4.1",
any(target_arch = "x86", target_arch = "x86_64")
))]
use self::pclmulqdq::M128i;
#[allow(unused_imports)]
use self::u32_soft::U32x4;
#[allow(unused_imports)]
use self::u64_soft::U64x2;
#[cfg(not(all(
target_feature = "pclmulqdq",
target_feature = "sse2",
target_feature = "sse4.1",
any(target_arch = "x86", target_arch = "x86_64")
)))]
cfg_if! {
if #[cfg(target_pointer_width = "64")] {
type M128i = U64x2;
} else {
type M128i = U32x4;
}
}
type Block = [u8; 16];
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct Element(M128i);
impl Element {
pub fn from_bytes(bytes: Block) -> Self {
Element(bytes.into())
}
pub fn to_bytes(self) -> Block {
self.0.into()
}
}
impl Default for Element {
fn default() -> Self {
Self::from_bytes(Block::default())
}
}
impl Add for Element {
type Output = Self;
fn add(self, rhs: Self) -> Self {
Element(self.0 + rhs.0)
}
}
impl Mul for Element {
type Output = Self;
fn mul(self, rhs: Self) -> Self {
Element(self.0 * rhs.0)
}
}