1use aead::generic_array::{typenum::U16, ArrayLength, GenericArray};
2
3const BLOCK_SIZE: usize = 16;
4pub(crate) type Block = GenericArray<u8, U16>;
5
6#[inline]
7pub(crate) fn inplace_xor<T, U>(a: &mut GenericArray<T, U>, b: &GenericArray<T, U>)
8where
9 U: ArrayLength<T>,
10 T: core::ops::BitXor<Output = T> + Copy,
11{
12 for (aa, bb) in a.as_mut_slice().iter_mut().zip(b.as_slice()) {
13 *aa = *aa ^ *bb;
14 }
15}
16
17#[inline]
21pub(crate) fn double(block: &Block) -> Block {
22 let mut v = u128::from_be_bytes((*block).into());
23 let v_hi = v >> 127;
24
25 v <<= 1;
28 v ^= v_hi ^ (v_hi << 1) ^ (v_hi << 2) ^ (v_hi << 7);
29 v.to_be_bytes().into()
30}
31
32#[inline]
36pub(crate) fn ntz(n: usize) -> usize {
37 n.trailing_zeros().try_into().unwrap()
38}
39
40#[inline]
41pub(crate) fn split_into_two_blocks(two_blocks: &mut [u8]) -> [&mut Block; 2] {
42 let (b0, b1) = two_blocks.split_at_mut(BLOCK_SIZE);
43 [b0.into(), b1.into()]
44}