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: consolidate AffineCoordinates trait #1237

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions elliptic-curve/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
ops::{LinearCombination, MulByGenerator, Reduce, ShrAssign},
point::{AffineXCoordinate, AffineYIsOdd},
point::AffineCoordinates,
scalar::FromUintUnchecked,
scalar::IsHigh,
Curve, FieldBytes, PrimeCurve, ScalarPrimitive,
Expand All @@ -15,8 +15,7 @@ use zeroize::DefaultIsZeroes;
pub trait CurveArithmetic: Curve {
/// Elliptic curve point in affine coordinates.
type AffinePoint: 'static
+ AffineXCoordinate<FieldRepr = FieldBytes<Self>>
+ AffineYIsOdd
+ AffineCoordinates<FieldRepr = FieldBytes<Self>>
+ Copy
+ ConditionallySelectable
+ ConstantTimeEq
Expand Down
6 changes: 2 additions & 4 deletions elliptic-curve/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
generic_array::typenum::U32,
ops::{LinearCombination, MulByGenerator, Reduce, ShrAssign},
pkcs8,
point::{AffineXCoordinate, AffineYIsOdd},
point::AffineCoordinates,
rand_core::RngCore,
scalar::{FromUintUnchecked, IsHigh},
sec1::{CompressedPoint, FromEncodedPoint, ToEncodedPoint},
Expand Down Expand Up @@ -415,15 +415,13 @@ pub enum AffinePoint {
Other(EncodedPoint),
}

impl AffineXCoordinate for AffinePoint {
impl AffineCoordinates for AffinePoint {
type FieldRepr = FieldBytes;

fn x(&self) -> FieldBytes {
unimplemented!();
}
}

impl AffineYIsOdd for AffinePoint {
fn y_is_odd(&self) -> Choice {
unimplemented!();
}
Expand Down
2 changes: 1 addition & 1 deletion elliptic-curve/src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//! [SIGMA]: https://webee.technion.ac.il/~hugo/sigma-pdf.pdf

use crate::{
point::AffineXCoordinate, AffinePoint, Curve, CurveArithmetic, FieldBytes, NonZeroScalar,
point::AffineCoordinates, AffinePoint, Curve, CurveArithmetic, FieldBytes, NonZeroScalar,
ProjectivePoint, PublicKey,
};
use core::borrow::Borrow;
Expand Down
8 changes: 3 additions & 5 deletions elliptic-curve/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ pub type AffinePoint<C> = <C as CurveArithmetic>::AffinePoint;
#[cfg(feature = "arithmetic")]
pub type ProjectivePoint<C> = <C as CurveArithmetic>::ProjectivePoint;

/// Obtain the affine x-coordinate of an elliptic curve point.
pub trait AffineXCoordinate {
/// Access to the affine coordinates of an elliptic curve point.
// TODO: use zkcrypto/group#30 coordinate API when available
pub trait AffineCoordinates {
/// Field element representation.
type FieldRepr: AsRef<[u8]>;

/// Get the affine x-coordinate as a serialized field element.
fn x(&self) -> Self::FieldRepr;
}

/// Is the affine y-coordinate of this elliptic curve point odd?
pub trait AffineYIsOdd {
/// Is the affine y-coordinate odd?
fn y_is_odd(&self) -> Choice;
}
Expand Down