Skip to content

Commit f9bb29e

Browse files
Add boilerplate to recover a transaction during init
1 parent 4aea103 commit f9bb29e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

library/psa_crypto.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5782,6 +5782,30 @@ void mbedtls_psa_crypto_free( void )
57825782
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
57835783
}
57845784

5785+
#if defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS)
5786+
/** Recover a transaction that was interrupted by a power failure.
5787+
*
5788+
* This function is called during initialization, before psa_crypto_init()
5789+
* returns. If this function returns a failure status, the initialization
5790+
* fails.
5791+
*/
5792+
static psa_status_t psa_crypto_recover_transaction(
5793+
const psa_crypto_transaction_t *transaction )
5794+
{
5795+
switch( transaction->unknown.type )
5796+
{
5797+
case PSA_CRYPTO_TRANSACTION_CREATE_KEY:
5798+
case PSA_CRYPTO_TRANSACTION_DESTROY_KEY:
5799+
/* TOnogrepDO - fall through to the failure case until this
5800+
* is implemented */
5801+
default:
5802+
/* We found an unsupported transaction in the storage.
5803+
* We don't know what state the storage is in. Give up. */
5804+
return( PSA_ERROR_STORAGE_FAILURE );
5805+
}
5806+
}
5807+
#endif /* PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS */
5808+
57855809
psa_status_t psa_crypto_init( void )
57865810
{
57875811
psa_status_t status;
@@ -5819,7 +5843,10 @@ psa_status_t psa_crypto_init( void )
58195843
status = psa_crypto_load_transaction( );
58205844
if( status == PSA_SUCCESS )
58215845
{
5822-
/*TOnogrepDO: complete or abort the transaction*/
5846+
status = psa_crypto_recover_transaction( &psa_crypto_transaction );
5847+
if( status != PSA_SUCCESS )
5848+
goto exit;
5849+
status = psa_crypto_stop_transaction( );
58235850
}
58245851
else if( status == PSA_ERROR_DOES_NOT_EXIST )
58255852
{

0 commit comments

Comments
 (0)