diff --git a/Cargo.lock b/Cargo.lock index 9bb4b9d9..6dab0b7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "elliptic-curve" version = "0.5.0-pre" -source = "git+https://github.com/RustCrypto/traits#a65edce5d5ee2f5daec882d68fe00f860674f542" +source = "git+https://github.com/RustCrypto/traits#920522ae53f03483a27b24bc8e924db9e8aff29c" dependencies = [ "generic-array", "rand_core", diff --git a/ecdsa/src/hazmat.rs b/ecdsa/src/hazmat.rs index 5edb181b..8301f119 100644 --- a/ecdsa/src/hazmat.rs +++ b/ecdsa/src/hazmat.rs @@ -45,6 +45,42 @@ where ) -> Result, Error>; } +/// [`SignPrimitive`] for signature implementations that can provide public key +/// recovery implementation. +pub trait RecoverableSignPrimitive +where + C: Curve + Arithmetic, + SignatureSize: ArrayLength, +{ + /// Try to sign the prehashed message. + /// + /// Accepts the same arguments as [`SignPrimitive::try_sign_prehashed`] + /// but returns a boolean flag which indicates whether or not the + /// y-coordinate of the computed 𝐑 = 𝑘×𝑮 point is odd, which can be + /// incorporated into recoverable signatures. + fn try_sign_recoverable_prehashed + Invert>( + &self, + ephemeral_scalar: &K, + hashed_msg: &ScalarBytes, + ) -> Result<(Signature, bool), Error>; +} + +impl SignPrimitive for T +where + C: Curve + Arithmetic, + T: RecoverableSignPrimitive, + SignatureSize: ArrayLength, +{ + fn try_sign_prehashed + Invert>( + &self, + ephemeral_scalar: &K, + hashed_msg: &ScalarBytes, + ) -> Result, Error> { + let (sig, _) = self.try_sign_recoverable_prehashed(ephemeral_scalar, hashed_msg)?; + Ok(sig) + } +} + /// Verify the given prehashed message using ECDSA. /// /// This trait is intended to be implemented on type which can access