briansmith / ring

Safe, fast, small crypto using Rust
Other
3.75k stars 704 forks source link

ECDSA public key coordinate import/export #1161

Open FlorianUekermann opened 3 years ago

FlorianUekermann commented 3 years ago

For ECDSA public keys, import and export of the x and y coordinates is necessary to convert from and to JWK representations (and presumably some other formats). I personally only need to extract the coordinates. OpenSSL offers EC_POINT_get_affine_coordinates_GFp for this purpose.

gjvnq commented 3 years ago

Take a look at the jsonwebkey-convert crate.

FlorianUekermann commented 3 years ago

Thanks for the pointer. I eventually figured it out in rustls-acme. Some documentation or a method on EcdsaKeyPair may be a good idea to point other people in the right direction and make code that needs the coordinates easier to understand and review.

briansmith commented 1 year ago

In ring 0.17 we have ring::signature::RsaPublicKeyComponents. This is asking to do the same for ECDSA (and presumably Ed25519).

andrewbaxter commented 10 months ago

Can I hack on this? I see ec::PublicKey is an opaque blob. AFAICT there's no information on the curve in that, and users need to supply the correct algorithm for the curve when signing/verifying. I'm not sure why specifically, but unlike RSA which doesn't need the RSA Parameters for the JWK with EC the curve needs to be supplied.

Should I add a custom from method that takes both the public key and the curve? I feel like this could lead to people guessing or hard coding a curve when it needs to match the curve used for generating the key pair.

Alternatively the from method could require the full key pair/private key, or maybe the curve could somehow be added to the type information of the public key.