Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ecdsa/src/der.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ where
}
}

impl<C> core::hash::Hash for Signature<C>
where
C: EcdsaCurve,
MaxSize<C>: ArraySize,
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
{
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.as_bytes().hash(state);
}
}

impl<C> AsRef<[u8]> for Signature<C>
where
C: EcdsaCurve,
Expand Down
22 changes: 22 additions & 0 deletions ecdsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,16 @@ where
}
}

impl<C> core::hash::Hash for Signature<C>
where
C: EcdsaCurve,
SignatureSize<C>: ArraySize,
{
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.to_bytes().hash(state);
}
}

impl<C> fmt::LowerHex for Signature<C>
where
C: EcdsaCurve,
Expand Down Expand Up @@ -667,6 +677,18 @@ where
{
}

#[cfg(feature = "digest")]
impl<C> core::hash::Hash for SignatureWithOid<C>
where
C: EcdsaCurve,
SignatureSize<C>: ArraySize,
{
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.signature.hash(state);
self.oid.hash(state);
}
}

#[cfg(feature = "digest")]
impl<C> From<SignatureWithOid<C>> for Signature<C>
where
Expand Down
2 changes: 1 addition & 1 deletion ed25519/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ pub type SignatureBytes = [u8; Signature::BYTE_SIZE];
///
/// Signature verification libraries are expected to reject invalid field
/// elements at the time a signature is verified.
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Copy, Clone, Eq, Hash, PartialEq)]
#[cfg_attr(
feature = "zerocopy",
derive(FromBytes, IntoBytes, Immutable, KnownLayout, Unaligned)
Expand Down
2 changes: 1 addition & 1 deletion ed25519/src/pkcs8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl str::FromStr for KeypairBytes {
///
/// Note that this type operates on raw bytes and performs no validation that
/// public keys represent valid compressed Ed25519 y-coordinates.
#[derive(Clone, Copy, Eq, PartialEq)]
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
#[cfg_attr(
feature = "zerocopy",
derive(IntoBytes, FromBytes, Unaligned, KnownLayout, Immutable,)
Expand Down
2 changes: 1 addition & 1 deletion ed448/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub type SignatureBytes = [u8; Signature::BYTE_SIZE];
///
/// Signature verification libraries are expected to reject invalid field
/// elements at the time a signature is verified.
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Copy, Clone, Eq, Hash, PartialEq)]
#[repr(C)]
pub struct Signature {
R: ComponentBytes,
Expand Down
2 changes: 1 addition & 1 deletion ed448/src/pkcs8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl fmt::Debug for KeypairBytes {
///
/// Note that this type operates on raw bytes and performs no validation that
/// public keys represent valid compressed Ed448 y-coordinates.
#[derive(Clone, Copy, Eq, PartialEq)]
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct PublicKeyBytes(pub [u8; Self::BYTE_SIZE]);

impl PublicKeyBytes {
Expand Down
12 changes: 12 additions & 0 deletions ml-dsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ impl<P: MlDsaParams> signature::SignatureEncoding for Signature<P> {
type Repr = EncodedSignature<P>;
}

impl<P: MlDsaParams> core::hash::Hash for Signature<P> {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.encode().hash(state);
}
}

struct MuBuilder(H);

impl MuBuilder {
Expand Down Expand Up @@ -834,6 +840,12 @@ impl<P: MlDsaParams> VerifyingKey<P> {
}
}

impl<P: MlDsaParams> core::hash::Hash for VerifyingKey<P> {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.encode().hash(state);
}
}

impl<P: MlDsaParams> signature::Verifier<Signature<P>> for VerifyingKey<P> {
fn verify(&self, msg: &[u8], signature: &Signature<P>) -> Result<(), Error> {
self.multipart_verify(&[msg], signature)
Expand Down
6 changes: 6 additions & 0 deletions slh-dsa/src/signature_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ impl<P: ParameterSet> Signature<P> {
}
}

impl<P: ParameterSet> core::hash::Hash for Signature<P> {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.to_bytes().hash(state);
}
}

impl<P: ParameterSet> TryFrom<&[u8]> for Signature<P> {
type Error = Error;

Expand Down
6 changes: 6 additions & 0 deletions slh-dsa/src/verifying_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ impl<P: ParameterSet + VerifyingKeyLen> VerifyingKey<P> {
}
}

impl<P: ParameterSet> core::hash::Hash for VerifyingKey<P> {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.to_bytes().hash(state);
}
}

impl<P: ParameterSet> Clone for VerifyingKey<P> {
fn clone(&self) -> Self {
VerifyingKey {
Expand Down