@@ -18,23 +18,23 @@ use core::fmt;
18
18
use core:: ops:: Mul ;
19
19
use subtle:: { Choice , ConditionallySelectable , ConstantTimeEq } ;
20
20
21
- impl MontgomeryPoint {
21
+ impl MontgomeryXpoint {
22
22
/// First low order point on Curve448 and it's twist
23
- pub const LOW_A : MontgomeryPoint = MontgomeryPoint ( [
23
+ pub const LOW_A : MontgomeryXpoint = MontgomeryXpoint ( [
24
24
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
25
25
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
26
26
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
27
27
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
28
28
] ) ;
29
29
/// Second low order point on Curve448 and it's twist
30
- pub const LOW_B : MontgomeryPoint = MontgomeryPoint ( [
30
+ pub const LOW_B : MontgomeryXpoint = MontgomeryXpoint ( [
31
31
0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
32
32
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
33
33
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
34
34
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
35
35
] ) ;
36
36
/// Third low order point on Curve448 and it's twist
37
- pub const LOW_C : MontgomeryPoint = MontgomeryPoint ( [
37
+ pub const LOW_C : MontgomeryXpoint = MontgomeryXpoint ( [
38
38
0xfe , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
39
39
0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xfe , 0xff ,
40
40
0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
@@ -44,51 +44,51 @@ impl MontgomeryPoint {
44
44
45
45
/// A point in Montgomery form
46
46
#[ derive( Copy , Clone ) ]
47
- pub struct MontgomeryPoint ( pub [ u8 ; 56 ] ) ;
47
+ pub struct MontgomeryXpoint ( pub [ u8 ; 56 ] ) ;
48
48
49
- impl Default for MontgomeryPoint {
50
- fn default ( ) -> MontgomeryPoint {
49
+ impl Default for MontgomeryXpoint {
50
+ fn default ( ) -> MontgomeryXpoint {
51
51
Self ( [ 0u8 ; 56 ] )
52
52
}
53
53
}
54
54
55
- impl elliptic_curve:: zeroize:: DefaultIsZeroes for MontgomeryPoint { }
55
+ impl elliptic_curve:: zeroize:: DefaultIsZeroes for MontgomeryXpoint { }
56
56
57
- impl fmt:: Debug for MontgomeryPoint {
57
+ impl fmt:: Debug for MontgomeryXpoint {
58
58
fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
59
59
self . 0 [ ..] . fmt ( formatter)
60
60
}
61
61
}
62
62
63
- impl ConstantTimeEq for MontgomeryPoint {
64
- fn ct_eq ( & self , other : & MontgomeryPoint ) -> Choice {
63
+ impl ConstantTimeEq for MontgomeryXpoint {
64
+ fn ct_eq ( & self , other : & MontgomeryXpoint ) -> Choice {
65
65
self . 0 . ct_eq ( & other. 0 )
66
66
}
67
67
}
68
68
69
- impl PartialEq for MontgomeryPoint {
70
- fn eq ( & self , other : & MontgomeryPoint ) -> bool {
69
+ impl PartialEq for MontgomeryXpoint {
70
+ fn eq ( & self , other : & MontgomeryXpoint ) -> bool {
71
71
self . ct_eq ( other) . into ( )
72
72
}
73
73
}
74
- impl Eq for MontgomeryPoint { }
74
+ impl Eq for MontgomeryXpoint { }
75
75
76
76
/// A Projective point in Montgomery form
77
77
#[ derive( Copy , Clone , Debug ) ]
78
- pub struct ProjectiveMontgomeryPoint {
78
+ pub struct ProjectiveMontgomeryXpoint {
79
79
U : FieldElement ,
80
80
W : FieldElement ,
81
81
}
82
82
83
- impl Mul < & EdwardsScalar > for & MontgomeryPoint {
84
- type Output = MontgomeryPoint ;
83
+ impl Mul < & EdwardsScalar > for & MontgomeryXpoint {
84
+ type Output = MontgomeryXpoint ;
85
85
86
86
#[ allow( clippy:: suspicious_arithmetic_impl) ]
87
- fn mul ( self , scalar : & EdwardsScalar ) -> MontgomeryPoint {
87
+ fn mul ( self , scalar : & EdwardsScalar ) -> MontgomeryXpoint {
88
88
// Algorithm 8 of Costello-Smith 2017
89
89
let affine_u = FieldElement :: from_bytes ( & self . 0 ) ;
90
- let mut x0 = ProjectiveMontgomeryPoint :: identity ( ) ;
91
- let mut x1 = ProjectiveMontgomeryPoint {
90
+ let mut x0 = ProjectiveMontgomeryXpoint :: identity ( ) ;
91
+ let mut x1 = ProjectiveMontgomeryXpoint {
92
92
U : affine_u,
93
93
W : FieldElement :: ONE ,
94
94
} ;
@@ -99,7 +99,7 @@ impl Mul<&EdwardsScalar> for &MontgomeryPoint {
99
99
let bit = bits[ s] as u8 ;
100
100
let choice: u8 = swap ^ bit;
101
101
102
- ProjectiveMontgomeryPoint :: conditional_swap ( & mut x0, & mut x1, Choice :: from ( choice) ) ;
102
+ ProjectiveMontgomeryXpoint :: conditional_swap ( & mut x0, & mut x1, Choice :: from ( choice) ) ;
103
103
differential_add_and_double ( & mut x0, & mut x1, & affine_u) ;
104
104
105
105
swap = bit;
@@ -109,15 +109,15 @@ impl Mul<&EdwardsScalar> for &MontgomeryPoint {
109
109
}
110
110
}
111
111
112
- impl Mul < & MontgomeryPoint > for & EdwardsScalar {
113
- type Output = MontgomeryPoint ;
112
+ impl Mul < & MontgomeryXpoint > for & EdwardsScalar {
113
+ type Output = MontgomeryXpoint ;
114
114
115
- fn mul ( self , point : & MontgomeryPoint ) -> MontgomeryPoint {
115
+ fn mul ( self , point : & MontgomeryXpoint ) -> MontgomeryXpoint {
116
116
point * self
117
117
}
118
118
}
119
119
120
- impl MontgomeryPoint {
120
+ impl MontgomeryXpoint {
121
121
/// Returns the generator specified in RFC7748
122
122
pub const GENERATOR : Self = Self ( [
123
123
0x05 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
@@ -144,30 +144,30 @@ impl MontgomeryPoint {
144
144
}
145
145
146
146
/// Convert the point to a ProjectiveMontgomeryPoint
147
- pub fn to_projective ( & self ) -> ProjectiveMontgomeryPoint {
148
- ProjectiveMontgomeryPoint {
147
+ pub fn to_projective ( & self ) -> ProjectiveMontgomeryXpoint {
148
+ ProjectiveMontgomeryXpoint {
149
149
U : FieldElement :: from_bytes ( & self . 0 ) ,
150
150
W : FieldElement :: ONE ,
151
151
}
152
152
}
153
153
}
154
154
155
- impl ConditionallySelectable for ProjectiveMontgomeryPoint {
155
+ impl ConditionallySelectable for ProjectiveMontgomeryXpoint {
156
156
fn conditional_select (
157
- a : & ProjectiveMontgomeryPoint ,
158
- b : & ProjectiveMontgomeryPoint ,
157
+ a : & ProjectiveMontgomeryXpoint ,
158
+ b : & ProjectiveMontgomeryXpoint ,
159
159
choice : Choice ,
160
- ) -> ProjectiveMontgomeryPoint {
161
- ProjectiveMontgomeryPoint {
160
+ ) -> ProjectiveMontgomeryXpoint {
161
+ ProjectiveMontgomeryXpoint {
162
162
U : FieldElement :: conditional_select ( & a. U , & b. U , choice) ,
163
163
W : FieldElement :: conditional_select ( & a. W , & b. W , choice) ,
164
164
}
165
165
}
166
166
}
167
167
168
168
fn differential_add_and_double (
169
- P : & mut ProjectiveMontgomeryPoint ,
170
- Q : & mut ProjectiveMontgomeryPoint ,
169
+ P : & mut ProjectiveMontgomeryXpoint ,
170
+ Q : & mut ProjectiveMontgomeryXpoint ,
171
171
affine_PmQ : & FieldElement ,
172
172
) {
173
173
let t0 = P . U + P . W ;
@@ -203,19 +203,19 @@ fn differential_add_and_double(
203
203
Q . W = t17; // W_{Q'} = U_D * 4 (W_P U_Q - U_P W_Q)^2
204
204
}
205
205
206
- impl ProjectiveMontgomeryPoint {
206
+ impl ProjectiveMontgomeryXpoint {
207
207
/// The identity element of the group: the point at infinity.
208
- pub fn identity ( ) -> ProjectiveMontgomeryPoint {
209
- ProjectiveMontgomeryPoint {
208
+ pub fn identity ( ) -> ProjectiveMontgomeryXpoint {
209
+ ProjectiveMontgomeryXpoint {
210
210
U : FieldElement :: ONE ,
211
211
W : FieldElement :: ZERO ,
212
212
}
213
213
}
214
214
215
215
/// Convert the point to affine form
216
- pub fn to_affine ( & self ) -> MontgomeryPoint {
216
+ pub fn to_affine ( & self ) -> MontgomeryXpoint {
217
217
let x = self . U * self . W . invert ( ) ;
218
- MontgomeryPoint ( x. to_bytes ( ) )
218
+ MontgomeryXpoint ( x. to_bytes ( ) )
219
219
}
220
220
}
221
221
@@ -230,11 +230,11 @@ mod tests {
230
230
use crate :: GOLDILOCKS_BASE_POINT as bp;
231
231
232
232
// Montgomery scalar mul
233
- let montgomery_bp = bp. to_montgomery ( ) ;
233
+ let montgomery_bp = bp. to_montgomery_x ( ) ;
234
234
let montgomery_res = & montgomery_bp * & scalar;
235
235
236
236
// Goldilocks scalar mul
237
237
let goldilocks_point = bp. scalar_mul ( & scalar) ;
238
- assert_eq ! ( goldilocks_point. to_montgomery ( ) , montgomery_res) ;
238
+ assert_eq ! ( goldilocks_point. to_montgomery_x ( ) , montgomery_res) ;
239
239
}
240
240
}
0 commit comments