@@ -69,10 +69,10 @@ pub struct ProjectiveMontgomeryXpoint {
69
69
}
70
70
71
71
impl Mul < & EdwardsScalar > for & MontgomeryXpoint {
72
- type Output = MontgomeryXpoint ;
72
+ type Output = ProjectiveMontgomeryXpoint ;
73
73
74
74
#[ allow( clippy:: suspicious_arithmetic_impl) ]
75
- fn mul ( self , scalar : & EdwardsScalar ) -> MontgomeryXpoint {
75
+ fn mul ( self , scalar : & EdwardsScalar ) -> ProjectiveMontgomeryXpoint {
76
76
// Algorithm 8 of Costello-Smith 2017
77
77
let affine_u = FieldElement :: from_bytes ( & self . 0 ) ;
78
78
let mut x0 = ProjectiveMontgomeryXpoint :: identity ( ) ;
@@ -93,14 +93,14 @@ impl Mul<&EdwardsScalar> for &MontgomeryXpoint {
93
93
swap = bit;
94
94
}
95
95
96
- x0. to_affine ( )
96
+ x0
97
97
}
98
98
}
99
99
100
100
impl Mul < & MontgomeryXpoint > for & EdwardsScalar {
101
- type Output = MontgomeryXpoint ;
101
+ type Output = ProjectiveMontgomeryXpoint ;
102
102
103
- fn mul ( self , point : & MontgomeryXpoint ) -> MontgomeryXpoint {
103
+ fn mul ( self , point : & MontgomeryXpoint ) -> ProjectiveMontgomeryXpoint {
104
104
point * self
105
105
}
106
106
}
@@ -165,6 +165,22 @@ impl PartialEq for ProjectiveMontgomeryXpoint {
165
165
}
166
166
}
167
167
168
+ impl Mul < & EdwardsScalar > for & ProjectiveMontgomeryXpoint {
169
+ type Output = ProjectiveMontgomeryXpoint ;
170
+
171
+ fn mul ( self , scalar : & EdwardsScalar ) -> ProjectiveMontgomeryXpoint {
172
+ & self . to_affine ( ) * scalar
173
+ }
174
+ }
175
+
176
+ impl Mul < & ProjectiveMontgomeryXpoint > for & EdwardsScalar {
177
+ type Output = ProjectiveMontgomeryXpoint ;
178
+
179
+ fn mul ( self , point : & ProjectiveMontgomeryXpoint ) -> ProjectiveMontgomeryXpoint {
180
+ point * self
181
+ }
182
+ }
183
+
168
184
fn differential_add_and_double (
169
185
P : & mut ProjectiveMontgomeryXpoint ,
170
186
Q : & mut ProjectiveMontgomeryXpoint ,
@@ -231,10 +247,13 @@ mod tests {
231
247
232
248
// Montgomery scalar mul
233
249
let montgomery_bp = bp. to_montgomery_x ( ) ;
234
- let montgomery_res = & montgomery_bp * & scalar;
250
+ let montgomery_res = & ( & montgomery_bp * & scalar ) * & scalar;
235
251
236
252
// Goldilocks scalar mul
237
- let goldilocks_point = bp. scalar_mul ( & scalar) ;
238
- assert_eq ! ( goldilocks_point. to_montgomery_x( ) , montgomery_res) ;
253
+ let goldilocks_point = bp. scalar_mul ( & scalar) . scalar_mul ( & scalar) ;
254
+ assert_eq ! (
255
+ goldilocks_point. to_montgomery_x( ) ,
256
+ montgomery_res. to_affine( )
257
+ ) ;
239
258
}
240
259
}
0 commit comments