9 #include "../include/secp256k1.h"
21 static void help(
char **argv) {
22 printf(
"Benchmark EC multiplication algorithms\n");
24 printf(
"Usage: %s <help|pippenger_wnaf|strauss_wnaf|simple>\n", argv[0]);
25 printf(
"The output shows the number of multiplied and summed points right after the\n");
26 printf(
"function name. The letter 'g' indicates that one of the points is the generator.\n");
27 printf(
"The benchmarks are divided by the number of points.\n");
29 printf(
"default (ecmult_multi): picks pippenger_wnaf or strauss_wnaf depending on the\n");
31 printf(
"pippenger_wnaf: for all batch sizes\n");
32 printf(
"strauss_wnaf: for all batch sizes\n");
33 printf(
"simple: multiply and sum each point individually\n");
75 for (i = 0; i < iters; ++i) {
77 if (scalar_gen_offset != NULL) {
80 if (seckey_offset != NULL) {
101 for (i = 0; i < iters; ++i) {
115 for (i = 0; i < iters; ++i) {
129 for (i = 0; i < iters; ++i) {
145 for (i = 0; i < iters; ++i) {
159 for (i = 0; i < iters/2; ++i) {
171 sprintf(str,
"ecmult_gen");
173 sprintf(str,
"ecmult_const");
176 sprintf(str,
"ecmult_1p");
179 sprintf(str,
"ecmult_0p_g");
182 sprintf(str,
"ecmult_1p_g");
205 iters = iters / data->
count;
207 for (iter = 0; iter < iters; ++iter) {
222 iters = iters / data->
count;
224 for (iter = 0; iter < iters; ++iter) {
233 unsigned char c[10] = {
'e',
'c',
'm',
'u',
'l',
't', 0, 0, 0, 0};
234 unsigned char buf[32];
250 size_t iters = 1 + num_iters /
count;
258 for (iter = 0; iter < iters; ++iter) {
262 for (i = 0; i + 1 <
count; ++i) {
272 sprintf(str,
"ecmult_multi_%ip_g", (
int)
count - 1);
274 sprintf(str,
"ecmult_multi_%ip", (
int)
count);
279 int main(
int argc,
char **argv) {
294 }
else if(
have_flag(argc, argv,
"pippenger_wnaf")) {
295 printf(
"Using pippenger_wnaf:\n");
297 }
else if(
have_flag(argc, argv,
"strauss_wnaf")) {
298 printf(
"Using strauss_wnaf:\n");
300 }
else if(
have_flag(argc, argv,
"simple")) {
301 printf(
"Using simple algorithm:\n");
303 fprintf(stderr,
"%s: unrecognized argument '%s'.\n\n", argv[0], argv[1]);
328 for (i = 0; i <
POINTS; ++i) {
343 for (i = 1; i <= 8; ++i) {
351 for (p = 0; p <= 11; ++p) {
352 for (i = 9; i <= 16; ++i) {
static void bench_ecmult_const(void *arg, int iters)
static void bench_ecmult_gen_teardown(void *arg, int iters)
static int bench_ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *ge, size_t idx, void *arg)
static void bench_ecmult_teardown_helper(bench_data *data, size_t *seckey_offset, size_t *scalar_offset, size_t *scalar_gen_offset, int iters)
int main(int argc, char **argv)
static void bench_ecmult_setup(void *arg)
static void bench_ecmult_gen(void *arg, int iters)
static void generate_scalar(uint32_t num, secp256k1_scalar *scalar)
static void bench_ecmult_const_teardown(void *arg, int iters)
static void bench_ecmult_multi_setup(void *arg)
static void bench_ecmult_1p_g_teardown(void *arg, int iters)
static void bench_ecmult_1p(void *arg, int iters)
static void bench_ecmult_1p_teardown(void *arg, int iters)
static void bench_ecmult_multi(void *arg, int iters)
static void hash_into_offset(bench_data *data, size_t x)
static void help(char **argv)
static void bench_ecmult_0p_g_teardown(void *arg, int iters)
static void run_ecmult_bench(bench_data *data, int iters)
static void bench_ecmult_1p_g(void *arg, int iters)
static void bench_ecmult_0p_g(void *arg, int iters)
static void bench_ecmult_multi_teardown(void *arg, int iters)
static void run_ecmult_multi_bench(bench_data *data, size_t count, int includes_g, int num_iters)
static void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
static int secp256k1_ecmult_multi_var(const secp256k1_callback *error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n)
Multi-multiply: R = inp_g_sc * G + sum_i ni * Ai.
static void secp256k1_ecmult(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng)
Double multiply: R = na*A + ng*G.
static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q, int bits)
Multiply: R = q*A (in constant-time) Here bits should be set to the maximum bitlength of the absolute...
static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp256k1_gej *r, const secp256k1_scalar *a)
Multiply with the generator: R = a*G.
#define STRAUSS_SCRATCH_OBJECTS
static int secp256k1_ecmult_strauss_batch_single(const secp256k1_callback *error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n)
static size_t secp256k1_strauss_scratch_size(size_t n_points)
static int secp256k1_ecmult_pippenger_batch_single(const secp256k1_callback *error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n)
int(* secp256k1_ecmult_multi_func)(const secp256k1_callback *error_callback, secp256k1_scratch *, secp256k1_gej *, const secp256k1_scalar *, secp256k1_ecmult_multi_callback cb, void *, size_t)
static int secp256k1_gej_eq_var(const secp256k1_gej *a, const secp256k1_gej *b)
Check two group elements (jacobian) for equality in variable time.
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 void secp256k1_gej_set_infinity(secp256k1_gej *r)
Set a group element (jacobian) equal to the point at infinity.
static int secp256k1_gej_is_infinity(const secp256k1_gej *a)
Check whether a group element is the point at 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_ge_set_all_gej_var(secp256k1_ge *r, const secp256k1_gej *a, size_t len)
Set a batch of group elements equal to the inputs given in jacobian coordinates.
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 const secp256k1_ge secp256k1_ge_const_g
#define CHECK(cond)
Unconditional failure on condition failure.
Internal SHA-256 implementation.
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_set_int(secp256k1_scalar *r, unsigned int v)
Set a scalar to an unsigned integer.
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_clear(secp256k1_scalar *r)
Clear a scalar to prevent the leak of sensitive data.
#define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0)
static int get_iters(int default_iters)
static void print_output_table_header_row(void)
static int have_flag(int argc, char **argv, char *flag)
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash)
static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t size)
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
Destroy a secp256k1 context object (created in dynamically allocated memory).
#define SECP256K1_CONTEXT_NONE
Context flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size,...
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object (in dynamically allocated memory).
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space * secp256k1_scratch_space_create(const secp256k1_context *ctx, size_t size) SECP256K1_ARG_NONNULL(1)
Create a secp256k1 scratch space object.
SECP256K1_API void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space *scratch) SECP256K1_ARG_NONNULL(1)
Destroy a secp256k1 scratch space.
secp256k1_scalar * seckeys
secp256k1_gej * pubkeys_gej
secp256k1_ecmult_multi_func ecmult_multi
secp256k1_scratch_space * scratch
secp256k1_scalar * scalars
secp256k1_gej * expected_output
secp256k1_callback error_callback
secp256k1_ecmult_gen_context ecmult_gen_ctx
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
A group element of the secp256k1 curve, in jacobian coordinates.
A scalar modulo the group order of the secp256k1 curve.