mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-30 17:44:15 +01:00
Merge pull request #48 from dgreen-arm/fix-zero-key-copy
Allow NULL buffers in psa_copy_key_material when the key size is zero
This commit is contained in:
commit
8a23dc6642
@ -1227,7 +1227,7 @@ static psa_status_t psa_copy_key_material( const psa_key_slot_t *source,
|
|||||||
buffer_size = PSA_KEY_EXPORT_MAX_SIZE( source->type,
|
buffer_size = PSA_KEY_EXPORT_MAX_SIZE( source->type,
|
||||||
psa_get_key_bits( source ) );
|
psa_get_key_bits( source ) );
|
||||||
buffer = mbedtls_calloc( 1, buffer_size );
|
buffer = mbedtls_calloc( 1, buffer_size );
|
||||||
if( buffer == NULL )
|
if( buffer == NULL && buffer_size != 0 )
|
||||||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||||
status = psa_internal_export_key( source, buffer, buffer_size, &length, 0 );
|
status = psa_internal_export_key( source, buffer, buffer_size, &length, 0 );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
@ -1235,6 +1235,7 @@ static psa_status_t psa_copy_key_material( const psa_key_slot_t *source,
|
|||||||
status = psa_import_key( target, source->type, buffer, length );
|
status = psa_import_key( target, source->type, buffer, length );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if( buffer_size != 0 )
|
||||||
mbedtls_platform_zeroize( buffer, buffer_size );
|
mbedtls_platform_zeroize( buffer, buffer_size );
|
||||||
mbedtls_free( buffer );
|
mbedtls_free( buffer );
|
||||||
return( status );
|
return( status );
|
||||||
|
Loading…
Reference in New Issue
Block a user