Skip to content

Commit

Permalink
chore: remove reordering of bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Sep 23, 2024
1 parent 10b9c7b commit 3efd419
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions noir_stdlib/src/hash/keccak.nr
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,22 @@ pub(crate) fn keccak256<let N: u32>(input: [u8; N], message_size: u32) -> [u8; 3
// populate a vector of 64-bit limbs from our byte array
for i in 0..num_limbs {
let limb_start = WORD_SIZE * i;
let limb_end: u32 = limb_start + (WORD_SIZE - 1);

// TODO: we should be able to just remove this for-loop by indexing `block_bytes` more intelligently
// when constructing `sliced` below.
for j in 0..WORD_SIZE / 2 {
// keccak lanes interpret memory as little-endian integers,
// means we need to swap our byte ordering
let temp = block_bytes[limb_end - j];
block_bytes[limb_end - j] = block_bytes[limb_start+j];
block_bytes[limb_start + j] = temp;
}

let mut sliced = 0;
if (limb_start + WORD_SIZE > max_blocks_length) {
let slice_size = max_blocks_length - limb_start;
let byte_shift = (WORD_SIZE - slice_size) * 8;
let mut v = 1;
for k in 0..slice_size {
sliced += v * (block_bytes[limb_end-k] as Field);
sliced += v * (block_bytes[limb_start+k] as Field);
v *= 256;
}
let w = 1 << (byte_shift as u8);
sliced *= w as Field;
} else {
let mut v = 1;
for k in 0..WORD_SIZE {
sliced += v * (block_bytes[limb_end-k] as Field);
sliced += v * (block_bytes[limb_start+k] as Field);
v *= 256;
}
}
Expand Down

0 comments on commit 3efd419

Please sign in to comment.