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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions ecdsa/src/hazmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,42 @@ where
) -> Result<Signature<C>, Error>;
}

/// [`SignPrimitive`] for signature implementations that can provide public key
/// recovery implementation.
pub trait RecoverableSignPrimitive<C>
where
C: Curve + Arithmetic,
SignatureSize<C>: ArrayLength<u8>,
{
/// 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<K: Borrow<C::Scalar> + Invert<Output = C::Scalar>>(
&self,
ephemeral_scalar: &K,
hashed_msg: &ScalarBytes<C>,
) -> Result<(Signature<C>, bool), Error>;
}

impl<C, T> SignPrimitive<C> for T
where
C: Curve + Arithmetic,
T: RecoverableSignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn try_sign_prehashed<K: Borrow<C::Scalar> + Invert<Output = C::Scalar>>(
&self,
ephemeral_scalar: &K,
hashed_msg: &ScalarBytes<C>,
) -> Result<Signature<C>, 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
Expand Down