Dash Core  0.12.2.1
P2P Digital Currency
secp256k1.h
Go to the documentation of this file.
1 #ifndef _SECP256K1_
2 # define _SECP256K1_
3 
4 # ifdef __cplusplus
5 extern "C" {
6 # endif
7 
8 #include <stddef.h>
9 
10 /* These rules specify the order of arguments in API calls:
11  *
12  * 1. Context pointers go first, followed by output arguments, combined
13  * output/input arguments, and finally input-only arguments.
14  * 2. Array lengths always immediately the follow the argument whose length
15  * they describe, even if this violates rule 1.
16  * 3. Within the OUT/OUTIN/IN groups, pointers to data that is typically generated
17  * later go first. This means: signatures, public nonces, private nonces,
18  * messages, public keys, secret keys, tweaks.
19  * 4. Arguments that are not data pointers go last, from more complex to less
20  * complex: function pointers, algorithm names, messages, void pointers,
21  * counts, flags, booleans.
22  * 5. Opaque data pointers follow the function pointer they are to be passed to.
23  */
24 
44 
56 typedef struct {
57  unsigned char data[64];
59 
72 typedef struct {
73  unsigned char data[64];
75 
92 typedef int (*secp256k1_nonce_function)(
93  unsigned char *nonce32,
94  const unsigned char *msg32,
95  const unsigned char *key32,
96  const unsigned char *algo16,
97  void *data,
98  unsigned int attempt
99 );
100 
101 # if !defined(SECP256K1_GNUC_PREREQ)
102 # if defined(__GNUC__)&&defined(__GNUC_MINOR__)
103 # define SECP256K1_GNUC_PREREQ(_maj,_min) \
104  ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
105 # else
106 # define SECP256K1_GNUC_PREREQ(_maj,_min) 0
107 # endif
108 # endif
109 
110 # if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )
111 # if SECP256K1_GNUC_PREREQ(2,7)
112 # define SECP256K1_INLINE __inline__
113 # elif (defined(_MSC_VER))
114 # define SECP256K1_INLINE __inline
115 # else
116 # define SECP256K1_INLINE
117 # endif
118 # else
119 # define SECP256K1_INLINE inline
120 # endif
121 
122 #ifndef SECP256K1_API
123 # if defined(_WIN32)
124 # ifdef SECP256K1_BUILD
125 # define SECP256K1_API __declspec(dllexport)
126 # else
127 # define SECP256K1_API
128 # endif
129 # elif defined(__GNUC__) && defined(SECP256K1_BUILD)
130 # define SECP256K1_API __attribute__ ((visibility ("default")))
131 # else
132 # define SECP256K1_API
133 # endif
134 #endif
135 
139 # if defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
140 # define SECP256K1_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
141 # else
142 # define SECP256K1_WARN_UNUSED_RESULT
143 # endif
144 # if !defined(SECP256K1_BUILD) && defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
145 # define SECP256K1_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x)))
146 # else
147 # define SECP256K1_ARG_NONNULL(_x)
148 # endif
149 
151 #define SECP256K1_FLAGS_TYPE_MASK ((1 << 8) - 1)
152 #define SECP256K1_FLAGS_TYPE_CONTEXT (1 << 0)
153 #define SECP256K1_FLAGS_TYPE_COMPRESSION (1 << 1)
154 
155 #define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY (1 << 8)
156 #define SECP256K1_FLAGS_BIT_CONTEXT_SIGN (1 << 9)
157 #define SECP256K1_FLAGS_BIT_COMPRESSION (1 << 8)
158 
160 #define SECP256K1_CONTEXT_VERIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_VERIFY)
161 #define SECP256K1_CONTEXT_SIGN (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_SIGN)
162 #define SECP256K1_CONTEXT_NONE (SECP256K1_FLAGS_TYPE_CONTEXT)
163 
165 #define SECP256K1_EC_COMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION | SECP256K1_FLAGS_BIT_COMPRESSION)
166 #define SECP256K1_EC_UNCOMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION)
167 
174  unsigned int flags
176 
183  const secp256k1_context* ctx
185 
193 );
194 
217  void (*fun)(const char* message, void* data),
218  const void* data
220 
239  void (*fun)(const char* message, void* data),
240  const void* data
242 
258  const secp256k1_context* ctx,
259  secp256k1_pubkey* pubkey,
260  const unsigned char *input,
261  size_t inputlen
263 
280  const secp256k1_context* ctx,
281  unsigned char *output,
282  size_t *outputlen,
283  const secp256k1_pubkey* pubkey,
284  unsigned int flags
286 
303  const secp256k1_context* ctx,
305  const unsigned char *input64
307 
324  const secp256k1_context* ctx,
326  const unsigned char *input,
327  size_t inputlen
329 
342  const secp256k1_context* ctx,
343  unsigned char *output,
344  size_t *outputlen,
345  const secp256k1_ecdsa_signature* sig
347 
358  const secp256k1_context* ctx,
359  unsigned char *output64,
360  const secp256k1_ecdsa_signature* sig
362 
382  const secp256k1_context* ctx,
383  const secp256k1_ecdsa_signature *sig,
384  const unsigned char *msg32,
385  const secp256k1_pubkey *pubkey
387 
431  const secp256k1_context* ctx,
433  const secp256k1_ecdsa_signature *sigin
435 
441 
444 
460  const secp256k1_context* ctx,
462  const unsigned char *msg32,
463  const unsigned char *seckey,
464  secp256k1_nonce_function noncefp,
465  const void *ndata
467 
476  const secp256k1_context* ctx,
477  const unsigned char *seckey
479 
489  const secp256k1_context* ctx,
490  secp256k1_pubkey *pubkey,
491  const unsigned char *seckey
493 
504  const secp256k1_context* ctx,
505  unsigned char *seckey,
506  const unsigned char *tweak
508 
520  const secp256k1_context* ctx,
521  secp256k1_pubkey *pubkey,
522  const unsigned char *tweak
524 
533  const secp256k1_context* ctx,
534  unsigned char *seckey,
535  const unsigned char *tweak
537 
547  const secp256k1_context* ctx,
548  secp256k1_pubkey *pubkey,
549  const unsigned char *tweak
551 
560  const unsigned char *seed32
562 
573  const secp256k1_context* ctx,
575  const secp256k1_pubkey * const * ins,
576  size_t n
578 
579 # ifdef __cplusplus
580 }
581 # endif
582 
583 #endif
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Definition: secp256k1.c:456
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Definition: secp256k1.c:480
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)
Definition: secp256k1.c:103
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)
Definition: secp256k1.c:265
#define SECP256K1_WARN_UNUSED_RESULT
Definition: secp256k1.h:142
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)
Definition: secp256k1.c:278
SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_default
Definition: secp256k1.c:347
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32) SECP256K1_ARG_NONNULL(1)
Definition: secp256k1.c:527
int flags
Definition: dash-tx.cpp:326
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)
Definition: secp256k1.c:168
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Definition: secp256k1.c:432
SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
Definition: secp256k1.c:346
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Definition: secp256k1.c:94
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)
Definition: secp256k1.c:409
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)
Definition: secp256k1.c:395
static secp256k1_context * ctx
Definition: tests.c:42
SECP256K1_API int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *msg32, 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)
Definition: secp256k1.c:349
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Definition: secp256k1.c:503
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)
Definition: secp256k1.c:152
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)
Definition: secp256k1.c:111
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)
Definition: secp256k1.c:216
#define SECP256K1_ARG_NONNULL(_x)
Definition: secp256k1.h:147
SECP256K1_API secp256k1_context * secp256k1_context_clone(const secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT
Definition: secp256k1.c:85
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)
Definition: secp256k1.c:253
int(* secp256k1_nonce_function)(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int attempt)
Definition: secp256k1.h:92
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)
Definition: secp256k1.c:232
#define SECP256K1_API
Definition: secp256k1.h:132
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(2) SECP256K1_ARG_NONNULL(3)
Definition: secp256k1.c:534
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Definition: secp256k1.c:60
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const secp256k1_pubkey *pubkey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition: secp256k1.c:297