aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/crypter.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-09-18 08:23:29 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-10-19 16:17:33 +0200
commit999e4c91c2cd93f4cd8760b3572780c9d568f2f0 (patch)
tree6a7abfb39a4a697f84fa63ed600a60c1e5079618 /src/wallet/crypter.h
parent97c7f7362f9b59247753d6e8fa8022a6205f9c09 (diff)
downloadbitcoin-999e4c91c2cd93f4cd8760b3572780c9d568f2f0.tar.xz
wallet: Change CCrypter to use vectors with secure allocator
Change CCrypter to use vectors with secure allocator instead of buffers on in the object itself which will end up on the stack. This avoids having to call LockedPageManager to lock stack memory pages to prevent the memory from being swapped to disk. This is wasteful.
Diffstat (limited to 'src/wallet/crypter.h')
-rw-r--r--src/wallet/crypter.h19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/wallet/crypter.h b/src/wallet/crypter.h
index 5d0a4a3305..f00f7fa731 100644
--- a/src/wallet/crypter.h
+++ b/src/wallet/crypter.h
@@ -77,8 +77,8 @@ class CCrypter
{
friend class wallet_crypto::TestCrypter; // for test access to chKey/chIV
private:
- unsigned char chKey[WALLET_CRYPTO_KEY_SIZE];
- unsigned char chIV[WALLET_CRYPTO_IV_SIZE];
+ std::vector<unsigned char, secure_allocator<unsigned char>> vchKey;
+ std::vector<unsigned char, secure_allocator<unsigned char>> vchIV;
bool fKeySet;
int BytesToKeySHA512AES(const std::vector<unsigned char>& chSalt, const SecureString& strKeyData, int count, unsigned char *key,unsigned char *iv) const;
@@ -91,28 +91,21 @@ public:
void CleanKey()
{
- memory_cleanse(chKey, sizeof(chKey));
- memory_cleanse(chIV, sizeof(chIV));
+ memory_cleanse(vchKey.data(), vchKey.size());
+ memory_cleanse(vchIV.data(), vchIV.size());
fKeySet = false;
}
CCrypter()
{
fKeySet = false;
-
- // Try to keep the key data out of swap (and be a bit over-careful to keep the IV that we don't even use out of swap)
- // Note that this does nothing about suspend-to-disk (which will put all our key data on disk)
- // Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process.
- LockedPageManager::Instance().LockRange(&chKey[0], sizeof chKey);
- LockedPageManager::Instance().LockRange(&chIV[0], sizeof chIV);
+ vchKey.resize(WALLET_CRYPTO_KEY_SIZE);
+ vchIV.resize(WALLET_CRYPTO_IV_SIZE);
}
~CCrypter()
{
CleanKey();
-
- LockedPageManager::Instance().UnlockRange(&chKey[0], sizeof chKey);
- LockedPageManager::Instance().UnlockRange(&chIV[0], sizeof chIV);
}
};