corePKCS11  V3.0.0
PKCS #11 Cryptoki Library
C_DigestInit
CK_DECLARE_FUNCTION( CK_RV, C_DigestInit )( CK_SESSION_HANDLE hSession,
CK_MECHANISM_PTR pMechanism )
{
P11Session_t * pxSession = prvSessionPointerFromHandle( hSession );
CK_RV xResult = prvCheckValidSessionAndModule( pxSession );
int32_t lMbedTLSResult = 0;
if( pMechanism == NULL )
{
LogError( ( "Failed to initialize digest operation. Mechanism pointer "
"was NULL." ) );
xResult = CKR_ARGUMENTS_BAD;
}
if( xResult == CKR_OK )
{
/* See explanation in prvCheckValidSessionAndModule for this exception. */
/* coverity[misra_c_2012_rule_10_5_violation] */
if( prvOperationActive( pxSession ) == ( CK_BBOOL ) CK_TRUE )
{
LogError( ( "Failed to initialize digest operation. An operation "
"was already active." ) );
xResult = CKR_OPERATION_ACTIVE;
}
}
if( xResult == CKR_OK )
{
if( pMechanism->mechanism != CKM_SHA256 )
{
LogError( ( "Failed to initialize digest operation. Currently only "
"the CKM_SHA256 mechanism is supported." ) );
xResult = CKR_MECHANISM_INVALID;
}
}
/*
* Initialize the requested hash type
*/
if( xResult == CKR_OK )
{
mbedtls_sha256_init( &pxSession->xSHA256Context );
lMbedTLSResult = mbedtls_sha256_starts_ret( &pxSession->xSHA256Context, 0 );
if( 0 != lMbedTLSResult )
{
LogError( ( "Failed to initialize digest operation. "
"mbedtls_sha256_starts_ret failed with: mbed TLS error = %s : %s.",
mbedtlsHighLevelCodeOrDefault( lMbedTLSResult ),
mbedtlsLowLevelCodeOrDefault( lMbedTLSResult ) ) );
xResult = CKR_FUNCTION_FAILED;
}
else
{
pxSession->xOperationDigestMechanism = pMechanism->mechanism;
}
}
return xResult;
}
CK_DECLARE_FUNCTION
#define CK_DECLARE_FUNCTION(returnType, name)
Macro for defining a PKCS #11 functions.
Definition: core_pkcs11.h:72