Browse Source
Merge pull request #5239
65e3a1e
Make sure that GetRandomBytes never fails (Wladimir J. van der Laan)
pull/145/head
Wladimir J. van der Laan
10 years ago
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
3 changed files with
5 additions and
8 deletions
-
src/random.cpp
-
src/random.h
-
src/wallet.cpp
|
|
@ -82,13 +82,12 @@ void RandAddSeedPerfmon() |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
bool GetRandBytes(unsigned char* buf, int num) |
|
|
|
void GetRandBytes(unsigned char* buf, int num) |
|
|
|
{ |
|
|
|
if (RAND_bytes(buf, num) != 1) { |
|
|
|
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) |
|
|
|
|
|
@ -19,7 +19,7 @@ void RandAddSeedPerfmon(); |
|
|
|
/**
|
|
|
|
* 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); |
|
|
|
int GetRandInt(int nMax); |
|
|
|
uint256 GetRandHash(); |
|
|
|
|
|
@ -422,15 +422,13 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) |
|
|
|
RandAddSeedPerfmon(); |
|
|
|
|
|
|
|
vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE); |
|
|
|
if (!GetRandBytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE)) |
|
|
|
return false; |
|
|
|
GetRandBytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE); |
|
|
|
|
|
|
|
CMasterKey kMasterKey; |
|
|
|
RandAddSeedPerfmon(); |
|
|
|
|
|
|
|
kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE); |
|
|
|
if (!GetRandBytes(&kMasterKey.vchSalt[0], WALLET_CRYPTO_SALT_SIZE)) |
|
|
|
return false; |
|
|
|
GetRandBytes(&kMasterKey.vchSalt[0], WALLET_CRYPTO_SALT_SIZE); |
|
|
|
|
|
|
|
CCrypter crypter; |
|
|
|
int64_t nStartTime = GetTimeMillis(); |
|
|
|