1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 19:08:26 -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:
Mounir IDRASSI
2014-12-10 19:24:39 +01:00
parent e673006969
commit c8c8cc517d
8 changed files with 991 additions and 36 deletions

View File

@@ -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;
}
}