7 #define SECP256K1_BUILD (1) 23 #define ARG_CHECK(cond) do { \ 24 if (EXPECT(!(cond), 0)) { \ 25 secp256k1_callback_call(&ctx->illegal_callback, #cond); \ 32 fprintf(
stderr,
"[libsecp256k1] illegal argument: %s\n", str);
43 fprintf(
stderr,
"[libsecp256k1] internal consistency check failed: %s\n", str);
158 memset(pubkey, 0,
sizeof(*pubkey));
180 memset(output, 0, len);
227 memset(sig, 0,
sizeof(*sig));
248 memset(sig, 0,
sizeof(*sig));
287 if (sigout != NULL) {
314 static int nonce_function_rfc6979(
unsigned char *nonce32,
const unsigned char *msg32,
const unsigned char *key32,
const unsigned char *algo16,
void *
data,
unsigned int counter) {
315 unsigned char keydata[112];
327 memcpy(keydata, key32, 32);
328 memcpy(keydata + 32, msg32, 32);
333 if (algo16 != NULL) {
334 memcpy(keydata + keylen, algo16, 16);
338 memset(keydata, 0,
sizeof(keydata));
339 for (i = 0; i <= counter; i++) {
359 if (noncefp == NULL) {
366 unsigned int count = 0;
369 unsigned char nonce32[32];
370 ret = noncefp(nonce32, msg32, seckey, NULL, (
void*)noncedata,
count);
375 memset(nonce32, 0, 32);
390 memset(signature, 0,
sizeof(*signature));
417 memset(pubkey, 0,
sizeof(*pubkey));
446 memset(seckey, 0, 32);
468 memset(pubkey, 0,
sizeof(*pubkey));
493 memset(seckey, 0, 32);
515 memset(pubkey, 0,
sizeof(*pubkey));
540 memset(pubnonce, 0,
sizeof(*pubnonce));
546 for (i = 0; i <
n; i++) {
558 #ifdef ENABLE_MODULE_ECDH 562 #ifdef ENABLE_MODULE_SCHNORR 566 #ifdef ENABLE_MODULE_RECOVERY static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx)
static int secp256k1_ge_is_infinity(const secp256k1_ge *a)
#define VERIFY_CHECK(cond)
static void default_error_callback_fn(const char *str, void *data)
int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature *sig)
static int secp256k1_gej_is_infinity(const secp256k1_gej *a)
static int secp256k1_fe_is_zero(const secp256k1_fe *a)
static const secp256k1_callback default_illegal_callback
static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp256k1_gej *r, const secp256k1_scalar *a)
static void secp256k1_fe_normalize_var(secp256k1_fe *r)
static void secp256k1_ecmult_gen_context_clone(secp256k1_ecmult_gen_context *dst, const secp256k1_ecmult_gen_context *src, const secp256k1_callback *cb)
static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256_t *rng, const unsigned char *key, size_t keylen)
static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid)
static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak)
static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter)
int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags)
static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size)
static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a)
static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const unsigned char *seed32)
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed)
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
int secp256k1_ecdsa_signature_parse_der(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *input, size_t inputlen)
static void secp256k1_pubkey_save(secp256k1_pubkey *pubkey, secp256k1_ge *ge)
static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256_t *rng, unsigned char *out, size_t outlen)
int secp256k1_ec_seckey_verify(const secp256k1_context *ctx, const unsigned char *seckey)
void(* fn)(const char *text, void *data)
static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow)
static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak)
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ctx, const secp256k1_callback *cb)
static const secp256k1_callback default_error_callback
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ctx)
static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature *sig, const secp256k1_scalar *r, const secp256k1_scalar *s)
#define SECP256K1_FLAGS_TYPE_CONTEXT
static void secp256k1_gej_set_infinity(secp256k1_gej *r)
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size)
#define SECP256K1_FLAGS_TYPE_MASK
static void default_illegal_callback_fn(const char *str, void *data)
const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *signature, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *noncedata)
static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256_t *rng)
static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak)
secp256k1_context * secp256k1_context_clone(const secp256k1_context *ctx)
int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak)
static void secp256k1_ecmult_context_clone(secp256k1_ecmult_context *dst, const secp256k1_ecmult_context *src, const secp256k1_callback *cb)
int secp256k1_ec_pubkey_combine(const secp256k1_context *ctx, secp256k1_pubkey *pubnonce, const secp256k1_pubkey *const *pubnonces, size_t n)
secp256k1_ecmult_gen_context ecmult_gen_ctx
int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const secp256k1_pubkey *pubkey)
static secp256k1_context * ctx
static void secp256k1_ge_set_gej(secp256k1_ge *r, secp256k1_gej *a)
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx)
static int secp256k1_scalar_is_high(const secp256k1_scalar *a)
int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey)
void secp256k1_context_set_error_callback(secp256k1_context *ctx, void(*fun)(const char *message, void *data), const void *data)
void secp256k1_context_set_illegal_callback(secp256k1_context *ctx, void(*fun)(const char *message, void *data), const void *data)
secp256k1_ecmult_context ecmult_ctx
static void secp256k1_scalar_clear(secp256k1_scalar *r)
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak)
static void secp256k1_ge_clear(secp256k1_ge *r)
const secp256k1_nonce_function secp256k1_nonce_function_default
secp256k1_callback illegal_callback
static void secp256k1_ecdsa_signature_load(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_ecdsa_signature *sig)
#define SECP256K1_FLAGS_BIT_CONTEXT_SIGN
static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar *a)
static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a)
static void secp256k1_ge_set_xy(secp256k1_ge *r, const secp256k1_fe *x, const secp256k1_fe *y)
int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen)
#define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY
int(* secp256k1_nonce_function)(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int attempt)
static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context *ctx)
void * memcpy(void *a, const void *b, size_t c)
static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar *r, const secp256k1_scalar *s, const secp256k1_ge *pubkey, const secp256k1_scalar *message)
static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback *const cb, const char *const text)
void secp256k1_context_destroy(secp256k1_context *ctx)
int secp256k1_ecdsa_signature_serialize_compact(const secp256k1_context *ctx, unsigned char *output64, const secp256k1_ecdsa_signature *sig)
static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a)
static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b)
static int secp256k1_pubkey_load(const secp256k1_context *ctx, secp256k1_ge *ge, const secp256k1_pubkey *pubkey)
secp256k1_callback error_callback
static void secp256k1_ge_from_storage(secp256k1_ge *r, const secp256k1_ge_storage *a)
int secp256k1_ec_pubkey_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak)
int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32)
static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, const secp256k1_callback *cb)
int secp256k1_ec_privkey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak)
static void secp256k1_ge_to_storage(secp256k1_ge_storage *r, const secp256k1_ge *a)
static SECP256K1_INLINE void * checked_malloc(const secp256k1_callback *cb, size_t size)
static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context *ctx)
static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx)
#define SECP256K1_FLAGS_TYPE_COMPRESSION
int secp256k1_ecdsa_signature_parse_compact(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *input64)
secp256k1_context * secp256k1_context_create(unsigned int flags)
int secp256k1_ec_privkey_tweak_mul(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak)
static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s)
#define SECP256K1_FLAGS_BIT_COMPRESSION
int secp256k1_ecdsa_signature_normalize(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sigout, const secp256k1_ecdsa_signature *sigin)