Created
January 12, 2021 14:21
-
-
Save mjs3339/2698070579cd0ec14c53930a92d320b8 to your computer and use it in GitHub Desktop.
Modified Sha3
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; | |
[Serializable] | |
public class SHA3ModInt : HashAlgorithmEx | |
{ | |
private readonly KeccakSpongeManaged _sponge; | |
public SHA3ModInt(int size, int rounds = 24, ulong[] seed = null) | |
{ | |
if (rounds > 24) | |
throw new Exception($"Maximum rounds allowed is {24}"); | |
var MaxBR = (64 >> 3) * 25; | |
var sizeBytes = size >> 3; | |
var rateBytes = MaxBR - (sizeBytes << 1); | |
var MaxSize = ((MaxBR - 8) >> 1) << 3; | |
if (rateBytes < 8) | |
throw new Exception($"Maximum size allowed is {MaxSize} Bits with {64} bit Width specified. Specified Size is {size} Bits."); | |
var outputLength = size >> 3; | |
_sponge = new KeccakSpongeManaged(rateBytes, 200 - rateBytes, KeccakSpongeManaged.KeccakDelimiter, outputLength, seed); | |
_sponge.Rounds = rounds; | |
HashSizeValue = size; | |
} | |
public override void Initialize() | |
{ | |
_sponge.Initialize(); | |
} | |
protected override void HashCore(byte[] array, int ibStart, int cbSize) | |
{ | |
Initialize(); | |
_sponge.Absorb(array, ibStart, cbSize); | |
} | |
protected override byte[] HashFinal() | |
{ | |
return _sponge.Squeeze(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment