Variable 16Bit to 512Bit Hashing Algorithm
using System;
using System.Security.Cryptography;
[Serializable]
public class Sha16512 : HashAlgorithm
{
private int _bitWidth;
private SHA512Managed _hash = new SHA512Managed();
public Sha16512(int bitWidth)
{
if (bitWidth < 16 || bitWidth > 512)
throw new ArgumentException($"Bit Width {bitWidth} must be between 16 and 512.");
_bitWidth = bitWidth;
}
public override int HashSize => _bitWidth;
public override void Initialize()
{
}
protected override void HashCore(byte[] bytes, int ibStart, int cbSize)
{
var buf = bytes.SubByte(ibStart, cbSize);
HashValue = _hash.ComputeHash(buf).SubByte(0, _bitWidth >> 3);
}
protected override byte[] HashFinal()
{
return (byte[]) HashValue.Clone();
}
}