Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
bench_impl.h
Go to the documentation of this file.
1/***********************************************************************
2 * Copyright (c) 2015 Pieter Wuille, Andrew Poelstra *
3 * Distributed under the MIT software license, see the accompanying *
4 * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 ***********************************************************************/
6
7#ifndef SECP256K1_MODULE_ECDH_BENCH_H
8#define SECP256K1_MODULE_ECDH_BENCH_H
9
10#include "../include/secp256k1_ecdh.h"
11
12typedef struct {
15 unsigned char scalar[32];
17
18static void bench_ecdh_setup(void* arg) {
19 int i;
20 bench_ecdh_data *data = (bench_ecdh_data*)arg;
21 const unsigned char point[] = {
22 0x03,
23 0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06,
24 0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd,
25 0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb,
26 0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f
27 };
28
29 for (i = 0; i < 32; i++) {
30 data->scalar[i] = i + 1;
31 }
32 CHECK(secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1);
33}
34
35static void bench_ecdh(void* arg, int iters) {
36 int i;
37 unsigned char res[32];
38 bench_ecdh_data *data = (bench_ecdh_data*)arg;
39
40 for (i = 0; i < iters; i++) {
41 CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar, NULL, NULL) == 1);
42 }
43}
44
45void run_ecdh_bench(int iters, int argc, char** argv) {
46 bench_ecdh_data data;
47 int d = argc == 1;
48
49 /* create a context with no capabilities */
51
52 if (d || have_flag(argc, argv, "ecdh")) run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters);
53
55}
56
57#endif /* SECP256K1_MODULE_ECDH_BENCH_H */
int have_flag(int argc, char **argv, char *flag)
Definition bench.h:116
void run_benchmark(char *name, void(*benchmark)(void *, int), void(*setup)(void *), void(*teardown)(void *, int), void *data, int count, int iter)
Definition bench.h:82
void run_ecdh_bench(int iters, int argc, char **argv)
Definition bench_impl.h:45
#define CHECK(cond)
Definition util.h:80
char ** argv
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
Definition secp256k1.c:146
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Definition secp256k1.c:107
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Definition secp256k1.c:228
#define SECP256K1_FLAGS_TYPE_CONTEXT
Definition secp256k1.h:185
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(const secp256k1_context *ctx, unsigned char *output, const secp256k1_pubkey *pubkey, const unsigned char *seckey, secp256k1_ecdh_hash_function hashfp, void *data) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition main_impl.h:29
secp256k1_pubkey point
Definition bench_impl.h:14
secp256k1_context * ctx
Definition bench_impl.h:13
CK_ULONG d