Computes the HMAC value of an entire message.
IppStatus ippsHMACSHA256MessageDigest(const Ipp8u *pSrcMesg, int mesgLen, const Ipp8u *pKey, int keyLen, Ipp8u *pMAC, int macLen);
pSrcMesg |
Pointer to the input message. |
mesgLen |
Message length in bytes. |
pKey |
Pointer to the user-supplied key. |
keyLen |
Key length in bytes. |
pMAC |
Pointer to the resultant HMAC value. |
macLen |
Specified HMAC length. |
This function is declared in the ippcp.h file. The function takes the input key pKey of the specified key length keyLen and applies the keyed hash-based message authentication code scheme to transform the input message into the respective message authentication code pMAC of the specified length macLen.
ippStsNoErr |
Indicates no error. Any other value indicates an error or warning. |
ippStsNullPtrErr |
Indicates an error condition if any of the specified pointers is NULL. |
ippStsLengthErr |
Indicates an error condition if msgLen is less than zero and macLen is less than one or greater than the length of the hash value. |
// Compute two keyed-hash based message // authentication codes using the HMAC scheme // 1-st will correspond of 1/2 message // 2-nd will correspond of whole message void HMACSHA256_sample(void){ // define key Ipp8u key[] = "the key for HMAC scheme"; // get size of HMACSHA256 context int ctxSize; ippsHMACSHA256GetSize(&ctxSize); // allocate HMACSHA256 context IppsHMACSHA256State* pCtx = (IppsHMACSHA256State*)( new Ipp8u [ctxSize] ); // and ini context ippsHMACSHA256Init(key, strlen((char*)key), pCtx); // define message Ipp8u msg[] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; int n; // update MAC using piece of message for(n=0; n<(sizeof(msg)-1)/2; n++) ippsHMACSHA256Update(msg+n, 1, pCtx); // clone HMACSHA256 context IppsHMACSHA256State* pCtx2 = (IppsHMACSHA256State*)( new Ipp8u [ctxSize] ); ippsHMACSHA256Init(key, strlen((char*)key), pCtx2); ippsHMACSHA256Duplicate(pCtx, pCtx2); // finalize and extract digest of a half message const int macLen = 16; Ipp8u mac[macLen]; ippsHMACSHA256Final(mac, macLen, pCtx); // update MAC using HMACSHA256 clone context ippsHMACSHA256Update(msg+n, sizeof(msg)-1-n, pCtx2); // finalize and extract digest of a whole message Ipp8u mac2[macLen]; ippsHMACSHA256Final(mac2, macLen, pCtx2); delete [] (Ipp8u*)pCtx; delete [] (Ipp8u*)pCtx2; }
Copyright © 2000 - 2010, Intel Corporation. All rights reserved.