-
Notifications
You must be signed in to change notification settings - Fork 4
/
MeowHashAlgorithm.cs
58 lines (50 loc) · 1.47 KB
/
MeowHashAlgorithm.cs
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
using System;
using System.Runtime.Intrinsics.X86;
using System.Security.Cryptography;
namespace Meow
{
public sealed class MeowHashAlgorithm : HashAlgorithm
{
private MeowHash.State m_state = new MeowHash.State();
private byte[] m_seed = MeowHash.MeowDefaultSeed;
public MeowHashAlgorithm()
{
HashSizeValue = 128;
State = -1;
}
public byte[] Seed
{
get { return m_seed; }
set
{
if (value != null && value.Length != 128)
{
throw new Exception("Seed must be 128 bytes.");
}
m_seed = value ?? MeowHash.MeowDefaultSeed;
}
}
public override void Initialize()
{
MeowHash.Begin(ref m_state, m_seed);
}
protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
HashCore(array.AsSpan().Slice(ibStart, cbSize));
}
protected override void HashCore(ReadOnlySpan<byte> source)
{
MeowHash.Absorb(ref m_state, source);
}
protected unsafe override byte[] HashFinal()
{
var result = MeowHash.End(ref m_state, null);
HashValue = new byte[16];
fixed (byte* outputPtr = HashValue)
{
Sse2.Store(outputPtr, result);
}
return HashValue;
}
}
}