I was just reviewing the source-code of the NBitcoin-package. As far as i can see when you create a new bitcoin-keypair
Key privateKey = new Key();
(without passing some random data to be used as private key generated by yourself) then the library generates a private key using a random-number-generator for you. Very usual. But then i stumbled across the fact that the output of the random-number-generator will not directly be used as private key: NBitcoin also applies a PushEntropy-function on this byte-array:
private static void PushEntropy(byte[] data)
{
if (!UseAdditionalEntropy || additionalEntropy == null || data.Length == 0)
return;
int pos = entropyIndex;
var entropy = additionalEntropy;
for (int i = 0; i < data.Length; i++)
{
data[i] ^= entropy[pos % 32];
pos++;
}
entropy = Hashes.SHA256(data);
for (int i = 0; i < data.Length; i++)
{
data[i] ^= entropy[pos % 32];
pos++;
}
entropyIndex = pos % 32;
}
I understand what this function does, but I do not understand why we need this function to generate a private-key.
Why is a cryptographically secure random-number-generator (to generate the private key aka data
-bytearray) not enough?
Does this function increase security in any kind?