Bitcoin Core 31.0.0
P2P Digital Currency
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
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
45static void run_ecdh_bench(int iters, int argc, char** argv) {
46 bench_ecdh_data data;
47 int d = argc == 1;
48
49 data.ctx = secp256k1_context_static;
50
51 if (d || have_flag(argc, argv, "ecdh")) run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters);
52}
53
54#endif /* SECP256K1_MODULE_ECDH_BENCH_H */
static void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
Definition bench.c:26
static void bench_ecdh_setup(void *arg)
Definition bench_impl.h:18
static void bench_ecdh(void *arg, int iters)
Definition bench_impl.h:35
static void run_ecdh_bench(int iters, int argc, char **argv)
Definition bench_impl.h:45
#define CHECK(cond)
Unconditional failure on condition failure.
Definition util.h:35
static int have_flag(int argc, char **argv, char *flag)
Definition bench.h:112
struct secp256k1_context_struct secp256k1_context
Unless explicitly stated all pointer arguments must not be NULL.
Definition secp256k1.h:50
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)
Parse a variable-length public key into the pubkey object.
Definition secp256k1.c:250
SECP256K1_API const secp256k1_context *const secp256k1_context_static
A built-in constant secp256k1 context object with static storage duration, to be used in conjunction ...
Definition secp256k1.h:245
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)
Compute an EC Diffie-Hellman secret in constant time.
Definition main_impl.h:30
secp256k1_pubkey point
Definition bench_impl.h:14
const secp256k1_context * ctx
Definition bench_impl.h:13
unsigned char scalar[32]
Definition bench_impl.h:15
Opaque data structure that holds a parsed and valid public key.
Definition secp256k1.h:61