From ef11838cab16412e5fda821835ddb43f6956d4a3 Mon Sep 17 00:00:00 2001 From: moana Date: Fri, 1 Mar 2024 16:07:05 +0100 Subject: [PATCH] Remove AsRef again (doesn't compile for some mysterious reason) --- src/cipher.rs | 3 --- src/hash.rs | 27 ++++++++++++++------------- src/hash/gadget.rs | 14 +++++++------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/cipher.rs b/src/cipher.rs index f030f54..8703626 100644 --- a/src/cipher.rs +++ b/src/cipher.rs @@ -98,9 +98,6 @@ use bytecheck::CheckBytes; #[cfg(feature = "rkyv-impl")] use rkyv::{Archive, Deserialize, Serialize}; -#[cfg(feature = "zk")] -pub(crate) use zk::{decrypt, encrypt}; - const MESSAGE_CAPACITY: usize = 2; const CIPHER_SIZE: usize = MESSAGE_CAPACITY + 1; const CIPHER_BYTES_SIZE: usize = CIPHER_SIZE * BlsScalar::SIZE; diff --git a/src/hash.rs b/src/hash.rs index fb069a3..32b8d4e 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -49,16 +49,14 @@ impl Domain { } } -fn io_pattern, T>( +fn io_pattern( domain: Domain, - input: &[R], + input: &[&[BlsScalar]], output_len: usize, ) -> Result, Error> { let mut io_pattern = Vec::new(); // check total input length against domain - let input_len = input - .iter() - .fold(0, |acc, input| acc + input.as_ref().len()); + let input_len = input.iter().fold(0, |acc, input| acc + input.len()); match domain { Domain::Merkle2 if input_len != 2 || output_len != 1 => { return Err(Error::IOPatternViolation); @@ -69,7 +67,7 @@ fn io_pattern, T>( _ => {} } for input in input.iter() { - io_pattern.push(Call::Absorb(input.as_ref().len())); + io_pattern.push(Call::Absorb(input.len())); } io_pattern.push(Call::Squeeze(output_len)); @@ -81,13 +79,13 @@ fn io_pattern, T>( /// only call `squeeze` once at the finalization of the hash. /// The output length is set to 1 element per default, but this can be /// overridden with [`Hash::output_len`]. -pub struct Hash> { +pub struct Hash<'a> { domain: Domain, - input: Vec, + input: Vec<&'a [BlsScalar]>, output_len: usize, } -impl> Hash { +impl<'a> Hash<'a> { /// Create a new hash. pub fn new(domain: Domain) -> Self { Self { @@ -103,7 +101,7 @@ impl> Hash { } /// Update the hash input. - pub fn update(&mut self, input: R) { + pub fn update(&mut self, input: &'a [BlsScalar]) { self.input.push(input); } @@ -121,7 +119,7 @@ impl> Hash { Sponge::start(ScalarPermutation::new(), io_pattern, domain_sep)?; // absorb the input for input in self.input.iter() { - sponge.absorb(input.as_ref().len(), input)?; + sponge.absorb(input.len(), input)?; } // squeeze the output sponge.squeeze(self.output_len)?; @@ -154,7 +152,10 @@ impl> Hash { } /// Digest an input and calculate the hash immediately - pub fn digest(domain: Domain, input: R) -> Result, Error> { + pub fn digest( + domain: Domain, + input: &'a [BlsScalar], + ) -> Result, Error> { let mut hash = Self::new(domain); hash.update(input); hash.finalize() @@ -163,7 +164,7 @@ impl> Hash { /// Digest an input and calculate the hash as jubjub-scalar immediately pub fn digest_truncated( domain: Domain, - input: R, + input: &'a [BlsScalar], ) -> Result, Error> { let mut hash = Self::new(domain); hash.update(input); diff --git a/src/hash/gadget.rs b/src/hash/gadget.rs index f2c7b68..0c4164e 100644 --- a/src/hash/gadget.rs +++ b/src/hash/gadget.rs @@ -15,13 +15,13 @@ use crate::{Domain, Error}; use super::io_pattern; /// Hash struct. -pub struct HashGadget> { +pub struct HashGadget<'a> { domain: Domain, - input: Vec, + input: Vec<&'a [Witness]>, output_len: usize, } -impl> HashGadget { +impl<'a> HashGadget<'a> { /// Create a new hash. pub fn new(domain: Domain) -> Self { Self { @@ -37,7 +37,7 @@ impl> HashGadget { } /// Update the hash input. - pub fn update(&mut self, input: R) { + pub fn update(&mut self, input: &'a [Witness]) { self.input.push(input); } @@ -61,7 +61,7 @@ impl> HashGadget { )?; // absorb the input for input in self.input.iter() { - sponge.absorb(input.as_ref().len(), input)?; + sponge.absorb(input.len(), input)?; } // squeeze the output sponge.squeeze(self.output_len as usize)?; @@ -89,7 +89,7 @@ impl> HashGadget { pub fn digest( domain: Domain, composer: &mut Composer, - input: R, + input: &'a [Witness], ) -> Result, Error> { let mut hash = Self::new(domain); hash.update(input); @@ -100,7 +100,7 @@ impl> HashGadget { pub fn digest_truncated( domain: Domain, composer: &mut Composer, - input: R, + input: &'a [Witness], ) -> Result, Error> { let mut hash = Self::new(domain); hash.update(input);