(Answer) (Category) Crypto++ Faq-O-Matic :
How do I use a message authentication code?
Moderator: weidai (inherited from parent)
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);

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

2008-Jul-01 4:46pm weidai
[Append to This Answer]
2008-Jul-01 4:46pm
Previous: (Answer) How do I use a hash function?
Next: (Answer) How do I use a random number generator?
This document is: http://www.cryptopp.com/cgi-bin/fom.cgi?file=82
[Search] [Appearance] [Show Expert Edit Commands]
This is a Faq-O-Matic 2.721.
This FAQ is administered by Wei Dai.