Skip to content

Commit ccfa042

Browse files
committed
Account for more identity point conversion
1 parent 79e7a0f commit ccfa042

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

ed448-goldilocks/src/edwards/affine.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ impl AffinePoint {
130130
// v = (2 - x^2 - y^2)*y/x^3)
131131
let v = ((FieldElement::TWO - x_sq - y_sq) * self.y) * (x_sq * self.x).invert();
132132

133-
MontgomeryPoint::new(u, v)
133+
MontgomeryPoint::conditional_select(
134+
&MontgomeryPoint::new(u, v),
135+
&MontgomeryPoint::IDENTITY,
136+
self.ct_eq(&Self::IDENTITY),
137+
)
134138
}
135139

136140
/// The X coordinate

ed448-goldilocks/src/montgomery/point.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ pub struct MontgomeryPoint {
3030
}
3131

3232
impl MontgomeryPoint {
33+
/// The identity element of the group: the point at infinity.
34+
pub const IDENTITY: Self = Self {
35+
x: FieldElement::ZERO,
36+
y: FieldElement::ONE,
37+
};
38+
3339
pub(crate) fn new(x: FieldElement, y: FieldElement) -> Self {
3440
Self { x, y }
3541
}
@@ -57,7 +63,11 @@ impl MontgomeryPoint {
5763
let x = xn * yd * d;
5864
let y = yn * xd * d;
5965

60-
AffinePoint { x, y }
66+
AffinePoint::conditional_select(
67+
&AffinePoint { x, y },
68+
&AffinePoint::IDENTITY,
69+
self.ct_eq(&Self::IDENTITY),
70+
)
6171
}
6272

6373
/// Convert the point to its form without the y-coordinate
@@ -410,7 +420,7 @@ mod tests {
410420
use hex_literal::hex;
411421

412422
#[test]
413-
fn test_montgomery_edwards() {
423+
fn to_edwards() {
414424
let scalar = MontgomeryScalar::from(200u32);
415425

416426
// Montgomery scalar mul
@@ -424,15 +434,31 @@ mod tests {
424434
}
425435

426436
#[test]
427-
fn test_montgomery_x() {
437+
fn identity_to_edwards() {
438+
let edwards = AffinePoint::IDENTITY;
439+
let montgomery = MontgomeryPoint::IDENTITY;
440+
441+
assert_eq!(montgomery.to_edwards(), edwards);
442+
}
443+
444+
#[test]
445+
fn identity_from_montgomery() {
446+
let edwards = AffinePoint::IDENTITY;
447+
let montgomery = MontgomeryPoint::IDENTITY;
448+
449+
assert_eq!(edwards.to_montgomery(), montgomery);
450+
}
451+
452+
#[test]
453+
fn to_montgomery_x() {
428454
let x_identity = ProjectiveMontgomeryXpoint::IDENTITY;
429455
let identity = ProjectiveMontgomeryPoint::IDENTITY;
430456

431457
assert_eq!(identity.to_projective_x(), x_identity);
432458
}
433459

434460
#[test]
435-
fn test_montgomery_affine_x() {
461+
fn to_montgomery_affine_x() {
436462
let x_identity = ProjectiveMontgomeryXpoint::IDENTITY.to_affine();
437463
let identity = ProjectiveMontgomeryPoint::IDENTITY.to_affine();
438464

ed448-goldilocks/src/montgomery/x.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ mod tests {
369369
use sha3::Shake256;
370370

371371
#[test]
372-
fn test_montgomery_edwards() {
372+
fn to_edwards() {
373373
let scalar = MontgomeryScalar::from(200u32);
374374

375375
// Montgomery scalar mul
@@ -383,15 +383,15 @@ mod tests {
383383
}
384384

385385
#[test]
386-
fn test_montgomery_extended() {
386+
fn to_montgomery_extended_x() {
387387
let x_identity = ProjectiveMontgomeryXpoint::IDENTITY;
388388
let identity = ProjectiveMontgomeryPoint::IDENTITY;
389389

390390
assert_eq!(x_identity.to_extended(Choice::from(1)), identity);
391391
}
392392

393393
#[test]
394-
fn test_montgomery_extended_affine() {
394+
fn to_montgomery_extended_affine() {
395395
let x_identity = ProjectiveMontgomeryXpoint::IDENTITY.to_affine();
396396
let identity = ProjectiveMontgomeryPoint::IDENTITY.to_affine();
397397

0 commit comments

Comments
 (0)