1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 using System
.Diagnostics
;
8 internal static partial class Interop
10 internal static unsafe void GetRandomBytes(byte* buffer
, int length
)
12 Debug
.Assert(buffer
!= null);
13 Debug
.Assert(length
>= 0);
15 BCrypt
.NTSTATUS status
= BCrypt
.BCryptGenRandom(IntPtr
.Zero
, buffer
, length
, BCrypt
.BCRYPT_USE_SYSTEM_PREFERRED_RNG
);
16 if (status
!= BCrypt
.NTSTATUS
.STATUS_SUCCESS
)
18 if (status
== BCrypt
.NTSTATUS
.STATUS_NO_MEMORY
)
20 throw new OutOfMemoryException();
24 throw new InvalidOperationException();