1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use block_buffer::block_padding::{PadError, Padding, UnpadError};
macro_rules! impl_padding {
($name:ident, $pad:expr) => {
#[derive(Copy, Clone, Default)]
pub struct $name;
impl Padding for $name {
#[inline(always)]
fn pad_block(block: &mut [u8], pos: usize) -> Result<(), PadError> {
if pos >= block.len() {
Err(PadError)?
}
block[pos] = $pad;
block[pos + 1..].iter_mut().for_each(|b| *b = 0);
let n = block.len();
block[n - 1] |= 0x80;
Ok(())
}
#[inline(always)]
fn unpad(_data: &[u8]) -> Result<&[u8], UnpadError> {
unimplemented!();
}
}
};
}
impl_padding!(Keccak, 0x01);
impl_padding!(Sha3, 0x06);
impl_padding!(Shake, 0x1f);