diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-11-07 13:42:52 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-11-07 13:49:25 +0100 |
commit | 65e3a1e76202b9a695fc6319dbd527ac563e0895 (patch) | |
tree | 4346296f76f3f17b5f3c0120c79f166da64c489f /src | |
parent | 9ea87f9e187da41964c3cafdadf54b2f767c3450 (diff) |
Make sure that GetRandomBytes never fails
We're using GetRandomBytes in several contexts where it's either
unwieldy to return an error, or an error would mean a fatal exception
anyhow.
@gmaxwell checked OpenSSL a while ago and discovered that it never
actually fails, but it can't hurt to be a bit paranoid here.
Diffstat (limited to 'src')
-rw-r--r-- | src/random.cpp | 5 | ||||
-rw-r--r-- | src/random.h | 2 | ||||
-rw-r--r-- | src/wallet.cpp | 6 |
3 files changed, 5 insertions, 8 deletions
diff --git a/src/random.cpp b/src/random.cpp index 998e7dfb08..fc9505ae73 100644 --- a/src/random.cpp +++ b/src/random.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) diff --git a/src/random.h b/src/random.h index 161ebe8986..ec73d910c4 100644 --- a/src/random.h +++ b/src/random.h @@ -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(); diff --git a/src/wallet.cpp b/src/wallet.cpp index d392149dbb..ec439c5aad 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -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(); |