2020-12-17 08:33:49 +02:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Copyright (c) 2015 Pieter Wuille, Andrew Poelstra *
|
|
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
|
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
|
***********************************************************************/
|
2015-05-15 14:46:08 -05:00
|
|
|
|
2021-10-17 12:10:23 -04:00
|
|
|
#ifndef SECP256K1_MODULE_ECDH_BENCH_H
|
|
|
|
|
#define SECP256K1_MODULE_ECDH_BENCH_H
|
2015-05-15 14:46:08 -05:00
|
|
|
|
2022-06-30 17:16:21 +02:00
|
|
|
#include "../../../include/secp256k1_ecdh.h"
|
2015-05-15 14:46:08 -05:00
|
|
|
|
|
|
|
|
typedef struct {
|
2025-09-16 23:01:06 +02:00
|
|
|
const secp256k1_context *ctx;
|
2015-09-21 20:57:54 +02:00
|
|
|
secp256k1_pubkey point;
|
2015-05-15 14:46:08 -05:00
|
|
|
unsigned char scalar[32];
|
2017-12-18 18:22:09 -08:00
|
|
|
} bench_ecdh_data;
|
2015-05-15 14:46:08 -05:00
|
|
|
|
|
|
|
|
static void bench_ecdh_setup(void* arg) {
|
|
|
|
|
int i;
|
2017-12-18 18:22:09 -08:00
|
|
|
bench_ecdh_data *data = (bench_ecdh_data*)arg;
|
2015-05-15 14:46:08 -05:00
|
|
|
const unsigned char point[] = {
|
|
|
|
|
0x03,
|
|
|
|
|
0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06,
|
|
|
|
|
0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd,
|
|
|
|
|
0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb,
|
|
|
|
|
0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-21 17:21:35 +00:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
|
data->scalar[i] = i + 1;
|
|
|
|
|
}
|
2015-05-15 14:46:08 -05:00
|
|
|
CHECK(secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-04 15:13:35 +02:00
|
|
|
static void bench_ecdh(void* arg, int iters) {
|
2015-05-15 14:46:08 -05:00
|
|
|
int i;
|
|
|
|
|
unsigned char res[32];
|
2017-12-18 18:22:09 -08:00
|
|
|
bench_ecdh_data *data = (bench_ecdh_data*)arg;
|
2015-05-15 14:46:08 -05:00
|
|
|
|
2020-03-04 15:13:35 +02:00
|
|
|
for (i = 0; i < iters; i++) {
|
2018-05-17 00:12:46 +03:00
|
|
|
CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar, NULL, NULL) == 1);
|
2015-05-15 14:46:08 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-09 12:02:27 -05:00
|
|
|
static void run_ecdh_bench(int iters, int argc, char** argv) {
|
2017-12-18 18:22:09 -08:00
|
|
|
bench_ecdh_data data;
|
2021-11-05 17:48:18 -04:00
|
|
|
int d = argc == 1;
|
2015-05-15 14:46:08 -05:00
|
|
|
|
2025-09-16 23:01:06 +02:00
|
|
|
data.ctx = secp256k1_context_static;
|
2020-03-04 14:14:51 +02:00
|
|
|
|
2021-11-05 17:48:18 -04:00
|
|
|
if (d || have_flag(argc, argv, "ecdh")) run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters);
|
2015-05-15 14:46:08 -05:00
|
|
|
}
|
2021-10-17 12:10:23 -04:00
|
|
|
|
|
|
|
|
#endif /* SECP256K1_MODULE_ECDH_BENCH_H */
|