Search code examples
ccryptographyecdsaecdh

Is it necessary to have two coordinates for the public key of ECDSA?


I am trying to generate an ECDSA key-pair using an external library called easy-ecc. The thing that I do not understand is this library generates a single coordinate for public key. As far as I see from books, online ECDSA generators or NIST test vectors, the public key has always two coordinates on the curve (X and Y). For example, if P-384 curve is used, the length of the private key will be 48 bytes and the public key will have two different points X and Y, 48 bytes each. So, in total 96 bytes. Yet, the ecc_make_key function does not behave as expected.

Here is the prototype of the function that creates key pairs:

int ecc_make_key(
    uint8_t p_publicKey[ECC_BYTES+1],
    uint8_t p_privateKey[ECC_BYTES]
);

This function fills the empty arrays with pass by reference strategy. However, why the p_publicKey has to be ECC_BYTES+1 instead of ECC_BYTES*2?


Solution

  • If you look at the code;

    int ecc_make_key(uint8_t p_publicKey[ECC_BYTES+1], uint8_t p_privateKey[ECC_BYTES])
    

    takes two parameters a public key and a private key and initialize, them.

    Let's look at the last three lines;

        ecc_native2bytes(p_privateKey, l_private);
        ecc_native2bytes(p_publicKey + 1, l_public.x);
        p_publicKey[0] = 2 + (l_public.y[0] & 0x01);
    
    • private key just copied and that is just a big integer.

    • Only the x coordinate of the public point is copied. This clearly indicates point compression and that need an indicator to resolve the y from only x since except order two points, all other points have a negative.

      • 0x04 indicated there is no compression so the public point is stored completely as

        0x04|public_x|public_y

      • 0x02 This indicates that the public_y is even, and

      • 0x03 This indicates that the public_y is odd

        Both is stored as (0x02|0x03)|public_x

    Why do we compress

    1. It requires fewer data to store and transmit
    2. It helps on point validation