Skip to content

Commit dfa23b9

Browse files
committed
CSecret/CKey -> CKey/CPubKey split/refactor
1 parent 5d89148 commit dfa23b9

26 files changed

+564
-595
lines changed

src/alert.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ bool CAlert::RelayTo(CNode* pnode) const
144144

145145
bool CAlert::CheckSignature() const
146146
{
147-
CKey key;
148-
if (!key.SetPubKey(ParseHex(fTestNet ? pszTestKey : pszMainKey)))
149-
return error("CAlert::CheckSignature() : SetPubKey failed");
147+
CPubKey key(ParseHex(fTestNet ? pszTestKey : pszMainKey));
150148
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
151149
return error("CAlert::CheckSignature() : verify signature failed");
152150

src/allocators.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ class LockedPageManager: public LockedPageManagerBase<MemoryPageLocker>
176176
{}
177177
};
178178

179+
template<typename T> void LockObject(const T &t) {
180+
LockedPageManager::instance.LockRange((void*)(&t), sizeof(T));
181+
}
182+
183+
template<typename T> void UnlockObject(const T &t) {
184+
OPENSSL_cleanse((void*)(&t), sizeof(T));
185+
LockedPageManager::instance.UnlockRange((void*)(&t), sizeof(T));
186+
}
187+
179188
//
180189
// Allocator that locks its contents from being paged
181190
// out of memory and clears its contents before deletion.

src/base58.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,21 +398,19 @@ bool inline CBitcoinAddressVisitor::operator()(const CNoDestination &id) const {
398398
class CBitcoinSecret : public CBase58Data
399399
{
400400
public:
401-
void SetSecret(const CSecret& vchSecret, bool fCompressed)
401+
void SetKey(const CKey& vchSecret)
402402
{
403-
assert(vchSecret.size() == 32);
404-
SetData(fTestNet ? 239 : 128, &vchSecret[0], vchSecret.size());
405-
if (fCompressed)
403+
assert(vchSecret.IsValid());
404+
SetData(fTestNet ? 239 : 128, vchSecret.begin(), vchSecret.size());
405+
if (vchSecret.IsCompressed())
406406
vchData.push_back(1);
407407
}
408408

409-
CSecret GetSecret(bool &fCompressedOut)
409+
CKey GetKey()
410410
{
411-
CSecret vchSecret;
412-
vchSecret.resize(32);
413-
memcpy(&vchSecret[0], &vchData[0], 32);
414-
fCompressedOut = vchData.size() == 33;
415-
return vchSecret;
411+
CKey ret;
412+
ret.Set(&vchData[0], &vchData[32], vchData.size() > 32 && vchData[32] == 1);
413+
return ret;
416414
}
417415

418416
bool IsValid() const
@@ -443,9 +441,9 @@ class CBitcoinSecret : public CBase58Data
443441
return SetString(strSecret.c_str());
444442
}
445443

446-
CBitcoinSecret(const CSecret& vchSecret, bool fCompressed)
444+
CBitcoinSecret(const CKey& vchSecret)
447445
{
448-
SetSecret(vchSecret, fCompressed);
446+
SetKey(vchSecret);
449447
}
450448

451449
CBitcoinSecret()

src/crypter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingM
100100
}
101101

102102

103-
bool EncryptSecret(CKeyingMaterial& vMasterKey, const CSecret &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext)
103+
bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext)
104104
{
105105
CCrypter cKeyCrypter;
106106
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE);
107107
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE);
108108
if(!cKeyCrypter.SetKey(vMasterKey, chIV))
109109
return false;
110-
return cKeyCrypter.Encrypt((CKeyingMaterial)vchPlaintext, vchCiphertext);
110+
return cKeyCrypter.Encrypt(*((const CKeyingMaterial*)&vchPlaintext), vchCiphertext);
111111
}
112112

113-
bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CSecret& vchPlaintext)
113+
bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext)
114114
{
115115
CCrypter cKeyCrypter;
116116
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE);

src/crypter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class CCrypter
101101
}
102102
};
103103

104-
bool EncryptSecret(CKeyingMaterial& vMasterKey, const CSecret &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext);
105-
bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char> &vchCiphertext, const uint256& nIV, CSecret &vchPlaintext);
104+
bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext);
105+
bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext);
106106

107107
#endif

0 commit comments

Comments
 (0)