1
1
#![ allow( non_snake_case) ]
2
2
3
- use crate :: curve:: twedwards:: extended:: ExtendedPoint ;
4
3
use crate :: curve:: twedwards:: extensible:: ExtensiblePoint ;
5
4
use crate :: field:: FieldElement ;
6
5
use subtle:: { Choice , ConditionallyNegatable , ConditionallySelectable } ;
7
6
8
7
impl Default for ProjectiveNielsPoint {
9
8
fn default ( ) -> ProjectiveNielsPoint {
10
- ProjectiveNielsPoint :: identity ( )
9
+ ProjectiveNielsPoint :: IDENTITY
11
10
}
12
11
}
13
12
14
13
// Its a variant of Niels, where a Z coordinate is added for unmixed readdition
15
14
// ((y+x)/2, (y-x)/2, dxy, Z)
16
- #[ derive( Copy , Clone ) ]
15
+ #[ derive( Copy , Clone , Debug ) ]
17
16
pub struct ProjectiveNielsPoint {
18
17
pub ( crate ) Y_plus_X : FieldElement ,
19
18
pub ( crate ) Y_minus_X : FieldElement ,
@@ -46,9 +45,12 @@ impl ConditionallyNegatable for ProjectiveNielsPoint {
46
45
}
47
46
48
47
impl 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
+ } ;
52
54
53
55
pub fn to_extensible ( self ) -> ExtensiblePoint {
54
56
let A = self . Y_plus_X - self . Y_minus_X ;
@@ -65,6 +67,23 @@ impl ProjectiveNielsPoint {
65
67
#[ cfg( test) ]
66
68
mod tests {
67
69
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
+ }
68
87
69
88
#[ test]
70
89
fn test_conditional_negate ( ) {
0 commit comments