VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Core
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2020-06-19 03:30:05 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2020-06-19 03:31:47 +0200
commit4f1de9666abc476c72462cb6436c85e53eb3f048 (patch)
treec2b096e0a1779e4f3f4c814da2d9a33f41fa5176 /src/Core
parentf765860dfb60a98dd7d46c97d76fe2776b7e2022 (diff)
downloadVeraCrypt-4f1de9666abc476c72462cb6436c85e53eb3f048.tar.gz
VeraCrypt-4f1de9666abc476c72462cb6436c85e53eb3f048.zip
Linux/MacOSX: Don't always ignore /dev/random failure by making sure that it has returned random bytes successfully at least once during the lifetime of RandomNumberGenerator
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/RandomNumberGenerator.cpp21
-rw-r--r--src/Core/RandomNumberGenerator.h1
2 files changed, 21 insertions, 1 deletions
diff --git a/src/Core/RandomNumberGenerator.cpp b/src/Core/RandomNumberGenerator.cpp
index 70c46492..6ad46605 100644
--- a/src/Core/RandomNumberGenerator.cpp
+++ b/src/Core/RandomNumberGenerator.cpp
@@ -44,7 +44,24 @@ namespace VeraCrypt
throw_sys_sub_if (random == -1, L"/dev/random");
finally_do_arg (int, random, { close (finally_arg); });
- throw_sys_sub_if (read (random, buffer, buffer.Size()) == -1 && errno != EAGAIN, L"/dev/random");
+ // ensure that we have read /dev/random successfully at least once before continuing
+ while (true)
+ {
+ int rndCount = read (random, buffer, buffer.Size());
+ throw_sys_sub_if ((rndCount == -1) && errno != EAGAIN, L"/dev/random");
+ if (rndCount == -1 && !DevRandomSucceeded)
+ {
+ // wait 250ms before querying /dev/random again
+ ::usleep (250 * 1000);
+ }
+ else
+ {
+ if (rndCount != -1)
+ DevRandomSucceeded = true;
+ break;
+ }
+ }
+
AddToPool (buffer);
/* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
@@ -218,6 +235,7 @@ namespace VeraCrypt
EnrichedByUser = false;
Running = false;
+ DevRandomSucceeded = false;
}
void RandomNumberGenerator::Test ()
@@ -255,4 +273,5 @@ namespace VeraCrypt
bool RandomNumberGenerator::Running = false;
size_t RandomNumberGenerator::WriteOffset;
struct rand_data *RandomNumberGenerator::JitterRngCtx = NULL;
+ bool RandomNumberGenerator::DevRandomSucceeded = false;
}
diff --git a/src/Core/RandomNumberGenerator.h b/src/Core/RandomNumberGenerator.h
index 6df31ae0..9ef45dfe 100644
--- a/src/Core/RandomNumberGenerator.h
+++ b/src/Core/RandomNumberGenerator.h
@@ -55,6 +55,7 @@ namespace VeraCrypt
static bool Running;
static size_t WriteOffset;
static struct rand_data *JitterRngCtx;
+ static bool DevRandomSucceeded;
};
}