Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/bench_ecdh.c
Show All 9 Lines | |||||
#include "include/secp256k1_ecdh.h" | #include "include/secp256k1_ecdh.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "bench.h" | #include "bench.h" | ||||
typedef struct { | typedef struct { | ||||
secp256k1_context *ctx; | secp256k1_context *ctx; | ||||
secp256k1_pubkey point; | secp256k1_pubkey point; | ||||
unsigned char scalar[32]; | unsigned char scalar[32]; | ||||
} bench_ecdh; | } bench_ecdh_data; | ||||
static void bench_ecdh_setup(void* arg) { | static void bench_ecdh_setup(void* arg) { | ||||
int i; | int i; | ||||
bench_ecdh *data = (bench_ecdh*)arg; | bench_ecdh_data *data = (bench_ecdh_data*)arg; | ||||
const unsigned char point[] = { | const unsigned char point[] = { | ||||
0x03, | 0x03, | ||||
0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06, | 0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06, | ||||
0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd, | 0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd, | ||||
0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb, | 0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb, | ||||
0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f | 0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f | ||||
}; | }; | ||||
/* create a context with no capabilities */ | /* create a context with no capabilities */ | ||||
data->ctx = secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT); | data->ctx = secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT); | ||||
for (i = 0; i < 32; i++) { | for (i = 0; i < 32; i++) { | ||||
data->scalar[i] = i + 1; | data->scalar[i] = i + 1; | ||||
} | } | ||||
CHECK(secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1); | CHECK(secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1); | ||||
} | } | ||||
static void bench_ecdh(void* arg) { | static void bench_ecdh(void* arg) { | ||||
int i; | int i; | ||||
unsigned char res[32]; | unsigned char res[32]; | ||||
bench_ecdh *data = (bench_ecdh*)arg; | bench_ecdh_data *data = (bench_ecdh_data*)arg; | ||||
for (i = 0; i < 20000; i++) { | for (i = 0; i < 20000; i++) { | ||||
CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar) == 1); | CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar) == 1); | ||||
} | } | ||||
} | } | ||||
int main(void) { | int main(void) { | ||||
bench_ecdh data; | bench_ecdh_data data; | ||||
run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, 20000); | run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, 20000); | ||||
return 0; | return 0; | ||||
} | } |