33 static const unsigned char init_x[32] = {
34 0x02, 0x03, 0x05, 0x07, 0x0b, 0x0d, 0x11, 0x13,
35 0x17, 0x1d, 0x1f, 0x25, 0x29, 0x2b, 0x2f, 0x35,
36 0x3b, 0x3d, 0x43, 0x47, 0x49, 0x4f, 0x53, 0x59,
37 0x61, 0x65, 0x67, 0x6b, 0x6d, 0x71, 0x7f, 0x83
40 static const unsigned char init_y[32] = {
41 0x82, 0x83, 0x85, 0x87, 0x8b, 0x8d, 0x81, 0x83,
42 0x97, 0xad, 0xaf, 0xb5, 0xb9, 0xbb, 0xbf, 0xc5,
43 0xdb, 0xdd, 0xe3, 0xe7, 0xe9, 0xef, 0xf3, 0xf9,
44 0x11, 0x15, 0x17, 0x1b, 0x1d, 0xb1, 0xbf, 0xd3
47 secp256k1_scalar_set_b32(&data->
scalar_x, init_x, NULL);
48 secp256k1_scalar_set_b32(&data->
scalar_y, init_y, NULL);
49 secp256k1_fe_set_b32(&data->
fe_x, init_x);
50 secp256k1_fe_set_b32(&data->
fe_y, init_y);
53 secp256k1_gej_set_ge(&data->
gej_x, &data->
ge_x);
54 secp256k1_gej_set_ge(&data->
gej_y, &data->
ge_y);
63 for (i = 0; i < 2000000; i++) {
72 for (i = 0; i < 2000000; i++) {
81 for (i = 0; i < 200000; i++) {
90 for (i = 0; i < 200000; i++) {
95 #ifdef USE_ENDOMORPHISM 96 void bench_scalar_split(
void* arg) {
100 for (i = 0; i < 20000; i++) {
102 secp256k1_scalar_split_lambda(&l, &r, &data->
scalar_x);
112 for (i = 0; i < 2000; i++) {
122 for (i = 0; i < 2000; i++) {
132 for (i = 0; i < 2000000; i++) {
133 secp256k1_fe_normalize(&data->
fe_x);
141 for (i = 0; i < 2000000; i++) {
142 secp256k1_fe_normalize_weak(&data->
fe_x);
150 for (i = 0; i < 200000; i++) {
151 secp256k1_fe_mul(&data->
fe_x, &data->
fe_x, &data->
fe_y);
159 for (i = 0; i < 200000; i++) {
160 secp256k1_fe_sqr(&data->
fe_x, &data->
fe_x);
168 for (i = 0; i < 20000; i++) {
169 secp256k1_fe_inv(&data->
fe_x, &data->
fe_x);
170 secp256k1_fe_add(&data->
fe_x, &data->
fe_y);
178 for (i = 0; i < 20000; i++) {
179 secp256k1_fe_inv_var(&data->
fe_x, &data->
fe_x);
180 secp256k1_fe_add(&data->
fe_x, &data->
fe_y);
188 for (i = 0; i < 20000; i++) {
189 secp256k1_fe_sqrt(&data->
fe_x, &data->
fe_x);
190 secp256k1_fe_add(&data->
fe_x, &data->
fe_y);
198 for (i = 0; i < 200000; i++) {
199 secp256k1_gej_double_var(&data->
gej_x, &data->
gej_x, NULL);
207 for (i = 0; i < 200000; i++) {
216 for (i = 0; i < 200000; i++) {
225 for (i = 0; i < 200000; i++) {
226 secp256k1_gej_add_ge_var(&data->
gej_x, &data->
gej_x, &data->
ge_y, NULL);
234 for (i = 0; i < 20000; i++) {
235 secp256k1_gej_has_quad_y_var(&data->
gej_x);
243 for (i = 0; i < 20000; i++) {
253 for (i = 0; i < 20000; i++) {
265 for (i = 0; i < 20000; i++) {
266 secp256k1_sha256_initialize(&sha);
267 secp256k1_sha256_write(&sha, data->
data, 32);
268 secp256k1_sha256_finalize(&sha, data->
data);
277 for (i = 0; i < 20000; i++) {
278 secp256k1_hmac_sha256_initialize(&hmac, data->
data, 32);
279 secp256k1_hmac_sha256_write(&hmac, data->
data, 32);
280 secp256k1_hmac_sha256_finalize(&hmac, data->
data);
289 for (i = 0; i < 20000; i++) {
290 secp256k1_rfc6979_hmac_sha256_initialize(&rng, data->
data, 64);
291 secp256k1_rfc6979_hmac_sha256_generate(&rng, data->
data, 32);
298 for (i = 0; i < 20; i++) {
306 for (i = 0; i < 200; i++) {
317 secp256k1_scalar_get_num(&nx, &data->
scalar_x);
318 secp256k1_scalar_order_get_num(&norder);
319 secp256k1_scalar_get_num(&norder, &data->
scalar_y);
321 for (i = 0; i < 200000; i++) {
322 secp256k1_num_jacobi(&nx, &norder);
328 char** argm = argv + argc;
333 while (argv != NULL && argv != argm) {
334 if (strcmp(*argv, flag) == 0) {
342 int main(
int argc,
char **argv) {
344 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"add"))
run_benchmark(
"scalar_add",
bench_scalar_add,
bench_setup, NULL, &data, 10, 2000000);
345 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"negate"))
run_benchmark(
"scalar_negate",
bench_scalar_negate,
bench_setup, NULL, &data, 10, 2000000);
346 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"sqr"))
run_benchmark(
"scalar_sqr",
bench_scalar_sqr,
bench_setup, NULL, &data, 10, 200000);
347 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"mul"))
run_benchmark(
"scalar_mul",
bench_scalar_mul,
bench_setup, NULL, &data, 10, 200000);
348 #ifdef USE_ENDOMORPHISM 349 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"split"))
run_benchmark(
"scalar_split", bench_scalar_split,
bench_setup, NULL, &data, 10, 20000);
351 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"inverse"))
run_benchmark(
"scalar_inverse",
bench_scalar_inverse,
bench_setup, NULL, &data, 10, 2000);
352 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"inverse"))
run_benchmark(
"scalar_inverse_var",
bench_scalar_inverse_var,
bench_setup, NULL, &data, 10, 2000);
354 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"normalize"))
run_benchmark(
"field_normalize",
bench_field_normalize,
bench_setup, NULL, &data, 10, 2000000);
355 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"normalize"))
run_benchmark(
"field_normalize_weak",
bench_field_normalize_weak,
bench_setup, NULL, &data, 10, 2000000);
356 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"sqr"))
run_benchmark(
"field_sqr",
bench_field_sqr,
bench_setup, NULL, &data, 10, 200000);
357 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"mul"))
run_benchmark(
"field_mul",
bench_field_mul,
bench_setup, NULL, &data, 10, 200000);
358 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"inverse"))
run_benchmark(
"field_inverse",
bench_field_inverse,
bench_setup, NULL, &data, 10, 20000);
359 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"inverse"))
run_benchmark(
"field_inverse_var",
bench_field_inverse_var,
bench_setup, NULL, &data, 10, 20000);
360 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"sqrt"))
run_benchmark(
"field_sqrt",
bench_field_sqrt,
bench_setup, NULL, &data, 10, 20000);
362 if (
have_flag(argc, argv,
"group") ||
have_flag(argc, argv,
"double"))
run_benchmark(
"group_double_var",
bench_group_double_var,
bench_setup, NULL, &data, 10, 200000);
363 if (
have_flag(argc, argv,
"group") ||
have_flag(argc, argv,
"add"))
run_benchmark(
"group_add_var",
bench_group_add_var,
bench_setup, NULL, &data, 10, 200000);
364 if (
have_flag(argc, argv,
"group") ||
have_flag(argc, argv,
"add"))
run_benchmark(
"group_add_affine",
bench_group_add_affine,
bench_setup, NULL, &data, 10, 200000);
365 if (
have_flag(argc, argv,
"group") ||
have_flag(argc, argv,
"add"))
run_benchmark(
"group_add_affine_var",
bench_group_add_affine_var,
bench_setup, NULL, &data, 10, 200000);
366 if (
have_flag(argc, argv,
"group") ||
have_flag(argc, argv,
"jacobi"))
run_benchmark(
"group_jacobi_var",
bench_group_jacobi_var,
bench_setup, NULL, &data, 10, 20000);
368 if (
have_flag(argc, argv,
"ecmult") ||
have_flag(argc, argv,
"wnaf"))
run_benchmark(
"wnaf_const",
bench_wnaf_const,
bench_setup, NULL, &data, 10, 20000);
369 if (
have_flag(argc, argv,
"ecmult") ||
have_flag(argc, argv,
"wnaf"))
run_benchmark(
"ecmult_wnaf",
bench_ecmult_wnaf,
bench_setup, NULL, &data, 10, 20000);
371 if (
have_flag(argc, argv,
"hash") ||
have_flag(argc, argv,
"sha256"))
run_benchmark(
"hash_sha256",
bench_sha256,
bench_setup, NULL, &data, 10, 20000);
372 if (
have_flag(argc, argv,
"hash") ||
have_flag(argc, argv,
"hmac"))
run_benchmark(
"hash_hmac_sha256",
bench_hmac_sha256,
bench_setup, NULL, &data, 10, 20000);
373 if (
have_flag(argc, argv,
"hash") ||
have_flag(argc, argv,
"rng6979"))
run_benchmark(
"hash_rfc6979_hmac_sha256",
bench_rfc6979_hmac_sha256,
bench_setup, NULL, &data, 10, 20000);
375 if (
have_flag(argc, argv,
"context") ||
have_flag(argc, argv,
"verify"))
run_benchmark(
"context_verify",
bench_context_verify,
bench_setup, NULL, &data, 10, 20);
376 if (
have_flag(argc, argv,
"context") ||
have_flag(argc, argv,
"sign"))
run_benchmark(
"context_sign",
bench_context_sign,
bench_setup, NULL, &data, 10, 200);
379 if (
have_flag(argc, argv,
"num") ||
have_flag(argc, argv,
"jacobi"))
run_benchmark(
"num_jacobi",
bench_num_jacobi,
bench_setup, NULL, &data, 10, 200000);
void bench_context_sign(void *arg)
void bench_num_jacobi(void *arg)
void bench_field_normalize(void *arg)
void bench_group_add_var(void *arg)
void bench_scalar_mul(void *arg)
A group element of the secp256k1 curve, in jacobian coordinates.
void bench_group_jacobi_var(void *arg)
#define SECP256K1_CONTEXT_SIGN
void bench_field_sqr(void *arg)
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object.
void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
void bench_scalar_inverse(void *arg)
void bench_field_inverse_var(void *arg)
void bench_scalar_negate(void *arg)
void bench_wnaf_const(void *arg)
secp256k1_scalar scalar_x
void bench_group_add_affine(void *arg)
A group element of the secp256k1 curve, in affine coordinates.
void bench_scalar_inverse_var(void *arg)
void bench_rfc6979_hmac_sha256(void *arg)
A scalar modulo the group order of the secp256k1 curve.
void bench_ecmult_wnaf(void *arg)
void bench_field_normalize_weak(void *arg)
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create.
void bench_group_double_var(void *arg)
void bench_field_sqrt(void *arg)
void bench_hmac_sha256(void *arg)
void * memcpy(void *a, const void *b, size_t c)
void bench_sha256(void *arg)
void bench_setup(void *arg)
int main(int argc, char **argv)
void bench_scalar_add(void *arg)
void bench_group_add_affine_var(void *arg)
void bench_field_mul(void *arg)
void bench_context_verify(void *arg)
int have_flag(int argc, char **argv, char *flag)
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object.
void bench_field_inverse(void *arg)
void bench_scalar_sqr(void *arg)
secp256k1_scalar scalar_y