FreeRTOS: PKCS11
PKCS11 Cryptoki Library
Return to main page ↑
C_DigestInit

Initializes a message-digesting operation.

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 );
if( pMechanism == 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 )
{
xResult = CKR_OPERATION_ACTIVE;
}
}
if( xResult == CKR_OK )
{
if( pMechanism->mechanism != CKM_SHA256 )
{
xResult = CKR_MECHANISM_INVALID;
}
}
/*
* Initialize the requested hash type
*/
if( xResult == CKR_OK )
{
mbedtls_sha256_init( &pxSession->xSHA256Context );
if( 0 != mbedtls_sha256_starts_ret( &pxSession->xSHA256Context, 0 ) )
{
xResult = CKR_FUNCTION_FAILED;
}
else
{
pxSession->xOperationDigestMechanism = pMechanism->mechanism;
}
}
return xResult;
}
See also
C_DigestUpdate(), C_DigestFinal()
Note
Digest parameters are shared by a session. Calling C_DigestInit(), C_DigestUpdate(), and C_DigestFinal() with the same session across different tasks may lead to unexpected results.
Parameters
[in]hSessionHandle of a valid PKCS #11 session.
[in]pMechanismDigesting mechanism. This port only supports the mechanism CKM_SHA256.
Returns
CKR_OK if successful. Else, see PKCS #11 specification for more information.
CK_DECLARE_FUNCTION
#define CK_DECLARE_FUNCTION(returnType, name)
Macro for defining a PKCS #11 functions.
Definition: iot_pkcs11.h:66
P11Session_t::xOperationDigestMechanism
CK_MECHANISM_TYPE xOperationDigestMechanism
Indicates if a digest operation is in progress.
Definition: iot_pkcs11_mbedtls.c:220
prvOperationActive
static CK_BBOOL prvOperationActive(const P11Session_t *pxSession)
Determines if an operation is in progress.
Definition: iot_pkcs11_mbedtls.c:303
P11Session_t::xSHA256Context
mbedtls_sha256_context xSHA256Context
Context for in progress digest operation.
Definition: iot_pkcs11_mbedtls.c:229
prvSessionPointerFromHandle
static P11Session_t * prvSessionPointerFromHandle(CK_SESSION_HANDLE xSession)
Maps an opaque caller session handle into its internal state structure.
Definition: iot_pkcs11_mbedtls.c:287
prvCheckValidSessionAndModule
static CK_RV prvCheckValidSessionAndModule(const P11Session_t *pxSession)
Helper to check if the current session is initialized and valid.
Definition: iot_pkcs11_mbedtls.c:248
C_DigestInit
CK_RV C_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism)
Initializes a message-digesting operation.
Definition: iot_pkcs11_mbedtls.c:3145
P11Session_t
Session structure.
Definition: iot_pkcs11_mbedtls.c:217