Skip to content

Commit eb814f1

Browse files
committed
tweak read
1 parent b9827f9 commit eb814f1

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

cshake/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,14 @@ impl<Rate: BlockSizes> XofReader for CShakeReader<Rate> {
250250
} = self;
251251

252252
buffer.read(buf, |block| {
253-
for (src, dst) in state.iter().zip(block.chunks_mut(8)) {
254-
dst.copy_from_slice(&src.to_le_bytes()[..dst.len()]);
253+
let mut chunks = block.chunks_exact_mut(8);
254+
for (src, dst) in state.iter().zip(&mut chunks) {
255+
dst.copy_from_slice(&src.to_le_bytes());
255256
}
257+
assert!(
258+
chunks.into_remainder().is_empty(),
259+
"rate is either 136 or 168",
260+
);
256261
keccak.with_f1600(|f1600| f1600(state));
257262
});
258263
}

turbo-shake/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,14 @@ impl<Rate: BlockSizes> XofReader for TurboShakeReader<Rate> {
191191
} = self;
192192

193193
buffer.read(buf, |block| {
194-
for (src, dst) in state.iter().zip(block.chunks_mut(8)) {
195-
dst.copy_from_slice(&src.to_le_bytes()[..dst.len()]);
194+
let mut chunks = block.chunks_exact_mut(8);
195+
for (src, dst) in state.iter().zip(&mut chunks) {
196+
dst.copy_from_slice(&src.to_le_bytes());
196197
}
198+
assert!(
199+
chunks.into_remainder().is_empty(),
200+
"rate is either 136 or 168",
201+
);
197202
keccak.with_p1600::<ROUNDS>(|p1600| p1600(state));
198203
});
199204
}

0 commit comments

Comments
 (0)