Skip to content

Commit 645c80e

Browse files
committed
Restrict Edwards <-> Montgomery conversion to Affine form
1 parent 3ac0ae8 commit 645c80e

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

ed448-goldilocks/src/edwards/affine.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl AffinePoint {
111111
}
112112

113113
/// Convert this point to [`MontgomeryXpoint`]
114+
// See https://www.rfc-editor.org/rfc/rfc7748#section-4.2 4-isogeny maps
114115
pub fn to_montgomery_x(&self) -> MontgomeryXpoint {
115116
// u = y^2/x^2
116117
let u = self.y.square() * self.x.square().invert();
@@ -119,10 +120,12 @@ impl AffinePoint {
119120
}
120121

121122
/// Convert this point to [`MontgomeryPoint`]
123+
// See https://www.rfc-editor.org/rfc/rfc7748#section-4.2 4-isogeny maps
122124
pub fn to_montgomery(&self) -> MontgomeryPoint {
123125
let x_sq = self.x.square();
124126
let y_sq = self.y.square();
125127

128+
// u = y^2/x^2
126129
let u = y_sq * x_sq.invert();
127130
// v = (2 - x^2 - y^2)*y/x^3)
128131
let v = ((FieldElement::TWO - x_sq - y_sq) * self.y) * (x_sq * self.x).invert();

ed448-goldilocks/src/edwards/extended.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,14 +1186,16 @@ mod tests {
11861186

11871187
// Test Montgomery to Edwards conversion.
11881188
let conv_p =
1189-
ProjectiveMontgomeryXpoint::encode::<ExpandMsgXof<Shake256>>(&[msg], &[DST]);
1189+
ProjectiveMontgomeryXpoint::encode::<ExpandMsgXof<Shake256>>(&[msg], &[DST])
1190+
.to_affine();
11901191
let conv_p1 = conv_p.to_edwards(Choice::from(0));
11911192
let conv_p2 = conv_p.to_edwards(Choice::from(1));
11921193
assert!(conv_p1.x == p.x || conv_p2.x == p.x);
11931194
assert!(conv_p1.y == p.y || conv_p2.y == p.y);
11941195

11951196
let conv_p = Curve448::encode_from_bytes::<ExpandMsgXof<Shake256>>(&[msg], &[DST])
11961197
.unwrap()
1198+
.to_affine()
11971199
.to_edwards();
11981200
assert_eq!(conv_p.x, p.x);
11991201
assert_eq!(conv_p.y, p.y);

ed448-goldilocks/src/montgomery/point.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ impl ProjectiveMontgomeryPoint {
174174
self.to_projective_x().to_affine()
175175
}
176176

177-
/// Convert this point to an [`AffinePoint`]
178-
pub fn to_edwards(&self) -> AffinePoint {
179-
self.to_affine().to_edwards()
180-
}
181-
182177
/// Hash a message to a point on the curve
183178
///
184179
/// Hash using the default domain separation tag and hash function.

ed448-goldilocks/src/montgomery/x.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ impl ProjectiveMontgomeryXpoint {
240240
W: FieldElement::ONE,
241241
};
242242

243+
// See https://www.rfc-editor.org/rfc/rfc7748#section-1
243244
fn y(&self, sign: Choice) -> FieldElement {
244245
// v^2 = u^3 + A*u^2 + u
245246
let u_sq = self.U.square();
@@ -342,11 +343,6 @@ impl ProjectiveMontgomeryXpoint {
342343
pub fn to_extended(&self, sign: Choice) -> ProjectiveMontgomeryPoint {
343344
ProjectiveMontgomeryPoint::new(self.U, self.y(sign), self.W)
344345
}
345-
346-
/// Convert this point to an [`AffinePoint`]
347-
pub fn to_edwards(&self, sign: Choice) -> AffinePoint {
348-
self.to_affine().to_edwards(sign)
349-
}
350346
}
351347

352348
#[cfg(test)]

0 commit comments

Comments
 (0)