Skip to content

Commit d63b7a6

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 fcfd4f3 commit d63b7a6

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

library/psa_crypto.c

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

1508+
/** An enumeration indicating how a key is created.
1509+
*/
1510+
typedef enum
1511+
{
1512+
PSA_KEY_CREATION_IMPORT,
1513+
PSA_KEY_CREATION_GENERATE,
1514+
PSA_KEY_CREATION_DERIVE,
1515+
PSA_KEY_CREATION_COPY,
1516+
} psa_key_creation_method_t;
1517+
15081518
/** Prepare a key slot to receive key material.
15091519
*
15101520
* This function allocates a key slot and sets its metadata.
@@ -1531,6 +1541,7 @@ static psa_status_t psa_validate_key_attributes(
15311541
* You must call psa_fail_key_creation() to wipe and free the slot.
15321542
*/
15331543
static psa_status_t psa_start_key_creation(
1544+
psa_key_creation_method_t method,
15341545
const psa_key_attributes_t *attributes,
15351546
psa_key_handle_t *handle,
15361547
psa_key_slot_t **p_slot,
@@ -1539,6 +1550,7 @@ static psa_status_t psa_start_key_creation(
15391550
psa_status_t status;
15401551
psa_key_slot_t *slot;
15411552

1553+
(void) method;
15421554
*p_drv = NULL;
15431555

15441556
status = psa_validate_key_attributes( attributes, p_drv );
@@ -1792,7 +1804,8 @@ psa_status_t psa_import_key( const psa_key_attributes_t *attributes,
17921804
psa_key_slot_t *slot = NULL;
17931805
psa_se_drv_table_entry_t *driver = NULL;
17941806

1795-
status = psa_start_key_creation( attributes, handle, &slot, &driver );
1807+
status = psa_start_key_creation( PSA_KEY_CREATION_IMPORT, attributes,
1808+
handle, &slot, &driver );
17961809
if( status != PSA_SUCCESS )
17971810
goto exit;
17981811

@@ -1895,7 +1908,8 @@ psa_status_t psa_copy_key( psa_key_handle_t source_handle,
18951908
if( status != PSA_SUCCESS )
18961909
goto exit;
18971910

1898-
status = psa_start_key_creation( &actual_attributes,
1911+
status = psa_start_key_creation( PSA_KEY_CREATION_COPY,
1912+
&actual_attributes,
18991913
target_handle, &target_slot, &driver );
19001914
if( status != PSA_SUCCESS )
19011915
goto exit;
@@ -4813,7 +4827,8 @@ psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attribut
48134827
psa_status_t status;
48144828
psa_key_slot_t *slot = NULL;
48154829
psa_se_drv_table_entry_t *driver = NULL;
4816-
status = psa_start_key_creation( attributes, handle, &slot, &driver );
4830+
status = psa_start_key_creation( PSA_KEY_CREATION_DERIVE,
4831+
attributes, handle, &slot, &driver );
48174832
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
48184833
if( driver != NULL )
48194834
{
@@ -5851,7 +5866,8 @@ psa_status_t psa_generate_key( const psa_key_attributes_t *attributes,
58515866
psa_status_t status;
58525867
psa_key_slot_t *slot = NULL;
58535868
psa_se_drv_table_entry_t *driver = NULL;
5854-
status = psa_start_key_creation( attributes, handle, &slot, &driver );
5869+
status = psa_start_key_creation( PSA_KEY_CREATION_GENERATE,
5870+
attributes, handle, &slot, &driver );
58555871
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
58565872
if( driver != NULL )
58575873
{

0 commit comments

Comments
 (0)