@@ -34,30 +34,6 @@ impl<Fq: FqTrait> Curve<Fq> {
34
34
* Z *= V1 ;
35
35
}
36
36
37
- /// x-only doubling, set `R` to the value of \[2\]P
38
- #[ inline]
39
- fn set_xdouble ( self , xR : & mut PointX < Fq > ) {
40
- self . xdbl ( & mut xR. X , & mut xR. Z ) ;
41
- }
42
-
43
- /// Return the value [2]P
44
- #[ inline]
45
- fn xdouble ( self , xP : & PointX < Fq > ) -> PointX < Fq > {
46
- let mut xR = * xP;
47
- self . set_xdouble ( & mut xR) ;
48
- xR
49
- }
50
-
51
- /// Return the value [2^n]P
52
- #[ inline]
53
- fn xdouble_iter ( self , xP : & PointX < Fq > , n : usize ) -> PointX < Fq > {
54
- let mut xR = * xP;
55
- for _ in 0 ..n {
56
- self . set_xdouble ( & mut xR) ;
57
- }
58
- xR
59
- }
60
-
61
37
/// x-only differential formula Note: order of arguments:
62
38
/// (XPQ : ZPQ), (XP : ZP), (XQ : ZQ) For PQ = P - Q
63
39
/// Sets Q = P + Q in place
@@ -97,7 +73,7 @@ impl<Fq: FqTrait> Curve<Fq> {
97
73
* ZQ = * XPQ * ( V1 - V2 ) . square ( ) ;
98
74
}
99
75
100
- /// P3 <- n*P, X -only variant.
76
+ /// P3 <- n*P, x -only variant.
101
77
/// Integer n is encoded as unsigned little-endian, with length
102
78
/// nbitlen bits. Bits beyond that length are ignored.
103
79
pub fn xmul_into ( self , P3 : & mut PointX < Fq > , P : & PointX < Fq > , n : & [ u8 ] , nbitlen : usize ) {
@@ -153,7 +129,7 @@ impl<Fq: FqTrait> Curve<Fq> {
153
129
P3 . Z . set_cond ( & Fq :: ONE , spec) ;
154
130
}
155
131
156
- /// Return n*P as a new point (X -only variant).
132
+ /// Return n*P as a new point (x -only variant).
157
133
/// Integer n is encoded as unsigned little-endian, with length
158
134
/// nbitlen bits. Bits beyond that length are ignored.
159
135
pub fn xmul ( self , P : & PointX < Fq > , n : & [ u8 ] , nbitlen : usize ) -> PointX < Fq > {
@@ -162,8 +138,27 @@ impl<Fq: FqTrait> Curve<Fq> {
162
138
P3
163
139
}
164
140
165
- /// P3 <- (2^e)*P (X-only variant)
166
- fn xmul_2e_into ( self , P3 : & mut PointX < Fq > , P : & PointX < Fq > , e : usize ) {
141
+ /// P3 <- [2]*P (x-only variant)
142
+ fn xdouble_into ( self , P3 : & mut PointX < Fq > , P : & PointX < Fq > ) {
143
+ let mut V1 = ( P . X + P . Z ) . square ( ) ;
144
+ let V2 = ( P . X - P . Z ) . square ( ) ;
145
+ P3 . X = V1 * V2 ;
146
+ V1 -= V2 ;
147
+ P3 . Z = V1 ;
148
+ P3 . Z *= self . A24 ;
149
+ P3 . Z += V2 ;
150
+ P3 . Z *= V1 ;
151
+ }
152
+
153
+ /// Return [2]*P (x-only variant).
154
+ pub fn xdouble ( self , P : & PointX < Fq > ) -> PointX < Fq > {
155
+ let mut Q = PointX :: INFINITY ;
156
+ self . xdouble_into ( & mut Q , P ) ;
157
+ Q
158
+ }
159
+
160
+ /// P3 <- (2^e)*P (x-only variant)
161
+ fn xdouble_iter_into ( self , P3 : & mut PointX < Fq > , P : & PointX < Fq > , e : usize ) {
167
162
let mut X = P . X ;
168
163
let mut Z = P . Z ;
169
164
for _ in 0 ..e {
@@ -181,17 +176,17 @@ impl<Fq: FqTrait> Curve<Fq> {
181
176
}
182
177
183
178
/// Return (2^e)*P (x-only variant).
184
- pub fn xmul_2e ( self , P : & PointX < Fq > , e : usize ) -> PointX < Fq > {
179
+ pub fn xdouble_iter ( self , P : & PointX < Fq > , e : usize ) -> PointX < Fq > {
185
180
let mut Q = PointX :: INFINITY ;
186
- self . xmul_2e_into ( & mut Q , P , e) ;
181
+ self . xdouble_iter_into ( & mut Q , P , e) ;
187
182
Q
188
183
}
189
184
190
185
/// Return (2^e)*R for R in [P, Q, P - Q] (x-only variant).
191
- pub fn basis_xmul_2e ( self , B : & BasisX < Fq > , e : usize ) -> BasisX < Fq > {
192
- let P = self . xmul_2e ( & B . P , e) ;
193
- let Q = self . xmul_2e ( & B . Q , e) ;
194
- let PQ = self . xmul_2e ( & B . PQ , e) ;
186
+ pub fn basis_double_iter ( self , B : & BasisX < Fq > , e : usize ) -> BasisX < Fq > {
187
+ let P = self . xdouble_iter ( & B . P , e) ;
188
+ let Q = self . xdouble_iter ( & B . Q , e) ;
189
+ let PQ = self . xdouble_iter ( & B . PQ , e) ;
195
190
BasisX :: from_points ( & P , & Q , & PQ )
196
191
}
197
192
@@ -230,7 +225,7 @@ impl<Fq: FqTrait> Curve<Fq> {
230
225
* ZQ = ZPQ ;
231
226
}
232
227
233
- /// Return P + n*Q, X -only variant given the x-only basis x(P), x(Q) and x(P - Q).
228
+ /// Return P + n*Q, x -only variant given the x-only basis x(P), x(Q) and x(P - Q).
234
229
/// Integer `n` is encoded as unsigned little-endian, with length `nbitlen` bits.
235
230
/// Bits beyond that length are ignored.
236
231
pub fn three_point_ladder ( self , B : & BasisX < Fq > , n : & [ u8 ] , nbitlen : usize ) -> PointX < Fq > {
@@ -308,7 +303,7 @@ impl<Fq: FqTrait> Curve<Fq> {
308
303
( ( s0 & 1 ) as usize , ( s1 & 1 ) as usize , r)
309
304
}
310
305
311
- /// Return [a]P + [b]*Q, X -only variant given the x-only basis x(P), x(Q) and x(P - Q).
306
+ /// Return [a]P + [b]*Q, x -only variant given the x-only basis x(P), x(Q) and x(P - Q).
312
307
/// The integers `a` and `b` are encoded as unsigned little-endian.
313
308
pub fn ladder_biscalar (
314
309
self ,
0 commit comments