INNER CODE UNIT · C#

BCRYPT_USE_SYSTEM_PREFERRED_RNG

sdrapkin/SecurityDriven.Inferno · CryptoRandom.cs:408

		const int BCRYPT_USE_SYSTEM_PREFERRED_RNG = 0x00000002; // https://msdn.microsoft.com/en-us/library/windows/desktop/aa375458.aspx

		// https://msdn.microsoft.com/en-ca/library/cc704588.aspx
		internal enum NTSTATUS : uint { STATUS_SUCCESS = 0x0 } // and many other "failure" statuses we have no need to differentiate

		static readonly bool s_isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
		static readonly RandomNumberGenerator s_rng = RandomNumberGenerator.Create();

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static NTSTATUS BCryptGenRandom(byte[] pbBuffer, int cbBuffer)
		{
			Debug.Assert(pbBuffer != null);
			Debug.Assert(cbBuffer >= 0 && cbBuffer <= pbBuffer.Length);

			if (s_isWindows)
				return BCryptGenRandom(default, pbBuffer, cbBuffer, BCRYPT_USE_SYSTEM_PREFERRED_RNG);

			s_rng.GetBytes(pbBuffer, 0, cbBuffer);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…