Skip to content

Commit

Permalink
Dev/peinlcy (#179)
Browse files Browse the repository at this point in the history
* add hash bytes

* add poseidon hash bytes

* padding enough to input bytes in hash_bytes
  • Loading branch information
peinlcy authored Dec 5, 2023
1 parent 5b15ebd commit 4cb3612
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion plonky2/plonky2/src/hash/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ pub fn poseidon_hash_bytes(input: &[u8]) -> [u8; 32] {
pub fn hash_bytes<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>(
input: &[u8],
) -> [u8; 32] {
let field_elements = bytes_to_u64s(input)
let u64_arr = if input.len() % GOLDILOCKS_FIELD_U8_LEN == 0 {
bytes_to_u64s(input)
} else {
let padding_count = GOLDILOCKS_FIELD_U8_LEN - input.len() % GOLDILOCKS_FIELD_U8_LEN;
let mut bytes = vec![0 as u8; padding_count];
bytes.extend_from_slice(input);
bytes_to_u64s(bytes.as_slice())
};

let field_elements = u64_arr
.par_iter()
.map(|&i| F::from_canonical_u64(i))
.collect::<Vec<_>>();
Expand Down

0 comments on commit 4cb3612

Please sign in to comment.