Persistent storage implementation: psa_key_slot_t -> psa_key_id_t
Move the persistent storage implementation from psa_key_slot_t to
psa_key_id_t. For the most part, this just means changing the types of
function arguments.
Update the documentation of some functions to reflect the fact that
the slot identifier is purely a storage identifier and is not related
to how the slot is designated in memory.
diff --git a/library/psa_crypto_storage_file.c b/library/psa_crypto_storage_file.c
index 03c711a..95857fa 100644
--- a/library/psa_crypto_storage_file.c
+++ b/library/psa_crypto_storage_file.c
@@ -48,15 +48,15 @@
enum { MAX_LOCATION_LEN = sizeof(CRYPTO_STORAGE_FILE_LOCATION) + 40 };
-static void key_slot_to_location( const psa_key_slot_t key,
- char *location,
- size_t location_size )
+static void key_id_to_location( const psa_key_id_t key,
+ char *location,
+ size_t location_size )
{
mbedtls_snprintf( location, location_size,
CRYPTO_STORAGE_FILE_LOCATION "psa_key_slot_%d", key );
}
-psa_status_t psa_crypto_storage_load( const psa_key_slot_t key, uint8_t *data,
+psa_status_t psa_crypto_storage_load( const psa_key_id_t key, uint8_t *data,
size_t data_size )
{
psa_status_t status = PSA_SUCCESS;
@@ -64,7 +64,7 @@
size_t num_read;
char slot_location[MAX_LOCATION_LEN];
- key_slot_to_location( key, slot_location, MAX_LOCATION_LEN );
+ key_id_to_location( key, slot_location, MAX_LOCATION_LEN );
file = fopen( slot_location, "rb" );
if( file == NULL )
{
@@ -81,12 +81,12 @@
return( status );
}
-int psa_is_key_present_in_storage( const psa_key_slot_t key )
+int psa_is_key_present_in_storage( const psa_key_id_t key )
{
char slot_location[MAX_LOCATION_LEN];
FILE *file;
- key_slot_to_location( key, slot_location, MAX_LOCATION_LEN );
+ key_id_to_location( key, slot_location, MAX_LOCATION_LEN );
file = fopen( slot_location, "r" );
if( file == NULL )
@@ -99,7 +99,7 @@
return( 1 );
}
-psa_status_t psa_crypto_storage_store( const psa_key_slot_t key,
+psa_status_t psa_crypto_storage_store( const psa_key_id_t key,
const uint8_t *data,
size_t data_length )
{
@@ -114,7 +114,7 @@
* affect actual keys. */
const char *temp_location = CRYPTO_STORAGE_FILE_LOCATION "psa_key_slot_0";
- key_slot_to_location( key, slot_location, MAX_LOCATION_LEN );
+ key_id_to_location( key, slot_location, MAX_LOCATION_LEN );
if( psa_is_key_present_in_storage( key ) == 1 )
return( PSA_ERROR_OCCUPIED_SLOT );
@@ -154,12 +154,12 @@
return( status );
}
-psa_status_t psa_destroy_persistent_key( const psa_key_slot_t key )
+psa_status_t psa_destroy_persistent_key( const psa_key_id_t key )
{
FILE *file;
char slot_location[MAX_LOCATION_LEN];
- key_slot_to_location( key, slot_location, MAX_LOCATION_LEN );
+ key_id_to_location( key, slot_location, MAX_LOCATION_LEN );
/* Only try remove the file if it exists */
file = fopen( slot_location, "rb" );
@@ -173,7 +173,7 @@
return( PSA_SUCCESS );
}
-psa_status_t psa_crypto_storage_get_data_length( const psa_key_slot_t key,
+psa_status_t psa_crypto_storage_get_data_length( const psa_key_id_t key,
size_t *data_length )
{
psa_status_t status = PSA_SUCCESS;
@@ -181,7 +181,7 @@
long file_size;
char slot_location[MAX_LOCATION_LEN];
- key_slot_to_location( key, slot_location, MAX_LOCATION_LEN );
+ key_id_to_location( key, slot_location, MAX_LOCATION_LEN );
file = fopen( slot_location, "rb" );
if( file == NULL )