Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
bench_impl.h
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
#ifndef SECP256K1_MODULE_RECOVERY_BENCH_H
8
#define SECP256K1_MODULE_RECOVERY_BENCH_H
9
10
#include "
../../../include/secp256k1_recovery.h
"
11
12
typedef
struct
{
13
secp256k1_context
*
ctx
;
14
unsigned
char
msg
[32];
15
unsigned
char
sig
[64];
16
}
bench_recover_data
;
17
18
static
void
bench_recover(
void
* arg,
int
iters) {
19
int
i;
20
bench_recover_data
*data = (
bench_recover_data
*)arg;
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;
27
secp256k1_ecdsa_recoverable_signature
sig;
28
CHECK
(
secp256k1_ecdsa_recoverable_signature_parse_compact
(data->
ctx
, &sig, data->
sig
, i % 2));
29
CHECK
(
secp256k1_ecdsa_recover
(data->
ctx
, &pubkey, &sig, data->
msg
));
30
CHECK
(
secp256k1_ec_pubkey_serialize
(data->
ctx
, pubkeyc, &pubkeylen, &pubkey,
SECP256K1_EC_COMPRESSED
));
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
39
static
void
bench_recover_setup(
void
* arg) {
40
int
i;
41
bench_recover_data
*data = (
bench_recover_data
*)arg;
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
51
static
void
run_recovery_bench(
int
iters,
int
argc,
char
** argv) {
52
bench_recover_data
data;
53
int
d = argc == 1;
54
55
data.
ctx
=
secp256k1_context_create
(
SECP256K1_CONTEXT_NONE
);
56
57
if
(d || have_flag(argc, argv,
"ecdsa"
) || have_flag(argc, argv,
"recover"
) || have_flag(argc, argv,
"ecdsa_recover"
)) run_benchmark(
"ecdsa_recover"
, bench_recover, bench_recover_setup, NULL, &data, 10, iters);
58
59
secp256k1_context_destroy
(data.
ctx
);
60
}
61
62
#endif
/* SECP256K1_MODULE_RECOVERY_BENCH_H */
CHECK
#define CHECK(cond)
Definition
util.h:81
secp256k1_context_destroy
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
secp256k1_context
struct secp256k1_context_struct secp256k1_context
Definition
secp256k1.h:50
secp256k1_ec_pubkey_serialize
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)
secp256k1_context_create
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
SECP256K1_CONTEXT_NONE
#define SECP256K1_CONTEXT_NONE
Definition
secp256k1.h:203
SECP256K1_EC_COMPRESSED
#define SECP256K1_EC_COMPRESSED
Definition
secp256k1.h:213
secp256k1_recovery.h
secp256k1_ecdsa_recoverable_signature_parse_compact
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)
Definition
main_impl.h:38
secp256k1_ecdsa_recover
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)
Definition
main_impl.h:137
bench_recover_data
Definition
bench_impl.h:12
bench_recover_data::msg
unsigned char msg[32]
Definition
bench_impl.h:14
bench_recover_data::ctx
secp256k1_context * ctx
Definition
bench_impl.h:13
bench_recover_data::sig
unsigned char sig[64]
Definition
bench_impl.h:15
secp256k1_ecdsa_recoverable_signature
Definition
secp256k1_recovery.h:24
secp256k1_pubkey
Definition
secp256k1.h:74
external
secp256k1
src
modules
recovery
bench_impl.h
Generated on
for Electroneum by
1.17.0