@@ -5782,6 +5782,30 @@ void mbedtls_psa_crypto_free( void )
5782
5782
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
5783
5783
}
5784
5784
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
+
5785
5809
psa_status_t psa_crypto_init ( void )
5786
5810
{
5787
5811
psa_status_t status ;
@@ -5819,7 +5843,10 @@ psa_status_t psa_crypto_init( void )
5819
5843
status = psa_crypto_load_transaction ( );
5820
5844
if ( status == PSA_SUCCESS )
5821
5845
{
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 ( );
5823
5850
}
5824
5851
else if ( status == PSA_ERROR_DOES_NOT_EXIST )
5825
5852
{
0 commit comments