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

Support Secp256r1 curve (NIST P-256) #81

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

Support Secp256r1 curve (NIST P-256) #81

wants to merge 14 commits into from

Conversation

oleiba
Copy link
Contributor

@oleiba oleiba commented Apr 27, 2020

Note: ring's branch dependency can be changed to master once ZenGo-X/ring#1 is merged.

Comment on lines +32 to +36
[dependencies.ring]
git = "https:/KZen-networks/ring.git"
branch = "feature/p256"
optional = true

Copy link
Contributor

Choose a reason for hiding this comment

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

You probably explained it to me before, but why can't we take Ring from crate.io ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I forked and modified it (in order to extend the API of the keypair which is needed for this PR).
If we'll merge it to master (see ZenGo-X/ring#1) then we can publish KZen's repo with another name. How does that sound?

Copy link
Contributor

Choose a reason for hiding this comment

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

can you give me a sense of what API extension were needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Point arithmetics, serialization etc. (see PR)

Comment on lines 28 to 29
/// The size (in bytes) of a P-256 signature
pub const SIGNATURE_SIZE: usize = 64;
Copy link
Contributor

Choose a reason for hiding this comment

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

what is P-256 signature ?
where do we use this const ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, we don't we use it.
I'll push a commit to delete it.

BigInt::from(CURVE_ORDER.as_ref())
}

fn add(&self, other: &Seed) -> Secp256r1Scalar {
Copy link
Contributor

@omershlo omershlo Apr 27, 2020

Choose a reason for hiding this comment

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

Ring is not providing a way to do add/mul/sub/inv?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not for a field element.
I followed the same pattern as used in the Secp256k1 source, see https:/KZen-networks/curv/blob/master/src/elliptic/curves/secp256_k1.rs#L160.

@omershlo
Copy link
Contributor

omershlo commented May 1, 2020

Hey @oleiba ,

Have you checked https:/RustCrypto/elliptic-curves ?
There is an implementation there for P-256 that looks really good.
(btw, it seems on first look that the above library has a similar concept to Curv library - maybe they were inspired by us. I would be happy to hear your take)

@oleiba
Copy link
Contributor Author

oleiba commented May 1, 2020

It looks like a very new library, first commit in Jan 2020, even after I started my work on this P256 integration.
This seems like a good proposal for moving forward and easier integration in the future with smoother APIs, i.e. for p256 v2.
There's a good use of generics (type templates) for avoiding reuse of code and subtracting away the common and it's pure Rust. On the downside, ring is probably more battle-tested at this point (RustCrypto/elliptic-curves library do not use openssl or another highly used C lib).
That being said, I don't think I will have the bandwidth to substitute ring with this library in the near future.

@omershlo
Copy link
Contributor

omershlo commented May 3, 2020

There is another issue there: RustCrypto/elliptic-curves#29

@str4d
Copy link

str4d commented May 3, 2020

It looks like a very new library, first commit in Jan 2020

The traits in that library started off in the ecdsa crate back in October 2018. The elliptic-curves crate was extracted from ecdsa in December 2019, and moved into its own repository in January.

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.

3 participants