Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to export private key from context->ecc_dhe->k #123

Open
naushadck opened this issue Feb 14, 2025 · 2 comments
Open

How to export private key from context->ecc_dhe->k #123

naushadck opened this issue Feb 14, 2025 · 2 comments

Comments

@naushadck
Copy link

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 ?.

@eduardsui
Copy link
Owner

eduardsui commented Feb 14, 2025

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.

@naushadck
Copy link
Author

Thank you.

My understanding was (rpk * lpk = lpk * rpk )
remote_public_key * local_private_key == local_public_key * remote_private_key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants