How to export private key from context->ecc_dhe->k
How can i export private key/public key from context->ecc_dhe->k and make a new ecc_key variable.
I can create an ecc_key by using ecc_ansi_x963_import_ex() from
a buffer. Is it possible to do the similar for the private key ?.
It should be possible. You should check the tomcrypt API reference, TLSe is just using the tomcrypt crypto funcitons.
Just keep in mind that the private key when using ECDHE (Elliptic Curve Diffie-Hellman Ephemeral) is useless, because the common secret is derived as: remote_public_key (+) local_private_key == local_public_key (+) remote_private_key.
Knowing keysize, you could just save key->k to an unsigned char *buf of keysize (you should check if its in bits or bytes). That should be enough. You also need the curve parameters, but this is set in the named curve definition. In other others, you should add an id for the curve in order to identify it.
Check mp_unsigned_bin_size(a) and mp_to_unsigned_bin(a, buffer) where a is key->k and buffer is your saved buffer. Then you can use mp_read_unsigned_bin to read it back from the buffer.
Hope it helps.
Thank you.
My understanding was (rpk * lpk = lpk * rpk ) remote_public_key * local_private_key == local_public_key * remote_private_key.