26 unsigned char data[64];
33 static const unsigned char init[4][32] = {
37 0x02, 0x03, 0x05, 0x07, 0x0b, 0x0d, 0x11, 0x13,
38 0x17, 0x1d, 0x1f, 0x25, 0x29, 0x2b, 0x2f, 0x35,
39 0x3b, 0x3d, 0x43, 0x47, 0x49, 0x4f, 0x53, 0x59,
40 0x61, 0x65, 0x67, 0x6b, 0x6d, 0x71, 0x7f, 0x83
45 0x82, 0x83, 0x85, 0x87, 0x8b, 0x8d, 0x81, 0x83,
46 0x97, 0xad, 0xaf, 0xb5, 0xb9, 0xbb, 0xbf, 0xc5,
47 0xdb, 0xdd, 0xe3, 0xe7, 0xe9, 0xef, 0xf3, 0xf9,
48 0x11, 0x15, 0x17, 0x1b, 0x1d, 0xb1, 0xbf, 0xd3
52 0x3d, 0x2d, 0xef, 0xf4, 0x25, 0x98, 0x4f, 0x5d,
53 0xe2, 0xca, 0x5f, 0x41, 0x3f, 0x3f, 0xce, 0x44,
54 0xaa, 0x2c, 0x53, 0x8a, 0xc6, 0x59, 0x1f, 0x38,
55 0x38, 0x23, 0xe4, 0x11, 0x27, 0xc6, 0xa0, 0xe7
59 0xbd, 0x21, 0xa5, 0xe1, 0x13, 0x50, 0x73, 0x2e,
60 0x52, 0x98, 0xc8, 0x9e, 0xab, 0x00, 0xa2, 0x68,
61 0x43, 0xf5, 0xd7, 0x49, 0x80, 0x72, 0xa7, 0xf3,
62 0xd7, 0x60, 0xe6, 0xab, 0x90, 0x92, 0xdf, 0xc5
79 memcpy(data->
data + 32,
init[1], 32);
86 for (i = 0; i < iters; i++) {
96 for (i = 0; i < iters; i++) {
105 for (i = 0; i < iters; i++) {
114 for (i = 0; i < iters; i++) {
125 for (i = 0; i < iters; i++) {
136 for (i = 0; i < iters; i++) {
147 for (i = 0; i < iters; i++) {
156 for (i = 0; i < iters; i++) {
165 for (i = 0; i < iters; i++) {
174 for (i = 0; i < iters; i++) {
183 for (i = 0; i < iters; i++) {
193 for (i = 0; i < iters; i++) {
204 for (i = 0; i < iters; i++) {
216 for (i = 0; i < iters; i++) {
225 for (i = 0; i < iters; i++) {
234 for (i = 0; i < iters; i++) {
243 for (i = 0; i < iters; i++) {
252 for (i = 0; i < iters; i++) {
272 for (i = 0; i < iters; ++i) {
287 int i, bits = 0, overflow = 0;
290 for (i = 0; i < iters; i++) {
294 CHECK(overflow >= 0);
295 CHECK(bits <= 256*iters);
299 int i, bits = 0, overflow = 0;
302 for (i = 0; i < iters; i++) {
306 CHECK(overflow >= 0);
307 CHECK(bits <= 256*iters);
316 for (i = 0; i < iters; i++) {
328 for (i = 0; i < iters; i++) {
340 for (i = 0; i < iters; i++) {
349 for (i = 0; i < iters; i++) {
357 for (i = 0; i < iters; i++) {
362int main(
int argc,
char **argv) {
366 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"add"))
run_benchmark(
"scalar_add",
bench_scalar_add,
bench_setup, NULL, &data, 10, iters*100);
367 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"negate"))
run_benchmark(
"scalar_negate",
bench_scalar_negate,
bench_setup, NULL, &data, 10, iters*100);
368 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"mul"))
run_benchmark(
"scalar_mul",
bench_scalar_mul,
bench_setup, NULL, &data, 10, iters*10);
369 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"split"))
run_benchmark(
"scalar_split",
bench_scalar_split,
bench_setup, NULL, &data, 10, iters);
370 if (
have_flag(argc, argv,
"scalar") ||
have_flag(argc, argv,
"inverse"))
run_benchmark(
"scalar_inverse",
bench_scalar_inverse,
bench_setup, NULL, &data, 10, iters);
371 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, iters);
373 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"normalize"))
run_benchmark(
"field_normalize",
bench_field_normalize,
bench_setup, NULL, &data, 10, iters*100);
374 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, iters*100);
375 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"sqr"))
run_benchmark(
"field_sqr",
bench_field_sqr,
bench_setup, NULL, &data, 10, iters*10);
376 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"mul"))
run_benchmark(
"field_mul",
bench_field_mul,
bench_setup, NULL, &data, 10, iters*10);
377 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"inverse"))
run_benchmark(
"field_inverse",
bench_field_inverse,
bench_setup, NULL, &data, 10, iters);
378 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, iters);
379 if (
have_flag(argc, argv,
"field") ||
have_flag(argc, argv,
"sqrt"))
run_benchmark(
"field_sqrt",
bench_field_sqrt,
bench_setup, NULL, &data, 10, iters);
381 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, iters*10);
382 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, iters*10);
383 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, iters*10);
384 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, iters*10);
385 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, iters);
386 if (
have_flag(argc, argv,
"group") ||
have_flag(argc, argv,
"to_affine"))
run_benchmark(
"group_to_affine_var",
bench_group_to_affine_var,
bench_setup, NULL, &data, 10, iters);
388 if (
have_flag(argc, argv,
"ecmult") ||
have_flag(argc, argv,
"wnaf"))
run_benchmark(
"wnaf_const",
bench_wnaf_const,
bench_setup, NULL, &data, 10, iters);
389 if (
have_flag(argc, argv,
"ecmult") ||
have_flag(argc, argv,
"wnaf"))
run_benchmark(
"ecmult_wnaf",
bench_ecmult_wnaf,
bench_setup, NULL, &data, 10, iters);
391 if (
have_flag(argc, argv,
"hash") ||
have_flag(argc, argv,
"sha256"))
run_benchmark(
"hash_sha256",
bench_sha256,
bench_setup, NULL, &data, 10, iters);
392 if (
have_flag(argc, argv,
"hash") ||
have_flag(argc, argv,
"hmac"))
run_benchmark(
"hash_hmac_sha256",
bench_hmac_sha256,
bench_setup, NULL, &data, 10, iters);
393 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, iters);
395 if (
have_flag(argc, argv,
"context") ||
have_flag(argc, argv,
"verify"))
run_benchmark(
"context_verify",
bench_context_verify,
bench_setup, NULL, &data, 10, 1 + iters/1000);
396 if (
have_flag(argc, argv,
"context") ||
have_flag(argc, argv,
"sign"))
run_benchmark(
"context_sign",
bench_context_sign,
bench_setup, NULL, &data, 10, 1 + iters/100);
void bench_field_inverse(void *arg, int iters)
void bench_scalar_negate(void *arg, int iters)
void bench_scalar_inverse_var(void *arg, int iters)
void bench_field_normalize(void *arg, int iters)
void bench_sha256(void *arg, int iters)
int main(int argc, char **argv)
void bench_hmac_sha256(void *arg, int iters)
void bench_scalar_split(void *arg, int iters)
void bench_field_normalize_weak(void *arg, int iters)
void bench_field_sqrt(void *arg, int iters)
void bench_context_verify(void *arg, int iters)
void bench_wnaf_const(void *arg, int iters)
void bench_ecmult_wnaf(void *arg, int iters)
void bench_scalar_inverse(void *arg, int iters)
void bench_group_double_var(void *arg, int iters)
void bench_context_sign(void *arg, int iters)
void bench_group_jacobi_var(void *arg, int iters)
void bench_field_inverse_var(void *arg, int iters)
void bench_scalar_add(void *arg, int iters)
void bench_scalar_mul(void *arg, int iters)
void bench_group_add_affine_var(void *arg, int iters)
void bench_field_mul(void *arg, int iters)
void bench_group_to_affine_var(void *arg, int iters)
void bench_rfc6979_hmac_sha256(void *arg, int iters)
void bench_group_add_var(void *arg, int iters)
void bench_field_sqr(void *arg, int iters)
void bench_setup(void *arg)
void bench_group_add_affine(void *arg, int iters)
static int secp256k1_wnaf_const(int *wnaf, const secp256k1_scalar *scalar, int w, int size)
Convert a number to WNAF notation.
static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a, int w)
Convert a number to WNAF notation.
static void secp256k1_fe_inv_var(secp256k1_fe *r, const secp256k1_fe *a)
Potentially faster version of secp256k1_fe_inv, without constant-time guarantee.
static void secp256k1_fe_normalize_weak(secp256k1_fe *r)
Weakly normalize a field element: reduce its magnitude to 1, but don't fully normalize.
static int secp256k1_fe_sqrt(secp256k1_fe *r, const secp256k1_fe *a)
If a has a square root, it is computed in r and 1 is returned.
static void secp256k1_fe_normalize_var(secp256k1_fe *r)
Normalize a field element, without constant-time guarantee.
static void secp256k1_fe_inv(secp256k1_fe *r, const secp256k1_fe *a)
Sets a field element to be the (modular) inverse of another.
static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe *SECP256K1_RESTRICT b)
Sets a field element to be the product of two others.
static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a)
Set a field element equal to 32-byte big endian value.
static void secp256k1_fe_sqr(secp256k1_fe *r, const secp256k1_fe *a)
Sets a field element to be the square of another.
static void secp256k1_fe_add(secp256k1_fe *r, const secp256k1_fe *a)
Adds a field element to another.
static void secp256k1_fe_normalize(secp256k1_fe *r)
Field element module.
static void secp256k1_gej_double_var(secp256k1_gej *r, const secp256k1_gej *a, secp256k1_fe *rzr)
Set r equal to the double of a.
static int secp256k1_ge_set_xo_var(secp256k1_ge *r, const secp256k1_fe *x, int odd)
Set a group element (affine) equal to the point with the given X coordinate, and given oddness for Y.
static void secp256k1_gej_add_ge_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, secp256k1_fe *rzr)
Set r equal to the sum of a and b (with b given in affine coordinates).
static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b)
Set r equal to the sum of a and b (with b given in affine coordinates, and not infinity).
static void secp256k1_gej_add_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_gej *b, secp256k1_fe *rzr)
Set r equal to the sum of a and b.
static void secp256k1_gej_rescale(secp256k1_gej *r, const secp256k1_fe *b)
Rescale a jacobian point by b which must be non-zero.
static void secp256k1_gej_set_ge(secp256k1_gej *r, const secp256k1_ge *a)
Set a group element (jacobian) equal to another which is given in affine coordinates.
static void secp256k1_ge_set_gej_var(secp256k1_ge *r, secp256k1_gej *a)
Set a group element equal to another which is given in jacobian coordinates.
static int secp256k1_gej_has_quad_y_var(const secp256k1_gej *a)
Check whether a group element's y coordinate is a quadratic residue.
static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow)
Set a scalar from a big endian byte array.
static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_scalar *a)
Compute the inverse of a scalar (modulo the group order), without constant-time guarantee.
static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Add two scalars together (modulo the group order).
static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Multiply two scalars (modulo the group order).
static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a)
Compute the complement of a scalar (modulo the group order).
static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar *a)
Compute the inverse of a scalar (modulo the group order).
static void secp256k1_scalar_split_lambda(secp256k1_scalar *r1, secp256k1_scalar *r2, const secp256k1_scalar *k)
Find r1 and r2 such that r1+r2*lambda = k, where r1 and r2 or their negations are maximum 128 bits lo...
int have_flag(int argc, char **argv, char *flag)
int get_iters(int default_iters)
void run_benchmark(char *name, void(*benchmark)(void *, int), void(*setup)(void *), void(*teardown)(void *, int), void *data, int count, int iter)
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash)
static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen)
static void secp256k1_hmac_sha256_finalize(secp256k1_hmac_sha256 *hash, unsigned char *out32)
static void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256 *hash, const unsigned char *key, size_t size)
static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256 *rng, const unsigned char *key, size_t keylen)
static void secp256k1_hmac_sha256_write(secp256k1_hmac_sha256 *hash, const unsigned char *data, size_t size)
static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t size)
#define SECP256K1_CONTEXT_SIGN
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object (in dynamically allocated memory).
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size, and secp256k1_context...
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object (created in dynamically allocated memory).
secp256k1_scalar scalar[2]
A group element of the secp256k1 curve, in affine coordinates.
A group element of the secp256k1 curve, in jacobian coordinates.
A scalar modulo the group order of the secp256k1 curve.