]> Git Repo - secp256k1.git/blame - src/bench_verify.c
Implement endomorphism optimization for secp256k1_ecmult_const
[secp256k1.git] / src / bench_verify.c
CommitLineData
6558a267
PW
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 **********************************************************************/
6
7#include <stdio.h>
8#include <string.h>
9
10#include "include/secp256k1.h"
11#include "util.h"
12#include "bench.h"
13
14typedef struct {
a9b6595e 15 secp256k1_context_t *ctx;
6558a267
PW
16 unsigned char msg[32];
17 unsigned char key[32];
6558a267
PW
18 unsigned char sig[72];
19 int siglen;
20 unsigned char pubkey[33];
21 int pubkeylen;
22} benchmark_verify_t;
23
24static void benchmark_verify(void* arg) {
f735446c 25 int i;
6558a267
PW
26 benchmark_verify_t* data = (benchmark_verify_t*)arg;
27
f735446c 28 for (i = 0; i < 20000; i++) {
23cfa914 29 secp256k1_pubkey_t pubkey;
74a2acdb 30 secp256k1_ecdsa_signature_t sig;
6558a267
PW
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);
23cfa914 34 CHECK(secp256k1_ec_pubkey_parse(data->ctx, &pubkey, data->pubkey, data->pubkeylen) == 1);
74a2acdb
PW
35 CHECK(secp256k1_ecdsa_signature_parse_der(data->ctx, &sig, data->sig, data->siglen) == 1);
36 CHECK(secp256k1_ecdsa_verify(data->ctx, data->msg, &sig, &pubkey) == (i == 0));
6558a267
PW
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);
40 }
41}
42
43int main(void) {
f735446c 44 int i;
23cfa914 45 secp256k1_pubkey_t pubkey;
74a2acdb 46 secp256k1_ecdsa_signature_t sig;
6558a267
PW
47 benchmark_verify_t data;
48
a9b6595e 49 data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
f735446c
GM
50
51 for (i = 0; i < 32; i++) data.msg[i] = 1 + i;
52 for (i = 0; i < 32; i++) data.key[i] = 33 + i;
6558a267 53 data.siglen = 72;
74a2acdb
PW
54 CHECK(secp256k1_ecdsa_sign(data.ctx, data.msg, &sig, data.key, NULL, NULL));
55 CHECK(secp256k1_ecdsa_signature_serialize_der(data.ctx, data.sig, &data.siglen, &sig));
23cfa914
PW
56 CHECK(secp256k1_ec_pubkey_create(data.ctx, &pubkey, data.key));
57 CHECK(secp256k1_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, 1) == 1);
6558a267 58
039723d5 59 run_benchmark("ecdsa_verify", benchmark_verify, NULL, NULL, &data, 10, 20000);
6558a267 60
a9b6595e 61 secp256k1_context_destroy(data.ctx);
6558a267
PW
62 return 0;
63}
This page took 0.027544 seconds and 4 git commands to generate.