The points of an elliptic curve are almost always encoded using the encoding specified in X9.62.
It is not necessary to use point compression. It is trivial to encode using dot compression, but decoding a compressed point requires a bit more work, so if you really don't need to save extra bytes, I would not bother. Let me know if you need it and I will add details. You can recognize X9.62 encoded points with dot compression by the first byte, which will be 0x02 or 0x03.
Encoding without point compression is very simple: start with 0x04 (to indicate no compression). Then follow first with the x coordinate, then with the y coordinate, with zero padding on the left to the size in bytes of the field:
int qLength = (q.bitLength()+7)/8; byte[] xArr = toUnsignedByteArray(x); byte[] yArr = toUnsignedByteArray(y); byte[] res = new byte[1+2*qLength]; res[0] = 0x04; System.arraycopy(xArr, 0, res, qLength - xArr.length, xArr.length); System.arraycopy(yArr, 0, res, 2* qLength - yArr.length, nLength);
Decoding is, of course, trivial.
Rasmus faber
source share