/rust/registry/src/index.crates.io-6f17d22bba15001f/sha3-0.10.8/src/macros.rs
Line | Count | Source (jump to first uncovered line) |
1 | | macro_rules! impl_sha3 { |
2 | | ( |
3 | | $name:ident, $full_name:ident, $output_size:ident, |
4 | | $rate:ident, $pad:expr, $alg_name:expr $(,)? |
5 | | ) => { |
6 | | #[doc = "Core "] |
7 | | #[doc = $alg_name] |
8 | | #[doc = " hasher state."] |
9 | | #[derive(Clone)] |
10 | | #[allow(non_camel_case_types)] |
11 | | pub struct $name { |
12 | | state: Sha3State, |
13 | | } |
14 | | |
15 | | impl HashMarker for $name {} |
16 | | |
17 | | impl BlockSizeUser for $name { |
18 | | type BlockSize = $rate; |
19 | | } |
20 | | |
21 | | impl BufferKindUser for $name { |
22 | | type BufferKind = Eager; |
23 | | } |
24 | | |
25 | | impl OutputSizeUser for $name { |
26 | | type OutputSize = $output_size; |
27 | | } |
28 | | |
29 | | impl UpdateCore for $name { |
30 | | #[inline] |
31 | 7.03k | fn update_blocks(&mut self, blocks: &[Block<Self>]) { |
32 | 63.8k | for block in blocks { |
33 | 56.7k | self.state.absorb_block(block) |
34 | | } |
35 | 7.03k | } <sha3::Sha3_256Core as digest::core_api::UpdateCore>::update_blocks Line | Count | Source | 31 | 7.03k | fn update_blocks(&mut self, blocks: &[Block<Self>]) { | 32 | 63.8k | for block in blocks { | 33 | 56.7k | self.state.absorb_block(block) | 34 | | } | 35 | 7.03k | } |
Unexecuted instantiation: <sha3::Sha3_512Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::Keccak224Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::Keccak256Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::Keccak384Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::Keccak512Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::Keccak256FullCore as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::Sha3_224Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::Sha3_256Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::Sha3_384Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::Sha3_512Core as digest::core_api::UpdateCore>::update_blocks |
36 | | } |
37 | | |
38 | | impl FixedOutputCore for $name { |
39 | | #[inline] |
40 | 12.9k | fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>) { |
41 | 12.9k | let pos = buffer.get_pos(); |
42 | 12.9k | let block = buffer.pad_with_zeros(); |
43 | 12.9k | block[pos] = $pad; |
44 | 12.9k | let n = block.len(); |
45 | 12.9k | block[n - 1] |= 0x80; |
46 | 12.9k | |
47 | 12.9k | self.state.absorb_block(block); |
48 | 12.9k | |
49 | 12.9k | self.state.as_bytes(out); |
50 | 12.9k | } <sha3::Sha3_256Core as digest::core_api::FixedOutputCore>::finalize_fixed_core Line | Count | Source | 40 | 7.03k | fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>) { | 41 | 7.03k | let pos = buffer.get_pos(); | 42 | 7.03k | let block = buffer.pad_with_zeros(); | 43 | 7.03k | block[pos] = $pad; | 44 | 7.03k | let n = block.len(); | 45 | 7.03k | block[n - 1] |= 0x80; | 46 | 7.03k | | 47 | 7.03k | self.state.absorb_block(block); | 48 | 7.03k | | 49 | 7.03k | self.state.as_bytes(out); | 50 | 7.03k | } |
<sha3::Sha3_512Core as digest::core_api::FixedOutputCore>::finalize_fixed_core Line | Count | Source | 40 | 5.92k | fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>) { | 41 | 5.92k | let pos = buffer.get_pos(); | 42 | 5.92k | let block = buffer.pad_with_zeros(); | 43 | 5.92k | block[pos] = $pad; | 44 | 5.92k | let n = block.len(); | 45 | 5.92k | block[n - 1] |= 0x80; | 46 | 5.92k | | 47 | 5.92k | self.state.absorb_block(block); | 48 | 5.92k | | 49 | 5.92k | self.state.as_bytes(out); | 50 | 5.92k | } |
Unexecuted instantiation: <sha3::Keccak224Core as digest::core_api::FixedOutputCore>::finalize_fixed_core Unexecuted instantiation: <sha3::Keccak256Core as digest::core_api::FixedOutputCore>::finalize_fixed_core Unexecuted instantiation: <sha3::Keccak384Core as digest::core_api::FixedOutputCore>::finalize_fixed_core Unexecuted instantiation: <sha3::Keccak512Core as digest::core_api::FixedOutputCore>::finalize_fixed_core Unexecuted instantiation: <sha3::Keccak256FullCore as digest::core_api::FixedOutputCore>::finalize_fixed_core Unexecuted instantiation: <sha3::Sha3_224Core as digest::core_api::FixedOutputCore>::finalize_fixed_core Unexecuted instantiation: <sha3::Sha3_256Core as digest::core_api::FixedOutputCore>::finalize_fixed_core Unexecuted instantiation: <sha3::Sha3_384Core as digest::core_api::FixedOutputCore>::finalize_fixed_core Unexecuted instantiation: <sha3::Sha3_512Core as digest::core_api::FixedOutputCore>::finalize_fixed_core |
51 | | } |
52 | | |
53 | | impl Default for $name { |
54 | | #[inline] |
55 | 12.9k | fn default() -> Self { |
56 | 12.9k | Self { |
57 | 12.9k | state: Default::default(), |
58 | 12.9k | } |
59 | 12.9k | } <sha3::Sha3_256Core as core::default::Default>::default Line | Count | Source | 55 | 7.03k | fn default() -> Self { | 56 | 7.03k | Self { | 57 | 7.03k | state: Default::default(), | 58 | 7.03k | } | 59 | 7.03k | } |
<sha3::Sha3_512Core as core::default::Default>::default Line | Count | Source | 55 | 5.92k | fn default() -> Self { | 56 | 5.92k | Self { | 57 | 5.92k | state: Default::default(), | 58 | 5.92k | } | 59 | 5.92k | } |
Unexecuted instantiation: <sha3::Keccak224Core as core::default::Default>::default Unexecuted instantiation: <sha3::Keccak256Core as core::default::Default>::default Unexecuted instantiation: <sha3::Keccak384Core as core::default::Default>::default Unexecuted instantiation: <sha3::Keccak512Core as core::default::Default>::default Unexecuted instantiation: <sha3::Keccak256FullCore as core::default::Default>::default Unexecuted instantiation: <sha3::Sha3_224Core as core::default::Default>::default Unexecuted instantiation: <sha3::Sha3_256Core as core::default::Default>::default Unexecuted instantiation: <sha3::Sha3_384Core as core::default::Default>::default Unexecuted instantiation: <sha3::Sha3_512Core as core::default::Default>::default |
60 | | } |
61 | | |
62 | | impl Reset for $name { |
63 | | #[inline] |
64 | 0 | fn reset(&mut self) { |
65 | 0 | *self = Default::default(); |
66 | 0 | } Unexecuted instantiation: <sha3::Keccak224Core as crypto_common::Reset>::reset Unexecuted instantiation: <sha3::Keccak256Core as crypto_common::Reset>::reset Unexecuted instantiation: <sha3::Keccak384Core as crypto_common::Reset>::reset Unexecuted instantiation: <sha3::Keccak512Core as crypto_common::Reset>::reset Unexecuted instantiation: <sha3::Keccak256FullCore as crypto_common::Reset>::reset Unexecuted instantiation: <sha3::Sha3_224Core as crypto_common::Reset>::reset Unexecuted instantiation: <sha3::Sha3_256Core as crypto_common::Reset>::reset Unexecuted instantiation: <sha3::Sha3_384Core as crypto_common::Reset>::reset Unexecuted instantiation: <sha3::Sha3_512Core as crypto_common::Reset>::reset |
67 | | } |
68 | | |
69 | | impl AlgorithmName for $name { |
70 | 0 | fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { |
71 | 0 | f.write_str(stringify!($full_name)) |
72 | 0 | } Unexecuted instantiation: <sha3::Keccak224Core as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::Keccak256Core as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::Keccak384Core as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::Keccak512Core as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::Keccak256FullCore as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::Sha3_224Core as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::Sha3_256Core as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::Sha3_384Core as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::Sha3_512Core as crypto_common::AlgorithmName>::write_alg_name |
73 | | } |
74 | | |
75 | | impl fmt::Debug for $name { |
76 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
77 | 0 | f.write_str(concat!(stringify!($name), " { ... }")) |
78 | 0 | } Unexecuted instantiation: <sha3::Keccak224Core as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::Keccak256Core as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::Keccak384Core as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::Keccak512Core as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::Keccak256FullCore as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::Sha3_224Core as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::Sha3_256Core as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::Sha3_384Core as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::Sha3_512Core as core::fmt::Debug>::fmt |
79 | | } |
80 | | |
81 | | #[doc = $alg_name] |
82 | | #[doc = " hasher state."] |
83 | | pub type $full_name = CoreWrapper<$name>; |
84 | | }; |
85 | | ( |
86 | | $name:ident, $full_name:ident, $output_size:ident, |
87 | | $rate:ident, $pad:expr, $alg_name:expr, $oid:literal $(,)? |
88 | | ) => { |
89 | | impl_sha3!($name, $full_name, $output_size, $rate, $pad, $alg_name); |
90 | | |
91 | | #[cfg(feature = "oid")] |
92 | | #[cfg_attr(docsrs, doc(cfg(feature = "oid")))] |
93 | | impl AssociatedOid for $name { |
94 | | const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap($oid); |
95 | | } |
96 | | }; |
97 | | } |
98 | | |
99 | | macro_rules! impl_shake { |
100 | | ( |
101 | | $name:ident, $full_name:ident, $reader:ident, $reader_full:ident, |
102 | | $rate:ident, $pad:expr, $alg_name:expr $(,)? |
103 | | ) => { |
104 | | #[doc = "Core "] |
105 | | #[doc = $alg_name] |
106 | | #[doc = " hasher state."] |
107 | | #[derive(Clone)] |
108 | | #[allow(non_camel_case_types)] |
109 | | pub struct $name { |
110 | | state: Sha3State, |
111 | | } |
112 | | |
113 | | impl HashMarker for $name {} |
114 | | |
115 | | impl BlockSizeUser for $name { |
116 | | type BlockSize = $rate; |
117 | | } |
118 | | |
119 | | impl BufferKindUser for $name { |
120 | | type BufferKind = Eager; |
121 | | } |
122 | | |
123 | | impl UpdateCore for $name { |
124 | | #[inline] |
125 | 3.33k | fn update_blocks(&mut self, blocks: &[Block<Self>]) { |
126 | 16.5k | for block in blocks { |
127 | 13.2k | self.state.absorb_block(block) |
128 | | } |
129 | 3.33k | } Unexecuted instantiation: <sha3::Shake128Core as digest::core_api::UpdateCore>::update_blocks <sha3::Shake256Core as digest::core_api::UpdateCore>::update_blocks Line | Count | Source | 125 | 3.33k | fn update_blocks(&mut self, blocks: &[Block<Self>]) { | 126 | 16.5k | for block in blocks { | 127 | 13.2k | self.state.absorb_block(block) | 128 | | } | 129 | 3.33k | } |
Unexecuted instantiation: <sha3::Shake128Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::Shake256Core as digest::core_api::UpdateCore>::update_blocks |
130 | | } |
131 | | |
132 | | impl ExtendableOutputCore for $name { |
133 | | type ReaderCore = $reader; |
134 | | |
135 | | #[inline] |
136 | 100k | fn finalize_xof_core(&mut self, buffer: &mut Buffer<Self>) -> Self::ReaderCore { |
137 | 100k | let pos = buffer.get_pos(); |
138 | 100k | let block = buffer.pad_with_zeros(); |
139 | 100k | block[pos] = $pad; |
140 | 100k | let n = block.len(); |
141 | 100k | block[n - 1] |= 0x80; |
142 | 100k | |
143 | 100k | self.state.absorb_block(block); |
144 | 100k | $reader { |
145 | 100k | state: self.state.clone(), |
146 | 100k | } |
147 | 100k | } <sha3::Shake128Core as digest::core_api::ExtendableOutputCore>::finalize_xof_core Line | Count | Source | 136 | 58.8k | fn finalize_xof_core(&mut self, buffer: &mut Buffer<Self>) -> Self::ReaderCore { | 137 | 58.8k | let pos = buffer.get_pos(); | 138 | 58.8k | let block = buffer.pad_with_zeros(); | 139 | 58.8k | block[pos] = $pad; | 140 | 58.8k | let n = block.len(); | 141 | 58.8k | block[n - 1] |= 0x80; | 142 | 58.8k | | 143 | 58.8k | self.state.absorb_block(block); | 144 | 58.8k | $reader { | 145 | 58.8k | state: self.state.clone(), | 146 | 58.8k | } | 147 | 58.8k | } |
<sha3::Shake256Core as digest::core_api::ExtendableOutputCore>::finalize_xof_core Line | Count | Source | 136 | 41.3k | fn finalize_xof_core(&mut self, buffer: &mut Buffer<Self>) -> Self::ReaderCore { | 137 | 41.3k | let pos = buffer.get_pos(); | 138 | 41.3k | let block = buffer.pad_with_zeros(); | 139 | 41.3k | block[pos] = $pad; | 140 | 41.3k | let n = block.len(); | 141 | 41.3k | block[n - 1] |= 0x80; | 142 | 41.3k | | 143 | 41.3k | self.state.absorb_block(block); | 144 | 41.3k | $reader { | 145 | 41.3k | state: self.state.clone(), | 146 | 41.3k | } | 147 | 41.3k | } |
Unexecuted instantiation: <sha3::Shake128Core as digest::core_api::ExtendableOutputCore>::finalize_xof_core Unexecuted instantiation: <sha3::Shake256Core as digest::core_api::ExtendableOutputCore>::finalize_xof_core |
148 | | } |
149 | | |
150 | | impl Default for $name { |
151 | | #[inline] |
152 | 100k | fn default() -> Self { |
153 | 100k | Self { |
154 | 100k | state: Default::default(), |
155 | 100k | } |
156 | 100k | } <sha3::Shake128Core as core::default::Default>::default Line | Count | Source | 152 | 58.8k | fn default() -> Self { | 153 | 58.8k | Self { | 154 | 58.8k | state: Default::default(), | 155 | 58.8k | } | 156 | 58.8k | } |
<sha3::Shake256Core as core::default::Default>::default Line | Count | Source | 152 | 41.3k | fn default() -> Self { | 153 | 41.3k | Self { | 154 | 41.3k | state: Default::default(), | 155 | 41.3k | } | 156 | 41.3k | } |
Unexecuted instantiation: <sha3::Shake128Core as core::default::Default>::default Unexecuted instantiation: <sha3::Shake256Core as core::default::Default>::default |
157 | | } |
158 | | |
159 | | impl Reset for $name { |
160 | | #[inline] |
161 | 0 | fn reset(&mut self) { |
162 | 0 | *self = Default::default(); |
163 | 0 | } Unexecuted instantiation: <sha3::Shake128Core as crypto_common::Reset>::reset Unexecuted instantiation: <sha3::Shake256Core as crypto_common::Reset>::reset |
164 | | } |
165 | | |
166 | | impl AlgorithmName for $name { |
167 | 0 | fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { |
168 | 0 | f.write_str(stringify!($full_name)) |
169 | 0 | } Unexecuted instantiation: <sha3::Shake128Core as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::Shake256Core as crypto_common::AlgorithmName>::write_alg_name |
170 | | } |
171 | | |
172 | | impl fmt::Debug for $name { |
173 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
174 | 0 | f.write_str(concat!(stringify!($name), " { ... }")) |
175 | 0 | } Unexecuted instantiation: <sha3::Shake128Core as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::Shake256Core as core::fmt::Debug>::fmt |
176 | | } |
177 | | |
178 | | #[doc = "Core "] |
179 | | #[doc = $alg_name] |
180 | | #[doc = " reader state."] |
181 | | #[derive(Clone)] |
182 | | #[allow(non_camel_case_types)] |
183 | | pub struct $reader { |
184 | | state: Sha3State, |
185 | | } |
186 | | |
187 | | impl BlockSizeUser for $reader { |
188 | | type BlockSize = $rate; |
189 | | } |
190 | | |
191 | | impl XofReaderCore for $reader { |
192 | | #[inline] |
193 | 227k | fn read_block(&mut self) -> Block<Self> { |
194 | 227k | let mut block = Block::<Self>::default(); |
195 | 227k | self.state.as_bytes(&mut block); |
196 | 227k | self.state.permute(); |
197 | 227k | block |
198 | 227k | } <sha3::Shake128ReaderCore as digest::core_api::XofReaderCore>::read_block Line | Count | Source | 193 | 180k | fn read_block(&mut self) -> Block<Self> { | 194 | 180k | let mut block = Block::<Self>::default(); | 195 | 180k | self.state.as_bytes(&mut block); | 196 | 180k | self.state.permute(); | 197 | 180k | block | 198 | 180k | } |
<sha3::Shake256ReaderCore as digest::core_api::XofReaderCore>::read_block Line | Count | Source | 193 | 46.6k | fn read_block(&mut self) -> Block<Self> { | 194 | 46.6k | let mut block = Block::<Self>::default(); | 195 | 46.6k | self.state.as_bytes(&mut block); | 196 | 46.6k | self.state.permute(); | 197 | 46.6k | block | 198 | 46.6k | } |
Unexecuted instantiation: <sha3::Shake128ReaderCore as digest::core_api::XofReaderCore>::read_block Unexecuted instantiation: <sha3::Shake256ReaderCore as digest::core_api::XofReaderCore>::read_block |
199 | | } |
200 | | |
201 | | #[doc = $alg_name] |
202 | | #[doc = " hasher state."] |
203 | | pub type $full_name = CoreWrapper<$name>; |
204 | | |
205 | | #[doc = $alg_name] |
206 | | #[doc = " reader state."] |
207 | | pub type $reader_full = XofReaderCoreWrapper<$reader>; |
208 | | }; |
209 | | ( |
210 | | $name:ident, $full_name:ident, $reader:ident, $reader_full:ident, |
211 | | $rate:ident, $pad:expr, $alg_name:expr, $oid:literal $(,)? |
212 | | ) => { |
213 | | impl_shake!( |
214 | | $name, |
215 | | $full_name, |
216 | | $reader, |
217 | | $reader_full, |
218 | | $rate, |
219 | | $pad, |
220 | | $alg_name |
221 | | ); |
222 | | |
223 | | #[cfg(feature = "oid")] |
224 | | #[cfg_attr(docsrs, doc(cfg(feature = "oid")))] |
225 | | impl AssociatedOid for $name { |
226 | | const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap($oid); |
227 | | } |
228 | | }; |
229 | | } |
230 | | |
231 | | macro_rules! impl_turbo_shake { |
232 | | ( |
233 | | $name:ident, $full_name:ident, $reader:ident, $reader_full:ident, |
234 | | $rate:ident, $alg_name:expr $(,)? |
235 | | ) => { |
236 | | #[doc = "Core "] |
237 | | #[doc = $alg_name] |
238 | | #[doc = " hasher state."] |
239 | | #[derive(Clone)] |
240 | | #[allow(non_camel_case_types)] |
241 | | pub struct $name { |
242 | | domain_separation: u8, |
243 | | state: Sha3State, |
244 | | } |
245 | | |
246 | | impl $name { |
247 | | /// Creates a new TurboSHAKE instance with the given domain separation. |
248 | | /// Note that the domain separation needs to be a byte with a value in |
249 | | /// the range [0x01, . . . , 0x7F] |
250 | 0 | pub fn new(domain_separation: u8) -> Self { |
251 | 0 | assert!((0x01..=0x7F).contains(&domain_separation)); |
252 | 0 | Self { |
253 | 0 | domain_separation, |
254 | 0 | state: Sha3State::new(TURBO_SHAKE_ROUND_COUNT), |
255 | 0 | } |
256 | 0 | } Unexecuted instantiation: <sha3::TurboShake128Core>::new Unexecuted instantiation: <sha3::TurboShake256Core>::new |
257 | | } |
258 | | |
259 | | impl HashMarker for $name {} |
260 | | |
261 | | impl BlockSizeUser for $name { |
262 | | type BlockSize = $rate; |
263 | | } |
264 | | |
265 | | impl BufferKindUser for $name { |
266 | | type BufferKind = Eager; |
267 | | } |
268 | | |
269 | | impl UpdateCore for $name { |
270 | | #[inline] |
271 | 0 | fn update_blocks(&mut self, blocks: &[Block<Self>]) { |
272 | 0 | for block in blocks { |
273 | 0 | self.state.absorb_block(block) |
274 | | } |
275 | 0 | } Unexecuted instantiation: <sha3::TurboShake128Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::TurboShake256Core as digest::core_api::UpdateCore>::update_blocks |
276 | | } |
277 | | |
278 | | impl ExtendableOutputCore for $name { |
279 | | type ReaderCore = $reader; |
280 | | |
281 | | #[inline] |
282 | 0 | fn finalize_xof_core(&mut self, buffer: &mut Buffer<Self>) -> Self::ReaderCore { |
283 | 0 | let pos = buffer.get_pos(); |
284 | 0 | let block = buffer.pad_with_zeros(); |
285 | 0 | block[pos] = self.domain_separation; |
286 | 0 | let n = block.len(); |
287 | 0 | block[n - 1] |= 0x80; |
288 | 0 |
|
289 | 0 | self.state.absorb_block(block); |
290 | 0 | $reader { |
291 | 0 | state: self.state.clone(), |
292 | 0 | } |
293 | 0 | } Unexecuted instantiation: <sha3::TurboShake128Core as digest::core_api::ExtendableOutputCore>::finalize_xof_core Unexecuted instantiation: <sha3::TurboShake256Core as digest::core_api::ExtendableOutputCore>::finalize_xof_core |
294 | | } |
295 | | |
296 | | impl Reset for $name { |
297 | | #[inline] |
298 | 0 | fn reset(&mut self) { |
299 | 0 | *self = Self::new(self.domain_separation); |
300 | 0 | } Unexecuted instantiation: <sha3::TurboShake128Core as crypto_common::Reset>::reset Unexecuted instantiation: <sha3::TurboShake256Core as crypto_common::Reset>::reset |
301 | | } |
302 | | |
303 | | impl AlgorithmName for $name { |
304 | 0 | fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { |
305 | 0 | f.write_str(stringify!($full_name)) |
306 | 0 | } Unexecuted instantiation: <sha3::TurboShake128Core as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::TurboShake256Core as crypto_common::AlgorithmName>::write_alg_name |
307 | | } |
308 | | |
309 | | impl fmt::Debug for $name { |
310 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
311 | 0 | f.write_str(concat!(stringify!($name), " { ... }")) |
312 | 0 | } Unexecuted instantiation: <sha3::TurboShake128Core as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::TurboShake256Core as core::fmt::Debug>::fmt |
313 | | } |
314 | | |
315 | | #[doc = "Core "] |
316 | | #[doc = $alg_name] |
317 | | #[doc = " reader state."] |
318 | | #[derive(Clone)] |
319 | | #[allow(non_camel_case_types)] |
320 | | pub struct $reader { |
321 | | state: Sha3State, |
322 | | } |
323 | | |
324 | | impl BlockSizeUser for $reader { |
325 | | type BlockSize = $rate; |
326 | | } |
327 | | |
328 | | impl XofReaderCore for $reader { |
329 | | #[inline] |
330 | 0 | fn read_block(&mut self) -> Block<Self> { |
331 | 0 | let mut block = Block::<Self>::default(); |
332 | 0 | self.state.as_bytes(&mut block); |
333 | 0 | self.state.permute(); |
334 | 0 | block |
335 | 0 | } Unexecuted instantiation: <sha3::TurboShake128ReaderCore as digest::core_api::XofReaderCore>::read_block Unexecuted instantiation: <sha3::TurboShake256ReaderCore as digest::core_api::XofReaderCore>::read_block |
336 | | } |
337 | | |
338 | | #[doc = $alg_name] |
339 | | #[doc = " hasher state."] |
340 | | pub type $full_name = CoreWrapper<$name>; |
341 | | |
342 | | #[doc = $alg_name] |
343 | | #[doc = " reader state."] |
344 | | pub type $reader_full = XofReaderCoreWrapper<$reader>; |
345 | | }; |
346 | | ( |
347 | | $name:ident, $full_name:ident, $reader:ident, $reader_full:ident, |
348 | | $rate:ident, $alg_name:expr, $oid:literal $(,)? |
349 | | ) => { |
350 | | impl_turbo_shake!($name, $full_name, $reader, $reader_full, $rate, $alg_name); |
351 | | |
352 | | #[cfg(feature = "oid")] |
353 | | #[cfg_attr(docsrs, doc(cfg(feature = "oid")))] |
354 | | impl AssociatedOid for $name { |
355 | | const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap($oid); |
356 | | } |
357 | | }; |
358 | | } |
359 | | |
360 | | macro_rules! impl_cshake { |
361 | | ( |
362 | | $name:ident, $full_name:ident, $reader:ident, $reader_full:ident, |
363 | | $rate:ident, $shake_pad:expr, $cshake_pad:expr, $alg_name:expr, |
364 | | ) => { |
365 | | #[doc = "Core "] |
366 | | #[doc = $alg_name] |
367 | | #[doc = " hasher state."] |
368 | | #[derive(Clone)] |
369 | | #[allow(non_camel_case_types)] |
370 | | pub struct $name { |
371 | | padding: u8, |
372 | | state: Sha3State, |
373 | | #[cfg(feature = "reset")] |
374 | | initial_state: Sha3State, |
375 | | } |
376 | | |
377 | | impl $name { |
378 | | /// Creates a new CSHAKE instance with the given customization. |
379 | 0 | pub fn new(customization: &[u8]) -> Self { |
380 | 0 | Self::new_with_function_name(&[], customization) |
381 | 0 | } Unexecuted instantiation: <sha3::CShake128Core>::new Unexecuted instantiation: <sha3::CShake256Core>::new |
382 | | |
383 | | /// Creates a new CSHAKE instance with the given function name and customization. |
384 | | /// Note that the function name is intended for use by NIST and should only be set to |
385 | | /// values defined by NIST. You probably don't need to use this function. |
386 | 0 | pub fn new_with_function_name(function_name: &[u8], customization: &[u8]) -> Self { |
387 | 0 | let mut state = Sha3State::default(); |
388 | 0 | if function_name.is_empty() && customization.is_empty() { |
389 | 0 | return Self { |
390 | 0 | padding: $shake_pad, |
391 | 0 | state: state.clone(), |
392 | 0 | #[cfg(feature = "reset")] |
393 | 0 | initial_state: state, |
394 | 0 | }; |
395 | 0 | } |
396 | 0 |
|
397 | 0 | let mut buffer = Buffer::<Self>::default(); |
398 | 0 | let mut b = [0u8; 9]; |
399 | 0 | buffer.digest_blocks(left_encode($rate::to_u64(), &mut b), |blocks| { |
400 | 0 | for block in blocks { |
401 | 0 | state.absorb_block(block); |
402 | 0 | } |
403 | 0 | }); Unexecuted instantiation: <sha3::CShake128Core>::new_with_function_name::{closure#0} Unexecuted instantiation: <sha3::CShake256Core>::new_with_function_name::{closure#0} |
404 | 0 | buffer.digest_blocks( |
405 | 0 | left_encode((function_name.len() * 8) as u64, &mut b), |
406 | 0 | |blocks| { |
407 | 0 | for block in blocks { |
408 | 0 | state.absorb_block(block); |
409 | 0 | } |
410 | 0 | }, Unexecuted instantiation: <sha3::CShake128Core>::new_with_function_name::{closure#1} Unexecuted instantiation: <sha3::CShake256Core>::new_with_function_name::{closure#1} |
411 | 0 | ); |
412 | 0 | buffer.digest_blocks(function_name, |blocks| { |
413 | 0 | for block in blocks { |
414 | 0 | state.absorb_block(block); |
415 | 0 | } |
416 | 0 | }); Unexecuted instantiation: <sha3::CShake128Core>::new_with_function_name::{closure#2} Unexecuted instantiation: <sha3::CShake256Core>::new_with_function_name::{closure#2} |
417 | 0 | buffer.digest_blocks( |
418 | 0 | left_encode((customization.len() * 8) as u64, &mut b), |
419 | 0 | |blocks| { |
420 | 0 | for block in blocks { |
421 | 0 | state.absorb_block(block); |
422 | 0 | } |
423 | 0 | }, Unexecuted instantiation: <sha3::CShake128Core>::new_with_function_name::{closure#3} Unexecuted instantiation: <sha3::CShake256Core>::new_with_function_name::{closure#3} |
424 | 0 | ); |
425 | 0 | buffer.digest_blocks(customization, |blocks| { |
426 | 0 | for block in blocks { |
427 | 0 | state.absorb_block(block); |
428 | 0 | } |
429 | 0 | }); Unexecuted instantiation: <sha3::CShake128Core>::new_with_function_name::{closure#4} Unexecuted instantiation: <sha3::CShake256Core>::new_with_function_name::{closure#4} |
430 | 0 | state.absorb_block(buffer.pad_with_zeros()); |
431 | 0 |
|
432 | 0 | Self { |
433 | 0 | padding: $cshake_pad, |
434 | 0 | state: state.clone(), |
435 | 0 | #[cfg(feature = "reset")] |
436 | 0 | initial_state: state, |
437 | 0 | } |
438 | 0 | } Unexecuted instantiation: <sha3::CShake128Core>::new_with_function_name Unexecuted instantiation: <sha3::CShake256Core>::new_with_function_name |
439 | | } |
440 | | |
441 | | impl HashMarker for $name {} |
442 | | |
443 | | impl BlockSizeUser for $name { |
444 | | type BlockSize = $rate; |
445 | | } |
446 | | |
447 | | impl BufferKindUser for $name { |
448 | | type BufferKind = Eager; |
449 | | } |
450 | | |
451 | | impl UpdateCore for $name { |
452 | | #[inline] |
453 | 0 | fn update_blocks(&mut self, blocks: &[Block<Self>]) { |
454 | 0 | for block in blocks { |
455 | 0 | self.state.absorb_block(block) |
456 | | } |
457 | 0 | } Unexecuted instantiation: <sha3::CShake128Core as digest::core_api::UpdateCore>::update_blocks Unexecuted instantiation: <sha3::CShake256Core as digest::core_api::UpdateCore>::update_blocks |
458 | | } |
459 | | |
460 | | impl ExtendableOutputCore for $name { |
461 | | type ReaderCore = $reader; |
462 | | |
463 | | #[inline] |
464 | 0 | fn finalize_xof_core(&mut self, buffer: &mut Buffer<Self>) -> Self::ReaderCore { |
465 | 0 | let pos = buffer.get_pos(); |
466 | 0 | let block = buffer.pad_with_zeros(); |
467 | 0 | block[pos] = self.padding; |
468 | 0 | let n = block.len(); |
469 | 0 | block[n - 1] |= 0x80; |
470 | 0 |
|
471 | 0 | self.state.absorb_block(block); |
472 | 0 | $reader { |
473 | 0 | state: self.state.clone(), |
474 | 0 | } |
475 | 0 | } Unexecuted instantiation: <sha3::CShake128Core as digest::core_api::ExtendableOutputCore>::finalize_xof_core Unexecuted instantiation: <sha3::CShake256Core as digest::core_api::ExtendableOutputCore>::finalize_xof_core |
476 | | } |
477 | | |
478 | | #[cfg(feature = "reset")] |
479 | | impl Reset for $name { |
480 | | #[inline] |
481 | | fn reset(&mut self) { |
482 | | self.state = self.initial_state.clone(); |
483 | | } |
484 | | } |
485 | | |
486 | | impl AlgorithmName for $name { |
487 | 0 | fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { |
488 | 0 | f.write_str(stringify!($full_name)) |
489 | 0 | } Unexecuted instantiation: <sha3::CShake128Core as crypto_common::AlgorithmName>::write_alg_name Unexecuted instantiation: <sha3::CShake256Core as crypto_common::AlgorithmName>::write_alg_name |
490 | | } |
491 | | |
492 | | impl fmt::Debug for $name { |
493 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
494 | 0 | f.write_str(concat!(stringify!($name), " { ... }")) |
495 | 0 | } Unexecuted instantiation: <sha3::CShake128Core as core::fmt::Debug>::fmt Unexecuted instantiation: <sha3::CShake256Core as core::fmt::Debug>::fmt |
496 | | } |
497 | | |
498 | | #[doc = "Core "] |
499 | | #[doc = $alg_name] |
500 | | #[doc = " reader state."] |
501 | | #[derive(Clone)] |
502 | | #[allow(non_camel_case_types)] |
503 | | pub struct $reader { |
504 | | state: Sha3State, |
505 | | } |
506 | | |
507 | | impl BlockSizeUser for $reader { |
508 | | type BlockSize = $rate; |
509 | | } |
510 | | |
511 | | impl XofReaderCore for $reader { |
512 | | #[inline] |
513 | 0 | fn read_block(&mut self) -> Block<Self> { |
514 | 0 | let mut block = Block::<Self>::default(); |
515 | 0 | self.state.as_bytes(&mut block); |
516 | 0 | self.state.permute(); |
517 | 0 | block |
518 | 0 | } Unexecuted instantiation: <sha3::CShake128ReaderCore as digest::core_api::XofReaderCore>::read_block Unexecuted instantiation: <sha3::CShake256ReaderCore as digest::core_api::XofReaderCore>::read_block |
519 | | } |
520 | | |
521 | | #[doc = $alg_name] |
522 | | #[doc = " hasher state."] |
523 | | pub type $full_name = CoreWrapper<$name>; |
524 | | |
525 | | #[doc = $alg_name] |
526 | | #[doc = " reader state."] |
527 | | pub type $reader_full = XofReaderCoreWrapper<$reader>; |
528 | | }; |
529 | | } |