forked from PeterWaher/IoTGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSHA3_512_Tests.cs
More file actions
76 lines (64 loc) · 2.53 KB
/
SHA3_512_Tests.cs
File metadata and controls
76 lines (64 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Waher.Security.SHA3.Test
{
[TestClass]
public partial class SHA3_512_Tests
{
[TestMethod]
public void Test_01_0_bits()
{
SHA3_512 H = new SHA3_512();
int i = 0;
H.NewState += (sender, e) =>
{
string Expected = States0Bits[i++].Replace(" ", string.Empty);
string Actual = Hashes.BinaryToString(H.GetState()).ToUpper();
Assert.AreEqual(Expected, Actual);
};
byte[] Digest = H.ComputeVariable(new byte[0]);
string s = Hashes.BinaryToString(Digest);
Assert.AreEqual("a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26", s);
Assert.AreEqual(States0Bits.Length, i);
}
[TestMethod]
public void Test_02_1600_bits()
{
SHA3_512 H = new SHA3_512();
int i = 0;
H.NewState += (sender, e) =>
{
string Expected = States1600Bits[i++].Replace(" ", string.Empty);
string Actual = Hashes.BinaryToString(H.GetState()).ToUpper();
Assert.AreEqual(Expected, Actual);
};
byte[] Input = new byte[200];
int j;
for (j = 0; j < 200; j++)
Input[j] = 0xa3;
byte[] Digest = H.ComputeVariable(Input);
string s = Hashes.BinaryToString(Digest);
Assert.AreEqual("e76dfad22084a8b1467fcf2ffa58361bec7628edf5f3fdc0e4805dc48caeeca81b7c13c30adf52a3659584739a2df46be589c51ca1a4a8416df6545a1ce8ba00", s);
Assert.AreEqual(States1600Bits.Length, i);
}
[TestMethod]
public void Test_03_1600_bits_Stream()
{
SHA3_512 H = new SHA3_512();
byte[] Input = new byte[200];
int j;
for (j = 0; j < 200; j++)
Input[j] = 0xa3;
byte[] Digest = H.ComputeVariable(new MemoryStream(Input));
string s = Hashes.BinaryToString(Digest);
Assert.AreEqual("e76dfad22084a8b1467fcf2ffa58361bec7628edf5f3fdc0e4805dc48caeeca81b7c13c30adf52a3659584739a2df46be589c51ca1a4a8416df6545a1ce8ba00", s);
}
[TestMethod]
public void Test_04_Performance()
{
byte[] Data = new byte[80 * 1024 * 1024];
SHA3_512 H = new SHA3_512();
H.ComputeVariable(Data);
}
}
}