psa: driver wrapper: Fix buffer allocation in case of key generation

In case of a secure element or cryptoprocessor with
storage, when generating a key, the key material is
not exported from the secure element or cryptoprocessor
thus there is no need to allocate a buffer in that case.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-12-05 19:07:47 +01:00
parent 2b56bc84f5
commit 9cca31654c

View file

@ -341,6 +341,10 @@ psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attrib
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
size_t export_size = 0;
/* If this is not to generate a key in a secure element or cryptoprocessor
* with storage. */
if( slot->key.data == NULL )
{
status = get_expected_key_size( attributes, &export_size );
if( status != PSA_SUCCESS )
return( status );
@ -349,6 +353,7 @@ psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attrib
if( slot->key.data == NULL )
return( PSA_ERROR_INSUFFICIENT_MEMORY );
slot->key.bytes = export_size;
}
switch( location )
{