github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/crypto/secp256k1/libsecp256k1/src/bench_ecdh.c (about) 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 "include/secp256k1_ecdh.h" 11 #include "util.h" 12 #include "bench.h" 13 14 typedef struct { 15 secp256k1_context *ctx; 16 secp256k1_pubkey point; 17 unsigned char scalar[32]; 18 } bench_ecdh_t; 19 20 static void bench_ecdh_setup(void* arg) { 21 int i; 22 bench_ecdh_t *data = (bench_ecdh_t*)arg; 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 31 data->ctx = secp256k1_context_create(0); 32 for (i = 0; i < 32; i++) { 33 data->scalar[i] = i + 1; 34 } 35 CHECK(secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1); 36 } 37 38 static void bench_ecdh(void* arg) { 39 int i; 40 unsigned char res[32]; 41 bench_ecdh_t *data = (bench_ecdh_t*)arg; 42 43 for (i = 0; i < 20000; i++) { 44 CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar) == 1); 45 } 46 } 47 48 int main(void) { 49 bench_ecdh_t data; 50 51 run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, 20000); 52 return 0; 53 }