Skip to content

Commit

Permalink
chore: undo recent change
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Jun 11, 2024
1 parent 114d739 commit 87644b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/hash/rescue/rpo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ impl Hasher for Rpo256 {
// every time the rate range is filled, a permutation is performed. if the final value of
// `rate_pos` is not zero, then the chunks count wasn't enough to fill the state range,
// and an additional permutation must be performed.
let mut current_element = 0_usize;
// handle the case of an empty `bytes`
let last_element = if num_field_elem == 0 {
current_element
} else {
num_field_elem - 1
};
let rate_pos = bytes.chunks(BINARY_CHUNK_SIZE).fold(0, |rate_pos, chunk| {
// copy the chunk into the buffer
if chunk.len() == BINARY_CHUNK_SIZE {
if current_element != last_element {
buf[..BINARY_CHUNK_SIZE].copy_from_slice(chunk);
} else {
// on the last iteration, we pad `buf` with a 1 followed by as many 0's as are
Expand All @@ -97,6 +104,7 @@ impl Hasher for Rpo256 {
buf[..chunk.len()].copy_from_slice(chunk);
buf[chunk.len()] = 1;
}
current_element += 1;

// set the current rate element to the input. since we take at most 7 bytes, we are
// guaranteed that the inputs data will fit into a single field element.
Expand Down
10 changes: 9 additions & 1 deletion src/hash/rescue/rpx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,16 @@ impl Hasher for Rpx256 {
// every time the rate range is filled, a permutation is performed. if the final value of
// `rate_pos` is not zero, then the chunks count wasn't enough to fill the state range,
// and an additional permutation must be performed.
let mut current_element = 0_usize;
// handle the case of an empty `bytes`
let last_element = if num_field_elem == 0 {
current_element
} else {
num_field_elem - 1
};
let rate_pos = bytes.chunks(BINARY_CHUNK_SIZE).fold(0, |rate_pos, chunk| {
// copy the chunk into the buffer
if chunk.len() == BINARY_CHUNK_SIZE {
if current_element != last_element {
buf[..BINARY_CHUNK_SIZE].copy_from_slice(chunk);
} else {
// on the last iteration, we pad `buf` with a 1 followed by as many 0's as are
Expand All @@ -102,6 +109,7 @@ impl Hasher for Rpx256 {
buf[..chunk.len()].copy_from_slice(chunk);
buf[chunk.len()] = 1;
}
current_element += 1;

// set the current rate element to the input. since we take at most 7 bytes, we are
// guaranteed that the inputs data will fit into a single field element.
Expand Down

0 comments on commit 87644b4

Please sign in to comment.