Bitcoin ABC 0.32.10
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
64
74typedef struct {
75 unsigned char data[64];
77
87typedef struct {
88 unsigned char data[64];
90
108 unsigned char *nonce32,
109 const unsigned char *msg32,
110 const unsigned char *key32,
111 const unsigned char *algo16,
112 void *data,
113 unsigned int attempt
114);
115
116# if !defined(SECP256K1_GNUC_PREREQ)
117# if defined(__GNUC__)&&defined(__GNUC_MINOR__)
118# define SECP256K1_GNUC_PREREQ(_maj,_min) \
119 ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
120# else
121# define SECP256K1_GNUC_PREREQ(_maj,_min) 0
122# endif
123# endif
124
125# if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )
126# if SECP256K1_GNUC_PREREQ(2,7)
127# define SECP256K1_INLINE __inline__
128# elif (defined(_MSC_VER))
129# define SECP256K1_INLINE __inline
130# else
131# define SECP256K1_INLINE
132# endif
133# else
134# define SECP256K1_INLINE inline
135# endif
136
137/* When this header is used at build-time the SECP256K1_BUILD define needs to be set
138 * to correctly setup export attributes and nullness checks. This is normally done
139 * by secp256k1.c but to guard against this header being included before secp256k1.c
140 * has had a chance to set the define (e.g. via test harnesses that just includes
141 * secp256k1.c) we set SECP256K1_NO_BUILD when this header is processed without the
142 * BUILD define so this condition can be caught.
143 */
144#ifndef SECP256K1_BUILD
145# define SECP256K1_NO_BUILD
146#endif
147
152#ifndef SECP256K1_API
153# if defined(_WIN32)
154# if defined(SECP256K1_BUILD) && defined(DLL_EXPORT)
155# define SECP256K1_API __declspec(dllexport)
156# else
157# define SECP256K1_API
158# endif
159# elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD)
160# define SECP256K1_API __attribute__ ((visibility ("default")))
161# else
162# define SECP256K1_API
163# endif
164#endif
165
166/* Warning attributes
167 * NONNULL is not used if SECP256K1_BUILD is set to avoid the compiler optimizing out
168 * some paranoid null checks. */
169# if defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
170# define SECP256K1_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
171# else
172# define SECP256K1_WARN_UNUSED_RESULT
173# endif
174# if !defined(SECP256K1_BUILD) && defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
175# define SECP256K1_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x)))
176# else
177# define SECP256K1_ARG_NONNULL(_x)
178# endif
179
180/* Attribute for marking functions, types, and variables as deprecated */
181#if !defined(SECP256K1_BUILD) && defined(__has_attribute)
182# if __has_attribute(__deprecated__)
183# define SECP256K1_DEPRECATED(_msg) __attribute__ ((__deprecated__(_msg)))
184# else
185# define SECP256K1_DEPRECATED(_msg)
186# endif
187#else
188# define SECP256K1_DEPRECATED(_msg)
189#endif
190
191/* All flags' lower 8 bits indicate what they're for. Do not use directly. */
192#define SECP256K1_FLAGS_TYPE_MASK ((1 << 8) - 1)
193#define SECP256K1_FLAGS_TYPE_CONTEXT (1 << 0)
194#define SECP256K1_FLAGS_TYPE_COMPRESSION (1 << 1)
195/* The higher bits contain the actual data. Do not use directly. */
196#define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY (1 << 8)
197#define SECP256K1_FLAGS_BIT_CONTEXT_SIGN (1 << 9)
198#define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY (1 << 10)
199#define SECP256K1_FLAGS_BIT_COMPRESSION (1 << 8)
200
203#define SECP256K1_CONTEXT_NONE (SECP256K1_FLAGS_TYPE_CONTEXT)
204
206#define SECP256K1_CONTEXT_VERIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_VERIFY)
207#define SECP256K1_CONTEXT_SIGN (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_SIGN)
208
209/* Testing flag. Do not use. */
210#define SECP256K1_CONTEXT_DECLASSIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY)
211
213#define SECP256K1_EC_COMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION | SECP256K1_FLAGS_BIT_COMPRESSION)
214#define SECP256K1_EC_UNCOMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION)
215
217#define SECP256K1_TAG_PUBKEY_EVEN 0x02
218#define SECP256K1_TAG_PUBKEY_ODD 0x03
219#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED 0x04
220#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN 0x06
221#define SECP256K1_TAG_PUBKEY_HYBRID_ODD 0x07
222
235
238SECP256K1_DEPRECATED("Use secp256k1_context_static instead");
239
257
258
285 unsigned int flags
287
300
317
357 void (*fun)(const char* message, void* data),
358 const void* data
360
385 void (*fun)(const char* message, void* data),
386 const void* data
388
397 const secp256k1_context* ctx,
398 size_t size
400
408 const secp256k1_context* ctx,
411
427 const secp256k1_context* ctx,
428 secp256k1_pubkey* pubkey,
429 const unsigned char *input,
430 size_t inputlen
432
449 const secp256k1_context* ctx,
450 unsigned char *output,
451 size_t *outputlen,
452 const secp256k1_pubkey* pubkey,
453 unsigned int flags
455
466 const secp256k1_context* ctx,
467 const secp256k1_pubkey* pubkey1,
468 const secp256k1_pubkey* pubkey2
470
487 const secp256k1_context* ctx,
489 const unsigned char *input64
491
508 const secp256k1_context* ctx,
510 const unsigned char *input,
511 size_t inputlen
513
526 const secp256k1_context* ctx,
527 unsigned char *output,
528 size_t *outputlen,
531
542 const secp256k1_context* ctx,
543 unsigned char *output64,
546
573 const secp256k1_context* ctx,
575 const unsigned char *msghash32,
576 const secp256k1_pubkey *pubkey
578
621 const secp256k1_context* ctx,
623 const secp256k1_ecdsa_signature *sigin
625
631
634
654 const secp256k1_context* ctx,
656 const unsigned char *msghash32,
657 const unsigned char *seckey,
659 const void *ndata
661
675 const secp256k1_context* ctx,
676 const unsigned char *seckey
678
688 const secp256k1_context* ctx,
689 secp256k1_pubkey *pubkey,
690 const unsigned char *seckey
692
704 const secp256k1_context* ctx,
705 unsigned char *seckey
707
711 const secp256k1_context* ctx,
712 unsigned char *seckey
715
723 const secp256k1_context* ctx,
724 secp256k1_pubkey *pubkey
726
743 const secp256k1_context* ctx,
744 unsigned char *seckey,
745 const unsigned char *tweak32
747
751 const secp256k1_context* ctx,
752 unsigned char *seckey,
753 const unsigned char *tweak32
756
771 const secp256k1_context* ctx,
772 secp256k1_pubkey *pubkey,
773 const unsigned char *tweak32
775
790 const secp256k1_context* ctx,
791 unsigned char *seckey,
792 const unsigned char *tweak32
794
798 const secp256k1_context* ctx,
799 unsigned char *seckey,
800 const unsigned char *tweak32
803
816 const secp256k1_context* ctx,
817 secp256k1_pubkey *pubkey,
818 const unsigned char *tweak32
820
859 const unsigned char *seed32
861
872 const secp256k1_context* ctx,
873 secp256k1_pubkey *out,
874 const secp256k1_pubkey * const * ins,
875 size_t n
877
895 const secp256k1_context* ctx,
896 unsigned char *hash32,
897 const unsigned char *tag,
898 size_t taglen,
899 const unsigned char *msg,
900 size_t msglen
902
903#ifdef __cplusplus
904}
905#endif
906
907#endif /* SECP256K1_H */
int flags
Definition: bitcoin-tx.cpp:542
secp256k1_context * ctx
Definition: bench_impl.h:13
SchnorrSig sig
Definition: processor.cpp:523
const secp256k1_context * secp256k1_context_no_precomp
Definition: secp256k1.c:77
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:176
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:696
#define SECP256K1_ARG_NONNULL(_x)
Definition: secp256k1.h:177
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space * secp256k1_scratch_space_create(const secp256k1_context *ctx, size_t size) SECP256K1_ARG_NONNULL(1)
Create a secp256k1 scratch space object.
Definition: secp256k1.c:207
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:743
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:751
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:606
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:492
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:371
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:282
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:195
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:305
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:565
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:137
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:183
#define SECP256K1_API
At secp256k1 build-time DLL_EXPORT is defined when building objects destined for a shared library,...
Definition: secp256k1.h:162
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:550
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:264
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:107
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:355
SECP256K1_API void secp256k1_selftest(void)
Perform basic self tests (to be used in conjunction with secp256k1_context_static)
Definition: secp256k1.c:88
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:588
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:777
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:436
#define SECP256K1_DEPRECATED(_msg)
Definition: secp256k1.h:188
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:417
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:158
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:679
SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function.
Definition: secp256k1.c:491
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:392
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:625
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:668
SECP256K1_API void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space *scratch) SECP256K1_ARG_NONNULL(1)
Destroy a secp256k1 scratch space.
Definition: secp256k1.c:212
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:621
#define SECP256K1_WARN_UNUSED_RESULT
Definition: secp256k1.h:172
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:652
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:720
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:404
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:76
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:716
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:87
Opaque data structure that holds a parsed and valid public key.
Definition: secp256k1.h:74
void * data
actual allocated data
Definition: scratch.h:16