From 8d9315b797a2e201388dbcd1694709581760be89 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Thu, 29 Sep 2022 05:33:46 -0400 Subject: [PATCH] Use HashMarker for Transcript and when generating scalars from digests --- crypto/dalek-ff-group/src/lib.rs | 4 ++-- crypto/dleq/src/cross_group/mod.rs | 4 ++-- crypto/transcript/src/lib.rs | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crypto/dalek-ff-group/src/lib.rs b/crypto/dalek-ff-group/src/lib.rs index 34a77efe..249c7577 100644 --- a/crypto/dalek-ff-group/src/lib.rs +++ b/crypto/dalek-ff-group/src/lib.rs @@ -10,7 +10,7 @@ use zeroize::Zeroize; use subtle::{ConstantTimeEq, ConditionallySelectable}; use rand_core::RngCore; -use digest::{consts::U64, Digest}; +use digest::{consts::U64, Digest, HashMarker}; use subtle::{Choice, CtOption}; @@ -182,7 +182,7 @@ impl Scalar { } /// Derive a Scalar without bias from a digest via wide reduction. - pub fn from_hash>(hash: D) -> Scalar { + pub fn from_hash + HashMarker>(hash: D) -> Scalar { let mut output = [0u8; 64]; output.copy_from_slice(&hash.finalize()); let res = Scalar(DScalar::from_bytes_mod_order_wide(&output)); diff --git a/crypto/dleq/src/cross_group/mod.rs b/crypto/dleq/src/cross_group/mod.rs index e1a0c6e2..57444450 100644 --- a/crypto/dleq/src/cross_group/mod.rs +++ b/crypto/dleq/src/cross_group/mod.rs @@ -4,7 +4,7 @@ use rand_core::{RngCore, CryptoRng}; use zeroize::Zeroize; -use digest::Digest; +use digest::{Digest, HashMarker}; use transcript::Transcript; @@ -280,8 +280,8 @@ where /// to safely and securely generate a Scalar, without risk of failure, nor bias. /// It also ensures a lack of determinable relation between keys, guaranteeing security in the /// currently expected use case for this, atomic swaps, where each swap leaks the key. Knowing - pub fn prove( /// the relationship between keys would allow breaking all swaps after just one. + pub fn prove( rng: &mut R, transcript: &mut T, generators: (Generators, Generators), diff --git a/crypto/transcript/src/lib.rs b/crypto/transcript/src/lib.rs index b429649c..72324171 100644 --- a/crypto/transcript/src/lib.rs +++ b/crypto/transcript/src/lib.rs @@ -6,7 +6,7 @@ mod merlin; #[cfg(feature = "merlin")] pub use crate::merlin::MerlinTranscript; -use digest::{typenum::type_operators::IsGreaterOrEqual, consts::U256, Digest, Output}; +use digest::{typenum::type_operators::IsGreaterOrEqual, consts::U256, Digest, Output, HashMarker}; pub trait Transcript { type Challenge: Clone + Send + Sync + AsRef<[u8]>; @@ -50,16 +50,16 @@ impl DigestTranscriptMember { } } -pub trait SecureDigest: Clone + Digest {} -impl SecureDigest for D where D::OutputSize: IsGreaterOrEqual {} /// A trait defining cryptographic Digests with at least a 256-byte output size, assuming at least /// a 128-bit level of security accordingly. +pub trait SecureDigest: Digest + HashMarker {} +impl SecureDigest for D where D::OutputSize: IsGreaterOrEqual {} /// A simple transcript format constructed around the specified hash algorithm. #[derive(Clone, Debug)] -pub struct DigestTranscript(D); +pub struct DigestTranscript(D); -impl DigestTranscript { +impl DigestTranscript { fn append(&mut self, kind: DigestTranscriptMember, value: &[u8]) { self.0.update([kind.as_u8()]); // Assumes messages don't exceed 16 exabytes @@ -68,7 +68,7 @@ impl DigestTranscript { } } -impl Transcript for DigestTranscript { +impl Transcript for DigestTranscript { type Challenge = Output; fn new(name: &'static [u8]) -> Self {