7#ifndef SECP256K1_ECMULT_CONST_IMPL_H
8#define SECP256K1_ECMULT_CONST_IMPL_H
29#define ECMULT_CONST_TABLE_GET_GE(r,pre,n,w) do { \
32 int mask = (n) >> (sizeof(n) * CHAR_BIT - 1); \
33 int abs_n = ((n) + mask) ^ mask; \
34 int idx_n = abs_n >> 1; \
36 VERIFY_CHECK(((n) & 1) == 1); \
37 VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1)); \
38 VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1)); \
39 VERIFY_SETUP(secp256k1_fe_clear(&(r)->x)); \
40 VERIFY_SETUP(secp256k1_fe_clear(&(r)->y)); \
43 (r)->x = (pre)[m].x; \
44 (r)->y = (pre)[m].y; \
45 for (m = 1; m < ECMULT_TABLE_SIZE(w); m++) { \
48 secp256k1_fe_cmov(&(r)->x, &(pre)[m].x, m == idx_n); \
49 secp256k1_fe_cmov(&(r)->y, &(pre)[m].y, m == idx_n); \
52 secp256k1_fe_negate(&neg_y, &(r)->y, 1); \
53 secp256k1_fe_cmov(&(r)->y, &neg_y, (n) != abs_n); \
69static int secp256k1_wnaf_const(
int *wnaf,
const secp256k1_scalar *scalar,
int w,
int size) {
96 flip = secp256k1_scalar_is_high(&
s);
97 skew = flip ^ secp256k1_scalar_is_even(&
s);
98 secp256k1_scalar_cadd_bit(&
s, 0, skew);
99 global_sign = secp256k1_scalar_cond_negate(&
s, flip);
102 u_last = secp256k1_scalar_shr_int(&
s, w);
107 u = secp256k1_scalar_shr_int(&
s, w);
109 even = ((u & 1) == 0);
119 u_last -= even * (1 << w);
122 wnaf[word++] = u_last * global_sign;
125 }
while (word * w < size);
126 wnaf[word] = u * global_sign;
152 secp256k1_scalar_split_lambda(&q_1, &q_lam, scalar);
153 skew_1 = secp256k1_wnaf_const(wnaf_1, &q_1,
WINDOW_A - 1, 128);
154 skew_lam = secp256k1_wnaf_const(wnaf_lam, &q_lam,
WINDOW_A - 1, 128);
157 skew_1 = secp256k1_wnaf_const(wnaf_1, scalar,
WINDOW_A - 1, size);
168 secp256k1_gej_set_ge(
r,
a);
169 secp256k1_ecmult_odd_multiples_table_globalz_windowa(pre_a, &Z,
r);
171 secp256k1_fe_normalize_weak(&pre_a[i].y);
175 secp256k1_ge_mul_lambda(&pre_a_lam[i], &pre_a[i]);
186 secp256k1_gej_set_ge(
r, &tmpa);
191 secp256k1_gej_add_ge(
r,
r, &tmpa);
198 secp256k1_gej_double(
r,
r);
204 secp256k1_gej_add_ge(
r,
r, &tmpa);
209 secp256k1_gej_add_ge(
r,
r, &tmpa);
217 secp256k1_ge_neg(&tmpa, &pre_a[0]);
218 secp256k1_gej_add_ge(&tmpj,
r, &tmpa);
219 secp256k1_gej_cmov(
r, &tmpj, skew_1);
222 secp256k1_ge_neg(&tmpa, &pre_a_lam[0]);
223 secp256k1_gej_add_ge(&tmpj,
r, &tmpa);
224 secp256k1_gej_cmov(
r, &tmpj, skew_lam);
228 secp256k1_fe_mul(&
r->z, &
r->z, &Z);
#define ECMULT_TABLE_SIZE(w)
#define ECMULT_CONST_TABLE_GET_GE(r, pre, n, w)
#define WNAF_SIZE_BITS(bits, w)
#define VERIFY_CHECK(cond)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a