28 size_t rpos, rlen, spos, slen;
31 unsigned char tmpsig[64] = {0};
38 if (pos == inputlen || input[pos] != 0x30) {
44 if (pos == inputlen) {
47 lenbyte = input[pos++];
50 if (lenbyte > inputlen - pos) {
57 if (pos == inputlen || input[pos] != 0x02) {
63 if (pos == inputlen) {
66 lenbyte = input[pos++];
69 if (lenbyte > inputlen - pos) {
72 while (lenbyte > 0 && input[pos] == 0) {
76 static_assert(
sizeof(
size_t) >= 4,
"size_t too small");
82 rlen = (rlen << 8) + input[pos];
89 if (rlen > inputlen - pos) {
96 if (pos == inputlen || input[pos] != 0x02) {
102 if (pos == inputlen) {
105 lenbyte = input[pos++];
106 if (lenbyte & 0x80) {
108 if (lenbyte > inputlen - pos) {
111 while (lenbyte > 0 && input[pos] == 0) {
115 static_assert(
sizeof(
size_t) >= 4,
"size_t too small");
120 while (lenbyte > 0) {
121 slen = (slen << 8) + input[pos];
128 if (slen > inputlen - pos) {
134 while (rlen > 0 && input[rpos] == 0) {
142 memcpy(tmpsig + 32 - rlen, input + rpos, rlen);
146 while (slen > 0 && input[spos] == 0) {
154 memcpy(tmpsig + 64 - slen, input + spos, slen);
163 memset(tmpsig, 0, 64);
175 assert(secp256k1_context_verify &&
"secp256k1_context_verify must be initialized to use CPubKey.");
179 if (!ecdsa_signature_parse_der_lax(secp256k1_context_verify, &sig, vchSig.
data(), vchSig.size())) {
192 int recid = (vchSig[0] - 27) & 3;
193 bool fComp = ((vchSig[0] - 27) & 4) != 0;
196 assert(secp256k1_context_verify &&
"secp256k1_context_verify must be initialized to use CPubKey.");
206 Set(pub, pub + publen);
215 assert(secp256k1_context_verify &&
"secp256k1_context_verify must be initialized to use CPubKey.");
224 assert(secp256k1_context_verify &&
"secp256k1_context_verify must be initialized to use CPubKey.");
231 Set(pub, pub + publen);
238 assert((nChild >> 31) == 0);
240 unsigned char out[64];
244 assert(secp256k1_context_verify &&
"secp256k1_context_verify must be initialized to use CPubKey.");
254 pubkeyChild.
Set(pub, pub + publen);
262 code[5] = (
nChild >> 24) & 0xFF; code[6] = (
nChild >> 16) & 0xFF;
263 code[7] = (
nChild >> 8) & 0xFF; code[8] = (
nChild >> 0) & 0xFF;
273 nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8];
289 assert(secp256k1_context_verify &&
"secp256k1_context_verify must be initialized to use CPubKey.");
290 if (!ecdsa_signature_parse_der_lax(secp256k1_context_verify, &sig, vchSig.
data(), vchSig.size())) {
301 assert(secp256k1_context_verify ==
nullptr);
303 assert(secp256k1_context_verify !=
nullptr);
312 assert(secp256k1_context_verify !=
nullptr);
314 secp256k1_context_verify =
nullptr;
A reference to a CKey: the Hash160 of its serialized public key.
An encapsulated public key.
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
Recover a public key from a compact signature.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
static bool CheckLowS(const std::vector< unsigned char > &vchSig)
Check whether a signature is normalized (lower-S).
bool Decompress()
Turn this public key into an uncompressed public key.
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Verify a DER signature (~72 bytes).
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
const unsigned char * begin() const
unsigned char vch[PUBLIC_KEY_SIZE]
see www.keylength.com script supports up to 75 for single byte push
static constexpr unsigned int PUBLIC_KEY_SIZE
secp256k1:
bool Derive(CPubKey &pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child pubkey.
static constexpr unsigned int COMPRESSED_PUBLIC_KEY_SIZE
static constexpr unsigned int COMPACT_SIGNATURE_SIZE
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
void * memcpy(void *a, const void *b, size_t c)
void BIP32Hash(const ChainCode chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64])
const unsigned int BIP32_EXTKEY_SIZE
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Tweak a public key by adding tweak times the generator to it.
SECP256K1_API int secp256k1_ecdsa_signature_parse_compact(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *input64) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse an ECDSA signature in compact (64 bytes) format.
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize a pubkey object into a serialized byte sequence.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const secp256k1_pubkey *pubkey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Verify an ECDSA signature.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a variable-length public key into the pubkey object.
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object.
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize and secp256k1_ec_privkey_export.
SECP256K1_API int secp256k1_ecdsa_signature_normalize(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sigout, const secp256k1_ecdsa_signature *sigin) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3)
Convert a signature to a normalized lower-S form.
#define SECP256K1_EC_UNCOMPRESSED
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create.
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object.
SECP256K1_API int secp256k1_ecdsa_recoverable_signature_parse_compact(const secp256k1_context *ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *input64, int recid) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a compact ECDSA signature (64 bytes + recovery id).
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msg32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Recover an ECDSA public key from a signature.
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
bool Derive(CExtPubKey &out, unsigned int nChild) const
unsigned char vchFingerprint[4]
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE])
Opaque data structured that holds a parsed ECDSA signature, supporting pubkey recovery.
Opaque data structured that holds a parsed ECDSA signature.
Opaque data structure that holds a parsed and valid public key.