]> Git Repo - VerusCoin.git/commitdiff
Make sure that GetRandomBytes never fails
authorWladimir J. van der Laan <[email protected]>
Fri, 7 Nov 2014 12:42:52 +0000 (13:42 +0100)
committerWladimir J. van der Laan <[email protected]>
Fri, 7 Nov 2014 12:49:25 +0000 (13:49 +0100)
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.

src/random.cpp
src/random.h
src/wallet.cpp

index 998e7dfb08a035dc5b70ade9b91b129dbfc996de..fc9505ae73dbf4422489918d0b3b016078bdfb78 100644 (file)
@@ -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)
index 161ebe89860aedfe96353cf30f06c159450c68a5..ec73d910c48d76dade5de58312afdf9be0967808 100644 (file)
@@ -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();
index d392149dbb3b7c263180465056080f46106db088..ec439c5aad9076d9f25c16652dd9541ca9d8e9f6 100644 (file)
@@ -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();
This page took 0.032447 seconds and 4 git commands to generate.