github.com/shopperooofficial/ethereum-protocol@v1.9.7/crypto/secp256k1/libsecp256k1/include/secp256k1_recovery.h (about)

     1  #ifndef _SECP256K1_RECOVERY_
     2  # define _SECP256K1_RECOVERY_
     3  
     4  # include "secp256k1.h"
     5  
     6  # ifdef __cplusplus
     7  extern "C" {
     8  # endif
     9  
    10  /** Opaque data structured 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 {
    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:     a secp256k1 context object
    32   *  Out:  sig:     a pointer to a signature object
    33   *  In:   input64: a 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   *  Out: sig:    a pointer to a normal signature (cannot be NULL).
    47   *  In:  sigin:  a pointer to a recoverable signature (cannot be NULL).
    48   */
    49  SECP256K1_API int secp256k1_ecdsa_recoverable_signature_convert(
    50      const secp256k1_context* ctx,
    51      secp256k1_ecdsa_signature* sig,
    52      const secp256k1_ecdsa_recoverable_signature* sigin
    53  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
    54  
    55  /** Serialize an ECDSA signature in compact format (64 bytes + recovery id).
    56   *
    57   *  Returns: 1
    58   *  Args: ctx:      a secp256k1 context object
    59   *  Out:  output64: a pointer to a 64-byte array of the compact signature (cannot be NULL)
    60   *        recid:    a pointer to an integer to hold the recovery id (can be NULL).
    61   *  In:   sig:      a pointer to an initialized signature object (cannot be NULL)
    62   */
    63  SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(
    64      const secp256k1_context* ctx,
    65      unsigned char *output64,
    66      int *recid,
    67      const secp256k1_ecdsa_recoverable_signature* sig
    68  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
    69  
    70  /** Create a recoverable ECDSA signature.
    71   *
    72   *  Returns: 1: signature created
    73   *           0: the nonce generation function failed, or the private key was invalid.
    74   *  Args:    ctx:    pointer to a context object, initialized for signing (cannot be NULL)
    75   *  Out:     sig:    pointer to an array where the signature will be placed (cannot be NULL)
    76   *  In:      msg32:  the 32-byte message hash being signed (cannot be NULL)
    77   *           seckey: pointer to a 32-byte secret key (cannot be NULL)
    78   *           noncefp:pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used
    79   *           ndata:  pointer to arbitrary data used by the nonce generation function (can be NULL)
    80   */
    81  SECP256K1_API int secp256k1_ecdsa_sign_recoverable(
    82      const secp256k1_context* ctx,
    83      secp256k1_ecdsa_recoverable_signature *sig,
    84      const unsigned char *msg32,
    85      const unsigned char *seckey,
    86      secp256k1_nonce_function noncefp,
    87      const void *ndata
    88  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
    89  
    90  /** Recover an ECDSA public key from a signature.
    91   *
    92   *  Returns: 1: public key successfully recovered (which guarantees a correct signature).
    93   *           0: otherwise.
    94   *  Args:    ctx:        pointer to a context object, initialized for verification (cannot be NULL)
    95   *  Out:     pubkey:     pointer to the recovered public key (cannot be NULL)
    96   *  In:      sig:        pointer to initialized signature that supports pubkey recovery (cannot be NULL)
    97   *           msg32:      the 32-byte message hash assumed to be signed (cannot be NULL)
    98   */
    99  SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover(
   100      const secp256k1_context* ctx,
   101      secp256k1_pubkey *pubkey,
   102      const secp256k1_ecdsa_recoverable_signature *sig,
   103      const unsigned char *msg32
   104  ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
   105  
   106  # ifdef __cplusplus
   107  }
   108  # endif
   109  
   110  #endif