@@ -343,41 +343,41 @@ impl EdwardsPoint {
343343 }
344344
345345 /// Add two points
346- //https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf (3.1)
347- // These formulas are unified, so for now we can use it for doubling. Will refactor later for speed
346+ // (3.1) https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf
348347 pub fn add ( & self , other : & EdwardsPoint ) -> Self {
349- let aXX = self . X * other. X ; // aX1X2
350- let dTT = FieldElement :: EDWARDS_D * self . T * other. T ; // dT1T2
351- let ZZ = self . Z * other. Z ; // Z1Z2
352- let YY = self . Y * other. Y ;
353-
354- let X = {
355- let x_1 = ( self . X * other. Y ) + ( self . Y * other. X ) ;
356- let x_2 = ZZ - dTT;
357- x_1 * x_2
358- } ;
359- let Y = {
360- let y_1 = YY - aXX;
361- let y_2 = ZZ + dTT;
362- y_1 * y_2
363- } ;
364-
365- let T = {
366- let t_1 = YY - aXX;
367- let t_2 = ( self . X * other. Y ) + ( self . Y * other. X ) ;
368- t_1 * t_2
369- } ;
370-
371- let Z = { ( ZZ - dTT) * ( ZZ + dTT) } ;
372-
373- EdwardsPoint { X , Y , Z , T }
348+ let A = self . X * other. X ;
349+ let B = self . Y * other. Y ;
350+ let C = self . T * other. T * FieldElement :: EDWARDS_D ;
351+ let D = self . Z * other. Z ;
352+ let E = ( self . X + self . Y ) * ( other. X + other. Y ) - A - B ;
353+ let F = D - C ;
354+ let G = D + C ;
355+ let H = B - A ;
356+ Self {
357+ X : E * F ,
358+ Y : G * H ,
359+ Z : F * G ,
360+ T : E * H ,
361+ }
374362 }
375363
376364 /// Double this point
377- // XXX: See comment on addition, the formula is unified, so this will do for now
378- //https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf (3.1)
365+ // (3.3) https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf
379366 pub fn double ( & self ) -> Self {
380- self . add ( self )
367+ let A = self . X . square ( ) ;
368+ let B = self . Y . square ( ) ;
369+ let C = self . Z . square ( ) . double ( ) ;
370+ let D = A ;
371+ let E = ( self . X + self . Y ) . square ( ) - A - B ;
372+ let G = D + B ;
373+ let F = G - C ;
374+ let H = D - B ;
375+ Self {
376+ X : E * F ,
377+ Y : G * H ,
378+ Z : F * G ,
379+ T : E * H ,
380+ }
381381 }
382382
383383 /// Check if this point is on the curve
0 commit comments