@@ -30,6 +30,12 @@ pub struct MontgomeryPoint {
3030}
3131
3232impl 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
0 commit comments