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