Skip to content

Commit

Permalink
Merge bitcoin-core/secp256k1#1190: Make all non-API functions (except…
Browse files Browse the repository at this point in the history
… main) static

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

Pull request description:

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

Tree-SHA512: 36a35d9a8da05411c88644aec81e79883febce3e08c9eb6b0ec95cfc3705fd6abfd66f7ee10dfa081ca20786d26b0a060ead7f5c8109bf02a73dde7ef811144b
  • Loading branch information
real-or-random committed Jan 16, 2023
2 parents f29a327 + e03ef86 commit a7a7bfa
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 233 deletions.
2 changes: 1 addition & 1 deletion src/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "util.h"
#include "bench.h"

void help(int default_iters) {
static void help(int default_iters) {
printf("Benchmarks the following algorithms:\n");
printf(" - ECDSA signing/verification\n");

Expand Down
12 changes: 6 additions & 6 deletions src/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int64_t gettime_i64(void) {
#define FP_MULT (1000000LL)

/* Format fixed point number. */
void print_number(const int64_t x) {
static void print_number(const int64_t x) {
int64_t x_abs, y;
int c, i, rounding, g; /* g = integer part size, c = fractional part size */
size_t ptr;
Expand Down Expand Up @@ -95,7 +95,7 @@ void print_number(const int64_t x) {
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;
int64_t min = INT64_MAX;
int64_t sum = 0;
Expand Down Expand Up @@ -129,7 +129,7 @@ void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setup)(void
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;
argv++;
while (argv != argm) {
Expand All @@ -145,7 +145,7 @@ int have_flag(int argc, char** argv, char *flag) {
returns:
- 1 if the user entered an invalid argument
- 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;
int found_valid;
char** argm = argv + argc;
Expand All @@ -167,7 +167,7 @@ int have_invalid_args(int argc, char** argv, char** valid_args, size_t n) {
return 0;
}

int get_iters(int default_iters) {
static int get_iters(int default_iters) {
char* env = getenv("SECP256K1_BENCH_ITERS");
if (env) {
return strtol(env, NULL, 0);
Expand All @@ -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* min_str = " Min(us) "; /* center alignment */
char* avg_str = " Avg(us) ";
Expand Down
2 changes: 1 addition & 1 deletion src/bench_ecmult.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#define POINTS 32768

void help(char **argv) {
static void help(char **argv) {
printf("Benchmark EC multiplication algorithms\n");
printf("\n");
printf("Usage: %s <help|pippenger_wnaf|strauss_wnaf|simple>\n", argv[0]);
Expand Down
55 changes: 27 additions & 28 deletions src/bench_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef struct {
int wnaf[256];
} bench_inv;

void bench_setup(void* arg) {
static void bench_setup(void* arg) {
bench_inv *data = (bench_inv*)arg;

static const unsigned char init[4][32] = {
Expand Down Expand Up @@ -79,7 +79,7 @@ void bench_setup(void* arg) {
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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -89,7 +89,7 @@ void bench_scalar_add(void* arg, int iters) {
CHECK(j <= iters);
}

void bench_scalar_negate(void* arg, int iters) {
static void bench_scalar_negate(void* arg, int iters) {
int i;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -118,7 +118,7 @@ void bench_scalar_split(void* arg, int 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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -129,7 +129,7 @@ void bench_scalar_inverse(void* arg, int 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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -140,7 +140,7 @@ void bench_scalar_inverse_var(void* arg, int iters) {
CHECK(j <= iters);
}

void bench_field_half(void* arg, int iters) {
static void bench_field_half(void* arg, int iters) {
int i;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;
secp256k1_fe t;
Expand All @@ -218,7 +218,7 @@ void bench_field_sqrt(void* arg, int 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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -295,7 +295,7 @@ void bench_ecmult_wnaf(void* arg, int 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;
bench_inv *data = (bench_inv*)arg;

Expand All @@ -307,8 +307,7 @@ void bench_wnaf_const(void* arg, int iters) {
CHECK(bits <= 256*iters);
}


void bench_sha256(void* arg, int iters) {
static void bench_sha256(void* arg, int iters) {
int i;
bench_inv *data = (bench_inv*)arg;
secp256k1_sha256 sha;
Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;
secp256k1_hmac_sha256 hmac;
Expand All @@ -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;
bench_inv *data = (bench_inv*)arg;
secp256k1_rfc6979_hmac_sha256 rng;
Expand All @@ -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;
(void)arg;
for (i = 0; i < iters; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/ctime_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "../include/secp256k1_schnorrsig.h"
#endif

void run_tests(secp256k1_context *ctx, unsigned char *key);
static void run_tests(secp256k1_context *ctx, unsigned char *key);

int main(void) {
secp256k1_context* ctx;
Expand Down Expand Up @@ -63,7 +63,7 @@ int main(void) {
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_pubkey pubkey;
size_t siglen = 74;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/ecdh/bench_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
int d = argc == 1;

Expand Down
Loading

0 comments on commit a7a7bfa

Please sign in to comment.