]>
Commit | Line | Data |
---|---|---|
71712b27 GM |
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 | **********************************************************************/ | |
fa5c13ff PW |
6 | |
7 | #include "include/secp256k1.h" | |
8 | #include "util.h" | |
6558a267 | 9 | #include "bench.h" |
fa5c13ff | 10 | |
6558a267 | 11 | typedef struct { |
a9b6595e | 12 | secp256k1_context_t* ctx; |
fa5c13ff | 13 | unsigned char msg[32]; |
fa5c13ff | 14 | unsigned char key[32]; |
6558a267 | 15 | } bench_sign_t; |
fa5c13ff | 16 | |
6558a267 | 17 | static void bench_sign_setup(void* arg) { |
f735446c | 18 | int i; |
6558a267 | 19 | bench_sign_t *data = (bench_sign_t*)arg; |
fa5c13ff | 20 | |
f735446c GM |
21 | for (i = 0; i < 32; i++) data->msg[i] = i + 1; |
22 | for (i = 0; i < 32; i++) data->key[i] = i + 65; | |
6558a267 PW |
23 | } |
24 | ||
25 | static void bench_sign(void* arg) { | |
f735446c | 26 | int i; |
6558a267 | 27 | bench_sign_t *data = (bench_sign_t*)arg; |
fa5c13ff | 28 | |
6558a267 | 29 | unsigned char sig[64]; |
f735446c GM |
30 | for (i = 0; i < 20000; i++) { |
31 | int j; | |
fa5c13ff | 32 | int recid = 0; |
74a2acdb PW |
33 | secp256k1_ecdsa_signature_t signature; |
34 | CHECK(secp256k1_ecdsa_sign(data->ctx, data->msg, &signature, data->key, NULL, NULL)); | |
35 | CHECK(secp256k1_ecdsa_signature_serialize_compact(data->ctx, sig, &recid, &signature)); | |
f735446c | 36 | for (j = 0; j < 32; j++) { |
6558a267 PW |
37 | data->msg[j] = sig[j]; /* Move former R to message. */ |
38 | data->key[j] = sig[j + 32]; /* Move former S to key. */ | |
fa5c13ff PW |
39 | } |
40 | } | |
6558a267 PW |
41 | } |
42 | ||
43 | int main(void) { | |
f735446c | 44 | bench_sign_t data; |
a9b6595e PW |
45 | |
46 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); | |
fa5c13ff | 47 | |
039723d5 | 48 | run_benchmark("ecdsa_sign", bench_sign, bench_sign_setup, NULL, &data, 10, 20000); |
fa5c13ff | 49 | |
a9b6595e | 50 | secp256k1_context_destroy(data.ctx); |
fa5c13ff PW |
51 | return 0; |
52 | } |