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;
40 printf(
"Failed to generate randomness\n");
56 printf(
"Failed to generate randomness\n");
98 if (!
fill_random(auxiliary_rand,
sizeof(auxiliary_rand))) {
99 printf(
"Failed to generate randomness\n");
119 printf(
"Failed parsing the public key\n");
131 printf(
"Is the signature valid? %s\n", is_signature_valid ?
"true" :
"false");
135 print_hex(serialized_pubkey,
sizeof(serialized_pubkey));
149 memset(seckey, 0,
sizeof(seckey));
static int fill_random(unsigned char *data, size_t size)
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).
#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)
Updates the context randomization to protect 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).
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.
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size, and secp256k1_context...
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.