VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Core/RandomNumberGenerator.cpp26
-rw-r--r--src/Core/RandomNumberGenerator.h1
2 files changed, 11 insertions, 16 deletions
diff --git a/src/Core/RandomNumberGenerator.cpp b/src/Core/RandomNumberGenerator.cpp
index 4451348e..6b401901 100644
--- a/src/Core/RandomNumberGenerator.cpp
+++ b/src/Core/RandomNumberGenerator.cpp
@@ -54,22 +54,20 @@ namespace VeraCrypt
{
int rndCount = read (random, buffer, buffer.Size());
throw_sys_sub_if ((rndCount == -1) && errno != EAGAIN && errno != ERESTART && errno != EINTR, L"/dev/random");
- if (rndCount == -1 && (!DevRandomSucceeded || (DevRandomBytesCount < 32)))
- {
- // wait 250ms before querying /dev/random again
- ::usleep (250 * 1000);
+ if (rndCount != -1) {
+ // We count returned bytes until 32-bytes threshold reached
+ if (DevRandomBytesCount < 32)
+ DevRandomBytesCount += rndCount;
+ break;
}
- else
- {
- if (rndCount != -1)
- {
- // We count returned bytes untill 32-bytes treshold reached
- if (DevRandomBytesCount < 32)
- DevRandomBytesCount += rndCount;
- DevRandomSucceeded = true;
- }
+ else if (DevRandomBytesCount >= 32) {
+ // allow /dev/random to fail gracefully since we have enough bytes
break;
}
+ else {
+ // wait 250ms before querying /dev/random again
+ ::usleep (250 * 1000);
+ }
}
AddToPool (buffer);
@@ -253,7 +251,6 @@ namespace VeraCrypt
EnrichedByUser = false;
Running = false;
- DevRandomSucceeded = false;
DevRandomBytesCount = 0;
}
@@ -292,6 +289,5 @@ namespace VeraCrypt
bool RandomNumberGenerator::Running = false;
size_t RandomNumberGenerator::WriteOffset;
struct rand_data *RandomNumberGenerator::JitterRngCtx = NULL;
- bool RandomNumberGenerator::DevRandomSucceeded = false;
int RandomNumberGenerator::DevRandomBytesCount = 0;
}
diff --git a/src/Core/RandomNumberGenerator.h b/src/Core/RandomNumberGenerator.h
index 8f440630..333a8e36 100644
--- a/src/Core/RandomNumberGenerator.h
+++ b/src/Core/RandomNumberGenerator.h
@@ -55,7 +55,6 @@ namespace VeraCrypt
static bool Running;
static size_t WriteOffset;
static struct rand_data *JitterRngCtx;
- static bool DevRandomSucceeded;
static int DevRandomBytesCount;
};
}