Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RandomNumberGeneratorImplementation.cs
Go to the documentation of this file.
2
4{
6
10
11 internal unsafe static void FillSpan(Span<byte> data)
12 {
13 if (data.Length > 0)
14 {
15 fixed (byte* pbBuffer = data)
16 {
17 GetBytes(pbBuffer, data.Length);
18 }
19 }
20 }
21
22 public override void GetBytes(byte[] data)
23 {
24 if (data == null)
25 {
26 throw new ArgumentNullException("data");
27 }
28 GetBytes(new Span<byte>(data));
29 }
30
31 public override void GetBytes(byte[] data, int offset, int count)
32 {
34 GetBytes(new Span<byte>(data, offset, count));
35 }
36
37 public unsafe override void GetBytes(Span<byte> data)
38 {
39 if (data.Length > 0)
40 {
41 fixed (byte* pbBuffer = data)
42 {
43 GetBytes(pbBuffer, data.Length);
44 }
45 }
46 }
47
48 public override void GetNonZeroBytes(byte[] data)
49 {
50 if (data == null)
51 {
52 throw new ArgumentNullException("data");
53 }
54 GetNonZeroBytes(new Span<byte>(data));
55 }
56
57 public override void GetNonZeroBytes(Span<byte> data)
58 {
59 while (data.Length > 0)
60 {
61 GetBytes(data);
62 int num = data.Length;
63 for (int i = 0; i < data.Length; i++)
64 {
65 if (data[i] == 0)
66 {
67 num = i;
68 break;
69 }
70 }
71 for (int j = num + 1; j < data.Length; j++)
72 {
73 if (data[j] != 0)
74 {
75 data[num++] = data[j];
76 }
77 }
78 data = data.Slice(num);
79 }
80 }
81
82 private unsafe static void GetBytes(byte* pbBuffer, int count)
83 {
84 global::Interop.BCrypt.NTSTATUS nTSTATUS = global::Interop.BCrypt.BCryptGenRandom(IntPtr.Zero, pbBuffer, count, 2);
85 if (nTSTATUS != 0)
86 {
87 throw global::Interop.BCrypt.CreateCryptographicException(nTSTATUS);
88 }
89 }
90}
void VerifyGetBytes(byte[] data, int offset, int count)
static readonly IntPtr Zero
Definition IntPtr.cs:18
Span< T > Slice(int start)
Definition Span.cs:271
int Length
Definition Span.cs:70