11#![ allow( non_snake_case) ]
22
3- use crate :: curve:: twedwards:: extended:: ExtendedPoint ;
43use crate :: curve:: twedwards:: extensible:: ExtensiblePoint ;
54use crate :: field:: FieldElement ;
65use subtle:: { Choice , ConditionallyNegatable , ConditionallySelectable } ;
76
87impl Default for ProjectiveNielsPoint {
98 fn default ( ) -> ProjectiveNielsPoint {
10- ProjectiveNielsPoint :: identity ( )
9+ ProjectiveNielsPoint :: IDENTITY
1110 }
1211}
1312
1413// Its a variant of Niels, where a Z coordinate is added for unmixed readdition
1514// ((y+x)/2, (y-x)/2, dxy, Z)
16- #[ derive( Copy , Clone ) ]
15+ #[ derive( Copy , Clone , Debug ) ]
1716pub struct ProjectiveNielsPoint {
1817 pub ( crate ) Y_plus_X : FieldElement ,
1918 pub ( crate ) Y_minus_X : FieldElement ,
@@ -46,9 +45,12 @@ impl ConditionallyNegatable for ProjectiveNielsPoint {
4645}
4746
4847impl ProjectiveNielsPoint {
49- pub fn identity ( ) -> ProjectiveNielsPoint {
50- ExtendedPoint :: IDENTITY . to_projective_niels ( )
51- }
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+ } ;
5254
5355 pub fn to_extensible ( self ) -> ExtensiblePoint {
5456 let A = self . Y_plus_X - self . Y_minus_X ;
@@ -65,6 +67,23 @@ impl ProjectiveNielsPoint {
6567#[ cfg( test) ]
6668mod tests {
6769 use super :: * ;
70+ use crate :: curve:: twedwards:: extended:: ExtendedPoint ;
71+
72+ #[ test]
73+ fn identity ( ) {
74+ // Internally are compared by converting to `ExtendedPoint`.
75+ // Here the right-side identity point is converted to Niel's
76+ // and then both sides are converted to twisted-curve form.
77+ assert_eq ! (
78+ ProjectiveNielsPoint :: IDENTITY ,
79+ ExtendedPoint :: IDENTITY . to_projective_niels( ) ,
80+ ) ;
81+ // Here only the left-side identity point is converted.
82+ assert_eq ! (
83+ ProjectiveNielsPoint :: IDENTITY . to_extensible( ) ,
84+ ExtendedPoint :: IDENTITY ,
85+ ) ;
86+ }
6887
6988 #[ test]
7089 fn test_conditional_negate ( ) {
0 commit comments