aboutsummaryrefslogtreecommitdiff
path: root/src/pubkey.cpp
diff options
context:
space:
mode:
authorgeekwisdom <[email protected]>2021-05-20 07:24:54 -0300
committerRoss Nicoll <[email protected]>2021-07-25 19:32:23 +0100
commitc7a1b7c90cd6981321924991d7bd05f77a3cc7db (patch)
tree4154255d908aea27914c24f6b0e2a67abca7f21e /src/pubkey.cpp
parentMerge pull request #1941 from elybin/fixing-indonesian-translation (diff)
downloaddiscoin-c7a1b7c90cd6981321924991d7bd05f77a3cc7db.tar.xz
discoin-c7a1b7c90cd6981321924991d7bd05f77a3cc7db.zip
Trivial: Fix Magic Numbers in key and pubkey - fixes #1968
Diffstat (limited to 'src/pubkey.cpp')
-rw-r--r--src/pubkey.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/pubkey.cpp b/src/pubkey.cpp
index b0407cbee..af905fe0b 100644
--- a/src/pubkey.cpp
+++ b/src/pubkey.cpp
@@ -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() != CPubKey::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[CPubKey::SIZE];
+ size_t publen = CPubKey::SIZE;
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, fComp ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
Set(pub, pub + publen);
return true;
@@ -217,8 +217,8 @@ bool CPubKey::Compress() {
secp256k1_pubkey pubkey;
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, &(*this)[0], size()))
return false;
- unsigned char pub[33];
- size_t publen = 33;
+ unsigned char pub[CPubKey::COMPRESSED_SIZE];
+ size_t publen = CPubKey::COMPRESSED_SIZE;
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_COMPRESSED);
Set(pub, pub + publen);
return true;
@@ -231,8 +231,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[CPubKey::SIZE];
+ size_t publen = CPubKey::SIZE;
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
Set(pub, pub + publen);
return true;
@@ -241,7 +241,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(begin() + 33 == end());
+ assert(begin() + CPubKey::COMPRESSED_SIZE == end());
unsigned char out[64];
BIP32Hash(cc, nChild, *begin(), begin()+1, out);
memcpy(ccChild.begin(), out+32, 32);
@@ -252,8 +252,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[CPubKey::COMPRESSED_SIZE];
+ size_t publen = CPubKey::COMPRESSED_SIZE;
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_COMPRESSED);
pubkeyChild.Set(pub, pub + publen);
return true;
@@ -265,7 +265,7 @@ 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);
+ assert(pubkey.size() == CPubKey::COMPRESSED_SIZE);
memcpy(code+41, pubkey.begin(), 33);
}