|
| 1 | +use crate::encoding::{left_encode, right_encode}; |
| 2 | +use crate::traits::{CShake, EagerHash}; |
1 | 3 | use core::fmt; |
2 | | -use digest::block_api::{AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, Eager, ExtendableOutputCore, FixedOutputCore, UpdateCore, XofReaderCore}; |
| 4 | +use digest::block_api::{ |
| 5 | + AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, Eager, ExtendableOutputCore, |
| 6 | + FixedOutputCore, UpdateCore, XofReaderCore, |
| 7 | +}; |
3 | 8 | use digest::crypto_common::KeySizeUser; |
4 | 9 | use digest::{InvalidLength, Key, KeyInit, MacMarker, Output, OutputSizeUser}; |
5 | | -use crate::encoding::{left_encode, right_encode}; |
6 | | -use crate::traits::{CShake, EagerHash}; |
7 | 10 |
|
8 | 11 | pub struct KmacCore<D: EagerHash> { |
9 | 12 | digest: D::Core, |
@@ -45,27 +48,22 @@ impl<D: EagerHash> KmacCore<D> { |
45 | 48 | // bytepad, left_encode(w) |
46 | 49 | buffer.digest_blocks( |
47 | 50 | left_encode(D::block_size() as u64, &mut encode_buffer), |
48 | | - |blocks| digest.update_blocks(blocks) |
| 51 | + |blocks| digest.update_blocks(blocks), |
49 | 52 | ); |
50 | 53 |
|
51 | 54 | // encode_string(K), left_encode(len(K)) -- length is in bits |
52 | 55 | buffer.digest_blocks( |
53 | 56 | left_encode(8 * key.len() as u64, &mut encode_buffer), |
54 | | - |blocks| digest.update_blocks(blocks) |
| 57 | + |blocks| digest.update_blocks(blocks), |
55 | 58 | ); |
56 | 59 |
|
57 | 60 | // encode_string(K) copy K into blocks |
58 | | - buffer.digest_blocks( |
59 | | - &key, |
60 | | - |blocks| digest.update_blocks(blocks) |
61 | | - ); |
| 61 | + buffer.digest_blocks(key, |blocks| digest.update_blocks(blocks)); |
62 | 62 |
|
63 | 63 | // bytepad, pad the key to the block size |
64 | 64 | digest.update_blocks(&[buffer.pad_with_zeros()]); |
65 | 65 |
|
66 | | - Self { |
67 | | - digest, |
68 | | - } |
| 66 | + Self { digest } |
69 | 67 | } |
70 | 68 | } |
71 | 69 |
|
@@ -95,7 +93,7 @@ impl<D: EagerHash> KmacCore<D> { |
95 | 93 | // right_encode(L), where L = output length in bits |
96 | 94 | buffer.digest_blocks( |
97 | 95 | right_encode(8 * out.len() as u64, &mut [0u8; 9]), |
98 | | - |blocks| self.update_blocks(blocks) |
| 96 | + |blocks| self.update_blocks(blocks), |
99 | 97 | ); |
100 | 98 |
|
101 | 99 | let mut reader = self.digest.finalize_xof_core(buffer); |
@@ -126,10 +124,9 @@ impl<D: EagerHash> ExtendableOutputCore for KmacCore<D> { |
126 | 124 | #[inline(always)] |
127 | 125 | fn finalize_xof_core(&mut self, buffer: &mut Buffer<Self>) -> Self::ReaderCore { |
128 | 126 | // right_encode(0), as L = 0 for extendable output |
129 | | - buffer.digest_blocks( |
130 | | - right_encode(0, &mut [0u8; 9]), |
131 | | - |blocks| self.update_blocks(blocks) |
132 | | - ); |
| 127 | + buffer.digest_blocks(right_encode(0, &mut [0u8; 9]), |blocks| { |
| 128 | + self.update_blocks(blocks) |
| 129 | + }); |
133 | 130 | self.digest.finalize_xof_core(buffer) |
134 | 131 | } |
135 | 132 | } |
|
0 commit comments