|
QuickHash Library |
C++ Interface |
|
CHMAC::Calculate
static void Calculate( unsigned char*
pDest, const unsigned char* pSrc, unsigned int
nSrcLength, const unsigned char* pKey, unsigned int
nKeyLength = DEFAULTKEYLEN );
static void Calculate( unsigned char*
pDest, const char* pSrc, const char* pKey );
Parameters
pDest
[out] Pointer to the memory
buffer that will receive the HMAC.
pSrc
[in]
In the first case - pointer to the
continuous memory block for which to calculate the HMAC.
In the second case - pointer to the
null-terminated string for which to calculate the HMAC.
nSrcLength
[in] Length in bytes
of the memory block.
pKey
[in]
In the first case - pointer to the
continuous memory block used as the key.
In the second case - pointer to the
null-terminated string used as the key.
nKeyLength
[in] Length in bytes
of the key.
Remarks
-
static void Calculate( unsigned char*
pDest, const unsigned char* pSrc, unsigned int
nSrcLength, const unsigned char* pKey, unsigned int
nKeyLength = DEFAULTKEYLEN );
Calculates the HMAC for the memory block
pointed by pSrc using the key using the key which is a memory block pointed by pKey.
Calculates the HMAC for the null-terminated string
pointed by pSrc using the key which is a null-terminated string pointed by pKey.
The HMAC is retrieved in the memory buffer pointed by
pDest. The size of the memory buffer pointed by pDest
must be at least CHMAC<T>::DIGESTSIZE bytes.
For example, the size of the memory buffer pointed by pDest
must be at least CHMAC<CMD5>::DIGESTSIZE bytes, if the HMAC is
calculated using the MD5 hash algorithm.
Example
#include <string.h>
#include <QuickHash.h>
using namespace QuickHash;
int main()
{
char mydata[] = "Test String";
char key[] = "Test Password";
unsigned char hmac[ CHMAC<CMD5>::DIGESTSIZE ];
//Calculate the HMAC using MD5 algorithm
CHMAC<CMD5>::Calculate( hmac, (const unsigned char*)mydata, strlen( mydata ),
(const unsigned char*)key, strlen( key ) );
//Use the HMAC
//...
return 0;
}
|
|
Note.
In the above example mydata and key
are null-terminated strings. Therefore, the call
CHMAC<CMD5>::Calculate( hmac, (const unsigned char*)mydata, strlen( mydata ), (const unsigned char*)key, strlen( key ) );
can be replaced by
CHMAC<CMD5>::Calculate( hmac, mydata,
key );
CHMAC Overview
| Class Members
|
Useful Links | HashCalc
See Also
CHMAC::CalculateHex
|