|
| 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