Skip to content

Commit

Permalink
feat(dsa): implement `SigningKey::sign_prehashed_rfc6979 (#798)
Browse files Browse the repository at this point in the history
Allows to use other digest algorithms.
  • Loading branch information
dignifiedquire authored and tarcieri committed Jan 28, 2024
1 parent 4654dc5 commit 24180bb
Showing 1 changed file with 13 additions and 0 deletions.
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

0 comments on commit 24180bb

Please sign in to comment.