7 #ifndef SECP256K1_ECMULT_CONST_IMPL_H 8 #define SECP256K1_ECMULT_CONST_IMPL_H 15 #ifdef USE_ENDOMORPHISM 20 #define WNAF_SIZE(w) ((WNAF_BITS + (w) - 1) / (w)) 23 #define ECMULT_CONST_TABLE_GET_GE(r,pre,n,w) do { \ 25 int abs_n = (n) * (((n) > 0) * 2 - 1); \ 26 int idx_n = abs_n / 2; \ 28 VERIFY_CHECK(((n) & 1) == 1); \ 29 VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1)); \ 30 VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1)); \ 31 VERIFY_SETUP(secp256k1_fe_clear(&(r)->x)); \ 32 VERIFY_SETUP(secp256k1_fe_clear(&(r)->y)); \ 33 for (m = 0; m < ECMULT_TABLE_SIZE(w); m++) { \ 36 secp256k1_fe_cmov(&(r)->x, &(pre)[m].x, m == idx_n); \ 37 secp256k1_fe_cmov(&(r)->y, &(pre)[m].y, m == idx_n); \ 40 secp256k1_fe_negate(&neg_y, &(r)->y, 1); \ 41 secp256k1_fe_cmov(&(r)->y, &neg_y, (n) != abs_n); \ 80 flip = secp256k1_scalar_is_high(&s);
82 bit = flip ^ !secp256k1_scalar_is_even(&s);
84 secp256k1_scalar_negate(&neg_s, &s);
85 not_neg_one = !secp256k1_scalar_is_one(&neg_s);
86 secp256k1_scalar_cadd_bit(&s, bit, not_neg_one);
92 global_sign = secp256k1_scalar_cond_negate(&s, flip);
93 global_sign *= not_neg_one * 2 - 1;
97 u_last = secp256k1_scalar_shr_int(&s, w);
103 u = secp256k1_scalar_shr_int(&s, w);
105 even = ((u & 1) == 0);
106 sign = 2 * (u_last > 0) - 1;
108 u_last -= sign * even * (1 << w);
111 wnaf[word++] = u_last * global_sign;
115 wnaf[
word] = u * global_sign;
130 #ifdef USE_ENDOMORPHISM 141 #ifdef USE_ENDOMORPHISM 143 secp256k1_scalar_split_lambda(&q_1, &q_lam, &sc);
144 skew_1 = secp256k1_wnaf_const(wnaf_1, q_1,
WINDOW_A - 1);
145 skew_lam = secp256k1_wnaf_const(wnaf_lam, q_lam,
WINDOW_A - 1);
147 skew_1 = secp256k1_wnaf_const(wnaf_1, sc,
WINDOW_A - 1);
156 secp256k1_gej_set_ge(r, a);
157 secp256k1_ecmult_odd_multiples_table_globalz_windowa(pre_a, &Z, r);
159 secp256k1_fe_normalize_weak(&pre_a[i].y);
161 #ifdef USE_ENDOMORPHISM 163 secp256k1_ge_mul_lambda(&pre_a_lam[i], &pre_a[i]);
173 secp256k1_gej_set_ge(r, &tmpa);
174 #ifdef USE_ENDOMORPHISM 178 secp256k1_gej_add_ge(r, r, &tmpa);
184 for (j = 0; j <
WINDOW_A - 1; ++j) {
185 secp256k1_gej_double_nonzero(r, r, NULL);
191 secp256k1_gej_add_ge(r, r, &tmpa);
192 #ifdef USE_ENDOMORPHISM 196 secp256k1_gej_add_ge(r, r, &tmpa);
200 secp256k1_fe_mul(&r->
z, &r->
z, &Z);
206 #ifdef USE_ENDOMORPHISM 211 secp256k1_gej_set_ge(&tmpj, &correction);
212 secp256k1_gej_double_var(&tmpj, &tmpj, NULL);
213 secp256k1_ge_set_gej(&correction, &tmpj);
214 secp256k1_ge_to_storage(&correction_1_stor, a);
215 #ifdef USE_ENDOMORPHISM 216 secp256k1_ge_to_storage(&correction_lam_stor, a);
218 secp256k1_ge_to_storage(&a2_stor, &correction);
221 secp256k1_ge_storage_cmov(&correction_1_stor, &a2_stor, skew_1 == 2);
222 #ifdef USE_ENDOMORPHISM 223 secp256k1_ge_storage_cmov(&correction_lam_stor, &a2_stor, skew_lam == 2);
227 secp256k1_ge_from_storage(&correction, &correction_1_stor);
228 secp256k1_ge_neg(&correction, &correction);
229 secp256k1_gej_add_ge(r, r, &correction);
231 #ifdef USE_ENDOMORPHISM 232 secp256k1_ge_from_storage(&correction, &correction_lam_stor);
233 secp256k1_ge_neg(&correction, &correction);
234 secp256k1_ge_mul_lambda(&correction, &correction);
235 secp256k1_gej_add_ge(r, r, &correction);
#define VERIFY_CHECK(cond)
#define ECMULT_TABLE_SIZE(w)
The number of entries a table with precomputed multiples needs to have.
A group element of the secp256k1 curve, in jacobian coordinates.
#define ECMULT_CONST_TABLE_GET_GE(r, pre, n, w)
A group element of the secp256k1 curve, in affine coordinates.
A scalar modulo the group order of the secp256k1 curve.
Signature sign(Secret const &_k, h256 const &_hash)
Returns siganture of message hash.