use bitvec::prelude::*;
use halo2::pasta::pallas;
use sinsemilla::HashDomain;
#[allow(non_snake_case)]
pub fn sinsemilla_hash(D: &[u8], M: &BitVec<u8, Lsb0>) -> Option<pallas::Base> {
let domain = std::str::from_utf8(D).expect("must be valid UTF-8");
let hash_domain = HashDomain::new(domain);
hash_domain.hash(M.iter().map(|b| *b.as_ref())).into()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::orchard::tests::vectors;
#[test]
#[allow(non_snake_case)]
fn sinsemilla_hackworks_test_vectors() {
use halo2::pasta::group::ff::PrimeField;
for tv in tests::vectors::SINSEMILLA.iter() {
let D = tv.domain.as_slice();
let M: &BitVec<u8, Lsb0> = &tv.msg.iter().collect();
assert_eq!(
sinsemilla_hash(D, M).expect("should not fail per Theorem 5.4.4"),
pallas::Base::from_repr(tv.hash).unwrap()
)
}
}
}