@@ -219,7 +219,6 @@ struct secp256k1_strauss_point_state {
219
219
int wnaf_na_lam [129 ];
220
220
int bits_na_1 ;
221
221
int bits_na_lam ;
222
- size_t input_pos ;
223
222
};
224
223
225
224
struct secp256k1_strauss_state {
@@ -243,12 +242,13 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
243
242
size_t np ;
244
243
size_t no = 0 ;
245
244
245
+ secp256k1_fe_set_int (& Z , 1 );
246
246
for (np = 0 ; np < num ; ++ np ) {
247
+ secp256k1_gej tmp ;
247
248
secp256k1_scalar na_1 , na_lam ;
248
249
if (secp256k1_scalar_is_zero (& na [np ]) || secp256k1_gej_is_infinity (& a [np ])) {
249
250
continue ;
250
251
}
251
- state -> ps [no ].input_pos = np ;
252
252
/* split na into na_1 and na_lam (where na = na_1 + na_lam*lambda, and na_1 and na_lam are ~128 bit) */
253
253
secp256k1_scalar_split_lambda (& na_1 , & na_lam , & na [np ]);
254
254
@@ -263,37 +263,33 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
263
263
if (state -> ps [no ].bits_na_lam > bits ) {
264
264
bits = state -> ps [no ].bits_na_lam ;
265
265
}
266
- ++ no ;
267
- }
268
266
269
- /* Calculate odd multiples of a.
270
- * All multiples are brought to the same Z 'denominator', which is stored
271
- * in Z. Due to secp256k1' isomorphism we can do all operations pretending
272
- * that the Z coordinate was 1, use affine addition formulae, and correct
273
- * the Z coordinate of the result once at the end.
274
- * The exception is the precomputed G table points, which are actually
275
- * affine. Compared to the base used for other points, they have a Z ratio
276
- * of 1/Z, so we can use secp256k1_gej_add_zinv_var, which uses the same
277
- * isomorphism to efficiently add with a known Z inverse.
278
- */
279
- if (no > 0 ) {
280
- /* Compute the odd multiples in Jacobian form. */
281
- secp256k1_ecmult_odd_multiples_table (ECMULT_TABLE_SIZE (WINDOW_A ), state -> pre_a , state -> aux , & Z , & a [state -> ps [0 ].input_pos ]);
282
- for (np = 1 ; np < no ; ++ np ) {
283
- secp256k1_gej tmp = a [state -> ps [np ].input_pos ];
267
+ /* Calculate odd multiples of a.
268
+ * All multiples are brought to the same Z 'denominator', which is stored
269
+ * in Z. Due to secp256k1' isomorphism we can do all operations pretending
270
+ * that the Z coordinate was 1, use affine addition formulae, and correct
271
+ * the Z coordinate of the result once at the end.
272
+ * The exception is the precomputed G table points, which are actually
273
+ * affine. Compared to the base used for other points, they have a Z ratio
274
+ * of 1/Z, so we can use secp256k1_gej_add_zinv_var, which uses the same
275
+ * isomorphism to efficiently add with a known Z inverse.
276
+ */
277
+ tmp = a [np ];
278
+ if (no ) {
284
279
#ifdef VERIFY
285
280
secp256k1_fe_normalize_var (& Z );
286
281
#endif
287
282
secp256k1_gej_rescale (& tmp , & Z );
288
- secp256k1_ecmult_odd_multiples_table (ECMULT_TABLE_SIZE (WINDOW_A ), state -> pre_a + np * ECMULT_TABLE_SIZE (WINDOW_A ), state -> aux + np * ECMULT_TABLE_SIZE (WINDOW_A ), & Z , & tmp );
289
- secp256k1_fe_mul (state -> aux + np * ECMULT_TABLE_SIZE (WINDOW_A ), state -> aux + np * ECMULT_TABLE_SIZE (WINDOW_A ), & (a [state -> ps [np ].input_pos ].z ));
290
283
}
291
- /* Bring them to the same Z denominator. */
292
- secp256k1_ge_globalz_fixup_table ( ECMULT_TABLE_SIZE ( WINDOW_A ) * no , state -> pre_a , state -> aux );
293
- } else {
294
- secp256k1_fe_set_int ( & Z , 1 ) ;
284
+ secp256k1_ecmult_odd_multiples_table ( ECMULT_TABLE_SIZE ( WINDOW_A ), state -> pre_a + no * ECMULT_TABLE_SIZE ( WINDOW_A ), state -> aux + no * ECMULT_TABLE_SIZE ( WINDOW_A ), & Z , & tmp );
285
+ if ( no ) secp256k1_fe_mul ( state -> aux + no * ECMULT_TABLE_SIZE ( WINDOW_A ) , state -> aux + no * ECMULT_TABLE_SIZE ( WINDOW_A ), & ( a [ np ]. z ) );
286
+
287
+ ++ no ;
295
288
}
296
289
290
+ /* Bring them to the same Z denominator. */
291
+ secp256k1_ge_globalz_fixup_table (ECMULT_TABLE_SIZE (WINDOW_A ) * no , state -> pre_a , state -> aux );
292
+
297
293
for (np = 0 ; np < no ; ++ np ) {
298
294
for (i = 0 ; i < ECMULT_TABLE_SIZE (WINDOW_A ); i ++ ) {
299
295
secp256k1_fe_mul (& state -> aux [np * ECMULT_TABLE_SIZE (WINDOW_A ) + i ], & state -> pre_a [np * ECMULT_TABLE_SIZE (WINDOW_A ) + i ].x , & secp256k1_const_beta );
0 commit comments