In export tests, also test PSA_KEY_EXPORT_MAX_SIZE

When testing psa_export_key or psa_export_public_key, test that the
expected result fits in the size given by PSA_KEY_EXPORT_MAX_SIZE.
This commit is contained in:
Gilles Peskine 2018-10-29 15:18:41 +01:00
parent 49c2591916
commit d8b7d4f87e

View File

@ -1021,6 +1021,7 @@ void import_export( data_t *data,
ASSERT_COMPARE( exported, exported_length, ASSERT_COMPARE( exported, exported_length,
reexported, reexported_length ); reexported, reexported_length );
} }
TEST_ASSERT( exported_length <= PSA_KEY_EXPORT_MAX_SIZE( type, got_bits ) );
destroy: destroy:
/* Destroy the key */ /* Destroy the key */
@ -1070,8 +1071,16 @@ void import_export_public_key( data_t *data,
&exported_length ); &exported_length );
TEST_ASSERT( status == expected_export_status ); TEST_ASSERT( status == expected_export_status );
if( status == PSA_SUCCESS ) if( status == PSA_SUCCESS )
{
psa_key_type_t public_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( type );
size_t bits;
TEST_ASSERT( psa_get_key_information( slot, NULL, &bits ) ==
PSA_SUCCESS );
TEST_ASSERT( expected_public_key->len <=
PSA_KEY_EXPORT_MAX_SIZE( public_type, bits ) );
ASSERT_COMPARE( expected_public_key->x, expected_public_key->len, ASSERT_COMPARE( expected_public_key->x, expected_public_key->len,
exported, exported_length ); exported, exported_length );
}
exit: exit:
mbedtls_free( exported ); mbedtls_free( exported );