mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Linux/MacOSX: Implement generating more than one keyfile, specifying the size of the generated keyfiles and letting VeraCrypt choose random size values.
This commit is contained in:
@@ -65,45 +65,63 @@ namespace VeraCrypt
|
||||
}
|
||||
}
|
||||
|
||||
void RandomNumberGenerator::GetData (const BufferPtr &buffer, bool fast)
|
||||
void RandomNumberGenerator::GetData (const BufferPtr &buffer, bool fast, bool allowAnyLength)
|
||||
{
|
||||
if (!Running)
|
||||
throw NotInitialized (SRC_POS);
|
||||
|
||||
if (buffer.Size() > PoolSize)
|
||||
if (!allowAnyLength && (buffer.Size() > PoolSize))
|
||||
throw ParameterIncorrect (SRC_POS);
|
||||
|
||||
ScopeLock lock (AccessMutex);
|
||||
size_t bufferLen = buffer.Size(), loopLen;
|
||||
byte* pbBuffer = buffer.Get();
|
||||
|
||||
// Poll system for data
|
||||
AddSystemDataToPool (fast);
|
||||
HashMixPool();
|
||||
|
||||
// Transfer bytes from pool to output buffer
|
||||
for (size_t i = 0; i < buffer.Size(); ++i)
|
||||
while (bufferLen > 0)
|
||||
{
|
||||
buffer[i] += Pool[ReadOffset++];
|
||||
if (bufferLen > PoolSize)
|
||||
{
|
||||
loopLen = PoolSize;
|
||||
bufferLen -= PoolSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
loopLen = bufferLen;
|
||||
bufferLen = 0;
|
||||
}
|
||||
|
||||
if (ReadOffset >= PoolSize)
|
||||
ReadOffset = 0;
|
||||
}
|
||||
// Transfer bytes from pool to output buffer
|
||||
for (size_t i = 0; i < loopLen; ++i)
|
||||
{
|
||||
pbBuffer[i] += Pool[ReadOffset++];
|
||||
|
||||
// Invert and mix the pool
|
||||
for (size_t i = 0; i < Pool.Size(); ++i)
|
||||
{
|
||||
Pool[i] = ~Pool[i];
|
||||
}
|
||||
if (ReadOffset >= PoolSize)
|
||||
ReadOffset = 0;
|
||||
}
|
||||
|
||||
AddSystemDataToPool (true);
|
||||
HashMixPool();
|
||||
// Invert and mix the pool
|
||||
for (size_t i = 0; i < Pool.Size(); ++i)
|
||||
{
|
||||
Pool[i] = ~Pool[i];
|
||||
}
|
||||
|
||||
// XOR the current pool content into the output buffer to prevent pool state leaks
|
||||
for (size_t i = 0; i < buffer.Size(); ++i)
|
||||
{
|
||||
buffer[i] ^= Pool[ReadOffset++];
|
||||
AddSystemDataToPool (true);
|
||||
HashMixPool();
|
||||
|
||||
if (ReadOffset >= PoolSize)
|
||||
ReadOffset = 0;
|
||||
// XOR the current pool content into the output buffer to prevent pool state leaks
|
||||
for (size_t i = 0; i < loopLen; ++i)
|
||||
{
|
||||
pbBuffer[i] ^= Pool[ReadOffset++];
|
||||
|
||||
if (ReadOffset >= PoolSize)
|
||||
ReadOffset = 0;
|
||||
}
|
||||
|
||||
pbBuffer += loopLen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace VeraCrypt
|
||||
{
|
||||
public:
|
||||
static void AddToPool (const ConstBufferPtr &buffer);
|
||||
static void GetData (const BufferPtr &buffer) { GetData (buffer, false); }
|
||||
static void GetDataFast (const BufferPtr &buffer) { GetData (buffer, true); }
|
||||
static void GetData (const BufferPtr &buffer, bool allowAnyLength = false) { GetData (buffer, false, allowAnyLength); }
|
||||
static void GetDataFast (const BufferPtr &buffer, bool allowAnyLength = false) { GetData (buffer, true, allowAnyLength); }
|
||||
static shared_ptr <Hash> GetHash ();
|
||||
static bool IsEnrichedByUser () { return EnrichedByUser; }
|
||||
static bool IsRunning () { return Running; }
|
||||
@@ -34,7 +34,7 @@ namespace VeraCrypt
|
||||
|
||||
protected:
|
||||
static void AddSystemDataToPool (bool fast);
|
||||
static void GetData (const BufferPtr &buffer, bool fast);
|
||||
static void GetData (const BufferPtr &buffer, bool fast, bool allowAnyLength);
|
||||
static void HashMixPool ();
|
||||
static void Test ();
|
||||
RandomNumberGenerator ();
|
||||
|
||||
Reference in New Issue
Block a user