arnaucube
arnaucube/miden-cryptoPublic Self-hosted repository
fix: always pad bytes with 10*0 (#267)

Al-Kindi-0 82364884+Al-Kindi-0@users.noreply.github.com
Sat, 27 Jan 2024 02:54:14 +0100
commit

0acceaa5262ab5265ff912cabd1e490ff22990fe

parent

3882e0f719189a0a43ee2efa7652e465c5247c5b

1 files changed, 2 insertions(+), 4 deletions(-)

jump to
M src/hash/rescue/rpx/mod.rs → src/hash/rescue/rpx/mod.rs

@@ -88,10 +88,8 @@ // every time the rate range is filled, a permutation is performed. if the final value of

// `i` is not zero, then the chunks count wasn't enough to fill the state range, and an // additional permutation must be performed. let i = bytes.chunks(BINARY_CHUNK_SIZE).fold(0, |i, chunk| { - // the last element of the iteration may or may not be a full chunk. if it's not, then - // we need to pad the remainder bytes of the chunk with zeroes, separated by a `1`. - // this will avoid collisions at the bytes level. - if chunk.len() == BINARY_CHUNK_SIZE { + // we always pad `bytes` with a 1 followed by as many 0's to fill up `buf`. + if i != num_field_elem - 1 { buf[..BINARY_CHUNK_SIZE].copy_from_slice(chunk); } else { buf.fill(0);