diff options
-rw-r--r-- | src/Core/RandomNumberGenerator.cpp | 21 | ||||
-rw-r--r-- | src/Core/RandomNumberGenerator.h | 1 |
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; }; } |