-
Notifications
You must be signed in to change notification settings - Fork 228
elliptic-curve: make ToEncodedPoint fallible
#400
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
Conversation
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.
8e0ba21 to
376c96f
Compare
|
|
||
| fn try_from(public_key: &PublicKey<C>) -> Result<EncodedPoint<C>, Error> { | ||
| public_key.to_encoded_point(C::COMPRESS_POINTS).ok_or(Error) | ||
| } |
There was a problem hiding this comment.
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.
|
Per continued discussion on #399, I think I'll retry this with a slightly different approach. |
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).
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).
Closes #399.
As discussed in the aforementioned issue, this changes
ToEncodedPointto be fallible, returning anOption<EncodedPoint<C>>with the expectation thatNoneis returned for the additive identity(a.k.a. point-at-infinity)
Brief background: originally it was not expected for
AffinePointto be able to encode the additive identity, however supporting it allowed for infallible conversions betweenAffinePoint<->ProjectivePoint.Technically, according to SEC1 Section 2.3.3, the identity can be represented by the
Elliptic-Curve-Point-to-Octet-Stringencoding 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 makingToEncodedPointinfallible once again.cc @rozbb @fjarri