|
|
@ -37,7 +37,7 @@ bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::v |
|
|
|
|
|
|
|
|
|
|
|
bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const std::vector<unsigned char>& chNewIV) |
|
|
|
bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const std::vector<unsigned char>& chNewIV) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (chNewKey.size() != WALLET_CRYPTO_KEY_SIZE || chNewIV.size() != WALLET_CRYPTO_KEY_SIZE) |
|
|
|
if (chNewKey.size() != WALLET_CRYPTO_KEY_SIZE || chNewIV.size() != WALLET_CRYPTO_IV_SIZE) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
memcpy(&chKey[0], &chNewKey[0], sizeof chKey); |
|
|
|
memcpy(&chKey[0], &chNewKey[0], sizeof chKey); |
|
|
@ -105,8 +105,8 @@ bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingM |
|
|
|
static 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_IV_SIZE); |
|
|
|
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE); |
|
|
|
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_IV_SIZE); |
|
|
|
if(!cKeyCrypter.SetKey(vMasterKey, chIV)) |
|
|
|
if(!cKeyCrypter.SetKey(vMasterKey, chIV)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
return cKeyCrypter.Encrypt(*((const CKeyingMaterial*)&vchPlaintext), vchCiphertext); |
|
|
|
return cKeyCrypter.Encrypt(*((const CKeyingMaterial*)&vchPlaintext), vchCiphertext); |
|
|
@ -115,8 +115,8 @@ static bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMateri |
|
|
|
static 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_IV_SIZE); |
|
|
|
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE); |
|
|
|
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_IV_SIZE); |
|
|
|
if(!cKeyCrypter.SetKey(vMasterKey, chIV)) |
|
|
|
if(!cKeyCrypter.SetKey(vMasterKey, chIV)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext)); |
|
|
|
return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext)); |
|
|
|