Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ libsecp256k1.pc
### Python
__pycache__/
*.py[oc]
_codeql_build_dir/
_codeql_detected_source_root
2 changes: 1 addition & 1 deletion src/bench_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct {
secp256k1_ge ge[2];
secp256k1_gej gej[2];
unsigned char data[64];
int wnaf[256];
int32_t wnaf[256];
} bench_inv;

static void bench_setup(void* arg) {
Expand Down
32 changes: 16 additions & 16 deletions src/ecmult_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_ge *pre_a, sec
secp256k1_fe_mul(z, &ai.z, &d.z);
}

SECP256K1_INLINE static void secp256k1_ecmult_table_verify(int n, int w) {
SECP256K1_INLINE static void secp256k1_ecmult_table_verify(int32_t n, int w) {
(void)n;
(void)w;
VERIFY_CHECK(((n) & 1) == 1);
VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1));
VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1));
}

SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge(secp256k1_ge *r, const secp256k1_ge *pre, int n, int w) {
SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge(secp256k1_ge *r, const secp256k1_ge *pre, int32_t n, int w) {
secp256k1_ecmult_table_verify(n,w);
if (n > 0) {
*r = pre[(n-1)/2];
Expand All @@ -132,7 +132,7 @@ SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge(secp256k1_ge *r, cons
}
}

SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_lambda(secp256k1_ge *r, const secp256k1_ge *pre, const secp256k1_fe *x, int n, int w) {
SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_lambda(secp256k1_ge *r, const secp256k1_ge *pre, const secp256k1_fe *x, int32_t n, int w) {
secp256k1_ecmult_table_verify(n,w);
if (n > 0) {
secp256k1_ge_set_xy(r, &x[(n-1)/2], &pre[(n-1)/2].y);
Expand All @@ -142,7 +142,7 @@ SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_lambda(secp256k1_ge *
}
}

SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_storage(secp256k1_ge *r, const secp256k1_ge_storage *pre, int n, int w) {
SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_storage(secp256k1_ge *r, const secp256k1_ge_storage *pre, int32_t n, int w) {
secp256k1_ecmult_table_verify(n,w);
if (n > 0) {
secp256k1_ge_from_storage(r, &pre[(n-1)/2]);
Expand All @@ -159,12 +159,12 @@ SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_storage(secp256k1_ge
* - the number of set values in wnaf is returned. This number is at most 256, and at most one more
* than the number of bits in the (absolute value) of the input.
*/
static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a, int w) {
static int secp256k1_ecmult_wnaf(int32_t *wnaf, int len, const secp256k1_scalar *a, int w) {
secp256k1_scalar s;
int last_set_bit = -1;
int bit = 0;
int sign = 1;
int carry = 0;
int32_t sign = 1;
int32_t carry = 0;

VERIFY_CHECK(wnaf != NULL);
VERIFY_CHECK(0 <= len && len <= 256);
Expand All @@ -184,7 +184,7 @@ static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a,
bit = 0;
while (bit < len) {
int now;
int word;
int32_t word;
if (secp256k1_scalar_get_bits_limb32(&s, bit, 1) == (unsigned int)carry) {
bit++;
continue;
Expand Down Expand Up @@ -221,8 +221,8 @@ static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a,
}

struct secp256k1_strauss_point_state {
int wnaf_na_1[129];
int wnaf_na_lam[129];
int32_t wnaf_na_1[129];
int32_t wnaf_na_lam[129];
int bits_na_1;
int bits_na_lam;
};
Expand All @@ -239,9 +239,9 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
secp256k1_fe Z;
/* Split G factors. */
secp256k1_scalar ng_1, ng_128;
int wnaf_ng_1[129];
int32_t wnaf_ng_1[129];
int bits_ng_1 = 0;
int wnaf_ng_128[129];
int32_t wnaf_ng_128[129];
int bits_ng_128 = 0;
int i;
int bits = 0;
Expand Down Expand Up @@ -319,7 +319,7 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
secp256k1_gej_set_infinity(r);

for (i = bits - 1; i >= 0; i--) {
int n;
int32_t n;
secp256k1_gej_double_var(r, r, NULL);
for (np = 0; np < no; ++np) {
if (i < state->ps[np].bits_na_1 && (n = state->ps[np].wnaf_na_1[i])) {
Expand Down Expand Up @@ -418,7 +418,7 @@ static size_t secp256k1_strauss_max_points(const secp256k1_callback* error_callb
* - the number of words set is always WNAF_SIZE(w)
* - the returned skew is 0 or 1
*/
static int secp256k1_wnaf_fixed(int *wnaf, const secp256k1_scalar *s, int w) {
static int secp256k1_wnaf_fixed(int32_t *wnaf, const secp256k1_scalar *s, int w) {
int skew = 0;
int pos;
int max_pos;
Expand Down Expand Up @@ -486,7 +486,7 @@ struct secp256k1_pippenger_point_state {
};

struct secp256k1_pippenger_state {
int *wnaf_na;
int32_t *wnaf_na;
struct secp256k1_pippenger_point_state* ps;
};

Expand Down Expand Up @@ -526,7 +526,7 @@ static int secp256k1_ecmult_pippenger_wnaf(secp256k1_gej *buckets, int bucket_wi
}

for (np = 0; np < no; ++np) {
int n = state->wnaf_na[np*n_wnaf + i];
int32_t n = state->wnaf_na[np*n_wnaf + i];
struct secp256k1_pippenger_point_state point_state = state->ps[np];
secp256k1_ge tmp;
int idx;
Expand Down
20 changes: 10 additions & 10 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -5271,7 +5271,7 @@ static void run_ecmult_multi_tests(void) {

static void test_wnaf(const secp256k1_scalar *number, int w) {
secp256k1_scalar x, two, t;
int wnaf[256];
int32_t wnaf[256];
int zeroes = -1;
int i;
int bits;
Expand All @@ -5280,7 +5280,7 @@ static void test_wnaf(const secp256k1_scalar *number, int w) {
bits = secp256k1_ecmult_wnaf(wnaf, 256, number, w);
CHECK(bits <= 256);
for (i = bits-1; i >= 0; i--) {
int v = wnaf[i];
int32_t v = wnaf[i];
secp256k1_scalar_mul(&x, &x, &two);
if (v) {
CHECK(zeroes == -1 || zeroes >= w-1); /* check that distance between non-zero elements is at least w-1 */
Expand All @@ -5305,7 +5305,7 @@ static void test_wnaf(const secp256k1_scalar *number, int w) {

static void test_fixed_wnaf(const secp256k1_scalar *number, int w) {
secp256k1_scalar x, shift;
int wnaf[256] = {0};
int32_t wnaf[256] = {0};
int i;
int skew;
secp256k1_scalar num, unused;
Expand Down Expand Up @@ -5339,7 +5339,7 @@ static void test_fixed_wnaf(const secp256k1_scalar *number, int w) {

/* Checks that the first 8 elements of wnaf are equal to wnaf_expected and the
* rest is 0.*/
static void test_fixed_wnaf_small_helper(int *wnaf, int *wnaf_expected, int w) {
static void test_fixed_wnaf_small_helper(int32_t *wnaf, int32_t *wnaf_expected, int w) {
int i;
for (i = WNAF_SIZE(w)-1; i >= 8; --i) {
CHECK(wnaf[i] == 0);
Expand All @@ -5351,15 +5351,15 @@ static void test_fixed_wnaf_small_helper(int *wnaf, int *wnaf_expected, int w) {

static void test_fixed_wnaf_small(void) {
int w = 4;
int wnaf[256] = {0};
int32_t wnaf[256] = {0};
int i;
int skew;
secp256k1_scalar num;

secp256k1_scalar_set_int(&num, 0);
skew = secp256k1_wnaf_fixed(wnaf, &num, w);
for (i = WNAF_SIZE(w)-1; i >= 0; --i) {
int v = wnaf[i];
int32_t v = wnaf[i];
CHECK(v == 0);
}
CHECK(skew == 0);
Expand All @@ -5374,28 +5374,28 @@ static void test_fixed_wnaf_small(void) {
CHECK(skew == 0);

{
int wnaf_expected[8] = { 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf };
int32_t wnaf_expected[8] = { 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf };
secp256k1_scalar_set_int(&num, 0xffffffff);
skew = secp256k1_wnaf_fixed(wnaf, &num, w);
test_fixed_wnaf_small_helper(wnaf, wnaf_expected, w);
CHECK(skew == 0);
}
{
int wnaf_expected[8] = { -1, -1, -1, -1, -1, -1, -1, 0xf };
int32_t wnaf_expected[8] = { -1, -1, -1, -1, -1, -1, -1, 0xf };
secp256k1_scalar_set_int(&num, 0xeeeeeeee);
skew = secp256k1_wnaf_fixed(wnaf, &num, w);
test_fixed_wnaf_small_helper(wnaf, wnaf_expected, w);
CHECK(skew == 1);
}
{
int wnaf_expected[8] = { 1, 0, 1, 0, 1, 0, 1, 0 };
int32_t wnaf_expected[8] = { 1, 0, 1, 0, 1, 0, 1, 0 };
secp256k1_scalar_set_int(&num, 0x01010101);
skew = secp256k1_wnaf_fixed(wnaf, &num, w);
test_fixed_wnaf_small_helper(wnaf, wnaf_expected, w);
CHECK(skew == 0);
}
{
int wnaf_expected[8] = { -0xf, 0, 0xf, -0xf, 0, 0xf, 1, 0 };
int32_t wnaf_expected[8] = { -0xf, 0, 0xf, -0xf, 0, 0xf, 1, 0 };
secp256k1_scalar_set_int(&num, 0x01ef1ef1);
skew = secp256k1_wnaf_fixed(wnaf, &num, w);
test_fixed_wnaf_small_helper(wnaf, wnaf_expected, w);
Expand Down