Advanced _HMAC SHA2(256 & 512) - Chewhern/ASodium GitHub Wiki

For detailed documentation, kindly refer to official libsodium.

I don't really know that is there really a need to include multiple message MAC computation for HMAC as I don't think that HMAC will be used in computing actual MAC as people nowadays I believe will be using Poly1305 or SHAKE or Keccak to compute advanced MAC.

There's one more uncovered function which is HMAC-SHA512256, kindly refer to the link before for more information.

(https://github.com/Chewhern/ASodium/blob/main/Source/SodiumHMACSHA512256.cs)

HMAC-SHA256

Single part message

Initial Functions

public static Byte[] ComputeMAC(Byte[] Message,Byte[] Key,Boolean ClearKey=false)
public static Boolean VerifyMAC(Byte[] MAC,Byte[] Message, Byte[] Key,Boolean ClearKey=false)

Example Code

Byte[] Key = SodiumHMACSHA256.GenerateKey();
Byte[] RandomMessage = SodiumRNG.GetRandomBytes(22);
Byte[] ComputedHMAC = SodiumHMACSHA256.ComputeMAC(RandomMessage, Key);
Boolean VerifyHMAC = SodiumHMACSHA256.VerifyMAC(ComputedHMAC, RandomMessage, Key);
MessageBox.Show(VerifyHMAC.ToString());

HMAC-SHA512

Single part message

Initial Functions

public static Byte[] ComputeMAC(Byte[] Message,Byte[] Key,Boolean ClearKey=false)
public static Boolean VerifyMAC(Byte[] MAC,Byte[] Message, Byte[] Key,Boolean ClearKey=false)

Example Code

Byte[] Key = SodiumHMACSHA512.GenerateKey();
Byte[] RandomMessage = SodiumRNG.GetRandomBytes(22);
Byte[] ComputedHMAC = SodiumHMACSHA512.ComputeMAC(RandomMessage, Key);
Boolean VerifyHMAC = SodiumHMACSHA512.VerifyMAC(ComputedHMAC, RandomMessage, Key);
MessageBox.Show(VerifyHMAC.ToString());