Skip to content

Commit 015ae2f

Browse files
dgreen-armPatater
authored andcommitted
Add hook for generating keys using secure element
1 parent f710f33 commit 015ae2f

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
@@ -5768,22 +5768,38 @@ psa_status_t psa_generate_key( const psa_key_attributes_t *attributes,
57685768
psa_status_t status;
57695769
psa_key_slot_t *slot = NULL;
57705770
psa_se_drv_table_entry_t *driver = NULL;
5771+
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
5772+
const psa_drv_se_t *drv;
5773+
psa_drv_se_context_t *drv_context;
5774+
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
5775+
57715776
status = psa_start_key_creation( attributes, handle, &slot, &driver );
5777+
if( status != PSA_SUCCESS )
5778+
goto exit;
57725779
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
5773-
if( driver != NULL )
5780+
if( psa_get_se_driver( slot->lifetime, &drv, &drv_context ) )
57745781
{
5775-
/* Generating a key in a secure element is not implemented yet. */
5776-
status = PSA_ERROR_NOT_SUPPORTED;
5782+
if( drv->key_management == NULL ||
5783+
drv->key_management->p_generate == NULL )
5784+
{
5785+
status = PSA_ERROR_NOT_SUPPORTED;
5786+
goto exit;
5787+
}
5788+
status = drv->key_management->p_generate(
5789+
drv_context,
5790+
slot->data.se.slot_number, slot->type, slot->policy.usage,
5791+
attributes->bits, NULL, 0, NULL);
57775792
}
5793+
else
57785794
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
5779-
if( status == PSA_SUCCESS )
57805795
{
57815796
status = psa_generate_key_internal(
57825797
slot, attributes->bits,
57835798
attributes->domain_parameters, attributes->domain_parameters_size );
57845799
}
57855800
if( status == PSA_SUCCESS )
57865801
status = psa_finish_key_creation( slot, driver );
5802+
exit:
57875803
if( status != PSA_SUCCESS )
57885804
{
57895805
psa_fail_key_creation( slot, driver );

0 commit comments

Comments
 (0)