From ed315ffcae789358186fca2365ff51e6df1bad93 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Thu, 18 May 2017 23:00:55 +0000 Subject: [PATCH 1/3] Implement {AddAssign, SubAssign} for ExtendedPoint. --- src/curve.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/curve.rs b/src/curve.rs index a9387a6..9d34f6f 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -83,6 +83,7 @@ use collections::Vec; use core::fmt::Debug; use core::iter::Iterator; use core::ops::{Add, Sub, Neg}; +use core::ops::{AddAssign, SubAssign}; use core::ops::{Mul, MulAssign}; use core::ops::Index; @@ -802,6 +803,12 @@ impl<'a,'b> Add<&'b ExtendedPoint> for &'a ExtendedPoint { } } +impl<'b> AddAssign<&'b ExtendedPoint> for ExtendedPoint { + fn add_assign(&mut self, _rhs: &'b ExtendedPoint) { + *self = (self as &ExtendedPoint) + _rhs; + } +} + impl<'a,'b> Sub<&'b ExtendedPoint> for &'a ExtendedPoint { type Output = ExtendedPoint; fn sub(self, other: &'b ExtendedPoint) -> ExtendedPoint { @@ -809,6 +816,12 @@ impl<'a,'b> Sub<&'b ExtendedPoint> for &'a ExtendedPoint { } } +impl<'b> SubAssign<&'b ExtendedPoint> for ExtendedPoint { + fn sub_assign(&mut self, _rhs: &'b ExtendedPoint) { + *self = (self as &ExtendedPoint) - _rhs; + } +} + impl<'a> Neg for &'a ExtendedPoint { type Output = ExtendedPoint; From 27e4ea518165f3260abd303202cf6ec02b1e3f9c Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Thu, 18 May 2017 23:01:31 +0000 Subject: [PATCH 2/3] Add a divider to separate Neg code from Add/Sub. --- src/curve.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/curve.rs b/src/curve.rs index 9d34f6f..3656174 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -822,6 +822,10 @@ impl<'b> SubAssign<&'b ExtendedPoint> for ExtendedPoint { } } +// ------------------------------------------------------------------------ +// Negation +// ------------------------------------------------------------------------ + impl<'a> Neg for &'a ExtendedPoint { type Output = ExtendedPoint; From e37445124931e1a0cb5af78af84adb9c21b8d843 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Thu, 18 May 2017 23:02:39 +0000 Subject: [PATCH 3/3] Implement {AddAssign, SubAssign} for DecafPoint. --- src/decaf.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/decaf.rs b/src/decaf.rs index a97347f..4c4cd6c 100644 --- a/src/decaf.rs +++ b/src/decaf.rs @@ -36,6 +36,7 @@ use subtle::CTAssignable; use subtle::CTNegatable; use core::ops::{Add, Sub, Neg}; +use core::ops::{AddAssign, SubAssign}; use core::ops::{Mul, MulAssign}; use curve; @@ -427,6 +428,12 @@ impl<'a, 'b> Add<&'b DecafPoint> for &'a DecafPoint { } } +impl<'b> AddAssign<&'b DecafPoint> for DecafPoint { + fn add_assign(&mut self, _rhs: &DecafPoint) { + *self = (self as &DecafPoint) + _rhs; + } +} + impl<'a, 'b> Sub<&'b DecafPoint> for &'a DecafPoint { type Output = DecafPoint; @@ -435,6 +442,12 @@ impl<'a, 'b> Sub<&'b DecafPoint> for &'a DecafPoint { } } +impl<'b> SubAssign<&'b DecafPoint> for DecafPoint { + fn sub_assign(&mut self, _rhs: &DecafPoint) { + *self = (self as &DecafPoint) - _rhs; + } +} + impl<'a> Neg for &'a DecafPoint { type Output = DecafPoint;