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

Fixes Curve25519/Ed25519 and adds Brainpool curves for use in OpenPGP.js #144

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mahrud
Copy link

@mahrud mahrud commented Jan 5, 2018

This pull request fixes point encoding problems for X25519 curves, fixes key generation for Curve25519, and adds a key generation function for Ed25519. These are necessary fixes needed for adding ECC support to OpenPGP.js in this pull request: openpgpjs/openpgpjs#618 .

@coveralls
Copy link

coveralls commented Jan 5, 2018

Coverage Status

Coverage increased (+1.0%) to 90.07% when pulling 75637c7 on mahrud:master into ee7970b on indutny:master.

@mahrud
Copy link
Author

mahrud commented Jan 25, 2018

@indutny have you had a chance to review this?
I didn't add any tests here since it still doesn't produce test vectors from #142, but there are new tests in the ecc_nist branch of OpenPGP.js that incorporate changes this PR.

@mahrud mahrud force-pushed the master branch 2 times, most recently from 50d5d5e to 8b8ee84 Compare February 3, 2018 01:19
@mahrud mahrud changed the title Fixes Curve25519/Ed25519 for use in OpenPGP.js Fixes Curve25519/Ed25519 and adds Brainpool curves for use in OpenPGP.js Mar 15, 2018
Copy link
Owner

@indutny indutny left a comment

Choose a reason for hiding this comment

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

Left few comments, otherwise LGTM

compact = null;
}

KeyPair.prototype.getPublic = function getPublic(enc, compact) {
Copy link
Owner

Choose a reason for hiding this comment

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

This is going to be a major semver change.

Copy link
Author

Choose a reason for hiding this comment

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

Do you know when you'd like to release v7.0.0? I can think of some other possibly breaking cleanups that might be worthwhile to do.

For instance, I think it would make sense to remove dependency on hmac-drbg and brorand and instead pass a callback function that returns randomness. This one is definitely breaking, but there are some other things that I can't quite remember off the top of my head.

Copy link

Choose a reason for hiding this comment

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

Don't know about this one. This breaks node.js convention: enc is typically the last argument. It's also going to be a huge pain replacing all the code which relies on the old parameter order.

Agree with removing the brorand dependency though.

Copy link
Author

Choose a reason for hiding this comment

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

I think consistency is more important here. Also, I've done the work of replacing the code which relies on the old order in this project (which was minimal), and other projects can easily fix it whenever they update the vendored version of elliptic.

lib/elliptic/eddsa/index.js Outdated Show resolved Hide resolved
lib/elliptic/eddsa/key.js Outdated Show resolved Hide resolved
@dkg
Copy link

dkg commented Apr 3, 2018

what's the status on this pull request? it'd be nice to get it included so that openpgp.js doesn't use a fork :)

@mahrud
Copy link
Author

mahrud commented Apr 5, 2018

@dkg sorry about the delay. I think it's ready.

@mahrud
Copy link
Author

mahrud commented Apr 12, 2018

Is there anything else I should do here?

@chjj
Copy link

chjj commented Sep 23, 2018

Been looking at some other code and it made me think of this PR and a possible change: are all montgomery points supposed to be the X coordinate in little endian? OpenSSL[1], libsodium[2], and ed25519-donna's X25519 serialization[3] make it seem so.

Also, a lot of these implementations seem to have a nice helper function for converting edwards points to montgomery points[4]. This is useful (though maybe discouraged) for using ed25519 keys for an X25519 ECDH. I have a very particular use case which requires this, which is why I ended up digging through this code.

The point conversion seems to be something like:

// From ed25519-donna:
// x = ((y + z) * inverse(z - y)) % p
const y = ed25519Point.y;
const z = ed25519Point.z;

// curve25519_add(yplusz, p.y, p.z);
const yplusz = y.redAdd(z);

// curve25519_sub(zminusy, p.z, p.y);
const zminusy = z.redSub(y);

// curve25519_recip(zminusy, zminusy);
const zinv = zminusy.redInvm();

// curve25519_mul(yplusz, yplusz, zminusy);
const zmul = yplusz.redMul(zinv);

// curve25519_contract(pk, yplusz);
const x = zmul.fromRed();

return curve25519.point(x, 1);

Adding a Edwards#toMontgomery(curve) method might be nice.

cc @mahrud @indutny

[1] https://github.com/openssl/openssl/blob/master/crypto/ec/curve25519.c#L852
[2] https://github.com/jedisct1/libsodium/blob/master/src/libsodium/crypto_core/ed25519/ref10/fe_51/fe.h#L102
[3] https://github.com/floodyberry/ed25519-donna/blob/master/curve25519-donna-32bit.h#L449
[4] https://github.com/jedisct1/libsodium/blob/master/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c#L143

@chesnokovilya
Copy link

chesnokovilya commented Aug 12, 2019

@indutny Hey! So what prevents this PR from merging? Is it order of parameters in the line? KeyPair.prototype.getPublic = function getPublic(enc, compact)
I think, in general, brainpool curves and better curve25519 support could be good for this library!

@mahrud
Copy link
Author

mahrud commented Aug 12, 2019

@chjj, I haven't used or followed the changes to this repository since last April, so I'm not confident I can add the conversion method you requested. I do remember a lot of pain dealing with conflicting endian-ness in different RFCs, and I kept that in mind when making this PR and added notes or references to relevant RFCs when necessary.

With regards to the order of enc and compact, my opinion is that checking the type of the first input and switching the order of inputs if it is a string, as it is currently, should be avoided.

KeyPair.prototype.getPublic = function getPublic(compact, enc) {
// compact is optional argument
if (typeof compact === 'string') {
enc = compact;
compact = null;
}

That said, if it is the only thing keeping this PR from being merged, then please feel free to amend the PR as you see fit.

I rebased the PR and brought it up to date with the version that openpgp.js uses. All tests are green.

@mahrud
Copy link
Author

mahrud commented Nov 24, 2020

Should I close this PR? Not sure why it's still open, despite being approved. If the changes have already been applied elsewhere, please feel free to close it.

@francois4224
Copy link

Hi, is this PR dead? I'm interested about pure js Brainpool curves support

@mahrud
Copy link
Author

mahrud commented May 2, 2024

I don't think so. It just was never merged...

@Thijs-van-Drongelen
Copy link

Brainpool support would be nice

@mahrud mahrud requested a review from indutny October 16, 2024 12:45
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.

9 participants