diff --git a/crypto/transcript/src/lib.rs b/crypto/transcript/src/lib.rs index d5e4aa14..54299c94 100644 --- a/crypto/transcript/src/lib.rs +++ b/crypto/transcript/src/lib.rs @@ -35,30 +35,24 @@ impl DigestTranscriptMember { } #[derive(Clone, Debug)] -pub struct DigestTranscript(Vec, PhantomData); +pub struct DigestTranscript(D, PhantomData); -impl PartialEq for DigestTranscript { - fn eq(&self, other: &DigestTranscript) -> bool { - self.0 == other.0 - } -} - -impl DigestTranscript { +impl DigestTranscript { fn append(&mut self, kind: DigestTranscriptMember, value: &[u8]) { - self.0.push(kind.as_u8()); + self.0.update(&[kind.as_u8()]); // Assumes messages don't exceed 16 exabytes - self.0.extend(u64::try_from(value.len()).unwrap().to_le_bytes()); - self.0.extend(value); + self.0.update(u64::try_from(value.len()).unwrap().to_le_bytes()); + self.0.update(value); } pub fn new(name: &'static [u8]) -> Self { - let mut res = DigestTranscript(vec![], PhantomData); + let mut res = DigestTranscript(D::new(), PhantomData); res.append(DigestTranscriptMember::Name, name); res } } -impl Transcript for DigestTranscript { +impl Transcript for DigestTranscript { fn domain_separate(&mut self, label: &[u8]) { self.append(DigestTranscriptMember::Domain, label); } @@ -70,7 +64,7 @@ impl Transcript for DigestTranscript { fn challenge(&mut self, label: &'static [u8]) -> Vec { self.append(DigestTranscriptMember::Challenge, label); - D::new().chain_update(&self.0).finalize().to_vec() + self.0.clone().finalize().to_vec() } fn rng_seed(&mut self, label: &'static [u8]) -> [u8; 32] {