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