Skip to content

Commit 284eca2

Browse files
committed
Add hook for generating keys using secure element
1 parent e7d08c3 commit 284eca2

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

library/psa_crypto.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5330,15 +5330,34 @@ psa_status_t psa_generate_key( const psa_key_attributes_t *attributes,
53305330
psa_status_t status;
53315331
psa_key_slot_t *slot = NULL;
53325332
const psa_se_drv_table_entry_t *driver = NULL;
5333+
53335334
status = psa_start_key_creation( attributes, handle, &slot, &driver );
5334-
if( status == PSA_SUCCESS )
5335+
if( status != PSA_SUCCESS )
5336+
goto exit;
5337+
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
5338+
if( driver != NULL )
5339+
{
5340+
const psa_drv_se_t *drv = psa_get_se_driver_methods( driver );
5341+
if( drv->key_management == NULL ||
5342+
drv->key_management->p_generate == NULL )
5343+
{
5344+
status = PSA_ERROR_NOT_SUPPORTED;
5345+
goto exit;
5346+
}
5347+
status = drv->key_management->p_generate(
5348+
slot->data.se.slot_number, slot->type, slot->policy.usage,
5349+
attributes->bits, NULL, 0, NULL);
5350+
}
5351+
else
5352+
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
53355353
{
53365354
status = psa_generate_key_internal(
53375355
slot, attributes->bits,
53385356
attributes->domain_parameters, attributes->domain_parameters_size );
53395357
}
53405358
if( status == PSA_SUCCESS )
53415359
status = psa_finish_key_creation( slot, driver );
5360+
exit:
53425361
if( status != PSA_SUCCESS )
53435362
{
53445363
psa_fail_key_creation( slot, driver );

0 commit comments

Comments
 (0)