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

Crypto library support for compressed public key representations of supported elliptic curves (eg secp256k1, secp256r1...) #9626

Open
daidoji opened this issue Mar 21, 2025 · 0 comments
Assignees
Labels
enhancement team:VM Assigned to OTP team VM

Comments

@daidoji
Copy link

daidoji commented Mar 21, 2025

Is your feature request related to a problem? Please describe.
It is not directly related to any particular problem, its just some functionality that would be useful in interacting with other libraries that provide the compressed forms of ecc public keys rather than the uncompressed format that the crypto library currently provides.

Describe the solution you'd like
It would be nice if there were a flag or method that could take public keys of elliptic curves (ie secp256k1, secp256r1,...) and provide the compressed representation of that public key rather than the uncompressed version which is currently supported by generate_key. crypto is compatible with https://datatracker.ietf.org/doc/html/rfc3279.html as the uncompressed form is a MAY requirement, but many libraries online now use this representation so it would be nice to have in the standard library.

What happens now:

iex(1)> {public_key, secret_key} = :crypto.generate_key(:ecdh, :secp256r1)
{<<4, 247, 16, 231, 77, 232, 141, 236, 250, 218, 164, 80, 186, 117, 170, 186,
   220, 12, 242, 175, 151, 151, 201, 163, 56, 254, 57, 224, 210, 80, 243, 120,
   138, 7, 217, 80, 222, 72, 45, 167, 220, 218, 221, 13, 212, 133, 30, 129, 79,
   ...>>,
 <<232, 164, 104, 253, 217, 81, 96, 138, 146, 100, 233, 120, 67, 34, 104, 3,
   170, 232, 161, 232, 30, 159, 180, 164, 227, 245, 163, 83, 132, 237, 127,
   133>>}
iex(2)> {byte_size(public_key), byte_size(secret_key)}
{65, 32}

With the compressed format of the public key to the RFC, it would be {33, 32} for that last line.

Describe alternatives you've considered
We have looked for alternative library support in hex but have not yet found it and are currently implementing the compression/uncompression of these public key representations in our application. We may also look to NIF bindings to Rust libraries which do provide this functionality.

@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

4 participants