|
QuickHash Library |
API |
|
SL_HMAC_CalculateStrHex
int SL_HASHCALL SL_HMAC_CalculateStrHex( unsigned
int nAlgID, void* pDest, const char* pSrc,
const char* pKey, int bUpper );
Return value
Nonzero if calculation is successful, otherwise 0. In particular, this
function returns 0 when nAlgID is invalid.
Parameters
nAlgID
[in] The ID of the hash
algorithm selected for calculations. For example, nAlgID has to be set
to SLC_SHA256_ALGID when you need to calculate the HMAC using
SHA256 hash algorithm.
All supported hash algorithms with
their corresponding IDs are listed in
Table1.
pDest
[out] Pointer to the text
buffer that will receive the HMAC.
pSrc
[in] Pointer to the
null-terminated string for which to calculate the HMAC.
pKey
[in] Pointer to the key
which represents a null-terminated key.
bUpper
[in] Uppercase flag.
If bUpper is 0, the received HMAC represents a lowercase
string, otherwise it represents an uppercase string.
Remarks
Calculates the HMAC for the null-terminated string
pointed by pSrc using the key pointed by pKey. The HMAC is retrieved as a null-terminated hexadecimal
string in the text buffer
pointed by pDest. The size of the text buffer pointed by pDest
must be at least HEXDIGESTSIZE characters.
HEXDIGESTSIZE is a predefined constant that specifies the size of the
hexadecimal string representation of the HMAC for a specific hash algorithm. For
example, you have to allocate at least SLC_SHA256_HEXDIGESTSIZE
characters for the text buffer pointed by pDest if you need to calculate
the HMAC using SHA256 hash algorithm.
All
supported hash algorithms with their corresponding HEXDIGESTSIZEs are listed in Table1.
Table1. Supported
hash algorithms, their IDs and HEXDIGESTSIZEs.
|
Algorithm Name |
Algorithm ID |
Algorithm HEXDIGESTSIZE |
|
MD4 |
SLC_MD4_ALGID |
SLC_MD4_HEXDIGESTSIZE |
|
MD5 |
SLC_MD5_ALGID |
SLC_MD5_HEXDIGESTSIZE |
|
SHA-1 |
SLC_SHA1_ALGID |
SLC_SHA1_HEXDIGESTSIZE |
|
SHA-256 |
SLC_SHA256_ALGID |
SLC_SHA256_HEXDIGESTSIZE |
|
SHA-512 |
SLC_SHA512_ALGID |
SLC_SHA512_HEXDIGESTSIZE |
|
SHA-384 |
SLC_SHA384_ALGID |
SLC_SHA384_HEXDIGESTSIZE |
|
RIPEMD128 |
SLC_RIPEMD128_ALGID |
SLC_RIPEMD128_HEXDIGESTSIZE |
|
RIPEMD160 |
SLC_RIPEMD160_ALGID |
SLC_RIPEMD160_HEXDIGESTSIZE |
|
RIPEMD256 |
SLC_RIPEMD256_ALGID |
SLC_RIPEMD256_HEXDIGESTSIZE |
|
RIPEMD320 |
SLC_RIPEMD320_ALGID |
SLC_RIPEMD320_HEXDIGESTSIZE |
|
PANAMA |
SLC_PANAMA_ALGID |
SLC_PANAMA_HEXDIGESTSIZE |
|
TIGER |
SLC_TIGER_ALGID |
SLC_TIGER_HEXDIGESTSIZE |
Note. The call SL_HMAC_CalculateStrHex(
nAlgID, pDest, pSrc, pKey,
bUpper );
is equivalent to the call
SL_HMAC_CalculateHex(
nAlgID, pDest, pSrc, strlen( pSrc
), pKey, strlen( pKey ), bUpper );
Example
#include <string.h>
#include <QuickHash.h>
int main()
{
char mydata[] = "Test String";
char key[] = "Test Password";
char hmachex[ SLC_PANAMA_HEXDIGESTSIZE ]; /*0 terminated*/
/*****Calculate the HMAC using PANAMA hash algorithm******/
SL_HMAC_CalculateStrHex( SLC_PANAMA_ALGID, hmachex, mydata, key, 0 );
/*****Use the HMAC****************************************/
/*...*/
return 0;
}
|
|
HMAC API Overview
| HMAC API Functions
|
Useful Links | HashCalc
See Also
SL_HMAC_CalculateStr,
SL_HMAC_Calculate,
SL_HMAC_CalculateHex
|