Hashing _Generic Hashing (Blake2b) - Chewhern/ASodium GitHub Wiki

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)

Single message hashing

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);

Multi messages hashing

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);