You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add API for computing RSA/ECDSA signatures from a pre-computed digest #253
Note - Ed25519 signatures won't be able to implement this, because the algorithm requires computing a combined digest of the message with a prefix. That means you can't re-use the main VerificationAlgorithmImpl trait for this purpose.
It seems like this will be straightforward to do after @djc's change to use traits. We simply need to make a trait analogous to ring::signature::VerificationAlgorithm for prehashed verification, ring::signature::PrehashedVerificationAlgorithm, and a verify_prehashed function analogous to verify that takes a PrehashedVerificationAlgorithm. Then implement PrehashedVerificationAlgorithm for ECDSA and RSA, redoing the VerificationAlgorithm implementations to be based on the PrehashedVerificationAlgorithm implementations. And, just don't implement PrehashedVerificationAlgorithm for Ed25519.
This might change marginally due to the modifications to the signing/padding mechanism (in #262). However, the Encoding/Verification traits could also support encode_from_digest and verify_digest which would similarly skip the extra step of first hashing. The original encode and verify methods could then just hash and call encode_from_digest.
Probably best to wait until #262 lands before doing this. Not far off, hopefully.
This might change marginally due to the modifications to the signing/padding mechanism (in #262). However, the Encoding/Verification traits could also support encode_from_digest and verify_digest which would similarly skip the extra step of first hashing. The original encode and verify methods could then just hash and call encode_from_digest.
You're right; see #348. We actually don't need both the from_digest and non-from_digest variants though.
Unless/until a really important use case comes along, I don't think we should bother with this for a while. I'd like to see how far we can get without it, especially considering we want to help applications support Ed25519, and this doesn't work with Ed25519.
So I think I just ran into one use case: Tor. Tor uses a funny signing algorithm in which they do most of a SHA1/SHA256-based PKCS1 signature, except without the digest info prefix in the padding before the hash. In the other implementation I worked on, I ended up implementing this method by precomputing the SHA1/SHA256 hash, and then passing it into the RSA PKCS1 function directly with "no hash function". Which sounds like what the original reporter was looking for in this issue?
Digging around a bit in ring, it looks like a similar trick might work there, except that there's obviously no NULL hash function. I dug a little bit further and ran into a wall, in that the digest code seems very attached to SHA variants. There didn't seem an obvious way forward there, but perhaps I'm missing something?
Have you had any further thoughts about doing this? The major issue I'm seeing, at least from the verification side, is the strong connection between ring::rsa and ring::digest, combined with the strong connection between ring::digest and SHA variants. Which leads me to believe that this issue could be resolved without too much evil hackery if it were possible to:
Expand ring::digest to support the NULL digest, and then pipe that through as RSA_PKCS1_2048_8192_NULL; or
Open up the interface much more widely, and allow folks to create their own RSAParameters and PKCS1 variants using less stringent requirements (i.e., without having to go through Digest).
So I think I just ran into one use case: Tor. Tor uses a funny signing algorithm in which they do most of a SHA1/SHA256-based PKCS1 signature, except without the digest info prefix in the padding before the hash.
If we want to support that kind of RSA signature, then we would probably do so by offering RSA_TORWIERDFORMAT_2048_8192_SHA256, which would probably use a lot of the same code as RSA_PKCS1_2048_8192_SHA256.
Any progress on this? Beyond the usefulness of swapping digest algos, it would also be great to be able to do custom absorption for messages that spread across multiple buffers.
Any progress on this? Beyond the usefulness of swapping digest algos, it would also be great to be able to do custom absorption for messages that spread across multiple buffers.
I do think it would be useful to sign messages without requiring the message be provided all at once. However, that's not the same as signing a precomputed digest.
I am working on a new API for signing messages in ring. The ECDSA signing implementation is the start of it. My goal is to safely support piecewise signing of messages (e.g. in the style of ring::digest::Context and ring::digest::SigningContext) that works for all signature algorithms we support, including Ed25519.
It would be interesting to see use cases where such an API would be insufficient; i.e. where there is a need for signing a precomputed digest that can't be met by having a SigningContext-like API for feeding the message into the signature.
In the yubihsm crate I implement a software simulation of a YubiHSM ("mockhsm") which is useful for downstream crates which want to run end-to-end integration tests in CI but don't have access to a YubiHSM in that environment.
One of the commands provided by the YubiHSM which I recently implemented computes an ECDSA (ASN.1 DER) signature of a provided digest:
There are hacks I could potentially do to accommodate ring's current API, like have the sign_ecdsa_sha2 function send the original message to the mock HSM rather than prehashing it. That wouldn't be the end of the world but it would wind up with slightly different semantics versus prehashing, since the APDU-ish messages the mock HSM uses have a relatively short maximum length, so it wouldn't be possible to sign longer messages with the mock HSM which would ordinarily work when prehashed in software.
I guess I could start with that approach and see how problematic it actually is...
@briansmith , our company uses pre-computed hash signing with RSA as an equivalent of RSA encryption, because it seems to be the only simple way to RSA-encrypt a message. This approach can be achieved with CryptoAPI on Windows and with Security API on macOS.
Can you please recommend a rust package (as safe and fast as ring package) to RSA-encrypt a message?
As for signing a precomputed digest, There are three cases:
You have a digest of some message. You want to sign it. You can already pass that digest as the message into the existing ring signing API. This would have the effect of hashing the message, then hashing the resulting digest, and then computing the public/private key operation. Not ideal, but it works today.
You want to compute the digest separately, perhaps in multiple parts, using ring::digest and then sign the digest in a separate step. I would be happy to add this kind of API.
You want to compute the digest separately using different software, or perhaps you want to sign a digest that was computed by somebody else. In general I'm not eager to support this kind of use case because it is very useful to require that the holder of the private key actually see the contents of the message it is signing. Maybe at some point we'd have a compelling reason to add an API that supports this, but I'd prefer to avoid it if we can.
Activity
sciyoshi commentedon Jul 18, 2016
Note - Ed25519 signatures won't be able to implement this, because the algorithm requires computing a combined digest of the message with a prefix. That means you can't re-use the main
VerificationAlgorithmImpltrait for this purpose.briansmith commentedon Aug 8, 2016
It seems like this will be straightforward to do after @djc's change to use traits. We simply need to make a trait analogous to
ring::signature::VerificationAlgorithmfor prehashed verification,ring::signature::PrehashedVerificationAlgorithm, and averify_prehashedfunction analogous toverifythat takes aPrehashedVerificationAlgorithm. Then implementPrehashedVerificationAlgorithmfor ECDSA and RSA, redoing theVerificationAlgorithmimplementations to be based on thePrehashedVerificationAlgorithmimplementations. And, just don't implementPrehashedVerificationAlgorithmfor Ed25519.samscott89 commentedon Aug 11, 2016
This might change marginally due to the modifications to the signing/padding mechanism (in #262). However, the Encoding/Verification traits could also support
encode_from_digestandverify_digestwhich would similarly skip the extra step of first hashing. The originalencodeandverifymethods could then just hash and callencode_from_digest.Probably best to wait until #262 lands before doing this. Not far off, hopefully.
briansmith commentedon Nov 15, 2016
You're right; see #348. We actually don't need both the
from_digestand non-from_digestvariants though.Unless/until a really important use case comes along, I don't think we should bother with this for a while. I'd like to see how far we can get without it, especially considering we want to help applications support Ed25519, and this doesn't work with Ed25519.
acw commentedon Aug 9, 2017
So I think I just ran into one use case: Tor. Tor uses a funny signing algorithm in which they do most of a SHA1/SHA256-based PKCS1 signature, except without the digest info prefix in the padding before the hash. In the other implementation I worked on, I ended up implementing this method by precomputing the SHA1/SHA256 hash, and then passing it into the RSA PKCS1 function directly with "no hash function". Which sounds like what the original reporter was looking for in this issue?
Digging around a bit in
ring, it looks like a similar trick might work there, except that there's obviously no NULL hash function. I dug a little bit further and ran into a wall, in that the digest code seems very attached to SHA variants. There didn't seem an obvious way forward there, but perhaps I'm missing something?Have you had any further thoughts about doing this? The major issue I'm seeing, at least from the verification side, is the strong connection between ring::rsa and ring::digest, combined with the strong connection between ring::digest and SHA variants. Which leads me to believe that this issue could be resolved without too much evil hackery if it were possible to:
RSAParametersandPKCS1variants using less stringent requirements (i.e., without having to go throughDigest).briansmith commentedon Aug 9, 2017
If we want to support that kind of RSA signature, then we would probably do so by offering
RSA_TORWIERDFORMAT_2048_8192_SHA256, which would probably use a lot of the same code asRSA_PKCS1_2048_8192_SHA256.fspmarshall commentedon Nov 21, 2017
Any progress on this? Beyond the usefulness of swapping digest algos, it would also be great to be able to do custom absorption for messages that spread across multiple buffers.
briansmith commentedon Jun 15, 2018
I do think it would be useful to sign messages without requiring the message be provided all at once. However, that's not the same as signing a precomputed digest.
I am working on a new API for signing messages in ring. The ECDSA signing implementation is the start of it. My goal is to safely support piecewise signing of messages (e.g. in the style of
ring::digest::Contextandring::digest::SigningContext) that works for all signature algorithms we support, including Ed25519.It would be interesting to see use cases where such an API would be insufficient; i.e. where there is a need for signing a precomputed digest that can't be met by having a
SigningContext-like API for feeding the message into the signature.tarcieri commentedon Jul 5, 2018
This is something of an odd use case, but...
In the
yubihsmcrate I implement a software simulation of a YubiHSM ("mockhsm") which is useful for downstream crates which want to run end-to-end integration tests in CI but don't have access to a YubiHSM in that environment.One of the commands provided by the YubiHSM which I recently implemented computes an ECDSA (ASN.1 DER) signature of a provided digest:
https://developers.yubico.com/YubiHSM2/Commands/Sign_Data_Ecdsa.html
In the client library I expose a function which precomputes the digest for you then invokes the "sign a digest" method in the YubiHSM:
https://github.com/tendermint/yubihsm-rs/blob/master/src/commands.rs#L120
There are hacks I could potentially do to accommodate ring's current API, like have the
sign_ecdsa_sha2function send the original message to the mock HSM rather than prehashing it. That wouldn't be the end of the world but it would wind up with slightly different semantics versus prehashing, since the APDU-ish messages the mock HSM uses have a relatively short maximum length, so it wouldn't be possible to sign longer messages with the mock HSM which would ordinarily work when prehashed in software.I guess I could start with that approach and see how problematic it actually is...
dmitry-zakablukov commentedon Apr 30, 2020
@briansmith , our company uses pre-computed hash signing with RSA as an equivalent of RSA encryption, because it seems to be the only simple way to RSA-encrypt a message. This approach can be achieved with CryptoAPI on Windows and with Security API on macOS.
Can you please recommend a rust package (as safe and fast as ring package) to RSA-encrypt a message?
briansmith commentedon Apr 30, 2020
@dmitry-zakablukov RSA encryption, using OAEP, is being tracked in [edited] #691.
briansmith commentedon Apr 30, 2020
As for signing a precomputed digest, There are three cases:
You have a digest of some message. You want to sign it. You can already pass that digest as the message into the existing ring signing API. This would have the effect of hashing the message, then hashing the resulting digest, and then computing the public/private key operation. Not ideal, but it works today.
You want to compute the digest separately, perhaps in multiple parts, using
ring::digestand then sign the digest in a separate step. I would be happy to add this kind of API.You want to compute the digest separately using different software, or perhaps you want to sign a digest that was computed by somebody else. In general I'm not eager to support this kind of use case because it is very useful to require that the holder of the private key actually see the contents of the message it is signing. Maybe at some point we'd have a compelling reason to add an API that supports this, but I'd prefer to avoid it if we can.
dmitry-zakablukov commentedon Apr 30, 2020
Did you mean #691 ?
briansmith commentedon Apr 30, 2020
Yes! Thanks!