Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Commit

Permalink
[WIP] Implement Default & Add for EdwardsPoint
Browse files Browse the repository at this point in the history
- Implemented `Default` trait returning (0,1,1,0).
- Half-implemented Point addition for Projective
Twisted Edwards coordinates.
- Added Docs and paper references.
- Added use of needed traits.
  • Loading branch information
CPereez committed May 14, 2019
1 parent 786e6dd commit b45abc5
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
use crate::field::FieldElement;
use crate::scalar::Scalar;
use crate::montgomery::MontgomeryPoint;
use crate::constants;

use subtle::Choice;
use subtle::ConditionallyNegatable;
use subtle::ConditionallySelectable;
use subtle::ConstantTimeEq;

use std::default::Default;
use std::ops::{Add, Sub, Mul, Neg};
use std::fmt::Debug;


/// The first 255 bits of a `CompressedEdwardsY` represent the
/// \\(y\\)-coordinate. The high bit of the 32nd byte gives the sign of \\(x\\).
#[derive(Copy, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -90,19 +96,15 @@ impl PartialEq for EdwardsPoint {
}
}

impl<'a, 'b> Add<&'b EdwardsPoint> for &'a EdwardsPoint {
type Output = EdwardsPoint;
/// Add two EdwardsPoints and give the resulting `EdwardsPoint`
fn add(self, other: &'b EdwardsPoint) -> EdwardsPoint {
unimplemented!()
}
}

impl<'a, 'b> Sub<&'b EdwardsPoint> for &'a EdwardsPoint {
type Output = EdwardsPoint;
/// Substract two EdwardsPoints and give the resulting `EdwardsPoint`
fn sub(self, other: &'b EdwardsPoint) -> EdwardsPoint {
unimplemented!()
impl Default for EdwardsPoint {
/// Returns the default EdwardsPoint Coordinates: (0, 1, 1, 0).
fn default() -> EdwardsPoint {
EdwardsPoint {
X: FieldElement::zero(),
Y: FieldElement::one(),
Z: FieldElement::one(),
T: FieldElement::zero()
}
}
}

Expand All @@ -127,6 +129,33 @@ impl Neg for EdwardsPoint {
}
}

impl<'a, 'b> Add<&'b EdwardsPoint> for &'a EdwardsPoint {
type Output = EdwardsPoint;
/// Add two EdwardsPoints and give the resulting `EdwardsPoint`.
/// Cost: 9M + 1*a + 7add.
/// Cost: 9M + 1*a + 6add dependent upon the first point.
/// Source: 2008 Hisil–Wong–Carter–Dawson, http://eprint.iacr.org/2008/522, Section 3.1.
fn add(self, other: &'b EdwardsPoint) -> EdwardsPoint {
let A: FieldElement = (self.X * other.X);
let B: FieldElement = (self.Y * other.Y);
let C: FieldElement = (self.Z * other.T);
let D: FieldElement = (self.T * other.Z);
let E: FieldElement = &D + &C;
let F: FieldElement = &((self.X - self.Y) * (other.X + other.Y)) + &B - &A;
let G: FieldElement = &B + &(constants::EDWARDS_A) * &A;


}
}

impl<'a, 'b> Sub<&'b EdwardsPoint> for &'a EdwardsPoint {
type Output = EdwardsPoint;
/// Substract two EdwardsPoints and give the resulting `EdwardsPoint`
fn sub(self, other: &'b EdwardsPoint) -> EdwardsPoint {
unimplemented!()
}
}

impl<'a, 'b> Mul<&'b Scalar> for &'a EdwardsPoint {
type Output = EdwardsPoint;
/// Scalar multiplication: compute `scalar * self`.
Expand All @@ -150,7 +179,6 @@ impl EdwardsPoint {
/// Convert to a ProjectiveNielsPoint
pub(crate) fn to_projective_niels(&self) -> ProjectiveNielsPoint {
unimplemented!()
}
}

/// Convert the representation of this point from extended
Expand Down

0 comments on commit b45abc5

Please sign in to comment.