21 unsigned char msg[] = {
'H',
'e',
'l',
'l',
'o',
' ',
'W',
'o',
'r',
'l',
'd',
'!'};
22 unsigned char msg_hash[32];
23 unsigned char tag[] = {
'm',
'y',
'_',
'f',
'a',
'n',
'c',
'y',
'_',
'p',
'r',
'o',
't',
'o',
'c',
'o',
'l'};
24 unsigned char seckey[32];
25 unsigned char randomize[32];
26 unsigned char auxiliary_rand[32];
27 unsigned char serialized_pubkey[32];
28 unsigned char signature[64];
29 int is_signature_valid, is_signature_valid2;
36 printf(
"Failed to generate randomness\n");
47 printf(
"Failed to generate randomness\n");
55 printf(
"Generated secret key is invalid. This indicates an issue with the random number generator.\n");
91 if (!
fill_random(auxiliary_rand,
sizeof(auxiliary_rand))) {
92 printf(
"Failed to generate randomness\n");
112 printf(
"Failed parsing the public key\n");
124 printf(
"Is the signature valid? %s\n", is_signature_valid ?
"true" :
"false");
128 print_hex(serialized_pubkey,
sizeof(serialized_pubkey));
141 signature, msg_hash, 32, &pubkey);
142 assert(is_signature_valid2 == is_signature_valid);
static int fill_random(unsigned char *data, size_t size)
static void secure_erase(void *ptr, size_t len)
static void print_hex(unsigned char *data, size_t size)
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
Destroy a secp256k1 context object (created in dynamically allocated memory).
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32) SECP256K1_ARG_NONNULL(1)
Randomizes the context to provide enhanced protection against side-channel leakage.
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object (in dynamically allocated memory).
#define SECP256K1_CONTEXT_NONE
Context flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size,...
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_tagged_sha256(const secp256k1_context *ctx, unsigned char *hash32, const unsigned char *tag, size_t taglen, const unsigned char *msg, size_t msglen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5)
Compute a tagged hash as defined in BIP-340.
SECP256K1_API const secp256k1_context * secp256k1_context_static
A built-in constant secp256k1 context object with static storage duration, to be used in conjunction ...
SECP256K1_API int secp256k1_schnorrsig_sign32(const secp256k1_context *ctx, unsigned char *sig64, const unsigned char *msg32, const secp256k1_keypair *keypair, const unsigned char *aux_rand32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Create a Schnorr signature.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify(const secp256k1_context *ctx, const unsigned char *sig64, const unsigned char *msg, size_t msglen, const secp256k1_xonly_pubkey *pubkey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(5)
Verify a Schnorr signature.
Opaque data structure that holds a keypair consisting of a secret and a public key.
Opaque data structure that holds a parsed and valid "x-only" public key.