Implement addition and subtraction for DecafPoint.

This commit is contained in:
Henry & Isis 2017-02-20 02:37:12 -08:00 committed by Henry de Valence
parent f52e2ee37e
commit 084c29c4ed

View file

@ -25,6 +25,8 @@ use constants;
use field::FieldElement;
use subtle::CTAssignable;
use core::ops::{Add, Sub, Neg};
use curve::ExtendedPoint;
// ------------------------------------------------------------------------
@ -151,6 +153,33 @@ impl DecafPoint {
}
}
// ------------------------------------------------------------------------
// Arithmetic
// ------------------------------------------------------------------------
impl<'a, 'b> Add<&'b DecafPoint> for &'a DecafPoint {
type Output = DecafPoint;
fn add(self, other: &'b DecafPoint) -> DecafPoint {
DecafPoint(&self.0 + &other.0)
}
}
impl<'a, 'b> Sub<&'b DecafPoint> for &'a DecafPoint {
type Output = DecafPoint;
fn sub(self, other: &'b DecafPoint) -> DecafPoint {
DecafPoint(&self.0 - &other.0)
}
}
impl<'a> Neg for &'a DecafPoint {
type Output = DecafPoint;
fn neg(self) -> DecafPoint {
DecafPoint(-&self.0)
}
}
// ------------------------------------------------------------------------
// Debug traits