CK_BYTE_PTR pPart,
CK_ULONG ulPartLen )
{
P11Session_t * pxSession = prvSessionPointerFromHandle( hSession );
CK_RV xResult = prvCheckValidSessionAndModule( pxSession );
int32_t lMbedTLSResult = 0;
if( pPart == NULL )
{
LogError( ( "Failed to start digest operation. Received a NULL pointer "
"in digest request." ) );
xResult = CKR_ARGUMENTS_BAD;
}
if( xResult == CKR_OK )
{
if( pxSession->xOperationDigestMechanism != CKM_SHA256 )
{
LogError( ( "Failed to start digest operation. CKM_SHA256 is the "
"expected digest mechanism." ) );
xResult = CKR_OPERATION_NOT_INITIALIZED;
}
}
if( xResult == CKR_OK )
{
lMbedTLSResult = mbedtls_sha256_update_ret( &pxSession->xSHA256Context, pPart, ulPartLen );
if( 0 != lMbedTLSResult )
{
LogError( ( "Failed to perform digest operation. "
"mbedtls_sha256_update_ret failed: mbed TLS error = %s : %s.",
mbedtlsHighLevelCodeOrDefault( lMbedTLSResult ),
mbedtlsLowLevelCodeOrDefault( lMbedTLSResult ) ) );
pxSession->xOperationDigestMechanism = pkcs11NO_OPERATION;
xResult = CKR_FUNCTION_FAILED;
}
}
if( ( xResult != CKR_OK ) && ( xResult != CKR_SESSION_HANDLE_INVALID ) &&
( xResult != CKR_OPERATION_NOT_INITIALIZED ) )
{
LogDebug( ( "Tearing down operation due to errors." ) );
pxSession->xOperationDigestMechanism = pkcs11NO_OPERATION;
mbedtls_sha256_free( &pxSession->xSHA256Context );
}
return xResult;
}