INNER CODE UNIT · C#
testBuffer
sdrapkin/SecurityDriven.Inferno · CryptoRandom.cs:35
var testBuffer = new byte[BYTE_CACHE_SIZE / 2];
int status, i, j;
const int COLLISION_FREE_BLOCK_SIZE = 16;
status = (int)BCrypt.BCryptGenRandom(testBuffer, testBuffer.Length);
if (status != (int)BCrypt.NTSTATUS.STATUS_SUCCESS) ThrowNewCryptographicException(status);
if (testBuffer.Length < COLLISION_FREE_BLOCK_SIZE * 2) return; // should be compiled away
for (i = 0; i < testBuffer.Length - COLLISION_FREE_BLOCK_SIZE; i += COLLISION_FREE_BLOCK_SIZE)
{
for (j = 0, status = 0; j < COLLISION_FREE_BLOCK_SIZE; ++j)
status |= testBuffer[i + j] ^ testBuffer[i + j + COLLISION_FREE_BLOCK_SIZE];
if (status == 0) ThrowNewCryptographicException("CryptoRandom failed sanity check #2.");
}
}// SanityCheck()
/// <summary>Returns a random number between 0.0 and 1.0.</summary>
protected override double Sample() => NextDouble();