Merge bitcoin-core/secp256k1#1190: Make all non-API functions (except main) static

e03ef8655933d3e2b4830e7f8fe86deba820a073 Make all non-API functions (except main) static (Pieter Wuille)

Pull request description:

ACKs for top commit:
  real-or-random:
    utACK e03ef8655933d3e2b4830e7f8fe86deba820a073
  hebasto:
    ACK e03ef8655933d3e2b4830e7f8fe86deba820a073.

Tree-SHA512: 36a35d9a8da05411c88644aec81e79883febce3e08c9eb6b0ec95cfc3705fd6abfd66f7ee10dfa081ca20786d26b0a060ead7f5c8109bf02a73dde7ef811144b
This commit is contained in:
Tim Ruffing 2023-01-16 18:38:35 +01:00
commit a7a7bfaf3d
No known key found for this signature in database
GPG Key ID: 8C461CCD293F6011
15 changed files with 230 additions and 233 deletions

View File

@ -11,7 +11,7 @@
#include "util.h" #include "util.h"
#include "bench.h" #include "bench.h"
void help(int default_iters) { static void help(int default_iters) {
printf("Benchmarks the following algorithms:\n"); printf("Benchmarks the following algorithms:\n");
printf(" - ECDSA signing/verification\n"); printf(" - ECDSA signing/verification\n");

View File

@ -38,7 +38,7 @@ static int64_t gettime_i64(void) {
#define FP_MULT (1000000LL) #define FP_MULT (1000000LL)
/* Format fixed point number. */ /* Format fixed point number. */
void print_number(const int64_t x) { static void print_number(const int64_t x) {
int64_t x_abs, y; int64_t x_abs, y;
int c, i, rounding, g; /* g = integer part size, c = fractional part size */ int c, i, rounding, g; /* g = integer part size, c = fractional part size */
size_t ptr; size_t ptr;
@ -95,7 +95,7 @@ void print_number(const int64_t x) {
printf("%-*s", FP_EXP, &buffer[ptr + g]); /* Prints fractional part */ printf("%-*s", FP_EXP, &buffer[ptr + g]); /* Prints fractional part */
} }
void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setup)(void*), void (*teardown)(void*, int), void* data, int count, int iter) { static void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setup)(void*), void (*teardown)(void*, int), void* data, int count, int iter) {
int i; int i;
int64_t min = INT64_MAX; int64_t min = INT64_MAX;
int64_t sum = 0; int64_t sum = 0;
@ -129,7 +129,7 @@ void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setup)(void
printf("\n"); printf("\n");
} }
int have_flag(int argc, char** argv, char *flag) { static int have_flag(int argc, char** argv, char *flag) {
char** argm = argv + argc; char** argm = argv + argc;
argv++; argv++;
while (argv != argm) { while (argv != argm) {
@ -145,7 +145,7 @@ int have_flag(int argc, char** argv, char *flag) {
returns: returns:
- 1 if the user entered an invalid argument - 1 if the user entered an invalid argument
- 0 if all the user entered arguments are valid */ - 0 if all the user entered arguments are valid */
int have_invalid_args(int argc, char** argv, char** valid_args, size_t n) { static int have_invalid_args(int argc, char** argv, char** valid_args, size_t n) {
size_t i; size_t i;
int found_valid; int found_valid;
char** argm = argv + argc; char** argm = argv + argc;
@ -167,7 +167,7 @@ int have_invalid_args(int argc, char** argv, char** valid_args, size_t n) {
return 0; return 0;
} }
int get_iters(int default_iters) { static int get_iters(int default_iters) {
char* env = getenv("SECP256K1_BENCH_ITERS"); char* env = getenv("SECP256K1_BENCH_ITERS");
if (env) { if (env) {
return strtol(env, NULL, 0); return strtol(env, NULL, 0);
@ -176,7 +176,7 @@ int get_iters(int default_iters) {
} }
} }
void print_output_table_header_row(void) { static void print_output_table_header_row(void) {
char* bench_str = "Benchmark"; /* left justified */ char* bench_str = "Benchmark"; /* left justified */
char* min_str = " Min(us) "; /* center alignment */ char* min_str = " Min(us) "; /* center alignment */
char* avg_str = " Avg(us) "; char* avg_str = " Avg(us) ";

View File

@ -18,7 +18,7 @@
#define POINTS 32768 #define POINTS 32768
void help(char **argv) { static void help(char **argv) {
printf("Benchmark EC multiplication algorithms\n"); printf("Benchmark EC multiplication algorithms\n");
printf("\n"); printf("\n");
printf("Usage: %s <help|pippenger_wnaf|strauss_wnaf|simple>\n", argv[0]); printf("Usage: %s <help|pippenger_wnaf|strauss_wnaf|simple>\n", argv[0]);

View File

@ -27,7 +27,7 @@ typedef struct {
int wnaf[256]; int wnaf[256];
} bench_inv; } bench_inv;
void bench_setup(void* arg) { static void bench_setup(void* arg) {
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
static const unsigned char init[4][32] = { static const unsigned char init[4][32] = {
@ -79,7 +79,7 @@ void bench_setup(void* arg) {
memcpy(data->data + 32, init[1], 32); memcpy(data->data + 32, init[1], 32);
} }
void bench_scalar_add(void* arg, int iters) { static void bench_scalar_add(void* arg, int iters) {
int i, j = 0; int i, j = 0;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -89,7 +89,7 @@ void bench_scalar_add(void* arg, int iters) {
CHECK(j <= iters); CHECK(j <= iters);
} }
void bench_scalar_negate(void* arg, int iters) { static void bench_scalar_negate(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -98,7 +98,7 @@ void bench_scalar_negate(void* arg, int iters) {
} }
} }
void bench_scalar_mul(void* arg, int iters) { static void bench_scalar_mul(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -107,7 +107,7 @@ void bench_scalar_mul(void* arg, int iters) {
} }
} }
void bench_scalar_split(void* arg, int iters) { static void bench_scalar_split(void* arg, int iters) {
int i, j = 0; int i, j = 0;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -118,7 +118,7 @@ void bench_scalar_split(void* arg, int iters) {
CHECK(j <= iters); CHECK(j <= iters);
} }
void bench_scalar_inverse(void* arg, int iters) { static void bench_scalar_inverse(void* arg, int iters) {
int i, j = 0; int i, j = 0;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -129,7 +129,7 @@ void bench_scalar_inverse(void* arg, int iters) {
CHECK(j <= iters); CHECK(j <= iters);
} }
void bench_scalar_inverse_var(void* arg, int iters) { static void bench_scalar_inverse_var(void* arg, int iters) {
int i, j = 0; int i, j = 0;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -140,7 +140,7 @@ void bench_scalar_inverse_var(void* arg, int iters) {
CHECK(j <= iters); CHECK(j <= iters);
} }
void bench_field_half(void* arg, int iters) { static void bench_field_half(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -149,7 +149,7 @@ void bench_field_half(void* arg, int iters) {
} }
} }
void bench_field_normalize(void* arg, int iters) { static void bench_field_normalize(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -158,7 +158,7 @@ void bench_field_normalize(void* arg, int iters) {
} }
} }
void bench_field_normalize_weak(void* arg, int iters) { static void bench_field_normalize_weak(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -167,7 +167,7 @@ void bench_field_normalize_weak(void* arg, int iters) {
} }
} }
void bench_field_mul(void* arg, int iters) { static void bench_field_mul(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -176,7 +176,7 @@ void bench_field_mul(void* arg, int iters) {
} }
} }
void bench_field_sqr(void* arg, int iters) { static void bench_field_sqr(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -185,7 +185,7 @@ void bench_field_sqr(void* arg, int iters) {
} }
} }
void bench_field_inverse(void* arg, int iters) { static void bench_field_inverse(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -195,7 +195,7 @@ void bench_field_inverse(void* arg, int iters) {
} }
} }
void bench_field_inverse_var(void* arg, int iters) { static void bench_field_inverse_var(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -205,7 +205,7 @@ void bench_field_inverse_var(void* arg, int iters) {
} }
} }
void bench_field_sqrt(void* arg, int iters) { static void bench_field_sqrt(void* arg, int iters) {
int i, j = 0; int i, j = 0;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
secp256k1_fe t; secp256k1_fe t;
@ -218,7 +218,7 @@ void bench_field_sqrt(void* arg, int iters) {
CHECK(j <= iters); CHECK(j <= iters);
} }
void bench_group_double_var(void* arg, int iters) { static void bench_group_double_var(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -227,7 +227,7 @@ void bench_group_double_var(void* arg, int iters) {
} }
} }
void bench_group_add_var(void* arg, int iters) { static void bench_group_add_var(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -236,7 +236,7 @@ void bench_group_add_var(void* arg, int iters) {
} }
} }
void bench_group_add_affine(void* arg, int iters) { static void bench_group_add_affine(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -245,7 +245,7 @@ void bench_group_add_affine(void* arg, int iters) {
} }
} }
void bench_group_add_affine_var(void* arg, int iters) { static void bench_group_add_affine_var(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -254,7 +254,7 @@ void bench_group_add_affine_var(void* arg, int iters) {
} }
} }
void bench_group_add_zinv_var(void* arg, int iters) { static void bench_group_add_zinv_var(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -263,7 +263,7 @@ void bench_group_add_zinv_var(void* arg, int iters) {
} }
} }
void bench_group_to_affine_var(void* arg, int iters) { static void bench_group_to_affine_var(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -283,7 +283,7 @@ void bench_group_to_affine_var(void* arg, int iters) {
} }
} }
void bench_ecmult_wnaf(void* arg, int iters) { static void bench_ecmult_wnaf(void* arg, int iters) {
int i, bits = 0, overflow = 0; int i, bits = 0, overflow = 0;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -295,7 +295,7 @@ void bench_ecmult_wnaf(void* arg, int iters) {
CHECK(bits <= 256*iters); CHECK(bits <= 256*iters);
} }
void bench_wnaf_const(void* arg, int iters) { static void bench_wnaf_const(void* arg, int iters) {
int i, bits = 0, overflow = 0; int i, bits = 0, overflow = 0;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
@ -307,8 +307,7 @@ void bench_wnaf_const(void* arg, int iters) {
CHECK(bits <= 256*iters); CHECK(bits <= 256*iters);
} }
static void bench_sha256(void* arg, int iters) {
void bench_sha256(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
secp256k1_sha256 sha; secp256k1_sha256 sha;
@ -320,7 +319,7 @@ void bench_sha256(void* arg, int iters) {
} }
} }
void bench_hmac_sha256(void* arg, int iters) { static void bench_hmac_sha256(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
secp256k1_hmac_sha256 hmac; secp256k1_hmac_sha256 hmac;
@ -332,7 +331,7 @@ void bench_hmac_sha256(void* arg, int iters) {
} }
} }
void bench_rfc6979_hmac_sha256(void* arg, int iters) { static void bench_rfc6979_hmac_sha256(void* arg, int iters) {
int i; int i;
bench_inv *data = (bench_inv*)arg; bench_inv *data = (bench_inv*)arg;
secp256k1_rfc6979_hmac_sha256 rng; secp256k1_rfc6979_hmac_sha256 rng;
@ -343,7 +342,7 @@ void bench_rfc6979_hmac_sha256(void* arg, int iters) {
} }
} }
void bench_context(void* arg, int iters) { static void bench_context(void* arg, int iters) {
int i; int i;
(void)arg; (void)arg;
for (i = 0; i < iters; i++) { for (i = 0; i < iters; i++) {

View File

@ -30,7 +30,7 @@
#include "../include/secp256k1_schnorrsig.h" #include "../include/secp256k1_schnorrsig.h"
#endif #endif
void run_tests(secp256k1_context *ctx, unsigned char *key); static void run_tests(secp256k1_context *ctx, unsigned char *key);
int main(void) { int main(void) {
secp256k1_context* ctx; secp256k1_context* ctx;
@ -63,7 +63,7 @@ int main(void) {
return 0; return 0;
} }
void run_tests(secp256k1_context *ctx, unsigned char *key) { static void run_tests(secp256k1_context *ctx, unsigned char *key) {
secp256k1_ecdsa_signature signature; secp256k1_ecdsa_signature signature;
secp256k1_pubkey pubkey; secp256k1_pubkey pubkey;
size_t siglen = 74; size_t siglen = 74;

View File

@ -42,7 +42,7 @@ static void bench_ecdh(void* arg, int iters) {
} }
} }
void run_ecdh_bench(int iters, int argc, char** argv) { static void run_ecdh_bench(int iters, int argc, char** argv) {
bench_ecdh_data data; bench_ecdh_data data;
int d = argc == 1; int d = argc == 1;

View File

@ -7,7 +7,7 @@
#ifndef SECP256K1_MODULE_ECDH_TESTS_H #ifndef SECP256K1_MODULE_ECDH_TESTS_H
#define SECP256K1_MODULE_ECDH_TESTS_H #define SECP256K1_MODULE_ECDH_TESTS_H
int ecdh_hash_function_test_fail(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data) { static int ecdh_hash_function_test_fail(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data) {
(void)output; (void)output;
(void)x; (void)x;
(void)y; (void)y;
@ -15,7 +15,7 @@ int ecdh_hash_function_test_fail(unsigned char *output, const unsigned char *x,
return 0; return 0;
} }
int ecdh_hash_function_custom(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data) { static int ecdh_hash_function_custom(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data) {
(void)data; (void)data;
/* Save x and y as uncompressed public key */ /* Save x and y as uncompressed public key */
output[0] = 0x04; output[0] = 0x04;
@ -24,7 +24,7 @@ int ecdh_hash_function_custom(unsigned char *output, const unsigned char *x, con
return 1; return 1;
} }
void test_ecdh_api(void) { static void test_ecdh_api(void) {
/* Setup context that just counts errors */ /* Setup context that just counts errors */
secp256k1_context *tctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE); secp256k1_context *tctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
secp256k1_pubkey point; secp256k1_pubkey point;
@ -53,7 +53,7 @@ void test_ecdh_api(void) {
secp256k1_context_destroy(tctx); secp256k1_context_destroy(tctx);
} }
void test_ecdh_generator_basepoint(void) { static void test_ecdh_generator_basepoint(void) {
unsigned char s_one[32] = { 0 }; unsigned char s_one[32] = { 0 };
secp256k1_pubkey point[2]; secp256k1_pubkey point[2];
int i; int i;
@ -94,7 +94,7 @@ void test_ecdh_generator_basepoint(void) {
} }
} }
void test_bad_scalar(void) { static void test_bad_scalar(void) {
unsigned char s_zero[32] = { 0 }; unsigned char s_zero[32] = { 0 };
unsigned char s_overflow[32] = { unsigned char s_overflow[32] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@ -124,7 +124,7 @@ void test_bad_scalar(void) {
} }
/** Test that ECDH(sG, 1/s) == ECDH((1/s)G, s) == ECDH(G, 1) for a few random s. */ /** Test that ECDH(sG, 1/s) == ECDH((1/s)G, s) == ECDH(G, 1) for a few random s. */
void test_result_basepoint(void) { static void test_result_basepoint(void) {
secp256k1_pubkey point; secp256k1_pubkey point;
secp256k1_scalar rand; secp256k1_scalar rand;
unsigned char s[32]; unsigned char s[32];
@ -155,7 +155,7 @@ void test_result_basepoint(void) {
} }
} }
void run_ecdh_tests(void) { static void run_ecdh_tests(void) {
test_ecdh_api(); test_ecdh_api();
test_ecdh_generator_basepoint(); test_ecdh_generator_basepoint();
test_bad_scalar(); test_bad_scalar();

View File

@ -14,7 +14,7 @@ static void set_counting_callbacks(secp256k1_context *ctx0, int *ecount) {
secp256k1_context_set_illegal_callback(ctx0, counting_illegal_callback_fn, ecount); secp256k1_context_set_illegal_callback(ctx0, counting_illegal_callback_fn, ecount);
} }
void test_xonly_pubkey(void) { static void test_xonly_pubkey(void) {
secp256k1_pubkey pk; secp256k1_pubkey pk;
secp256k1_xonly_pubkey xonly_pk, xonly_pk_tmp; secp256k1_xonly_pubkey xonly_pk, xonly_pk_tmp;
secp256k1_ge pk1; secp256k1_ge pk1;
@ -128,7 +128,7 @@ void test_xonly_pubkey(void) {
CHECK(ecount == 2); CHECK(ecount == 2);
} }
void test_xonly_pubkey_comparison(void) { static void test_xonly_pubkey_comparison(void) {
unsigned char pk1_ser[32] = { unsigned char pk1_ser[32] = {
0x58, 0x84, 0xb3, 0xa2, 0x4b, 0x97, 0x37, 0x88, 0x92, 0x38, 0xa6, 0x26, 0x62, 0x52, 0x35, 0x11, 0x58, 0x84, 0xb3, 0xa2, 0x4b, 0x97, 0x37, 0x88, 0x92, 0x38, 0xa6, 0x26, 0x62, 0x52, 0x35, 0x11,
0xd0, 0x9a, 0xa1, 0x1b, 0x80, 0x0b, 0x5e, 0x93, 0x80, 0x26, 0x11, 0xef, 0x67, 0x4b, 0xd9, 0x23 0xd0, 0x9a, 0xa1, 0x1b, 0x80, 0x0b, 0x5e, 0x93, 0x80, 0x26, 0x11, 0xef, 0x67, 0x4b, 0xd9, 0x23
@ -164,7 +164,7 @@ void test_xonly_pubkey_comparison(void) {
CHECK(ecount == 6); CHECK(ecount == 6);
} }
void test_xonly_pubkey_tweak(void) { static void test_xonly_pubkey_tweak(void) {
unsigned char zeros64[64] = { 0 }; unsigned char zeros64[64] = { 0 };
unsigned char overflows[32]; unsigned char overflows[32];
unsigned char sk[32]; unsigned char sk[32];
@ -231,7 +231,7 @@ void test_xonly_pubkey_tweak(void) {
CHECK(secp256k1_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0); CHECK(secp256k1_memcmp_var(&output_pk, zeros64, sizeof(output_pk)) == 0);
} }
void test_xonly_pubkey_tweak_check(void) { static void test_xonly_pubkey_tweak_check(void) {
unsigned char zeros64[64] = { 0 }; unsigned char zeros64[64] = { 0 };
unsigned char overflows[32]; unsigned char overflows[32];
unsigned char sk[32]; unsigned char sk[32];
@ -297,7 +297,7 @@ void test_xonly_pubkey_tweak_check(void) {
* additional pubkeys by calling tweak_add. Then verifies every tweak starting * additional pubkeys by calling tweak_add. Then verifies every tweak starting
* from the last pubkey. */ * from the last pubkey. */
#define N_PUBKEYS 32 #define N_PUBKEYS 32
void test_xonly_pubkey_tweak_recursive(void) { static void test_xonly_pubkey_tweak_recursive(void) {
unsigned char sk[32]; unsigned char sk[32];
secp256k1_pubkey pk[N_PUBKEYS]; secp256k1_pubkey pk[N_PUBKEYS];
unsigned char pk_serialized[32]; unsigned char pk_serialized[32];
@ -326,7 +326,7 @@ void test_xonly_pubkey_tweak_recursive(void) {
} }
#undef N_PUBKEYS #undef N_PUBKEYS
void test_keypair(void) { static void test_keypair(void) {
unsigned char sk[32]; unsigned char sk[32];
unsigned char sk_tmp[32]; unsigned char sk_tmp[32];
unsigned char zeros96[96] = { 0 }; unsigned char zeros96[96] = { 0 };
@ -444,7 +444,7 @@ void test_keypair(void) {
secp256k1_context_set_illegal_callback(STATIC_CTX, NULL, NULL); secp256k1_context_set_illegal_callback(STATIC_CTX, NULL, NULL);
} }
void test_keypair_add(void) { static void test_keypair_add(void) {
unsigned char sk[32]; unsigned char sk[32];
secp256k1_keypair keypair; secp256k1_keypair keypair;
unsigned char overflows[32]; unsigned char overflows[32];
@ -550,7 +550,7 @@ void test_keypair_add(void) {
} }
} }
void run_extrakeys_tests(void) { static void run_extrakeys_tests(void) {
/* xonly key test cases */ /* xonly key test cases */
test_xonly_pubkey(); test_xonly_pubkey();
test_xonly_pubkey_tweak(); test_xonly_pubkey_tweak();

View File

@ -15,7 +15,7 @@ typedef struct {
unsigned char sig[64]; unsigned char sig[64];
} bench_recover_data; } bench_recover_data;
void bench_recover(void* arg, int iters) { static void bench_recover(void* arg, int iters) {
int i; int i;
bench_recover_data *data = (bench_recover_data*)arg; bench_recover_data *data = (bench_recover_data*)arg;
secp256k1_pubkey pubkey; secp256k1_pubkey pubkey;
@ -36,7 +36,7 @@ void bench_recover(void* arg, int iters) {
} }
} }
void bench_recover_setup(void* arg) { static void bench_recover_setup(void* arg) {
int i; int i;
bench_recover_data *data = (bench_recover_data*)arg; bench_recover_data *data = (bench_recover_data*)arg;
@ -48,7 +48,7 @@ void bench_recover_setup(void* arg) {
} }
} }
void run_recovery_bench(int iters, int argc, char** argv) { static void run_recovery_bench(int iters, int argc, char** argv) {
bench_recover_data data; bench_recover_data data;
int d = argc == 1; int d = argc == 1;

View File

@ -10,7 +10,7 @@
#include "main_impl.h" #include "main_impl.h"
#include "../../../include/secp256k1_recovery.h" #include "../../../include/secp256k1_recovery.h"
void test_exhaustive_recovery_sign(const secp256k1_context *ctx, const secp256k1_ge *group) { static void test_exhaustive_recovery_sign(const secp256k1_context *ctx, const secp256k1_ge *group) {
int i, j, k; int i, j, k;
uint64_t iter = 0; uint64_t iter = 0;
@ -79,7 +79,7 @@ void test_exhaustive_recovery_sign(const secp256k1_context *ctx, const secp256k1
} }
} }
void test_exhaustive_recovery_verify(const secp256k1_context *ctx, const secp256k1_ge *group) { static void test_exhaustive_recovery_verify(const secp256k1_context *ctx, const secp256k1_ge *group) {
/* This is essentially a copy of test_exhaustive_verify, with recovery added */ /* This is essentially a copy of test_exhaustive_verify, with recovery added */
int s, r, msg, key; int s, r, msg, key;
uint64_t iter = 0; uint64_t iter = 0;

View File

@ -28,7 +28,7 @@ static int recovery_test_nonce_function(unsigned char *nonce32, const unsigned c
return secp256k1_testrand_bits(1); return secp256k1_testrand_bits(1);
} }
void test_ecdsa_recovery_api(void) { static void test_ecdsa_recovery_api(void) {
/* Setup contexts that just count errors */ /* Setup contexts that just count errors */
secp256k1_pubkey pubkey; secp256k1_pubkey pubkey;
secp256k1_pubkey recpubkey; secp256k1_pubkey recpubkey;
@ -127,7 +127,7 @@ void test_ecdsa_recovery_api(void) {
secp256k1_context_set_illegal_callback(STATIC_CTX, NULL, NULL); secp256k1_context_set_illegal_callback(STATIC_CTX, NULL, NULL);
} }
void test_ecdsa_recovery_end_to_end(void) { static void test_ecdsa_recovery_end_to_end(void) {
unsigned char extra[32] = {0x00}; unsigned char extra[32] = {0x00};
unsigned char privkey[32]; unsigned char privkey[32];
unsigned char message[32]; unsigned char message[32];
@ -186,7 +186,7 @@ void test_ecdsa_recovery_end_to_end(void) {
} }
/* Tests several edge cases. */ /* Tests several edge cases. */
void test_ecdsa_recovery_edge_cases(void) { static void test_ecdsa_recovery_edge_cases(void) {
const unsigned char msg32[32] = { const unsigned char msg32[32] = {
'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'T', 'h', 'i', 's', ' ', 'i', 's', ' ',
'a', ' ', 'v', 'e', 'r', 'y', ' ', 's', 'a', ' ', 'v', 'e', 'r', 'y', ' ', 's',
@ -359,7 +359,7 @@ void test_ecdsa_recovery_edge_cases(void) {
} }
} }
void run_recovery_tests(void) { static void run_recovery_tests(void) {
int i; int i;
for (i = 0; i < COUNT; i++) { for (i = 0; i < COUNT; i++) {
test_ecdsa_recovery_api(); test_ecdsa_recovery_api();

View File

@ -21,7 +21,7 @@ typedef struct {
const unsigned char **msgs; const unsigned char **msgs;
} bench_schnorrsig_data; } bench_schnorrsig_data;
void bench_schnorrsig_sign(void* arg, int iters) { static void bench_schnorrsig_sign(void* arg, int iters) {
bench_schnorrsig_data *data = (bench_schnorrsig_data *)arg; bench_schnorrsig_data *data = (bench_schnorrsig_data *)arg;
int i; int i;
unsigned char msg[MSGLEN] = {0}; unsigned char msg[MSGLEN] = {0};
@ -34,7 +34,7 @@ void bench_schnorrsig_sign(void* arg, int iters) {
} }
} }
void bench_schnorrsig_verify(void* arg, int iters) { static void bench_schnorrsig_verify(void* arg, int iters) {
bench_schnorrsig_data *data = (bench_schnorrsig_data *)arg; bench_schnorrsig_data *data = (bench_schnorrsig_data *)arg;
int i; int i;
@ -45,7 +45,7 @@ void bench_schnorrsig_verify(void* arg, int iters) {
} }
} }
void run_schnorrsig_bench(int iters, int argc, char** argv) { static void run_schnorrsig_bench(int iters, int argc, char** argv) {
int i; int i;
bench_schnorrsig_data data; bench_schnorrsig_data data;
int d = argc == 1; int d = argc == 1;

View File

@ -12,7 +12,7 @@
/* Checks that a bit flip in the n_flip-th argument (that has n_bytes many /* Checks that a bit flip in the n_flip-th argument (that has n_bytes many
* bytes) changes the hash function * bytes) changes the hash function
*/ */
void nonce_function_bip340_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes, size_t msglen, size_t algolen) { static void nonce_function_bip340_bitflip(unsigned char **args, size_t n_flip, size_t n_bytes, size_t msglen, size_t algolen) {
unsigned char nonces[2][32]; unsigned char nonces[2][32];
CHECK(nonce_function_bip340(nonces[0], args[0], msglen, args[1], args[2], args[3], algolen, args[4]) == 1); CHECK(nonce_function_bip340(nonces[0], args[0], msglen, args[1], args[2], args[3], algolen, args[4]) == 1);
secp256k1_testrand_flip(args[n_flip], n_bytes); secp256k1_testrand_flip(args[n_flip], n_bytes);
@ -23,7 +23,7 @@ void nonce_function_bip340_bitflip(unsigned char **args, size_t n_flip, size_t n
/* Tests for the equality of two sha256 structs. This function only produces a /* Tests for the equality of two sha256 structs. This function only produces a
* correct result if an integer multiple of 64 many bytes have been written * correct result if an integer multiple of 64 many bytes have been written
* into the hash functions. */ * into the hash functions. */
void test_sha256_eq(const secp256k1_sha256 *sha1, const secp256k1_sha256 *sha2) { static void test_sha256_eq(const secp256k1_sha256 *sha1, const secp256k1_sha256 *sha2) {
/* Is buffer fully consumed? */ /* Is buffer fully consumed? */
CHECK((sha1->bytes & 0x3F) == 0); CHECK((sha1->bytes & 0x3F) == 0);
@ -31,7 +31,7 @@ void test_sha256_eq(const secp256k1_sha256 *sha1, const secp256k1_sha256 *sha2)
CHECK(secp256k1_memcmp_var(sha1->s, sha2->s, sizeof(sha1->s)) == 0); CHECK(secp256k1_memcmp_var(sha1->s, sha2->s, sizeof(sha1->s)) == 0);
} }
void run_nonce_function_bip340_tests(void) { static void run_nonce_function_bip340_tests(void) {
unsigned char tag[13] = "BIP0340/nonce"; unsigned char tag[13] = "BIP0340/nonce";
unsigned char aux_tag[11] = "BIP0340/aux"; unsigned char aux_tag[11] = "BIP0340/aux";
unsigned char algo[13] = "BIP0340/nonce"; unsigned char algo[13] = "BIP0340/nonce";
@ -114,7 +114,7 @@ void run_nonce_function_bip340_tests(void) {
CHECK(secp256k1_memcmp_var(nonce_z, nonce, 32) == 0); CHECK(secp256k1_memcmp_var(nonce_z, nonce, 32) == 0);
} }
void test_schnorrsig_api(void) { static void test_schnorrsig_api(void) {
unsigned char sk1[32]; unsigned char sk1[32];
unsigned char sk2[32]; unsigned char sk2[32];
unsigned char sk3[32]; unsigned char sk3[32];
@ -203,7 +203,7 @@ void test_schnorrsig_api(void) {
/* Checks that hash initialized by secp256k1_schnorrsig_sha256_tagged has the /* Checks that hash initialized by secp256k1_schnorrsig_sha256_tagged has the
* expected state. */ * expected state. */
void test_schnorrsig_sha256_tagged(void) { static void test_schnorrsig_sha256_tagged(void) {
unsigned char tag[17] = "BIP0340/challenge"; unsigned char tag[17] = "BIP0340/challenge";
secp256k1_sha256 sha; secp256k1_sha256 sha;
secp256k1_sha256 sha_optimized; secp256k1_sha256 sha_optimized;
@ -215,7 +215,7 @@ void test_schnorrsig_sha256_tagged(void) {
/* Helper function for schnorrsig_bip_vectors /* Helper function for schnorrsig_bip_vectors
* Signs the message and checks that it's the same as expected_sig. */ * Signs the message and checks that it's the same as expected_sig. */
void test_schnorrsig_bip_vectors_check_signing(const unsigned char *sk, const unsigned char *pk_serialized, const unsigned char *aux_rand, const unsigned char *msg32, const unsigned char *expected_sig) { static void test_schnorrsig_bip_vectors_check_signing(const unsigned char *sk, const unsigned char *pk_serialized, const unsigned char *aux_rand, const unsigned char *msg32, const unsigned char *expected_sig) {
unsigned char sig[64]; unsigned char sig[64];
secp256k1_keypair keypair; secp256k1_keypair keypair;
secp256k1_xonly_pubkey pk, pk_expected; secp256k1_xonly_pubkey pk, pk_expected;
@ -232,7 +232,7 @@ void test_schnorrsig_bip_vectors_check_signing(const unsigned char *sk, const un
/* Helper function for schnorrsig_bip_vectors /* Helper function for schnorrsig_bip_vectors
* Checks that both verify and verify_batch (TODO) return the same value as expected. */ * Checks that both verify and verify_batch (TODO) return the same value as expected. */
void test_schnorrsig_bip_vectors_check_verify(const unsigned char *pk_serialized, const unsigned char *msg32, const unsigned char *sig, int expected) { static void test_schnorrsig_bip_vectors_check_verify(const unsigned char *pk_serialized, const unsigned char *msg32, const unsigned char *sig, int expected) {
secp256k1_xonly_pubkey pk; secp256k1_xonly_pubkey pk;
CHECK(secp256k1_xonly_pubkey_parse(CTX, &pk, pk_serialized)); CHECK(secp256k1_xonly_pubkey_parse(CTX, &pk, pk_serialized));
@ -241,7 +241,7 @@ void test_schnorrsig_bip_vectors_check_verify(const unsigned char *pk_serialized
/* Test vectors according to BIP-340 ("Schnorr Signatures for secp256k1"). See /* Test vectors according to BIP-340 ("Schnorr Signatures for secp256k1"). See
* https://github.com/bitcoin/bips/blob/master/bip-0340/test-vectors.csv. */ * https://github.com/bitcoin/bips/blob/master/bip-0340/test-vectors.csv. */
void test_schnorrsig_bip_vectors(void) { static void test_schnorrsig_bip_vectors(void) {
{ {
/* Test vector 0 */ /* Test vector 0 */
const unsigned char sk[32] = { const unsigned char sk[32] = {
@ -699,7 +699,7 @@ static int nonce_function_overflowing(unsigned char *nonce32, const unsigned cha
return 1; return 1;
} }
void test_schnorrsig_sign(void) { static void test_schnorrsig_sign(void) {
unsigned char sk[32]; unsigned char sk[32];
secp256k1_xonly_pubkey pk; secp256k1_xonly_pubkey pk;
secp256k1_keypair keypair; secp256k1_keypair keypair;
@ -749,7 +749,7 @@ void test_schnorrsig_sign(void) {
/* Creates N_SIGS valid signatures and verifies them with verify and /* Creates N_SIGS valid signatures and verifies them with verify and
* verify_batch (TODO). Then flips some bits and checks that verification now * verify_batch (TODO). Then flips some bits and checks that verification now
* fails. */ * fails. */
void test_schnorrsig_sign_verify(void) { static void test_schnorrsig_sign_verify(void) {
unsigned char sk[32]; unsigned char sk[32];
unsigned char msg[N_SIGS][32]; unsigned char msg[N_SIGS][32];
unsigned char sig[N_SIGS][64]; unsigned char sig[N_SIGS][64];
@ -826,7 +826,7 @@ void test_schnorrsig_sign_verify(void) {
} }
#undef N_SIGS #undef N_SIGS
void test_schnorrsig_taproot(void) { static void test_schnorrsig_taproot(void) {
unsigned char sk[32]; unsigned char sk[32];
secp256k1_keypair keypair; secp256k1_keypair keypair;
secp256k1_xonly_pubkey internal_pk; secp256k1_xonly_pubkey internal_pk;
@ -862,7 +862,7 @@ void test_schnorrsig_taproot(void) {
CHECK(secp256k1_xonly_pubkey_tweak_add_check(CTX, output_pk_bytes, pk_parity, &internal_pk, tweak) == 1); CHECK(secp256k1_xonly_pubkey_tweak_add_check(CTX, output_pk_bytes, pk_parity, &internal_pk, tweak) == 1);
} }
void run_schnorrsig_tests(void) { static void run_schnorrsig_tests(void) {
int i; int i;
run_nonce_function_bip340_tests(); run_nonce_function_bip340_tests();

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@
static int count = 2; static int count = 2;
/** stolen from tests.c */ /** stolen from tests.c */
void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b) { static void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b) {
CHECK(a->infinity == b->infinity); CHECK(a->infinity == b->infinity);
if (a->infinity) { if (a->infinity) {
return; return;
@ -33,7 +33,7 @@ void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b) {
CHECK(secp256k1_fe_equal_var(&a->y, &b->y)); CHECK(secp256k1_fe_equal_var(&a->y, &b->y));
} }
void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) { static void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) {
secp256k1_fe z2s; secp256k1_fe z2s;
secp256k1_fe u1, u2, s1, s2; secp256k1_fe u1, u2, s1, s2;
CHECK(a->infinity == b->infinity); CHECK(a->infinity == b->infinity);
@ -50,7 +50,7 @@ void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) {
CHECK(secp256k1_fe_equal_var(&s1, &s2)); CHECK(secp256k1_fe_equal_var(&s1, &s2));
} }
void random_fe(secp256k1_fe *x) { static void random_fe(secp256k1_fe *x) {
unsigned char bin[32]; unsigned char bin[32];
do { do {
secp256k1_testrand256(bin); secp256k1_testrand256(bin);
@ -70,7 +70,7 @@ SECP256K1_INLINE static int skip_section(uint64_t* iter) {
return ((((uint32_t)*iter ^ (*iter >> 32)) * num_cores) >> 32) != this_core; return ((((uint32_t)*iter ^ (*iter >> 32)) * num_cores) >> 32) != this_core;
} }
int secp256k1_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg32, static int secp256k1_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg32,
const unsigned char *key32, const unsigned char *algo16, const unsigned char *key32, const unsigned char *algo16,
void *data, unsigned int attempt) { void *data, unsigned int attempt) {
secp256k1_scalar s; secp256k1_scalar s;
@ -90,7 +90,7 @@ int secp256k1_nonce_function_smallint(unsigned char *nonce32, const unsigned cha
return 1; return 1;
} }
void test_exhaustive_endomorphism(const secp256k1_ge *group) { static void test_exhaustive_endomorphism(const secp256k1_ge *group) {
int i; int i;
for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
secp256k1_ge res; secp256k1_ge res;
@ -99,7 +99,7 @@ void test_exhaustive_endomorphism(const secp256k1_ge *group) {
} }
} }
void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *groupj) { static void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *groupj) {
int i, j; int i, j;
uint64_t iter = 0; uint64_t iter = 0;
@ -159,7 +159,7 @@ void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *gr
} }
} }
void test_exhaustive_ecmult(const secp256k1_ge *group, const secp256k1_gej *groupj) { static void test_exhaustive_ecmult(const secp256k1_ge *group, const secp256k1_gej *groupj) {
int i, j, r_log; int i, j, r_log;
uint64_t iter = 0; uint64_t iter = 0;
for (r_log = 1; r_log < EXHAUSTIVE_TEST_ORDER; r_log++) { for (r_log = 1; r_log < EXHAUSTIVE_TEST_ORDER; r_log++) {
@ -195,7 +195,7 @@ static int ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t
return 1; return 1;
} }
void test_exhaustive_ecmult_multi(const secp256k1_context *ctx, const secp256k1_ge *group) { static void test_exhaustive_ecmult_multi(const secp256k1_context *ctx, const secp256k1_ge *group) {
int i, j, k, x, y; int i, j, k, x, y;
uint64_t iter = 0; uint64_t iter = 0;
secp256k1_scratch *scratch = secp256k1_scratch_create(&ctx->error_callback, 4096); secp256k1_scratch *scratch = secp256k1_scratch_create(&ctx->error_callback, 4096);
@ -225,7 +225,7 @@ void test_exhaustive_ecmult_multi(const secp256k1_context *ctx, const secp256k1_
secp256k1_scratch_destroy(&ctx->error_callback, scratch); secp256k1_scratch_destroy(&ctx->error_callback, scratch);
} }
void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overflow) { static void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overflow) {
secp256k1_fe x; secp256k1_fe x;
unsigned char x_bin[32]; unsigned char x_bin[32];
k %= EXHAUSTIVE_TEST_ORDER; k %= EXHAUSTIVE_TEST_ORDER;
@ -235,7 +235,7 @@ void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overfl
secp256k1_scalar_set_b32(r, x_bin, overflow); secp256k1_scalar_set_b32(r, x_bin, overflow);
} }
void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *group) { static void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *group) {
int s, r, msg, key; int s, r, msg, key;
uint64_t iter = 0; uint64_t iter = 0;
for (s = 1; s < EXHAUSTIVE_TEST_ORDER; s++) { for (s = 1; s < EXHAUSTIVE_TEST_ORDER; s++) {
@ -288,7 +288,7 @@ void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *gr
} }
} }
void test_exhaustive_sign(const secp256k1_context *ctx, const secp256k1_ge *group) { static void test_exhaustive_sign(const secp256k1_context *ctx, const secp256k1_ge *group) {
int i, j, k; int i, j, k;
uint64_t iter = 0; uint64_t iter = 0;