Skip to content

Commit d2e74c5

Browse files
committed
boost: moveonly: split CPubKey and friends to new files
1 parent 78c228c commit d2e74c5

17 files changed

+356
-305
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ BITCOIN_CORE_H = \
102102
noui.h \
103103
pow.h \
104104
protocol.h \
105+
pubkey.h \
105106
random.h \
106107
rpcclient.h \
107108
rpcprotocol.h \
@@ -228,6 +229,7 @@ libbitcoin_common_a_SOURCES = \
228229
keystore.cpp \
229230
netbase.cpp \
230231
protocol.cpp \
232+
pubkey.cpp \
231233
script/interpreter.cpp \
232234
script/script.cpp \
233235
script/sigcache.cpp \

src/alert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "chainparams.h"
99
#include "clientversion.h"
10-
#include "key.h"
10+
#include "pubkey.h"
1111
#include "net.h"
1212
#include "timedata.h"
1313
#include "ui_interface.h"

src/base58.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "chainparams.h"
1818
#include "key.h"
19+
#include "pubkey.h"
1920
#include "script/script.h"
2021
#include "script/standard.h"
2122

src/bloom.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "bloom.h"
66

77
#include "core/transaction.h"
8+
#include "hash.h"
89
#include "script/script.h"
910
#include "script/standard.h"
1011
#include "streams.h"

src/compressor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "compressor.h"
77

88
#include "hash.h"
9-
#include "key.h"
9+
#include "pubkey.h"
1010
#include "script/standard.h"
1111

1212
bool CScriptCompressor::IsToKeyID(CKeyID &hash) const

src/key.cpp

Lines changed: 1 addition & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "crypto/sha2.h"
88
#include "eccryptoverify.h"
9+
#include "pubkey.h"
910
#include "random.h"
1011

1112
#ifdef USE_SECP256K1
@@ -167,76 +168,6 @@ bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) {
167168
return true;
168169
}
169170

170-
bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const {
171-
if (!IsValid())
172-
return false;
173-
#ifdef USE_SECP256K1
174-
if (secp256k1_ecdsa_verify((const unsigned char*)&hash, 32, &vchSig[0], vchSig.size(), begin(), size()) != 1)
175-
return false;
176-
#else
177-
CECKey key;
178-
if (!key.SetPubKey(begin(), size()))
179-
return false;
180-
if (!key.Verify(hash, vchSig))
181-
return false;
182-
#endif
183-
return true;
184-
}
185-
186-
bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig) {
187-
if (vchSig.size() != 65)
188-
return false;
189-
int recid = (vchSig[0] - 27) & 3;
190-
bool fComp = ((vchSig[0] - 27) & 4) != 0;
191-
#ifdef USE_SECP256K1
192-
int pubkeylen = 65;
193-
if (!secp256k1_ecdsa_recover_compact((const unsigned char*)&hash, 32, &vchSig[1], (unsigned char*)begin(), &pubkeylen, fComp, recid))
194-
return false;
195-
assert((int)size() == pubkeylen);
196-
#else
197-
CECKey key;
198-
if (!key.Recover(hash, &vchSig[1], recid))
199-
return false;
200-
std::vector<unsigned char> pubkey;
201-
key.GetPubKey(pubkey, fComp);
202-
Set(pubkey.begin(), pubkey.end());
203-
#endif
204-
return true;
205-
}
206-
207-
bool CPubKey::IsFullyValid() const {
208-
if (!IsValid())
209-
return false;
210-
#ifdef USE_SECP256K1
211-
if (!secp256k1_ecdsa_pubkey_verify(begin(), size()))
212-
return false;
213-
#else
214-
CECKey key;
215-
if (!key.SetPubKey(begin(), size()))
216-
return false;
217-
#endif
218-
return true;
219-
}
220-
221-
bool CPubKey::Decompress() {
222-
if (!IsValid())
223-
return false;
224-
#ifdef USE_SECP256K1
225-
int clen = size();
226-
int ret = secp256k1_ecdsa_pubkey_decompress((unsigned char*)begin(), &clen);
227-
assert(ret);
228-
assert(clen == (int)size());
229-
#else
230-
CECKey key;
231-
if (!key.SetPubKey(begin(), size()))
232-
return false;
233-
std::vector<unsigned char> pubkey;
234-
key.GetPubKey(pubkey, false);
235-
Set(pubkey.begin(), pubkey.end());
236-
#endif
237-
return true;
238-
}
239-
240171
bool CKey::Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const {
241172
assert(IsValid());
242173
assert(IsCompressed());
@@ -263,27 +194,6 @@ bool CKey::Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild
263194
return ret;
264195
}
265196

266-
bool CPubKey::Derive(CPubKey& pubkeyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const {
267-
assert(IsValid());
268-
assert((nChild >> 31) == 0);
269-
assert(begin() + 33 == end());
270-
unsigned char out[64];
271-
BIP32Hash(cc, nChild, *begin(), begin()+1, out);
272-
memcpy(ccChild, out+32, 32);
273-
#ifdef USE_SECP256K1
274-
pubkeyChild = *this;
275-
bool ret = secp256k1_ecdsa_pubkey_tweak_add((unsigned char*)pubkeyChild.begin(), pubkeyChild.size(), out);
276-
#else
277-
CECKey key;
278-
bool ret = key.SetPubKey(begin(), size());
279-
ret &= key.TweakPublic(out);
280-
std::vector<unsigned char> pubkey;
281-
key.GetPubKey(pubkey, true);
282-
pubkeyChild.Set(pubkey.begin(), pubkey.end());
283-
#endif
284-
return ret;
285-
}
286-
287197
bool CExtKey::Derive(CExtKey &out, unsigned int nChild) const {
288198
out.nDepth = nDepth + 1;
289199
CKeyID id = key.GetPubKey().GetID();
@@ -334,32 +244,6 @@ void CExtKey::Decode(const unsigned char code[74]) {
334244
key.Set(code+42, code+74, true);
335245
}
336246

337-
void CExtPubKey::Encode(unsigned char code[74]) const {
338-
code[0] = nDepth;
339-
memcpy(code+1, vchFingerprint, 4);
340-
code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF;
341-
code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF;
342-
memcpy(code+9, vchChainCode, 32);
343-
assert(pubkey.size() == 33);
344-
memcpy(code+41, pubkey.begin(), 33);
345-
}
346-
347-
void CExtPubKey::Decode(const unsigned char code[74]) {
348-
nDepth = code[0];
349-
memcpy(vchFingerprint, code+1, 4);
350-
nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8];
351-
memcpy(vchChainCode, code+9, 32);
352-
pubkey.Set(code+41, code+74);
353-
}
354-
355-
bool CExtPubKey::Derive(CExtPubKey &out, unsigned int nChild) const {
356-
out.nDepth = nDepth + 1;
357-
CKeyID id = pubkey.GetID();
358-
memcpy(&out.vchFingerprint[0], &id, 4);
359-
out.nChild = nChild;
360-
return pubkey.Derive(out.pubkey, out.vchChainCode, nChild, vchChainCode);
361-
}
362-
363247
bool ECC_InitSanityCheck() {
364248
#ifdef USE_SECP256K1
365249
return true;

0 commit comments

Comments
 (0)