from_partial (non-target) now takes in a slice

- Doesn't need to take in a `Vec`.
This commit is contained in:
BGluth 2022-02-09 18:31:58 -07:00
parent fe89fa949e
commit adf5444f3f
2 changed files with 8 additions and 10 deletions

View File

@ -31,14 +31,12 @@ impl<F: Field> HashOut<F> {
}
}
pub fn from_partial(mut elements: Vec<F>) -> Self {
debug_assert!(elements.len() <= 4);
while elements.len() < 4 {
elements.push(F::ZERO);
}
Self {
elements: [elements[0], elements[1], elements[2], elements[3]],
}
pub fn from_partial(elements_in: &[F]) -> Self {
debug_assert!(elements_in.len() <= 4);
let mut elements = [F::ZERO; 4];
elements[0..elements_in.len()].copy_from_slice(elements_in);
Self { elements }
}
pub fn rand_from_rng<R: Rng>(rng: &mut R) -> Self {

View File

@ -14,11 +14,11 @@ pub const SPONGE_WIDTH: usize = SPONGE_RATE + SPONGE_CAPACITY;
/// Hash the vector if necessary to reduce its length to ~256 bits. If it already fits, this is a
/// no-op.
pub fn hash_or_noop<F: RichField, P: PlonkyPermutation<F>>(inputs: Vec<F>) -> HashOut<F> {
pub fn hash_or_noop<F: RichField, P: PlonkyPermutation<F>>(inputs: &[F]) -> HashOut<F> {
if inputs.len() <= 4 {
HashOut::from_partial(inputs)
} else {
hash_n_to_hash_no_pad::<F, P>(&inputs)
hash_n_to_hash_no_pad::<F, P>(inputs)
}
}