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;
189 for (j = 0; j <
WINDOW_A - 1; ++j) {
307 if (!known_on_curve) {
321 if (!known_on_curve) {
static int secp256k1_ge_is_infinity(const secp256k1_ge *a)
Check whether a group element is the point at infinity.
#define VERIFY_CHECK(cond)
static int secp256k1_gej_is_infinity(const secp256k1_gej *a)
Check whether a group element is the point at infinity.
This field implementation represents the value as 10 uint32_t limbs in base 2^26. ...
#define secp256k1_fe_add_int
static int secp256k1_scalar_is_even(const secp256k1_scalar *a)
Check whether a scalar, considered as an nonnegative integer, is even.
#define ECMULT_TABLE_SIZE(w)
The number of entries a table with precomputed multiples needs to have.
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_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...
#define secp256k1_fe_normalizes_to_zero
#define secp256k1_fe_mul_int(r, a)
Multiply a field element with a small integer.
#define secp256k1_fe_is_square_var
#define secp256k1_fe_normalize_weak
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.
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
Check whether a scalar equals zero.
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...
static int secp256k1_wnaf_const(int *wnaf, const secp256k1_scalar *scalar, int w, int size)
Convert a number to WNAF notation.
A group element of the secp256k1 curve, in jacobian coordinates.
static void secp256k1_gej_set_infinity(secp256k1_gej *r)
Set a group element (jacobian) equal to the point at infinity.
#define ECMULT_CONST_TABLE_GET_GE(r, pre, n, w)
#define WNAF_SIZE_BITS(bits, w)
static void secp256k1_gej_double(secp256k1_gej *r, const secp256k1_gej *a)
Set r equal to the double of a.
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_cadd_bit(secp256k1_scalar *r, unsigned int bit, int flag)
Conditionally add a power of two to a scalar.
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
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...
A scalar modulo the group order of the secp256k1 curve.
static int secp256k1_scalar_cond_negate(secp256k1_scalar *a, int flag)
Conditionally negate a number, in constant time.
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 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 int secp256k1_ecmult_const_xonly(secp256k1_fe *r, const secp256k1_fe *n, const secp256k1_fe *d, const secp256k1_scalar *q, int known_on_curve)
static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *scalar)
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_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_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...