Skip to content

Add sign_digest to EcdsaKeyPair to allow signing of pre-digested messages. #915

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IanLuites
Copy link

I need to sign a relatively large message and was using digest::Context to piece wise stream and update the digest.

I did however find out that sign does not accept a digest, but only an undigested message.

This PR would add a sign_digest sibling, which verifies the digest is generated with the correct (matching) algorithm, and then signs it.

@IanLuites IanLuites changed the title Add sign_digest to EcdsaKeyPair to allow signing of pre-digests messages. Add sign_digest to EcdsaKeyPair to allow signing of pre-digested messages. Nov 13, 2019
Copy link
Owner

@briansmith briansmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. I'll get this merged right away if you make the changes I requested.

digest: digest::Digest,
) -> Result<signature::Signature, error::Unspecified> {
// Step 4 (out of order, already performed by caller).
if digest.algorithm() == self.alg.digest_alg {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the early return style: if ... != ... { return Err(...); }

@@ -435,6 +454,44 @@ mod tests {
);
}

#[test]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests of the public API should be done in tests/ecdsa_tests.rs.

I suggest that you add a constructor pub(crate) try_from_test_vector to ring::digest::Digest that accepts a digest algorithm and a precomputed value. Then you can rewrite the existing tests to use your new function instead of calling sign_ directly as they currently do.

/// generated by `rng`.
///
/// The `digest` algorithm must match that of the signing algorithm.
pub fn sign_digest(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please name this sign_digest_less_safe.

Please add a note like the following to the documentation: "In general, it is not safe to sign an arbitrary digest. Ensure that you only sign digests that you have computed yourself, or that you otherwise know are safe to sign. It could be a bad mistake to sign an attacker-controlled digest."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants