@@ -597,41 +597,41 @@ impl EdwardsPoint {
597
597
}
598
598
599
599
/// Add two points
600
- //https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf (3.1)
601
- // These formulas are unified, so for now we can use it for doubling. Will refactor later for speed
600
+ // (3.1) https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf
602
601
pub fn add ( & self , other : & EdwardsPoint ) -> Self {
603
- let aXX = self . X * other. X ; // aX1X2
604
- let dTT = FieldElement :: EDWARDS_D * self . T * other. T ; // dT1T2
605
- let ZZ = self . Z * other. Z ; // Z1Z2
606
- let YY = self . Y * other. Y ;
607
-
608
- let X = {
609
- let x_1 = ( self . X * other. Y ) + ( self . Y * other. X ) ;
610
- let x_2 = ZZ - dTT;
611
- x_1 * x_2
612
- } ;
613
- let Y = {
614
- let y_1 = YY - aXX;
615
- let y_2 = ZZ + dTT;
616
- y_1 * y_2
617
- } ;
618
-
619
- let T = {
620
- let t_1 = YY - aXX;
621
- let t_2 = ( self . X * other. Y ) + ( self . Y * other. X ) ;
622
- t_1 * t_2
623
- } ;
624
-
625
- let Z = { ( ZZ - dTT) * ( ZZ + dTT) } ;
626
-
627
- EdwardsPoint { X , Y , Z , T }
602
+ let A = self . X * other. X ;
603
+ let B = self . Y * other. Y ;
604
+ let C = self . T * other. T * FieldElement :: EDWARDS_D ;
605
+ let D = self . Z * other. Z ;
606
+ let E = ( self . X + self . Y ) * ( other. X + other. Y ) - A - B ;
607
+ let F = D - C ;
608
+ let G = D + C ;
609
+ let H = B - A ;
610
+ Self {
611
+ X : E * F ,
612
+ Y : G * H ,
613
+ Z : F * G ,
614
+ T : E * H ,
615
+ }
628
616
}
629
617
630
618
/// Double this point
631
- // XXX: See comment on addition, the formula is unified, so this will do for now
632
- //https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf (3.1)
619
+ // (3.3) https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf
633
620
pub fn double ( & self ) -> Self {
634
- self . add ( self )
621
+ let A = self . X . square ( ) ;
622
+ let B = self . Y . square ( ) ;
623
+ let C = self . Z . square ( ) . double ( ) ;
624
+ let D = A ;
625
+ let E = ( self . X + self . Y ) . square ( ) - A - B ;
626
+ let G = D + B ;
627
+ let F = G - C ;
628
+ let H = D - B ;
629
+ Self {
630
+ X : E * F ,
631
+ Y : G * H ,
632
+ Z : F * G ,
633
+ T : E * H ,
634
+ }
635
635
}
636
636
637
637
/// Check if this point is on the curve
0 commit comments