From e25a464e570b8c069cac6e1df6c5d802e4b2c4f6 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:48:52 +0200 Subject: [PATCH] Small perf adjustments for ShortWeierstrassProjectivePoint operations (#842) Co-authored-by: Diego K <43053772+diegokingston@users.noreply.github.com> --- math/src/elliptic_curve/short_weierstrass/point.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/math/src/elliptic_curve/short_weierstrass/point.rs b/math/src/elliptic_curve/short_weierstrass/point.rs index 888d3f50a..679edeaea 100644 --- a/math/src/elliptic_curve/short_weierstrass/point.rs +++ b/math/src/elliptic_curve/short_weierstrass/point.rs @@ -52,6 +52,9 @@ impl ShortWeierstrassProjectivePoint { } pub fn double(&self) -> Self { + if self.is_neutral_element() { + return self.clone(); + } let [px, py, pz] = self.coordinates(); let px_square = px * px; @@ -86,11 +89,6 @@ impl ShortWeierstrassProjectivePoint { } // https://hyperelliptic.org/EFD/g1p/data/shortw/projective/addition/madd-1998-cmo pub fn operate_with_affine(&self, other: &Self) -> Self { - let [px, py, pz] = self.coordinates(); - let [qx, qy, _qz] = other.coordinates(); - let u = qy * pz; - let v = qx * pz; - if self.is_neutral_element() { return other.clone(); } @@ -98,6 +96,11 @@ impl ShortWeierstrassProjectivePoint { return self.clone(); } + let [px, py, pz] = self.coordinates(); + let [qx, qy, _qz] = other.coordinates(); + let u = qy * pz; + let v = qx * pz; + if u == *py { if v != *px || *py == FieldElement::zero() { return Self::new([