Merge pull request #5239

65e3a1e Make sure that GetRandomBytes never fails (Wladimir J. van der Laan)
This commit is contained in:
Wladimir J. van der Laan committed 2014-11-10 17:30:13 +01:00
commit 33d5ee6830
3 files changed
+5 -8

No files matched your search

+2 -3
View File
@@ -82,13 +82,12 @@ void RandAddSeedPerfmon()
#endif #endif
} }
bool GetRandBytes(unsigned char* buf, int num) void GetRandBytes(unsigned char* buf, int num)
{ {
if (RAND_bytes(buf, num) != 1) { if (RAND_bytes(buf, num) != 1) {
LogPrintf("%s: OpenSSL RAND_bytes() failed with error: %s\n", __func__, ERR_error_string(ERR_get_error(), NULL)); LogPrintf("%s: OpenSSL RAND_bytes() failed with error: %s\n", __func__, ERR_error_string(ERR_get_error(), NULL));
return false; assert(false);
} }
return true;
} }
uint64_t GetRand(uint64_t nMax) uint64_t GetRand(uint64_t nMax)
+1 -1
View File
@@ -19,7 +19,7 @@ void RandAddSeedPerfmon();
/** /**
* Functions to gather random data via the OpenSSL PRNG * Functions to gather random data via the OpenSSL PRNG
*/ */
bool GetRandBytes(unsigned char* buf, int num); void GetRandBytes(unsigned char* buf, int num);
uint64_t GetRand(uint64_t nMax); uint64_t GetRand(uint64_t nMax);
int GetRandInt(int nMax); int GetRandInt(int nMax);
uint256 GetRandHash(); uint256 GetRandHash();
+2 -4
View File
@@ -422,15 +422,13 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
RandAddSeedPerfmon(); RandAddSeedPerfmon();
vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE); vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
if (!GetRandBytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE)) GetRandBytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);
return false;
CMasterKey kMasterKey; CMasterKey kMasterKey;
RandAddSeedPerfmon(); RandAddSeedPerfmon();
kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE); kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE);
if (!GetRandBytes(&kMasterKey.vchSalt[0], WALLET_CRYPTO_SALT_SIZE)) GetRandBytes(&kMasterKey.vchSalt[0], WALLET_CRYPTO_SALT_SIZE);
return false;
CCrypter crypter; CCrypter crypter;
int64_t nStartTime = GetTimeMillis(); int64_t nStartTime = GetTimeMillis();