I am writing code that needs to produce a truly random number of 96 bits. The requirements are:
- The code must be able to produce all $2^{96}$ values.
- The likelihood for any value to come up must be the same for all values.
- It must be impossible to predict the next $96$-bit number that will come up.
So, using RNGCryptoServiceProvider
, I have the following implementation:
Public Function GetRandom96BitNumber() As BigInteger
Dim random96BitNumber As BigInteger
'We need 12 bytes, but take 13 in order to ensure a positive number.
Dim bytesFor96BitNumber(12) As Byte
Dim cryptoProvider = New RNGCryptoServiceProvider
cryptoProvider.GetBytes(bytesFor96BitNumber)
'Set the thirteenth byte to zero to ensure that we get a positive BigInteger.
bytesFor96BitNumber(12) = 0
random96BitNumber = New BigInteger(bytesFor96BitNumber)
Return random96BitNumber
End Function
Question:
This code (assuming it employs the RNGCryptoServiceProvider
correctly) is only as good as the quality of randomness of the RNGCryptoServiceProvider
. How can I convince myself and my clients that the three criteria stated above are met? I found this document that compares cryptographic random number generation between Windows and Linux and I think I read there that the entropy used to seed the RNGCryptoServiceProvider
is at least 256 bits.
Does this mean that the three requirements stated above are met? If yes: why? If not: why not?
Any further guidance for getting enlightenment are very much appreciated.