ark-r1cs-std/crypto-primitives/src/commitment/blake2s/mod.rs
crypto-primitives/src/commitment/blake2s/mod.rsRaw
1use super::CommitmentScheme;
2use blake2::Blake2s as b2s;
3use digest::Digest;
4use crate::Error;
5use rand::Rng;
6
7pub struct Blake2sCommitment;
8
9impl CommitmentScheme for Blake2sCommitment {
10 type Parameters = ();
11 type Randomness = [u8; 32];
12 type Output = [u8; 32];
13
14 fn setup<R: Rng>(_: &mut R) -> Result<Self::Parameters, Error> {
15 Ok(())
16 }
17
18 fn commit(
19 _: &Self::Parameters,
20 input: &[u8],
21 randomness: &Self::Randomness,
22 ) -> Result<Self::Output, Error> {
23 let mut h = b2s::new();
24 h.input(input);
25 h.input(randomness.as_ref());
26 let mut result = [0u8; 32];
27 result.copy_from_slice(&h.result());
28 Ok(result)
29 }
30}