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 **********************************************************************/
7 #include "include/secp256k1.h"
12 secp256k1_context_t *ctx;
13 unsigned char msg[32];
14 unsigned char sig[64];
17 void bench_recover(void* arg) {
19 bench_recover_t *data = (bench_recover_t*)arg;
20 secp256k1_pubkey_t pubkey;
21 unsigned char pubkeyc[33];
23 for (i = 0; i < 20000; i++) {
26 secp256k1_ecdsa_signature_t sig;
27 CHECK(secp256k1_ecdsa_signature_parse_compact(data->ctx, &sig, data->sig, i % 2));
28 CHECK(secp256k1_ecdsa_recover(data->ctx, data->msg, &sig, &pubkey));
29 CHECK(secp256k1_ec_pubkey_serialize(data->ctx, pubkeyc, &pubkeylen, &pubkey, 1));
30 for (j = 0; j < 32; j++) {
31 data->sig[j + 32] = data->msg[j]; /* Move former message to S. */
32 data->msg[j] = data->sig[j]; /* Move former R to message. */
33 data->sig[j] = pubkeyc[j + 1]; /* Move recovered pubkey X coordinate to R (which must be a valid X coordinate). */
38 void bench_recover_setup(void* arg) {
40 bench_recover_t *data = (bench_recover_t*)arg;
42 for (i = 0; i < 32; i++) data->msg[i] = 1 + i;
43 for (i = 0; i < 64; i++) data->sig[i] = 65 + i;
49 data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY);
51 run_benchmark("ecdsa_recover", bench_recover, bench_recover_setup, NULL, &data, 10, 20000);
53 secp256k1_context_destroy(data.ctx);