From 0297cf548558a20e36acac3057728ad9a9aac234 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 15 Aug 2013 09:03:58 +0200 Subject: Updated CryptoPP to 5.6.2 --- CryptoPP/osrng.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'CryptoPP/osrng.cpp') diff --git a/CryptoPP/osrng.cpp b/CryptoPP/osrng.cpp index fa6dd36dd..76e486b4e 100644 --- a/CryptoPP/osrng.cpp +++ b/CryptoPP/osrng.cpp @@ -83,8 +83,22 @@ void NonblockingRng::GenerateBlock(byte *output, size_t size) if (!CryptGenRandom(m_Provider.GetProviderHandle(), (DWORD)size, output)) throw OS_RNG_Err("CryptGenRandom"); #else - if (read(m_fd, output, size) != size) - throw OS_RNG_Err("read /dev/urandom"); + while (size) + { + ssize_t len = read(m_fd, output, size); + + if (len < 0) + { + // /dev/urandom reads CAN give EAGAIN errors! (maybe EINTR as well) + if (errno != EINTR && errno != EAGAIN) + throw OS_RNG_Err("read /dev/urandom"); + + continue; + } + + output += len; + size -= len; + } #endif } @@ -119,10 +133,17 @@ void BlockingRng::GenerateBlock(byte *output, size_t size) while (size) { // on some systems /dev/random will block until all bytes - // are available, on others it will returns immediately + // are available, on others it returns immediately ssize_t len = read(m_fd, output, size); if (len < 0) - throw OS_RNG_Err("read " CRYPTOPP_BLOCKING_RNG_FILENAME); + { + // /dev/random reads CAN give EAGAIN errors! (maybe EINTR as well) + if (errno != EINTR && errno != EAGAIN) + throw OS_RNG_Err("read " CRYPTOPP_BLOCKING_RNG_FILENAME); + + continue; + } + size -= len; output += len; if (size) -- cgit v1.2.3