0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-21 12:22:50 -05:00
bitcoin-bitcoin-core/src/bench_verify.c

45 lines
1.5 KiB
C
Raw Normal View History

/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
**********************************************************************/
2013-05-05 00:21:03 +02:00
2013-03-16 15:51:55 +01:00
#include <stdio.h>
2014-10-31 03:17:44 -07:00
#include <string.h>
2013-03-16 15:51:55 +01:00
2014-09-29 08:20:07 +02:00
#include "include/secp256k1.h"
2014-10-31 03:15:25 -07:00
#include "util.h"
2013-04-20 23:34:41 +02:00
int main(void) {
2014-09-29 08:20:07 +02:00
secp256k1_start(SECP256K1_START_VERIFY);
2013-03-30 22:32:16 +01:00
2014-10-31 03:15:25 -07:00
unsigned char msg[32];
unsigned char sig[64];
for (int i = 0; i < 32; i++) msg[i] = 1 + i;
for (int i = 0; i < 64; i++) sig[i] = 65 + i;
unsigned char pubkey[33];
2013-03-16 15:51:55 +01:00
for (int i=0; i<1000000; i++) {
2014-10-31 03:15:25 -07:00
int pubkeylen = 33;
CHECK(secp256k1_ecdsa_recover_compact(msg, 32, sig, pubkey, &pubkeylen, 1, i % 2));
for (int j = 0; j < 32; j++) {
sig[j + 32] = msg[j]; /* Move former message to S. */
msg[j] = sig[j]; /* Move former R to message. */
sig[j] = pubkey[j + 1]; /* Move recovered pubkey X coordinate to R (which must be a valid X coordinate). */
2014-10-31 03:15:25 -07:00
}
2014-09-29 08:20:07 +02:00
}
2014-10-31 03:15:25 -07:00
static const unsigned char fini[33] = {
0x02,
0x52, 0x63, 0xae, 0x9a, 0x9d, 0x47, 0x1f, 0x1a,
0xb2, 0x36, 0x65, 0x89, 0x11, 0xe7, 0xcc, 0x86,
0xa3, 0xab, 0x97, 0xb6, 0xf1, 0xaf, 0xfd, 0x8f,
0x9b, 0x38, 0xb6, 0x18, 0x55, 0xe5, 0xc2, 0x43
};
CHECK(memcmp(fini, pubkey, 33) == 0);
2013-03-30 22:32:16 +01:00
2014-09-29 08:20:07 +02:00
secp256k1_stop();
2013-03-16 15:51:55 +01:00
return 0;
}