2020-12-29 17:15:51 +00: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-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-06-14 14:55:38 +00:00
|
|
|
#include "../include/secp256k1.h"
|
|
|
|
#include "../include/secp256k1_ecdh.h"
|
2015-10-26 14:54:21 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "bench.h"
|
|
|
|
|
|
|
|
typedef struct {
|
2021-06-14 14:55:38 +00:00
|
|
|
rustsecp256k1_v0_4_1_context *ctx;
|
|
|
|
rustsecp256k1_v0_4_1_pubkey point;
|
2015-10-26 14:54:21 +00:00
|
|
|
unsigned char scalar[32];
|
2018-07-09 11:17:44 +00:00
|
|
|
} bench_ecdh_data;
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
static void bench_ecdh_setup(void* arg) {
|
|
|
|
int i;
|
2018-07-09 11:17:44 +00:00
|
|
|
bench_ecdh_data *data = (bench_ecdh_data*)arg;
|
2015-10-26 14:54:21 +00: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
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
data->scalar[i] = i + 1;
|
|
|
|
}
|
2021-06-14 14:55:38 +00:00
|
|
|
CHECK(rustsecp256k1_v0_4_1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1);
|
2015-10-26 14:54:21 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 17:35:27 +00:00
|
|
|
static void bench_ecdh(void* arg, int iters) {
|
2015-10-26 14:54:21 +00:00
|
|
|
int i;
|
|
|
|
unsigned char res[32];
|
2018-07-09 11:17:44 +00:00
|
|
|
bench_ecdh_data *data = (bench_ecdh_data*)arg;
|
2015-10-26 14:54:21 +00:00
|
|
|
|
2020-08-26 17:35:27 +00:00
|
|
|
for (i = 0; i < iters; i++) {
|
2021-06-14 14:55:38 +00:00
|
|
|
CHECK(rustsecp256k1_v0_4_1_ecdh(data->ctx, res, &data->point, data->scalar, NULL, NULL) == 1);
|
2015-10-26 14:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
2018-07-09 11:17:44 +00:00
|
|
|
bench_ecdh_data data;
|
2015-10-26 14:54:21 +00:00
|
|
|
|
2020-08-26 17:35:27 +00:00
|
|
|
int iters = get_iters(20000);
|
|
|
|
|
|
|
|
/* create a context with no capabilities */
|
2021-06-14 14:55:38 +00:00
|
|
|
data.ctx = rustsecp256k1_v0_4_1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT);
|
2020-08-26 17:35:27 +00:00
|
|
|
|
|
|
|
run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters);
|
|
|
|
|
2021-06-14 14:55:38 +00:00
|
|
|
rustsecp256k1_v0_4_1_context_destroy(data.ctx);
|
2015-10-26 14:54:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|