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:
parent
2b56bc84f5
commit
9cca31654c
1 changed files with 12 additions and 7 deletions
|
@ -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);
|
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
|
||||||
size_t export_size = 0;
|
size_t export_size = 0;
|
||||||
|
|
||||||
status = get_expected_key_size( attributes, &export_size );
|
/* If this is not to generate a key in a secure element or cryptoprocessor
|
||||||
if( status != PSA_SUCCESS )
|
* with storage. */
|
||||||
return( status );
|
|
||||||
|
|
||||||
slot->key.data = mbedtls_calloc(1, export_size);
|
|
||||||
if( slot->key.data == NULL )
|
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 )
|
switch( location )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue