Skip to content

Commit 853ca1e

Browse files
committed
Change MontgomeryPoint scalar multiplication output to ProjectiveMontgomeryXpoint
1 parent 3228f9b commit 853ca1e

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
@@ -65,10 +65,10 @@ pub struct ProjectiveMontgomeryXpoint {
6565
}
6666

6767
impl Mul<&EdwardsScalar> for &MontgomeryXpoint {
68-
type Output = MontgomeryXpoint;
68+
type Output = ProjectiveMontgomeryXpoint;
6969

7070
#[allow(clippy::suspicious_arithmetic_impl)]
71-
fn mul(self, scalar: &EdwardsScalar) -> MontgomeryXpoint {
71+
fn mul(self, scalar: &EdwardsScalar) -> ProjectiveMontgomeryXpoint {
7272
// Algorithm 8 of Costello-Smith 2017
7373
let affine_u = FieldElement::from_bytes(&self.0);
7474
let mut x0 = ProjectiveMontgomeryXpoint::identity();
@@ -89,14 +89,14 @@ impl Mul<&EdwardsScalar> for &MontgomeryXpoint {
8989
swap = bit;
9090
}
9191

92-
x0.to_affine()
92+
x0
9393
}
9494
}
9595

9696
impl Mul<&MontgomeryXpoint> for &EdwardsScalar {
97-
type Output = MontgomeryXpoint;
97+
type Output = ProjectiveMontgomeryXpoint;
9898

99-
fn mul(self, point: &MontgomeryXpoint) -> MontgomeryXpoint {
99+
fn mul(self, point: &MontgomeryXpoint) -> ProjectiveMontgomeryXpoint {
100100
point * self
101101
}
102102
}
@@ -161,6 +161,22 @@ impl PartialEq for ProjectiveMontgomeryXpoint {
161161
}
162162
}
163163

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+
164180
fn differential_add_and_double(
165181
P: &mut ProjectiveMontgomeryXpoint,
166182
Q: &mut ProjectiveMontgomeryXpoint,
@@ -227,10 +243,13 @@ mod tests {
227243

228244
// Montgomery scalar mul
229245
let montgomery_bp = bp.to_montgomery_x();
230-
let montgomery_res = &montgomery_bp * &scalar;
246+
let montgomery_res = &(&montgomery_bp * &scalar) * &scalar;
231247

232248
// 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+
);
235254
}
236255
}

0 commit comments

Comments
 (0)