20 {
21
22
23
24
25
26 unsigned char msg_hash[32] = {
27 0x31, 0x5F, 0x5B, 0xDB, 0x76, 0xD0, 0x78, 0xC4,
28 0x3B, 0x8A, 0xC0, 0x06, 0x4E, 0x4A, 0x01, 0x64,
29 0x61, 0x2B, 0x1F, 0xCE, 0x77, 0xC8, 0x69, 0x34,
30 0x5B, 0xFC, 0x94, 0xC7, 0x58, 0x94, 0xED, 0xD3,
31 };
32 unsigned char seckey[32];
33 unsigned char randomize[32];
34 unsigned char compressed_pubkey[33];
35 unsigned char serialized_signature[64];
37 int is_signature_valid;
38 int return_val;
41
42
43
44
45
47 if (!fill_random(randomize, sizeof(randomize))) {
48 printf(
"Failed to generate randomness\n");
49 return 1;
50 }
51
52
53
55 assert(return_val);
56
57
58
59
60
61
62 while (1) {
63 if (!fill_random(seckey, sizeof(seckey))) {
64 printf(
"Failed to generate randomness\n");
65 return 1;
66 }
68 break;
69 }
70 }
71
72
74 assert(return_val);
75
76
77 len =
sizeof(compressed_pubkey);
79 assert(return_val);
80
81 assert(
len ==
sizeof(compressed_pubkey));
82
83
84
85
86
87
88
90 assert(return_val);
91
92
93
95 assert(return_val);
96
97
98
99
100
102 printf(
"Failed parsing the signature\n");
103 return 1;
104 }
105
106
108 printf(
"Failed parsing the public key\n");
109 return 1;
110 }
111
112
114
115 printf(
"Is the signature valid? %s\n", is_signature_valid ?
"true" :
"false");
117 print_hex(seckey, sizeof(seckey));
119 print_hex(compressed_pubkey, sizeof(compressed_pubkey));
121 print_hex(serialized_signature, sizeof(serialized_signature));
122
123
124
126
127
128
129
130
131
132
133
134 memset(seckey, 0,
sizeof(seckey));
135
136 return 0;
137}
LOGGING_API void printf(Category category, const char *format,...)
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
#define SECP256K1_CONTEXT_SIGN
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32) SECP256K1_ARG_NONNULL(1)
SECP256K1_API int secp256k1_ecdsa_signature_parse_compact(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *input64) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(const secp256k1_context *ctx, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
SECP256K1_API int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
#define SECP256K1_EC_COMPRESSED
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const secp256k1_pubkey *pubkey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
#define SECP256K1_CONTEXT_VERIFY
SECP256K1_API int secp256k1_ecdsa_signature_serialize_compact(const secp256k1_context *ctx, unsigned char *output64, const secp256k1_ecdsa_signature *sig) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
memset(pInfo->slotDescription, ' ', 64)