#[inline(always)]
pub fn resize_block<const LEN: usize>(block: &[u8]) -> [u8; LEN] {
let mut output = [0u8; LEN];
(0..block.len().min(LEN)).for_each(|i| output[i] = block[i]);
output
}
#[inline(always)]
pub fn pad_input<const LEN: usize>(input: &[u8]) -> Vec<[u8; LEN]> {
let block_cnt = (input.len() + LEN - 1) / LEN;
let chunks = input.chunks_exact(LEN);
let mut result_vec = Vec::with_capacity(block_cnt);
let remainder = chunks.remainder();
chunks.for_each(|chunk| result_vec.push(chunk.try_into().unwrap()));
result_vec.push(resize_block(remainder));
result_vec
}
#[inline(always)]
pub fn xor_blocks<const LEN: usize>(lhs: &mut [u8; LEN], rhs: &[u8; LEN]) {
(0..LEN).for_each(|i| lhs[i] ^= rhs[i])
}
#[inline(always)]
pub fn inc_block<const LEN: usize>(block: &mut [u8; LEN]) {
for elem in block.iter_mut() {
*elem = elem.wrapping_add(1);
if *elem != 0 {
return;
}
}
}