Search code examples
cryptographybouncycastleelliptic-curvelibcrypto

OpenSSL libcrypto: how does EC_POINT_point2oct() encode its result? Is it portable?


EC_POINT_point2oct(ecGroup,EC_KEY_get0_public_key(key),POINT_CONVERSION_COMPRESSED,_pub._key,sizeof(_pub._key),0)

It wouldn't be anything high level like DER, PKCS*, or anything ASN.1. (Would it?) I'm guessing a raw BN containing an EC compressed point.

I'm curious as to whether this result is something that could be ported to other languages, e.g. Java using BouncyCastle's EC classes.


Solution

  • If you browse the source deep enough you will see statements such as these:

    ret = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2*field_len;
    

    so it should not apply any additional encoding, as you expected. It is easy enough try too, of course.

    Returning a compressed point should not be too hard. Retrieving the value back is trickier and may get you into trouble regarding software patents.