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

add ed25519 to curve25519 conversion helpers #217

Merged
merged 4 commits into from
Mar 15, 2021
Merged

Conversation

abom
Copy link
Contributor

@abom abom commented Mar 15, 2021

Don't know if it's the right place to add these helpers or If I did any unintended mistakes or more tests need to be added!

If this need to be moved to Util module or somewhere else, just let me know.

https://libsodium.gitbook.io/doc/advanced/ed25519-curve25519 should be read for anyone who uses this (we already used this in one of our projects).

Resolves #204.

Copy link
Contributor

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The methods should at least indicate that they're converting from the Edwards ("Ed25519") to Montgomery ("Curve25519", "X25519") forms.

Unfortunately this gem uses the now outdated "Curve25519" naming which is a bit ambiguous (as Curve25519 is also often used to describe the curve regardless of what form it's expressed in).

All that said, maybe to_curve25519_private_key and to_curve25519_public_key?

@abom
Copy link
Contributor Author

abom commented Mar 15, 2021

Yes, that would be less ambiguous for sure, updated method names and added (x25519) in the doc.

Comment on lines 34 to 36
it "can be converted to curve25519 private key" do
expect(subject.to_private_key).to be_a_kind_of(RbNaCl::PrivateKey)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to find some test vectors and ensure the output is correct for both methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added test vectors (generated by pynacl).

@tarcieri
Copy link
Contributor

Looks good, thanks!

@tarcieri tarcieri merged commit 3fb9eb2 into RubyCrypto:master Mar 15, 2021
@nlsrchtr
Copy link

nlsrchtr commented Feb 8, 2022

Hi @tarcieri and @abom,

thanks for your work here. I was trying this on main branch with the following code:

signing_private_key = RbNaCl::Signatures::Ed25519::SigningKey.new(SecureRandom.random_bytes(32))
signing_public_key = signing_private_key.verify_key
private_key = signing_private_key.to_curve25519_private_key
public_key = private_key.public_key

and was running into undefined method "to_curve25519_private_key" for #<RbNaCl::Signatures::Ed25519::SigningKey:eddda15d> (NoMethodError).

Is there anything I'm missing here? Thanks for your help!

@abom
Copy link
Contributor Author

abom commented Feb 10, 2022

Hi @nlsrchtr

I tested your example and it's working, please make sure you're using the correct version of rbnacl. I think you need to make sure it does not load it from another path. Also, a complete backtrace would help.

@tarcieri tarcieri mentioned this pull request Oct 15, 2024
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

Successfully merging this pull request may close these issues.

Converting a verification key into public key
3 participants