Remove RAND_bytes calls.

This commit is contained in:
JoelKatz
2012-12-06 10:55:56 -08:00
parent fa5e328561
commit 1d2bb868b6
7 changed files with 20 additions and 41 deletions

View File

@@ -45,8 +45,8 @@ Application::Application() :
mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL), mWSPublicDoor(NULL), mWSPrivateDoor(NULL), mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL), mWSPublicDoor(NULL), mWSPrivateDoor(NULL),
mSweepTimer(mAuxService) mSweepTimer(mAuxService)
{ {
RAND_bytes(mNonce256.begin(), mNonce256.size()); getRand(mNonce256.begin(), mNonce256.size());
RAND_bytes(reinterpret_cast<unsigned char *>(&mNonceST), sizeof(mNonceST)); getRand(reinterpret_cast<unsigned char *>(&mNonceST), sizeof(mNonceST));
mJobQueue.setThreadCount(); mJobQueue.setThreadCount();
mSweepTimer.expires_from_now(boost::posix_time::seconds(60)); mSweepTimer.expires_from_now(boost::posix_time::seconds(60));
mSweepTimer.async_wait(boost::bind(&Application::sweep, this)); mSweepTimer.async_wait(boost::bind(&Application::sweep, this));

View File

@@ -116,8 +116,7 @@ std::vector<unsigned char> CKey::encryptECIES(CKey& otherKey, const std::vector<
{ {
ECIES_ENC_IV_TYPE iv; ECIES_ENC_IV_TYPE iv;
if (RAND_bytes(static_cast<unsigned char *>(iv.begin()), ECIES_ENC_BLK_SIZE) != 1) getRand(static_cast<unsigned char *>(iv.begin()), ECIES_ENC_BLK_SIZE);
throw std::runtime_error("insufficient entropy");
ECIES_ENC_KEY_TYPE secret; ECIES_ENC_KEY_TYPE secret;
ECIES_HMAC_KEY_TYPE hmacKey; ECIES_HMAC_KEY_TYPE hmacKey;
@@ -280,8 +279,7 @@ bool checkECIES(void)
std::vector<unsigned char> message(4096); std::vector<unsigned char> message(4096);
int msglen = i%3000; int msglen = i%3000;
if (RAND_bytes(static_cast<unsigned char *>(&message.front()), msglen) != 1) getRand(static_cast<unsigned char *>(&message.front()), msglen);
throw std::runtime_error("insufficient entropy");
message.resize(msglen); message.resize(msglen);
// encrypt message with sender's private key and recipient's public key // encrypt message with sender's private key and recipient's public key

View File

@@ -1311,19 +1311,8 @@ bool NetworkOPs::subServer(InfoSub* ispListener, Json::Value& jvResult)
jvResult["stand_alone"] = theConfig.RUN_STANDALONE; jvResult["stand_alone"] = theConfig.RUN_STANDALONE;
switch (RAND_bytes(uRandom.begin(), uRandom.size())) getRand(uRandom.begin(), uRandom.size());
{
case 0:
case 1:
jvResult["random"] = uRandom.ToString(); jvResult["random"] = uRandom.ToString();
break;
case -1:
default:
// XXX Should probably stop running.
cLog(lsFATAL) << "Internal error: unable to generate secure random.";
break;
}
return mSubServer.insert(ispListener).second; return mSubServer.insert(ispListener).second;
} }

View File

@@ -61,7 +61,7 @@ uint256 ProofOfWork::solve(int maxIterations) const
throw std::runtime_error("invalid proof of work target/iteration"); throw std::runtime_error("invalid proof of work target/iteration");
uint256 nonce; uint256 nonce;
RAND_bytes(nonce.begin(), nonce.size()); getRand(nonce.begin(), nonce.size());
std::vector<uint256> buf2; std::vector<uint256> buf2;
buf2.resize(mIterations); buf2.resize(mIterations);
@@ -112,7 +112,7 @@ bool ProofOfWork::checkSolution(const uint256& solution) const
ProofOfWorkGenerator::ProofOfWorkGenerator() : mValidTime(180) ProofOfWorkGenerator::ProofOfWorkGenerator() : mValidTime(180)
{ {
setDifficulty(1); setDifficulty(1);
RAND_bytes(mSecret.begin(), mSecret.size()); getRand(mSecret.begin(), mSecret.size());
} }
ProofOfWork ProofOfWorkGenerator::getProof() ProofOfWork ProofOfWorkGenerator::getProof()
@@ -123,7 +123,7 @@ ProofOfWork ProofOfWorkGenerator::getProof()
int now = static_cast<int>(time(NULL) / 4); int now = static_cast<int>(time(NULL) / 4);
uint256 challenge; uint256 challenge;
RAND_bytes(challenge.begin(), challenge.size()); getRand(challenge.begin(), challenge.size());
boost::mutex::scoped_lock sl(mLock); boost::mutex::scoped_lock sl(mLock);

View File

@@ -664,23 +664,15 @@ Json::Value RPCHandler::doRandom(Json::Value jvRequest)
{ {
uint256 uRandom; uint256 uRandom;
switch (RAND_bytes(uRandom.begin(), uRandom.size())) try
{
case 0:
case 1:
{ {
getRand(uRandom.begin(), uRandom.size());
Json::Value jvResult; Json::Value jvResult;
jvResult["random"] = uRandom.ToString(); jvResult["random"] = uRandom.ToString();
return jvResult; return jvResult;
} }
break; catch (...)
{
case -1:
return rpcError(rpcNOT_SUPPORTED);
default:
return rpcError(rpcINTERNAL); return rpcError(rpcINTERNAL);
} }
} }

View File

@@ -792,7 +792,7 @@ void RippleAddress::setSeedRandom()
// XXX Maybe we should call MakeNewKey // XXX Maybe we should call MakeNewKey
uint128 key; uint128 key;
RAND_bytes(key.begin(), key.size()); getRand(key.begin(), key.size());
RippleAddress::setSeed(key); RippleAddress::setSeed(key);
} }

View File

@@ -78,7 +78,7 @@ void SNTPClient::resolveComplete(const boost::system::error_code& error, boost::
} }
query.mReceivedReply = false; query.mReceivedReply = false;
query.mLocalTimeSent = now; query.mLocalTimeSent = now;
RAND_bytes(reinterpret_cast<unsigned char *>(&query.mQueryNonce), sizeof(query.mQueryNonce)); getRand(reinterpret_cast<unsigned char *>(&query.mQueryNonce), sizeof(query.mQueryNonce));
reinterpret_cast<uint32*>(SNTPQueryData)[NTP_OFF_XMITTS_INT] = time(NULL) + NTP_UNIX_OFFSET; reinterpret_cast<uint32*>(SNTPQueryData)[NTP_OFF_XMITTS_INT] = time(NULL) + NTP_UNIX_OFFSET;
reinterpret_cast<uint32*>(SNTPQueryData)[NTP_OFF_XMITTS_FRAC] = query.mQueryNonce; reinterpret_cast<uint32*>(SNTPQueryData)[NTP_OFF_XMITTS_FRAC] = query.mQueryNonce;
mSocket.async_send_to(boost::asio::buffer(SNTPQueryData, 48), *sel, mSocket.async_send_to(boost::asio::buffer(SNTPQueryData, 48), *sel,