11#![ allow( non_snake_case) ]
22
3- use crate :: curve:: twedwards:: { extended:: ExtendedPoint , extensible :: ExtensiblePoint } ;
3+ use crate :: curve:: twedwards:: extended:: ExtendedPoint ;
44use crate :: field:: FieldElement ;
55use subtle:: { Choice , ConditionallyNegatable , ConditionallySelectable } ;
66
77impl Default for ProjectiveNielsPoint {
88 fn default ( ) -> ProjectiveNielsPoint {
9- ProjectiveNielsPoint :: identity ( )
9+ ProjectiveNielsPoint :: IDENTITY
1010 }
1111}
1212
1313// Its a variant of Niels, where a Z coordinate is added for unmixed readdition
1414// ((y+x)/2, (y-x)/2, dxy, Z)
15- #[ derive( Copy , Clone ) ]
15+ #[ derive( Copy , Clone , Debug ) ]
1616pub struct ProjectiveNielsPoint {
1717 pub ( crate ) Y_plus_X : FieldElement ,
1818 pub ( crate ) Y_minus_X : FieldElement ,
@@ -45,9 +45,12 @@ impl ConditionallyNegatable for ProjectiveNielsPoint {
4545}
4646
4747impl ProjectiveNielsPoint {
48- pub fn identity ( ) -> ProjectiveNielsPoint {
49- ExtensiblePoint :: IDENTITY . to_projective_niels ( )
50- }
48+ pub const IDENTITY : ProjectiveNielsPoint = ProjectiveNielsPoint {
49+ Y_plus_X : FieldElement :: ONE ,
50+ Y_minus_X : FieldElement :: ONE ,
51+ Td : FieldElement :: ZERO ,
52+ Z : FieldElement :: TWO ,
53+ } ;
5154
5255 pub fn to_extended ( self ) -> ExtendedPoint {
5356 let A = self . Y_plus_X - self . Y_minus_X ;
@@ -63,6 +66,23 @@ impl ProjectiveNielsPoint {
6366#[ cfg( test) ]
6467mod tests {
6568 use super :: * ;
69+ use crate :: curve:: twedwards:: extensible:: ExtensiblePoint ;
70+
71+ #[ test]
72+ fn identity ( ) {
73+ // Internally are compared by converting to `ExtendedPoint`.
74+ // Here the right-side identity point is converted to Niel's
75+ // and then both sides are converted to twisted-curve form.
76+ assert_eq ! (
77+ ProjectiveNielsPoint :: IDENTITY ,
78+ ExtensiblePoint :: IDENTITY . to_projective_niels( ) ,
79+ ) ;
80+ // Here only the left-side identity point is converted.
81+ assert_eq ! (
82+ ProjectiveNielsPoint :: IDENTITY . to_extended( ) ,
83+ ExtendedPoint :: IDENTITY ,
84+ ) ;
85+ }
6686
6787 #[ test]
6888 fn test_conditional_negate ( ) {
0 commit comments