Skip to content

Commit cbe1c59

Browse files
committed
Initial work for generate_key hook
1 parent 75f16b5 commit cbe1c59

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

library/psa_crypto.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5331,15 +5331,39 @@ psa_status_t psa_generate_key( const psa_key_attributes_t *attributes,
53315331
psa_status_t status;
53325332
psa_key_slot_t *slot = NULL;
53335333
const psa_se_drv_table_entry_t *driver = NULL;
5334+
uint8_t p_pubkey_out;
5335+
size_t pubkey_out_size;
5336+
size_t p_pubkey_length;
5337+
53345338
status = psa_start_key_creation( attributes, handle, &slot, &driver );
5335-
if( status == PSA_SUCCESS )
5339+
if( status != PSA_SUCCESS )
5340+
goto exit;
5341+
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
5342+
if( driver != NULL )
5343+
{
5344+
const psa_drv_se_t *drv = psa_get_se_driver_methods( driver );
5345+
if( drv->key_management == NULL ||
5346+
drv->key_management->p_generate == NULL )
5347+
{
5348+
status = PSA_ERROR_NOT_SUPPORTED;
5349+
goto exit;
5350+
}
5351+
status = drv->key_management->p_generate(
5352+
slot->data.se.slot_number, slot->type, slot->policy.usage,
5353+
attributes->bits, &p_pubkey_out, pubkey_out_size, &p_pubkey_length);
5354+
if( status != PSA_SUCCESS )
5355+
goto exit;
5356+
}
5357+
else
5358+
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
53365359
{
53375360
status = psa_generate_key_internal(
53385361
slot, attributes->bits,
53395362
attributes->domain_parameters, attributes->domain_parameters_size );
53405363
}
53415364
if( status == PSA_SUCCESS )
53425365
status = psa_finish_key_creation( slot, driver );
5366+
exit:
53435367
if( status != PSA_SUCCESS )
53445368
{
53455369
psa_fail_key_creation( slot, driver );

0 commit comments

Comments
 (0)