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

elliptic-curve: generic impl of complete prime order formulas #1022

Merged
merged 1 commit into from Jun 12, 2022

Conversation

tarcieri
Copy link
Member

Adds a generic implementation of the complete addition formulas from Renes-Costello-Batina 2015 adapted from @str4d's original implementation for the p256 crate:

RustCrypto/elliptic-curves#15

This implementation has subsequently been copied-and-pasted into the p384 crate (see RustCrypto/elliptic-curves#565), hence the motivation to make it generic and extract it somewhere that it can be reused.

The API exposed is fairly low-level, however it's difficult to better encapsulate it without making breaking changes to the elliptic-curve crate. Thus this PR opts to provide an initial low-level generic implementation with the goal of exploring removing more duplication with a higher-level API as followup work to be done at a time when breaking changes are permitted.

Adds a generic implementation of the complete addition formulas from
Renes-Costello-Batina 2015[1] adapted from @str4d's original
implementation for the `p256` crate:

RustCrypto/elliptic-curves#15

This implementation has been copied-and-pasted into the `p384` crate,
hence the motivation to make it generic and extract it somewhere that it
can be reused.

The API exposed is fairly low-level, however it's difficult to better
encapsulate it without making breaking changes to the `elliptic-curve`
crate. Thus this PR opts to provide an initial low-level generic
implementation with the goal of exploring removing more duplication with
a higher-level API as followup work to be done at a time when breaking
changes are permitted.

[1]: https://eprint.iacr.org/2015/1060
@tarcieri tarcieri requested a review from str4d June 12, 2022 00:16
Comment on lines +10 to +14
/// Affine point whose coordinates are represented by the given field element.
pub type AffinePoint<Fe> = (Fe, Fe);

/// Projective point whose coordinates are represented by the given field element.
pub type ProjectivePoint<Fe> = (Fe, Fe, Fe);
Copy link
Member Author

Choose a reason for hiding this comment

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

The use of coordinate tuples is to prevent confusion with the AffinePoint and ProjectivePoint types currently defined on a crate-by-crate basis (i.e. in p256 and p384)

Perhaps it would be possible in an eventual followup PR to extract a generic ProjectivePoint type which impls these formulas for C: PrimeCurve.

@tarcieri
Copy link
Member Author

An unaddressed problem is testing the implementation in absence of a concrete curve implementation.

Perhaps the dev module could be further implemented to where it contains the core of e.g. P-256.

tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jun 12, 2022
Uses the generic implementation of Renes-Costello-Batina 2015 added to
the `elliptic-curve` crate:

RustCrypto/traits#1022
@tarcieri
Copy link
Member Author

This PR adapts the p384 crate to use this generic implementation: RustCrypto/elliptic-curves#601

@tarcieri tarcieri merged commit ccdae97 into master Jun 12, 2022
@tarcieri tarcieri deleted the elliptic-curve/generic-prime-order-formulas branch June 12, 2022 13:24
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jun 12, 2022
Uses the generic implementation of Renes-Costello-Batina 2015 added to
the `elliptic-curve` crate:

RustCrypto/traits#1022
@newpavlov
Copy link
Member

What about making a fully generic implementation of Weierstrass curves as I tried long ago with elliptic-curves/pull/218?

@tarcieri
Copy link
Member Author

@newpavlov yes, that would be the longer term goal, but as noted in the commit messages doing that effectively would require breaking changes which this implementation is trying to avoid for now.

I can write up some potential designs. One would be changing PrimeCurve from a marker trait to one which actually incorporates these formulas (and provides a blanket impl of the other traits like ScalarArithmetic and ProjectiveArithmetic)

tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jun 12, 2022
Uses the generic implementation of Renes-Costello-Batina 2015 added to
the `elliptic-curve` crate:

RustCrypto/traits#1022
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jun 12, 2022
Uses the generic implementation of Renes-Costello-Batina 2015 added to
the `elliptic-curve` crate:

RustCrypto/traits#1022

This is effectively the same changes as #601 made to `p384`, but for the
`p256` crate.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jun 12, 2022
Uses the generic implementation of Renes-Costello-Batina 2015 added to
the `elliptic-curve` crate:

RustCrypto/traits#1022

This is effectively the same changes as #601 made to `p384`, but for the
`p256` crate.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jun 12, 2022
Uses the generic implementation of Renes-Costello-Batina 2015 added to
the `elliptic-curve` crate:

RustCrypto/traits#1022

This is effectively the same changes as #601 made to `p384`, but for the
`p256` crate.
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.

None yet

2 participants