From 963d9eab10b8d5e93f13975f48dc3d9d04c4e6d0 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Fri, 24 Jun 2022 18:49:04 -0400 Subject: [PATCH] Have DigestTranscript require a 32-byte hash Needed to generate RNG seeds without panicking. Mandates at least a 128-bit security level. --- crypto/transcript/src/lib.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crypto/transcript/src/lib.rs b/crypto/transcript/src/lib.rs index 54299c94..1ea4a7a8 100644 --- a/crypto/transcript/src/lib.rs +++ b/crypto/transcript/src/lib.rs @@ -1,11 +1,11 @@ -use core::{marker::PhantomData, fmt::Debug}; +use core::fmt::Debug; #[cfg(features = "merlin")] mod merlin; #[cfg(features = "merlin")] pub use merlin::MerlinTranscript; -use digest::Digest; +use digest::{typenum::type_operators::IsGreaterOrEqual, consts::U256, Digest}; pub trait Transcript { fn domain_separate(&mut self, label: &'static [u8]); @@ -35,9 +35,9 @@ impl DigestTranscriptMember { } #[derive(Clone, Debug)] -pub struct DigestTranscript(D, PhantomData); +pub struct DigestTranscript(D) where D::OutputSize: IsGreaterOrEqual; -impl DigestTranscript { +impl DigestTranscript where D::OutputSize: IsGreaterOrEqual { fn append(&mut self, kind: DigestTranscriptMember, value: &[u8]) { self.0.update(&[kind.as_u8()]); // Assumes messages don't exceed 16 exabytes @@ -46,13 +46,14 @@ impl DigestTranscript { } pub fn new(name: &'static [u8]) -> Self { - let mut res = DigestTranscript(D::new(), PhantomData); + let mut res = DigestTranscript(D::new()); res.append(DigestTranscriptMember::Name, name); res } } -impl Transcript for DigestTranscript { +impl Transcript for DigestTranscript + where D::OutputSize: IsGreaterOrEqual { fn domain_separate(&mut self, label: &[u8]) { self.append(DigestTranscriptMember::Domain, label); }