mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Use HashMarker for Transcript and when generating scalars from digests
This commit is contained in:
@@ -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<D: Clone + Digest> SecureDigest for D where D::OutputSize: IsGreaterOrEqual<U256> {}
|
||||
/// 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<D: Digest + HashMarker> SecureDigest for D where D::OutputSize: IsGreaterOrEqual<U256> {}
|
||||
|
||||
/// A simple transcript format constructed around the specified hash algorithm.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DigestTranscript<D: SecureDigest>(D);
|
||||
pub struct DigestTranscript<D: Clone + SecureDigest>(D);
|
||||
|
||||
impl<D: SecureDigest> DigestTranscript<D> {
|
||||
impl<D: Clone + SecureDigest> DigestTranscript<D> {
|
||||
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<D: SecureDigest> DigestTranscript<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: SecureDigest> Transcript for DigestTranscript<D> {
|
||||
impl<D: Clone + SecureDigest> Transcript for DigestTranscript<D> {
|
||||
type Challenge = Output<D>;
|
||||
|
||||
fn new(name: &'static [u8]) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user