Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/bench_verify.c
/********************************************************************** | /********************************************************************** | ||||
* Copyright (c) 2014 Pieter Wuille * | * Copyright (c) 2014 Pieter Wuille * | ||||
* Distributed under the MIT software license, see the accompanying * | * Distributed under the MIT software license, see the accompanying * | ||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.* | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* | ||||
**********************************************************************/ | **********************************************************************/ | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "include/secp256k1.h" | #include "include/secp256k1.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "bench.h" | #include "bench.h" | ||||
#ifdef ENABLE_MODULE_SCHNORR | |||||
#include "include/secp256k1_schnorr.h" | |||||
#endif | |||||
#ifdef ENABLE_OPENSSL_TESTS | #ifdef ENABLE_OPENSSL_TESTS | ||||
#include <openssl/bn.h> | #include <openssl/bn.h> | ||||
#include <openssl/ecdsa.h> | #include <openssl/ecdsa.h> | ||||
#include <openssl/obj_mac.h> | #include <openssl/obj_mac.h> | ||||
#endif | #endif | ||||
typedef struct { | typedef struct { | ||||
secp256k1_context *ctx; | secp256k1_context *ctx; | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | for (i = 0; i < 20000; i++) { | ||||
} | } | ||||
data->sig[data->siglen - 1] ^= (i & 0xFF); | data->sig[data->siglen - 1] ^= (i & 0xFF); | ||||
data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF); | data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF); | ||||
data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF); | data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF); | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
#ifdef ENABLE_MODULE_SCHNORR | |||||
static void benchmark_schnorr_verify(void* arg) { | |||||
int i; | |||||
benchmark_verify_t* data = (benchmark_verify_t*)arg; | |||||
for (i = 0; i < 20000; i++) { | |||||
secp256k1_pubkey pubkey; | |||||
data->sig[data->siglen - 1] ^= (i & 0xFF); | |||||
data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF); | |||||
data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF); | |||||
CHECK(secp256k1_ec_pubkey_parse(data->ctx, &pubkey, data->pubkey, data->pubkeylen) == 1); | |||||
CHECK(secp256k1_schnorr_verify(data->ctx, data->sig, data->msg, &pubkey) == (i == 0)); | |||||
data->sig[data->siglen - 1] ^= (i & 0xFF); | |||||
data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF); | |||||
data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF); | |||||
} | |||||
} | |||||
#endif | |||||
int main(void) { | int main(void) { | ||||
int i; | int i; | ||||
secp256k1_pubkey pubkey; | secp256k1_pubkey pubkey; | ||||
secp256k1_ecdsa_signature sig; | secp256k1_ecdsa_signature sig; | ||||
benchmark_verify_t data; | benchmark_verify_t data; | ||||
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); | ||||
Show All 11 Lines | int main(void) { | ||||
CHECK(secp256k1_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED) == 1); | CHECK(secp256k1_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED) == 1); | ||||
run_benchmark("ecdsa_verify", benchmark_verify, NULL, NULL, &data, 10, 20000); | run_benchmark("ecdsa_verify", benchmark_verify, NULL, NULL, &data, 10, 20000); | ||||
#ifdef ENABLE_OPENSSL_TESTS | #ifdef ENABLE_OPENSSL_TESTS | ||||
data.ec_group = EC_GROUP_new_by_curve_name(NID_secp256k1); | data.ec_group = EC_GROUP_new_by_curve_name(NID_secp256k1); | ||||
run_benchmark("ecdsa_verify_openssl", benchmark_verify_openssl, NULL, NULL, &data, 10, 20000); | run_benchmark("ecdsa_verify_openssl", benchmark_verify_openssl, NULL, NULL, &data, 10, 20000); | ||||
EC_GROUP_free(data.ec_group); | EC_GROUP_free(data.ec_group); | ||||
#endif | #endif | ||||
#ifdef ENABLE_MODULE_SCHNORR | |||||
CHECK(secp256k1_schnorr_sign(data.ctx, data.sig, data.msg, data.key, NULL, NULL)); | |||||
data.siglen = 64; | |||||
run_benchmark("schnorr_verify", benchmark_schnorr_verify, NULL, NULL, &data, 10, 20000); | |||||
#endif | |||||
secp256k1_context_destroy(data.ctx); | secp256k1_context_destroy(data.ctx); | ||||
return 0; | return 0; | ||||
} | } |