Skip to content

Commit 8a23dc6

Browse files
authored
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
2 parents 2a0f48a + 8096caf commit 8a23dc6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/psa_crypto.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,15 +1227,16 @@ static psa_status_t psa_copy_key_material( const psa_key_slot_t *source,
12271227
buffer_size = PSA_KEY_EXPORT_MAX_SIZE( source->type,
12281228
psa_get_key_bits( source ) );
12291229
buffer = mbedtls_calloc( 1, buffer_size );
1230-
if( buffer == NULL )
1230+
if( buffer == NULL && buffer_size != 0 )
12311231
return( PSA_ERROR_INSUFFICIENT_MEMORY );
12321232
status = psa_internal_export_key( source, buffer, buffer_size, &length, 0 );
12331233
if( status != PSA_SUCCESS )
12341234
goto exit;
12351235
status = psa_import_key( target, source->type, buffer, length );
12361236

12371237
exit:
1238-
mbedtls_platform_zeroize( buffer, buffer_size );
1238+
if( buffer_size != 0 )
1239+
mbedtls_platform_zeroize( buffer, buffer_size );
12391240
mbedtls_free( buffer );
12401241
return( status );
12411242
}

0 commit comments

Comments
 (0)