Skip to content

Commit

Permalink
Make all non-API functions (except main) static
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Jan 9, 2023
1 parent cbe41ac commit e03ef86
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
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
14 changes: 7 additions & 7 deletions src/modules/ecdh/tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#ifndef 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)x;
(void)y;
(void)data;
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;
/* Save x and y as uncompressed public key */
output[0] = 0x04;
Expand All @@ -24,7 +24,7 @@ int ecdh_hash_function_custom(unsigned char *output, const unsigned char *x, con
return 1;
}

void test_ecdh_api(void) {
static void test_ecdh_api(void) {
/* Setup context that just counts errors */
secp256k1_context *tctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
secp256k1_pubkey point;
Expand Down Expand Up @@ -53,7 +53,7 @@ void test_ecdh_api(void) {
secp256k1_context_destroy(tctx);
}

void test_ecdh_generator_basepoint(void) {
static void test_ecdh_generator_basepoint(void) {
unsigned char s_one[32] = { 0 };
secp256k1_pubkey point[2];
int i;
Expand Down Expand Up @@ -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_overflow[32] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
Expand Down Expand Up @@ -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. */
void test_result_basepoint(void) {
static void test_result_basepoint(void) {
secp256k1_pubkey point;
secp256k1_scalar rand;
unsigned char s[32];
Expand Down Expand Up @@ -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_generator_basepoint();
test_bad_scalar();
Expand Down
Loading

0 comments on commit e03ef86

Please sign in to comment.