Line data Source code
1 : #include "fd_curve25519.h"
2 : #include "../hex/fd_hex.h"
3 :
4 : /*
5 : * Secure implementations (const time + clean temp vars)
6 : */
7 : #include "fd_curve25519_secure.c"
8 :
9 : #if FD_HAS_AVX512
10 : #include "avx512/fd_curve25519.c"
11 : #else
12 : #include "ref/fd_curve25519.c"
13 : #endif
14 :
15 8127216 : #define WNAF_BIT_SZ 4
16 7224192 : #define WNAF_TBL_SZ (2*WNAF_BIT_SZ)
17 :
18 : /*
19 : * Ser/de
20 : */
21 :
22 : void
23 : fd_ed25519_debug( char const * name,
24 0 : fd_ed25519_point_t const * a ) {
25 0 : fd_f25519_t x[1], y[1], z[1], t[1];
26 0 : fd_ed25519_point_to( x, y, z, t, a );
27 0 : FD_LOG_WARNING(( "%s", name ));
28 0 : fd_f25519_debug( "x", x );
29 0 : fd_f25519_debug( "y", y );
30 0 : fd_f25519_debug( "z", z );
31 0 : fd_f25519_debug( "t", t );
32 0 : }
33 :
34 : fd_ed25519_point_t *
35 : fd_ed25519_point_frombytes( fd_ed25519_point_t * r,
36 5634176 : uchar const buf[ 32 ] ) {
37 5634176 : fd_f25519_t x[1], y[1], t[1];
38 5634176 : fd_f25519_frombytes( y, buf );
39 5634176 : uchar expected_x_sign = buf[31] >> 7;
40 :
41 5634176 : fd_f25519_t u[1];
42 5634176 : fd_f25519_t v[1];
43 5634176 : fd_f25519_sqr( u, y );
44 5634176 : fd_f25519_mul( v, u, fd_f25519_d );
45 5634176 : fd_f25519_sub( u, u, fd_f25519_one ); /* u = y^2-1 */
46 5634176 : fd_f25519_add( v, v, fd_f25519_one ); /* v = dy^2+1 */
47 :
48 5634176 : int was_square = fd_f25519_sqrt_ratio( x, u, v );
49 5634176 : if( FD_UNLIKELY( !was_square ) ) {
50 586352 : return NULL;
51 586352 : }
52 :
53 : /* Note: RFC 8032 Section 5.1.3 says "if x=0 and x_0=1, decoding
54 : fails", but Dalek does not enforce this — neg(0)==0 so it silently
55 : accepts the point. We match Dalek for compatibility.
56 : https://github.com/dalek-cryptography/curve25519-dalek/blob/curve25519-4.1.3/curve25519-dalek/src/edwards.rs#L194-L240
57 : https://github.com/dalek-cryptography/curve25519-dalek/blob/3.2.1/src/edwards.rs#L193-L209 */
58 5047824 : if( fd_f25519_sgn(x)!=expected_x_sign ) { /* 50% prob */
59 2423390 : fd_f25519_neg( x, x );
60 2423390 : }
61 :
62 5047824 : fd_f25519_mul( t, x, y );
63 5047824 : fd_ed25519_point_from( r, x, y, fd_f25519_one, t );
64 :
65 5047824 : return r;
66 5634176 : }
67 :
68 : /* fd_ed25519_point_frombytes (like Dalek's decompress) takes y mod p
69 : (non-canonical y accepted), ignores the sign bit for validity (x=0
70 : with sign 1 is accepted) and succeeds iff u/v is a square or zero,
71 : with u=y^2-1 and v=d*y^2+1. v is never 0 as d is a non-square and -1
72 : is a square, so this is the same as u*v being a square or zero, which
73 : a Jacobi symbol decides much faster than a square root. */
74 : int
75 700818 : fd_ed25519_point_validate( uchar const buf[ 32 ] ) {
76 700818 : fd_f25519_t y[1], u[1], v[1];
77 700818 : fd_f25519_frombytes( y, buf );
78 700818 : fd_f25519_sqr( u, y );
79 700818 : fd_f25519_mul( v, u, fd_f25519_d );
80 700818 : fd_f25519_sub( u, u, fd_f25519_one ); /* u = y^2-1 */
81 700818 : fd_f25519_add( v, v, fd_f25519_one ); /* v = dy^2+1 */
82 700818 : fd_f25519_mul( u, u, v );
83 700818 : return fd_f25519_is_square_var( u );
84 700818 : }
85 :
86 : uchar *
87 : fd_ed25519_point_tobytes_batch8( uchar out[], /* 32*n */
88 : fd_ed25519_point_t const * pt, /* n */
89 14 : ulong n ) { /* in [1,8] */
90 14 : FD_TEST( 0UL<n && n<=8UL );
91 :
92 14 : fd_f25519_t x[8], y[8], z[8], t[1];
93 84 : for( ulong i=0UL; i<n; i++ ) fd_ed25519_point_to( &x[i], &y[i], &z[i], t, &pt[i] );
94 :
95 : /* batch inv */
96 :
97 14 : fd_f25519_t c[8], iz[8], u[1];
98 14 : c[0] = z[0];
99 70 : for( ulong i=1UL; i<n; i++ ) fd_f25519_mul( &c[i], &c[i-1], &z[i] );
100 14 : fd_f25519_inv( u, &c[n-1UL] );
101 70 : for( ulong i=n-1UL; i>0UL; i-- ) {
102 56 : fd_f25519_mul( &iz[i], u, &c[i-1] );
103 56 : fd_f25519_mul( u, u, &z[i] );
104 56 : }
105 14 : iz[0] = *u;
106 :
107 14 : ulong i=0UL;
108 46 : for( ; i+2UL<=n; i+=2UL ) fd_f25519_mul4( &x[i ], &x[i ], &iz[i ],
109 32 : &y[i ], &y[i ], &iz[i ],
110 32 : &x[i+1], &x[i+1], &iz[i+1],
111 32 : &y[i+1], &y[i+1], &iz[i+1] );
112 14 : if( i<n ) fd_f25519_mul2( &x[i], &x[i], &iz[i],
113 6 : &y[i], &y[i], &iz[i] );
114 :
115 84 : for( ulong j=0UL; j<n; j++ ) {
116 70 : fd_f25519_tobytes( out+32UL*j, &y[j] );
117 70 : out[ 32UL*j+31UL ] ^= (uchar)(fd_f25519_sgn( &x[j] ) << 7);
118 70 : }
119 14 : return out;
120 14 : }
121 :
122 : uchar *
123 : fd_ed25519_point_tobytes( uchar out[ 32 ],
124 84523 : fd_ed25519_point_t const * a ) {
125 : /* equivalent to: return fd_ed25519_point_tobytes_batch8( out, a, 1UL ) */
126 84523 : fd_f25519_t x[1], y[1], z[1], t[1];
127 84523 : fd_ed25519_point_to( x, y, z, t, a );
128 84523 : fd_f25519_inv( t, z );
129 84523 : fd_f25519_mul2( x, x, t,
130 84523 : y, y, t );
131 84523 : fd_f25519_tobytes( out, y );
132 84523 : out[31] ^= (uchar)(fd_f25519_sgn( x ) << 7);
133 84523 : return out;
134 84523 : }
135 :
136 : /*
137 : * Scalar multiplication
138 : */
139 :
140 : fd_ed25519_point_t *
141 : fd_ed25519_scalar_mul( fd_ed25519_point_t * r,
142 : uchar const n[ 32 ],
143 30024 : fd_ed25519_point_t const * a ) {
144 30024 : short nslide[256];
145 30024 : fd_curve25519_scalar_wnaf( nslide, n, WNAF_BIT_SZ );
146 :
147 30024 : fd_ed25519_point_t ai[WNAF_TBL_SZ]; /* A,3A,5A,7A,9A,11A,13A,15A */
148 30024 : fd_ed25519_point_t a2[1]; /* 2A (temp) */
149 30024 : fd_ed25519_point_t t[1];
150 :
151 : /* pre-computed table */
152 30024 : fd_ed25519_point_set( &ai[0], a );
153 30024 : fd_ed25519_point_dbln( a2, a, 1 ); // note: a is affine, we could save 1mul
154 30024 : fd_curve25519_into_precomputed( &ai[0] );
155 240192 : for( int i=1; i<WNAF_TBL_SZ; i++ ) {
156 210168 : fd_ed25519_point_add_with_opts( t, a2, &ai[i-1], i==1, 1, 1 );
157 210168 : fd_ed25519_point_add_final_mul( &ai[i], t );
158 : /* pre-compute kT, to save 1mul during the loop */
159 210168 : fd_curve25519_into_precomputed( &ai[i] );
160 210168 : }
161 :
162 : /* main dbl-and-add loop. note: last iter unrolled */
163 30024 : fd_ed25519_point_set_zero( r );
164 30024 : int i;
165 121686 : for( i=255; i>=0; i-- ) { if( nslide[i] ) break; }
166 7624506 : for( ; i>=0; i-- ) {
167 7594482 : fd_ed25519_partial_dbl( t, r );
168 7594482 : if( nslide[i] > 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_add_with_opts( t, r, &ai[ nslide[i] / 2], nslide[i]==1, 1, 1 ); }
169 7294194 : else if( nslide[i] < 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_sub_with_opts( t, r, &ai[(-nslide[i]) / 2], nslide[i]==-1, 1, 1 ); }
170 :
171 : /* ignore r->T because dbl doesn't need it, except in the last cycle */
172 7594482 : if (i == 0) {
173 30024 : fd_ed25519_point_add_final_mul( r, t ); // compute r->T
174 7564458 : } else {
175 7564458 : fd_ed25519_point_add_final_mul_projective( r, t ); // ignore r->T
176 7564458 : }
177 7594482 : }
178 30024 : return r;
179 30024 : }
180 :
181 : fd_ed25519_point_t *
182 : fd_ed25519_double_scalar_mul_base( fd_ed25519_point_t * r,
183 : uchar const n1[ 32 ],
184 : fd_ed25519_point_t const * a,
185 695868 : uchar const n2[ 32 ] ) {
186 :
187 695868 : short n1slide[256]; fd_curve25519_scalar_wnaf( n1slide, n1, WNAF_BIT_SZ );
188 695868 : short n2slide[256]; fd_curve25519_scalar_wnaf( n2slide, n2, 8 );
189 :
190 695868 : fd_ed25519_point_t ai[WNAF_TBL_SZ]; /* A,3A,5A,7A,9A,11A,13A,15A */
191 695868 : fd_ed25519_point_t a2[1]; /* 2A (temp) */
192 695868 : fd_ed25519_point_t t[1];
193 :
194 : /* pre-computed table */
195 695868 : fd_ed25519_point_set( &ai[0], a );
196 695868 : fd_ed25519_point_dbln( a2, a, 1 ); // note: a is affine, we could save 1mul
197 695868 : fd_curve25519_into_precomputed( &ai[0] );
198 5566944 : for( int i=1; i<WNAF_TBL_SZ; i++ ) {
199 4871076 : fd_ed25519_point_add_with_opts( t, a2, &ai[i-1], i==1, 1, 1 );
200 4871076 : fd_ed25519_point_add_final_mul( &ai[i], t );
201 : /* pre-compute kT, to save 1mul during the loop */
202 4871076 : fd_curve25519_into_precomputed( &ai[i] );
203 4871076 : }
204 :
205 : /* main dbl-and-add loop */
206 695868 : fd_ed25519_point_set_zero( r );
207 :
208 695868 : int i;
209 4209022 : for( i=255; i>=0; i-- ) { if( n1slide[i] || n2slide[i] ) break; }
210 175324922 : for( ; i>=0; i-- ) {
211 174629054 : fd_ed25519_partial_dbl( t, r );
212 174629054 : if( n1slide[i] > 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_add_with_opts( t, r, &ai[ n1slide[i] / 2], n1slide[i]==1, 1, 1 ); }
213 160178575 : else if( n1slide[i] < 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_sub_with_opts( t, r, &ai[(-n1slide[i]) / 2], n1slide[i]==-1, 1, 1 ); }
214 174629054 : if( n2slide[i] > 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_add_with_opts( t, r, &fd_ed25519_base_point_wnaf_table[ n2slide[i] / 2], 1, 1, 1 ); }
215 165387419 : else if( n2slide[i] < 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_sub_with_opts( t, r, &fd_ed25519_base_point_wnaf_table[(-n2slide[i]) / 2], 1, 1, 1 ); }
216 :
217 : /* ignore r->T because dbl doesn't need it, except in the last cycle */
218 174629054 : if (i == 0) {
219 695790 : fd_ed25519_point_add_final_mul( r, t ); // compute r->T
220 173933264 : } else {
221 173933264 : fd_ed25519_point_add_final_mul_projective( r, t ); // ignore r->T
222 173933264 : }
223 174629054 : }
224 695868 : return r;
225 695868 : }
226 :
227 :
228 : /* split_odd_table fills tbl[0,n) with p,3p,..,(2n-1)p in precomputed
229 : form. */
230 :
231 : static void
232 : split_odd_table( fd_ed25519_point_t * tbl,
233 : fd_ed25519_point_t const * p,
234 101980 : int n ) {
235 101980 : fd_ed25519_point_t p2[1];
236 101980 : fd_ed25519_point_set( &tbl[0], p );
237 101980 : fd_ed25519_point_dbln( p2, p, 1 );
238 564160 : for( int i=1; i<n; i++ ) fd_ed25519_point_add( &tbl[i], p2, &tbl[i-1] );
239 666140 : for( int i=0; i<n; i++ ) fd_curve25519_into_precomputed( &tbl[i] );
240 101980 : }
241 :
242 : void
243 : fd_ed25519_split_table_a( fd_ed25519_point_t tbl[ FD_ED25519_SPLIT_A_TBL_CNT ],
244 12590 : fd_ed25519_point_t const * a ) {
245 12590 : fd_ed25519_point_t p[1];
246 12590 : fd_ed25519_point_set( p, a );
247 113310 : for( int j=0; j<FD_ED25519_SPLIT_SEG_CNT; j++ ) {
248 100720 : if( j ) fd_ed25519_point_dbln( p, p, FD_ED25519_SPLIT_SEG_BITS );
249 100720 : split_odd_table( tbl+FD_ED25519_SPLIT_A_SEG_CNT*j, p, FD_ED25519_SPLIT_A_SEG_CNT );
250 100720 : }
251 12590 : }
252 :
253 : void
254 180 : fd_ed25519_split_table_b( fd_ed25519_point_t tbl[ FD_ED25519_SPLIT_B_TBL_CNT ] ) {
255 180 : fd_ed25519_point_t p[1];
256 180 : fd_ed25519_point_set( p, fd_ed25519_base_point );
257 1440 : for( int j=1; j<FD_ED25519_SPLIT_SEG_CNT; j++ ) {
258 1260 : fd_ed25519_point_dbln( p, p, FD_ED25519_SPLIT_SEG_BITS );
259 1260 : split_odd_table( tbl+128*(j-1), p, 128 );
260 1260 : }
261 180 : }
262 :
263 : /* double_scalar_mul_base_split also advances dec (if non-NULL) by
264 : DEC_STEP chain ops after each point op (3 measured best). */
265 :
266 33045528 : #define DEC_STEP (3UL)
267 :
268 : static inline fd_ed25519_point_t *
269 : double_scalar_mul_base_split( fd_ed25519_point_t * r,
270 : uchar const n1[ 32 ],
271 : fd_ed25519_point_t const * a_tbl,
272 : uchar const n2[ 32 ],
273 : fd_ed25519_point_t const * b_tbl,
274 314229 : fd_ed25519_point_decode_t * dec ) {
275 :
276 : /* Digit d at position b*j+i contributes [d 2^i][2^(b*j)]P, so the
277 : segments of each wNAF share a single b doubling loop. */
278 :
279 314229 : short n1slide[256]; fd_curve25519_scalar_wnaf( n1slide, n1, FD_ED25519_SPLIT_A_BITS );
280 314229 : short n2slide[256]; fd_curve25519_scalar_wnaf( n2slide, n2, 8 );
281 :
282 314229 : fd_ed25519_point_t const * bt[ FD_ED25519_SPLIT_SEG_CNT ];
283 314229 : bt[0] = fd_ed25519_base_point_wnaf_table;
284 2513832 : for( int j=1; j<FD_ED25519_SPLIT_SEG_CNT; j++ ) bt[j] = b_tbl + 128*(j-1);
285 314229 : fd_ed25519_point_t t[1];
286 :
287 314229 : fd_ed25519_point_set_zero( r );
288 :
289 314229 : int i;
290 357834 : for( i=FD_ED25519_SPLIT_SEG_BITS-1; i>=0; i-- ) {
291 357486 : short nz = 0;
292 3217374 : for( int j=0; j<FD_ED25519_SPLIT_SEG_CNT; j++ ) nz |= n1slide[ FD_ED25519_SPLIT_SEG_BITS*j+i ] | n2slide[ FD_ED25519_SPLIT_SEG_BITS*j+i ];
293 357486 : if( nz ) break;
294 357486 : }
295 10325952 : for( ; i>=0; i-- ) {
296 10011723 : fd_ed25519_partial_dbl( t, r );
297 10011723 : if( dec ) fd_ed25519_point_decode_step( dec, DEC_STEP );
298 90105507 : for( int j=0; j<FD_ED25519_SPLIT_SEG_CNT; j++ ) {
299 80093784 : short d1 = n1slide[ FD_ED25519_SPLIT_SEG_BITS*j+i ];
300 80093784 : short d2 = n2slide[ FD_ED25519_SPLIT_SEG_BITS*j+i ];
301 80093784 : if( d1 > 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_add_with_opts( t, r, &a_tbl[ FD_ED25519_SPLIT_A_SEG_CNT*j + d1/2 ], 0, 1, 1 ); if( dec ) fd_ed25519_point_decode_step( dec, DEC_STEP ); }
302 71957035 : else if( d1 < 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_sub_with_opts( t, r, &a_tbl[ FD_ED25519_SPLIT_A_SEG_CNT*j + (-d1)/2 ], 0, 1, 1 ); if( dec ) fd_ed25519_point_decode_step( dec, DEC_STEP ); }
303 80093784 : if( d2 > 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_add_with_opts( t, r, &bt[j][ d2/2 ], j==0, 1, 1 ); if( dec ) fd_ed25519_point_decode_step( dec, DEC_STEP ); }
304 75983515 : else if( d2 < 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_sub_with_opts( t, r, &bt[j][ (-d2)/2 ], j==0, 1, 1 ); if( dec ) fd_ed25519_point_decode_step( dec, DEC_STEP ); }
305 80093784 : }
306 :
307 : /* ignore r->T because dbl doesn't need it, except in the last cycle */
308 10011723 : if( i==0 ) fd_ed25519_point_add_final_mul( r, t );
309 9697842 : else fd_ed25519_point_add_final_mul_projective( r, t );
310 10011723 : }
311 314229 : return r;
312 314229 : }
313 :
314 : fd_ed25519_point_t *
315 : fd_ed25519_double_scalar_mul_base_split( fd_ed25519_point_t * r,
316 : uchar const n1[ 32 ],
317 : fd_ed25519_point_t const * a_tbl,
318 : uchar const n2[ 32 ],
319 7500 : fd_ed25519_point_t const * b_tbl ) {
320 7500 : return double_scalar_mul_base_split( r, n1, a_tbl, n2, b_tbl, NULL );
321 7500 : }
322 :
323 : fd_ed25519_point_t *
324 : fd_ed25519_double_scalar_mul_base_split_decode( fd_ed25519_point_t * r,
325 : uchar const n1[ 32 ],
326 : fd_ed25519_point_t const * a_tbl,
327 : uchar const n2[ 32 ],
328 : fd_ed25519_point_t const * b_tbl,
329 306729 : fd_ed25519_point_decode_t * dec ) {
330 306729 : return double_scalar_mul_base_split( r, n1, a_tbl, n2, b_tbl, dec );
331 306729 : }
332 :
333 : FD_25519_INLINE fd_ed25519_point_t *
334 : fd_ed25519_multi_scalar_mul_with_opts( fd_ed25519_point_t * r,
335 : uchar const n[], /* sz * 32 */
336 : fd_ed25519_point_t const a[], /* sz */
337 : ulong const sz,
338 5559 : ulong const base_sz ) {
339 5559 : short nslide[FD_BALLET_CURVE25519_MSM_BATCH_SZ][256];
340 5559 : fd_ed25519_point_t ai[FD_BALLET_CURVE25519_MSM_BATCH_SZ][WNAF_TBL_SZ]; /* A,3A,5A,7A,9A,11A,13A,15A */
341 5559 : fd_ed25519_point_t a2[1]; /* 2A (temp) */
342 5559 : fd_ed25519_point_t t[1]; /* temp */
343 :
344 5559 : if( base_sz ) {
345 0 : fd_curve25519_scalar_wnaf( nslide[0], &n[32*0], 8 );
346 0 : }
347 182691 : for( ulong j=base_sz; j<sz; j++ ) {
348 177132 : fd_curve25519_scalar_wnaf( nslide[j], &n[32*j], WNAF_BIT_SZ );
349 :
350 : /* pre-computed table */
351 177132 : fd_ed25519_point_set( &ai[j][0], &a[j] );
352 177132 : fd_ed25519_point_dbln( a2, &a[j], 1 ); // note: a is affine, we could save 1mul
353 177132 : fd_curve25519_into_precomputed( &ai[j][0] );
354 1417056 : for( int i=1; i<WNAF_TBL_SZ; i++ ) {
355 1239924 : fd_ed25519_point_add_with_opts( t, a2, &ai[j][i-1], i==1, 1, 1 );
356 1239924 : fd_ed25519_point_add_final_mul( &ai[j][i], t );
357 : /* pre-compute kT, to save 1mul during the loop */
358 1239924 : fd_curve25519_into_precomputed( &ai[j][i] );
359 1239924 : }
360 177132 : }
361 :
362 : /* main dbl-and-add loop */
363 5559 : fd_ed25519_point_set_zero( r );
364 1428663 : for( int i=255; i>=0; i-- ) {
365 1423104 : fd_ed25519_partial_dbl( t, r );
366 1423104 : if( base_sz ) {
367 0 : if( nslide[0][i] > 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_add_with_opts( t, r, &fd_ed25519_base_point_wnaf_table[ nslide[0][i] / 2], 1, 1, 1 ); }
368 0 : else if( nslide[0][i] < 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_sub_with_opts( t, r, &fd_ed25519_base_point_wnaf_table[(-nslide[0][i]) / 2], 1, 1, 1 ); }
369 0 : }
370 46768896 : for( ulong j=base_sz; j<sz; j++ ) {
371 45345792 : short n = nslide[j][i];
372 45345792 : if( n > 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_add_with_opts( t, r, &ai[j][ n / 2], (n==1), 1, 1 ); }
373 41551481 : else if( n < 0 ) { fd_ed25519_point_add_final_mul( r, t ); fd_ed25519_point_sub_with_opts( t, r, &ai[j][(-n) / 2], (n==-1), 1, 1 ); }
374 45345792 : }
375 :
376 : /* ignore r->T because dbl doesn't need it, except in the last cycle */
377 1423104 : if (i == 0) {
378 5559 : fd_ed25519_point_add_final_mul( r, t ); // compute r->T
379 1417545 : } else {
380 1417545 : fd_ed25519_point_add_final_mul_projective( r, t ); // ignore r->T
381 1417545 : }
382 1423104 : }
383 5559 : return r;
384 5559 : }
385 :
386 : fd_ed25519_point_t *
387 : fd_ed25519_multi_scalar_mul( fd_ed25519_point_t * r,
388 : uchar const n[], /* sz * 32 */
389 : fd_ed25519_point_t const a[], /* sz */
390 1869 : ulong const sz ) {
391 :
392 1869 : fd_ed25519_point_t h[1];
393 1869 : fd_ed25519_point_set_zero( r );
394 :
395 7428 : for( ulong i=0; i<sz; i+=FD_BALLET_CURVE25519_MSM_BATCH_SZ ) {
396 5559 : ulong batch_sz = fd_ulong_min(sz-i, FD_BALLET_CURVE25519_MSM_BATCH_SZ);
397 :
398 5559 : fd_ed25519_multi_scalar_mul_with_opts( h, &n[ 32*i ], &a[ i ], batch_sz, 0 );
399 5559 : fd_ed25519_point_add( r, r, h );
400 5559 : }
401 :
402 1869 : return r;
403 1869 : }
404 :
405 : /*
406 : * Init
407 : */
408 :
409 : fd_ed25519_point_t *
410 : fd_curve25519_affine_add( fd_ed25519_point_t * r,
411 : fd_ed25519_point_t const * a,
412 0 : fd_ed25519_point_t const * b ) {
413 0 : fd_ed25519_point_add_with_opts( r, a, b, 1, 0, 0 );
414 0 : return fd_curve25519_into_affine( r );
415 0 : }
416 :
417 : fd_ed25519_point_t *
418 : fd_curve25519_affine_dbln( fd_ed25519_point_t * r,
419 : fd_ed25519_point_t const * a,
420 0 : int const n ) {
421 0 : fd_ed25519_point_dbln( r, a, n );
422 0 : return fd_curve25519_into_affine( r );
423 0 : }
|