Skip to content

Commit 47101bb

Browse files
committed
scripted-diff: Rename CPubKey and CKey::*_KEY_SIZE and COMPRESSED_*_KEY_SIZE
To SIZE and COMPRESSED_SIZE -BEGIN VERIFY SCRIPT- sed -i 's/PRIVATE_KEY_SIZE/SIZE/g' src/*.h src/*.cpp src/**/*.h src/**/*.cpp sed -i 's/COMPRESSED_PRIVATE_KEY_SIZE/COMPRESSED_SIZE/g' src/*.h src/**/*.cpp src/**/*.h src/**/*.cpp sed -i 's/PUBLIC_KEY_SIZE/SIZE/g' src/*.h src/*.cpp src/**/*.h src/**/*.cpp sed -i 's/COMPRESSED_PUBLIC_KEY_SIZE/COMPRESSED_SIZE/g' src/*.h src/*.cpp src/**/*.h src/**/*.cpp -END VERIFY SCRIPT-
1 parent 2d46f1b commit 47101bb

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
lines changed

src/key.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *ou
8484
* <http://www.secg.org/sec1-v2.pdf>. The optional parameters and publicKey fields are
8585
* included.
8686
*
87-
* privkey must point to an output buffer of length at least CKey::PRIVATE_KEY_SIZE bytes.
87+
* privkey must point to an output buffer of length at least CKey::SIZE bytes.
8888
* privkeylen must initially be set to the size of the privkey buffer. Upon return it
8989
* will be set to the number of bytes used in the buffer.
9090
* key32 must point to a 32-byte raw private key.
9191
*/
9292
static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, bool compressed) {
93-
assert(*privkeylen >= CKey::PRIVATE_KEY_SIZE);
93+
assert(*privkeylen >= CKey::SIZE);
9494
secp256k1_pubkey pubkey;
9595
size_t pubkeylen = 0;
9696
if (!secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) {
@@ -116,11 +116,11 @@ static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *pr
116116
memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
117117
memcpy(ptr, key32, 32); ptr += 32;
118118
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
119-
pubkeylen = CPubKey::COMPRESSED_PUBLIC_KEY_SIZE;
119+
pubkeylen = CPubKey::COMPRESSED_SIZE;
120120
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
121121
ptr += pubkeylen;
122122
*privkeylen = ptr - privkey;
123-
assert(*privkeylen == CKey::COMPRESSED_PRIVATE_KEY_SIZE);
123+
assert(*privkeylen == CKey::COMPRESSED_SIZE);
124124
} else {
125125
static const unsigned char begin[] = {
126126
0x30,0x82,0x01,0x13,0x02,0x01,0x01,0x04,0x20
@@ -142,11 +142,11 @@ static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *pr
142142
memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
143143
memcpy(ptr, key32, 32); ptr += 32;
144144
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
145-
pubkeylen = CPubKey::PUBLIC_KEY_SIZE;
145+
pubkeylen = CPubKey::SIZE;
146146
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
147147
ptr += pubkeylen;
148148
*privkeylen = ptr - privkey;
149-
assert(*privkeylen == CKey::PRIVATE_KEY_SIZE);
149+
assert(*privkeylen == CKey::SIZE);
150150
}
151151
return 1;
152152
}
@@ -168,8 +168,8 @@ CPrivKey CKey::GetPrivKey() const {
168168
CPrivKey privkey;
169169
int ret;
170170
size_t privkeylen;
171-
privkey.resize(PRIVATE_KEY_SIZE);
172-
privkeylen = PRIVATE_KEY_SIZE;
171+
privkey.resize(SIZE);
172+
privkeylen = SIZE;
173173
ret = ec_privkey_export_der(secp256k1_context_sign, privkey.data(), &privkeylen, begin(), fCompressed);
174174
assert(ret);
175175
privkey.resize(privkeylen);
@@ -179,7 +179,7 @@ CPrivKey CKey::GetPrivKey() const {
179179
CPubKey CKey::GetPubKey() const {
180180
assert(fValid);
181181
secp256k1_pubkey pubkey;
182-
size_t clen = CPubKey::PUBLIC_KEY_SIZE;
182+
size_t clen = CPubKey::SIZE;
183183
CPubKey result;
184184
int ret = secp256k1_ec_pubkey_create(secp256k1_context_sign, &pubkey, begin());
185185
assert(ret);
@@ -271,7 +271,7 @@ bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const
271271
std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
272272
if ((nChild >> 31) == 0) {
273273
CPubKey pubkey = GetPubKey();
274-
assert(pubkey.size() == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE);
274+
assert(pubkey.size() == CPubKey::COMPRESSED_SIZE);
275275
BIP32Hash(cc, nChild, *pubkey.begin(), pubkey.begin()+1, vout.data());
276276
} else {
277277
assert(size() == 32);

src/key.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* secure_allocator is defined in allocators.h
2121
* CPrivKey is a serialized private key, with all parameters included
22-
* (PRIVATE_KEY_SIZE bytes)
22+
* (SIZE bytes)
2323
*/
2424
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
2525

@@ -30,15 +30,15 @@ class CKey
3030
/**
3131
* secp256k1:
3232
*/
33-
static const unsigned int PRIVATE_KEY_SIZE = 279;
34-
static const unsigned int COMPRESSED_PRIVATE_KEY_SIZE = 214;
33+
static const unsigned int SIZE = 279;
34+
static const unsigned int COMPRESSED_SIZE = 214;
3535
/**
3636
* see www.keylength.com
3737
* script supports up to 75 for single byte push
3838
*/
3939
static_assert(
40-
PRIVATE_KEY_SIZE >= COMPRESSED_PRIVATE_KEY_SIZE,
41-
"COMPRESSED_PRIVATE_KEY_SIZE is larger than PRIVATE_KEY_SIZE");
40+
SIZE >= COMPRESSED_SIZE,
41+
"COMPRESSED_SIZE is larger than SIZE");
4242

4343
private:
4444
//! Whether this private key is valid. We check for correctness when modifying the key

src/psbt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ struct PSBTInput
165165
case PSBT_IN_PARTIAL_SIG:
166166
{
167167
// Make sure that the key is the size of pubkey + 1
168-
if (key.size() != CPubKey::PUBLIC_KEY_SIZE + 1 && key.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 1) {
168+
if (key.size() != CPubKey::SIZE + 1 && key.size() != CPubKey::COMPRESSED_SIZE + 1) {
169169
throw std::ios_base::failure("Size of key was not the expected size for the type partial signature pubkey");
170170
}
171171
// Read in the pubkey from key

src/pubkey.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned cha
196196
if (!secp256k1_ecdsa_recover(secp256k1_context_verify, &pubkey, &sig, hash.begin())) {
197197
return false;
198198
}
199-
unsigned char pub[PUBLIC_KEY_SIZE];
200-
size_t publen = PUBLIC_KEY_SIZE;
199+
unsigned char pub[SIZE];
200+
size_t publen = SIZE;
201201
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, fComp ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
202202
Set(pub, pub + publen);
203203
return true;
@@ -217,8 +217,8 @@ bool CPubKey::Decompress() {
217217
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, size())) {
218218
return false;
219219
}
220-
unsigned char pub[PUBLIC_KEY_SIZE];
221-
size_t publen = PUBLIC_KEY_SIZE;
220+
unsigned char pub[SIZE];
221+
size_t publen = SIZE;
222222
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
223223
Set(pub, pub + publen);
224224
return true;
@@ -227,7 +227,7 @@ bool CPubKey::Decompress() {
227227
bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const {
228228
assert(IsValid());
229229
assert((nChild >> 31) == 0);
230-
assert(size() == COMPRESSED_PUBLIC_KEY_SIZE);
230+
assert(size() == COMPRESSED_SIZE);
231231
unsigned char out[64];
232232
BIP32Hash(cc, nChild, *begin(), begin()+1, out);
233233
memcpy(ccChild.begin(), out+32, 32);
@@ -238,8 +238,8 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChi
238238
if (!secp256k1_ec_pubkey_tweak_add(secp256k1_context_verify, &pubkey, out)) {
239239
return false;
240240
}
241-
unsigned char pub[COMPRESSED_PUBLIC_KEY_SIZE];
242-
size_t publen = COMPRESSED_PUBLIC_KEY_SIZE;
241+
unsigned char pub[COMPRESSED_SIZE];
242+
size_t publen = COMPRESSED_SIZE;
243243
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_COMPRESSED);
244244
pubkeyChild.Set(pub, pub + publen);
245245
return true;
@@ -251,8 +251,8 @@ void CExtPubKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const {
251251
code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF;
252252
code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF;
253253
memcpy(code+9, chaincode.begin(), 32);
254-
assert(pubkey.size() == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE);
255-
memcpy(code+41, pubkey.begin(), CPubKey::COMPRESSED_PUBLIC_KEY_SIZE);
254+
assert(pubkey.size() == CPubKey::COMPRESSED_SIZE);
255+
memcpy(code+41, pubkey.begin(), CPubKey::COMPRESSED_SIZE);
256256
}
257257

258258
void CExtPubKey::Decode(const unsigned char code[BIP32_EXTKEY_SIZE]) {

src/pubkey.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,33 @@ class CPubKey
3333
/**
3434
* secp256k1:
3535
*/
36-
static constexpr unsigned int PUBLIC_KEY_SIZE = 65;
37-
static constexpr unsigned int COMPRESSED_PUBLIC_KEY_SIZE = 33;
36+
static constexpr unsigned int SIZE = 65;
37+
static constexpr unsigned int COMPRESSED_SIZE = 33;
3838
static constexpr unsigned int SIGNATURE_SIZE = 72;
3939
static constexpr unsigned int COMPACT_SIGNATURE_SIZE = 65;
4040
/**
4141
* see www.keylength.com
4242
* script supports up to 75 for single byte push
4343
*/
4444
static_assert(
45-
PUBLIC_KEY_SIZE >= COMPRESSED_PUBLIC_KEY_SIZE,
46-
"COMPRESSED_PUBLIC_KEY_SIZE is larger than PUBLIC_KEY_SIZE");
45+
SIZE >= COMPRESSED_SIZE,
46+
"COMPRESSED_SIZE is larger than SIZE");
4747

4848
private:
4949

5050
/**
5151
* Just store the serialized data.
5252
* Its length can very cheaply be computed from the first byte.
5353
*/
54-
unsigned char vch[PUBLIC_KEY_SIZE];
54+
unsigned char vch[SIZE];
5555

5656
//! Compute the length of a pubkey with a given first byte.
5757
unsigned int static GetLen(unsigned char chHeader)
5858
{
5959
if (chHeader == 2 || chHeader == 3)
60-
return COMPRESSED_PUBLIC_KEY_SIZE;
60+
return COMPRESSED_SIZE;
6161
if (chHeader == 4 || chHeader == 6 || chHeader == 7)
62-
return PUBLIC_KEY_SIZE;
62+
return SIZE;
6363
return 0;
6464
}
6565

@@ -140,7 +140,7 @@ class CPubKey
140140
void Unserialize(Stream& s)
141141
{
142142
unsigned int len = ::ReadCompactSize(s);
143-
if (len <= PUBLIC_KEY_SIZE) {
143+
if (len <= SIZE) {
144144
s.read((char*)vch, len);
145145
} else {
146146
// invalid pubkey, skip available data
@@ -179,7 +179,7 @@ class CPubKey
179179
//! Check whether this is a compressed public key.
180180
bool IsCompressed() const
181181
{
182-
return size() == COMPRESSED_PUBLIC_KEY_SIZE;
182+
return size() == COMPRESSED_SIZE;
183183
}
184184

185185
/**

src/script/interpreter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ static inline void popstack(std::vector<valtype>& stack)
6161
}
6262

6363
bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
64-
if (vchPubKey.size() < CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) {
64+
if (vchPubKey.size() < CPubKey::COMPRESSED_SIZE) {
6565
// Non-canonical public key: too short
6666
return false;
6767
}
6868
if (vchPubKey[0] == 0x04) {
69-
if (vchPubKey.size() != CPubKey::PUBLIC_KEY_SIZE) {
69+
if (vchPubKey.size() != CPubKey::SIZE) {
7070
// Non-canonical public key: invalid length for uncompressed key
7171
return false;
7272
}
7373
} else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
74-
if (vchPubKey.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) {
74+
if (vchPubKey.size() != CPubKey::COMPRESSED_SIZE) {
7575
// Non-canonical public key: invalid length for compressed key
7676
return false;
7777
}
@@ -83,7 +83,7 @@ bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
8383
}
8484

8585
bool static IsCompressedPubKey(const valtype &vchPubKey) {
86-
if (vchPubKey.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) {
86+
if (vchPubKey.size() != CPubKey::COMPRESSED_SIZE) {
8787
// Non-canonical public key: invalid length for compressed key
8888
return false;
8989
}

src/script/sign.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ template<typename Stream>
168168
void DeserializeHDKeypaths(Stream& s, const std::vector<unsigned char>& key, std::map<CPubKey, KeyOriginInfo>& hd_keypaths)
169169
{
170170
// Make sure that the key is the size of pubkey + 1
171-
if (key.size() != CPubKey::PUBLIC_KEY_SIZE + 1 && key.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 1) {
171+
if (key.size() != CPubKey::SIZE + 1 && key.size() != CPubKey::COMPRESSED_SIZE + 1) {
172172
throw std::ios_base::failure("Size of key was not the expected size for the type BIP32 keypath");
173173
}
174174
// Read in the pubkey from key

src/script/standard.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ const char* GetTxnOutputType(txnouttype t)
4343

4444
static bool MatchPayToPubkey(const CScript& script, valtype& pubkey)
4545
{
46-
if (script.size() == CPubKey::PUBLIC_KEY_SIZE + 2 && script[0] == CPubKey::PUBLIC_KEY_SIZE && script.back() == OP_CHECKSIG) {
47-
pubkey = valtype(script.begin() + 1, script.begin() + CPubKey::PUBLIC_KEY_SIZE + 1);
46+
if (script.size() == CPubKey::SIZE + 2 && script[0] == CPubKey::SIZE && script.back() == OP_CHECKSIG) {
47+
pubkey = valtype(script.begin() + 1, script.begin() + CPubKey::SIZE + 1);
4848
return CPubKey::ValidSize(pubkey);
4949
}
50-
if (script.size() == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 2 && script[0] == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE && script.back() == OP_CHECKSIG) {
51-
pubkey = valtype(script.begin() + 1, script.begin() + CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 1);
50+
if (script.size() == CPubKey::COMPRESSED_SIZE + 2 && script[0] == CPubKey::COMPRESSED_SIZE && script.back() == OP_CHECKSIG) {
51+
pubkey = valtype(script.begin() + 1, script.begin() + CPubKey::COMPRESSED_SIZE + 1);
5252
return CPubKey::ValidSize(pubkey);
5353
}
5454
return false;

0 commit comments

Comments
 (0)