Melab
Melab

Reputation: 2862

What method does OpenSSL use to combine a public EC key's coordinates?

OpenSSL, at least with the command line, dumps an elliptic curve's public part in a sort of compressed format. I have been unable to find a way to get it dump it as the x- and y-coordinates separately. Documentation is lacking on whether this is one of those "compression" methods that I see talked about in RFCs. If it is, then I cannot find the procedure used for converting to and from this compressed form to raw coordinates. What method does OpenSSL use for this? Can it be done from the command line?

Upvotes: 1

Views: 4603

Answers (2)

dave_thompson_085
dave_thompson_085

Reputation: 39020

The public point for an ECC key as stored has two main formats, compressed and uncompressed. OpenSSL supports both, but by default writes uncompressed.

The ec -text option displays whatever was in the input file, in hex on stdout. The ec -conv_form option only affects what is written in the (PEM or DER) output file (which can be stdout or other) and since you specified -noout there is no PEM or DER output.

So your question really is about the input, which might be compressed or not. As the OpenSSL manpage you linked says, OpenSSL (like AFAICT everyone else) uses the ASN.1 formats defined in document SEC1 from the Standards for Efficient Cryptography Group at http://www.secg.org where "Efficient" means ECC and "Group" means mostly Certicom. (The relevant RFCs also link to this document, e.g. rfc 5480 for ECC public keys in X.509/PKIX certificates.)

Specifically, C.4 says the publicKey field in ECPrivateKey is the same as C.3 (for ECPublicKey) which says it is a BITSTRING containing an ECPoint which is defined in C.2 by reference to 2.3.3 (et seq) which says that (except for the point at infinity) it is either

  • uncompressed: the octet 04 followed by the X and Y coordinate values (in that order without additional framing) as big-endian binary integers, or

  • compressed: the octet 02 or 03 followed by the X coordinate (only) as a big-endian binary integer, where the choice between 02 and 03 encodes whether the Y coordinate is even or odd.

Upvotes: 4

Chiara Hsieh
Chiara Hsieh

Reputation: 3393

Generate EC parameters

openssl ecparam -name secp256k1 -out secp256k1.pem

Generate EC KEY with parameters

openssl ecparam -in secp256k1.pem -genkey -noout -out secp256k1-key.pem

Print public, private key components(uncompressed)

openssl ec -in secp256k1-key.pem -text -noout

or

openssl ec -in secp256k1-key.pem -text -noout -conv_form uncompressed

Print public, private key components(compressed)

openssl ec -in secp256k1-key.pem -text -noout -conv_form compressed

--

Reference

  1. openssl ec doc
  2. Command Line Elliptic Curve Operations

P.S. You can go to wiki.openssl.org, there are lots of examples with clear explanation.

Upvotes: 1

Related Questions