1 /**********************************************************************
2 * Copyright (c) 2014 Pieter Wuille *
3 * Distributed under the MIT software license, see the accompanying *
4 * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
5 **********************************************************************/
10 #include "include/secp256k1.h"
15 secp256k1_context *ctx;
16 unsigned char msg[32];
17 unsigned char key[32];
18 unsigned char sig[72];
20 unsigned char pubkey[33];
24 static void benchmark_verify(void* arg) {
26 benchmark_verify_t* data = (benchmark_verify_t*)arg;
28 for (i = 0; i < 20000; i++) {
29 secp256k1_pubkey pubkey;
30 secp256k1_ecdsa_signature sig;
31 data->sig[data->siglen - 1] ^= (i & 0xFF);
32 data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF);
33 data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF);
34 CHECK(secp256k1_ec_pubkey_parse(data->ctx, &pubkey, data->pubkey, data->pubkeylen) == 1);
35 CHECK(secp256k1_ecdsa_signature_parse_der(data->ctx, &sig, data->sig, data->siglen) == 1);
36 CHECK(secp256k1_ecdsa_verify(data->ctx, &sig, data->msg, &pubkey) == (i == 0));
37 data->sig[data->siglen - 1] ^= (i & 0xFF);
38 data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF);
39 data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF);
45 secp256k1_pubkey pubkey;
46 secp256k1_ecdsa_signature sig;
47 benchmark_verify_t data;
49 data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
51 for (i = 0; i < 32; i++) {
54 for (i = 0; i < 32; i++) {
58 CHECK(secp256k1_ecdsa_sign(data.ctx, &sig, data.msg, data.key, NULL, NULL));
59 CHECK(secp256k1_ecdsa_signature_serialize_der(data.ctx, data.sig, &data.siglen, &sig));
60 CHECK(secp256k1_ec_pubkey_create(data.ctx, &pubkey, data.key));
61 CHECK(secp256k1_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED) == 1);
63 run_benchmark("ecdsa_verify", benchmark_verify, NULL, NULL, &data, 10, 20000);
65 secp256k1_context_destroy(data.ctx);