Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#ifndef SECP256K1_RECOVERY_H2#define SECP256K1_RECOVERY_H4#include "secp256k1.h"6#ifdef __cplusplus7extern "C" {8#endif10/** 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 not14* guaranteed to be portable between different platforms or versions. It is15* 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, use17* the secp256k1_ecdsa_signature_serialize_* and18* secp256k1_ecdsa_signature_parse_* functions.19*20* Furthermore, it is guaranteed that identical signatures (including their21* recoverability) will have identical representation, so they can be22* memcmp'ed.23*/24typedef struct secp256k1_ecdsa_recoverable_signature {25unsigned char data[65];26} secp256k1_ecdsa_recoverable_signature;28/** Parse a compact ECDSA signature (64 bytes + recovery id).29*30* Returns: 1 when the signature could be parsed, 0 otherwise31* Args: ctx: pointer to a context object32* Out: sig: pointer to a signature object33* In: input64: pointer to a 64-byte compact signature34* recid: the recovery id (0, 1, 2 or 3)35*/36SECP256K1_API int secp256k1_ecdsa_recoverable_signature_parse_compact(37const secp256k1_context *ctx,38secp256k1_ecdsa_recoverable_signature *sig,39const unsigned char *input64,40int recid41) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);43/** Convert a recoverable signature into a normal signature.44*45* Returns: 146* Args: ctx: pointer to a context object.47* Out: sig: pointer to a normal signature.48* In: sigin: pointer to a recoverable signature.49*/50SECP256K1_API int secp256k1_ecdsa_recoverable_signature_convert(51const secp256k1_context *ctx,52secp256k1_ecdsa_signature *sig,53const secp256k1_ecdsa_recoverable_signature *sigin54) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);56/** Serialize an ECDSA signature in compact format (64 bytes + recovery id).57*58* Returns: 159* 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*/64SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(65const secp256k1_context *ctx,66unsigned char *output64,67int *recid,68const secp256k1_ecdsa_recoverable_signature *sig69) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);71/** Create a recoverable ECDSA signature.72*73* Returns: 1: signature created74* 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 a signature object.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 function82* (can be NULL for secp256k1_nonce_function_default).83*/84SECP256K1_API int secp256k1_ecdsa_sign_recoverable(85const secp256k1_context *ctx,86secp256k1_ecdsa_recoverable_signature *sig,87const unsigned char *msghash32,88const unsigned char *seckey,89secp256k1_nonce_function noncefp,90const void *ndata91) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);93/** Recover an ECDSA public key from a signature.94*95* Successful public key recovery guarantees that the signature, after normalization,96* passes `secp256k1_ecdsa_verify`. Thus, explicit verification is not necessary.97*98* However, a recoverable signature that successfully passes `secp256k1_ecdsa_recover`,99* when converted to a non-recoverable signature (using100* `secp256k1_ecdsa_recoverable_signature_convert`), is not guaranteed to be101* normalized and thus not guaranteed to pass `secp256k1_ecdsa_verify`. If a102* normalized signature is required, call `secp256k1_ecdsa_signature_normalize`103* after `secp256k1_ecdsa_recoverable_signature_convert`.104*105* Returns: 1: public key successfully recovered106* 0: otherwise.107* Args: ctx: pointer to a context object.108* Out: pubkey: pointer to the recovered public key.109* In: sig: pointer to initialized signature that supports pubkey recovery.110* msghash32: the 32-byte message hash assumed to be signed.111*/112SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover(113const secp256k1_context *ctx,114secp256k1_pubkey *pubkey,115const secp256k1_ecdsa_recoverable_signature *sig,116const unsigned char *msghash32117) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);119#ifdef __cplusplus120}121#endif123#endif /* SECP256K1_RECOVERY_H */
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.