in source/portable/mbedtls/core_pkcs11_mbedtls.c [3798:3859]
static CK_RV prvInitSHA256HMAC( P11Session_t * pxSession,
CK_OBJECT_HANDLE hKey,
CK_BYTE_PTR pucKeyData,
CK_ULONG ulKeyDataLength )
{
CK_RV xResult = CKR_OK;
int32_t lMbedTLSResult = 0;
const mbedtls_md_info_t * pxMdInfo = NULL;
mbedtls_md_init( &pxSession->xHMACSecretContext );
pxMdInfo = mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 );
if( pxMdInfo == NULL )
{
LogError( ( "Failed to initialize SHA256HMAC operation. "
"mbedtls_md_info_from_type failed. Consider "
"double checking the mbedtls_md_type_t object "
"that was used." ) );
xResult = CKR_FUNCTION_FAILED;
prvHMACCleanUp( pxSession );
}
if( xResult == CKR_OK )
{
lMbedTLSResult = mbedtls_md_setup( &pxSession->xHMACSecretContext,
pxMdInfo,
PKCS11_USING_HMAC );
if( lMbedTLSResult != 0 )
{
LogError( ( "Failed to initialize SHA256HMAC operation. "
"mbedtls_md_setup failed: mbed TLS error = %s : %s.",
mbedtlsHighLevelCodeOrDefault( lMbedTLSResult ),
mbedtlsLowLevelCodeOrDefault( lMbedTLSResult ) ) );
prvHMACCleanUp( pxSession );
xResult = CKR_KEY_HANDLE_INVALID;
}
}
if( xResult == CKR_OK )
{
lMbedTLSResult = mbedtls_md_hmac_starts( &pxSession->xHMACSecretContext,
pucKeyData, ulKeyDataLength );
if( lMbedTLSResult != 0 )
{
LogError( ( "Failed to initialize SHA256HMAC operation. "
"mbedtls_md_setup failed: mbed TLS error = %s : %s.",
mbedtlsHighLevelCodeOrDefault( lMbedTLSResult ),
mbedtlsLowLevelCodeOrDefault( lMbedTLSResult ) ) );
prvHMACCleanUp( pxSession );
xResult = CKR_KEY_HANDLE_INVALID;
}
}
if( xResult == CKR_OK )
{
pxSession->xHMACKeyHandle = hKey;
}
return xResult;
}