summaryrefslogtreecommitdiffstats
path: root/CryptoPP/osrng.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2013-08-16 12:25:53 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2013-08-16 12:25:53 +0200
commitcbde4f546a3135d9889b37aa227468106958a94a (patch)
tree0444a5f3d1797a01fb6a4c01def9933084652e8c /CryptoPP/osrng.cpp
parentFeature and bugfixes [SEE DESC] (diff)
parentReplaced E_ENTITY_TYPE_XXX with cMonster::mtXXX. (diff)
downloadcuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar.gz
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar.bz2
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar.lz
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar.xz
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar.zst
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.zip
Diffstat (limited to 'CryptoPP/osrng.cpp')
-rw-r--r--CryptoPP/osrng.cpp29
1 files changed, 25 insertions, 4 deletions
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)