I am working with mbedtls in a 32-bit microcontroller and have created a ECDH context. I put in the X and Y coordinates of the other party's public key, then attempt to create the shared secret. The shared secret that I am getting is all 0x00. The pertinent lines of code are shown below. key_size = 32. What am I missing/doing wrong?
//Initialize the Static ECDH context and retrieve the static public key
mbedtls_ecdh_init(&ECDH_Context_Static);
mbedtls_ecp_group_load(&ECDH_Context_Static.grp, ElipticCurveID);
mbedtls_ecdh_gen_public(&ECDH_Context_Static.grp, &ECDH_Context_Static.d, &ECDH_Context_Static.Q, mbedtls_ctr_drbg_random, &DRBG_Context);
mbedtls_mpi_write_binary(&ECDH_Context_Static.Q.X, StaticPublicKey_X, key_size); //Write to char array from ECDH context -> copy out static public key
mbedtls_mpi_write_binary(&ECDH_Context_Static.Q.Y, StaticPublicKey_Y, key_size);
//Generate a Static shared secret using local Static private key and Host's Static public key
success = mbedtls_mpi_read_binary(&ECDH_Context_Static.Qp.X, HostStaticPublicKey_X, key_size); //Read to ECDH context from char array -> load in Host's public key
success = mbedtls_mpi_read_binary(&ECDH_Context_Static.Qp.Y, HostStaticPublicKey_Y, key_size);
success = mbedtls_ecdh_compute_shared(&ECDH_Context_Static.grp, &ECDH_Context_Static.z, &ECDH_Context_Static.Qp, &ECDH_Context_Static.d, NULL, NULL);
success = mbedtls_mpi_write_binary(&ECDH_Context_Static.z, StaticSecret, key_size); //Write to char array from ECDH context -> copy out static shared secret