Arm Mbed OS support forum

Compact public ECC key representation

For an IETF protocol that I am currently implementing a compact representation [1] of ECDH public keys needs to be sent over the network and be used on the receiving side for deriving a shared secret. With psa_export_public_key() I can export the public key form a psa_key_id_t object. The exported key is 65 bytes long (I am working with P256) which has the format 04|x|y as documented in [2].

It is easy to compress the public key before sending it → just send the x part.

How to decompress the x part back to the representation 04|x|y. As far I understand psa_raw_key_agreement() function the public key must be encoded “in the same format that psa_import_key() accepts”, that is 04|x|y [3]. Is there a function for that?

In case some else is interested in this topic here is a great project doing exactly that: