Move from Curve*::negate to Neg operator

This commit is contained in:
Jack Grigg
2019-05-27 17:36:22 +01:00
parent 8193324986
commit 1a8ec21c03
5 changed files with 46 additions and 41 deletions

View File

@@ -134,6 +134,19 @@ macro_rules! curve_impl {
}
}
impl ::std::ops::Neg for $affine {
type Output = Self;
#[inline]
fn neg(self) -> Self {
let mut ret = self;
if !ret.is_zero() {
ret.y = ret.y.neg();
}
ret
}
}
impl CurveAffine for $affine {
type Engine = Bls12;
type Scalar = $scalarfield;
@@ -163,12 +176,6 @@ macro_rules! curve_impl {
self.mul_bits(bits)
}
fn negate(&mut self) {
if !self.is_zero() {
self.y = self.y.neg();
}
}
fn into_projective(&self) -> $projective {
(*self).into()
}
@@ -188,6 +195,19 @@ macro_rules! curve_impl {
}
}
impl ::std::ops::Neg for $projective {
type Output = Self;
#[inline]
fn neg(self) -> Self {
let mut ret = self;
if !ret.is_zero() {
ret.y = ret.y.neg();
}
ret
}
}
impl<'r> ::std::ops::Add<&'r $projective> for $projective {
type Output = Self;
@@ -324,9 +344,7 @@ macro_rules! curve_impl {
impl<'r> ::std::ops::SubAssign<&'r $projective> for $projective {
fn sub_assign(&mut self, other: &Self) {
let mut tmp = *other;
tmp.negate();
self.add_assign(&tmp);
self.add_assign(&other.neg());
}
}
@@ -566,12 +584,6 @@ macro_rules! curve_impl {
}
}
fn negate(&mut self) {
if !self.is_zero() {
self.y = self.y.neg();
}
}
fn mul_assign<S: Into<<Self::Scalar as PrimeField>::Repr>>(&mut self, other: S) {
let mut res = Self::zero();