VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Core
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2019-10-23 22:30:44 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2019-10-23 22:46:25 +0200
commit478066c6076934ef50f9cf922cfe55dd96580d12 (patch)
tree7acafc304087150dc2faf4746f826ae13ea5115d /src/Core
parent74e14c070fb5bebe5258dde72e879fe7be1e43cf (diff)
downloadVeraCrypt-478066c6076934ef50f9cf922cfe55dd96580d12.tar.gz
VeraCrypt-478066c6076934ef50f9cf922cfe55dd96580d12.zip
Linux/MacOSX: Add missing JitterEntropy implementation
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/RandomNumberGenerator.cpp23
-rw-r--r--src/Core/RandomNumberGenerator.h2
2 files changed, 25 insertions, 0 deletions
diff --git a/src/Core/RandomNumberGenerator.cpp b/src/Core/RandomNumberGenerator.cpp
index fffd948a..70c46492 100644
--- a/src/Core/RandomNumberGenerator.cpp
+++ b/src/Core/RandomNumberGenerator.cpp
@@ -46,6 +46,16 @@ namespace VeraCrypt
throw_sys_sub_if (read (random, buffer, buffer.Size()) == -1 && errno != EAGAIN, L"/dev/random");
AddToPool (buffer);
+
+ /* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
+ if (JitterRngCtx)
+ {
+ ssize_t rndLen = jent_read_entropy (JitterRngCtx, (char*) buffer.Ptr(), buffer.Size());
+ if (rndLen > 0)
+ {
+ AddToPool (buffer);
+ }
+ }
}
#endif
}
@@ -80,6 +90,12 @@ namespace VeraCrypt
ScopeLock lock (AccessMutex);
size_t bufferLen = buffer.Size(), loopLen;
byte* pbBuffer = buffer.Get();
+
+ // Initialize JitterEntropy RNG for this call
+ if (0 == jent_entropy_init ())
+ {
+ JitterRngCtx = jent_entropy_collector_alloc (1, 0);
+ }
// Poll system for data
AddSystemDataToPool (fast);
@@ -127,6 +143,12 @@ namespace VeraCrypt
pbBuffer += loopLen;
}
+
+ if (JitterRngCtx)
+ {
+ jent_entropy_collector_free (JitterRngCtx);
+ JitterRngCtx = NULL;
+ }
}
shared_ptr <Hash> RandomNumberGenerator::GetHash ()
@@ -232,4 +254,5 @@ namespace VeraCrypt
size_t RandomNumberGenerator::ReadOffset;
bool RandomNumberGenerator::Running = false;
size_t RandomNumberGenerator::WriteOffset;
+ struct rand_data *RandomNumberGenerator::JitterRngCtx = NULL;
}
diff --git a/src/Core/RandomNumberGenerator.h b/src/Core/RandomNumberGenerator.h
index 2d1d314a..6df31ae0 100644
--- a/src/Core/RandomNumberGenerator.h
+++ b/src/Core/RandomNumberGenerator.h
@@ -16,6 +16,7 @@
#include "Platform/Platform.h"
#include "Volume/Hash.h"
#include "Common/Random.h"
+#include "Crypto/jitterentropy.h"
namespace VeraCrypt
{
@@ -53,6 +54,7 @@ namespace VeraCrypt
static size_t ReadOffset;
static bool Running;
static size_t WriteOffset;
+ static struct rand_data *JitterRngCtx;
};
}