github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/crypto/secp256k1/libsecp256k1/include/secp256k1.h (about)

     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  
    25  /** Opaque data structure that holds context information (precomputed tables etc.).
    26   *
    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.
    30   *
    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).
    34   *
    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.
    39   *
    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.
    42   */
    43  typedef struct secp256k1_context_struct secp256k1_context;
    44  
    45  /** Opaque data structure that holds a parsed and valid public key.
    46   *
    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 or transmission, use
    51   *  secp256k1_ec_pubkey_serialize and secp256k1_ec_pubkey_parse.
    52   *
    53   *  Furthermore, it is guaranteed that identical public keys (ignoring
    54   *  compression) will have identical representation, so they can be memcmp'ed.
    55   */
    56  typedef struct {
    57      unsigned char data[64];
    58  } secp256k1_pubkey;
    59  
    60  /** Opaque data structured that holds a parsed ECDSA signature.
    61   *
    62   *  The exact representation of data inside is implementation defined and not
    63   *  guaranteed to be portable between different platforms or versions. It is
    64   *  however guaranteed to be 64 bytes in size, and can be safely copied/moved.
    65   *  If you need to convert to a format suitable for storage or transmission, use
    66   *  the secp256k1_ecdsa_signature_serialize_* and
    67   *  secp256k1_ecdsa_signature_serialize_* functions.
    68   *
    69   *  Furthermore, it is guaranteed to identical signatures will have identical
    70   *  representation, so they can be memcmp'ed.
    71   */
    72  typedef struct {
    73      unsigned char data[64];
    74  } secp256k1_ecdsa_signature;
    75  
    76  /** A pointer to a function to deterministically generate a nonce.
    77   *
    78   * Returns: 1 if a nonce was successfully generated. 0 will cause signing to fail.
    79   * Out:     nonce32:   pointer to a 32-byte array to be filled by the function.
    80   * In:      msg32:     the 32-byte message hash being verified (will not be NULL)
    81   *          key32:     pointer to a 32-byte secret key (will not be NULL)
    82   *          algo16:    pointer to a 16-byte array describing the signature
    83   *                     algorithm (will be NULL for ECDSA for compatibility).
    84   *          data:      Arbitrary data pointer that is passed through.
    85   *          attempt:   how many iterations we have tried to find a nonce.
    86   *                     This will almost always be 0, but different attempt values
    87   *                     are required to result in a different nonce.
    88   *
    89   * Except for test cases, this function should compute some cryptographic hash of
    90   * the message, the algorithm, the key and the attempt.
    91   */
    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  
   136  /**Warning attributes
   137    * NONNULL is not used if SECP256K1_BUILD is set to avoid the compiler optimizing out
   138    * some paranoid null checks. */
   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  
   150  /** Flags to pass to secp256k1_context_create. */
   151  # define SECP256K1_CONTEXT_VERIFY (1 << 0)
   152  # define SECP256K1_CONTEXT_SIGN   (1 << 1)
   153  
   154  /** Flag to pass to secp256k1_ec_pubkey_serialize and secp256k1_ec_privkey_export. */
   155  # define SECP256K1_EC_COMPRESSED  (1 << 0)
   156  
   157  /** Create a secp256k1 context object.
   158   *
   159   *  Returns: a newly created context object.
   160   *  In:      flags: which parts of the context to initialize.
   161   */
   162  SECP256K1_API secp256k1_context* secp256k1_context_create(
   163      unsigned int flags
   164  ) SECP256K1_WARN_UNUSED_RESULT;
   165  
   166  /** Copies a secp256k1 context object.
   167   *
   168   *  Returns: a newly created context object.
   169   *  Args:    ctx: an existing context to copy (cannot be NULL)
   170   */
   171  SECP256K1_API secp256k1_context* secp256k1_context_clone(
   172      const secp256k1_context* ctx
   173  ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
   174  
   175  /** Destroy a secp256k1 context object.
   176   *
   177   *  The context pointer may not be used afterwards.
   178   *  Args:   ctx: an existing context to destroy (cannot be NULL)
   179   */
   180  SECP256K1_API void secp256k1_context_destroy(
   181      secp256k1_context* ctx
   182  );
   183  
   184  /** Set a callback function to be called when an illegal argument is passed to
   185   *  an API call. It will only trigger for violations that are mentioned
   186   *  explicitly in the header.
   187   *
   188   *  The philosophy is that these shouldn't be dealt with through a
   189   *  specific return value, as calling code should not have branches to deal with
   190   *  the case that this code itself is broken.
   191   *
   192   *  On the other hand, during debug stage, one would want to be informed about
   193   *  such mistakes, and the default (crashing) may be inadvisable.
   194   *  When this callback is triggered, the API function called is guaranteed not
   195   *  to cause a crash, though its return value and output arguments are
   196   *  undefined.
   197   *
   198   *  Args: ctx:  an existing context object (cannot be NULL)
   199   *  In:   fun:  a pointer to a function to call when an illegal argument is
   200   *              passed to the API, taking a message and an opaque pointer
   201   *              (NULL restores a default handler that calls abort).
   202   *        data: the opaque pointer to pass to fun above.
   203   */
   204  SECP256K1_API void secp256k1_context_set_illegal_callback(
   205      secp256k1_context* ctx,
   206      void (*fun)(const char* message, void* data),
   207      const void* data
   208  ) SECP256K1_ARG_NONNULL(1);
   209  
   210  /** Set a callback function to be called when an internal consistency check
   211   *  fails. The default is crashing.
   212   *
   213   *  This can only trigger in case of a hardware failure, miscompilation,
   214   *  memory corruption, serious bug in the library, or other error would can
   215   *  otherwise result in undefined behaviour. It will not trigger due to mere
   216   *  incorrect usage of the API (see secp256k1_context_set_illegal_callback
   217   *  for that). After this callback returns, anything may happen, including
   218   *  crashing.
   219   *
   220   *  Args: ctx:  an existing context object (cannot be NULL)
   221   *  In:   fun:  a pointer to a function to call when an interal error occurs,
   222   *              taking a message and an opaque pointer (NULL restores a default
   223   *              handler that calls abort).
   224   *        data: the opaque pointer to pass to fun above.
   225   */
   226  SECP256K1_API void secp256k1_context_set_error_callback(
   227      secp256k1_context* ctx,
   228      void (*fun)(const char* message, void* data),
   229      const void* data
   230  ) SECP256K1_ARG_NONNULL(1);
   231  
   232  /** Parse a variable-length public key into the pubkey object.
   233   *
   234   *  Returns: 1 if the public key was fully valid.
   235   *           0 if the public key could not be parsed or is invalid.
   236   *  Args: ctx:      a secp256k1 context object.
   237   *  Out:  pubkey:   pointer to a pubkey object. If 1 is returned, it is set to a
   238   *                  parsed version of input. If not, its value is undefined.
   239   *  In:   input:    pointer to a serialized public key
   240   *        inputlen: length of the array pointed to by input
   241   *
   242   *  This function supports parsing compressed (33 bytes, header byte 0x02 or
   243   *  0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header
   244   *  byte 0x06 or 0x07) format public keys.
   245   */
   246  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(
   247      const secp256k1_context* ctx,
   248      secp256k1_pubkey* pubkey,
   249      const unsigned char *input,
   250      size_t inputlen
   251  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   252  
   253  /** Serialize a pubkey object into a serialized byte sequence.
   254   *
   255   *  Returns: 1 always.
   256   *  Args: ctx:        a secp256k1 context object.
   257   *  Out:  output:     a pointer to a 65-byte (if compressed==0) or 33-byte (if
   258   *                    compressed==1) byte array to place the serialized key in.
   259   *        outputlen:  a pointer to an integer which will contain the serialized
   260   *                    size.
   261   *  In:   pubkey:     a pointer to a secp256k1_pubkey containing an initialized
   262   *                    public key.
   263   *        flags:      SECP256K1_EC_COMPRESSED if serialization should be in
   264   *                    compressed format.
   265   */
   266  SECP256K1_API int secp256k1_ec_pubkey_serialize(
   267      const secp256k1_context* ctx,
   268      unsigned char *output,
   269      size_t *outputlen,
   270      const secp256k1_pubkey* pubkey,
   271      unsigned int flags
   272  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
   273  
   274  /** Parse a DER ECDSA signature.
   275   *
   276   *  Returns: 1 when the signature could be parsed, 0 otherwise.
   277   *  Args: ctx:      a secp256k1 context object
   278   *  Out:  sig:      a pointer to a signature object
   279   *  In:   input:    a pointer to the signature to be parsed
   280   *        inputlen: the length of the array pointed to be input
   281   *
   282   *  Note that this function also supports some violations of DER and even BER.
   283   */
   284  SECP256K1_API int secp256k1_ecdsa_signature_parse_der(
   285      const secp256k1_context* ctx,
   286      secp256k1_ecdsa_signature* sig,
   287      const unsigned char *input,
   288      size_t inputlen
   289  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   290  
   291  /** Serialize an ECDSA signature in DER format.
   292   *
   293   *  Returns: 1 if enough space was available to serialize, 0 otherwise
   294   *  Args:   ctx:       a secp256k1 context object
   295   *  Out:    output:    a pointer to an array to store the DER serialization
   296   *  In/Out: outputlen: a pointer to a length integer. Initially, this integer
   297   *                     should be set to the length of output. After the call
   298   *                     it will be set to the length of the serialization (even
   299   *                     if 0 was returned).
   300   *  In:     sig:       a pointer to an initialized signature object
   301   */
   302  SECP256K1_API int secp256k1_ecdsa_signature_serialize_der(
   303      const secp256k1_context* ctx,
   304      unsigned char *output,
   305      size_t *outputlen,
   306      const secp256k1_ecdsa_signature* sig
   307  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
   308  
   309  /** Verify an ECDSA signature.
   310   *
   311   *  Returns: 1: correct signature
   312   *           0: incorrect or unparseable signature
   313   *  Args:    ctx:       a secp256k1 context object, initialized for verification.
   314   *  In:      sig:       the signature being verified (cannot be NULL)
   315   *           msg32:     the 32-byte message hash being verified (cannot be NULL)
   316   *           pubkey:    pointer to an initialized public key to verify with (cannot be NULL)
   317   */
   318  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(
   319      const secp256k1_context* ctx,
   320      const secp256k1_ecdsa_signature *sig,
   321      const unsigned char *msg32,
   322      const secp256k1_pubkey *pubkey
   323  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
   324  
   325  /** An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function.
   326   * If a data pointer is passed, it is assumed to be a pointer to 32 bytes of
   327   * extra entropy.
   328   */
   329  extern const secp256k1_nonce_function secp256k1_nonce_function_rfc6979;
   330  
   331  /** A default safe nonce generation function (currently equal to secp256k1_nonce_function_rfc6979). */
   332  extern const secp256k1_nonce_function secp256k1_nonce_function_default;
   333  
   334  /** Create an ECDSA signature.
   335   *
   336   *  Returns: 1: signature created
   337   *           0: the nonce generation function failed, or the private key was invalid.
   338   *  Args:    ctx:    pointer to a context object, initialized for signing (cannot be NULL)
   339   *  Out:     sig:    pointer to an array where the signature will be placed (cannot be NULL)
   340   *  In:      msg32:  the 32-byte message hash being signed (cannot be NULL)
   341   *           seckey: pointer to a 32-byte secret key (cannot be NULL)
   342   *           noncefp:pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used
   343   *           ndata:  pointer to arbitrary data used by the nonce generation function (can be NULL)
   344   *
   345   * The sig always has an s value in the lower half of the range (From 0x1
   346   * to 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
   347   * inclusive), unlike many other implementations.
   348   *
   349   * With ECDSA a third-party can can forge a second distinct signature
   350   * of the same message given a single initial signature without knowing
   351   * the key by setting s to its additive inverse mod-order, 'flipping' the
   352   * sign of the random point R which is not included in the signature.
   353   * Since the forgery is of the same message this isn't universally
   354   * problematic, but in systems where message malleability or uniqueness
   355   * of signatures is important this can cause issues.  This forgery can be
   356   * blocked by all verifiers forcing signers to use a canonical form. The
   357   * lower-S form reduces the size of signatures slightly on average when
   358   * variable length encodings (such as DER) are used and is cheap to
   359   * verify, making it a good choice. Security of always using lower-S is
   360   * assured because anyone can trivially modify a signature after the
   361   * fact to enforce this property.  Adjusting it inside the signing
   362   * function avoids the need to re-serialize or have curve specific
   363   * constants outside of the library.  By always using a canonical form
   364   * even in applications where it isn't needed it becomes possible to
   365   * impose a requirement later if a need is discovered.
   366   * No other forms of ECDSA malleability are known and none seem likely,
   367   * but there is no formal proof that ECDSA, even with this additional
   368   * restriction, is free of other malleability.  Commonly used serialization
   369   * schemes will also accept various non-unique encodings, so care should
   370   * be taken when this property is required for an application.
   371   */
   372  SECP256K1_API int secp256k1_ecdsa_sign(
   373      const secp256k1_context* ctx,
   374      secp256k1_ecdsa_signature *sig,
   375      const unsigned char *msg32,
   376      const unsigned char *seckey,
   377      secp256k1_nonce_function noncefp,
   378      const void *ndata
   379  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
   380  
   381  /** Verify an ECDSA secret key.
   382   *
   383   *  Returns: 1: secret key is valid
   384   *           0: secret key is invalid
   385   *  Args:    ctx: pointer to a context object (cannot be NULL)
   386   *  In:      seckey: pointer to a 32-byte secret key (cannot be NULL)
   387   */
   388  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(
   389      const secp256k1_context* ctx,
   390      const unsigned char *seckey
   391  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
   392  
   393  /** Compute the public key for a secret key.
   394   *
   395   *  Returns: 1: secret was valid, public key stores
   396   *           0: secret was invalid, try again
   397   *  Args:   ctx:        pointer to a context object, initialized for signing (cannot be NULL)
   398   *  Out:    pubkey:     pointer to the created public key (cannot be NULL)
   399   *  In:     seckey:     pointer to a 32-byte private key (cannot be NULL)
   400   */
   401  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(
   402      const secp256k1_context* ctx,
   403      secp256k1_pubkey *pubkey,
   404      const unsigned char *seckey
   405  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   406  
   407  /** Export a private key in BER format.
   408   *
   409   *  Returns: 1 if the private key was valid.
   410   *  Args: ctx:        pointer to a context object, initialized for signing (cannot
   411   *                    be NULL)
   412   *  Out: privkey:     pointer to an array for storing the private key in BER.
   413   *                    Should have space for 279 bytes, and cannot be NULL.
   414   *       privkeylen:  Pointer to an int where the length of the private key in
   415   *                    privkey will be stored.
   416   *  In:  seckey:      pointer to a 32-byte secret key to export.
   417   *       flags:       SECP256K1_EC_COMPRESSED if the key should be exported in
   418   *                    compressed format.
   419   *
   420   *  This function is purely meant for compatibility with applications that
   421   *  require BER encoded keys. When working with secp256k1-specific code, the
   422   *  simple 32-byte private keys are sufficient.
   423   *
   424   *  Note that this function does not guarantee correct DER output. It is
   425   *  guaranteed to be parsable by secp256k1_ec_privkey_import.
   426   */
   427  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_export(
   428      const secp256k1_context* ctx,
   429      unsigned char *privkey,
   430      size_t *privkeylen,
   431      const unsigned char *seckey,
   432      unsigned int flags
   433  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
   434  
   435  /** Import a private key in DER format.
   436   * Returns: 1 if a private key was extracted.
   437   * Args: ctx:        pointer to a context object (cannot be NULL).
   438   * Out:  seckey:     pointer to a 32-byte array for storing the private key.
   439   *                   (cannot be NULL).
   440   * In:   privkey:    pointer to a private key in DER format (cannot be NULL).
   441   *       privkeylen: length of the DER private key pointed to be privkey.
   442   *
   443   * This function will accept more than just strict DER, and even allow some BER
   444   * violations. The public key stored inside the DER-encoded private key is not
   445   * verified for correctness, nor are the curve parameters. Use this function
   446   * only if you know in advance it is supposed to contain a secp256k1 private
   447   * key.
   448   */
   449  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_import(
   450      const secp256k1_context* ctx,
   451      unsigned char *seckey,
   452      const unsigned char *privkey,
   453      size_t privkeylen
   454  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   455  
   456  /** Tweak a private key by adding tweak to it.
   457   * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
   458   *          uniformly random 32-byte arrays, or if the resulting private key
   459   *          would be invalid (only when the tweak is the complement of the
   460   *          private key). 1 otherwise.
   461   * Args:    ctx:    pointer to a context object (cannot be NULL).
   462   * In/Out:  seckey: pointer to a 32-byte private key.
   463   * In:      tweak:  pointer to a 32-byte tweak.
   464   */
   465  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(
   466      const secp256k1_context* ctx,
   467      unsigned char *seckey,
   468      const unsigned char *tweak
   469  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   470  
   471  /** Tweak a public key by adding tweak times the generator to it.
   472   * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
   473   *          uniformly random 32-byte arrays, or if the resulting public key
   474   *          would be invalid (only when the tweak is the complement of the
   475   *          corresponding private key). 1 otherwise.
   476   * Args:    ctx:    pointer to a context object initialized for validation
   477   *                  (cannot be NULL).
   478   * In/Out:  pubkey: pointer to a public key object.
   479   * In:      tweak:  pointer to a 32-byte tweak.
   480   */
   481  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(
   482      const secp256k1_context* ctx,
   483      secp256k1_pubkey *pubkey,
   484      const unsigned char *tweak
   485  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   486  
   487  /** Tweak a private key by multiplying it by a tweak.
   488   * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
   489   *          uniformly random 32-byte arrays, or equal to zero. 1 otherwise.
   490   * Args:   ctx:    pointer to a context object (cannot be NULL).
   491   * In/Out: seckey: pointer to a 32-byte private key.
   492   * In:     tweak:  pointer to a 32-byte tweak.
   493   */
   494  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul(
   495      const secp256k1_context* ctx,
   496      unsigned char *seckey,
   497      const unsigned char *tweak
   498  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   499  
   500  /** Tweak a public key by multiplying it by a tweak value.
   501   * Returns: 0 if the tweak was out of range (chance of around 1 in 2^128 for
   502   *          uniformly random 32-byte arrays, or equal to zero. 1 otherwise.
   503   * Args:    ctx:    pointer to a context object initialized for validation
   504   *                 (cannot be NULL).
   505   * In/Out:  pubkey: pointer to a public key obkect.
   506   * In:      tweak:  pointer to a 32-byte tweak.
   507   */
   508  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(
   509      const secp256k1_context* ctx,
   510      secp256k1_pubkey *pubkey,
   511      const unsigned char *tweak
   512  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   513  
   514  /** Updates the context randomization.
   515   *  Returns: 1: randomization successfully updated
   516   *           0: error
   517   *  Args:    ctx:       pointer to a context object (cannot be NULL)
   518   *  In:      seed32:    pointer to a 32-byte random seed (NULL resets to initial state)
   519   */
   520  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(
   521      secp256k1_context* ctx,
   522      const unsigned char *seed32
   523  ) SECP256K1_ARG_NONNULL(1);
   524  
   525  /** Add a number of public keys together.
   526   *  Returns: 1: the sum of the public keys is valid.
   527   *           0: the sum of the public keys is not valid.
   528   *  Args:   ctx:        pointer to a context object
   529   *  Out:    out:        pointer to pubkey for placing the resulting public key
   530   *                      (cannot be NULL)
   531   *  In:     ins:        pointer to array of pointers to public keys (cannot be NULL)
   532   *          n:          the number of public keys to add together (must be at least 1)
   533   *  Use secp256k1_ec_pubkey_compress and secp256k1_ec_pubkey_decompress if the
   534   *  uncompressed format is needed.
   535   */
   536  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_combine(
   537      const secp256k1_context* ctx,
   538      secp256k1_pubkey *out,
   539      const secp256k1_pubkey * const * ins,
   540      int n
   541  ) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   542  
   543  # ifdef __cplusplus
   544  }
   545  # endif
   546  
   547  #endif