Skip to content

Commit c840261

Browse files
committed
Add optimized Edwards addition and doubling algorithms
1 parent bcc2f0b commit c840261

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

ed448-goldilocks/src/edwards/extended.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -598,41 +598,41 @@ impl EdwardsPoint {
598598
}
599599

600600
/// Add two points
601-
//https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf (3.1)
602-
// These formulas are unified, so for now we can use it for doubling. Will refactor later for speed
601+
// (3.1) https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf
603602
pub fn add(&self, other: &EdwardsPoint) -> Self {
604-
let aXX = self.X * other.X; // aX1X2
605-
let dTT = FieldElement::EDWARDS_D * self.T * other.T; // dT1T2
606-
let ZZ = self.Z * other.Z; // Z1Z2
607-
let YY = self.Y * other.Y;
608-
609-
let X = {
610-
let x_1 = (self.X * other.Y) + (self.Y * other.X);
611-
let x_2 = ZZ - dTT;
612-
x_1 * x_2
613-
};
614-
let Y = {
615-
let y_1 = YY - aXX;
616-
let y_2 = ZZ + dTT;
617-
y_1 * y_2
618-
};
619-
620-
let T = {
621-
let t_1 = YY - aXX;
622-
let t_2 = (self.X * other.Y) + (self.Y * other.X);
623-
t_1 * t_2
624-
};
625-
626-
let Z = { (ZZ - dTT) * (ZZ + dTT) };
627-
628-
EdwardsPoint { X, Y, Z, T }
603+
let A = self.X * other.X;
604+
let B = self.Y * other.Y;
605+
let C = self.T * other.T * FieldElement::EDWARDS_D;
606+
let D = self.Z * other.Z;
607+
let E = (self.X + self.Y) * (other.X + other.Y) - A - B;
608+
let F = D - C;
609+
let G = D + C;
610+
let H = B - A;
611+
Self {
612+
X: E * F,
613+
Y: G * H,
614+
Z: F * G,
615+
T: E * H,
616+
}
629617
}
630618

631619
/// Double this point
632-
// XXX: See comment on addition, the formula is unified, so this will do for now
633-
//https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf (3.1)
620+
// (3.3) https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf
634621
pub fn double(&self) -> Self {
635-
self.add(self)
622+
let A = self.X.square();
623+
let B = self.Y.square();
624+
let C = self.Z.square() + self.Z.square();
625+
let D = A;
626+
let E = (self.X + self.Y).square() - A - B;
627+
let G = D + B;
628+
let F = G - C;
629+
let H = D - B;
630+
Self {
631+
X: E * F,
632+
Y: G * H,
633+
Z: F * G,
634+
T: E * H,
635+
}
636636
}
637637

638638
/// Check if this point is on the curve

0 commit comments

Comments
 (0)