Skip to content

Commit 2192ef6

Browse files
committed
Change MontgomeryPoint scalar multiplication output to ProjectiveMontgomeryXpoint
1 parent 65a59aa commit 2192ef6

File tree

1 file changed

+27
-8
lines changed
  • ed448-goldilocks/src/montgomery

1 file changed

+27
-8
lines changed

ed448-goldilocks/src/montgomery/x.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ pub struct ProjectiveMontgomeryXpoint {
6969
}
7070

7171
impl Mul<&EdwardsScalar> for &MontgomeryXpoint {
72-
type Output = MontgomeryXpoint;
72+
type Output = ProjectiveMontgomeryXpoint;
7373

7474
#[allow(clippy::suspicious_arithmetic_impl)]
75-
fn mul(self, scalar: &EdwardsScalar) -> MontgomeryXpoint {
75+
fn mul(self, scalar: &EdwardsScalar) -> ProjectiveMontgomeryXpoint {
7676
// Algorithm 8 of Costello-Smith 2017
7777
let affine_u = FieldElement::from_bytes(&self.0);
7878
let mut x0 = ProjectiveMontgomeryXpoint::identity();
@@ -93,14 +93,14 @@ impl Mul<&EdwardsScalar> for &MontgomeryXpoint {
9393
swap = bit;
9494
}
9595

96-
x0.to_affine()
96+
x0
9797
}
9898
}
9999

100100
impl Mul<&MontgomeryXpoint> for &EdwardsScalar {
101-
type Output = MontgomeryXpoint;
101+
type Output = ProjectiveMontgomeryXpoint;
102102

103-
fn mul(self, point: &MontgomeryXpoint) -> MontgomeryXpoint {
103+
fn mul(self, point: &MontgomeryXpoint) -> ProjectiveMontgomeryXpoint {
104104
point * self
105105
}
106106
}
@@ -165,6 +165,22 @@ impl PartialEq for ProjectiveMontgomeryXpoint {
165165
}
166166
}
167167

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+
168184
fn differential_add_and_double(
169185
P: &mut ProjectiveMontgomeryXpoint,
170186
Q: &mut ProjectiveMontgomeryXpoint,
@@ -231,10 +247,13 @@ mod tests {
231247

232248
// Montgomery scalar mul
233249
let montgomery_bp = bp.to_montgomery_x();
234-
let montgomery_res = &montgomery_bp * &scalar;
250+
let montgomery_res = &(&montgomery_bp * &scalar) * &scalar;
235251

236252
// 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+
);
239258
}
240259
}

0 commit comments

Comments
 (0)