@@ -65,10 +65,10 @@ pub struct ProjectiveMontgomeryXpoint {
65
65
}
66
66
67
67
impl Mul < & EdwardsScalar > for & MontgomeryXpoint {
68
- type Output = MontgomeryXpoint ;
68
+ type Output = ProjectiveMontgomeryXpoint ;
69
69
70
70
#[ allow( clippy:: suspicious_arithmetic_impl) ]
71
- fn mul ( self , scalar : & EdwardsScalar ) -> MontgomeryXpoint {
71
+ fn mul ( self , scalar : & EdwardsScalar ) -> ProjectiveMontgomeryXpoint {
72
72
// Algorithm 8 of Costello-Smith 2017
73
73
let affine_u = FieldElement :: from_bytes ( & self . 0 ) ;
74
74
let mut x0 = ProjectiveMontgomeryXpoint :: identity ( ) ;
@@ -89,14 +89,14 @@ impl Mul<&EdwardsScalar> for &MontgomeryXpoint {
89
89
swap = bit;
90
90
}
91
91
92
- x0. to_affine ( )
92
+ x0
93
93
}
94
94
}
95
95
96
96
impl Mul < & MontgomeryXpoint > for & EdwardsScalar {
97
- type Output = MontgomeryXpoint ;
97
+ type Output = ProjectiveMontgomeryXpoint ;
98
98
99
- fn mul ( self , point : & MontgomeryXpoint ) -> MontgomeryXpoint {
99
+ fn mul ( self , point : & MontgomeryXpoint ) -> ProjectiveMontgomeryXpoint {
100
100
point * self
101
101
}
102
102
}
@@ -161,6 +161,22 @@ impl PartialEq for ProjectiveMontgomeryXpoint {
161
161
}
162
162
}
163
163
164
+ impl Mul < & EdwardsScalar > for & ProjectiveMontgomeryXpoint {
165
+ type Output = ProjectiveMontgomeryXpoint ;
166
+
167
+ fn mul ( self , scalar : & EdwardsScalar ) -> ProjectiveMontgomeryXpoint {
168
+ & self . to_affine ( ) * scalar
169
+ }
170
+ }
171
+
172
+ impl Mul < & ProjectiveMontgomeryXpoint > for & EdwardsScalar {
173
+ type Output = ProjectiveMontgomeryXpoint ;
174
+
175
+ fn mul ( self , point : & ProjectiveMontgomeryXpoint ) -> ProjectiveMontgomeryXpoint {
176
+ point * self
177
+ }
178
+ }
179
+
164
180
fn differential_add_and_double (
165
181
P : & mut ProjectiveMontgomeryXpoint ,
166
182
Q : & mut ProjectiveMontgomeryXpoint ,
@@ -227,10 +243,13 @@ mod tests {
227
243
228
244
// Montgomery scalar mul
229
245
let montgomery_bp = bp. to_montgomery_x ( ) ;
230
- let montgomery_res = & montgomery_bp * & scalar;
246
+ let montgomery_res = & ( & montgomery_bp * & scalar ) * & scalar;
231
247
232
248
// Goldilocks scalar mul
233
- let goldilocks_point = bp. scalar_mul ( & scalar) ;
234
- assert_eq ! ( goldilocks_point. to_montgomery_x( ) , montgomery_res) ;
249
+ let goldilocks_point = bp. scalar_mul ( & scalar) . scalar_mul ( & scalar) ;
250
+ assert_eq ! (
251
+ goldilocks_point. to_montgomery_x( ) ,
252
+ montgomery_res. to_affine( )
253
+ ) ;
235
254
}
236
255
}
0 commit comments