Bitcoin ABC  0.26.3
P2P Digital Currency
bench_sign.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 https://www.opensource.org/licenses/mit-license.php.*
5  ***********************************************************************/
6 
7 #include "include/secp256k1.h"
8 #include "util.h"
9 #include "bench.h"
10 
11 #ifdef ENABLE_MODULE_SCHNORR
13 #endif
14 
15 
16 typedef struct {
18  unsigned char msg[32];
19  unsigned char key[32];
21 
22 static void bench_sign_setup(void* arg) {
23  int i;
24  bench_sign_data *data = (bench_sign_data*)arg;
25 
26  for (i = 0; i < 32; i++) {
27  data->msg[i] = i + 1;
28  }
29  for (i = 0; i < 32; i++) {
30  data->key[i] = i + 65;
31  }
32 }
33 
34 static void bench_sign_run(void* arg, int iters) {
35  int i;
36  bench_sign_data *data = (bench_sign_data*)arg;
37 
38  unsigned char sig[74];
39  for (i = 0; i < iters; i++) {
40  size_t siglen = 74;
41  int j;
42  secp256k1_ecdsa_signature signature;
43  CHECK(secp256k1_ecdsa_sign(data->ctx, &signature, data->msg, data->key, NULL, NULL));
44  CHECK(secp256k1_ecdsa_signature_serialize_der(data->ctx, sig, &siglen, &signature));
45  for (j = 0; j < 32; j++) {
46  data->msg[j] = sig[j];
47  data->key[j] = sig[j + 32];
48  }
49  }
50 }
51 
52 #ifdef ENABLE_MODULE_SCHNORR
53 static void bench_schnorr_sign_run(void* arg, int iters) {
54  int i,j;
55  bench_sign_data *data = (bench_sign_data*)arg;
56 
57  unsigned char sig[64];
58  for (i = 0; i < iters; i++) {
59  CHECK(secp256k1_schnorr_sign(data->ctx, sig, data->msg, data->key, NULL, NULL));
60  for (j = 0; j < 32; j++) {
61  data->msg[j] = sig[j];
62  data->key[j] = sig[j + 32];
63  }
64  }
65 }
66 #endif
67 
68 int main(void) {
69  bench_sign_data data;
70 
71  int iters = get_iters(20000);
72 
74 
75  run_benchmark("ecdsa_sign", bench_sign_run, bench_sign_setup, NULL, &data, 10, iters);
76 #ifdef ENABLE_MODULE_SCHNORR
77  run_benchmark("schnorr_sign", bench_schnorr_sign_run, bench_sign_setup, NULL, &data, 10, iters);
78 #endif
79 
81  return 0;
82 }
int main(void)
Definition: bench_sign.c:68
static void bench_sign_setup(void *arg)
Definition: bench_sign.c:22
static void bench_sign_run(void *arg, int iters)
Definition: bench_sign.c:34
SchnorrSig sig
Definition: processor.cpp:491
int get_iters(int default_iters)
Definition: bench.h:124
void run_benchmark(char *name, void(*benchmark)(void *, int), void(*setup)(void *), void(*teardown)(void *, int), void *data, int count, int iter)
Definition: bench.h:76
#define CHECK(cond)
Definition: util.h:53
#define SECP256K1_CONTEXT_SIGN
Definition: secp256k1.h:171
SECP256K1_API int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, 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)
Create an ECDSA signature.
Definition: secp256k1.c:535
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object (in dynamically allocated memory).
Definition: secp256k1.c:152
SECP256K1_API int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature *sig) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize an ECDSA signature in DER format.
Definition: secp256k1.c:380
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object (created in dynamically allocated memory).
Definition: secp256k1.c:196
SECP256K1_API int secp256k1_schnorr_sign(const secp256k1_context *ctx, unsigned char *sig64, const unsigned char *msghash32, 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)
Create a signature using a custom EC-Schnorr-SHA256 construction.
Definition: main_impl.h:33
unsigned char key[32]
Definition: bench_sign.c:19
secp256k1_context * ctx
Definition: bench_sign.c:17
unsigned char msg[32]
Definition: bench_sign.c:18
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:80