#[cfg(target_arch = "x86_64")]
pub use x86::*;
#[cfg(target_arch = "x86_64")]
mod x86 {
use crate::chacha::{poly_avx2, zmm};
use core::arch::x86_64::*;
use core::mem::ManuallyDrop;
pub unsafe fn chacha20_zmm_group(
key: &[u8; 32],
nonce: &[u8; 12],
counter: u32,
data: &mut [u8; zmm::STRIDE],
) {
let start = ManuallyDrop::new(zmm::Start::new(key, nonce, counter));
unsafe { zmm::group(&start, data) }
}
#[inline]
#[target_feature(enable = "avx2")]
unsafe fn limbs(h: &[[u64; 4]; 5]) -> poly_avx2::Limbs {
core::array::from_fn(|j| unsafe { _mm256_loadu_si256(h[j].as_ptr() as *const __m256i) })
}
#[target_feature(enable = "avx2")]
pub unsafe fn poly1305_avx2_step(
h: &[[u64; 4]; 5],
r4: &[u32; 5],
blocks: &[u8; 64],
) -> [[u64; 4]; 5] {
let next = unsafe { poly_avx2::step(&limbs(h), &poly_avx2::Mul::splat(r4), blocks) };
let mut out = [[0u64; 4]; 5];
for (o, v) in out.iter_mut().zip(next) {
unsafe { _mm256_storeu_si256(o.as_mut_ptr() as *mut __m256i, v) };
}
out
}
#[target_feature(enable = "avx2")]
pub unsafe fn poly1305_avx2_finish(h: &[[u64; 4]; 5], powers: &[[u32; 5]; 4]) -> [u64; 5] {
let last = poly_avx2::Mul::lanes([&powers[0], &powers[1], &powers[2], &powers[3]]);
unsafe { poly_avx2::finish(&limbs(h), &last) }
}
}