PRCYCoin  2.0.0.7rc1
P2P Digital Currency
bench_verify.c
Go to the documentation of this file.
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  **********************************************************************/
6 
7 #include <stdio.h>
8 #include <string.h>
9 
10 #include "include/secp256k1.h"
11 #include "util.h"
12 
13 int main(void) {
15 
16  unsigned char msg[32];
17  unsigned char sig[64];
18 
19  for (int i = 0; i < 32; i++) msg[i] = 1 + i;
20  for (int i = 0; i < 64; i++) sig[i] = 65 + i;
21 
22  unsigned char pubkey[33];
23  for (int i=0; i<1000000; i++) {
24  int pubkeylen = 33;
25  CHECK(secp256k1_ecdsa_recover_compact(msg, 32, sig, pubkey, &pubkeylen, 1, i % 2));
26  for (int j = 0; j < 32; j++) {
27  sig[j + 32] = msg[j]; /* Move former message to S. */
28  msg[j] = sig[j]; /* Move former R to message. */
29  sig[j] = pubkey[j + 1]; /* Move recovered pubkey X coordinate to R (which must be a valid X coordinate). */
30  }
31  }
32 
33  static const unsigned char fini[33] = {
34  0x02,
35  0x52, 0x63, 0xae, 0x9a, 0x9d, 0x47, 0x1f, 0x1a,
36  0xb2, 0x36, 0x65, 0x89, 0x11, 0xe7, 0xcc, 0x86,
37  0xa3, 0xab, 0x97, 0xb6, 0xf1, 0xaf, 0xfd, 0x8f,
38  0x9b, 0x38, 0xb6, 0x18, 0x55, 0xe5, 0xc2, 0x43
39  };
40  CHECK(memcmp(fini, pubkey, 33) == 0);
41 
43  return 0;
44 }
secp256k1_start
void secp256k1_start(unsigned int flags)
Initialize the library.
Definition: secp256k1.c:21
SECP256K1_START_VERIFY
#define SECP256K1_START_VERIFY
Flags to pass to secp256k1_start.
Definition: secp256k1.h:45
util.h
secp256k1.h
secp256k1_ecdsa_recover_compact
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover_compact(const unsigned char *msg, int msglen, const unsigned char *sig64, unsigned char *pubkey, int *pubkeylen, int compressed, int recid) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5)
Recover an ECDSA public key from a compact signature.
Definition: secp256k1.c:141
secp256k1_stop
void secp256k1_stop(void)
Free all memory associated with this library.
Definition: secp256k1.c:34
main
int main(void)
Definition: bench_verify.c:13
CHECK
#define CHECK(cond)
Definition: util.h:43