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