Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do i compress or encode the Elliptic curve public key and put it over the network?

I am developing Distributed digital signature that signs a document and send it through network to the Application Server.I am using socket programming in java to do it. I think the public key should be encoded or compressed i.e the x and y values are somehow represented as a single binary data and saved in a public registry or network.But i don't know how to do it in java.

        // I have class like this 
           public class CryptoSystem{                  

               EllipticCurve ec = new EllipticCurve(new P192());

               //-------------------
               //--------------------

               public ECKeyPair generatekeyPair()
               {
                  return ECKeyPair(ec);

               }


            }    
        // i don't think i have problem in the above


    CryptoSystem crypto = new CryptoSystem();
    ECKeyPair keyPair = crypto.generateKeyPair();
    BigInteger prvKey = keyPair.getPrivateKey();
    ECPoint pubKey = keyPair.getPublicKey();
     // recommend me here to  compress and send it  the public key to a shared network.

I want to know how to encode the public key and domain parameters, so that the verifier of the signature will decode it to use it.because when you send them over the network to the verifier u gonna have to encode the as a single byte array.i am no using Bouncy Castle Provider. The whole implementation of ECDSA algorithm is my project

like image 758
Clickmit Wg Avatar asked Jun 07 '12 16:06

Clickmit Wg


People also ask

What is a public key in elliptic curves?

A public key is just the x and y co-ordinate of a point on the elliptic curve. It’s usually stored in hexadecimal format. There are two formats for public keys: 1. Uncompressed

How do I encode elliptic curve points?

Elliptic curve points are almost always encoded using the encoding specified in X9.62. It is optional to use point compression. It is trivial to encode using point compression, but decoding a compressed point needs a bit more work, so unless you really need to save the extra bytes, I would not bother.

What does it mean to compress a public key?

It's a specific way to compress public keys on most elliptic curves in common use. A public key is a point on the curve, represented by its coordinates, i.e. by two numbers. But it's enough to know one coordinate, plus the sign of the coordinate, to reconstruct the other coordinate.

How secure are elliptic curves in cryptography?

The elliptic curves over finite fields, described in these crypto standards are well researched and analysed by cryptographers and are considered to have certain security strength, also described in these standards.


1 Answers

Elliptic curve points are almost always encoded using the encoding specified in X9.62.

It is optional to use point compression. It is trivial to encode using point compression, but decoding a compressed point needs a bit more work, so unless you really need to save the extra bytes, I would not bother. Let me know if you need it, and I will add the details. You can recognize X9.62 encoded points with point compression by the first byte, which will be 0x02 or 0x03.

Encoding without point compression is really simple: start with a 0x04 (to indicate no compression). Then follow with first the x coordinate, then the y coordinate, both zero-padded on the left up 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 this is of course trivial.

like image 112
Rasmus Faber Avatar answered Sep 25 '22 09:09

Rasmus Faber