1 #ifndef SECP256K1_RECOVERY_H
2 #define SECP256K1_RECOVERY_H
10 /** Opaque data structured that holds a parsed ECDSA signature,
11 * supporting pubkey recovery.
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.
20 * Furthermore, it is guaranteed that identical signatures (including their
21 * recoverability) will have identical representation, so they can be
25 unsigned char data[65];
26 } secp256k1_ecdsa_recoverable_signature;
28 /** Parse a compact ECDSA signature (64 bytes + recovery id).
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)
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,
41 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
43 /** Convert a recoverable signature into a normal signature.
46 * Out: sig: a pointer to a normal signature (cannot be NULL).
47 * In: sigin: a pointer to a recoverable signature (cannot be NULL).
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);
55 /** Serialize an ECDSA signature in compact format (64 bytes + recovery id).
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)
63 SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(
64 const secp256k1_context* ctx,
65 unsigned char *output64,
67 const secp256k1_ecdsa_recoverable_signature* sig
68 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
70 /** Create a recoverable ECDSA signature.
72 * Returns: 1: signature created
73 * 0: the nonce generation function failed, or the secret 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)
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,
88 ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
90 /** Recover an ECDSA public key from a signature.
92 * Returns: 1: public key successfully recovered (which guarantees a correct signature).
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)
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);
110 #endif /* SECP256K1_RECOVERY_H */