@@ -446,7 +446,6 @@ struct secp256k1_strauss_point_state {
446
446
int wnaf_na_lam [129 ];
447
447
int bits_na_1 ;
448
448
int bits_na_lam ;
449
- size_t input_pos ;
450
449
};
451
450
452
451
struct secp256k1_strauss_state {
@@ -470,12 +469,13 @@ static void secp256k1_ecmult_strauss_wnaf(const secp256k1_ecmult_context *ctx, c
470
469
size_t np ;
471
470
size_t no = 0 ;
472
471
472
+ secp256k1_fe_set_int (& Z , 1 );
473
473
for (np = 0 ; np < num ; ++ np ) {
474
+ secp256k1_gej tmp ;
474
475
secp256k1_scalar na_1 , na_lam ;
475
476
if (secp256k1_scalar_is_zero (& na [np ]) || secp256k1_gej_is_infinity (& a [np ])) {
476
477
continue ;
477
478
}
478
- state -> ps [no ].input_pos = np ;
479
479
/* split na into na_1 and na_lam (where na = na_1 + na_lam*lambda, and na_1 and na_lam are ~128 bit) */
480
480
secp256k1_scalar_split_lambda (& na_1 , & na_lam , & na [np ]);
481
481
@@ -490,40 +490,34 @@ static void secp256k1_ecmult_strauss_wnaf(const secp256k1_ecmult_context *ctx, c
490
490
if (state -> ps [no ].bits_na_lam > bits ) {
491
491
bits = state -> ps [no ].bits_na_lam ;
492
492
}
493
- ++ no ;
494
- }
495
493
496
- /* Calculate odd multiples of a.
497
- * All multiples are brought to the same Z 'denominator', which is stored
498
- * in Z. Due to secp256k1' isomorphism we can do all operations pretending
499
- * that the Z coordinate was 1, use affine addition formulae, and correct
500
- * the Z coordinate of the result once at the end.
501
- * The exception is the precomputed G table points, which are actually
502
- * affine. Compared to the base used for other points, they have a Z ratio
503
- * of 1/Z, so we can use secp256k1_gej_add_zinv_var, which uses the same
504
- * isomorphism to efficiently add with a known Z inverse.
505
- */
506
- if (no > 0 ) {
507
- /* Compute the odd multiples in Jacobian form. */
508
- secp256k1_gej tmp = a [state -> ps [0 ].input_pos ];
509
- secp256k1_ecmult_odd_multiples_table (ECMULT_TABLE_SIZE (WINDOW_A ), state -> pre_a , state -> aux , & tmp );
510
- for (np = 1 ; np < no ; ++ np ) {
511
- Z = tmp .z ;
512
- tmp = a [state -> ps [np ].input_pos ];
494
+ /* Calculate odd multiples of a.
495
+ * All multiples are brought to the same Z 'denominator', which is stored
496
+ * in Z. Due to secp256k1' isomorphism we can do all operations pretending
497
+ * that the Z coordinate was 1, use affine addition formulae, and correct
498
+ * the Z coordinate of the result once at the end.
499
+ * The exception is the precomputed G table points, which are actually
500
+ * affine. Compared to the base used for other points, they have a Z ratio
501
+ * of 1/Z, so we can use secp256k1_gej_add_zinv_var, which uses the same
502
+ * isomorphism to efficiently add with a known Z inverse.
503
+ */
504
+ tmp = a [np ];
505
+ if (no ) {
513
506
#ifdef VERIFY
514
507
secp256k1_fe_normalize_var (& Z );
515
508
#endif
516
509
secp256k1_gej_rescale (& tmp , & Z );
517
- 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 );
518
- 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 ));
519
510
}
520
- /* Bring them to the same Z denominator. */
511
+ 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 );
512
+ if (no ) secp256k1_fe_mul (state -> aux + no * ECMULT_TABLE_SIZE (WINDOW_A ), state -> aux + no * ECMULT_TABLE_SIZE (WINDOW_A ), & (a [np ].z ));
521
513
Z = tmp .z ;
522
- secp256k1_ge_globalz_fixup_table (ECMULT_TABLE_SIZE (WINDOW_A ) * no , state -> pre_a , state -> aux );
523
- } else {
524
- secp256k1_fe_set_int (& Z , 1 );
514
+
515
+ ++ no ;
525
516
}
526
517
518
+ /* Bring them to the same Z denominator. */
519
+ secp256k1_ge_globalz_fixup_table (ECMULT_TABLE_SIZE (WINDOW_A ) * no , state -> pre_a , state -> aux );
520
+
527
521
for (np = 0 ; np < no ; ++ np ) {
528
522
for (i = 0 ; i < ECMULT_TABLE_SIZE (WINDOW_A ); i ++ ) {
529
523
secp256k1_ge pre_a_lam ;
0 commit comments