Squashed 'src/secp256k1/' changes from 8225239..84973d3
[bitcoinplatinum.git] / include / secp256k1.h
blobfc4c5cefbb3b654855908761b9a68be88303b813
1 #ifndef _SECP256K1_
2 # define _SECP256K1_
4 # ifdef __cplusplus
5 extern "C" {
6 # endif
8 #include <stddef.h>
10 /* These rules specify the order of arguments in API calls:
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.
25 /** Opaque data structure that holds context information (precomputed tables etc.).
27 * The purpose of context structures is to cache large precomputed data tables
28 * that are expensive to construct, and also to maintain the randomization data
29 * for blinding.
31 * Do not create a new context object for each operation, as construction is
32 * far slower than all other API calls (~100 times slower than an ECDSA
33 * verification).
35 * A constructed context can safely be used from multiple threads
36 * simultaneously, but API call that take a non-const pointer to a context
37 * need exclusive access to it. In particular this is the case for
38 * secp256k1_context_destroy and secp256k1_context_randomize.
40 * Regarding randomization, either do it once at creation time (in which case
41 * you do not need any locking for the other calls), or use a read-write lock.
43 typedef struct secp256k1_context_struct secp256k1_context;
45 /** Opaque data structure that holds a parsed and valid public key.
47 * The exact representation of data inside is implementation defined and not
48 * guaranteed to be portable between different platforms or versions. It is
49 * however guaranteed to be 64 bytes in size, and can be safely copied/moved.
50 * If you need to convert to a format suitable for storage, transmission, or
51 * comparison, use secp256k1_ec_pubkey_serialize and secp256k1_ec_pubkey_parse.
53 typedef struct {
54 unsigned char data[64];
55 } secp256k1_pubkey;
57 /** Opaque data structured that holds a parsed ECDSA signature.
59 * The exact representation of data inside is implementation defined and not
60 * guaranteed to be portable between different platforms or versions. It is
61 * however guaranteed to be 64 bytes in size, and can be safely copied/moved.
62 * If you need to convert to a format suitable for storage, transmission, or
63 * comparison, use the secp256k1_ecdsa_signature_serialize_* and
64 * secp256k1_ecdsa_signature_serialize_* functions.
66 typedef struct {
67 unsigned char data[64];
68 } secp256k1_ecdsa_signature;
70 /** A pointer to a function to deterministically generate a nonce.
72 * Returns: 1 if a nonce was successfully generated. 0 will cause signing to fail.
73 * Out: nonce32: pointer to a 32-byte array to be filled by the function.
74 * In: msg32: the 32-byte message hash being verified (will not be NULL)
75 * key32: pointer to a 32-byte secret key (will not be NULL)
76 * algo16: pointer to a 16-byte array describing the signature
77 * algorithm (will be NULL for ECDSA for compatibility).
78 * data: Arbitrary data pointer that is passed through.
79 * attempt: how many iterations we have tried to find a nonce.
80 * This will almost always be 0, but different attempt values
81 * are required to result in a different nonce.
83 * Except for test cases, this function should compute some cryptographic hash of
84 * the message, the algorithm, the key and the attempt.
86 typedef int (*secp256k1_nonce_function)(
87 unsigned char *nonce32,
88 const unsigned char *msg32,
89 const unsigned char *key32,
90 const unsigned char *algo16,
91 void *data,
92 unsigned int attempt
95 # if !defined(SECP256K1_GNUC_PREREQ)
96 # if defined(__GNUC__)&&defined(__GNUC_MINOR__)
97 # define SECP256K1_GNUC_PREREQ(_maj,_min) \
98 ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
99 # else
100 # define SECP256K1_GNUC_PREREQ(_maj,_min) 0
101 # endif
102 # endif
104 # if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )
105 # if SECP256K1_GNUC_PREREQ(2,7)
106 # define SECP256K1_INLINE __inline__
107 # elif (defined(_MSC_VER))
108 # define SECP256K1_INLINE __inline
109 # else
110 # define SECP256K1_INLINE
111 # endif
112 # else
113 # define SECP256K1_INLINE inline
114 # endif
116 #ifndef SECP256K1_API
117 # if defined(_WIN32)
118 # ifdef SECP256K1_BUILD
119 # define SECP256K1_API __declspec(dllexport)
120 # else
121 # define SECP256K1_API
122 # endif
123 # elif defined(__GNUC__) && defined(SECP256K1_BUILD)
124 # define SECP256K1_API __attribute__ ((visibility ("default")))
125 # else
126 # define SECP256K1_API
127 # endif
128 #endif
130 /**Warning attributes
131 * NONNULL is not used if SECP256K1_BUILD is set to avoid the compiler optimizing out
132 * some paranoid null checks. */
133 # if defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
134 # define SECP256K1_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
135 # else
136 # define SECP256K1_WARN_UNUSED_RESULT
137 # endif
138 # if !defined(SECP256K1_BUILD) && defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
139 # define SECP256K1_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x)))
140 # else
141 # define SECP256K1_ARG_NONNULL(_x)
142 # endif
144 /** All flags' lower 8 bits indicate what they're for. Do not use directly. */
145 #define SECP256K1_FLAGS_TYPE_MASK ((1 << 8) - 1)
146 #define SECP256K1_FLAGS_TYPE_CONTEXT (1 << 0)
147 #define SECP256K1_FLAGS_TYPE_COMPRESSION (1 << 1)
148 /** The higher bits contain the actual data. Do not use directly. */
149 #define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY (1 << 8)
150 #define SECP256K1_FLAGS_BIT_CONTEXT_SIGN (1 << 9)
151 #define SECP256K1_FLAGS_BIT_COMPRESSION (1 << 8)
153 /** Flags to pass to secp256k1_context_create. */
154 #define SECP256K1_CONTEXT_VERIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_VERIFY)
155 #define SECP256K1_CONTEXT_SIGN (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_SIGN)
156 #define SECP256K1_CONTEXT_NONE (SECP256K1_FLAGS_TYPE_CONTEXT)
158 /** Flag to pass to secp256k1_ec_pubkey_serialize and secp256k1_ec_privkey_export. */
159 #define SECP256K1_EC_COMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION | SECP256K1_FLAGS_BIT_COMPRESSION)
160 #define SECP256K1_EC_UNCOMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION)
162 /** Create a secp256k1 context object.
164 * Returns: a newly created context object.
165 * In: flags: which parts of the context to initialize.
167 * See also secp256k1_context_randomize.
169 SECP256K1_API secp256k1_context* secp256k1_context_create(
170 unsigned int flags
171 ) SECP256K1_WARN_UNUSED_RESULT;
173 /** Copies a secp256k1 context object.
175 * Returns: a newly created context object.
176 * Args: ctx: an existing context to copy (cannot be NULL)
178 SECP256K1_API secp256k1_context* secp256k1_context_clone(
179 const secp256k1_context* ctx
180 ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
182 /** Destroy a secp256k1 context object.
184 * The context pointer may not be used afterwards.
185 * Args: ctx: an existing context to destroy (cannot be NULL)
187 SECP256K1_API void secp256k1_context_destroy(
188 secp256k1_context* ctx
191 /** Set a callback function to be called when an illegal argument is passed to
192 * an API call. It will only trigger for violations that are mentioned
193 * explicitly in the header.
195 * The philosophy is that these shouldn't be dealt with through a
196 * specific return value, as calling code should not have branches to deal with
197 * the case that this code itself is broken.
199 * On the other hand, during debug stage, one would want to be informed about
200 * such mistakes, and the default (crashing) may be inadvisable.
201 * When this callback is triggered, the API function called is guaranteed not
202 * to cause a crash, though its return value and output arguments are
203 * undefined.
205 * Args: ctx: an existing context object (cannot be NULL)
206 * In: fun: a pointer to a function to call when an illegal argument is
207 * passed to the API, taking a message and an opaque pointer
208 * (NULL restores a default handler that calls abort).
209 * data: the opaque pointer to pass to fun above.
211 SECP256K1_API void secp256k1_context_set_illegal_callback(
212 secp256k1_context* ctx,
213 void (*fun)(const char* message, void* data),
214 const void* data
215 ) SECP256K1_ARG_NONNULL(1);
217 /** Set a callback function to be called when an internal consistency check
218 * fails. The default is crashing.
220 * This can only trigger in case of a hardware failure, miscompilation,
221 * memory corruption, serious bug in the library, or other error would can
222 * otherwise result in undefined behaviour. It will not trigger due to mere
223 * incorrect usage of the API (see secp256k1_context_set_illegal_callback
224 * for that). After this callback returns, anything may happen, including
225 * crashing.
227 * Args: ctx: an existing context object (cannot be NULL)
228 * In: fun: a pointer to a function to call when an internal error occurs,
229 * taking a message and an opaque pointer (NULL restores a default
230 * handler that calls abort).
231 * data: the opaque pointer to pass to fun above.
233 SECP256K1_API void secp256k1_context_set_error_callback(
234 secp256k1_context* ctx,
235 void (*fun)(const char* message, void* data),
236 const void* data
237 ) SECP256K1_ARG_NONNULL(1);
239 /** Parse a variable-length public key into the pubkey object.
241 * Returns: 1 if the public key was fully valid.
242 * 0 if the public key could not be parsed or is invalid.
243 * Args: ctx: a secp256k1 context object.
244 * Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to a
245 * parsed version of input. If not, its value is undefined.
246 * In: input: pointer to a serialized public key
247 * inputlen: length of the array pointed to by input
249 * This function supports parsing compressed (33 bytes, header byte 0x02 or
250 * 0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header
251 * byte 0x06 or 0x07) format public keys.
253 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(
254 const secp256k1_context* ctx,
255 secp256k1_pubkey* pubkey,
256 const unsigned char *input,
257 size_t inputlen
258 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
260 /** Serialize a pubkey object into a serialized byte sequence.
262 * Returns: 1 always.
263 * Args: ctx: a secp256k1 context object.
264 * Out: output: a pointer to a 65-byte (if compressed==0) or 33-byte (if
265 * compressed==1) byte array to place the serialized key
266 * in.
267 * In/Out: outputlen: a pointer to an integer which is initially set to the
268 * size of output, and is overwritten with the written
269 * size.
270 * In: pubkey: a pointer to a secp256k1_pubkey containing an
271 * initialized public key.
272 * flags: SECP256K1_EC_COMPRESSED if serialization should be in
273 * compressed format, otherwise SECP256K1_EC_UNCOMPRESSED.
275 SECP256K1_API int secp256k1_ec_pubkey_serialize(
276 const secp256k1_context* ctx,
277 unsigned char *output,
278 size_t *outputlen,
279 const secp256k1_pubkey* pubkey,
280 unsigned int flags
281 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
283 /** Parse an ECDSA signature in compact (64 bytes) format.
285 * Returns: 1 when the signature could be parsed, 0 otherwise.
286 * Args: ctx: a secp256k1 context object
287 * Out: sig: a pointer to a signature object
288 * In: input64: a pointer to the 64-byte array to parse
290 * The signature must consist of a 32-byte big endian R value, followed by a
291 * 32-byte big endian S value. If R or S fall outside of [0..order-1], the
292 * encoding is invalid. R and S with value 0 are allowed in the encoding.
294 * After the call, sig will always be initialized. If parsing failed or R or
295 * S are zero, the resulting sig value is guaranteed to fail validation for any
296 * message and public key.
298 SECP256K1_API int secp256k1_ecdsa_signature_parse_compact(
299 const secp256k1_context* ctx,
300 secp256k1_ecdsa_signature* sig,
301 const unsigned char *input64
302 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
304 /** Parse a DER ECDSA signature.
306 * Returns: 1 when the signature could be parsed, 0 otherwise.
307 * Args: ctx: a secp256k1 context object
308 * Out: sig: a pointer to a signature object
309 * In: input: a pointer to the signature to be parsed
310 * inputlen: the length of the array pointed to be input
312 * This function will accept any valid DER encoded signature, even if the
313 * encoded numbers are out of range.
315 * After the call, sig will always be initialized. If parsing failed or the
316 * encoded numbers are out of range, signature validation with it is
317 * guaranteed to fail for every message and public key.
319 SECP256K1_API int secp256k1_ecdsa_signature_parse_der(
320 const secp256k1_context* ctx,
321 secp256k1_ecdsa_signature* sig,
322 const unsigned char *input,
323 size_t inputlen
324 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
326 /** Serialize an ECDSA signature in DER format.
328 * Returns: 1 if enough space was available to serialize, 0 otherwise
329 * Args: ctx: a secp256k1 context object
330 * Out: output: a pointer to an array to store the DER serialization
331 * In/Out: outputlen: a pointer to a length integer. Initially, this integer
332 * should be set to the length of output. After the call
333 * it will be set to the length of the serialization (even
334 * if 0 was returned).
335 * In: sig: a pointer to an initialized signature object
337 SECP256K1_API int secp256k1_ecdsa_signature_serialize_der(
338 const secp256k1_context* ctx,
339 unsigned char *output,
340 size_t *outputlen,
341 const secp256k1_ecdsa_signature* sig
342 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
344 /** Serialize an ECDSA signature in compact (64 byte) format.
346 * Returns: 1
347 * Args: ctx: a secp256k1 context object
348 * Out: output64: a pointer to a 64-byte array to store the compact serialization
349 * In: sig: a pointer to an initialized signature object
351 * See secp256k1_ecdsa_signature_parse_compact for details about the encoding.
353 SECP256K1_API int secp256k1_ecdsa_signature_serialize_compact(
354 const secp256k1_context* ctx,
355 unsigned char *output64,
356 const secp256k1_ecdsa_signature* sig
357 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
359 /** Verify an ECDSA signature.
361 * Returns: 1: correct signature
362 * 0: incorrect or unparseable signature
363 * Args: ctx: a secp256k1 context object, initialized for verification.
364 * In: sig: the signature being verified (cannot be NULL)
365 * msg32: the 32-byte message hash being verified (cannot be NULL)
366 * pubkey: pointer to an initialized public key to verify with (cannot be NULL)
368 * To avoid accepting malleable signatures, only ECDSA signatures in lower-S
369 * form are accepted.
371 * If you need to accept ECDSA signatures from sources that do not obey this
372 * rule, apply secp256k1_ecdsa_signature_normalize to the signature prior to
373 * validation, but be aware that doing so results in malleable signatures.
375 * For details, see the comments for that function.
377 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(
378 const secp256k1_context* ctx,
379 const secp256k1_ecdsa_signature *sig,
380 const unsigned char *msg32,
381 const secp256k1_pubkey *pubkey
382 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
384 /** Convert a signature to a normalized lower-S form.
386 * Returns: 1 if sigin was not normalized, 0 if it already was.
387 * Args: ctx: a secp256k1 context object
388 * Out: sigout: a pointer to a signature to fill with the normalized form,
389 * or copy if the input was already normalized. (can be NULL if
390 * you're only interested in whether the input was already
391 * normalized).
392 * In: sigin: a pointer to a signature to check/normalize (cannot be NULL,
393 * can be identical to sigout)
395 * With ECDSA a third-party can forge a second distinct signature of the same
396 * message, given a single initial signature, but without knowing the key. This
397 * is done by negating the S value modulo the order of the curve, 'flipping'
398 * the sign of the random point R which is not included in the signature.
400 * Forgery of the same message isn't universally problematic, but in systems
401 * where message malleability or uniqueness of signatures is important this can
402 * cause issues. This forgery can be blocked by all verifiers forcing signers
403 * to use a normalized form.
405 * The lower-S form reduces the size of signatures slightly on average when
406 * variable length encodings (such as DER) are used and is cheap to verify,
407 * making it a good choice. Security of always using lower-S is assured because
408 * anyone can trivially modify a signature after the fact to enforce this
409 * property anyway.
411 * The lower S value is always between 0x1 and
412 * 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
413 * inclusive.
415 * No other forms of ECDSA malleability are known and none seem likely, but
416 * there is no formal proof that ECDSA, even with this additional restriction,
417 * is free of other malleability. Commonly used serialization schemes will also
418 * accept various non-unique encodings, so care should be taken when this
419 * property is required for an application.
421 * The secp256k1_ecdsa_sign function will by default create signatures in the
422 * lower-S form, and secp256k1_ecdsa_verify will not accept others. In case
423 * signatures come from a system that cannot enforce this property,
424 * secp256k1_ecdsa_signature_normalize must be called before verification.
426 SECP256K1_API int secp256k1_ecdsa_signature_normalize(
427 const secp256k1_context* ctx,
428 secp256k1_ecdsa_signature *sigout,
429 const secp256k1_ecdsa_signature *sigin
430 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3);
432 /** An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function.
433 * If a data pointer is passed, it is assumed to be a pointer to 32 bytes of
434 * extra entropy.
436 SECP256K1_API extern const secp256k1_nonce_function secp256k1_nonce_function_rfc6979;
438 /** A default safe nonce generation function (currently equal to secp256k1_nonce_function_rfc6979). */
439 SECP256K1_API extern const secp256k1_nonce_function secp256k1_nonce_function_default;
441 /** Create an ECDSA signature.
443 * Returns: 1: signature created
444 * 0: the nonce generation function failed, or the private key was invalid.
445 * Args: ctx: pointer to a context object, initialized for signing (cannot be NULL)
446 * Out: sig: pointer to an array where the signature will be placed (cannot be NULL)
447 * In: msg32: the 32-byte message hash being signed (cannot be NULL)
448 * seckey: pointer to a 32-byte secret key (cannot be NULL)
449 * noncefp:pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used
450 * ndata: pointer to arbitrary data used by the nonce generation function (can be NULL)
452 * The created signature is always in lower-S form. See
453 * secp256k1_ecdsa_signature_normalize for more details.
455 SECP256K1_API int secp256k1_ecdsa_sign(
456 const secp256k1_context* ctx,
457 secp256k1_ecdsa_signature *sig,
458 const unsigned char *msg32,
459 const unsigned char *seckey,
460 secp256k1_nonce_function noncefp,
461 const void *ndata
462 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
464 /** Verify an ECDSA secret key.
466 * Returns: 1: secret key is valid
467 * 0: secret key is invalid
468 * Args: ctx: pointer to a context object (cannot be NULL)
469 * In: seckey: pointer to a 32-byte secret key (cannot be NULL)
471 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(
472 const secp256k1_context* ctx,
473 const unsigned char *seckey
474 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
476 /** Compute the public key for a secret key.
478 * Returns: 1: secret was valid, public key stores
479 * 0: secret was invalid, try again
480 * Args: ctx: pointer to a context object, initialized for signing (cannot be NULL)
481 * Out: pubkey: pointer to the created public key (cannot be NULL)
482 * In: seckey: pointer to a 32-byte private key (cannot be NULL)
484 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(
485 const secp256k1_context* ctx,
486 secp256k1_pubkey *pubkey,
487 const unsigned char *seckey
488 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
490 /** Negates a private key in place.
492 * Returns: 1 always
493 * Args: ctx: pointer to a context object
494 * In/Out: pubkey: pointer to the public key to be negated (cannot be NULL)
496 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_negate(
497 const secp256k1_context* ctx,
498 unsigned char *seckey
499 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
501 /** Negates a public key in place.
503 * Returns: 1 always
504 * Args: ctx: pointer to a context object
505 * In/Out: pubkey: pointer to the public key to be negated (cannot be NULL)
507 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_negate(
508 const secp256k1_context* ctx,
509 secp256k1_pubkey *pubkey
510 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
512 /** Tweak a private key by adding tweak to it.
513 * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
514 * uniformly random 32-byte arrays, or if the resulting private key
515 * would be invalid (only when the tweak is the complement of the
516 * private key). 1 otherwise.
517 * Args: ctx: pointer to a context object (cannot be NULL).
518 * In/Out: seckey: pointer to a 32-byte private key.
519 * In: tweak: pointer to a 32-byte tweak.
521 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(
522 const secp256k1_context* ctx,
523 unsigned char *seckey,
524 const unsigned char *tweak
525 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
527 /** Tweak a public key by adding tweak times the generator to it.
528 * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
529 * uniformly random 32-byte arrays, or if the resulting public key
530 * would be invalid (only when the tweak is the complement of the
531 * corresponding private key). 1 otherwise.
532 * Args: ctx: pointer to a context object initialized for validation
533 * (cannot be NULL).
534 * In/Out: pubkey: pointer to a public key object.
535 * In: tweak: pointer to a 32-byte tweak.
537 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(
538 const secp256k1_context* ctx,
539 secp256k1_pubkey *pubkey,
540 const unsigned char *tweak
541 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
543 /** Tweak a private key by multiplying it by a tweak.
544 * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
545 * uniformly random 32-byte arrays, or equal to zero. 1 otherwise.
546 * Args: ctx: pointer to a context object (cannot be NULL).
547 * In/Out: seckey: pointer to a 32-byte private key.
548 * In: tweak: pointer to a 32-byte tweak.
550 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul(
551 const secp256k1_context* ctx,
552 unsigned char *seckey,
553 const unsigned char *tweak
554 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
556 /** Tweak a public key by multiplying it by a tweak value.
557 * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
558 * uniformly random 32-byte arrays, or equal to zero. 1 otherwise.
559 * Args: ctx: pointer to a context object initialized for validation
560 * (cannot be NULL).
561 * In/Out: pubkey: pointer to a public key obkect.
562 * In: tweak: pointer to a 32-byte tweak.
564 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(
565 const secp256k1_context* ctx,
566 secp256k1_pubkey *pubkey,
567 const unsigned char *tweak
568 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
570 /** Updates the context randomization to protect against side-channel leakage.
571 * Returns: 1: randomization successfully updated
572 * 0: error
573 * Args: ctx: pointer to a context object (cannot be NULL)
574 * In: seed32: pointer to a 32-byte random seed (NULL resets to initial state)
576 * While secp256k1 code is written to be constant-time no matter what secret
577 * values are, it's possible that a future compiler may output code which isn't,
578 * and also that the CPU may not emit the same radio frequencies or draw the same
579 * amount power for all values.
581 * This function provides a seed which is combined into the blinding value: that
582 * blinding value is added before each multiplication (and removed afterwards) so
583 * that it does not affect function results, but shields against attacks which
584 * rely on any input-dependent behaviour.
586 * You should call this after secp256k1_context_create or
587 * secp256k1_context_clone, and may call this repeatedly afterwards.
589 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(
590 secp256k1_context* ctx,
591 const unsigned char *seed32
592 ) SECP256K1_ARG_NONNULL(1);
594 /** Add a number of public keys together.
595 * Returns: 1: the sum of the public keys is valid.
596 * 0: the sum of the public keys is not valid.
597 * Args: ctx: pointer to a context object
598 * Out: out: pointer to a public key object for placing the resulting public key
599 * (cannot be NULL)
600 * In: ins: pointer to array of pointers to public keys (cannot be NULL)
601 * n: the number of public keys to add together (must be at least 1)
603 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_combine(
604 const secp256k1_context* ctx,
605 secp256k1_pubkey *out,
606 const secp256k1_pubkey * const * ins,
607 size_t n
608 ) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
610 # ifdef __cplusplus
612 # endif
614 #endif