Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Sha1ForNonSecretPurposes.cs
Go to the documentation of this file.
2
3namespace System;
4
6{
7 private long _length;
8
9 private uint[] _w;
10
11 private int _pos;
12
13 public void Start()
14 {
15 if (_w == null)
16 {
17 _w = new uint[85];
18 }
19 _length = 0L;
20 _pos = 0;
21 _w[80] = 1732584193u;
22 _w[81] = 4023233417u;
23 _w[82] = 2562383102u;
24 _w[83] = 271733878u;
25 _w[84] = 3285377520u;
26 }
27
28 public void Append(byte input)
29 {
30 int num = _pos >> 2;
31 _w[num] = (_w[num] << 8) | input;
32 if (64 == ++_pos)
33 {
34 Drain();
35 }
36 }
37
39 {
40 ReadOnlySpan<byte> readOnlySpan = input;
41 for (int i = 0; i < readOnlySpan.Length; i++)
42 {
43 byte input2 = readOnlySpan[i];
44 Append(input2);
45 }
46 }
47
48 public void Finish(Span<byte> output)
49 {
50 long num = _length + 8 * _pos;
51 Append(128);
52 while (_pos != 56)
53 {
54 Append(0);
55 }
56 Append((byte)(num >> 56));
57 Append((byte)(num >> 48));
58 Append((byte)(num >> 40));
59 Append((byte)(num >> 32));
60 Append((byte)(num >> 24));
61 Append((byte)(num >> 16));
62 Append((byte)(num >> 8));
63 Append((byte)num);
64 int num2 = ((output.Length < 20) ? output.Length : 20);
65 for (int i = 0; i != num2; i++)
66 {
67 uint num3 = _w[80 + i / 4];
68 output[i] = (byte)(num3 >> 24);
69 _w[80 + i / 4] = num3 << 8;
70 }
71 }
72
73 private void Drain()
74 {
75 for (int i = 16; i != 80; i++)
76 {
77 _w[i] = BitOperations.RotateLeft(_w[i - 3] ^ _w[i - 8] ^ _w[i - 14] ^ _w[i - 16], 1);
78 }
79 uint num = _w[80];
80 uint num2 = _w[81];
81 uint num3 = _w[82];
82 uint num4 = _w[83];
83 uint num5 = _w[84];
84 for (int j = 0; j != 20; j++)
85 {
86 uint num6 = (num2 & num3) | (~num2 & num4);
87 uint num7 = BitOperations.RotateLeft(num, 5) + num6 + num5 + 1518500249 + _w[j];
88 num5 = num4;
89 num4 = num3;
90 num3 = BitOperations.RotateLeft(num2, 30);
91 num2 = num;
92 num = num7;
93 }
94 for (int k = 20; k != 40; k++)
95 {
96 uint num8 = num2 ^ num3 ^ num4;
97 uint num9 = BitOperations.RotateLeft(num, 5) + num8 + num5 + 1859775393 + _w[k];
98 num5 = num4;
99 num4 = num3;
100 num3 = BitOperations.RotateLeft(num2, 30);
101 num2 = num;
102 num = num9;
103 }
104 for (int l = 40; l != 60; l++)
105 {
106 uint num10 = (num2 & num3) | (num2 & num4) | (num3 & num4);
107 uint num11 = (uint)((int)(BitOperations.RotateLeft(num, 5) + num10 + num5) + -1894007588) + _w[l];
108 num5 = num4;
109 num4 = num3;
110 num3 = BitOperations.RotateLeft(num2, 30);
111 num2 = num;
112 num = num11;
113 }
114 for (int m = 60; m != 80; m++)
115 {
116 uint num12 = num2 ^ num3 ^ num4;
117 uint num13 = (uint)((int)(BitOperations.RotateLeft(num, 5) + num12 + num5) + -899497514) + _w[m];
118 num5 = num4;
119 num4 = num3;
120 num3 = BitOperations.RotateLeft(num2, 30);
121 num2 = num;
122 num = num13;
123 }
124 _w[80] += num;
125 _w[81] += num2;
126 _w[82] += num3;
127 _w[83] += num4;
128 _w[84] += num5;
129 _length += 512L;
130 _pos = 0;
131 }
132}
static uint RotateLeft(uint value, int offset)
void Append(ReadOnlySpan< byte > input)
int Length
Definition Span.cs:70