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 #310

Merged
merged 6 commits into from
Oct 30, 2024
Merged

Support Secp256r1 #310

merged 6 commits into from
Oct 30, 2024

Conversation

mitschabaude
Copy link
Collaborator

@mitschabaude mitschabaude commented Oct 24, 2024

companion of o1-labs/o1js#1885

  • support general curve parameter a in most elliptic curve methods
  • change many EC methods to take the additional a parameter
  • support curve parameter a = -3 in projective curve doubling
    • this is the parameter used by secp256r1
    • note: there is a more efficient algorithm for a=-3 than for general a. thanks to the other changes here, it would now be very simple to add the general a case as well, but for testing we would need a concrete curve with general a, and I'm skipping the work of finding one since I'm not interested in general curves here
  • unit-test the new curve (and also its base field)

@mitschabaude
Copy link
Collaborator Author

@Trivo25 can you get me the necessary reviewers for this?

Copy link
Member

@Geometer1729 Geometer1729 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@querolita querolita left a comment

Choose a reason for hiding this comment

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

Left two observations, other than that looks good

@@ -15,6 +15,18 @@ const secp256k1Params: CurveParams = {
},
};

const secp256r1Params: CurveParams = {
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

@@ -26,6 +26,10 @@ let exampleFields = {
f25519: createField(p25519),
secp256k1: createField(pSecp256k1),
secq256k1: createField(pSecq256k1),
secp256r1:
createField(
0xffffffff00000001000000000000000000000000ffffffffffffffffffffffffn
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

@@ -530,14 +623,12 @@ function createCurveAffine({
endoScalar,
endoBase,
}: CurveParams) {
// TODO: lift this limitation by using other formulas (in projectiveScale) for a != 0
if (a !== 0n) throw Error('createCurveAffine only supports a = 0');
Copy link
Member

Choose a reason for hiding this comment

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

Removing this check implies you allow any a? In createCurveProjective you removed the check and called createProjectiveDouble where there's a check that a is 0 or -3. But what about here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that's a good point, I mean we do support general a now in all the purely affine methods like affineAdd, affineDouble. the only place which doesn't support general a is projectiveDouble, which is used here by methods like scale() and isInSubgroup()

so I think we can accept general a here at this point and only when using certain unsupported methods users would hit the error.

crypto/elliptic-curve.ts Show resolved Hide resolved
@Trivo25 Trivo25 merged commit acc5a7c into o1-labs:main Oct 30, 2024
1 check passed
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.

4 participants