Advanced _One time authentication (Poly1305) - Chewhern/ASodium GitHub Wiki

For detailed documentation, kindly refer to official libsodium.

Single Message's MAC computation and verification

Initial Functions

public static Byte[] ComputePoly1305MAC(Byte[] Message,Byte[] Key,Boolean ClearKey=false)
public static Boolean VerifyPoly1305MAC(Byte[] Poly1305MAC, Byte[] Message, Byte[] Key,Boolean ClearKey=false) 

Example Code

Byte[] Key = SodiumOneTimeAuth.GenerateKey();
Byte[] RandomMessage = SodiumRNG.GetRandomBytes(128);
Byte[] MAC = SodiumOneTimeAuth.ComputePoly1305MAC(RandomMessage, Key);
Boolean Verified = SodiumOneTimeAuth.VerifyPoly1305MAC(MAC, RandomMessage, Key);
MessageBox.Show(Verified.ToString());

Multiple messages MAC computation and verification

Initial Functions

public static Byte[] InitializeState(Byte[] Key,Boolean ClearKey=false)
public static Byte[] UpdateState(Byte[] OldState, Byte[] Message)
public static Byte[] ComputeFinalizedStatePoly1305MAC(Byte[] State)

Example Code

Byte[] Key = SodiumOneTimeAuth.GenerateKey();
Byte[] RandomMessage1 = SodiumRNG.GetRandomBytes(128);
Byte[] RandomMessage2 = SodiumRNG.GetRandomBytes(128);
Byte[] RandomMessage3 = SodiumRNG.GetRandomBytes(128);
Byte[] State = SodiumOneTimeAuth.InitializeState(Key);
State = SodiumOneTimeAuth.UpdateState(State, RandomMessage1);
State = SodiumOneTimeAuth.UpdateState(State, RandomMessage2);
State = SodiumOneTimeAuth.UpdateState(State, RandomMessage3);
Byte[] MAC = SodiumOneTimeAuth.ComputeFinalizedStatePoly1305MAC(State);
//Need to recompute MAC on other side and sees if it matches..