Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
bench_recover.c
Go to the documentation of this file.
1/***********************************************************************
2 * Copyright (c) 2014-2015 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"
9#include "util.h"
10#include "bench.h"
11
12typedef struct {
14 unsigned char msg[32];
15 unsigned char sig[64];
17
18void bench_recover(void* arg, int iters) {
19 int i;
21 secp256k1_pubkey pubkey;
22 unsigned char pubkeyc[33];
23
24 for (i = 0; i < iters; i++) {
25 int j;
26 size_t pubkeylen = 33;
29 CHECK(secp256k1_ecdsa_recover(data->ctx, &pubkey, &sig, data->msg));
31 for (j = 0; j < 32; j++) {
32 data->sig[j + 32] = data->msg[j]; /* Move former message to S. */
33 data->msg[j] = data->sig[j]; /* Move former R to message. */
34 data->sig[j] = pubkeyc[j + 1]; /* Move recovered pubkey X coordinate to R (which must be a valid X coordinate). */
35 }
36 }
37}
38
40 int i;
42
43 for (i = 0; i < 32; i++) {
44 data->msg[i] = 1 + i;
45 }
46 for (i = 0; i < 64; i++) {
47 data->sig[i] = 65 + i;
48 }
49}
50
51int main(void) {
53
54 int iters = get_iters(20000);
55
57
58 run_benchmark("ecdsa_recover", bench_recover, bench_recover_setup, NULL, &data, 10, iters);
59
61 return 0;
62}
static void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
Definition bench.c:26
void bench_recover_setup(void *arg)
void bench_recover(void *arg, int iters)
int main(void)
SchnorrSig sig
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
int get_iters(int default_iters)
Definition bench.h:124
#define CHECK(cond)
Definition util.h:53
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)
Serialize a pubkey object into a serialized byte sequence.
Definition secp256k1.c:296
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
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize.
Definition secp256k1.h:176
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size, and secp256k1_context...
Definition secp256k1.h:170
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_ecdsa_recoverable_signature_parse_compact(const secp256k1_context *ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *input64, int recid) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a compact ECDSA signature (64 bytes + recovery id).
Definition main_impl.h:38
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msghash32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Recover an ECDSA public key from a signature.
Definition main_impl.h:138
unsigned char msg[32]
secp256k1_context * ctx
unsigned char sig[64]
Opaque data structured that holds a parsed ECDSA signature, supporting pubkey recovery.
Opaque data structure that holds a parsed and valid public key.
Definition secp256k1.h:67