@@ -939,17 +939,36 @@ psa_status_t psa_destroy_key( psa_key_handle_t handle )
939
939
psa_key_slot_t * slot ;
940
940
psa_status_t status = PSA_SUCCESS ;
941
941
psa_status_t storage_status = PSA_SUCCESS ;
942
+ #if defined(MBEDTLS_PSA_CRYPTO_SE_C )
943
+ const psa_se_drv_table_entry_t * driver ;
944
+ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
942
945
943
946
status = psa_get_key_slot ( handle , & slot );
944
947
if ( status != PSA_SUCCESS )
945
948
return ( status );
949
+
950
+ #if defined(MBEDTLS_PSA_CRYPTO_SE_C )
951
+ driver = psa_get_se_driver_entry ( slot -> lifetime );
952
+ if ( driver != NULL )
953
+ {
954
+ const psa_drv_se_t * drv = psa_get_se_driver_methods ( driver );
955
+ psa_key_slot_number_t slot_number = slot -> data .se .slot_number ;
956
+ if ( drv -> key_management == NULL ||
957
+ drv -> key_management -> p_destroy == NULL )
958
+ return ( PSA_ERROR_NOT_PERMITTED );
959
+ status = drv -> key_management -> p_destroy ( slot_number );
960
+ psa_update_se_slot_usage ( driver , slot_number , 0 );
961
+ }
962
+ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
963
+
946
964
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C )
947
965
if ( slot -> lifetime == PSA_KEY_LIFETIME_PERSISTENT )
948
966
{
949
967
storage_status =
950
968
psa_destroy_persistent_key ( slot -> persistent_storage_id );
951
969
}
952
970
#endif /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
971
+
953
972
status = psa_wipe_key_slot ( slot );
954
973
if ( status != PSA_SUCCESS )
955
974
return ( status );
@@ -1122,11 +1141,29 @@ static psa_status_t psa_internal_export_key( const psa_key_slot_t *slot,
1122
1141
size_t * data_length ,
1123
1142
int export_public_key )
1124
1143
{
1144
+ #if defined(MBEDTLS_PSA_CRYPTO_SE_C )
1145
+ const psa_drv_se_t * drv = psa_get_se_driver ( slot -> lifetime );
1146
+ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
1147
+
1125
1148
* data_length = 0 ;
1126
1149
1127
1150
if ( export_public_key && ! PSA_KEY_TYPE_IS_ASYMMETRIC ( slot -> type ) )
1128
1151
return ( PSA_ERROR_INVALID_ARGUMENT );
1129
1152
1153
+ #if defined(MBEDTLS_PSA_CRYPTO_SE_C )
1154
+ if ( drv != NULL )
1155
+ {
1156
+ psa_drv_se_export_key_t method ;
1157
+ if ( drv -> key_management == NULL )
1158
+ return ( PSA_ERROR_NOT_SUPPORTED );
1159
+ method = ( export_public_key ?
1160
+ drv -> key_management -> p_export_public :
1161
+ drv -> key_management -> p_export );
1162
+ return ( ( * method )( slot -> data .se .slot_number ,
1163
+ data , data_size , data_length ) );
1164
+ }
1165
+ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
1166
+
1130
1167
if ( key_type_is_raw_bytes ( slot -> type ) )
1131
1168
{
1132
1169
if ( slot -> data .raw .bytes > data_size )
@@ -1528,12 +1565,32 @@ psa_status_t psa_import_key( const psa_key_attributes_t *attributes,
1528
1565
if ( status != PSA_SUCCESS )
1529
1566
goto exit ;
1530
1567
1531
- status = psa_import_key_into_slot ( slot , data , data_length );
1532
- if ( status != PSA_SUCCESS )
1533
- goto exit ;
1534
- status = psa_check_key_slot_attributes ( slot , attributes );
1535
- if ( status != PSA_SUCCESS )
1536
- goto exit ;
1568
+ #if defined(MBEDTLS_PSA_CRYPTO_SE_C )
1569
+ if ( driver != NULL )
1570
+ {
1571
+ const psa_drv_se_t * drv = psa_get_se_driver_methods ( driver );
1572
+ if ( drv -> key_management == NULL ||
1573
+ drv -> key_management -> p_import == NULL )
1574
+ {
1575
+ status = PSA_ERROR_NOT_SUPPORTED ;
1576
+ goto exit ;
1577
+ }
1578
+ status = drv -> key_management -> p_import (
1579
+ slot -> data .se .slot_number ,
1580
+ slot -> lifetime , slot -> type , slot -> policy .alg , slot -> policy .usage ,
1581
+ data , data_length );
1582
+ /* TOnogrepDO: psa_check_key_slot_attributes? */
1583
+ }
1584
+ else
1585
+ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
1586
+ {
1587
+ status = psa_import_key_into_slot ( slot , data , data_length );
1588
+ if ( status != PSA_SUCCESS )
1589
+ goto exit ;
1590
+ status = psa_check_key_slot_attributes ( slot , attributes );
1591
+ if ( status != PSA_SUCCESS )
1592
+ goto exit ;
1593
+ }
1537
1594
1538
1595
status = psa_finish_key_creation ( slot , driver );
1539
1596
exit :
0 commit comments