You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

secp256k1_recovery.h 4.6KB

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