Skip to content

Add API for computing RSA/ECDSA signatures from a pre-computed digest #253

Closed as not planned

Description

@sciyoshi

This is necessary to support client authentication without having to store all handshake messages in TLS 1.2 - see discussion in rustls/rustls#3.

Activity

  1. sciyoshi commented on Jul 18, 2016

    @sciyoshi
    Author

    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.

  2. briansmith commented on Aug 8, 2016

    @briansmith
    Owner

    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.

  3. samscott89 commented on Aug 11, 2016

    @samscott89
    Contributor

    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.

  4. self-assigned this
    on Sep 15, 2016
  5. briansmith commented on Nov 15, 2016

    @briansmith
    Owner

    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.

  6. removed their assignment
    on Dec 12, 2016
  7. acw commented on Aug 9, 2017

    @acw

    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:

    1. Expand ring::digest to support the NULL digest, and then pipe that through as RSA_PKCS1_2048_8192_NULL; or
    2. 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).
  8. briansmith commented on Aug 9, 2017

    @briansmith
    Owner

    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.

  9. fspmarshall commented on Nov 21, 2017

    @fspmarshall

    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.

  10. briansmith commented on Jun 15, 2018

    @briansmith
    Owner

    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.

  11. tarcieri commented on Jul 5, 2018

    @tarcieri
    Contributor

    This is something of an odd use case, but...

    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:

    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_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...

  12. dmitry-zakablukov commented on Apr 30, 2020

    @dmitry-zakablukov

    @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?

  13. briansmith commented on Apr 30, 2020

    @briansmith
    Owner

    @dmitry-zakablukov RSA encryption, using OAEP, is being tracked in [edited] #691.

  14. briansmith commented on Apr 30, 2020

    @briansmith
    Owner

    As for signing a precomputed digest, There are three cases:

    1. 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.

    2. 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.

    3. 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.

  15. dmitry-zakablukov commented on Apr 30, 2020

    @dmitry-zakablukov

    @dmitry-zakablukov RSA encryption, using OAEP, is being tracked in #692

    Did you mean #691 ?

  16. briansmith commented on Apr 30, 2020

    @briansmith
    Owner

    @dmitry-zakablukov RSA encryption, using OAEP, is being tracked in #692

    Did you mean #691 ?

    Yes! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions