Skip to content

Commit c1308f1

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 54e9bd8 commit c1308f1

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
@@ -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.
@@ -1519,6 +1529,7 @@ static psa_status_t psa_validate_key_attributes(
15191529
* In case of failure at any step, stop the sequence and call
15201530
* psa_fail_key_creation().
15211531
*
1532+
* \param method An identification of the calling function.
15221533
* \param[in] attributes Key attributes for the new key.
15231534
* \param[out] handle On success, a handle for the allocated slot.
15241535
* \param[out] p_slot On success, a pointer to the prepared slot.
@@ -1531,6 +1542,7 @@ static psa_status_t psa_validate_key_attributes(
15311542
* You must call psa_fail_key_creation() to wipe and free the slot.
15321543
*/
15331544
static psa_status_t psa_start_key_creation(
1545+
psa_key_creation_method_t method,
15341546
const psa_key_attributes_t *attributes,
15351547
psa_key_handle_t *handle,
15361548
psa_key_slot_t **p_slot,
@@ -1539,6 +1551,7 @@ static psa_status_t psa_start_key_creation(
15391551
psa_status_t status;
15401552
psa_key_slot_t *slot;
15411553

1554+
(void) method;
15421555
*p_drv = NULL;
15431556

15441557
status = psa_validate_key_attributes( attributes, p_drv );
@@ -1792,7 +1805,8 @@ psa_status_t psa_import_key( const psa_key_attributes_t *attributes,
17921805
psa_key_slot_t *slot = NULL;
17931806
psa_se_drv_table_entry_t *driver = NULL;
17941807

1795-
status = psa_start_key_creation( attributes, handle, &slot, &driver );
1808+
status = psa_start_key_creation( PSA_KEY_CREATION_IMPORT, attributes,
1809+
handle, &slot, &driver );
17961810
if( status != PSA_SUCCESS )
17971811
goto exit;
17981812

@@ -1895,7 +1909,8 @@ psa_status_t psa_copy_key( psa_key_handle_t source_handle,
18951909
if( status != PSA_SUCCESS )
18961910
goto exit;
18971911

1898-
status = psa_start_key_creation( &actual_attributes,
1912+
status = psa_start_key_creation( PSA_KEY_CREATION_COPY,
1913+
&actual_attributes,
18991914
target_handle, &target_slot, &driver );
19001915
if( status != PSA_SUCCESS )
19011916
goto exit;
@@ -4813,7 +4828,8 @@ psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attribut
48134828
psa_status_t status;
48144829
psa_key_slot_t *slot = NULL;
48154830
psa_se_drv_table_entry_t *driver = NULL;
4816-
status = psa_start_key_creation( attributes, handle, &slot, &driver );
4831+
status = psa_start_key_creation( PSA_KEY_CREATION_DERIVE,
4832+
attributes, handle, &slot, &driver );
48174833
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
48184834
if( driver != NULL )
48194835
{
@@ -5851,7 +5867,8 @@ psa_status_t psa_generate_key( const psa_key_attributes_t *attributes,
58515867
psa_status_t status;
58525868
psa_key_slot_t *slot = NULL;
58535869
psa_se_drv_table_entry_t *driver = NULL;
5854-
status = psa_start_key_creation( attributes, handle, &slot, &driver );
5870+
status = psa_start_key_creation( PSA_KEY_CREATION_GENERATE,
5871+
attributes, handle, &slot, &driver );
58555872
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
58565873
if( driver != NULL )
58575874
{

0 commit comments

Comments
 (0)