mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-10 19:43:13 +02:00
Specify ECDSA constant sizes as constants
This commit is contained in:
@@ -185,7 +185,7 @@ bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchS
|
||||
}
|
||||
|
||||
bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig) {
|
||||
if (vchSig.size() != 65)
|
||||
if (vchSig.size() != COMPACT_SIGNATURE_SIZE)
|
||||
return false;
|
||||
int recid = (vchSig[0] - 27) & 3;
|
||||
bool fComp = ((vchSig[0] - 27) & 4) != 0;
|
||||
@@ -197,8 +197,8 @@ bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned cha
|
||||
if (!secp256k1_ecdsa_recover(secp256k1_context_verify, &pubkey, &sig, hash.begin())) {
|
||||
return false;
|
||||
}
|
||||
unsigned char pub[65];
|
||||
size_t publen = 65;
|
||||
unsigned char pub[PUBLIC_KEY_SIZE];
|
||||
size_t publen = PUBLIC_KEY_SIZE;
|
||||
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, fComp ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
|
||||
Set(pub, pub + publen);
|
||||
return true;
|
||||
@@ -218,8 +218,8 @@ bool CPubKey::Decompress() {
|
||||
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, &(*this)[0], size())) {
|
||||
return false;
|
||||
}
|
||||
unsigned char pub[65];
|
||||
size_t publen = 65;
|
||||
unsigned char pub[PUBLIC_KEY_SIZE];
|
||||
size_t publen = PUBLIC_KEY_SIZE;
|
||||
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
|
||||
Set(pub, pub + publen);
|
||||
return true;
|
||||
@@ -228,7 +228,7 @@ bool CPubKey::Decompress() {
|
||||
bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const {
|
||||
assert(IsValid());
|
||||
assert((nChild >> 31) == 0);
|
||||
assert(size() == 33);
|
||||
assert(size() == COMPRESSED_PUBLIC_KEY_SIZE);
|
||||
unsigned char out[64];
|
||||
BIP32Hash(cc, nChild, *begin(), begin()+1, out);
|
||||
memcpy(ccChild.begin(), out+32, 32);
|
||||
@@ -239,8 +239,8 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChi
|
||||
if (!secp256k1_ec_pubkey_tweak_add(secp256k1_context_verify, &pubkey, out)) {
|
||||
return false;
|
||||
}
|
||||
unsigned char pub[33];
|
||||
size_t publen = 33;
|
||||
unsigned char pub[COMPRESSED_PUBLIC_KEY_SIZE];
|
||||
size_t publen = COMPRESSED_PUBLIC_KEY_SIZE;
|
||||
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_COMPRESSED);
|
||||
pubkeyChild.Set(pub, pub + publen);
|
||||
return true;
|
||||
@@ -252,8 +252,8 @@ void CExtPubKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const {
|
||||
code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF;
|
||||
code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF;
|
||||
memcpy(code+9, chaincode.begin(), 32);
|
||||
assert(pubkey.size() == 33);
|
||||
memcpy(code+41, pubkey.begin(), 33);
|
||||
assert(pubkey.size() == COMPRESSED_PUBLIC_KEY_SIZE);
|
||||
memcpy(code+41, pubkey.begin(), COMPRESSED_PUBLIC_KEY_SIZE);
|
||||
}
|
||||
|
||||
void CExtPubKey::Decode(const unsigned char code[BIP32_EXTKEY_SIZE]) {
|
||||
|
Reference in New Issue
Block a user