Update RSA signature traits implementations#179
Conversation
Change the SigningKey and VerifiyingKey implementations accept raw message rather than pre-hashed message. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
|
RFC:
|
Shouldn't
Looks like there is |
No, there are minor differences there, so
This looks like what I was looking for. Let's look it using it (and implementing it in various digest crates) would be fine with @tarcieri . |
It's not possible. The main difference is that It's an architecture decision: you should decide whether you rely on dynamic dispatch (i.e. |
|
@tarcieri @dignifiedquire your opinion/comments? |
src/lib.rs
Outdated
| //! let private_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key"); | ||
| //! let signing_key = SigningKey::new_with_hash(private_key, Hash::SHA2_256); | ||
| //! let verifying_key: VerifyingKey = (&signing_key).into(); | ||
| //! let signing_key = SigningKey::<Sha256>::new_with_hash(private_key, Hash::SHA2_256); |
There was a problem hiding this comment.
SigningKey::<Sha256>::new_with_hash(private_key, Hash::SHA2_256);...still repeats Sha256 and Hash::SHA2_256.
There was a problem hiding this comment.
This is a bullet 3 in the RFC in the first comment. @sandhose suggested implementing const_oid::AssociatedOID for the Digest implementations instead of having a separate Hash class. Is that ok with you?
Change the SigningKey and VerifiyingKey implementations accept raw message rather than pre-hashed message. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Implement the experimental (preview) DigestSigner and DigestVerifier traits for the PKCS1v15 structs. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Implement the experimental (preview) RandomizedDigestSigner and DigestVerifier traits for the PSS structs. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
|
@lumag using a trait to provide the linkage between a generic Will If you use |
|
@tarcieri no, the OIDs are generic enough. Consider e.g. Hash::SHA2_256 => &[
0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02,
0x01, 0x05, 0x00, 0x04, 0x20,
],This translates to: |
|
Ok, that would work, but you (or someone else) will need to add the impls upstream to |
|
I'll do that, I'll need to test it anyway. |
|
@tarcieri @sandhose my bad. The |
|
@lumag maybe for now you can add a trait with an associated constant of the existing Using OIDs seems interesting but yes that's a complication. Semi-related issue: RustCrypto/traits#1069. If we encapsulated each hash algorithm in a newtype, it would solve this particular problem. |
|
This will add dependencies from the rsa crate on the sha1/sha2/sha3 crates. Is it fine for now? |
|
@lumag maybe optional dependencies with |
|
@tarcieri done |
There is an information duplication when the keys are expected to generate signatures over the ASN.1-prefixed data: SigningKey::<Sha256>::new_with_hash(private_key, Hash::SHA2_256); Remove this duplication by adding the AssociatedHash trait and implementing it for sha1/sha2/sha3 types. Note, this trait should morph into DynAssociatedOid trait and be implemented directly for the corresponding digest implementations. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
| /* FIXME: This trait should be refactored into per-digest implementations returning OID */ | ||
| pub trait AssociatedHash { | ||
| const HASH: Hash; | ||
| } |
There was a problem hiding this comment.
This trait could probably use a doc comment, even if the intent is to remove/replace it
|
Going to go ahead and merge this as it's hopefully uncontroversial additive changes to the new signature features. @lumag seems we have a path forward on replacing |
|
@tarcieri thanks! |
- Change the `SigningKey` and `VerifiyingKey` implementations accept raw message rather than pre-hashed message. - Implement the experimental (preview) `DigestSigner` and `DigestVerifier` traits for the PKCS1v15 structs. - Implement the experimental (preview) `RandomizedDigestSigner` and `DigestVerifier` traits for the PSS structs. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signer/Verifierimplementations to accept raw messages rather than pre-hashed dataDigestSigner/VerifiertraitsDynDigestbounds for the RSASSA-PSS implmentationpkcs1v15::SigningKey<D>::new_with_hash, which duplicates information passed in<D>Use passeddigestobject for PSS calculations rather than newly createdDigest?