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
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
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.
54 unsigned char data
[64];
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_parse_* functions.
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
,
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))
100 # define SECP256K1_GNUC_PREREQ(_maj,_min) 0
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
110 # define SECP256K1_INLINE
113 # define SECP256K1_INLINE inline
116 #ifndef SECP256K1_API
118 # ifdef SECP256K1_BUILD
119 # define SECP256K1_API __declspec(dllexport)
121 # define SECP256K1_API
123 # elif defined(__GNUC__) && defined(SECP256K1_BUILD)
124 # define SECP256K1_API __attribute__ ((visibility ("default")))
126 # define SECP256K1_API
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__))
136 # define SECP256K1_WARN_UNUSED_RESULT
138 # if !defined(SECP256K1_BUILD) && defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
139 # define SECP256K1_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x)))
141 # define SECP256K1_ARG_NONNULL(_x)
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 /** Prefix byte used to tag various encoded curvepoints for specific purposes */
163 #define SECP256K1_TAG_PUBKEY_EVEN 0x02
164 #define SECP256K1_TAG_PUBKEY_ODD 0x03
165 #define SECP256K1_TAG_PUBKEY_UNCOMPRESSED 0x04
166 #define SECP256K1_TAG_PUBKEY_HYBRID_EVEN 0x06
167 #define SECP256K1_TAG_PUBKEY_HYBRID_ODD 0x07
169 /** Create a secp256k1 context object.
171 * Returns: a newly created context object.
172 * In: flags: which parts of the context to initialize.
174 * See also secp256k1_context_randomize.
176 SECP256K1_API secp256k1_context
* secp256k1_context_create(
178 ) SECP256K1_WARN_UNUSED_RESULT
;
180 /** Copies a secp256k1 context object.
182 * Returns: a newly created context object.
183 * Args: ctx: an existing context to copy (cannot be NULL)
185 SECP256K1_API secp256k1_context
* secp256k1_context_clone(
186 const secp256k1_context
* ctx
187 ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT
;
189 /** Destroy a secp256k1 context object.
191 * The context pointer may not be used afterwards.
192 * Args: ctx: an existing context to destroy (cannot be NULL)
194 SECP256K1_API
void secp256k1_context_destroy(
195 secp256k1_context
* ctx
198 /** Set a callback function to be called when an illegal argument is passed to
199 * an API call. It will only trigger for violations that are mentioned
200 * explicitly in the header.
202 * The philosophy is that these shouldn't be dealt with through a
203 * specific return value, as calling code should not have branches to deal with
204 * the case that this code itself is broken.
206 * On the other hand, during debug stage, one would want to be informed about
207 * such mistakes, and the default (crashing) may be inadvisable.
208 * When this callback is triggered, the API function called is guaranteed not
209 * to cause a crash, though its return value and output arguments are
212 * Args: ctx: an existing context object (cannot be NULL)
213 * In: fun: a pointer to a function to call when an illegal argument is
214 * passed to the API, taking a message and an opaque pointer
215 * (NULL restores a default handler that calls abort).
216 * data: the opaque pointer to pass to fun above.
218 SECP256K1_API
void secp256k1_context_set_illegal_callback(
219 secp256k1_context
* ctx
,
220 void (*fun
)(const char* message
, void* data
),
222 ) SECP256K1_ARG_NONNULL(1);
224 /** Set a callback function to be called when an internal consistency check
225 * fails. The default is crashing.
227 * This can only trigger in case of a hardware failure, miscompilation,
228 * memory corruption, serious bug in the library, or other error would can
229 * otherwise result in undefined behaviour. It will not trigger due to mere
230 * incorrect usage of the API (see secp256k1_context_set_illegal_callback
231 * for that). After this callback returns, anything may happen, including
234 * Args: ctx: an existing context object (cannot be NULL)
235 * In: fun: a pointer to a function to call when an internal error occurs,
236 * taking a message and an opaque pointer (NULL restores a default
237 * handler that calls abort).
238 * data: the opaque pointer to pass to fun above.
240 SECP256K1_API
void secp256k1_context_set_error_callback(
241 secp256k1_context
* ctx
,
242 void (*fun
)(const char* message
, void* data
),
244 ) SECP256K1_ARG_NONNULL(1);
246 /** Parse a variable-length public key into the pubkey object.
248 * Returns: 1 if the public key was fully valid.
249 * 0 if the public key could not be parsed or is invalid.
250 * Args: ctx: a secp256k1 context object.
251 * Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to a
252 * parsed version of input. If not, its value is undefined.
253 * In: input: pointer to a serialized public key
254 * inputlen: length of the array pointed to by input
256 * This function supports parsing compressed (33 bytes, header byte 0x02 or
257 * 0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header
258 * byte 0x06 or 0x07) format public keys.
260 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ec_pubkey_parse(
261 const secp256k1_context
* ctx
,
262 secp256k1_pubkey
* pubkey
,
263 const unsigned char *input
,
265 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
267 /** Serialize a pubkey object into a serialized byte sequence.
270 * Args: ctx: a secp256k1 context object.
271 * Out: output: a pointer to a 65-byte (if compressed==0) or 33-byte (if
272 * compressed==1) byte array to place the serialized key
274 * In/Out: outputlen: a pointer to an integer which is initially set to the
275 * size of output, and is overwritten with the written
277 * In: pubkey: a pointer to a secp256k1_pubkey containing an
278 * initialized public key.
279 * flags: SECP256K1_EC_COMPRESSED if serialization should be in
280 * compressed format, otherwise SECP256K1_EC_UNCOMPRESSED.
282 SECP256K1_API
int secp256k1_ec_pubkey_serialize(
283 const secp256k1_context
* ctx
,
284 unsigned char *output
,
286 const secp256k1_pubkey
* pubkey
,
288 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
290 /** Parse an ECDSA signature in compact (64 bytes) format.
292 * Returns: 1 when the signature could be parsed, 0 otherwise.
293 * Args: ctx: a secp256k1 context object
294 * Out: sig: a pointer to a signature object
295 * In: input64: a pointer to the 64-byte array to parse
297 * The signature must consist of a 32-byte big endian R value, followed by a
298 * 32-byte big endian S value. If R or S fall outside of [0..order-1], the
299 * encoding is invalid. R and S with value 0 are allowed in the encoding.
301 * After the call, sig will always be initialized. If parsing failed or R or
302 * S are zero, the resulting sig value is guaranteed to fail validation for any
303 * message and public key.
305 SECP256K1_API
int secp256k1_ecdsa_signature_parse_compact(
306 const secp256k1_context
* ctx
,
307 secp256k1_ecdsa_signature
* sig
,
308 const unsigned char *input64
309 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
311 /** Parse a DER ECDSA signature.
313 * Returns: 1 when the signature could be parsed, 0 otherwise.
314 * Args: ctx: a secp256k1 context object
315 * Out: sig: a pointer to a signature object
316 * In: input: a pointer to the signature to be parsed
317 * inputlen: the length of the array pointed to be input
319 * This function will accept any valid DER encoded signature, even if the
320 * encoded numbers are out of range.
322 * After the call, sig will always be initialized. If parsing failed or the
323 * encoded numbers are out of range, signature validation with it is
324 * guaranteed to fail for every message and public key.
326 SECP256K1_API
int secp256k1_ecdsa_signature_parse_der(
327 const secp256k1_context
* ctx
,
328 secp256k1_ecdsa_signature
* sig
,
329 const unsigned char *input
,
331 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
333 /** Serialize an ECDSA signature in DER format.
335 * Returns: 1 if enough space was available to serialize, 0 otherwise
336 * Args: ctx: a secp256k1 context object
337 * Out: output: a pointer to an array to store the DER serialization
338 * In/Out: outputlen: a pointer to a length integer. Initially, this integer
339 * should be set to the length of output. After the call
340 * it will be set to the length of the serialization (even
341 * if 0 was returned).
342 * In: sig: a pointer to an initialized signature object
344 SECP256K1_API
int secp256k1_ecdsa_signature_serialize_der(
345 const secp256k1_context
* ctx
,
346 unsigned char *output
,
348 const secp256k1_ecdsa_signature
* sig
349 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
351 /** Serialize an ECDSA signature in compact (64 byte) format.
354 * Args: ctx: a secp256k1 context object
355 * Out: output64: a pointer to a 64-byte array to store the compact serialization
356 * In: sig: a pointer to an initialized signature object
358 * See secp256k1_ecdsa_signature_parse_compact for details about the encoding.
360 SECP256K1_API
int secp256k1_ecdsa_signature_serialize_compact(
361 const secp256k1_context
* ctx
,
362 unsigned char *output64
,
363 const secp256k1_ecdsa_signature
* sig
364 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
366 /** Verify an ECDSA signature.
368 * Returns: 1: correct signature
369 * 0: incorrect or unparseable signature
370 * Args: ctx: a secp256k1 context object, initialized for verification.
371 * In: sig: the signature being verified (cannot be NULL)
372 * msg32: the 32-byte message hash being verified (cannot be NULL)
373 * pubkey: pointer to an initialized public key to verify with (cannot be NULL)
375 * To avoid accepting malleable signatures, only ECDSA signatures in lower-S
378 * If you need to accept ECDSA signatures from sources that do not obey this
379 * rule, apply secp256k1_ecdsa_signature_normalize to the signature prior to
380 * validation, but be aware that doing so results in malleable signatures.
382 * For details, see the comments for that function.
384 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ecdsa_verify(
385 const secp256k1_context
* ctx
,
386 const secp256k1_ecdsa_signature
*sig
,
387 const unsigned char *msg32
,
388 const secp256k1_pubkey
*pubkey
389 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
391 /** Convert a signature to a normalized lower-S form.
393 * Returns: 1 if sigin was not normalized, 0 if it already was.
394 * Args: ctx: a secp256k1 context object
395 * Out: sigout: a pointer to a signature to fill with the normalized form,
396 * or copy if the input was already normalized. (can be NULL if
397 * you're only interested in whether the input was already
399 * In: sigin: a pointer to a signature to check/normalize (cannot be NULL,
400 * can be identical to sigout)
402 * With ECDSA a third-party can forge a second distinct signature of the same
403 * message, given a single initial signature, but without knowing the key. This
404 * is done by negating the S value modulo the order of the curve, 'flipping'
405 * the sign of the random point R which is not included in the signature.
407 * Forgery of the same message isn't universally problematic, but in systems
408 * where message malleability or uniqueness of signatures is important this can
409 * cause issues. This forgery can be blocked by all verifiers forcing signers
410 * to use a normalized form.
412 * The lower-S form reduces the size of signatures slightly on average when
413 * variable length encodings (such as DER) are used and is cheap to verify,
414 * making it a good choice. Security of always using lower-S is assured because
415 * anyone can trivially modify a signature after the fact to enforce this
418 * The lower S value is always between 0x1 and
419 * 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
422 * No other forms of ECDSA malleability are known and none seem likely, but
423 * there is no formal proof that ECDSA, even with this additional restriction,
424 * is free of other malleability. Commonly used serialization schemes will also
425 * accept various non-unique encodings, so care should be taken when this
426 * property is required for an application.
428 * The secp256k1_ecdsa_sign function will by default create signatures in the
429 * lower-S form, and secp256k1_ecdsa_verify will not accept others. In case
430 * signatures come from a system that cannot enforce this property,
431 * secp256k1_ecdsa_signature_normalize must be called before verification.
433 SECP256K1_API
int secp256k1_ecdsa_signature_normalize(
434 const secp256k1_context
* ctx
,
435 secp256k1_ecdsa_signature
*sigout
,
436 const secp256k1_ecdsa_signature
*sigin
437 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3);
439 /** An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function.
440 * If a data pointer is passed, it is assumed to be a pointer to 32 bytes of
443 SECP256K1_API
extern const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
;
445 /** A default safe nonce generation function (currently equal to secp256k1_nonce_function_rfc6979). */
446 SECP256K1_API
extern const secp256k1_nonce_function secp256k1_nonce_function_default
;
448 /** Create an ECDSA signature.
450 * Returns: 1: signature created
451 * 0: the nonce generation function failed, or the private key was invalid.
452 * Args: ctx: pointer to a context object, initialized for signing (cannot be NULL)
453 * Out: sig: pointer to an array where the signature will be placed (cannot be NULL)
454 * In: msg32: the 32-byte message hash being signed (cannot be NULL)
455 * seckey: pointer to a 32-byte secret key (cannot be NULL)
456 * noncefp:pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used
457 * ndata: pointer to arbitrary data used by the nonce generation function (can be NULL)
459 * The created signature is always in lower-S form. See
460 * secp256k1_ecdsa_signature_normalize for more details.
462 SECP256K1_API
int secp256k1_ecdsa_sign(
463 const secp256k1_context
* ctx
,
464 secp256k1_ecdsa_signature
*sig
,
465 const unsigned char *msg32
,
466 const unsigned char *seckey
,
467 secp256k1_nonce_function noncefp
,
469 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
471 /** Verify an ECDSA secret key.
473 * Returns: 1: secret key is valid
474 * 0: secret key is invalid
475 * Args: ctx: pointer to a context object (cannot be NULL)
476 * In: seckey: pointer to a 32-byte secret key (cannot be NULL)
478 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ec_seckey_verify(
479 const secp256k1_context
* ctx
,
480 const unsigned char *seckey
481 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
483 /** Compute the public key for a secret key.
485 * Returns: 1: secret was valid, public key stores
486 * 0: secret was invalid, try again
487 * Args: ctx: pointer to a context object, initialized for signing (cannot be NULL)
488 * Out: pubkey: pointer to the created public key (cannot be NULL)
489 * In: seckey: pointer to a 32-byte private key (cannot be NULL)
491 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ec_pubkey_create(
492 const secp256k1_context
* ctx
,
493 secp256k1_pubkey
*pubkey
,
494 const unsigned char *seckey
495 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
497 /** Negates a private key in place.
500 * Args: ctx: pointer to a context object
501 * In/Out: pubkey: pointer to the public key to be negated (cannot be NULL)
503 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ec_privkey_negate(
504 const secp256k1_context
* ctx
,
505 unsigned char *seckey
506 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
508 /** Negates a public key in place.
511 * Args: ctx: pointer to a context object
512 * In/Out: pubkey: pointer to the public key to be negated (cannot be NULL)
514 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ec_pubkey_negate(
515 const secp256k1_context
* ctx
,
516 secp256k1_pubkey
*pubkey
517 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
519 /** Tweak a private key by adding tweak to it.
520 * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
521 * uniformly random 32-byte arrays, or if the resulting private key
522 * would be invalid (only when the tweak is the complement of the
523 * private key). 1 otherwise.
524 * Args: ctx: pointer to a context object (cannot be NULL).
525 * In/Out: seckey: pointer to a 32-byte private key.
526 * In: tweak: pointer to a 32-byte tweak.
528 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ec_privkey_tweak_add(
529 const secp256k1_context
* ctx
,
530 unsigned char *seckey
,
531 const unsigned char *tweak
532 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
534 /** Tweak a public key by adding tweak times the generator to it.
535 * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
536 * uniformly random 32-byte arrays, or if the resulting public key
537 * would be invalid (only when the tweak is the complement of the
538 * corresponding private key). 1 otherwise.
539 * Args: ctx: pointer to a context object initialized for validation
541 * In/Out: pubkey: pointer to a public key object.
542 * In: tweak: pointer to a 32-byte tweak.
544 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ec_pubkey_tweak_add(
545 const secp256k1_context
* ctx
,
546 secp256k1_pubkey
*pubkey
,
547 const unsigned char *tweak
548 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
550 /** Tweak a private key by multiplying it by a tweak.
551 * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
552 * uniformly random 32-byte arrays, or equal to zero. 1 otherwise.
553 * Args: ctx: pointer to a context object (cannot be NULL).
554 * In/Out: seckey: pointer to a 32-byte private key.
555 * In: tweak: pointer to a 32-byte tweak.
557 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ec_privkey_tweak_mul(
558 const secp256k1_context
* ctx
,
559 unsigned char *seckey
,
560 const unsigned char *tweak
561 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
563 /** Tweak a public key by multiplying it by a tweak value.
564 * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
565 * uniformly random 32-byte arrays, or equal to zero. 1 otherwise.
566 * Args: ctx: pointer to a context object initialized for validation
568 * In/Out: pubkey: pointer to a public key obkect.
569 * In: tweak: pointer to a 32-byte tweak.
571 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ec_pubkey_tweak_mul(
572 const secp256k1_context
* ctx
,
573 secp256k1_pubkey
*pubkey
,
574 const unsigned char *tweak
575 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
577 /** Updates the context randomization to protect against side-channel leakage.
578 * Returns: 1: randomization successfully updated
580 * Args: ctx: pointer to a context object (cannot be NULL)
581 * In: seed32: pointer to a 32-byte random seed (NULL resets to initial state)
583 * While secp256k1 code is written to be constant-time no matter what secret
584 * values are, it's possible that a future compiler may output code which isn't,
585 * and also that the CPU may not emit the same radio frequencies or draw the same
586 * amount power for all values.
588 * This function provides a seed which is combined into the blinding value: that
589 * blinding value is added before each multiplication (and removed afterwards) so
590 * that it does not affect function results, but shields against attacks which
591 * rely on any input-dependent behaviour.
593 * You should call this after secp256k1_context_create or
594 * secp256k1_context_clone, and may call this repeatedly afterwards.
596 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_context_randomize(
597 secp256k1_context
* ctx
,
598 const unsigned char *seed32
599 ) SECP256K1_ARG_NONNULL(1);
601 /** Add a number of public keys together.
602 * Returns: 1: the sum of the public keys is valid.
603 * 0: the sum of the public keys is not valid.
604 * Args: ctx: pointer to a context object
605 * Out: out: pointer to a public key object for placing the resulting public key
607 * In: ins: pointer to array of pointers to public keys (cannot be NULL)
608 * n: the number of public keys to add together (must be at least 1)
610 SECP256K1_API SECP256K1_WARN_UNUSED_RESULT
int secp256k1_ec_pubkey_combine(
611 const secp256k1_context
* ctx
,
612 secp256k1_pubkey
*out
,
613 const secp256k1_pubkey
* const * ins
,
615 ) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
621 #endif /* SECP256K1_H */