Skip to content
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: 3 additions & 2 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},
AffineXCoordinate, Curve, FieldBytes, IsHigh, PrimeCurve, ScalarCore,
AffineXCoordinate, AffineYIsOdd, Curve, FieldBytes, IsHigh, PrimeCurve, ScalarCore,
};
use core::fmt::Debug;
use subtle::{ConditionallySelectable, ConstantTimeEq};
Expand All @@ -12,7 +12,8 @@ use zeroize::DefaultIsZeroes;
pub trait CurveArithmetic: Curve {
/// Elliptic curve point in affine coordinates.
type AffinePoint: 'static
+ AffineXCoordinate<Self>
+ AffineXCoordinate<FieldRepr = FieldBytes<Self>>
+ AffineYIsOdd
+ Copy
+ ConditionallySelectable
+ ConstantTimeEq
Expand Down
12 changes: 10 additions & 2 deletions elliptic-curve/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
sec1::{CompressedPoint, FromEncodedPoint, ToEncodedPoint},
subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption},
zeroize::DefaultIsZeroes,
AffineXCoordinate, Curve, CurveArithmetic, IsHigh, PrimeCurve,
AffineXCoordinate, AffineYIsOdd, Curve, CurveArithmetic, IsHigh, PrimeCurve,
};
use core::{
iter::{Product, Sum},
Expand Down Expand Up @@ -377,12 +377,20 @@ pub enum AffinePoint {
Other(EncodedPoint),
}

impl AffineXCoordinate<MockCurve> for AffinePoint {
impl AffineXCoordinate for AffinePoint {
type FieldRepr = FieldBytes;

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

impl AffineYIsOdd for AffinePoint {
fn y_is_odd(&self) -> Choice {
unimplemented!();
}
}

impl ConstantTimeEq for AffinePoint {
fn ct_eq(&self, other: &Self) -> Choice {
match (self, other) {
Expand Down
3 changes: 2 additions & 1 deletion elliptic-curve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ mod jwk;
pub use crate::{
error::{Error, Result},
point::{
AffineXCoordinate, DecompactPoint, DecompressPoint, PointCompaction, PointCompression,
AffineXCoordinate, AffineYIsOdd, DecompactPoint, DecompressPoint, PointCompaction,
PointCompression,
},
scalar::{core::ScalarCore, IsHigh},
secret_key::SecretKey,
Expand Down
13 changes: 11 additions & 2 deletions elliptic-curve/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ use crate::{Curve, FieldBytes};
use subtle::{Choice, CtOption};

/// Obtain the affine x-coordinate of an elliptic curve point.
pub trait AffineXCoordinate<C: Curve> {
pub trait AffineXCoordinate {
/// Field element representation.
type FieldRepr: AsRef<[u8]>;

/// Get the affine x-coordinate as a serialized field element.
fn x(&self) -> FieldBytes<C>;
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;
}

/// Decompress an elliptic curve point.
Expand Down