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 volatile 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); \
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;
197 for (j = 0; j <
WINDOW_A - 1; ++j) {
#define ECMULT_TABLE_SIZE(w)
The number of entries a table with precomputed multiples needs to have.
static void secp256k1_ecmult_odd_multiples_table_globalz_windowa(secp256k1_ge *pre, secp256k1_fe *globalz, const secp256k1_gej *a)
Fill a table 'pre' with precomputed odd multiples of a.
#define ECMULT_CONST_TABLE_GET_GE(r, pre, n, w)
static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *scalar, int size)
static int secp256k1_wnaf_const(int *wnaf, const secp256k1_scalar *scalar, int w, int size)
Convert a number to WNAF notation.
#define WNAF_SIZE_BITS(bits, w)
static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_ge *pre_a, secp256k1_fe *zr, secp256k1_fe *z, const secp256k1_gej *a)
Fill a table 'pre_a' with precomputed odd multiples of a.
static void secp256k1_fe_normalize_weak(secp256k1_fe *r)
Weakly normalize a field element: reduce its magnitude to 1, but don't fully normalize.
static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe *SECP256K1_RESTRICT b)
Sets a field element to be the product of two others.
static void secp256k1_ge_mul_lambda(secp256k1_ge *r, const secp256k1_ge *a)
Set r to be equal to lambda times a, where lambda is chosen in a way such that this is very fast.
static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b)
Set r equal to the sum of a and b (with b given in affine coordinates, and not infinity).
static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const secp256k1_fe *zr)
Bring a batch of inputs to the same global z "denominator", based on ratios between (omitted) z coord...
static void secp256k1_ge_neg(secp256k1_ge *r, const secp256k1_ge *a)
Set r equal to the inverse of a (i.e., mirrored around the X axis)
static void secp256k1_gej_double(secp256k1_gej *r, const secp256k1_gej *a)
Set r equal to the double of a.
static void secp256k1_gej_set_ge(secp256k1_gej *r, const secp256k1_ge *a)
Set a group element (jacobian) equal to another which is given in affine coordinates.
static void secp256k1_gej_cmov(secp256k1_gej *r, const secp256k1_gej *a, int flag)
If flag is true, set *r equal to *a; otherwise leave it.
static int secp256k1_scalar_is_even(const secp256k1_scalar *a)
Check whether a scalar, considered as an nonnegative integer, is even.
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
Check whether a scalar equals zero.
static int secp256k1_scalar_cond_negate(secp256k1_scalar *a, int flag)
Conditionally negate a number, in constant time.
static int secp256k1_scalar_is_high(const secp256k1_scalar *a)
Check whether a scalar is higher than the group order divided by 2.
static void secp256k1_scalar_split_lambda(secp256k1_scalar *SECP256K1_RESTRICT r1, secp256k1_scalar *SECP256K1_RESTRICT r2, const secp256k1_scalar *SECP256K1_RESTRICT k)
Find r1 and r2 such that r1+r2*lambda = k, where r1 and r2 or their negations are maximum 128 bits lo...
static void secp256k1_scalar_cadd_bit(secp256k1_scalar *r, unsigned int bit, int flag)
Conditionally add a power of two to a scalar.
static int secp256k1_scalar_shr_int(secp256k1_scalar *r, int n)
Shift a scalar right by some amount strictly between 0 and 16, returning the low bits that were shift...
#define VERIFY_CHECK(cond)
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
A group element of the secp256k1 curve, in jacobian coordinates.
A scalar modulo the group order of the secp256k1 curve.