]> Git Repo - secp256k1.git/blame - src/bench_ecdh.c
Merge #930: Add ARM32/ARM64 CI
[secp256k1.git] / src / bench_ecdh.c
CommitLineData
07aa4c70
DA
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 ***********************************************************************/
91c0ce95
AP
6
7#include <string.h>
8
3c90bdda
WB
9#include "../include/secp256k1.h"
10#include "../include/secp256k1_ecdh.h"
91c0ce95
AP
11#include "util.h"
12#include "bench.h"
13
14typedef struct {
dd891e0e
PW
15 secp256k1_context *ctx;
16 secp256k1_pubkey point;
91c0ce95 17 unsigned char scalar[32];
1f46d608 18} bench_ecdh_data;
91c0ce95
AP
19
20static void bench_ecdh_setup(void* arg) {
21 int i;
1f46d608 22 bench_ecdh_data *data = (bench_ecdh_data*)arg;
91c0ce95
AP
23 const unsigned char point[] = {
24 0x03,
25 0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06,
26 0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd,
27 0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb,
28 0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f
29 };
30
912f203f
GM
31 for (i = 0; i < 32; i++) {
32 data->scalar[i] = i + 1;
33 }
91c0ce95
AP
34 CHECK(secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1);
35}
36
ca4906b0 37static void bench_ecdh(void* arg, int iters) {
91c0ce95
AP
38 int i;
39 unsigned char res[32];
1f46d608 40 bench_ecdh_data *data = (bench_ecdh_data*)arg;
91c0ce95 41
ca4906b0 42 for (i = 0; i < iters; i++) {
c8fbc3c3 43 CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar, NULL, NULL) == 1);
91c0ce95
AP
44 }
45}
46
47int main(void) {
1f46d608 48 bench_ecdh_data data;
91c0ce95 49
ca4906b0
ET
50 int iters = get_iters(20000);
51
02dd5f1b
ET
52 /* create a context with no capabilities */
53 data.ctx = secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT);
54
ca4906b0 55 run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters);
02dd5f1b
ET
56
57 secp256k1_context_destroy(data.ctx);
91c0ce95
AP
58 return 0;
59}
This page took 0.035611 seconds and 4 git commands to generate.