Bitcoin Core  0.19.99
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 http://www.opensource.org/licenses/mit-license.php.*
5  **********************************************************************/
6 
7 #include "include/secp256k1.h"
8 #include "util.h"
9 #include "bench.h"
10 
11 typedef struct {
13  unsigned char msg[32];
14  unsigned char key[32];
15 } bench_sign;
16 
17 static void bench_sign_setup(void* arg) {
18  int i;
19  bench_sign *data = (bench_sign*)arg;
20 
21  for (i = 0; i < 32; i++) {
22  data->msg[i] = i + 1;
23  }
24  for (i = 0; i < 32; i++) {
25  data->key[i] = i + 65;
26  }
27 }
28 
29 static void bench_sign_run(void* arg) {
30  int i;
31  bench_sign *data = (bench_sign*)arg;
32 
33  unsigned char sig[74];
34  for (i = 0; i < 20000; i++) {
35  size_t siglen = 74;
36  int j;
37  secp256k1_ecdsa_signature signature;
38  CHECK(secp256k1_ecdsa_sign(data->ctx, &signature, data->msg, data->key, NULL, NULL));
39  CHECK(secp256k1_ecdsa_signature_serialize_der(data->ctx, sig, &siglen, &signature));
40  for (j = 0; j < 32; j++) {
41  data->msg[j] = sig[j];
42  data->key[j] = sig[j + 32];
43  }
44  }
45 }
46 
47 int main(void) {
48  bench_sign data;
49 
51 
52  run_benchmark("ecdsa_sign", bench_sign_run, bench_sign_setup, NULL, &data, 10, 20000);
53 
55  return 0;
56 }
#define SECP256K1_CONTEXT_SIGN
Definition: secp256k1.h:168
int main(void)
Definition: bench_sign.c:47
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object.
Definition: secp256k1.c:101
void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
Definition: bench.h:34
static void bench_sign_setup(void *arg)
Definition: bench_sign.c:17
SECP256K1_API int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, 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)
Create an ECDSA signature.
Definition: secp256k1.c:369
unsigned char key[32]
Definition: bench_sign.c:14
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:79
#define CHECK(cond)
Definition: util.h:52
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:270
unsigned char msg[32]
Definition: bench_sign.c:13
static void bench_sign_run(void *arg)
Definition: bench_sign.c:29
secp256k1_context * ctx
Definition: bench_sign.c:12
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object.
Definition: secp256k1.c:67