Skip to content

Conversation

@tarcieri
Copy link
Member

This is a fairly substantial refactoring of the elliptic-curve crate which extracts a toplevel elliptic_curve::Curve trait and redefines all types to use it.

The elliptic_curve::weierstrass::Curve trait is maintained, but relegated to a marker trait. That said, it's still used as the marker trait for all traits/types defined in the elliptic_curve::weierstrass module.

Notably the main thing this facilitates is making SecretKey generic around a C: elliptic_curve::Curve generic type. The previous impetus was to avoid directly associating types dependent on scalars with specific elliptic curves (rather the curve's order), but this is ultimately unhelpful as it precludes accounting for trait impls on the curve in trait bounds.

With the new approach, we can use trait bounds to conditionally define methods on SecretKey, e.g. bounding a SecretKey::generate impl on curves which impl Arithmetic where Self::Scalar: Generate. This would eliminate the need for a special GenerateSecretKey trait.

One other notable change is the associated type for computing type sizes for a particular curve has been renamed to ElementSize, rather than the previous ScalarSize. This hopefully captures that this size is for all elements related to a particular curve, i.e. both the base and scalar fields.

This is a fairly substantial refactoring of the `elliptic-curve` crate
which extracts a toplevel `elliptic_curve::Curve` trait and redefines
all types to use it.

The `elliptic_curve::weierstrass::Curve` trait is maintained, but
relegated to a marker trait. That said, it's still used as the marker
trait for all traits/types defined in the `elliptic_curve::weierstrass`
module.

Notably the main thing this facilitates is making `SecretKey` generic
around a `C: elliptic_curve::Curve` generic type. The previous impetus
was to avoid directly associating types dependent on scalars with
specific elliptic curves (rather the curve's order), but this is
ultimately unhelpful as it precludes accounting for trait impls on the
curve in trait bounds.

With the new approach, we can use trait bounds to conditionally define
methods on `SecretKey`, e.g. bounding a `SecretKey::generate` impl on
curves which impl `Arithmetic where Self::Scalar: Generate`. This would
eliminate the need for a special `GenerateSecretKey` trait.

One other notable change is the associated type for computing type sizes
for a particular curve has been renamed to `ElementSize`, rather than
the previous `ScalarSize`. This hopefully captures that this size is for
all elements related to a particular curve, i.e. both the base and
scalar fields.
@tarcieri tarcieri force-pushed the elliptic-curve/extract-toplevel-curve-trait branch from 7f25738 to 005e578 Compare July 27, 2020 18:37
@tarcieri
Copy link
Member Author

Note: this is effectively complete, however I'm going to attempt to migrate the existing curve implementations to use it locally and make sure there isn't anything I've missed.

tarcieri added a commit to RustCrypto/signatures that referenced this pull request Jul 27, 2020
Updates usages of the `elliptic-curve` crate API
@tarcieri tarcieri changed the title [WIP] elliptic-curve: extract toplevel Curve trait elliptic-curve: extract toplevel Curve trait Jul 27, 2020
@tarcieri tarcieri marked this pull request as ready for review July 27, 2020 20:43
@tarcieri
Copy link
Member Author

I did the updates to get the ecdsa crate building on top of this in RustCrypto/signatures#105 and also have all of the current curve implementations building locally.

In both cases thanks to the existing type aliases, it was all fairly straightforward.

Based on that, and unifying all of the types/traits as being generic around a single elliptic_curve::Curve trait, I'm going to go ahead and merge this as I think it's a net improvement.

@tarcieri tarcieri merged commit 3fd8ac7 into master Jul 27, 2020
@tarcieri tarcieri deleted the elliptic-curve/extract-toplevel-curve-trait branch July 27, 2020 20:47
tarcieri added a commit to RustCrypto/signatures that referenced this pull request Jul 27, 2020
Updates usages of the `elliptic-curve` crate API
tarcieri added a commit to RustCrypto/signatures that referenced this pull request Jul 27, 2020
Updates usages of the `elliptic-curve` crate API
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jul 27, 2020
Updates usages of the elliptic-curve crate API to incorporate the
changes from RustCrypto/traits#223.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jul 27, 2020
Updates usages of the elliptic-curve crate API to incorporate the
changes from RustCrypto/traits#223.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jul 27, 2020
Updates usages of the elliptic-curve crate API to incorporate the
changes from RustCrypto/traits#223.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jul 27, 2020
Updates usages of the elliptic-curve crate API to incorporate the
changes from RustCrypto/traits#223.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request Jul 27, 2020
Updates usages of the elliptic-curve crate API to incorporate the
changes from RustCrypto/traits#223.
@tarcieri tarcieri mentioned this pull request Aug 10, 2020
dns2utf8 pushed a commit to dns2utf8/traits that referenced this pull request Jan 24, 2023
scv35 added a commit to scv35/Signature-algorithms that referenced this pull request Jul 4, 2025
Updates usages of the `elliptic-curve` crate API
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.

2 participants