Skip to content

Conversation

@tarcieri
Copy link
Member

@tarcieri tarcieri commented Dec 16, 2020

Closes #399.

As discussed in the aforementioned issue, this changes ToEncodedPoint to be fallible, returning an Option<EncodedPoint<C>> with the expectation that None is returned for the additive identity
(a.k.a. point-at-infinity)

Brief background: originally it was not expected for AffinePoint to be able to encode the additive identity, however supporting it allowed for infallible conversions between AffinePoint <-> ProjectivePoint.

Technically, according to SEC1 Section 2.3.3, the identity can be represented by the Elliptic-Curve-Point-to-Octet-String encoding by using a single NULL byte (i.e. [0u8]).

However, this would have the disadvantage of complicating EncodedPoint, making APIs that are presently infallible fallible, and may be unexpected by end users of the traits.

If there's a legitimate use case for supporting SEC1-encoded identity points, we can revisit this tradeoff, adding support for encoding the identity element to EncodedPoint, and making ToEncodedPoint infallible once again.

cc @rozbb @fjarri

Closes #399.

As discussed in the aforementioned issue, this changes `ToEncodedPoint`
to be fallible, returning an `Option<EncodedPoint<C>>` with the
expectation that `None` is returned for the additive identity
(a.k.a. point-at-infinity)

Brief background: originally it was not expected for `AffinePoint` to be
able to encode the additive identity, however supporting it allowed for
infallible conversions between `AffinePoint` <-> `ProjectivePoint`.

Technically, according to SEC1 Section 2.3.3, the identity can be
represented by the `Elliptic-Curve-Point-to-Octet-String` encoding by
using a single NULL byte (i.e. `[0u8]`).

However, this would have the disadvantage of complicating
`EncodedPoint`, making APIs that are presently infallible fallible, and
may be unexpected by end users of the traits.

If there's a legitimate use case for supporting SEC1-encoded identity
points, we can revisit this tradeoff, adding support for encoding the
identity element to `EncodedPoint`, and making `ToEncodedPoint`
infallible once again.
@tarcieri tarcieri force-pushed the elliptic-curve/make-to-encoded-point-fallible branch from 8e0ba21 to 376c96f Compare December 16, 2020 21:50

fn try_from(public_key: &PublicKey<C>) -> Result<EncodedPoint<C>, Error> {
public_key.to_encoded_point(C::COMPRESS_POINTS).ok_or(Error)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

These conversions could potentially remain infallible if we had PublicKey enforce the invariant that the inner point cannot be the additive identity.

That would require making PublicKey::from_affine fallible, which might make sense, and would nicely match the similar invariants of SecretKey, which wraps a NonZeroScalar.

All that said, I'd like to follow up on that in a separate PR.

@tarcieri
Copy link
Member Author

Per continued discussion on #399, I think I'll retry this with a slightly different approach.

@tarcieri tarcieri closed this Dec 16, 2020
@tarcieri tarcieri deleted the elliptic-curve/make-to-encoded-point-fallible branch December 16, 2020 23:23
tarcieri added a commit that referenced this pull request Dec 16, 2020
Closes #399.

The `ToEncodedPoint` trait is infallible. We can either make it fallible
(as attempted in #400) or add support for the SEC1 encoding for the
identity point.

This commit adds SEC1 support for identity, allowing `ToEncodedPoint`
to remain infallible.

Unfortunately breaking as it requires adding new enum variants and some
method signature changes.

However, that said, this should make the SEC1 implementation "complete"
in that it implements the full `Elliptic-Curve-Point-to-Octet-String`
encoding (and decoding).
tarcieri added a commit that referenced this pull request Dec 17, 2020
Closes #399.

The `ToEncodedPoint` trait is infallible. We can either make it fallible
(as attempted in #400) or add support for the SEC1 encoding for the
identity point.

This commit adds SEC1 support for identity, allowing `ToEncodedPoint`
to remain infallible.

Unfortunately breaking as it requires adding new enum variants and some
method signature changes.

However, that said, this should make the SEC1 implementation "complete"
in that it implements the full `Elliptic-Curve-Point-to-Octet-String`
encoding (and decoding).
@daxpedda daxpedda mentioned this pull request Jan 7, 2022
tarcieri pushed a commit that referenced this pull request Jan 7, 2022
Follow-up for #400

Prevent overflows and add zero check.
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.

elliptic-curve: ToEncodedPoint should be fallible

2 participants