7

In ASN.1, the X and Y values for a 256-bit elliptic curve key are stored as a single 66-byte ASN.1 BITSTRING. Are the values just the first and second half of this bitstring?

The private key is an OCTET STRING at the beginning of the DER private key and I know what to do with it; the public key is a BITSTRING for some reason.

joeforker
  • 571
  • 5
  • 13

2 Answers2

10

The first octet in a DER encoded BITSTRING is the number of unused bits (0 in this case). The remaining 65 octets are the elliptic curve point encoded as described in SEC 1 (http://www.secg.org/collateral/sec1_final.pdf) section 2.3.4. The first octet distinguishes the identity point and whether point compression is being used. Since you have 65=1+32+32 octets, this is an uncompressed point and the first octet should be 04, follows by the X and Y values encoded as described in section 2.3.6 (basically fixed length big endian).

Frank
  • 216
  • 1
  • 3
1

An ECDSA private key is just an integer, not a pair of integers. Therefore you simply need to interpret this bitstring as an integer, per the ASN.1 specs.

Conrado
  • 6,614
  • 1
  • 30
  • 45