Skip to content

Commit dfef397

Browse files
committed
add a comment explaining that hash_slice input data size must be a multiple of 8. Thanks @sanjay-sol for reporting this undocumented behaviour.
1 parent 6f06c02 commit dfef397

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

crates/backend/symetric/src/sponge.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
use crate::Compression;
44

55
// IV should have been added to data when necessary (typically: when the length of the data beeing hashed is not constant). Maybe we should re-add IV all the time for simplicity?
6+
// assumes data length is a multiple of RATE (= 8 in practice).
67
pub fn hash_slice<T, Comp, const WIDTH: usize, const RATE: usize, const OUT: usize>(comp: &Comp, data: &[T]) -> [T; OUT]
78
where
89
T: Default + Copy,
910
Comp: Compression<[T; WIDTH]>,
1011
{
1112
debug_assert!(RATE == OUT);
1213
debug_assert!(WIDTH == OUT + RATE);
14+
debug_assert!(data.len().is_multiple_of(RATE));
1315
let n_chunks = data.len() / RATE;
1416
debug_assert!(n_chunks >= 2);
1517
let mut state: [T; WIDTH] = data[data.len() - WIDTH..].try_into().unwrap();

0 commit comments

Comments
 (0)