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