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,14 +341,19 @@ 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;
status = get_expected_key_size( attributes, &export_size );
if( status != PSA_SUCCESS )
return( status );
slot->key.data = mbedtls_calloc(1, export_size);
/* If this is not to generate a key in a secure element or cryptoprocessor
* with storage. */
if( slot->key.data == NULL )
return( PSA_ERROR_INSUFFICIENT_MEMORY );
slot->key.bytes = export_size;
{
status = get_expected_key_size( attributes, &export_size );
if( status != PSA_SUCCESS )
return( status );
slot->key.data = mbedtls_calloc(1, export_size);
if( slot->key.data == NULL )
return( PSA_ERROR_INSUFFICIENT_MEMORY );
slot->key.bytes = export_size;
}
switch( location )
{