@@ -994,18 +994,16 @@ static psa_status_t psa_remove_key_data_from_memory( psa_key_slot_t *slot )
994994 return ( PSA_SUCCESS );
995995}
996996
997- static void psa_abort_operations_using_key ( psa_key_slot_t * slot )
998- {
999- /*FIXME how to implement this?*/
1000- (void ) slot ;
1001- }
1002-
1003997/** Completely wipe a slot in memory, including its policy.
1004998 * Persistent storage is not affected. */
1005999psa_status_t psa_wipe_key_slot ( psa_key_slot_t * slot )
10061000{
10071001 psa_status_t status = psa_remove_key_data_from_memory ( slot );
1008- psa_abort_operations_using_key ( slot );
1002+ /* Multipart operations may still be using the key. This is safe
1003+ * because all multipart operation objects are independent from
1004+ * the key slot: if they need to access the key after the setup
1005+ * phase, they have a copy of the key. Note that this means that
1006+ * key material can linger until all operations are completed. */
10091007 /* At this point, key material and other type-specific content has
10101008 * been wiped. Clear remaining metadata. We can call memset and not
10111009 * zeroize because the metadata is not particularly sensitive. */
@@ -1016,8 +1014,8 @@ psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot )
10161014psa_status_t psa_destroy_key ( psa_key_handle_t handle )
10171015{
10181016 psa_key_slot_t * slot ;
1019- psa_status_t status = PSA_SUCCESS ;
1020- psa_status_t storage_status = PSA_SUCCESS ;
1017+ psa_status_t status ; /* status of the last operation */
1018+ psa_status_t overall_status = PSA_SUCCESS ;
10211019#if defined(MBEDTLS_PSA_CRYPTO_SE_C )
10221020 psa_se_drv_table_entry_t * driver ;
10231021#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
@@ -1043,42 +1041,57 @@ psa_status_t psa_destroy_key( psa_key_handle_t handle )
10431041 if ( status != PSA_SUCCESS )
10441042 {
10451043 (void ) psa_crypto_stop_transaction ( );
1046- /* TOnogrepDO: destroy what can be destroyed anyway */
1047- return ( status );
1044+ /* We should still try to destroy the key in the secure
1045+ * element and the key metadata in storage. This is especially
1046+ * important if the error is that the storage is full.
1047+ * But how to do it exactly without risking an inconsistent
1048+ * state after a reset?
1049+ * https://github.com/ARMmbed/mbed-crypto/issues/215
1050+ */
1051+ overall_status = status ;
1052+ goto exit ;
10481053 }
10491054
10501055 status = psa_destroy_se_key ( driver , slot -> data .se .slot_number );
1056+ if ( overall_status == PSA_SUCCESS )
1057+ overall_status = status ;
10511058 }
10521059#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
10531060
10541061#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C )
1055- if ( slot -> attr .lifetime == PSA_KEY_LIFETIME_PERSISTENT )
1062+ if ( slot -> attr .lifetime != PSA_KEY_LIFETIME_VOLATILE )
10561063 {
1057- storage_status =
1058- psa_destroy_persistent_key ( slot -> attr .id );
1064+ status = psa_destroy_persistent_key ( slot -> attr .id );
1065+ if ( overall_status == PSA_SUCCESS )
1066+ overall_status = status ;
1067+
1068+ /* TODO: other slots may have a copy of the same key. We should
1069+ * invalidate them.
1070+ * https://github.com/ARMmbed/mbed-crypto/issues/214
1071+ */
10591072 }
10601073#endif /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
10611074
10621075#if defined(MBEDTLS_PSA_CRYPTO_SE_C )
10631076 if ( driver != NULL )
10641077 {
1065- psa_status_t status2 ;
10661078 status = psa_save_se_persistent_data ( driver );
1067- status2 = psa_crypto_stop_transaction ( );
1068- if ( status == PSA_SUCCESS )
1069- status = status2 ;
1070- if ( status != PSA_SUCCESS )
1071- {
1072- /* TOnogrepDO: destroy what can be destroyed anyway */
1073- return ( status );
1074- }
1079+ if ( overall_status == PSA_SUCCESS )
1080+ overall_status = status ;
1081+ status = psa_crypto_stop_transaction ( );
1082+ if ( overall_status == PSA_SUCCESS )
1083+ overall_status = status ;
10751084 }
10761085#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
10771086
1087+ #if defined(MBEDTLS_PSA_CRYPTO_SE_C )
1088+ exit :
1089+ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
10781090 status = psa_wipe_key_slot ( slot );
1079- if ( status != PSA_SUCCESS )
1080- return ( status );
1081- return ( storage_status );
1091+ /* Prioritize CORRUPTION_DETECTED from wiping over a storage error */
1092+ if ( overall_status == PSA_SUCCESS )
1093+ overall_status = status ;
1094+ return ( overall_status );
10821095}
10831096
10841097void psa_reset_key_attributes ( psa_key_attributes_t * attributes )
@@ -1201,8 +1214,10 @@ psa_status_t psa_get_key_attributes( psa_key_handle_t handle,
12011214 case PSA_KEY_TYPE_RSA_KEY_PAIR :
12021215 case PSA_KEY_TYPE_RSA_PUBLIC_KEY :
12031216#if defined(MBEDTLS_PSA_CRYPTO_SE_C )
1204- /* TOnogrepDO: reporting the public exponent for opaque keys
1205- * is not yet implemented. */
1217+ /* TODO: reporting the public exponent for opaque keys
1218+ * is not yet implemented.
1219+ * https://github.com/ARMmbed/mbed-crypto/issues/216
1220+ */
12061221 if ( psa_key_slot_is_external ( slot ) )
12071222 break ;
12081223#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
@@ -1722,10 +1737,12 @@ static void psa_fail_key_creation( psa_key_slot_t *slot,
17221737 return ;
17231738
17241739#if defined(MBEDTLS_PSA_CRYPTO_SE_C )
1725- /* TOnogrepDO : If the key has already been created in the secure
1740+ /* TODO : If the key has already been created in the secure
17261741 * element, and the failure happened later (when saving metadata
17271742 * to internal storage), we need to destroy the key in the secure
1728- * element. */
1743+ * element.
1744+ * https://github.com/ARMmbed/mbed-crypto/issues/217
1745+ */
17291746
17301747 /* Abort the ongoing transaction if any (there may not be one if
17311748 * the creation process failed before starting one, or if the
@@ -6075,8 +6092,10 @@ static psa_status_t psa_crypto_recover_transaction(
60756092 {
60766093 case PSA_CRYPTO_TRANSACTION_CREATE_KEY :
60776094 case PSA_CRYPTO_TRANSACTION_DESTROY_KEY :
6078- /* TOnogrepDO - fall through to the failure case until this
6079- * is implemented */
6095+ /* TODO - fall through to the failure case until this
6096+ * is implemented.
6097+ * https://github.com/ARMmbed/mbed-crypto/issues/218
6098+ */
60806099 default :
60816100 /* We found an unsupported transaction in the storage.
60826101 * We don't know what state the storage is in. Give up. */
0 commit comments