7#ifndef SECP256K1_MODULE_SCHNORRSIG_MAIN_H
8#define SECP256K1_MODULE_SCHNORRSIG_MAIN_H
10#include "../../../include/secp256k1.h"
11#include "../../../include/secp256k1_schnorrsig.h"
12#include "../../hash.h"
18 sha->
s[0] = 0x46615b35ul;
19 sha->
s[1] = 0xf4bfbff7ul;
20 sha->
s[2] = 0x9f8dc671ul;
21 sha->
s[3] = 0x83627ab3ul;
22 sha->
s[4] = 0x60217180ul;
23 sha->
s[5] = 0x57358661ul;
24 sha->
s[6] = 0x21a29e54ul;
25 sha->
s[7] = 0x68b07b4cul;
34 sha->
s[0] = 0x24dd3219ul;
35 sha->
s[1] = 0x4eba7e70ul;
36 sha->
s[2] = 0xca0fabb9ul;
37 sha->
s[3] = 0x0fa3166dul;
38 sha->
s[4] = 0x3afbe4b1ul;
39 sha->
s[5] = 0x4c44df97ul;
40 sha->
s[6] = 0x4aac2739ul;
41 sha->
s[7] = 0x249e850aul;
48static const unsigned char bip340_algo[] = {
'B',
'I',
'P',
'0',
'3',
'4',
'0',
'/',
'n',
'o',
'n',
'c',
'e'};
52static int nonce_function_bip340(
unsigned char *nonce32,
const unsigned char *
msg,
size_t msglen,
const unsigned char *key32,
const unsigned char *xonly_pk32,
const unsigned char *algo,
size_t algolen,
void *
data) {
54 unsigned char masked_key[32];
65 for (i = 0; i < 32; i++) {
66 masked_key[i] ^= key32[i];
70 static const unsigned char ZERO_MASK[32] = {
71 84, 241, 105, 207, 201, 226, 229, 114,
72 116, 128, 68, 31, 144, 186, 37, 196,
73 136, 244, 97, 199, 11, 94, 165, 220,
74 170, 247, 175, 105, 39, 10, 165, 20
76 for (i = 0; i < 32; i++) {
77 masked_key[i] = key32[i] ^ ZERO_MASK[i];
106 sha->
s[0] = 0x9cecba11ul;
107 sha->
s[1] = 0x23925381ul;
108 sha->
s[2] = 0x11679112ul;
109 sha->
s[3] = 0xd1627e0ful;
110 sha->
s[4] = 0x97c87550ul;
111 sha->
s[5] = 0x003cc765ul;
112 sha->
s[6] = 0x90f61164ul;
113 sha->
s[7] = 0x33e9b66aul;
119 unsigned char buf[32];
140 unsigned char buf[32] = { 0 };
141 unsigned char pk_buf[32];
142 unsigned char seckey[32];
151 if (noncefp == NULL) {
211 if (extraparams != NULL) {
214 sizeof(extraparams->
magic)) == 0);
215 noncefp = extraparams->
noncefp;
216 ndata = extraparams->
ndata;
229 unsigned char buf[32];
static void secp256k1_ecmult(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng)
Double multiply: R = na*A + ng*G.
static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp256k1_gej *r, const secp256k1_scalar *a)
Multiply with the generator: R = a*G.
static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context *ctx)
static int secp256k1_keypair_load(const secp256k1_context *ctx, secp256k1_scalar *sk, secp256k1_ge *pk, const secp256k1_keypair *keypair)
static SECP256K1_INLINE int secp256k1_xonly_pubkey_load(const secp256k1_context *ctx, secp256k1_ge *ge, const secp256k1_xonly_pubkey *pubkey)
#define secp256k1_fe_is_odd
#define secp256k1_fe_normalize_var
#define secp256k1_fe_set_b32_limit
#define secp256k1_fe_get_b32
static int secp256k1_fe_equal(const secp256k1_fe *a, const secp256k1_fe *b)
Determine whether two field elements are equal.
static void secp256k1_gej_clear(secp256k1_gej *r)
Clear a secp256k1_gej to prevent leaking sensitive information.
static void secp256k1_ge_set_gej(secp256k1_ge *r, secp256k1_gej *a)
Set a group element equal to another which is given in jacobian coordinates.
static int secp256k1_ge_is_infinity(const secp256k1_ge *a)
Check whether a group element is the point at infinity.
static void secp256k1_gej_set_ge(secp256k1_gej *r, const secp256k1_ge *a)
Set a group element (jacobian) equal to another which is given in affine coordinates.
static void secp256k1_ge_set_gej_var(secp256k1_ge *r, secp256k1_gej *a)
Set a group element equal to another which is given in jacobian coordinates.
static void secp256k1_sha256_initialize_tagged(secp256k1_sha256 *hash, const unsigned char *tag, size_t taglen)
static void secp256k1_scalar_cmov(secp256k1_scalar *r, const secp256k1_scalar *a, int flag)
If flag is true, set *r equal to *a; otherwise leave it.
static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow)
Set a scalar from a big endian byte array.
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
Check whether a scalar equals zero.
static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar *a)
Convert a scalar to a byte array.
static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Add two scalars together (modulo the group order).
static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Multiply two scalars (modulo the group order).
static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a)
Compute the complement of a scalar (modulo the group order).
static void secp256k1_scalar_clear(secp256k1_scalar *r)
Clear a scalar to prevent the leak of sensitive data.
static const secp256k1_scalar secp256k1_scalar_one
static void secp256k1_schnorrsig_challenge(secp256k1_scalar *e, const unsigned char *r32, const unsigned char *msg, size_t msglen, const unsigned char *pubkey32)
static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *msg, size_t msglen, const unsigned char *key32, const unsigned char *xonly_pk32, const unsigned char *algo, size_t algolen, void *data)
static const unsigned char schnorrsig_extraparams_magic[4]
static void secp256k1_nonce_function_bip340_sha256_tagged_aux(secp256k1_sha256 *sha)
int secp256k1_schnorrsig_sign(const secp256k1_context *ctx, unsigned char *sig64, const unsigned char *msg32, const secp256k1_keypair *keypair, const unsigned char *aux_rand32)
Same as secp256k1_schnorrsig_sign32, but DEPRECATED.
static void secp256k1_nonce_function_bip340_sha256_tagged(secp256k1_sha256 *sha)
static void secp256k1_schnorrsig_sha256_tagged(secp256k1_sha256 *sha)
int secp256k1_schnorrsig_sign_custom(const secp256k1_context *ctx, unsigned char *sig64, const unsigned char *msg, size_t msglen, const secp256k1_keypair *keypair, secp256k1_schnorrsig_extraparams *extraparams)
Create a Schnorr signature with a more flexible 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)
Create a Schnorr signature.
static const unsigned char bip340_algo[]
static int secp256k1_schnorrsig_sign_internal(const secp256k1_context *ctx, unsigned char *sig64, const unsigned char *msg, size_t msglen, const secp256k1_keypair *keypair, secp256k1_nonce_function_hardened noncefp, void *ndata)
const secp256k1_nonce_function_hardened secp256k1_nonce_function_bip340
int secp256k1_schnorrsig_verify(const secp256k1_context *ctx, const unsigned char *sig64, const unsigned char *msg, size_t msglen, const secp256k1_xonly_pubkey *pubkey)
Verify a Schnorr signature.
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash)
static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t size)
static void secp256k1_sha256_clear(secp256k1_sha256 *hash)
static SECP256K1_INLINE int secp256k1_memcmp_var(const void *s1, const void *s2, size_t n)
Semantics like memcmp.
static SECP256K1_INLINE void secp256k1_memclear(void *ptr, size_t len)
#define VERIFY_CHECK(cond)
static SECP256K1_INLINE void secp256k1_memczero(void *s, size_t len, int flag)
static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context *ctx, const void *p, size_t len)
#define SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC
int(* secp256k1_nonce_function_hardened)(unsigned char *nonce32, const unsigned char *msg, size_t msglen, const unsigned char *key32, const unsigned char *xonly_pk32, const unsigned char *algo, size_t algolen, void *data)
This module implements a variant of Schnorr signatures compliant with Bitcoin Improvement Proposal 34...
secp256k1_ecmult_gen_context ecmult_gen_ctx
This field implementation represents the value as 10 uint32_t limbs in base 2^26.
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
A group element of the secp256k1 curve, in jacobian coordinates.
Opaque data structure that holds a keypair consisting of a secret and a public key.
A scalar modulo the group order of the secp256k1 curve.
Opaque data structure that holds a parsed and valid "x-only" public key.