Bitcoin ABC 0.33.3
P2P Digital Currency
secp256k1.h
Go to the documentation of this file.
1#ifndef SECP256K1_H
2#define SECP256K1_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stddef.h>
9
51
61typedef struct {
62 unsigned char data[64];
64
74typedef struct {
75 unsigned char data[64];
77
95 unsigned char *nonce32,
96 const unsigned char *msg32,
97 const unsigned char *key32,
98 const unsigned char *algo16,
99 void *data,
100 unsigned int attempt
101);
102
103# if !defined(SECP256K1_GNUC_PREREQ)
104# if defined(__GNUC__)&&defined(__GNUC_MINOR__)
105# define SECP256K1_GNUC_PREREQ(_maj,_min) \
106 ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
107# else
108# define SECP256K1_GNUC_PREREQ(_maj,_min) 0
109# endif
110# endif
111
112/* When this header is used at build-time the SECP256K1_BUILD define needs to be set
113 * to correctly setup export attributes and nullness checks. This is normally done
114 * by secp256k1.c but to guard against this header being included before secp256k1.c
115 * has had a chance to set the define (e.g. via test harnesses that just includes
116 * secp256k1.c) we set SECP256K1_NO_BUILD when this header is processed without the
117 * BUILD define so this condition can be caught.
118 */
119#ifndef SECP256K1_BUILD
120# define SECP256K1_NO_BUILD
121#endif
122
127#ifndef SECP256K1_API
128# if defined(_WIN32)
129# if defined(SECP256K1_BUILD) && defined(DLL_EXPORT)
130# define SECP256K1_API __declspec(dllexport)
131# else
132# define SECP256K1_API
133# endif
134# elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD)
135# define SECP256K1_API __attribute__ ((visibility ("default")))
136# else
137# define SECP256K1_API
138# endif
139#endif
140
141/* Warning attributes
142 * NONNULL is not used if SECP256K1_BUILD is set to avoid the compiler optimizing out
143 * some paranoid null checks. */
144# if defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
145# define SECP256K1_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
146# else
147# define SECP256K1_WARN_UNUSED_RESULT
148# endif
149# if !defined(SECP256K1_BUILD) && defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
150# define SECP256K1_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x)))
151# else
152# define SECP256K1_ARG_NONNULL(_x)
153# endif
154
155/* Attribute for marking functions, types, and variables as deprecated */
156#if !defined(SECP256K1_BUILD) && defined(__has_attribute)
157# if __has_attribute(__deprecated__)
158# define SECP256K1_DEPRECATED(_msg) __attribute__ ((__deprecated__(_msg)))
159# else
160# define SECP256K1_DEPRECATED(_msg)
161# endif
162#else
163# define SECP256K1_DEPRECATED(_msg)
164#endif
165
166/* All flags' lower 8 bits indicate what they're for. Do not use directly. */
167#define SECP256K1_FLAGS_TYPE_MASK ((1 << 8) - 1)
168#define SECP256K1_FLAGS_TYPE_CONTEXT (1 << 0)
169#define SECP256K1_FLAGS_TYPE_COMPRESSION (1 << 1)
170/* The higher bits contain the actual data. Do not use directly. */
171#define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY (1 << 8)
172#define SECP256K1_FLAGS_BIT_CONTEXT_SIGN (1 << 9)
173#define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY (1 << 10)
174#define SECP256K1_FLAGS_BIT_COMPRESSION (1 << 8)
175
178#define SECP256K1_CONTEXT_NONE (SECP256K1_FLAGS_TYPE_CONTEXT)
179
181#define SECP256K1_CONTEXT_VERIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_VERIFY)
182#define SECP256K1_CONTEXT_SIGN (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_SIGN)
183
184/* Testing flag. Do not use. */
185#define SECP256K1_CONTEXT_DECLASSIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY)
186
188#define SECP256K1_EC_COMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION | SECP256K1_FLAGS_BIT_COMPRESSION)
189#define SECP256K1_EC_UNCOMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION)
190
192#define SECP256K1_TAG_PUBKEY_EVEN 0x02
193#define SECP256K1_TAG_PUBKEY_ODD 0x03
194#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED 0x04
195#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN 0x06
196#define SECP256K1_TAG_PUBKEY_HYBRID_ODD 0x07
197
210
213SECP256K1_DEPRECATED("Use secp256k1_context_static instead");
214
232
233
260 unsigned int flags
262
278
296
336 void (*fun)(const char *message, void *data),
337 const void *data
339
364 void (*fun)(const char *message, void *data),
365 const void *data
367
383 const secp256k1_context *ctx,
384 secp256k1_pubkey *pubkey,
385 const unsigned char *input,
386 size_t inputlen
388
405 const secp256k1_context *ctx,
406 unsigned char *output,
407 size_t *outputlen,
408 const secp256k1_pubkey *pubkey,
409 unsigned int flags
411
422 const secp256k1_context *ctx,
423 const secp256k1_pubkey *pubkey1,
424 const secp256k1_pubkey *pubkey2
426
443 const secp256k1_context *ctx,
445 const unsigned char *input64
447
464 const secp256k1_context *ctx,
466 const unsigned char *input,
467 size_t inputlen
469
482 const secp256k1_context *ctx,
483 unsigned char *output,
484 size_t *outputlen,
487
498 const secp256k1_context *ctx,
499 unsigned char *output64,
502
529 const secp256k1_context *ctx,
531 const unsigned char *msghash32,
532 const secp256k1_pubkey *pubkey
534
577 const secp256k1_context *ctx,
579 const secp256k1_ecdsa_signature *sigin
581
587
590
610 const secp256k1_context *ctx,
612 const unsigned char *msghash32,
613 const unsigned char *seckey,
615 const void *ndata
617
631 const secp256k1_context *ctx,
632 const unsigned char *seckey
634
644 const secp256k1_context *ctx,
645 secp256k1_pubkey *pubkey,
646 const unsigned char *seckey
648
660 const secp256k1_context *ctx,
661 unsigned char *seckey
663
667 const secp256k1_context *ctx,
668 unsigned char *seckey
671
679 const secp256k1_context *ctx,
680 secp256k1_pubkey *pubkey
682
699 const secp256k1_context *ctx,
700 unsigned char *seckey,
701 const unsigned char *tweak32
703
707 const secp256k1_context *ctx,
708 unsigned char *seckey,
709 const unsigned char *tweak32
712
727 const secp256k1_context *ctx,
728 secp256k1_pubkey *pubkey,
729 const unsigned char *tweak32
731
746 const secp256k1_context *ctx,
747 unsigned char *seckey,
748 const unsigned char *tweak32
750
754 const secp256k1_context *ctx,
755 unsigned char *seckey,
756 const unsigned char *tweak32
759
772 const secp256k1_context *ctx,
773 secp256k1_pubkey *pubkey,
774 const unsigned char *tweak32
776
811 const unsigned char *seed32
813
824 const secp256k1_context *ctx,
826 const secp256k1_pubkey * const *ins,
827 size_t n
829
847 const secp256k1_context *ctx,
848 unsigned char *hash32,
849 const unsigned char *tag,
850 size_t taglen,
851 const unsigned char *msg,
852 size_t msglen
854
855#ifdef __cplusplus
856}
857#endif
858
859#endif /* SECP256K1_H */
int flags
Definition: bitcoin-tx.cpp:546
secp256k1_context * ctx
Definition: bench_impl.h:13
SchnorrSig sig
Definition: processor.cpp:537
const secp256k1_context * secp256k1_context_no_precomp
Definition: secp256k1.c:74
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
Destroy a secp256k1 context object (created in dynamically allocated memory).
Definition: secp256k1.c:186
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_tweak_mul(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Tweak a secret key by multiplying it by a tweak.
Definition: secp256k1.c:704
#define SECP256K1_ARG_NONNULL(_x)
Definition: secp256k1.h:152
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.
Definition: secp256k1.c:751
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_combine(const secp256k1_context *ctx, secp256k1_pubkey *out, const secp256k1_pubkey *const *ins, size_t n) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Add a number of public keys together.
Definition: secp256k1.c:761
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_negate(const secp256k1_context *ctx, unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Negates a secret key in place.
Definition: secp256k1.c:614
SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_default
A default safe nonce generation function (currently equal to secp256k1_nonce_function_rfc6979).
Definition: secp256k1.c:500
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)
Parse an ECDSA signature in compact (64 bytes) format.
Definition: secp256k1.c:379
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)
Serialize a pubkey object into a serialized byte sequence.
Definition: secp256k1.c:290
SECP256K1_API void secp256k1_context_set_error_callback(secp256k1_context *ctx, void(*fun)(const char *message, void *data), const void *data) SECP256K1_ARG_NONNULL(1)
Set a callback function to be called when an internal consistency check fails.
Definition: secp256k1.c:210
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_cmp(const secp256k1_context *ctx, const secp256k1_pubkey *pubkey1, const secp256k1_pubkey *pubkey2) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Compare two public keys using lexicographic (of compressed serialization) order.
Definition: secp256k1.c:313
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)
Verify an ECDSA secret key.
Definition: secp256k1.c:573
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object (in dynamically allocated memory).
Definition: secp256k1.c:140
SECP256K1_API void secp256k1_context_set_illegal_callback(secp256k1_context *ctx, void(*fun)(const char *message, void *data), const void *data) SECP256K1_ARG_NONNULL(1)
Set a callback function to be called when an illegal argument is passed to an API call.
Definition: secp256k1.c:198
#define SECP256K1_API
At secp256k1 build-time DLL_EXPORT is defined when building objects destined for a shared library,...
Definition: secp256k1.h:137
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)
Create an ECDSA signature.
Definition: secp256k1.c:558
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)
Parse a variable-length public key into the pubkey object.
Definition: secp256k1.c:272
int(* secp256k1_nonce_function)(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int attempt)
A pointer to a function to deterministically generate a nonce.
Definition: secp256k1.h:94
SECP256K1_API int secp256k1_ecdsa_signature_parse_der(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *input, size_t inputlen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a DER ECDSA signature.
Definition: secp256k1.c:363
SECP256K1_API void secp256k1_selftest(void)
Perform basic self tests (to be used in conjunction with secp256k1_context_static)
Definition: secp256k1.c:85
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)
Compute the public key for a secret key.
Definition: secp256k1.c:596
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.
Definition: secp256k1.c:787
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)
Verify an ECDSA signature.
Definition: secp256k1.c:444
#define SECP256K1_DEPRECATED(_msg)
Definition: secp256k1.h:163
SECP256K1_API int secp256k1_ecdsa_signature_normalize(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sigout, const secp256k1_ecdsa_signature *sigin) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3)
Convert a signature to a normalized lower-S form.
Definition: secp256k1.c:425
SECP256K1_API secp256k1_context * secp256k1_context_clone(const secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT
Copy a secp256k1 context object (into dynamically allocated memory).
Definition: secp256k1.c:162
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Tweak a public key by adding tweak times the generator to it.
Definition: secp256k1.c:687
SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function.
Definition: secp256k1.c:499
SECP256K1_API int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature *sig) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize an ECDSA signature in DER format.
Definition: secp256k1.c:400
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_negate(const secp256k1_context *ctx, secp256k1_pubkey *pubkey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Negates a public key in place.
Definition: secp256k1.c:633
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_DEPRECATED("Use secp256k1_ec_seckey_tweak_add instead")
Same as secp256k1_ec_seckey_tweak_add, but DEPRECATED.
Definition: secp256k1.c:676
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_negate(const secp256k1_context *ctx, unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_DEPRECATED("Use secp256k1_ec_seckey_negate instead")
Same as secp256k1_ec_seckey_negate, but DEPRECATED.
Definition: secp256k1.c:629
#define SECP256K1_WARN_UNUSED_RESULT
Definition: secp256k1.h:147
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Tweak a secret key by adding tweak to it.
Definition: secp256k1.c:660
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Tweak a public key by multiplying it by a tweak value.
Definition: secp256k1.c:728
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)
Serialize an ECDSA signature in compact (64 byte) format.
Definition: secp256k1.c:412
SECP256K1_API const secp256k1_context * secp256k1_context_static
A built-in constant secp256k1 context object with static storage duration, to be used in conjunction ...
Definition: secp256k1.c:73
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_DEPRECATED("Use secp256k1_ec_seckey_tweak_mul instead")
Same as secp256k1_ec_seckey_tweak_mul, but DEPRECATED.
Definition: secp256k1.c:724
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:74
Opaque data structure that holds a parsed and valid public key.
Definition: secp256k1.h:61