-
Notifications
You must be signed in to change notification settings - Fork 267
Add AffineCoordinates trait + DRY out point serialization
#50
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| coverage: | ||
| status: | ||
| patch: off | ||
| project: off |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| //! Generic coordinate system support | ||
|
|
||
| use crate::ScalarBytes; | ||
| use generic_array::ArrayLength; | ||
|
|
||
| /// Trait for obtaining the coordinates of an affine point | ||
| pub trait AffineCoordinates { | ||
| /// Size of a byte array representing an affine coordinate | ||
| type ScalarSize: ArrayLength<u8>; | ||
|
|
||
| /// x-coordinate | ||
| fn x(&self) -> ScalarBytes<Self::ScalarSize>; | ||
|
|
||
| /// y-coordinate | ||
| fn y(&self) -> ScalarBytes<Self::ScalarSize>; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,28 @@ pub mod curve; | |
| pub mod point; | ||
| pub mod public_key; | ||
|
|
||
| pub use curve::{Curve, ScalarBytes}; | ||
| pub use curve::Curve; | ||
| pub use point::{ | ||
| CompressedCurvePoint, CompressedPointSize, UncompressedCurvePoint, UncompressedPointSize, | ||
| }; | ||
| pub use public_key::PublicKey; | ||
|
|
||
| use crate::{consts::U1, coordinates::AffineCoordinates, ScalarBytes}; | ||
| use core::ops::Add; | ||
| use generic_array::ArrayLength; | ||
| use subtle::{ConditionallySelectable, CtOption}; | ||
|
|
||
| /// Fixed-base scalar multiplication | ||
| pub trait FixedBaseScalarMul: Curve | ||
| where | ||
| <Self::ScalarSize as Add>::Output: Add<U1>, | ||
| CompressedPointSize<Self::ScalarSize>: ArrayLength<u8>, | ||
| UncompressedPointSize<Self::ScalarSize>: ArrayLength<u8>, | ||
| { | ||
| /// Affine point type for this elliptic curve | ||
| type Point: AffineCoordinates + ConditionallySelectable + Default; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed-base scalar multiplication doesn't require exposing affine coordinates, so this is a more restrictive abstraction than necessary. I suspect we can address the type bounds issue in another way. |
||
|
|
||
| /// Multiply the given scalar by the generator point for this elliptic | ||
| /// curve. | ||
| fn mul_base(scalar: &ScalarBytes<Self::ScalarSize>) -> CtOption<Self::Point>; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
This abstraction directly exposes the coordinates instead of the effect of using them. Making it a separate trait is better than having it be part of the core traits, but it still implies that coordinates are an API surface that is supported and encouraged.
I would prefer instead e.g. an
EcdsaPrimitivetrait that requires implementing the inner part of the ECDSA algorithm that requires coordinates, and thenEcdsaCurve: EcdsaPrimitivethat provides the full algorithm, which users can import without exposing the inner API unnecessarily. This is similar to thersa::PrivateKey: rsa::DecryptionPrimitivesplit.Separately, using
ScalarBytesfor the coordinates strongly encourages type errors during implementation of the trait. The coordinates are field elements, and scalars (of the affine point's curve) are field elements (of a different field), but the coordinates are not scalars (in the sense that elliptic curve scalars are generally understood).