Unable to calculate ecdh shared secret from x and y coordinates

Hello,

I am using mbed TLS on siliconlab microcontroller. I am using Openssl on android for Ecdh implementation and mbed TLS for the microcontroller.

On Android, i am able to calculate Ecdh shared Secret using X and Y coordinates of the curve generated by mbed TLS.

But on mbed TLS I am not able to calculate Ecdh shared Secret using the X and Y coordinates sent from android.

I am concatenating the X and Y and pass the buffer to the following function:

mbedtls_ecdh_read_public(&ecdhContext, concatinatedArray, 58);

but it returns error code .

1- Is there any simple way i can use the X and Y coordinates to calculate the Ecdh shared secret?

2- Is there any example that works with openSsl Ecdh?

3- How i can generate/ calculate public key from the X and Y coordinates?

I used the following function to get the public key:

mbedtls_ecp_point_read_binary(&ecpGroup, &ecpPoint, concatinatedArray.dataPtr, (size_t)concatinatedArray.dataLength);

but it is not correct.

mbedtls_ecdh_compute_shared gives error MBEDTLS_ERR_ECP_INVALID_KEY

I will be really thankful for your kind help.

Regards

Hi @mingele
Is the point compressed or uncompressed?
Note that the first byte in your buffer should be the compression byte, and then the value of X.
As you can see here, mbedtls_ecp_point_read_binary only supports reading uncompressed points for public key, and you should verify your buffer should be:
04 <Value of X> <value of Y>
Regards,
Mbed TLS Support
Ron

1 Like

Hi @roneld01

Thanks a lot. It helped and worked.

Another question is how i can check if the X, Y point lies on the curve?

Regards

Hi @mingele
mbedtls_ecp_check_pubkey() should answer your needs
Regards

1 Like