Dash Core  0.12.2.1
P2P Digital Currency
bench_schnorr_verify.c
Go to the documentation of this file.
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"
12 #include "util.h"
13 #include "bench.h"
14 
15 typedef struct {
16  unsigned char key[32];
17  unsigned char sig[64];
18  unsigned char pubkey[33];
19  size_t pubkeylen;
21 
22 typedef struct {
24  unsigned char msg[32];
26  int numsigs;
28 
29 static void benchmark_schnorr_init(void* arg) {
30  int i, k;
32 
33  for (i = 0; i < 32; i++) {
34  data->msg[i] = 1 + i;
35  }
36  for (k = 0; k < data->numsigs; k++) {
37  secp256k1_pubkey pubkey;
38  for (i = 0; i < 32; i++) {
39  data->sigs[k].key[i] = 33 + i + k;
40  }
41  secp256k1_schnorr_sign(data->ctx, data->sigs[k].sig, data->msg, data->sigs[k].key, NULL, NULL);
42  data->sigs[k].pubkeylen = 33;
43  CHECK(secp256k1_ec_pubkey_create(data->ctx, &pubkey, data->sigs[k].key));
44  CHECK(secp256k1_ec_pubkey_serialize(data->ctx, data->sigs[k].pubkey, &data->sigs[k].pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED));
45  }
46 }
47 
48 static void benchmark_schnorr_verify(void* arg) {
49  int i;
51 
52  for (i = 0; i < 20000 / data->numsigs; i++) {
53  secp256k1_pubkey pubkey;
54  data->sigs[0].sig[(i >> 8) % 64] ^= (i & 0xFF);
55  CHECK(secp256k1_ec_pubkey_parse(data->ctx, &pubkey, data->sigs[0].pubkey, data->sigs[0].pubkeylen));
56  CHECK(secp256k1_schnorr_verify(data->ctx, data->sigs[0].sig, data->msg, &pubkey) == ((i & 0xFF) == 0));
57  data->sigs[0].sig[(i >> 8) % 64] ^= (i & 0xFF);
58  }
59 }
60 
61 
62 
63 int main(void) {
65 
67 
68  data.numsigs = 1;
69  run_benchmark("schnorr_verify", benchmark_schnorr_verify, benchmark_schnorr_init, NULL, &data, 10, 20000);
70 
72  return 0;
73 }
static void benchmark_schnorr_verify(void *arg)
SECP256K1_API int secp256k1_schnorr_sign(const secp256k1_context *ctx, unsigned char *sig64, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition: main_impl.h:23
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition: secp256k1.c:168
#define SECP256K1_CONTEXT_SIGN
Definition: secp256k1.h:161
static void benchmark_schnorr_init(void *arg)
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Definition: secp256k1.c:94
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Definition: secp256k1.c:409
#define SECP256K1_EC_COMPRESSED
Definition: secp256k1.h:165
void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
Definition: bench.h:33
int main(void)
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Definition: secp256k1.c:152
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_verify(const secp256k1_context *ctx, const unsigned char *sig64, const unsigned char *msg32, const secp256k1_pubkey *pubkey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition: main_impl.h:61
#define CHECK(cond)
Definition: util.h:52
#define SECP256K1_CONTEXT_VERIFY
Definition: secp256k1.h:160
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Definition: secp256k1.c:60