Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dsa): implement `SigningKey::sign_prehashed_rfc6979 #798

Merged
Merged
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
13 changes: 13 additions & 0 deletions dsa/src/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ impl SigningKey {
&self.x
}

/// Try to sign the given message digest deterministically with a prehashed digest.
/// The parameter `D` must match the hash function used to sign the digest.
///
/// [RFC6979]: https://datatracker.ietf.org/doc/html/rfc6979
pub fn sign_prehashed_rfc6979<D>(&self, prehash: &[u8]) -> Result<Signature, signature::Error>
where
D: Digest + BlockSizeUser + FixedOutputReset,
{
let k_kinv = crate::generate::secret_number_rfc6979::<D>(self, prehash);
self.sign_prehashed(k_kinv, prehash)
}

/// Sign some pre-hashed data
fn sign_prehashed(
&self,
Expand Down Expand Up @@ -105,6 +117,7 @@ impl Signer<Signature> for SigningKey {
}

impl PrehashSigner<Signature> for SigningKey {
/// Warning: This uses `sha2::Sha256` as the hash function for the digest. If you need to use a different one, use [`SigningKey::sign_prehashed_rfc6979`].
fn sign_prehash(&self, prehash: &[u8]) -> Result<Signature, signature::Error> {
let k_kinv = crate::generate::secret_number_rfc6979::<sha2::Sha256>(self, prehash);
self.sign_prehashed(k_kinv, prehash)
Expand Down