1use crate::Permutation;
2
3macro_rules! define_keccak_state {
4 ($ty:ident, $length:expr, $pty:ty, $kf:ident) => {
5 #[derive(Clone, Debug)]
6 #[repr(align(8))]
7 pub struct $ty([u8; 200]);
9
10 impl Default for $ty {
11 fn default() -> Self {
12 Self([0u8; 200])
13 }
14 }
15
16 impl Permutation for $ty {
17 fn permute(&mut self) {
18 let s = unsafe { &mut *(self as *mut Self as *mut [$pty; 25]) };
19
20 crate::$kf(s);
21 }
22 }
23
24 impl AsRef<[u8]> for $ty {
25 fn as_ref(&self) -> &[u8] {
26 &self.0
27 }
28 }
29 };
30}
31
32define_keccak_state!(Keccak1600State, 200, u64, keccakf1600);
33define_keccak_state!(Keccak800State, 100, u32, keccakf800);
34define_keccak_state!(Keccak400State, 50, u16, keccakf400);
35define_keccak_state!(Keccak200State, 25, u8, keccakf200);