PRCYCoin  2.0.0.7rc1
P2P Digital Currency
bench_sign.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 #include <stdio.h>
7 #include <string.h>
8 
9 #include "include/secp256k1.h"
10 #include "util.h"
11 
12 int main(void) {
14 
15  unsigned char msg[32];
16  unsigned char nonce[32];
17  unsigned char key[32];
18 
19  for (int i = 0; i < 32; i++) msg[i] = i + 1;
20  for (int i = 0; i < 32; i++) nonce[i] = i + 33;
21  for (int i = 0; i < 32; i++) key[i] = i + 65;
22 
23  unsigned char sig[64];
24 
25  for (int i=0; i<1000000; i++) {
26  int recid = 0;
27  CHECK(secp256k1_ecdsa_sign_compact(msg, 32, sig, key, nonce, &recid));
28  for (int j = 0; j < 32; j++) {
29  nonce[j] = key[j]; /* Move former key to nonce */
30  msg[j] = sig[j]; /* Move former R to message. */
31  key[j] = sig[j + 32]; /* Move former S to key. */
32  }
33  }
34 
35  static const unsigned char fini[64] = {
36  0x92, 0x03, 0xef, 0xf1, 0x58, 0x0b, 0x49, 0x8d,
37  0x22, 0x3d, 0x49, 0x0e, 0xbf, 0x26, 0x50, 0x0e,
38  0x2d, 0x62, 0x90, 0xd7, 0x82, 0xbd, 0x3d, 0x5c,
39  0xa9, 0x10, 0xa5, 0x49, 0xb1, 0xd8, 0x8c, 0xc0,
40  0x5b, 0x5e, 0x9e, 0x68, 0x51, 0x3d, 0xe8, 0xec,
41  0x82, 0x30, 0x82, 0x88, 0x8c, 0xfd, 0xe7, 0x71,
42  0x15, 0x92, 0xfc, 0x14, 0x59, 0x78, 0x31, 0xb3,
43  0xf6, 0x07, 0x91, 0x18, 0x00, 0x8d, 0x4c, 0xb2
44  };
45  CHECK(memcmp(sig, fini, 64) == 0);
46 
48  return 0;
49 }
secp256k1_start
void secp256k1_start(unsigned int flags)
Initialize the library.
Definition: secp256k1.c:21
main
int main(void)
Definition: bench_sign.c:12
util.h
secp256k1.h
secp256k1_ecdsa_sign_compact
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_sign_compact(const unsigned char *msg, int msglen, unsigned char *sig64, const unsigned char *seckey, const unsigned char *nonce, int *recid) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5)
Create a compact ECDSA signature (64 byte + recovery id).
Definition: secp256k1.c:108
SECP256K1_START_SIGN
#define SECP256K1_START_SIGN
Definition: secp256k1.h:46
key
CKey key
Definition: bip38tooldialog.cpp:173
secp256k1_stop
void secp256k1_stop(void)
Free all memory associated with this library.
Definition: secp256k1.c:34
CHECK
#define CHECK(cond)
Definition: util.h:43