diff --git a/ecdsa/Cargo.toml b/ecdsa/Cargo.toml index f9f7f3b1..3e1f2965 100644 --- a/ecdsa/Cargo.toml +++ b/ecdsa/Cargo.toml @@ -30,4 +30,5 @@ hazmat = [] std = ["elliptic-curve/std", "signature/std"] [package.metadata.docs.rs] +features = ["digest", "std"] rustdoc-args = ["--cfg", "docsrs"] diff --git a/ecdsa/src/hazmat.rs b/ecdsa/src/hazmat.rs index 73619c64..e165c1c8 100644 --- a/ecdsa/src/hazmat.rs +++ b/ecdsa/src/hazmat.rs @@ -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 @@ -66,3 +69,28 @@ where signature: &Signature, ) -> 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 PrehashSignature for Signature +where + ::Output: ArrayLength, +{ + type Digest = C::Digest; +} diff --git a/ecdsa/src/lib.rs b/ecdsa/src/lib.rs index ce177f7c..e890234c 100644 --- a/ecdsa/src/lib.rs +++ b/ecdsa/src/lib.rs @@ -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)