-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of
CryptographicSponge
for Merlin (#136)
* Add Merlin, `squeeze_bits` does not work * Fix bug * Apply suggestions from code review * Rename the merlin directory * Fix `Cargo.toml` * Add link to Merlin page * Remove redundant imports, nightly check * Undo a mistake * Fix Merlin sponge * Fix nightly check errors --------- Co-authored-by: Marcin <marcin.gorny.94@protonmail.com> Co-authored-by: Cesar Descalzo <cesar.descalzo2@gmail.com>
- Loading branch information
1 parent
e51fc42
commit bd97ccc
Showing
5 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::sponge::{Absorb, CryptographicSponge}; | ||
#[cfg(not(feature = "std"))] | ||
use ark_std::vec::Vec; | ||
pub 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![0; 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![0; 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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters