Skip to content

Commit

Permalink
fix: properly pad sha256 input
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Feb 7, 2024
1 parent e47a823 commit 385e1fd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/coprocessor/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ fn synthesize_sha256<F: LurkField, CS: ConstraintSystem<F>>(

let mut bits = vec![];

let pad_to_next_len_multiple_of_8 = |bits: &mut Vec<_>| {
bits.resize((bits.len() + 7) / 8 * 8, zero.clone());
};

for ptr in ptrs {
let tag_bits = ptr
.tag()
Expand All @@ -39,9 +43,9 @@ fn synthesize_sha256<F: LurkField, CS: ConstraintSystem<F>>(
.to_bits_le_strict(&mut cs.namespace(|| "preimage_hash_bits"))?;

bits.extend(tag_bits);
bits.push(zero.clone()); // need 256 bits (or some multiple of 8).
pad_to_next_len_multiple_of_8(&mut bits);
bits.extend(hash_bits);
bits.push(zero.clone()); // need 256 bits (or some multiple of 8).
pad_to_next_len_multiple_of_8(&mut bits);
}

bits.reverse();
Expand Down

0 comments on commit 385e1fd

Please sign in to comment.