github.com/igggame/nebulas-go@v2.1.0+incompatible/crypto/keystore/secp256k1/libsecp256k1/include/secp256k1.h (about)

     1  #ifndef SECP256K1_H
     2  #define SECP256K1_H
     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, transmission, or
    51   *  comparison, use secp256k1_ec_pubkey_serialize and secp256k1_ec_pubkey_parse.
    52   */
    53  typedef struct {
    54      unsigned char data[64];
    55  } secp256k1_pubkey;
    56  
    57  /** Opaque data structured that holds a parsed ECDSA signature.
    58   *
    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.
    65   */
    66  typedef struct {
    67      unsigned char data[64];
    68  } secp256k1_ecdsa_signature;
    69  
    70  /** A pointer to a function to deterministically generate a nonce.
    71   *
    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.
    82   *
    83   * Except for test cases, this function should compute some cryptographic hash of
    84   * the message, the algorithm, the key and the attempt.
    85   */
    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
    93  );
    94  
    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
   103  
   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
   115  
   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
   129  
   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
   143  
   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)
   152  
   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)
   157  
   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)
   161  
   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
   168  
   169  /** Create a secp256k1 context object.
   170   *
   171   *  Returns: a newly created context object.
   172   *  In:      flags: which parts of the context to initialize.
   173   *
   174   *  See also secp256k1_context_randomize.
   175   */
   176  SECP256K1_API secp256k1_context* secp256k1_context_create(
   177      unsigned int flags
   178  ) SECP256K1_WARN_UNUSED_RESULT;
   179  
   180  /** Copies a secp256k1 context object.
   181   *
   182   *  Returns: a newly created context object.
   183   *  Args:    ctx: an existing context to copy (cannot be NULL)
   184   */
   185  SECP256K1_API secp256k1_context* secp256k1_context_clone(
   186      const secp256k1_context* ctx
   187  ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
   188  
   189  /** Destroy a secp256k1 context object.
   190   *
   191   *  The context pointer may not be used afterwards.
   192   *  Args:   ctx: an existing context to destroy (cannot be NULL)
   193   */
   194  SECP256K1_API void secp256k1_context_destroy(
   195      secp256k1_context* ctx
   196  );
   197  
   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.
   201   *
   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.
   205   *
   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
   210   *  undefined.
   211   *
   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.
   217   */
   218  SECP256K1_API void secp256k1_context_set_illegal_callback(
   219      secp256k1_context* ctx,
   220      void (*fun)(const char* message, void* data),
   221      const void* data
   222  ) SECP256K1_ARG_NONNULL(1);
   223  
   224  /** Set a callback function to be called when an internal consistency check
   225   *  fails. The default is crashing.
   226   *
   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
   232   *  crashing.
   233   *
   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.
   239   */
   240  SECP256K1_API void secp256k1_context_set_error_callback(
   241      secp256k1_context* ctx,
   242      void (*fun)(const char* message, void* data),
   243      const void* data
   244  ) SECP256K1_ARG_NONNULL(1);
   245  
   246  /** Parse a variable-length public key into the pubkey object.
   247   *
   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
   255   *
   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.
   259   */
   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,
   264      size_t inputlen
   265  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   266  
   267  /** Serialize a pubkey object into a serialized byte sequence.
   268   *
   269   *  Returns: 1 always.
   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
   273   *                      in.
   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
   276   *                      size.
   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.
   281   */
   282  SECP256K1_API int secp256k1_ec_pubkey_serialize(
   283      const secp256k1_context* ctx,
   284      unsigned char *output,
   285      size_t *outputlen,
   286      const secp256k1_pubkey* pubkey,
   287      unsigned int flags
   288  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
   289  
   290  /** Parse an ECDSA signature in compact (64 bytes) format.
   291   *
   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
   296   *
   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.
   300   *
   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.
   304   */
   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);
   310  
   311  /** Parse a DER ECDSA signature.
   312   *
   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
   318   *
   319   *  This function will accept any valid DER encoded signature, even if the
   320   *  encoded numbers are out of range.
   321   *
   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.
   325   */
   326  SECP256K1_API int secp256k1_ecdsa_signature_parse_der(
   327      const secp256k1_context* ctx,
   328      secp256k1_ecdsa_signature* sig,
   329      const unsigned char *input,
   330      size_t inputlen
   331  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   332  
   333  /** Serialize an ECDSA signature in DER format.
   334   *
   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
   343   */
   344  SECP256K1_API int secp256k1_ecdsa_signature_serialize_der(
   345      const secp256k1_context* ctx,
   346      unsigned char *output,
   347      size_t *outputlen,
   348      const secp256k1_ecdsa_signature* sig
   349  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
   350  
   351  /** Serialize an ECDSA signature in compact (64 byte) format.
   352   *
   353   *  Returns: 1
   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
   357   *
   358   *  See secp256k1_ecdsa_signature_parse_compact for details about the encoding.
   359   */
   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);
   365  
   366  /** Verify an ECDSA signature.
   367   *
   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)
   374   *
   375   * To avoid accepting malleable signatures, only ECDSA signatures in lower-S
   376   * form are accepted.
   377   *
   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.
   381   *
   382   * For details, see the comments for that function.
   383   */
   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);
   390  
   391  /** Convert a signature to a normalized lower-S form.
   392   *
   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
   398   *                normalized).
   399   *  In:   sigin:  a pointer to a signature to check/normalize (cannot be NULL,
   400   *                can be identical to sigout)
   401   *
   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.
   406   *
   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.
   411   *
   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
   416   *  property anyway.
   417   *
   418   *  The lower S value is always between 0x1 and
   419   *  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
   420   *  inclusive.
   421   *
   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.
   427   *
   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.
   432   */
   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);
   438  
   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
   441   * extra entropy.
   442   */
   443  SECP256K1_API extern const secp256k1_nonce_function secp256k1_nonce_function_rfc6979;
   444  
   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;
   447  
   448  /** Create an ECDSA signature.
   449   *
   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)
   458   *
   459   * The created signature is always in lower-S form. See
   460   * secp256k1_ecdsa_signature_normalize for more details.
   461   */
   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,
   468      const void *ndata
   469  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
   470  
   471  /** Verify an ECDSA secret key.
   472   *
   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)
   477   */
   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);
   482  
   483  /** Compute the public key for a secret key.
   484   *
   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)
   490   */
   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);
   496  
   497  /** Negates a private key in place.
   498   *
   499   *  Returns: 1 always
   500   *  Args:   ctx:        pointer to a context object
   501   *  In/Out: pubkey:     pointer to the public key to be negated (cannot be NULL)
   502   */
   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);
   507  
   508  /** Negates a public key in place.
   509   *
   510   *  Returns: 1 always
   511   *  Args:   ctx:        pointer to a context object
   512   *  In/Out: pubkey:     pointer to the public key to be negated (cannot be NULL)
   513   */
   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);
   518  
   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.
   527   */
   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);
   533  
   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
   540   *                  (cannot be NULL).
   541   * In/Out:  pubkey: pointer to a public key object.
   542   * In:      tweak:  pointer to a 32-byte tweak.
   543   */
   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);
   549  
   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.
   556   */
   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);
   562  
   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
   567   *                 (cannot be NULL).
   568   * In/Out:  pubkey: pointer to a public key obkect.
   569   * In:      tweak:  pointer to a 32-byte tweak.
   570   */
   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);
   576  
   577  /** Updates the context randomization to protect against side-channel leakage.
   578   *  Returns: 1: randomization successfully updated
   579   *           0: error
   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)
   582   *
   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.
   587   *
   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.
   592   *
   593   * You should call this after secp256k1_context_create or
   594   * secp256k1_context_clone, and may call this repeatedly afterwards.
   595   */
   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);
   600  
   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
   606   *                      (cannot be NULL)
   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)
   609   */
   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,
   614      size_t n
   615  ) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
   616  
   617  #ifdef __cplusplus
   618  }
   619  #endif
   620  
   621  #endif /* SECP256K1_H */