MCPcopy Create free account
hub / github.com/RustCrypto/utils / absorb_u64_le

Method absorb_u64_le

sponge-cursor/src/lib.rs:91–136  ·  view source on GitHub ↗
(
        &mut self,
        state: &mut [u64; N],
        sponge: fn(&mut [u64; N]),
        mut data: &[u8],
    )

Source from the content-addressed store, hash-verified

89 #[allow(clippy::missing_panics_doc, reason = "the method is panic-free")]
90 #[inline]
91 pub fn absorb_u64_le<const N: usize>(
92 &mut self,
93 state: &mut [u64; N],
94 sponge: fn(&mut [u64; N]),
95 mut data: &[u8],
96 ) {
97 const {
98 assert!(RATE <= size_of::<[u64; N]>());
99 assert!(RATE < u8::MAX as usize);
100 assert!(RATE % size_of::<u64>() == 0);
101 };
102
103 if self.pos != 0 {
104 let pos = self.pos();
105 let rem_len = RATE
106 .checked_sub(pos)
107 .expect("`pos` is always smaller than `RATE`");
108
109 if data.len() < rem_len {
110 u64_le_utils::absorb_partial::<N, RATE>(state, pos, data);
111 self.set_pos(pos + data.len());
112 return;
113 }
114
115 let (head, tail) = data.split_at(rem_len);
116 data = tail;
117 u64_le_utils::absorb_partial::<N, RATE>(state, pos, head);
118
119 sponge(state);
120 }
121
122 let blocks = data.chunks_exact(RATE);
123 let tail = blocks.remainder();
124
125 for block in blocks {
126 let block: &[u8; RATE] = block.try_into().expect("`block` has correct size");
127 u64_le_utils::absorb_full(state, block);
128 sponge(state);
129 }
130
131 if !tail.is_empty() {
132 u64_le_utils::absorb_partial::<N, RATE>(state, 0, tail);
133 }
134
135 self.set_pos(tail.len());
136 }
137
138 /// Squeeze data from `state` by reading it into `buf` using little-endian byte order.
139 ///

Callers 1

keccak_testFunction · 0.80

Calls 8

absorb_fullFunction · 0.85
posMethod · 0.80
expectMethod · 0.80
lenMethod · 0.80
split_atMethod · 0.80
try_intoMethod · 0.80
is_emptyMethod · 0.80
set_posMethod · 0.45

Tested by 1

keccak_testFunction · 0.64