User-supplied entropy (a.k.a. a "seed") is added as "additional input" to the generation process. It does not affect the accumulation pools and cannot be used by an attacker to control the output.
Remember it's not how "random" your user-supplied entropy is, but how little an
attacker knows about it. Using the current time is no use. If you can provide
32 bytes* of data of which an attacker knows nothing and cannot later discover,
then you have added 128 bits of security strength.
* The bytes must have been selected randomly from the range 0 to 255.
Here is an example in VB6 of how you could use the RNG to generate user-supplied entropy when creating a new pair of RSA keys. (The password should be entered separately, not hard-coded like this!)
Dim nRet As Long Dim nBits As Long Dim strPublicKeyFile As String Dim strPrivateKeyFile As String Dim strPassword As String Dim strSeed As String nBits = 512 strPublicKeyFile = "mykeypub.bin" strPrivateKeyFile = "mykeypri.bin" strPassword = "password" ' 1. Generate some user-derived entropy using the keyboard strSeed = String(64, " ") nRet = RNG_StringWithPrompt(strSeed, Len(strSeed), "", 0) ' 2. Create a new pair of RSA key files, adding this seed to the process Debug.Print "About to create a new RSA key pair..." nRet = RSA_MakeKeys(strPublicKeyFile, strPrivateKeyFile, nBits, _ PKI_RSAEXP_EQ_65537, 50, 1000, strPassword, strSeed, Len(strSeed), 0) Debug.Print "RSA_MakeKeys returns " & nRet & " (expected 0)" ' 3. Immediately wipe the sensitive data Call WIPE_String(strSeed, Len(strSeed)) Call WIPE_String(strPassword, Len(strPassword))
And the same example in C# (VB.NET is very similar)
int r; byte[] seed; int nbits = 512; string publicKeyFile = @"mykeypub.bin"; string privateKeyFile = @"mykeypri.bin"; StringBuilder sbPassword = new StringBuilder("password"); // 1. Generate some user-derived entropy using the keyboard seed = Rng.BytesWithPrompt(64,"",Rng.Strength.Default); Debug.Assert(seed.Length > 0, "Failed to create a seed"); // 2. Create a new pair of RSA key files, adding this seed to the process r = Rsa.MakeKeys(publicKeyFile, privateKeyFile, nbits, Rsa.PublicExponent.Exp_EQ_65537, 1000, sbPassword.ToString(), Rsa.PbeOptions.Default, false, seed); Console.WriteLine("Rsa.MakeKeys returns {0} (expected 0)", r); // 3. Immediately wipe the sensitive data Wipe.Data(seed); Wipe.String(sbPassword);
For more details on the security aspects of the random number generator, see the technical details published on our web site.