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