QuickHash Library API

SL_HMAC_Calculate

int SL_HASHCALL SL_HMAC_Calculate( unsigned int nAlgID, void* pDest, const void* pSrc, unsigned int nSrcLength, const void* pKey, unsigned int nKeyLength );

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_SHA1_ALGID when you need to calculate the HMAC using SHA-1 hash algorithm.

    All supported hash algorithms with their corresponding IDs are listed in Table1.

 pDest

    [out] Pointer to the memory buffer that will receive the HMAC.

 pSrc

    [in] Pointer to the continuous memory block for which to calculate the HMAC.

 nSrcLength

    [in] Length in bytes of the memory block. 

 pKey

    [in] Pointer to the key which represents a continuous memory block.

 nKeyLength

    [in] Length in bytes of the key.

Remarks

Calculates the HMAC for the memory block pointed by pSrc using the key 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 DIGESTSIZE bytes. DIGESTSIZE is a predefined constant that specifies the size of the HMAC for a specific hash algorithm. For example, you have to allocate at least SLC_SHA1_DIGESTSIZE bytes for the memory buffer pointed by pDest if you need to calculate the HMAC using SHA-1 hash algorithm.

All supported hash algorithms with their corresponding DIGESTSIZEs are listed in Table1.

Table1. Supported hash algorithms, their IDs and DIGESTSIZEs.

Algorithm Name Algorithm ID Algorithm DIGESTSIZE
MD4 SLC_MD4_ALGID SLC_MD4_DIGESTSIZE
MD5 SLC_MD5_ALGID SLC_MD5_DIGESTSIZE
SHA-1 SLC_SHA1_ALGID SLC_SHA1_DIGESTSIZE
SHA-256 SLC_SHA256_ALGID SLC_SHA256_DIGESTSIZE
SHA-512 SLC_SHA512_ALGID SLC_SHA512_DIGESTSIZE
SHA-384 SLC_SHA384_ALGID SLC_SHA384_DIGESTSIZE
RIPEMD128 SLC_RIPEMD128_ALGID SLC_RIPEMD128_DIGESTSIZE
RIPEMD160 SLC_RIPEMD160_ALGID SLC_RIPEMD160_DIGESTSIZE
RIPEMD256 SLC_RIPEMD256_ALGID SLC_RIPEMD256_DIGESTSIZE
RIPEMD320 SLC_RIPEMD320_ALGID SLC_RIPEMD320_DIGESTSIZE
PANAMA SLC_PANAMA_ALGID SLC_PANAMA_DIGESTSIZE
TIGER SLC_TIGER_ALGID SLC_TIGER_DIGESTSIZE

Example

int main()
{
    char string[] = "Test String";
    char key[] = "Test Password";

    unsigned char hmac[ SLC_SHA384_DIGESTSIZE ];

    /*****Calculate the HMAC using SHA-384 hash algorithm*****/

    SL_HMAC_Calculate( SLC_SHA384_ALGID, hmac, string, strlen( string ), 
                                               key, strlen( key ) );

    /*****Use the HMAC****************************************/
    /*...*/

    return 0;
}

 

 

HMAC API Overview   |   HMAC API_Functions   |   Useful Links   |   HashCalc

 

See Also    SL_HMAC_CalculateHex, SL_HMAC_CalculateStr, SL_HMAC_CalculateStrHex


 

 

Send Feedback to SlavaSoft Inc. Tell a friend about QuickHash Library