From 084c29c4ed6acb9bf3314420ff590056b4ea52f8 Mon Sep 17 00:00:00 2001 From: Henry & Isis Date: Mon, 20 Feb 2017 02:37:12 -0800 Subject: [PATCH] Implement addition and subtraction for DecafPoint. --- src/decaf.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/decaf.rs b/src/decaf.rs index 42d2721..d092d9d 100644 --- a/src/decaf.rs +++ b/src/decaf.rs @@ -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