Skip to content

Commit 1ba1824

Browse files
committed
Add benchmark for ECDH multiplication
1 parent 5b58dca commit 1ba1824

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bench_inv
2+
bench_ecdh
23
bench_sign
34
bench_verify
45
bench_recover

Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ libsecp256k1_la_LIBADD = $(SECP_LIBS)
5151

5252
noinst_PROGRAMS =
5353
if USE_BENCHMARK
54-
noinst_PROGRAMS += bench_verify bench_recover bench_sign bench_internal
54+
noinst_PROGRAMS += bench_verify bench_recover bench_sign bench_internal bench_ecdh
5555
bench_verify_SOURCES = src/bench_verify.c
5656
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS)
5757
bench_verify_LDFLAGS = -static
@@ -65,6 +65,10 @@ bench_internal_SOURCES = src/bench_internal.c
6565
bench_internal_LDADD = $(SECP_LIBS)
6666
bench_internal_LDFLAGS = -static
6767
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
68+
bench_ecdh_SOURCES = src/bench_ecdh.c
69+
bench_ecdh_LDADD = libsecp256k1.la $(SECP_LIBS)
70+
bench_ecdh_LDFLAGS = -static
71+
bench_ecdh_CPPFLAGS = $(SECP_INCLUDES)
6872
endif
6973

7074
if USE_TESTS

src/bench_ecdh.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**********************************************************************
2+
* Copyright (c) 2015 Pieter Wuille, Andrew Poelstra *
3+
* Distributed under the MIT software license, see the accompanying *
4+
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
5+
**********************************************************************/
6+
7+
#include <string.h>
8+
9+
#include "include/secp256k1.h"
10+
#include "util.h"
11+
#include "bench.h"
12+
13+
typedef struct {
14+
unsigned char point[33];
15+
int pointlen;
16+
unsigned char scalar[32];
17+
} bench_multiply_t;
18+
19+
static void bench_multiply_setup(void* arg) {
20+
int i;
21+
bench_multiply_t *data = (bench_multiply_t*)arg;
22+
const unsigned char point[] = {
23+
0x03,
24+
0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06,
25+
0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd,
26+
0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb,
27+
0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f
28+
};
29+
30+
for (i = 0; i < 32; i++) data->scalar[i] = i + 1;
31+
data->pointlen = sizeof(point);
32+
memcpy(data->point, point, data->pointlen);
33+
}
34+
35+
static void bench_multiply(void* arg) {
36+
int i;
37+
bench_multiply_t *data = (bench_multiply_t*)arg;
38+
39+
for (i = 0; i < 20000; i++) {
40+
CHECK(secp256k1_point_multiply(data->point, &data->pointlen, data->scalar) == 1);
41+
}
42+
}
43+
44+
int main(void) {
45+
bench_multiply_t data;
46+
47+
run_benchmark("ecdh_mult", bench_multiply, bench_multiply_setup, NULL, &data, 10, 20000);
48+
return 0;
49+
}

0 commit comments

Comments
 (0)