VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2023-05-27 17:24:11 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2023-05-27 17:24:11 +0200
commit7ae63335ac1a6179807a73f4794b7f279c05e85c (patch)
tree19293fbf2f3e9e1cc85ff0d9bb9f9881417b195f
parentf4b310b23f276744a1616137810c2135c7d5f736 (diff)
downloadVeraCrypt-7ae63335ac1a6179807a73f4794b7f279c05e85c.tar.gz
VeraCrypt-7ae63335ac1a6179807a73f4794b7f279c05e85c.zip
Linux/macOS: Make RNG implementation match documentation and the Windows implementation
-rw-r--r--src/Core/RandomNumberGenerator.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/Core/RandomNumberGenerator.cpp b/src/Core/RandomNumberGenerator.cpp
index 2473ef2f..4451348e 100644
--- a/src/Core/RandomNumberGenerator.cpp
+++ b/src/Core/RandomNumberGenerator.cpp
@@ -187,19 +187,26 @@ namespace VeraCrypt
void RandomNumberGenerator::HashMixPool ()
{
BytesAddedSincePoolHashMix = 0;
-
- for (size_t poolPos = 0; poolPos < Pool.Size(); )
+ 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 < poolSize; poolPos += digestSize)
{
// Compute the message digest of the entire pool using the selected hash function
- SecureBuffer digest (PoolHash->GetDigestSize());
+ SecureBuffer digest (digestSize);
PoolHash->Init();
PoolHash->ProcessData (Pool);
PoolHash->GetDigest (digest);
- // Add the message digest to the pool
- for (size_t digestPos = 0; digestPos < digest.Size() && poolPos < Pool.Size(); ++digestPos)
+ /* XOR the resultant message digest to the pool at the poolIndex position. */
+ /* 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);
}
- if (Crc32::ProcessBuffer (Pool) != 0x21CED8B7)
+ if (Crc32::ProcessBuffer (Pool) != 0x9c743238)
throw TestFailed (SRC_POS);
buffer.Allocate (PoolSize);
buffer.CopyFrom (PeekPool());
AddToPool (buffer);
- if (Crc32::ProcessBuffer (Pool) != 0xDCFD0A83)
+ if (Crc32::ProcessBuffer (Pool) != 0xd2d09c8d)
throw TestFailed (SRC_POS);
PoolHash = origPoolHash;