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
1 change: 1 addition & 0 deletions ecdsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ hazmat = []
std = ["elliptic-curve/std", "signature/std"]

[package.metadata.docs.rs]
features = ["digest", "std"]
rustdoc-args = ["--cfg", "docsrs"]
28 changes: 28 additions & 0 deletions ecdsa/src/hazmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use crate::{Signature, SignatureSize};
use elliptic_curve::{generic_array::ArrayLength, weierstrass::Curve, Error, ScalarBytes};

#[cfg(feature = "digest")]
use signature::{digest::Digest, PrehashSignature};

/// Try to sign the given prehashed message using ECDSA.
///
/// This trait is intended to be implemented on a type with access
Expand Down Expand Up @@ -66,3 +69,28 @@ where
signature: &Signature<C>,
) -> Result<(), Error>;
}

/// Bind a preferred [`Digest`] algorithm to an elliptic curve type.
///
/// Generally there is a preferred variety of the SHA-2 family used with ECDSA
/// for a particular elliptic curve.
///
/// This trait can be used to specify it, and with it receive a blanket impl of
/// [`PrehashSignature`], used by [`signature_derive`][1]) for the [`Signature`]
/// type for a particular elliptic curve.
///
/// [1]: https://github.com/RustCrypto/traits/tree/master/signature/derive
#[cfg(feature = "digest")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest")))]
pub trait DigestPrimitive: Curve {
/// Preferred digest to use when computing ECDSA signatures for this
/// elliptic curve. This should be a member of the SHA-2 family.
type Digest: Digest;
}

impl<C: DigestPrimitive> PrehashSignature for Signature<C>
where
<C::ScalarSize as core::ops::Add>::Output: ArrayLength<u8>,
{
type Digest = C::Digest;
}
1 change: 1 addition & 0 deletions ecdsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
pub mod asn1;

#[cfg(feature = "hazmat")]
#[cfg_attr(docsrs, doc(cfg(feature = "hazmat")))]
pub mod hazmat;

// Re-export the `elliptic-curve` crate (and select types)
Expand Down