decaf377_fmd/
hash.rs

1use decaf377::Fr;
2
3pub fn to_bit(a: &[u8; 32], b: &[u8; 32], c: &[u8; 32]) -> u8 {
4    blake2b_simd::Params::default()
5        .personal(b"decaf377-fmd.bit")
6        .to_state()
7        .update(a)
8        .update(b)
9        .update(c)
10        .finalize()
11        .as_bytes()[0]
12        & 1
13}
14
15pub fn to_scalar(point: &[u8; 32], n: u8, bits: &[u8]) -> Fr {
16    // assert to avoid forcing callers to copy into another array
17    assert_eq!(bits.len(), 3);
18
19    let hash = blake2b_simd::Params::default()
20        .personal(b"decaf377-fmd.sca")
21        .to_state()
22        .update(point)
23        .update(&[n])
24        .update(bits)
25        .finalize();
26
27    Fr::from_le_bytes_mod_order(hash.as_bytes())
28}