From 80429064848809675c41c7859631aa4dc07c55e4 Mon Sep 17 00:00:00 2001 From: David Nevado Date: Mon, 7 Mar 2022 11:19:15 +0100 Subject: [PATCH 1/3] Change `Coordinates` fields to `pub` --- src/arithmetic/curves.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/arithmetic/curves.rs b/src/arithmetic/curves.rs index ca94e58..d718fc2 100644 --- a/src/arithmetic/curves.rs +++ b/src/arithmetic/curves.rs @@ -134,8 +134,10 @@ pub trait CurveAffine: #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] #[derive(Clone, Copy, Debug, Default)] pub struct Coordinates { - pub(crate) x: C::Base, - pub(crate) y: C::Base, + /// x-coordinate of the EC point. + pub x: C::Base, + /// y-coordinate of the EC point. + pub y: C::Base, } #[cfg(feature = "alloc")] From 8a3643682fbde3343b9ca9aab1883757b3223213 Mon Sep 17 00:00:00 2001 From: David Nevado Date: Sat, 12 Mar 2022 15:42:57 +0100 Subject: [PATCH 2/3] Change `Coordinates` attrs back to `pub(crate)` --- src/arithmetic/curves.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/arithmetic/curves.rs b/src/arithmetic/curves.rs index d718fc2..ca94e58 100644 --- a/src/arithmetic/curves.rs +++ b/src/arithmetic/curves.rs @@ -134,10 +134,8 @@ pub trait CurveAffine: #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] #[derive(Clone, Copy, Debug, Default)] pub struct Coordinates { - /// x-coordinate of the EC point. - pub x: C::Base, - /// y-coordinate of the EC point. - pub y: C::Base, + pub(crate) x: C::Base, + pub(crate) y: C::Base, } #[cfg(feature = "alloc")] From 8b101d67c4408c1191dd0bb1ace2b9bc50b37553 Mon Sep 17 00:00:00 2001 From: David Nevado Date: Sat, 12 Mar 2022 15:46:43 +0100 Subject: [PATCH 3/3] Add `Coordinates` constructor --- src/arithmetic/curves.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/arithmetic/curves.rs b/src/arithmetic/curves.rs index ca94e58..44eced6 100644 --- a/src/arithmetic/curves.rs +++ b/src/arithmetic/curves.rs @@ -140,6 +140,11 @@ pub struct Coordinates { #[cfg(feature = "alloc")] impl Coordinates { + /// Obtains a `Coordinates` value given $(x, y)$, failing if it is not on the curve. + pub fn from_xy(x: C::Base, y: C::Base) -> CtOption { + // We use CurveAffine::from_xy to validate the coordinates. + C::from_xy(x, y).map(|_| Coordinates { x, y }) + } /// Returns the x-coordinate. /// /// Equivalent to `Coordinates::u`.