-
Notifications
You must be signed in to change notification settings - Fork 130
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
dsa: expose signing and verifying of prehashed hash value #558
Conversation
Would you mind changing the code to expose the prehashed signing/verifying functionality via the hazmat traits of the |
Sure, I'll have a look. Thanks for pointing out a direction. |
@aumetra can you confirm that there is no component of randomness in this logic? The I will follow up later: I've got some things to figure out, e.g. whether the trait needs the |
@aumetra for now you can just do the deterministic API. RFC6979 supports additional randomness, but that can be added as a followup. |
Yes, the logic of the function (as it currently is) is fully deterministic |
@cobratbq looks like one clippy nit for a needless borrow |
@aumetra it actually also supports using an RNG: signatures/dsa/src/signing_key.rs Lines 108 to 124 in a440df1
|
Oh yeah, I was only talking about the function |
@tarcieri @aumetra quick follow-up, I'd appreciate your feedback
Do you have an idea what to do with (3)? The type for |
@cobratbq The ECDSA crate uses a curve-specific digest when implementing https://github.com/RustCrypto/signatures/blob/3a13e77/ecdsa/src/sign.rs#L268 Failing that you could just use e.g. SHA-256, or some other SHA2-family digest which has test vectors in RFC6979. |
@tarcieri I've been looking into the ecdsa implementation. From what I can tell, I suspect that the It works for Is this something you would want to change/fix or should I work around it, like effectively (probably by accident) happened with |
The logic in
The DSA however doesn't really have a "recommended" hash digest. Most of the standards reference SHA-1 which is actually pretty awful because, you know. Also regarding your change where you added the assertion on the hash length and the size of parameter The full quote is as follows:
The quote can be found in FIPS 186-4, under section 5.1 "RSA Key Pair Generation" |
@cobratbq the current shape of the We previously did what I suspect you're suggesting: always use the Unless you have such specific requirements as well, you can instantiate RFC6979 with the secure cryptographic digest of your choice, which is why I recommended SHA-256 as a reasonable default. Again, it doesn't have to match what was used to hash the message, and really the only party who can discern what hash was used was the signer. The only time it really matters at all is if you are trying to match specific deterministic test vectors.
|
@aumetra: okay, you are right. Let me rephrase. Given the way DSA is defined, there is a open variable for the digest to be used. (Instead of a single prescribed digest, a set of possible values is defined.) So, this is effectively requires extending the trait, i.e. introducing a new variable component. For
@aumetra thanks for catching that, I see that in traversing the spec, I accidentally ended up with something RSA specific. That's my fuck-up. @tarcieri actually, it's the inverse: with my current understanding, I would define a edit @tarcieri comment regarding evolution of |
Again, See:
Even if we were to abandon that requirement, a
Adding a And again, there's already a similar trait with a That's why I suggested that if you really, really want to expose it as a user-configurable parameter, it needs to be on the type, not the trait. If you want a concrete example, |
@tarcieri just to check, I propose a edit if your suggestion is to hard-code |
@cobratbq aah, that's fine |
I'm glad this is clarified. I had wanted to align the solution direction, but discussions got a bit more complicated. To get back to my original questions/concerns. So,
|
If #520 is resolved, you can use the same approach as ECDSA, leveraging Alternatively, you could add a generic parameter to
If you really feel strongly about this, please open an issue on https://github.com/RustCrypto/traits/issues with your concrete proposal. If you're suggesting adding an additional trait, please note there's something of a "trait explosion" to handle all possible cases: Note that there are other things we'd potentially like to add, like domain separation, which would further compound this trait explosion. So I think the bar would be pretty high to add an additional trait, especially given |
I get the impression you have some reservations. I understand, especially given another issue is involved. My goal is to have prehash signing and verification exposed as part of the API. Given the complications as discussed above, what do you recommend? |
Use |
Expose the ability for the user to provide a prehashed hash-value for signing/verification. In rare cases, this is needed in other protocols. I have attempted to solve this with a custom Digest implementation, but eventually ran into (forced) finalization which affects the hash value.