Skip to content

Commit

Permalink
Add Merlin, squeeze_bits does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
autquis committed Jan 29, 2024
1 parent adf245e commit c3d9388
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ark-serialize = { version = "^0.4.0", default-features = false, features = [ "de
blake2 = { version = "0.10", default-features = false }
sha2 = { version = "0.10", default-features = false }
digest = { version = "0.10", default-features = false }
merlin = { version = "3.0.0", default-features = false }

ark-r1cs-std = { version = "^0.4.0", optional = true, default-features = false }
ark-snark = { version = "^0.4.0", default-features = false }
Expand Down
31 changes: 31 additions & 0 deletions src/sponge/merlin/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::sponge::{Absorb, CryptographicSponge};
use merlin::Transcript;

impl CryptographicSponge for Transcript {
type Config = &'static [u8];

fn new(params: &Self::Config) -> Self {
Transcript::new(*params)
}

fn absorb(&mut self, input: &impl Absorb) {
self.append_message(b"", &input.to_sponge_bytes_as_vec());
}

fn squeeze_bytes(&mut self, num_bytes: usize) -> Vec<u8> {
let mut dest = Vec::with_capacity(num_bytes);
self.challenge_bytes(b"", &mut dest);
dest
}

fn squeeze_bits(&mut self, num_bits: usize) -> Vec<bool> {
let num_bytes = (num_bits + 7) / 8;
let mut tmp = Vec::with_capacity(num_bytes);
self.challenge_bytes(b"", &mut tmp);
let dest = tmp
.iter()
.flat_map(|byte| (0..8u32).rev().map(move |i| (byte >> i) & 1 == 1))
.collect::<Vec<_>>();
dest[..num_bits].to_vec()
}
}
5 changes: 5 additions & 0 deletions src/sponge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ pub use absorb::*;
/// [cos]: https://eprint.iacr.org/2019/1076
pub mod poseidon;

/// The sponge for Merlin
///
///
pub mod merlin;

#[cfg(test)]
mod test;

Expand Down

0 comments on commit c3d9388

Please sign in to comment.