Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
bench_ecmult.c File Reference
#include <stdio.h>
#include "secp256k1.c"
#include "../include/secp256k1.h"
#include "util.h"
#include "hash_impl.h"
#include "field_impl.h"
#include "group_impl.h"
#include "scalar_impl.h"
#include "ecmult_impl.h"
#include "bench.h"
Include dependency graph for bench_ecmult.c:

Go to the source code of this file.

Classes

struct  bench_data
 

Macros

#define POINTS   32768
 

Functions

void help (char **argv)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ POINTS

#define POINTS   32768

Definition at line 19 of file bench_ecmult.c.

Function Documentation

◆ help()

void help ( char ** argv)

Definition at line 21 of file bench_ecmult.c.

21 {
22 printf("Benchmark EC multiplication algorithms\n");
23 printf("\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");
28 printf("\n");
29 printf("default (ecmult_multi): picks pippenger_wnaf or strauss_wnaf depending on the\n");
30 printf(" batch size\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");
34}
char ** argv
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 281 of file bench_ecmult.c.

281 {
282 bench_data data;
283 int i, p;
284 size_t scratch_size;
285
286 int iters = get_iters(10000);
287
288 data.ecmult_multi = secp256k1_ecmult_multi_var;
289
290 if (argc > 1) {
291 if(have_flag(argc, argv, "-h")
292 || have_flag(argc, argv, "--help")
293 || have_flag(argc, argv, "help")) {
294 help(argv);
295 return 0;
296 } else if(have_flag(argc, argv, "pippenger_wnaf")) {
297 printf("Using pippenger_wnaf:\n");
298 data.ecmult_multi = secp256k1_ecmult_pippenger_batch_single;
299 } else if(have_flag(argc, argv, "strauss_wnaf")) {
300 printf("Using strauss_wnaf:\n");
301 data.ecmult_multi = secp256k1_ecmult_strauss_batch_single;
302 } else if(have_flag(argc, argv, "simple")) {
303 printf("Using simple algorithm:\n");
304 } else {
305 fprintf(stderr, "%s: unrecognized argument '%s'.\n\n", argv[0], argv[1]);
306 help(argv);
307 return 1;
308 }
309 }
310
312 scratch_size = secp256k1_strauss_scratch_size(POINTS) + STRAUSS_SCRATCH_OBJECTS*16;
313 if (!have_flag(argc, argv, "simple")) {
314 data.scratch = secp256k1_scratch_space_create(data.ctx, scratch_size);
315 } else {
316 data.scratch = NULL;
317 }
318
319 /* Allocate stuff */
320 data.scalars = malloc(sizeof(secp256k1_scalar) * POINTS);
321 data.seckeys = malloc(sizeof(secp256k1_scalar) * POINTS);
322 data.pubkeys = malloc(sizeof(secp256k1_ge) * POINTS);
323 data.pubkeys_gej = malloc(sizeof(secp256k1_gej) * POINTS);
324 data.expected_output = malloc(sizeof(secp256k1_gej) * (iters + 1));
325 data.output = malloc(sizeof(secp256k1_gej) * (iters + 1));
326
327 /* Generate a set of scalars, and private/public keypairs. */
328 secp256k1_gej_set_ge(&data.pubkeys_gej[0], &secp256k1_ge_const_g);
329 secp256k1_scalar_set_int(&data.seckeys[0], 1);
330 for (i = 0; i < POINTS; ++i) {
331 generate_scalar(i, &data.scalars[i]);
332 if (i) {
333 secp256k1_gej_double_var(&data.pubkeys_gej[i], &data.pubkeys_gej[i - 1], NULL);
334 secp256k1_scalar_add(&data.seckeys[i], &data.seckeys[i - 1], &data.seckeys[i - 1]);
335 }
336 }
337 secp256k1_ge_set_all_gej_var(data.pubkeys, data.pubkeys_gej, POINTS);
338
339
341 /* Initialize offset1 and offset2 */
342 hash_into_offset(&data, 0);
343 run_ecmult_bench(&data, iters);
344
345 for (i = 1; i <= 8; ++i) {
346 run_ecmult_multi_bench(&data, i, 1, iters);
347 }
348
349 /* This is disabled with low count of iterations because the loop runs 77 times even with iters=1
350 * and the higher it goes the longer the computation takes(more points)
351 * So we don't run this benchmark with low iterations to prevent slow down */
352 if (iters > 2) {
353 for (p = 0; p <= 11; ++p) {
354 for (i = 9; i <= 16; ++i) {
355 run_ecmult_multi_bench(&data, i << p, 1, iters);
356 }
357 }
358 }
359
360 if (data.scratch != NULL) {
361 secp256k1_scratch_space_destroy(data.ctx, data.scratch);
362 }
364 free(data.scalars);
365 free(data.pubkeys);
366 free(data.pubkeys_gej);
367 free(data.seckeys);
368 free(data.output);
369 free(data.expected_output);
370
371 return(0);
372}
void print_output_table_header_row(void)
Definition bench.h:163
int have_flag(int argc, char **argv, char *flag)
Definition bench.h:116
int get_iters(int default_iters)
Definition bench.h:154
void help(char **argv)
#define POINTS
const mie::Vuint & p
Definition bn.cpp:27
#define STRAUSS_SCRATCH_OBJECTS
Definition ecmult_impl.h:50
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
Definition secp256k1.c:146
#define SECP256K1_CONTEXT_SIGN
Definition secp256k1.h:196
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space * secp256k1_scratch_space_create(const secp256k1_context *ctx, size_t size) SECP256K1_ARG_NONNULL(1)
Definition secp256k1.c:171
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Definition secp256k1.c:107
SECP256K1_API void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space *scratch) SECP256K1_ARG_NONNULL(1)
Definition secp256k1.c:176
#define SECP256K1_CONTEXT_VERIFY
Definition secp256k1.h:195
Here is the call graph for this function: