Eliminate input_pos state field from ecmult_strauss_wnaf.
This commit is contained in:
parent
0397d00ba0
commit
fe34d9f341
|
@ -214,7 +214,6 @@ struct secp256k1_strauss_point_state {
|
||||||
int wnaf_na_lam[129];
|
int wnaf_na_lam[129];
|
||||||
int bits_na_1;
|
int bits_na_1;
|
||||||
int bits_na_lam;
|
int bits_na_lam;
|
||||||
size_t input_pos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct secp256k1_strauss_state {
|
struct secp256k1_strauss_state {
|
||||||
|
@ -238,12 +237,13 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
|
||||||
size_t np;
|
size_t np;
|
||||||
size_t no = 0;
|
size_t no = 0;
|
||||||
|
|
||||||
|
secp256k1_fe_set_int(&Z, 1);
|
||||||
for (np = 0; np < num; ++np) {
|
for (np = 0; np < num; ++np) {
|
||||||
|
secp256k1_gej tmp;
|
||||||
secp256k1_scalar na_1, na_lam;
|
secp256k1_scalar na_1, na_lam;
|
||||||
if (secp256k1_scalar_is_zero(&na[np]) || secp256k1_gej_is_infinity(&a[np])) {
|
if (secp256k1_scalar_is_zero(&na[np]) || secp256k1_gej_is_infinity(&a[np])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
state->ps[no].input_pos = np;
|
|
||||||
/* split na into na_1 and na_lam (where na = na_1 + na_lam*lambda, and na_1 and na_lam are ~128 bit) */
|
/* split na into na_1 and na_lam (where na = na_1 + na_lam*lambda, and na_1 and na_lam are ~128 bit) */
|
||||||
secp256k1_scalar_split_lambda(&na_1, &na_lam, &na[np]);
|
secp256k1_scalar_split_lambda(&na_1, &na_lam, &na[np]);
|
||||||
|
|
||||||
|
@ -258,8 +258,6 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
|
||||||
if (state->ps[no].bits_na_lam > bits) {
|
if (state->ps[no].bits_na_lam > bits) {
|
||||||
bits = state->ps[no].bits_na_lam;
|
bits = state->ps[no].bits_na_lam;
|
||||||
}
|
}
|
||||||
++no;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Calculate odd multiples of a.
|
/* Calculate odd multiples of a.
|
||||||
* All multiples are brought to the same Z 'denominator', which is stored
|
* All multiples are brought to the same Z 'denominator', which is stored
|
||||||
|
@ -271,23 +269,21 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
|
||||||
* of 1/Z, so we can use secp256k1_gej_add_zinv_var, which uses the same
|
* of 1/Z, so we can use secp256k1_gej_add_zinv_var, which uses the same
|
||||||
* isomorphism to efficiently add with a known Z inverse.
|
* isomorphism to efficiently add with a known Z inverse.
|
||||||
*/
|
*/
|
||||||
if (no > 0) {
|
tmp = a[np];
|
||||||
/* Compute the odd multiples in Jacobian form. */
|
if (no) {
|
||||||
secp256k1_ecmult_odd_multiples_table(ECMULT_TABLE_SIZE(WINDOW_A), state->pre_a, state->aux, &Z, &a[state->ps[0].input_pos]);
|
|
||||||
for (np = 1; np < no; ++np) {
|
|
||||||
secp256k1_gej tmp = a[state->ps[np].input_pos];
|
|
||||||
#ifdef VERIFY
|
#ifdef VERIFY
|
||||||
secp256k1_fe_normalize_var(&Z);
|
secp256k1_fe_normalize_var(&Z);
|
||||||
#endif
|
#endif
|
||||||
secp256k1_gej_rescale(&tmp, &Z);
|
secp256k1_gej_rescale(&tmp, &Z);
|
||||||
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);
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
if (no) secp256k1_fe_mul(state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), &(a[np].z));
|
||||||
|
|
||||||
|
++no;
|
||||||
|
}
|
||||||
|
|
||||||
/* Bring them to the same Z denominator. */
|
/* Bring them to the same Z denominator. */
|
||||||
secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
|
secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
|
||||||
} else {
|
|
||||||
secp256k1_fe_set_int(&Z, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (np = 0; np < no; ++np) {
|
for (np = 0; np < no; ++np) {
|
||||||
for (i = 0; i < ECMULT_TABLE_SIZE(WINDOW_A); i++) {
|
for (i = 0; i < ECMULT_TABLE_SIZE(WINDOW_A); i++) {
|
||||||
|
|
Loading…
Reference in New Issue