Skip to content

Commit cf733e5

Browse files
psa_start_key_creation: take the method as a parameter
Let psa_start_key_creation what type of key creation this is. This will be used at least for key registration in a secure element, which is a peculiar kind of creation since it uses existing key material.
1 parent 0a11044 commit cf733e5

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

library/psa_crypto.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,16 @@ static psa_status_t psa_validate_key_attributes(
15061506
return( PSA_SUCCESS );
15071507
}
15081508

1509+
/** An enumeration indicating how a key is created.
1510+
*/
1511+
typedef enum
1512+
{
1513+
PSA_KEY_CREATION_IMPORT,
1514+
PSA_KEY_CREATION_GENERATE,
1515+
PSA_KEY_CREATION_DERIVE,
1516+
PSA_KEY_CREATION_COPY,
1517+
} psa_key_creation_method_t;
1518+
15091519
/** Prepare a key slot to receive key material.
15101520
*
15111521
* This function allocates a key slot and sets its metadata.
@@ -1520,6 +1530,7 @@ static psa_status_t psa_validate_key_attributes(
15201530
* In case of failure at any step, stop the sequence and call
15211531
* psa_fail_key_creation().
15221532
*
1533+
* \param method An identification of the calling function.
15231534
* \param[in] attributes Key attributes for the new key.
15241535
* \param[out] handle On success, a handle for the allocated slot.
15251536
* \param[out] p_slot On success, a pointer to the prepared slot.
@@ -1532,6 +1543,7 @@ static psa_status_t psa_validate_key_attributes(
15321543
* You must call psa_fail_key_creation() to wipe and free the slot.
15331544
*/
15341545
static psa_status_t psa_start_key_creation(
1546+
psa_key_creation_method_t method,
15351547
const psa_key_attributes_t *attributes,
15361548
psa_key_handle_t *handle,
15371549
psa_key_slot_t **p_slot,
@@ -1540,6 +1552,7 @@ static psa_status_t psa_start_key_creation(
15401552
psa_status_t status;
15411553
psa_key_slot_t *slot;
15421554

1555+
(void) method;
15431556
*p_drv = NULL;
15441557

15451558
status = psa_validate_key_attributes( attributes, p_drv );
@@ -1796,7 +1809,8 @@ psa_status_t psa_import_key( const psa_key_attributes_t *attributes,
17961809
psa_key_slot_t *slot = NULL;
17971810
psa_se_drv_table_entry_t *driver = NULL;
17981811

1799-
status = psa_start_key_creation( attributes, handle, &slot, &driver );
1812+
status = psa_start_key_creation( PSA_KEY_CREATION_IMPORT, attributes,
1813+
handle, &slot, &driver );
18001814
if( status != PSA_SUCCESS )
18011815
goto exit;
18021816

@@ -1899,7 +1913,8 @@ psa_status_t psa_copy_key( psa_key_handle_t source_handle,
18991913
if( status != PSA_SUCCESS )
19001914
goto exit;
19011915

1902-
status = psa_start_key_creation( &actual_attributes,
1916+
status = psa_start_key_creation( PSA_KEY_CREATION_COPY,
1917+
&actual_attributes,
19031918
target_handle, &target_slot, &driver );
19041919
if( status != PSA_SUCCESS )
19051920
goto exit;
@@ -4817,7 +4832,8 @@ psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attribut
48174832
psa_status_t status;
48184833
psa_key_slot_t *slot = NULL;
48194834
psa_se_drv_table_entry_t *driver = NULL;
4820-
status = psa_start_key_creation( attributes, handle, &slot, &driver );
4835+
status = psa_start_key_creation( PSA_KEY_CREATION_DERIVE,
4836+
attributes, handle, &slot, &driver );
48214837
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
48224838
if( driver != NULL )
48234839
{
@@ -5863,7 +5879,8 @@ psa_status_t psa_generate_key( const psa_key_attributes_t *attributes,
58635879
psa_status_t status;
58645880
psa_key_slot_t *slot = NULL;
58655881
psa_se_drv_table_entry_t *driver = NULL;
5866-
status = psa_start_key_creation( attributes, handle, &slot, &driver );
5882+
status = psa_start_key_creation( PSA_KEY_CREATION_GENERATE,
5883+
attributes, handle, &slot, &driver );
58675884
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
58685885
if( driver != NULL )
58695886
{

0 commit comments

Comments
 (0)