It's similar to using a hash function, except you have to key the MAC object first:
#include "sha.h" // or "md5.h" for MD5, etc
#include "hmac.h"
.
.
.
// pbOutputBuffer must be HMAC<SHA >::DIGESTSIZE bytes in length
HMAC<SHA >(pbKey, nKeyLen)).CalculateDigest(pbOutputBuffer, pbData, nDataLen);
or, if you have data that's made up of multiple pieces:
HMAC<SHA > mac;
mac.SetKey(pbKey, nKeyLen);
mac.Update(pbData1, nData1Len);
mac.Update(pbData2, nData2Len);
mac.Update(pbData3, nData3Len);
mac.Final(pbOutputBuffer);
2002-Dec-30 1:51pm weidai |
Some MACs, such as VMAC, require an IV for each message. So you need to use SetKeyWithIV() instead of SetKey(). For example:
#include "vmac.h"
#include "aes.h"
VMAC<AES > mac;
mac.SetKeyWithIV(pbKey, nKeyLen, pbIV);
...
// reset IV for next message
mac.Resynchronize(pbIV2);
...
2008-Jul-01 4:46pm weidai |