]>
Commit | Line | Data |
---|---|---|
71712b27 | 1 | /********************************************************************** |
9f443be0 | 2 | * Copyright (c) 2014-2015 Pieter Wuille * |
71712b27 GM |
3 | * Distributed under the MIT software license, see the accompanying * |
4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* | |
5 | **********************************************************************/ | |
78239167 | 6 | |
bae6a42b | 7 | #include "include/secp256k1.h" |
9f443be0 | 8 | #include "include/secp256k1_recovery.h" |
01097ddf | 9 | #include "util.h" |
6558a267 | 10 | #include "bench.h" |
d06e61cb | 11 | |
6558a267 | 12 | typedef struct { |
dd891e0e | 13 | secp256k1_context *ctx; |
01097ddf PW |
14 | unsigned char msg[32]; |
15 | unsigned char sig[64]; | |
1f46d608 | 16 | } bench_recover_data; |
01097ddf | 17 | |
6558a267 | 18 | void bench_recover(void* arg) { |
f735446c | 19 | int i; |
1f46d608 | 20 | bench_recover_data *data = (bench_recover_data*)arg; |
dd891e0e | 21 | secp256k1_pubkey pubkey; |
23cfa914 | 22 | unsigned char pubkeyc[33]; |
f735446c GM |
23 | |
24 | for (i = 0; i < 20000; i++) { | |
25 | int j; | |
788038d3 | 26 | size_t pubkeylen = 33; |
dd891e0e | 27 | secp256k1_ecdsa_recoverable_signature sig; |
439d34ad | 28 | CHECK(secp256k1_ecdsa_recoverable_signature_parse_compact(data->ctx, &sig, data->sig, i % 2)); |
dc0ce9fc | 29 | CHECK(secp256k1_ecdsa_recover(data->ctx, &pubkey, &sig, data->msg)); |
486b9bb8 | 30 | CHECK(secp256k1_ec_pubkey_serialize(data->ctx, pubkeyc, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED)); |
f735446c | 31 | for (j = 0; j < 32; j++) { |
6558a267 PW |
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. */ | |
23cfa914 | 34 | data->sig[j] = pubkeyc[j + 1]; /* Move recovered pubkey X coordinate to R (which must be a valid X coordinate). */ |
01097ddf | 35 | } |
bae6a42b | 36 | } |
6558a267 PW |
37 | } |
38 | ||
39 | void bench_recover_setup(void* arg) { | |
f735446c | 40 | int i; |
1f46d608 | 41 | bench_recover_data *data = (bench_recover_data*)arg; |
6558a267 | 42 | |
912f203f GM |
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 | } | |
6558a267 PW |
49 | } |
50 | ||
51 | int main(void) { | |
1f46d608 | 52 | bench_recover_data data; |
a9b6595e PW |
53 | |
54 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY); | |
01097ddf | 55 | |
039723d5 | 56 | run_benchmark("ecdsa_recover", bench_recover, bench_recover_setup, NULL, &data, 10, 20000); |
910d0de4 | 57 | |
a9b6595e | 58 | secp256k1_context_destroy(data.ctx); |
607884fc PW |
59 | return 0; |
60 | } |