github.com/ethereum/go-ethereum@v1.16.1/crypto/secp256k1/libsecp256k1/include/secp256k1_recovery.h (about)

     1  #ifndef SECP256K1_RECOVERY_H
     2  #define SECP256K1_RECOVERY_H
     3  
     4  #include "secp256k1.h"
     5  
     6  #ifdef __cplusplus
     7  extern "C" {
     8  #endif
     9  
    10  /** Opaque data structure that holds a parsed ECDSA signature,
    11   *  supporting pubkey recovery.
    12   *
    13   *  The exact representation of data inside is implementation defined and not
    14   *  guaranteed to be portable between different platforms or versions. It is
    15   *  however guaranteed to be 65 bytes in size, and can be safely copied/moved.
    16   *  If you need to convert to a format suitable for storage or transmission, use
    17   *  the secp256k1_ecdsa_signature_serialize_* and
    18   *  secp256k1_ecdsa_signature_parse_* functions.
    19   *
    20   *  Furthermore, it is guaranteed that identical signatures (including their
    21   *  recoverability) will have identical representation, so they can be
    22   *  memcmp'ed.
    23   */
    24  typedef struct secp256k1_ecdsa_recoverable_signature {
    25      unsigned char data[65];
    26  } secp256k1_ecdsa_recoverable_signature;
    27  
    28  /** Parse a compact ECDSA signature (64 bytes + recovery id).
    29   *
    30   *  Returns: 1 when the signature could be parsed, 0 otherwise
    31   *  Args: ctx:     pointer to a context object
    32   *  Out:  sig:     pointer to a signature object
    33   *  In:   input64: pointer to a 64-byte compact signature
    34   *        recid:   the recovery id (0, 1, 2 or 3)
    35   */
    36  SECP256K1_API int secp256k1_ecdsa_recoverable_signature_parse_compact(
    37      const secp256k1_context *ctx,
    38      secp256k1_ecdsa_recoverable_signature *sig,
    39      const unsigned char *input64,
    40      int recid
    41  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
    42  
    43  /** Convert a recoverable signature into a normal signature.
    44   *
    45   *  Returns: 1
    46   *  Args: ctx:    pointer to a context object.
    47   *  Out:  sig:    pointer to a normal signature.
    48   *  In:   sigin:  pointer to a recoverable signature.
    49   */
    50  SECP256K1_API int secp256k1_ecdsa_recoverable_signature_convert(
    51      const secp256k1_context *ctx,
    52      secp256k1_ecdsa_signature *sig,
    53      const secp256k1_ecdsa_recoverable_signature *sigin
    54  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
    55  
    56  /** Serialize an ECDSA signature in compact format (64 bytes + recovery id).
    57   *
    58   *  Returns: 1
    59   *  Args: ctx:      pointer to a context object.
    60   *  Out:  output64: pointer to a 64-byte array of the compact signature.
    61   *        recid:    pointer to an integer to hold the recovery id.
    62   *  In:   sig:      pointer to an initialized signature object.
    63   */
    64  SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(
    65      const secp256k1_context *ctx,
    66      unsigned char *output64,
    67      int *recid,
    68      const secp256k1_ecdsa_recoverable_signature *sig
    69  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
    70  
    71  /** Create a recoverable ECDSA signature.
    72   *
    73   *  Returns: 1: signature created
    74   *           0: the nonce generation function failed, or the secret key was invalid.
    75   *  Args:    ctx:       pointer to a context object (not secp256k1_context_static).
    76   *  Out:     sig:       pointer to an array where the signature will be placed.
    77   *  In:      msghash32: the 32-byte message hash being signed.
    78   *           seckey:    pointer to a 32-byte secret key.
    79   *           noncefp:   pointer to a nonce generation function. If NULL,
    80   *                      secp256k1_nonce_function_default is used.
    81   *           ndata:     pointer to arbitrary data used by the nonce generation function
    82   *                      (can be NULL for secp256k1_nonce_function_default).
    83   */
    84  SECP256K1_API int secp256k1_ecdsa_sign_recoverable(
    85      const secp256k1_context *ctx,
    86      secp256k1_ecdsa_recoverable_signature *sig,
    87      const unsigned char *msghash32,
    88      const unsigned char *seckey,
    89      secp256k1_nonce_function noncefp,
    90      const void *ndata
    91  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
    92  
    93  /** Recover an ECDSA public key from a signature.
    94   *
    95   *  Returns: 1: public key successfully recovered (which guarantees a correct signature).
    96   *           0: otherwise.
    97   *  Args:    ctx:       pointer to a context object.
    98   *  Out:     pubkey:    pointer to the recovered public key.
    99   *  In:      sig:       pointer to initialized signature that supports pubkey recovery.
   100   *           msghash32: the 32-byte message hash assumed to be signed.
   101   */
   102  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover(
   103      const secp256k1_context *ctx,
   104      secp256k1_pubkey *pubkey,
   105      const secp256k1_ecdsa_recoverable_signature *sig,
   106      const unsigned char *msghash32
   107  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
   108  
   109  #ifdef __cplusplus
   110  }
   111  #endif
   112  
   113  #endif /* SECP256K1_RECOVERY_H */