Created
January 12, 2021 14:07
-
-
Save mjs3339/c773263870a65c85b928d32b80924947 to your computer and use it in GitHub Desktop.
Variable 16Bit to 512Bit Hashing Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment