From a6d9c2d0cb5262b367c011698400129ed3b94278 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Fri, 15 May 2015 14:46:08 -0500 Subject: [PATCH] Add benchmark for ECDH multiplication --- .gitignore | 1 + Makefile.am | 6 +++++- src/bench_ecdh.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/bench_ecdh.c diff --git a/.gitignore b/.gitignore index 076ff1295f..a697a794cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bench_inv +bench_ecdh bench_sign bench_verify bench_recover diff --git a/Makefile.am b/Makefile.am index 5adba36fe6..ea9770e011 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,7 +51,7 @@ libsecp256k1_la_LIBADD = $(SECP_LIBS) noinst_PROGRAMS = if USE_BENCHMARK -noinst_PROGRAMS += bench_verify bench_recover bench_sign bench_internal +noinst_PROGRAMS += bench_verify bench_recover bench_sign bench_internal bench_ecdh bench_verify_SOURCES = src/bench_verify.c bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) bench_verify_LDFLAGS = -static @@ -65,6 +65,10 @@ bench_internal_SOURCES = src/bench_internal.c bench_internal_LDADD = $(SECP_LIBS) bench_internal_LDFLAGS = -static bench_internal_CPPFLAGS = $(SECP_INCLUDES) +bench_ecdh_SOURCES = src/bench_ecdh.c +bench_ecdh_LDADD = libsecp256k1.la $(SECP_LIBS) +bench_ecdh_LDFLAGS = -static +bench_ecdh_CPPFLAGS = $(SECP_INCLUDES) endif if USE_TESTS diff --git a/src/bench_ecdh.c b/src/bench_ecdh.c new file mode 100644 index 0000000000..dc69da2b1e --- /dev/null +++ b/src/bench_ecdh.c @@ -0,0 +1,49 @@ +/********************************************************************** + * Copyright (c) 2015 Pieter Wuille, Andrew Poelstra * + * Distributed under the MIT software license, see the accompanying * + * file COPYING or http://www.opensource.org/licenses/mit-license.php.* + **********************************************************************/ + +#include + +#include "include/secp256k1.h" +#include "util.h" +#include "bench.h" + +typedef struct { + unsigned char point[33]; + int pointlen; + unsigned char scalar[32]; +} bench_multiply_t; + +static void bench_multiply_setup(void* arg) { + int i; + bench_multiply_t *data = (bench_multiply_t*)arg; + 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; + data->pointlen = sizeof(point); + memcpy(data->point, point, data->pointlen); +} + +static void bench_multiply(void* arg) { + int i; + bench_multiply_t *data = (bench_multiply_t*)arg; + + for (i = 0; i < 20000; i++) { + CHECK(secp256k1_point_multiply(data->point, &data->pointlen, data->scalar) == 1); + } +} + +int main(void) { + bench_multiply_t data; + + run_benchmark("ecdh_mult", bench_multiply, bench_multiply_setup, NULL, &data, 10, 20000); + return 0; +}