Skip to content

Commit

Permalink
feat: implement Neg for AffinePoint (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Feb 26, 2024
1 parent 6ebaa9b commit 400deb6
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions starknet-curve/src/ec_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ impl ops::AddAssign<&AffinePoint> for AffinePoint {
}
}

impl ops::Neg for &AffinePoint {
type Output = AffinePoint;

fn neg(self) -> AffinePoint {
AffinePoint {
x: self.x,
y: -self.y,
infinity: self.infinity,
}
}
}

impl ops::Sub<&AffinePoint> for &AffinePoint {
type Output = AffinePoint;

Expand All @@ -116,11 +128,7 @@ impl ops::Sub<&AffinePoint> for &AffinePoint {

impl ops::SubAssign<&AffinePoint> for AffinePoint {
fn sub_assign(&mut self, rhs: &AffinePoint) {
*self += &AffinePoint {
x: rhs.x,
y: -rhs.y,
infinity: rhs.infinity,
};
*self += &-rhs;
}
}

Expand Down Expand Up @@ -195,10 +203,7 @@ impl ops::AddAssign<&AffinePoint> for ProjectivePoint {
return;
}
if self.infinity {
self.x = rhs.x;
self.y = rhs.y;
self.z = FieldElement::ONE;
self.infinity = rhs.infinity;
*self = Self::from_affine_point(rhs);
return;
}
let u0 = self.x;
Expand All @@ -208,11 +213,10 @@ impl ops::AddAssign<&AffinePoint> for ProjectivePoint {
if u0 == u1 {
if t0 != t1 {
self.infinity = true;
return;
} else {
self.double_assign();
return;
}
return;
}

let t = t0 - t1;
Expand Down

0 comments on commit 400deb6

Please sign in to comment.