in source/sigv4.c [2456:2522]
static int32_t hmacFinal( HmacContext_t * pHmacContext,
char * pMac,
size_t macLen )
{
int32_t returnStatus = -1;
uint8_t innerHashDigest[ SIGV4_HASH_MAX_DIGEST_LENGTH ];
size_t i = 0U;
const SigV4CryptoInterface_t * pCryptoInterface = NULL;
assert( pHmacContext != NULL );
assert( pHmacContext->key != NULL );
assert( pHmacContext->pCryptoInterface != NULL );
/* Note that we must have a block-sized derived key before calling this function. */
assert( pHmacContext->pCryptoInterface->hashInit != NULL );
assert( pHmacContext->pCryptoInterface->hashUpdate != NULL );
assert( pHmacContext->pCryptoInterface->hashFinal != NULL );
pCryptoInterface = pHmacContext->pCryptoInterface;
/* Write the inner hash. */
returnStatus = pCryptoInterface->hashFinal( pCryptoInterface->pHashContext,
innerHashDigest,
pCryptoInterface->hashDigestLen );
if( returnStatus == 0 )
{
/* Create the outer-padded key by retrieving the original key from
* the inner-padded key (by XORing with ipad byte) and then XOR with opad
* to generate the outer-padded key. As XOR is associative, one way to do
* this is by performing XOR on each byte of the inner-padded key (ipad ^ opad). */
for( i = 0U; i < pCryptoInterface->hashBlockLen; i++ )
{
pHmacContext->key[ i ] ^= HMAX_IPAD_XOR_OPAD_BYTE;
}
returnStatus = pCryptoInterface->hashInit( pCryptoInterface->pHashContext );
}
if( returnStatus == 0 )
{
/* Update hash using the outer-padded key. */
returnStatus = pCryptoInterface->hashUpdate( pCryptoInterface->pHashContext,
pHmacContext->key,
pCryptoInterface->hashBlockLen );
}
if( returnStatus == 0 )
{
/* Update hash using the inner digest. */
returnStatus = pCryptoInterface->hashUpdate( pCryptoInterface->pHashContext,
innerHashDigest,
pCryptoInterface->hashDigestLen );
}
if( returnStatus == 0 )
{
/* Write the final HMAC value. */
returnStatus = pCryptoInterface->hashFinal( pCryptoInterface->pHashContext,
( uint8_t * ) pMac,
macLen );
}
/* Reset the HMAC context. */
pHmacContext->keyLen = 0U;
return returnStatus;
}