diff --git a/src/keccak.rs b/src/keccak.rs index 2b997b8fa..c011a5a14 100644 --- a/src/keccak.rs +++ b/src/keccak.rs @@ -71,22 +71,23 @@ fn keccakf(st: &mut [Byte], rounds: usize) } } - fn xor>(&self, other: &State) -> State { + fn binary_map(&self, other: &State, f: F) -> State + where F: Fn(&Bit, &Bit) -> Bit, B: Borrow + { State { bits: self.bits.iter().map(|a| a.borrow()) .zip(other.bits.iter().map(|a| a.borrow())) - .map(|(a, b)| a.xor(b)) + .map(|(a, b)| f(a, b)) .collect() } } + fn xor>(&self, other: &State) -> State { + self.binary_map(other, Bit::xor) + } + fn notand>(&self, other: &State) -> State { - State { - bits: self.bits.iter().map(|a| a.borrow()) - .zip(other.bits.iter().map(|a| a.borrow())) - .map(|(a, b)| a.notand(b)) - .collect() - } + self.binary_map(other, Bit::notand) } fn rotl(&self, by: usize) -> State {