On Jun 26, 2012, at 7:20 PM, Dave Thompson wrote:
> It's probably still easier to write a small program, 
> but if you really want to do it yourself, you can see 
> the structure by asn1parse'ing an existing one, or 
> looking at the code starting with ec/ec_asn1.c . It is 
> SEQUENCE 
>  version INTEGER = 1
>  privatekey OCTETSTRING -- really the integer 
>  parameters CONTEXT[0] CHOICE 
>    named_curve OID 
>    -- other choices not applicable
>  publickey CONTEXT[1] BITSTRING 
>    -- contains the encoding/representation of the point 
>    -- there are several options for point "conversion" 
>    -- or "compression" apparently defined by X9.62 
>    -- which I don't have so you'll probably have to find a 
>    -- (good) reference or go through this part of the code

I had to do this fairly recently. There's probably no need to use the 
compressed point format unless you're really pressed for space. The 
uncompressed format is described by X9.62, SEC1, and/or P1353, but it boils 
down to:

   - convert Qx and Qy to unsigned integers whose width is determined by the 
size of the curve in the obvious way (e.g., for P-384, convert them into 
48-byte integers)
   - concatenate  the byte 0x04, then Qx, then Qy  (the 0x04 indicates that an 
uncompressed point follows)

then for the rest of the encoding:
   - treat the resulting byte string as a bit string and wrap it in a DER 
BITSTRING
   - wrap the result in the rest of the structure Dave Thompson describes

IIRC, neither X9.62 nor P1353 are freely available, but SEC1 is:  
     http://www.secg.org/collateral/sec1_final.pdf
and it contains enough detail to do the entire conversion, including point 
compression if you really want to. RFC 3279, RFC 5480, and RFC 2459 may also be 
useful references along with Burton S. Kaliski's "Layman's Guide to [a subset 
of] ASN.1, BER, and DER", and "openssl asn1parse" to check whether the result 
you have constructed is parsable.


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to