/rust/registry/src/index.crates.io-6f17d22bba15001f/block-buffer-0.10.4/src/lib.rs
Line | Count | Source (jump to first uncovered line) |
1 | | //! Fixed size buffer for block processing of data. |
2 | | #![no_std] |
3 | | #![doc( |
4 | | html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", |
5 | | html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg" |
6 | | )] |
7 | | #![warn(missing_docs, rust_2018_idioms)] |
8 | | |
9 | | pub use generic_array; |
10 | | |
11 | | use core::{fmt, marker::PhantomData, slice}; |
12 | | use generic_array::{ |
13 | | typenum::{IsLess, Le, NonZero, U256}, |
14 | | ArrayLength, GenericArray, |
15 | | }; |
16 | | |
17 | | mod sealed; |
18 | | |
19 | | /// Block on which `BlockBuffer` operates. |
20 | | pub type Block<BlockSize> = GenericArray<u8, BlockSize>; |
21 | | |
22 | | /// Trait for buffer kinds. |
23 | | pub trait BufferKind: sealed::Sealed {} |
24 | | |
25 | | /// Eager block buffer kind, which guarantees that buffer position |
26 | | /// always lies in the range of `0..BlockSize`. |
27 | | #[derive(Copy, Clone, Debug, Default)] |
28 | | pub struct Eager {} |
29 | | |
30 | | /// Lazy block buffer kind, which guarantees that buffer position |
31 | | /// always lies in the range of `0..=BlockSize`. |
32 | | #[derive(Copy, Clone, Debug, Default)] |
33 | | pub struct Lazy {} |
34 | | |
35 | | impl BufferKind for Eager {} |
36 | | impl BufferKind for Lazy {} |
37 | | |
38 | | /// Eager block buffer. |
39 | | pub type EagerBuffer<B> = BlockBuffer<B, Eager>; |
40 | | /// Lazy block buffer. |
41 | | pub type LazyBuffer<B> = BlockBuffer<B, Lazy>; |
42 | | |
43 | | /// Block buffer error. |
44 | | #[derive(Copy, Clone, Eq, PartialEq, Debug)] |
45 | | pub struct Error; |
46 | | |
47 | | impl fmt::Display for Error { |
48 | | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { |
49 | | f.write_str("Block buffer error") |
50 | | } |
51 | | } |
52 | | |
53 | | /// Buffer for block processing of data. |
54 | | #[derive(Debug)] |
55 | | pub struct BlockBuffer<BlockSize, Kind> |
56 | | where |
57 | | BlockSize: ArrayLength<u8> + IsLess<U256>, |
58 | | Le<BlockSize, U256>: NonZero, |
59 | | Kind: BufferKind, |
60 | | { |
61 | | buffer: Block<BlockSize>, |
62 | | pos: u8, |
63 | | _pd: PhantomData<Kind>, |
64 | | } |
65 | | |
66 | | impl<BlockSize, Kind> Default for BlockBuffer<BlockSize, Kind> |
67 | | where |
68 | | BlockSize: ArrayLength<u8> + IsLess<U256>, |
69 | | Le<BlockSize, U256>: NonZero, |
70 | | Kind: BufferKind, |
71 | | { |
72 | 66.7k | fn default() -> Self { |
73 | 66.7k | if BlockSize::USIZE == 0 { |
74 | 0 | panic!("Block size can not be equal to zero"); |
75 | 66.7k | } |
76 | 66.7k | Self { |
77 | 66.7k | buffer: Default::default(), |
78 | 66.7k | pos: 0, |
79 | 66.7k | _pd: PhantomData, |
80 | 66.7k | } |
81 | 66.7k | } <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager> as core::default::Default>::default Line | Count | Source | 72 | 1.87k | fn default() -> Self { | 73 | 1.87k | if BlockSize::USIZE == 0 { | 74 | 0 | panic!("Block size can not be equal to zero"); | 75 | 1.87k | } | 76 | 1.87k | Self { | 77 | 1.87k | buffer: Default::default(), | 78 | 1.87k | pos: 0, | 79 | 1.87k | _pd: PhantomData, | 80 | 1.87k | } | 81 | 1.87k | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager> as core::default::Default>::default Line | Count | Source | 72 | 36.9k | fn default() -> Self { | 73 | 36.9k | if BlockSize::USIZE == 0 { | 74 | 0 | panic!("Block size can not be equal to zero"); | 75 | 36.9k | } | 76 | 36.9k | Self { | 77 | 36.9k | buffer: Default::default(), | 78 | 36.9k | pos: 0, | 79 | 36.9k | _pd: PhantomData, | 80 | 36.9k | } | 81 | 36.9k | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager> as core::default::Default>::default Line | Count | Source | 72 | 28.0k | fn default() -> Self { | 73 | 28.0k | if BlockSize::USIZE == 0 { | 74 | 0 | panic!("Block size can not be equal to zero"); | 75 | 28.0k | } | 76 | 28.0k | Self { | 77 | 28.0k | buffer: Default::default(), | 78 | 28.0k | pos: 0, | 79 | 28.0k | _pd: PhantomData, | 80 | 28.0k | } | 81 | 28.0k | } |
|
82 | | } |
83 | | |
84 | | impl<BlockSize, Kind> Clone for BlockBuffer<BlockSize, Kind> |
85 | | where |
86 | | BlockSize: ArrayLength<u8> + IsLess<U256>, |
87 | | Le<BlockSize, U256>: NonZero, |
88 | | Kind: BufferKind, |
89 | | { |
90 | | fn clone(&self) -> Self { |
91 | | Self { |
92 | | buffer: self.buffer.clone(), |
93 | | pos: self.pos, |
94 | | _pd: PhantomData, |
95 | | } |
96 | | } |
97 | | } |
98 | | |
99 | | impl<BlockSize, Kind> BlockBuffer<BlockSize, Kind> |
100 | | where |
101 | | BlockSize: ArrayLength<u8> + IsLess<U256>, |
102 | | Le<BlockSize, U256>: NonZero, |
103 | | Kind: BufferKind, |
104 | | { |
105 | | /// Create new buffer from slice. |
106 | | /// |
107 | | /// # Panics |
108 | | /// If slice length is not valid for used buffer kind. |
109 | | #[inline(always)] |
110 | | pub fn new(buf: &[u8]) -> Self { |
111 | | Self::try_new(buf).unwrap() |
112 | | } |
113 | | |
114 | | /// Create new buffer from slice. |
115 | | /// |
116 | | /// Returns an error if slice length is not valid for used buffer kind. |
117 | | #[inline(always)] |
118 | | pub fn try_new(buf: &[u8]) -> Result<Self, Error> { |
119 | | if BlockSize::USIZE == 0 { |
120 | | panic!("Block size can not be equal to zero"); |
121 | | } |
122 | | let pos = buf.len(); |
123 | | if !Kind::invariant(pos, BlockSize::USIZE) { |
124 | | return Err(Error); |
125 | | } |
126 | | let mut buffer = Block::<BlockSize>::default(); |
127 | | buffer[..pos].copy_from_slice(buf); |
128 | | Ok(Self { |
129 | | buffer, |
130 | | pos: pos as u8, |
131 | | _pd: PhantomData, |
132 | | }) |
133 | | } |
134 | | |
135 | | /// Digest data in `input` in blocks of size `BlockSize` using |
136 | | /// the `compress` function, which accepts slice of blocks. |
137 | | #[inline] |
138 | 86.3k | pub fn digest_blocks( |
139 | 86.3k | &mut self, |
140 | 86.3k | mut input: &[u8], |
141 | 86.3k | mut compress: impl FnMut(&[Block<BlockSize>]), |
142 | 86.3k | ) { |
143 | 86.3k | let pos = self.get_pos(); |
144 | 86.3k | // using `self.remaining()` for some reason |
145 | 86.3k | // prevents panic elimination |
146 | 86.3k | let rem = self.size() - pos; |
147 | 86.3k | let n = input.len(); |
148 | 86.3k | // Note that checking condition `pos + n < BlockSize` is |
149 | 86.3k | // equivalent to checking `n < rem`, where `rem` is equal |
150 | 86.3k | // to `BlockSize - pos`. Using the latter allows us to work |
151 | 86.3k | // around compiler accounting for possible overflow of |
152 | 86.3k | // `pos + n` which results in it inserting unreachable |
153 | 86.3k | // panic branches. Using `unreachable_unchecked` in `get_pos` |
154 | 86.3k | // we convince compiler that `BlockSize - pos` never underflows. |
155 | 86.3k | if Kind::invariant(n, rem) { |
156 | | // double slicing allows to remove panic branches |
157 | 83.5k | self.buffer[pos..][..n].copy_from_slice(input); |
158 | 83.5k | self.set_pos_unchecked(pos + n); |
159 | 83.5k | return; |
160 | 2.72k | } |
161 | 2.72k | if pos != 0 { |
162 | 467 | let (left, right) = input.split_at(rem); |
163 | 467 | input = right; |
164 | 467 | self.buffer[pos..].copy_from_slice(left); |
165 | 467 | compress(slice::from_ref(&self.buffer)); |
166 | 2.25k | } |
167 | | |
168 | 2.72k | let (blocks, leftover) = Kind::split_blocks(input); |
169 | 2.72k | if !blocks.is_empty() { |
170 | 2.72k | compress(blocks); |
171 | 2.72k | } |
172 | | |
173 | 2.72k | let n = leftover.len(); |
174 | 2.72k | self.buffer[..n].copy_from_slice(leftover); |
175 | 2.72k | self.set_pos_unchecked(n); |
176 | 86.3k | } <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<digest::core_api::wrapper::CoreWrapper<sha3::Shake128Core> as digest::Update>::update::{closure#0}> Line | Count | Source | 138 | 55.3k | pub fn digest_blocks( | 139 | 55.3k | &mut self, | 140 | 55.3k | mut input: &[u8], | 141 | 55.3k | mut compress: impl FnMut(&[Block<BlockSize>]), | 142 | 55.3k | ) { | 143 | 55.3k | let pos = self.get_pos(); | 144 | 55.3k | // using `self.remaining()` for some reason | 145 | 55.3k | // prevents panic elimination | 146 | 55.3k | let rem = self.size() - pos; | 147 | 55.3k | let n = input.len(); | 148 | 55.3k | // Note that checking condition `pos + n < BlockSize` is | 149 | 55.3k | // equivalent to checking `n < rem`, where `rem` is equal | 150 | 55.3k | // to `BlockSize - pos`. Using the latter allows us to work | 151 | 55.3k | // around compiler accounting for possible overflow of | 152 | 55.3k | // `pos + n` which results in it inserting unreachable | 153 | 55.3k | // panic branches. Using `unreachable_unchecked` in `get_pos` | 154 | 55.3k | // we convince compiler that `BlockSize - pos` never underflows. | 155 | 55.3k | if Kind::invariant(n, rem) { | 156 | | // double slicing allows to remove panic branches | 157 | 55.3k | self.buffer[pos..][..n].copy_from_slice(input); | 158 | 55.3k | self.set_pos_unchecked(pos + n); | 159 | 55.3k | return; | 160 | 0 | } | 161 | 0 | if pos != 0 { | 162 | 0 | let (left, right) = input.split_at(rem); | 163 | 0 | input = right; | 164 | 0 | self.buffer[pos..].copy_from_slice(left); | 165 | 0 | compress(slice::from_ref(&self.buffer)); | 166 | 0 | } | 167 | | | 168 | 0 | let (blocks, leftover) = Kind::split_blocks(input); | 169 | 0 | if !blocks.is_empty() { | 170 | 0 | compress(blocks); | 171 | 0 | } | 172 | | | 173 | 0 | let n = leftover.len(); | 174 | 0 | self.buffer[..n].copy_from_slice(leftover); | 175 | 0 | self.set_pos_unchecked(n); | 176 | 55.3k | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<digest::core_api::wrapper::CoreWrapper<sha3::Sha3_256Core> as digest::Update>::update::{closure#0}> Line | Count | Source | 138 | 2.25k | pub fn digest_blocks( | 139 | 2.25k | &mut self, | 140 | 2.25k | mut input: &[u8], | 141 | 2.25k | mut compress: impl FnMut(&[Block<BlockSize>]), | 142 | 2.25k | ) { | 143 | 2.25k | let pos = self.get_pos(); | 144 | 2.25k | // using `self.remaining()` for some reason | 145 | 2.25k | // prevents panic elimination | 146 | 2.25k | let rem = self.size() - pos; | 147 | 2.25k | let n = input.len(); | 148 | 2.25k | // Note that checking condition `pos + n < BlockSize` is | 149 | 2.25k | // equivalent to checking `n < rem`, where `rem` is equal | 150 | 2.25k | // to `BlockSize - pos`. Using the latter allows us to work | 151 | 2.25k | // around compiler accounting for possible overflow of | 152 | 2.25k | // `pos + n` which results in it inserting unreachable | 153 | 2.25k | // panic branches. Using `unreachable_unchecked` in `get_pos` | 154 | 2.25k | // we convince compiler that `BlockSize - pos` never underflows. | 155 | 2.25k | if Kind::invariant(n, rem) { | 156 | | // double slicing allows to remove panic branches | 157 | 0 | self.buffer[pos..][..n].copy_from_slice(input); | 158 | 0 | self.set_pos_unchecked(pos + n); | 159 | 0 | return; | 160 | 2.25k | } | 161 | 2.25k | if pos != 0 { | 162 | 0 | let (left, right) = input.split_at(rem); | 163 | 0 | input = right; | 164 | 0 | self.buffer[pos..].copy_from_slice(left); | 165 | 0 | compress(slice::from_ref(&self.buffer)); | 166 | 2.25k | } | 167 | | | 168 | 2.25k | let (blocks, leftover) = Kind::split_blocks(input); | 169 | 2.25k | if !blocks.is_empty() { | 170 | 2.25k | compress(blocks); | 171 | 2.25k | } | 172 | | | 173 | 2.25k | let n = leftover.len(); | 174 | 2.25k | self.buffer[..n].copy_from_slice(leftover); | 175 | 2.25k | self.set_pos_unchecked(n); | 176 | 2.25k | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<digest::core_api::wrapper::CoreWrapper<sha3::Shake256Core> as digest::Update>::update::{closure#0}> Line | Count | Source | 138 | 25.7k | pub fn digest_blocks( | 139 | 25.7k | &mut self, | 140 | 25.7k | mut input: &[u8], | 141 | 25.7k | mut compress: impl FnMut(&[Block<BlockSize>]), | 142 | 25.7k | ) { | 143 | 25.7k | let pos = self.get_pos(); | 144 | 25.7k | // using `self.remaining()` for some reason | 145 | 25.7k | // prevents panic elimination | 146 | 25.7k | let rem = self.size() - pos; | 147 | 25.7k | let n = input.len(); | 148 | 25.7k | // Note that checking condition `pos + n < BlockSize` is | 149 | 25.7k | // equivalent to checking `n < rem`, where `rem` is equal | 150 | 25.7k | // to `BlockSize - pos`. Using the latter allows us to work | 151 | 25.7k | // around compiler accounting for possible overflow of | 152 | 25.7k | // `pos + n` which results in it inserting unreachable | 153 | 25.7k | // panic branches. Using `unreachable_unchecked` in `get_pos` | 154 | 25.7k | // we convince compiler that `BlockSize - pos` never underflows. | 155 | 25.7k | if Kind::invariant(n, rem) { | 156 | | // double slicing allows to remove panic branches | 157 | 25.2k | self.buffer[pos..][..n].copy_from_slice(input); | 158 | 25.2k | self.set_pos_unchecked(pos + n); | 159 | 25.2k | return; | 160 | 467 | } | 161 | 467 | if pos != 0 { | 162 | 467 | let (left, right) = input.split_at(rem); | 163 | 467 | input = right; | 164 | 467 | self.buffer[pos..].copy_from_slice(left); | 165 | 467 | compress(slice::from_ref(&self.buffer)); | 166 | 467 | } | 167 | | | 168 | 467 | let (blocks, leftover) = Kind::split_blocks(input); | 169 | 467 | if !blocks.is_empty() { | 170 | 467 | compress(blocks); | 171 | 467 | } | 172 | | | 173 | 467 | let n = leftover.len(); | 174 | 467 | self.buffer[..n].copy_from_slice(leftover); | 175 | 467 | self.set_pos_unchecked(n); | 176 | 25.7k | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<digest::core_api::wrapper::CoreWrapper<sha3::Sha3_512Core> as digest::Update>::update::{closure#0}> Line | Count | Source | 138 | 2.93k | pub fn digest_blocks( | 139 | 2.93k | &mut self, | 140 | 2.93k | mut input: &[u8], | 141 | 2.93k | mut compress: impl FnMut(&[Block<BlockSize>]), | 142 | 2.93k | ) { | 143 | 2.93k | let pos = self.get_pos(); | 144 | 2.93k | // using `self.remaining()` for some reason | 145 | 2.93k | // prevents panic elimination | 146 | 2.93k | let rem = self.size() - pos; | 147 | 2.93k | let n = input.len(); | 148 | 2.93k | // Note that checking condition `pos + n < BlockSize` is | 149 | 2.93k | // equivalent to checking `n < rem`, where `rem` is equal | 150 | 2.93k | // to `BlockSize - pos`. Using the latter allows us to work | 151 | 2.93k | // around compiler accounting for possible overflow of | 152 | 2.93k | // `pos + n` which results in it inserting unreachable | 153 | 2.93k | // panic branches. Using `unreachable_unchecked` in `get_pos` | 154 | 2.93k | // we convince compiler that `BlockSize - pos` never underflows. | 155 | 2.93k | if Kind::invariant(n, rem) { | 156 | | // double slicing allows to remove panic branches | 157 | 2.93k | self.buffer[pos..][..n].copy_from_slice(input); | 158 | 2.93k | self.set_pos_unchecked(pos + n); | 159 | 2.93k | return; | 160 | 0 | } | 161 | 0 | if pos != 0 { | 162 | 0 | let (left, right) = input.split_at(rem); | 163 | 0 | input = right; | 164 | 0 | self.buffer[pos..].copy_from_slice(left); | 165 | 0 | compress(slice::from_ref(&self.buffer)); | 166 | 0 | } | 167 | | | 168 | 0 | let (blocks, leftover) = Kind::split_blocks(input); | 169 | 0 | if !blocks.is_empty() { | 170 | 0 | compress(blocks); | 171 | 0 | } | 172 | | | 173 | 0 | let n = leftover.len(); | 174 | 0 | self.buffer[..n].copy_from_slice(leftover); | 175 | 0 | self.set_pos_unchecked(n); | 176 | 2.93k | } |
Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<sha3::CShake128Core>::new_with_function_name::{closure#0}> Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<sha3::CShake128Core>::new_with_function_name::{closure#2}> Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<sha3::CShake128Core>::new_with_function_name::{closure#3}> Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<sha3::CShake128Core>::new_with_function_name::{closure#4}> Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<sha3::CShake128Core>::new_with_function_name::{closure#1}> Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<sha3::CShake256Core>::new_with_function_name::{closure#0}> Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<sha3::CShake256Core>::new_with_function_name::{closure#2}> Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<sha3::CShake256Core>::new_with_function_name::{closure#3}> Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<sha3::CShake256Core>::new_with_function_name::{closure#4}> Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::digest_blocks::<<sha3::CShake256Core>::new_with_function_name::{closure#1}> |
177 | | |
178 | | /// Reset buffer by setting cursor position to zero. |
179 | | #[inline(always)] |
180 | | pub fn reset(&mut self) { |
181 | | self.set_pos_unchecked(0); |
182 | | } |
183 | | |
184 | | /// Pad remaining data with zeros and return resulting block. |
185 | | #[inline(always)] |
186 | 35.4k | pub fn pad_with_zeros(&mut self) -> &mut Block<BlockSize> { |
187 | 35.4k | let pos = self.get_pos(); |
188 | 3.90M | self.buffer[pos..].iter_mut().for_each(|b| *b = 0); <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::pad_with_zeros::{closure#0} Line | Count | Source | 188 | 39.8k | self.buffer[pos..].iter_mut().for_each(|b| *b = 0); |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::pad_with_zeros::{closure#0} Line | Count | Source | 188 | 2.47M | self.buffer[pos..].iter_mut().for_each(|b| *b = 0); |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::pad_with_zeros::{closure#0} Line | Count | Source | 188 | 1.39M | self.buffer[pos..].iter_mut().for_each(|b| *b = 0); |
|
189 | 35.4k | self.set_pos_unchecked(0); |
190 | 35.4k | &mut self.buffer |
191 | 35.4k | } <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::pad_with_zeros Line | Count | Source | 186 | 18.4k | pub fn pad_with_zeros(&mut self) -> &mut Block<BlockSize> { | 187 | 18.4k | let pos = self.get_pos(); | 188 | 18.4k | self.buffer[pos..].iter_mut().for_each(|b| *b = 0); | 189 | 18.4k | self.set_pos_unchecked(0); | 190 | 18.4k | &mut self.buffer | 191 | 18.4k | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::pad_with_zeros Line | Count | Source | 186 | 15.1k | pub fn pad_with_zeros(&mut self) -> &mut Block<BlockSize> { | 187 | 15.1k | let pos = self.get_pos(); | 188 | 15.1k | self.buffer[pos..].iter_mut().for_each(|b| *b = 0); | 189 | 15.1k | self.set_pos_unchecked(0); | 190 | 15.1k | &mut self.buffer | 191 | 15.1k | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::pad_with_zeros Line | Count | Source | 186 | 1.87k | pub fn pad_with_zeros(&mut self) -> &mut Block<BlockSize> { | 187 | 1.87k | let pos = self.get_pos(); | 188 | 1.87k | self.buffer[pos..].iter_mut().for_each(|b| *b = 0); | 189 | 1.87k | self.set_pos_unchecked(0); | 190 | 1.87k | &mut self.buffer | 191 | 1.87k | } |
Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::pad_with_zeros Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::pad_with_zeros |
192 | | |
193 | | /// Return current cursor position. |
194 | | #[inline(always)] |
195 | 6.03M | pub fn get_pos(&self) -> usize { |
196 | 6.03M | let pos = self.pos as usize; |
197 | 6.03M | if !Kind::invariant(pos, BlockSize::USIZE) { |
198 | 0 | debug_assert!(false); |
199 | | // SAFETY: `pos` never breaks the invariant |
200 | | unsafe { |
201 | 0 | core::hint::unreachable_unchecked(); |
202 | | } |
203 | 6.03M | } |
204 | 6.03M | pos |
205 | 6.03M | } <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::get_pos Line | Count | Source | 195 | 5.94M | pub fn get_pos(&self) -> usize { | 196 | 5.94M | let pos = self.pos as usize; | 197 | 5.94M | if !Kind::invariant(pos, BlockSize::USIZE) { | 198 | 0 | debug_assert!(false); | 199 | | // SAFETY: `pos` never breaks the invariant | 200 | | unsafe { | 201 | 0 | core::hint::unreachable_unchecked(); | 202 | | } | 203 | 5.94M | } | 204 | 5.94M | pos | 205 | 5.94M | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::get_pos Line | Count | Source | 195 | 84.0k | pub fn get_pos(&self) -> usize { | 196 | 84.0k | let pos = self.pos as usize; | 197 | 84.0k | if !Kind::invariant(pos, BlockSize::USIZE) { | 198 | 0 | debug_assert!(false); | 199 | | // SAFETY: `pos` never breaks the invariant | 200 | | unsafe { | 201 | 0 | core::hint::unreachable_unchecked(); | 202 | | } | 203 | 84.0k | } | 204 | 84.0k | pos | 205 | 84.0k | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::get_pos Line | Count | Source | 195 | 6.67k | pub fn get_pos(&self) -> usize { | 196 | 6.67k | let pos = self.pos as usize; | 197 | 6.67k | if !Kind::invariant(pos, BlockSize::USIZE) { | 198 | 0 | debug_assert!(false); | 199 | | // SAFETY: `pos` never breaks the invariant | 200 | | unsafe { | 201 | 0 | core::hint::unreachable_unchecked(); | 202 | | } | 203 | 6.67k | } | 204 | 6.67k | pos | 205 | 6.67k | } |
Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::get_pos Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::get_pos |
206 | | |
207 | | /// Return slice of data stored inside the buffer. |
208 | | #[inline(always)] |
209 | | pub fn get_data(&self) -> &[u8] { |
210 | | &self.buffer[..self.get_pos()] |
211 | | } |
212 | | |
213 | | /// Set buffer content and cursor position. |
214 | | /// |
215 | | /// # Panics |
216 | | /// If `pos` is bigger or equal to block size. |
217 | | #[inline] |
218 | | pub fn set(&mut self, buf: Block<BlockSize>, pos: usize) { |
219 | | assert!(Kind::invariant(pos, BlockSize::USIZE)); |
220 | | self.buffer = buf; |
221 | | self.set_pos_unchecked(pos); |
222 | | } |
223 | | |
224 | | /// Return size of the internal buffer in bytes. |
225 | | #[inline(always)] |
226 | 3.02M | pub fn size(&self) -> usize { |
227 | 3.02M | BlockSize::USIZE |
228 | 3.02M | } <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::size Line | Count | Source | 226 | 2.98M | pub fn size(&self) -> usize { | 227 | 2.98M | BlockSize::USIZE | 228 | 2.98M | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::size Line | Count | Source | 226 | 40.8k | pub fn size(&self) -> usize { | 227 | 40.8k | BlockSize::USIZE | 228 | 40.8k | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::size Line | Count | Source | 226 | 2.93k | pub fn size(&self) -> usize { | 227 | 2.93k | BlockSize::USIZE | 228 | 2.93k | } |
Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::size Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::size |
229 | | |
230 | | /// Return number of remaining bytes in the internal buffer. |
231 | | #[inline(always)] |
232 | 2.93M | pub fn remaining(&self) -> usize { |
233 | 2.93M | self.size() - self.get_pos() |
234 | 2.93M | } <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::remaining Line | Count | Source | 232 | 2.92M | pub fn remaining(&self) -> usize { | 233 | 2.92M | self.size() - self.get_pos() | 234 | 2.92M | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::remaining Line | Count | Source | 232 | 12.8k | pub fn remaining(&self) -> usize { | 233 | 12.8k | self.size() - self.get_pos() | 234 | 12.8k | } |
|
235 | | |
236 | | #[inline(always)] |
237 | 3.06M | fn set_pos_unchecked(&mut self, pos: usize) { |
238 | 3.06M | debug_assert!(Kind::invariant(pos, BlockSize::USIZE)); |
239 | 3.06M | self.pos = pos as u8; |
240 | 3.06M | } <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::set_pos_unchecked Line | Count | Source | 237 | 3.00M | fn set_pos_unchecked(&mut self, pos: usize) { | 238 | 3.00M | debug_assert!(Kind::invariant(pos, BlockSize::USIZE)); | 239 | 3.00M | self.pos = pos as u8; | 240 | 3.00M | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::set_pos_unchecked Line | Count | Source | 237 | 56.0k | fn set_pos_unchecked(&mut self, pos: usize) { | 238 | 56.0k | debug_assert!(Kind::invariant(pos, BlockSize::USIZE)); | 239 | 56.0k | self.pos = pos as u8; | 240 | 56.0k | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::set_pos_unchecked Line | Count | Source | 237 | 4.80k | fn set_pos_unchecked(&mut self, pos: usize) { | 238 | 4.80k | debug_assert!(Kind::invariant(pos, BlockSize::USIZE)); | 239 | 4.80k | self.pos = pos as u8; | 240 | 4.80k | } |
Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::set_pos_unchecked Unexecuted instantiation: <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::set_pos_unchecked |
241 | | } |
242 | | |
243 | | impl<BlockSize> BlockBuffer<BlockSize, Eager> |
244 | | where |
245 | | BlockSize: ArrayLength<u8> + IsLess<U256>, |
246 | | Le<BlockSize, U256>: NonZero, |
247 | | { |
248 | | /// Set `data` to generated blocks. |
249 | | #[inline] |
250 | 2.93M | pub fn set_data( |
251 | 2.93M | &mut self, |
252 | 2.93M | mut data: &mut [u8], |
253 | 2.93M | mut process_blocks: impl FnMut(&mut [Block<BlockSize>]), |
254 | 2.93M | ) { |
255 | 2.93M | let pos = self.get_pos(); |
256 | 2.93M | let r = self.remaining(); |
257 | 2.93M | let n = data.len(); |
258 | 2.93M | if pos != 0 { |
259 | 2.87M | if n < r { |
260 | | // double slicing allows to remove panic branches |
261 | 2.83M | data.copy_from_slice(&self.buffer[pos..][..n]); |
262 | 2.83M | self.set_pos_unchecked(pos + n); |
263 | 2.83M | return; |
264 | 38.1k | } |
265 | 38.1k | let (left, right) = data.split_at_mut(r); |
266 | 38.1k | data = right; |
267 | 38.1k | left.copy_from_slice(&self.buffer[pos..]); |
268 | 69.3k | } |
269 | | |
270 | 107k | let (blocks, leftover) = to_blocks_mut(data); |
271 | 107k | process_blocks(blocks); |
272 | 107k | |
273 | 107k | let n = leftover.len(); |
274 | 107k | if n != 0 { |
275 | 69.3k | let mut block = Default::default(); |
276 | 69.3k | process_blocks(slice::from_mut(&mut block)); |
277 | 69.3k | leftover.copy_from_slice(&block[..n]); |
278 | 69.3k | self.buffer = block; |
279 | 69.3k | } |
280 | 107k | self.set_pos_unchecked(n); |
281 | 2.93M | } <block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::set_data::<<digest::core_api::xof_reader::XofReaderCoreWrapper<sha3::Shake128ReaderCore> as digest::XofReader>::read::{closure#0}> Line | Count | Source | 250 | 2.92M | pub fn set_data( | 251 | 2.92M | &mut self, | 252 | 2.92M | mut data: &mut [u8], | 253 | 2.92M | mut process_blocks: impl FnMut(&mut [Block<BlockSize>]), | 254 | 2.92M | ) { | 255 | 2.92M | let pos = self.get_pos(); | 256 | 2.92M | let r = self.remaining(); | 257 | 2.92M | let n = data.len(); | 258 | 2.92M | if pos != 0 { | 259 | 2.87M | if n < r { | 260 | | // double slicing allows to remove panic branches | 261 | 2.83M | data.copy_from_slice(&self.buffer[pos..][..n]); | 262 | 2.83M | self.set_pos_unchecked(pos + n); | 263 | 2.83M | return; | 264 | 38.1k | } | 265 | 38.1k | let (left, right) = data.split_at_mut(r); | 266 | 38.1k | data = right; | 267 | 38.1k | left.copy_from_slice(&self.buffer[pos..]); | 268 | 56.4k | } | 269 | | | 270 | 94.6k | let (blocks, leftover) = to_blocks_mut(data); | 271 | 94.6k | process_blocks(blocks); | 272 | 94.6k | | 273 | 94.6k | let n = leftover.len(); | 274 | 94.6k | if n != 0 { | 275 | 56.4k | let mut block = Default::default(); | 276 | 56.4k | process_blocks(slice::from_mut(&mut block)); | 277 | 56.4k | leftover.copy_from_slice(&block[..n]); | 278 | 56.4k | self.buffer = block; | 279 | 56.4k | } | 280 | 94.6k | self.set_pos_unchecked(n); | 281 | 2.92M | } |
<block_buffer::BlockBuffer<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, block_buffer::Eager>>::set_data::<<digest::core_api::xof_reader::XofReaderCoreWrapper<sha3::Shake256ReaderCore> as digest::XofReader>::read::{closure#0}> Line | Count | Source | 250 | 12.8k | pub fn set_data( | 251 | 12.8k | &mut self, | 252 | 12.8k | mut data: &mut [u8], | 253 | 12.8k | mut process_blocks: impl FnMut(&mut [Block<BlockSize>]), | 254 | 12.8k | ) { | 255 | 12.8k | let pos = self.get_pos(); | 256 | 12.8k | let r = self.remaining(); | 257 | 12.8k | let n = data.len(); | 258 | 12.8k | if pos != 0 { | 259 | 0 | if n < r { | 260 | | // double slicing allows to remove panic branches | 261 | 0 | data.copy_from_slice(&self.buffer[pos..][..n]); | 262 | 0 | self.set_pos_unchecked(pos + n); | 263 | 0 | return; | 264 | 0 | } | 265 | 0 | let (left, right) = data.split_at_mut(r); | 266 | 0 | data = right; | 267 | 0 | left.copy_from_slice(&self.buffer[pos..]); | 268 | 12.8k | } | 269 | | | 270 | 12.8k | let (blocks, leftover) = to_blocks_mut(data); | 271 | 12.8k | process_blocks(blocks); | 272 | 12.8k | | 273 | 12.8k | let n = leftover.len(); | 274 | 12.8k | if n != 0 { | 275 | 12.8k | let mut block = Default::default(); | 276 | 12.8k | process_blocks(slice::from_mut(&mut block)); | 277 | 12.8k | leftover.copy_from_slice(&block[..n]); | 278 | 12.8k | self.buffer = block; | 279 | 12.8k | } | 280 | 12.8k | self.set_pos_unchecked(n); | 281 | 12.8k | } |
|
282 | | |
283 | | /// Compress remaining data after padding it with `delim`, zeros and |
284 | | /// the `suffix` bytes. If there is not enough unused space, `compress` |
285 | | /// will be called twice. |
286 | | /// |
287 | | /// # Panics |
288 | | /// If suffix length is bigger than block size. |
289 | | #[inline(always)] |
290 | | pub fn digest_pad( |
291 | | &mut self, |
292 | | delim: u8, |
293 | | suffix: &[u8], |
294 | | mut compress: impl FnMut(&Block<BlockSize>), |
295 | | ) { |
296 | | if suffix.len() > BlockSize::USIZE { |
297 | | panic!("suffix is too long"); |
298 | | } |
299 | | let pos = self.get_pos(); |
300 | | self.buffer[pos] = delim; |
301 | | for b in &mut self.buffer[pos + 1..] { |
302 | | *b = 0; |
303 | | } |
304 | | |
305 | | let n = self.size() - suffix.len(); |
306 | | if self.size() - pos - 1 < suffix.len() { |
307 | | compress(&self.buffer); |
308 | | let mut block = Block::<BlockSize>::default(); |
309 | | block[n..].copy_from_slice(suffix); |
310 | | compress(&block); |
311 | | } else { |
312 | | self.buffer[n..].copy_from_slice(suffix); |
313 | | compress(&self.buffer); |
314 | | } |
315 | | self.set_pos_unchecked(0) |
316 | | } |
317 | | |
318 | | /// Pad message with 0x80, zeros and 64-bit message length using |
319 | | /// big-endian byte order. |
320 | | #[inline] |
321 | | pub fn len64_padding_be(&mut self, data_len: u64, compress: impl FnMut(&Block<BlockSize>)) { |
322 | | self.digest_pad(0x80, &data_len.to_be_bytes(), compress); |
323 | | } |
324 | | |
325 | | /// Pad message with 0x80, zeros and 64-bit message length using |
326 | | /// little-endian byte order. |
327 | | #[inline] |
328 | | pub fn len64_padding_le(&mut self, data_len: u64, compress: impl FnMut(&Block<BlockSize>)) { |
329 | | self.digest_pad(0x80, &data_len.to_le_bytes(), compress); |
330 | | } |
331 | | |
332 | | /// Pad message with 0x80, zeros and 128-bit message length using |
333 | | /// big-endian byte order. |
334 | | #[inline] |
335 | | pub fn len128_padding_be(&mut self, data_len: u128, compress: impl FnMut(&Block<BlockSize>)) { |
336 | | self.digest_pad(0x80, &data_len.to_be_bytes(), compress); |
337 | | } |
338 | | } |
339 | | |
340 | | /// Split message into mutable slice of parallel blocks, blocks, and leftover bytes. |
341 | | #[inline(always)] |
342 | 107k | fn to_blocks_mut<N: ArrayLength<u8>>(data: &mut [u8]) -> (&mut [Block<N>], &mut [u8]) { |
343 | 107k | let nb = data.len() / N::USIZE; |
344 | 107k | let (left, right) = data.split_at_mut(nb * N::USIZE); |
345 | 107k | let p = left.as_mut_ptr() as *mut Block<N>; |
346 | 107k | // SAFETY: we guarantee that `blocks` does not point outside of `data`, and `p` is valid for |
347 | 107k | // mutation |
348 | 107k | let blocks = unsafe { slice::from_raw_parts_mut(p, nb) }; |
349 | 107k | (blocks, right) |
350 | 107k | } block_buffer::to_blocks_mut::<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>> Line | Count | Source | 342 | 94.6k | fn to_blocks_mut<N: ArrayLength<u8>>(data: &mut [u8]) -> (&mut [Block<N>], &mut [u8]) { | 343 | 94.6k | let nb = data.len() / N::USIZE; | 344 | 94.6k | let (left, right) = data.split_at_mut(nb * N::USIZE); | 345 | 94.6k | let p = left.as_mut_ptr() as *mut Block<N>; | 346 | 94.6k | // SAFETY: we guarantee that `blocks` does not point outside of `data`, and `p` is valid for | 347 | 94.6k | // mutation | 348 | 94.6k | let blocks = unsafe { slice::from_raw_parts_mut(p, nb) }; | 349 | 94.6k | (blocks, right) | 350 | 94.6k | } |
block_buffer::to_blocks_mut::<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>> Line | Count | Source | 342 | 12.8k | fn to_blocks_mut<N: ArrayLength<u8>>(data: &mut [u8]) -> (&mut [Block<N>], &mut [u8]) { | 343 | 12.8k | let nb = data.len() / N::USIZE; | 344 | 12.8k | let (left, right) = data.split_at_mut(nb * N::USIZE); | 345 | 12.8k | let p = left.as_mut_ptr() as *mut Block<N>; | 346 | 12.8k | // SAFETY: we guarantee that `blocks` does not point outside of `data`, and `p` is valid for | 347 | 12.8k | // mutation | 348 | 12.8k | let blocks = unsafe { slice::from_raw_parts_mut(p, nb) }; | 349 | 12.8k | (blocks, right) | 350 | 12.8k | } |
|