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

Small perf adjustments for ShortWeierstrassProjectivePoint operations #842

Merged
13 changes: 8 additions & 5 deletions math/src/elliptic_curve/short_weierstrass/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ impl<E: IsShortWeierstrass> ShortWeierstrassProjectivePoint<E> {
}

pub fn double(&self) -> Self {
if self.is_neutral_element() {
return self.clone();
}
let [px, py, pz] = self.coordinates();

let px_square = px * px;
Expand Down Expand Up @@ -86,18 +89,18 @@ impl<E: IsShortWeierstrass> ShortWeierstrassProjectivePoint<E> {
}
// 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();
}
if other.is_neutral_element() {
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([
Expand Down
Loading