|
|
@ -102,7 +102,7 @@ bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingM |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext) |
|
|
|
static bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CCrypter cKeyCrypter; |
|
|
|
CCrypter cKeyCrypter; |
|
|
|
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE); |
|
|
|
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE); |
|
|
@ -112,7 +112,7 @@ bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vch |
|
|
|
return cKeyCrypter.Encrypt(*((const CKeyingMaterial*)&vchPlaintext), vchCiphertext); |
|
|
|
return cKeyCrypter.Encrypt(*((const CKeyingMaterial*)&vchPlaintext), vchCiphertext); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext) |
|
|
|
static bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CCrypter cKeyCrypter; |
|
|
|
CCrypter cKeyCrypter; |
|
|
|
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE); |
|
|
|
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE); |
|
|
@ -122,6 +122,19 @@ bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned |
|
|
|
return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext)); |
|
|
|
return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool DecryptKey(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCryptedSecret, const CPubKey& vchPubKey, CKey& key) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CKeyingMaterial vchSecret; |
|
|
|
|
|
|
|
if(!DecryptSecret(vMasterKey, vchCryptedSecret, vchPubKey.GetHash(), vchSecret)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (vchSecret.size() != 32) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed()); |
|
|
|
|
|
|
|
return key.VerifyPubKey(vchPubKey); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CCryptoKeyStore::SetCrypted() |
|
|
|
bool CCryptoKeyStore::SetCrypted() |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_KeyStore); |
|
|
|
LOCK(cs_KeyStore); |
|
|
@ -161,20 +174,8 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const CPubKey &vchPubKey = (*mi).second.first; |
|
|
|
const CPubKey &vchPubKey = (*mi).second.first; |
|
|
|
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second; |
|
|
|
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second; |
|
|
|
CKeyingMaterial vchSecret; |
|
|
|
|
|
|
|
if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash(), vchSecret)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
keyFail = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (vchSecret.size() != 32) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
keyFail = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
CKey key; |
|
|
|
CKey key; |
|
|
|
key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed()); |
|
|
|
if (!DecryptKey(vMasterKeyIn, vchCryptedSecret, vchPubKey, key)) |
|
|
|
if (key.GetPubKey() != vchPubKey) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
keyFail = true; |
|
|
|
keyFail = true; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -243,13 +244,7 @@ bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
const CPubKey &vchPubKey = (*mi).second.first; |
|
|
|
const CPubKey &vchPubKey = (*mi).second.first; |
|
|
|
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second; |
|
|
|
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second; |
|
|
|
CKeyingMaterial vchSecret; |
|
|
|
return DecryptKey(vMasterKey, vchCryptedSecret, vchPubKey, keyOut); |
|
|
|
if (!DecryptSecret(vMasterKey, vchCryptedSecret, vchPubKey.GetHash(), vchSecret)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
if (vchSecret.size() != 32) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
keyOut.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed()); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|