Linux/macOS: Make RNG implementation match documentation and the Windows implementation
This commit is contained in:
parent
f4b310b23f
commit
7ae63335ac
|
@ -187,19 +187,26 @@ namespace VeraCrypt
|
||||||
void RandomNumberGenerator::HashMixPool ()
|
void RandomNumberGenerator::HashMixPool ()
|
||||||
{
|
{
|
||||||
BytesAddedSincePoolHashMix = 0;
|
BytesAddedSincePoolHashMix = 0;
|
||||||
|
size_t digestSize = PoolHash->GetDigestSize();
|
||||||
|
size_t poolSize = Pool.Size();
|
||||||
|
// pool size must be multiple of digest size
|
||||||
|
// this is always the case with default pool size value (320 bytes)
|
||||||
|
if (poolSize % digestSize)
|
||||||
|
throw AssertionFailed (SRC_POS);
|
||||||
|
|
||||||
for (size_t poolPos = 0; poolPos < Pool.Size(); )
|
for (size_t poolPos = 0; poolPos < poolSize; poolPos += digestSize)
|
||||||
{
|
{
|
||||||
// Compute the message digest of the entire pool using the selected hash function
|
// Compute the message digest of the entire pool using the selected hash function
|
||||||
SecureBuffer digest (PoolHash->GetDigestSize());
|
SecureBuffer digest (digestSize);
|
||||||
PoolHash->Init();
|
PoolHash->Init();
|
||||||
PoolHash->ProcessData (Pool);
|
PoolHash->ProcessData (Pool);
|
||||||
PoolHash->GetDigest (digest);
|
PoolHash->GetDigest (digest);
|
||||||
|
|
||||||
// Add the message digest to the pool
|
/* XOR the resultant message digest to the pool at the poolIndex position. */
|
||||||
for (size_t digestPos = 0; digestPos < digest.Size() && poolPos < Pool.Size(); ++digestPos)
|
/* this matches the documentation: https://veracrypt.fr/en/Random%20Number%20Generator.html */
|
||||||
|
for (size_t digestIndex = 0; digestIndex < digestSize; digestIndex++)
|
||||||
{
|
{
|
||||||
Pool[poolPos++] += digest[digestPos];
|
Pool [poolPos + digestIndex] ^= digest [digestIndex];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,14 +270,14 @@ namespace VeraCrypt
|
||||||
AddToPool (buffer);
|
AddToPool (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Crc32::ProcessBuffer (Pool) != 0x21CED8B7)
|
if (Crc32::ProcessBuffer (Pool) != 0x9c743238)
|
||||||
throw TestFailed (SRC_POS);
|
throw TestFailed (SRC_POS);
|
||||||
|
|
||||||
buffer.Allocate (PoolSize);
|
buffer.Allocate (PoolSize);
|
||||||
buffer.CopyFrom (PeekPool());
|
buffer.CopyFrom (PeekPool());
|
||||||
AddToPool (buffer);
|
AddToPool (buffer);
|
||||||
|
|
||||||
if (Crc32::ProcessBuffer (Pool) != 0xDCFD0A83)
|
if (Crc32::ProcessBuffer (Pool) != 0xd2d09c8d)
|
||||||
throw TestFailed (SRC_POS);
|
throw TestFailed (SRC_POS);
|
||||||
|
|
||||||
PoolHash = origPoolHash;
|
PoolHash = origPoolHash;
|
||||||
|
|
Loading…
Reference in New Issue