-
Notifications
You must be signed in to change notification settings - Fork 3
Hashing _Generic Hashing (Blake2b)
Chrono edited this page Dec 28, 2022
·
2 revisions
For detail documentation, kindly refer to official libsodium.
The minimum hash result length is unknown but the maximum hash result length is known which is 512 bits or 64 bytes. When using Generic Hashing from libsodium, it's advised to call some functions within the wrapper library to determine the lengths. (https://github.com/Chewhern/ASodium/blob/main/Source/SodiumGenericHash.cs)
Initial Function
public static Byte[] ComputeHash(Byte HashLength,Byte[] Message, Byte[] Key = null,Boolean ClearKey=false)
Example Code
Byte[] RandomMessage = SodiumRNG.GetRandomBytes(128);
Byte[] Hash = SodiumGenericHash.ComputeHash(64, RandomMessage);
//Hash computation has the key parameter which can be null or supplied with an actual key
Byte[] Key = SodiumGenericHash.GenerateStandardKey();
//Byte[] Key = SodiumGenericHash.GenerateMinKey();
//Byte[] Key = SodiumGenericHash.GenerateMaxKey();
Hash = SodiumGenericHash.ComputeHash(64, RandomMessage,Key);
Initial Functions
public static Byte[] InitializeState(Byte[] Key, Byte OutLength,Boolean ClearKey=false)
public static Byte[] UpdateState(Byte[] OldState,Byte[] Message)
public static Byte[] ComputeHashForFinalizedState(Byte[] State,Byte HashLength)
Example Code
Byte[] MessagePart1 = SodiumRNG.GetRandomBytes(128);
Byte[] MessagePart2 = SodiumRNG.GetRandomBytes(128);
Byte[] MessagePart3 = SodiumRNG.GetRandomBytes(128);
Byte[] State = SodiumGenericHash.InitializeState(null, 64);
State = SodiumGenericHash.UpdateState(State, MessagePart1);
State = SodiumGenericHash.UpdateState(State, MessagePart2);
State = SodiumGenericHash.UpdateState(State, MessagePart3);
Byte[] Hash = SodiumGenericHash.ComputeHashForFinalizedState(State, 64);