SE keys: implement persistent storage
For a key in a secure element, persist the key slot.
This is implemented in the nominal case. Failures may not be handled
properly.
diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c
index 5326fbd..6b87ea0 100644
--- a/library/psa_crypto_slot_management.c
+++ b/library/psa_crypto_slot_management.c
@@ -131,10 +131,28 @@
&key_data, &key_data_length );
if( status != PSA_SUCCESS )
goto exit;
+ p_slot->lifetime = psa_get_key_lifetime( &attributes );
p_slot->type = psa_get_key_type( &attributes );
p_slot->policy = attributes.policy;
- status = psa_import_key_into_slot( p_slot,
- key_data, key_data_length );
+
+#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
+ if( psa_key_lifetime_is_external( p_slot->lifetime ) )
+ {
+ if( key_data_length != sizeof( p_slot->data.se.slot_number ) )
+ {
+ status = PSA_ERROR_STORAGE_FAILURE;
+ goto exit;
+ }
+ memcpy( &p_slot->data.se.slot_number, key_data,
+ sizeof( p_slot->data.se.slot_number ) );
+ }
+ else
+#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
+ {
+ status = psa_import_key_into_slot( p_slot,
+ key_data, key_data_length );
+ }
+
exit:
psa_free_persistent_key_data( key_data, key_data_length );
return( status );