Repository navigation
Description
This is harder than EdDSA because there's no code to do the actual ECDSA signing anymore; the ECDSA_sign function in crypto/ecdsa/ecdsa.c was removed to help with the migration to the new Rust ECC code. So, a new implementation of ECDSA signing in Rust is necessary.
For all platforms it is OK (preferable, even) to use crypto::ec::PrivateKey::generate for the key generation (i.e. base point multiplication). So, that part is already done.
I have some code sitting around to do the constant-time modular inversions (mod q) and (mod n). I will try to integrate it...soonish.
For 64-bit platforms, we can use crypto/ec/p256-64.c and crypto/ec/p256-x86_64.c for the variable point multiplication (the multiplication done during the signing operation). However, we don't have any usable code for 32-bit platforms yet (at least, not checked in).
For 32-bit ARM, x86, and AAarch64, I will eventually import in the ecp_nistz256 field operations from OpenSSL. Actually, I'm planning to do this real soon. However, I don't think the ecp_nistz256 group operations are good to use for any platform except x86-64 (even then...). We might try, instead, adapting the p256-64.c variable point multiplication to work using the ecp_nistz256 field operations (which would require adapting it to work on Montgomery-encoded field elements).
Similarly, we need to do make new nonce generation, as the old C code that Adam Langley wrote was removed. It may be worth copying how golang is doing it. Regardless, it would be nice to do as much of this as possible in Rust.
NIST has some test vectors for ECDSA signing, which are the absolute minimum level of testing necessary before the API can be exposed.
There is also no code for serializing private keys or deserializing them, which is pretty essential to most users of ECDSA signing. This should probably be split off into its own task as it is a fair amount of work on its own.
See also any general notes about signing APIs in #205.
Activity
[-]Add ECDSA signing support[/-][+]Add ECDSA P-256 signing support[/+]briansmith commentedon Jun 3, 2016
ring::ec::PrivateKey)briansmith commentedon Jul 2, 2016
See https://go-review.googlesource.com/#/c/3340/ and the papers it cites.
See http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.35.1538.
briansmith commentedon Jul 3, 2016
Status update: All the checked-off stuff above is now in the main ring repo.
briansmith commentedon Jul 24, 2016
Status update: More checked-off stuff is now in the ring repo. Unassigning myself in case somebody else wants to take this on before I get to it.
Keats commentedon Jan 26, 2017
Is it still planned? It was asked for jsonwebtoken
I'm entirely unqualified to pick this up though :(
briansmith commentedon Jan 30, 2017
I doubt that is true!
Yes, I plan to do land it shortly, after I take care of the PR backlog.
16 remaining items
briansmith commentedon Oct 27, 2018
HMAC and digital signatures shouldn't have the same API anyway. The fact that the syntax is the same for both in JOSE is widely seen as one of its biggest design flaws.
manifest commentedon Oct 27, 2018
I still don't understand how the problem that I described might be solved. @briansmith could you please elaborate on how you see using ring to verify a signature in the untrusted environment?
manifest commentedon Nov 7, 2018
@briansmith Sorry to bother you, I'm just trying to find a solution for our problem.
It's what we need to solve the problem described above and start using ring library, or maybe you could suggest a different approach.
briansmith commentedon Nov 7, 2018
I'm getting the impression we might be talking past each other since we seem to have some misunderstandings.
The ECDSA verification API already takes
&[u8]for the public key. (If you only have the public key then you can only verify signatures, not generate signatures.)Only the ECDSA signing API requires a KeyPair object as input.
So my suggestion is to change the JWT crate to require a
KeyPairobject for signing (only). That would be a great improvement to the JWT crate. (Taking the private key as a&[u8]means that the user of the crate would have to keep the private key bytes easily-accessible which is bad.)In the future we'll have a type
signature::PublicKey(&[u8])which will make this a little more symmetric. However, no changes are needed to ring to provide the functionality you need today.manifest commentedon Nov 8, 2018
How can
KeyPairand&[u8](that will be replaced byPublicKeyin the future) be generated, in order to be used in signing and verification APIs? It's impossible without external tools at the moment, am I right?briansmith commentedon Nov 8, 2018
ring::signature;;ECDSAKeyPair::generate_pkcs8will generate a new ECDSA private key as a serialized PKCS#8 document.ring::signature::key_pair_from_pkcs8will create aKeyPairfrom the serialized document. (I understand that these APIs should be more symmetric; it's on the TODO istIncidentally, it turns out I already implemented the thing that was originally being asked for:
ring::signature::ECDSAKeyPair::from_private_key_and_public_keywill construct aECDSAKeyPairfrom the public key bytes and the private key bytes directly. IIRC, I actually added that API to support deserialization of JWKs.manifest commentedon Nov 20, 2018
@briansmith I'm following the steps you described above. I've generated
KeyPair, then I used it to sign a message. How can I generate a public key fromKeyPairin order to pass it to another application that will use it to verify the signed message?There is
public_key_bytes()forEd25519KeyPairbut nothing forECDSAKeyPair.Example
briansmith commentedon Dec 22, 2018
@Keats @manifest Please try ring 0.14.0-alpha2. In particular, look at
ring::signature::KeyPair::public_key(). I've temporarily removed the "generic" API that was was working on and I've renamed some types (RSA*->Rsa*,ECDSA*->Ecdsa*) and made some other minor changes which will (I hope) eventually make everything easier to use.briansmith commentedon Dec 22, 2018
I'm closing this because for the most part it was done. There are some details that need to be taken care of but it doesn't make sense to leave this issue open any more. If you run into troubles, please file a new issue.
manifest commentedon Dec 22, 2018
Thanks. Everything looks good. The only problem that it's still impossible to retrieve a public key because public_key function is private. I've opened an issue.
briansmith commentedon Dec 22, 2018
Thanks for the feedback. I replied in the issue you filed. Let's continue the discussion there.
moeziniaf commentedon Jun 7, 2020
How do you use verify? I can't figure out how to in version 0.16.14?
I tried rust::signature::verify and rust::signature::EcdsaKeyPair::verify..
briansmith commentedon Jun 8, 2020
@moeziniaf Doesn't the example for Ed25519 work for P-256 too?: https://docs.rs/ring/0.16.14/ring/signature/index.html#signing-and-verifying-with-ed25519
thomaseizinger commentedon Oct 31, 2022
Is implementation of RFC6979 still something that is planned for ring? I might have a go at implementing it then.