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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::{bits_to_rate, keccakf::KeccakF, Hasher, KeccakState, Xof};
#[derive(Clone)]
pub struct Shake {
state: KeccakState<KeccakF>,
}
impl Shake {
const DELIM: u8 = 0x1f;
pub fn v128() -> Shake {
Shake::new(128)
}
pub fn v256() -> Shake {
Shake::new(256)
}
pub(crate) fn new(bits: usize) -> Shake {
Shake {
state: KeccakState::new(bits_to_rate(bits), Self::DELIM),
}
}
}
impl Hasher for Shake {
fn update(&mut self, input: &[u8]) {
self.state.update(input);
}
fn finalize(self, output: &mut [u8]) {
self.state.finalize(output);
}
}
impl Xof for Shake {
fn squeeze(&mut self, output: &mut [u8]) {
self.state.squeeze(output)
}
}