/// <summary> /// Creates a new and initialized instance of the TripleSec RNG (no parameters). /// </summary> public RNGV4() { // sure, the .NET RNG is pretty good, but lets make an attacker's life miserable // and also guard against a compromised RNG SSC.RNGCryptoServiceProvider rng = new SSC.RNGCryptoServiceProvider(); byte[] tempKey = new byte[512]; byte[] tempSalt = new byte[512]; rng.GetBytes(tempKey); rng.GetBytes(tempSalt); byte[] interim = new SSC.Rfc2898DeriveBytes(tempKey, tempSalt, 64).GetBytes(1024); rng.GetBytes(tempSalt); byte[] final = new SSC.Rfc2898DeriveBytes(interim, tempSalt, 64).GetBytes(56); tempKey.Wipe(); tempSalt.Wipe(); interim.Wipe(); // DON'T LEAK!! _salt = new byte[16]; _aesIV = new byte[16]; _xsalsa20IV = new byte[24]; Buffer.BlockCopy(final, 0, _salt, 0, _salt.Length); Buffer.BlockCopy(final, 16, _aesIV, 0, _aesIV.Length); Buffer.BlockCopy(final, 16 + 16, _xsalsa20IV, 0, _xsalsa20IV.Length); _ready = true; //#if DEBUG // System.Diagnostics.Debug.Print("RNGV4:-------------------------------------"); // System.Diagnostics.Debug.Print("salt: " + BitConverter.ToString(_salt).Replace("-", "").ToLowerInvariant()); // System.Diagnostics.Debug.Print("aesIV: " + BitConverter.ToString(_salt).Replace("-", "").ToLowerInvariant()); // System.Diagnostics.Debug.Print("xsalsa20IV: " + BitConverter.ToString(_salt).Replace("-", "").ToLowerInvariant()); // System.Diagnostics.Debug.Print("final array: " + BitConverter.ToString(final).Replace("-", "").ToLowerInvariant()); //#endif final.Wipe(); // DON'T LEAVE COPIES LAYING AROUND! }