File tree Expand file tree Collapse file tree 1 file changed +14
-21
lines changed Expand file tree Collapse file tree 1 file changed +14
-21
lines changed Original file line number Diff line number Diff line change @@ -83,30 +83,22 @@ impl ops::AddAssign<&AffinePoint> for AffinePoint {
83
83
return ;
84
84
}
85
85
if self . infinity {
86
- self . x = rhs. x ;
87
- self . y = rhs. y ;
88
- self . infinity = rhs. infinity ;
86
+ * self = * rhs;
89
87
return ;
90
88
}
91
89
if self . x == rhs. x {
92
- if self . y == -rhs. y {
93
- self . x = FieldElement :: ZERO ;
94
- self . y = FieldElement :: ZERO ;
95
- self . infinity = true ;
96
- return ;
90
+ if self . y == rhs. y {
91
+ self . double_assign ( ) ;
92
+ } else {
93
+ * self = AffinePoint :: identity ( ) ;
97
94
}
98
- self . double_assign ( ) ;
99
95
return ;
100
96
}
101
97
102
- // l = (y2-y1)/(x2-x1)
103
- let lambda = {
104
- let dividend = rhs. y - self . y ;
105
- let divisor_inv = ( rhs. x - self . x ) . invert ( ) . unwrap ( ) ;
106
- dividend * divisor_inv
107
- } ;
98
+ let lambda = ( rhs. y - self . y ) * ( rhs. x - self . x ) . invert ( ) . unwrap ( ) ;
99
+
100
+ let result_x = lambda * lambda - self . x - rhs. x ;
108
101
109
- let result_x = ( lambda * lambda) - self . x - rhs. x ;
110
102
self . y = lambda * ( self . x - result_x) - self . y ;
111
103
self . x = result_x;
112
104
}
@@ -247,16 +239,17 @@ impl ops::AddAssign<&ProjectivePoint> for ProjectivePoint {
247
239
return ;
248
240
}
249
241
if self . infinity {
250
- self . x = rhs. x ;
251
- self . y = rhs. y ;
252
- self . z = rhs. z ;
253
- self . infinity = rhs. infinity ;
242
+ * self = * rhs;
254
243
return ;
255
244
}
256
245
let u0 = self . x * rhs. z ;
257
246
let u1 = rhs. x * self . z ;
258
247
if u0 == u1 {
259
- self . double_assign ( ) ;
248
+ if self . y == rhs. y {
249
+ self . double_assign ( ) ;
250
+ } else {
251
+ * self = ProjectivePoint :: identity ( ) ;
252
+ }
260
253
return ;
261
254
}
262
255
You can’t perform that action at this time.
0 commit comments