mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-25 01:35:38 +00:00
crypto_se_driver: add public key exporting test
This commit is contained in:
parent
903b5da51c
commit
136901c24c
|
@ -13,6 +13,12 @@ mock_export:PSA_SUCCESS:PSA_SUCCESS
|
|||
SE key exporting mock test: export failed
|
||||
mock_export:PSA_ERROR_HARDWARE_FAILURE:PSA_ERROR_HARDWARE_FAILURE
|
||||
|
||||
SE public key exporting mock test
|
||||
mock_export_public:PSA_SUCCESS:PSA_SUCCESS
|
||||
|
||||
SE public key exporting mock test: export failed
|
||||
mock_export_public:PSA_ERROR_HARDWARE_FAILURE:PSA_ERROR_HARDWARE_FAILURE
|
||||
|
||||
SE key generating mock test
|
||||
mock_generate:PSA_SUCCESS:PSA_SUCCESS:PSA_SUCCESS
|
||||
|
||||
|
|
|
@ -30,6 +30,14 @@ static struct
|
|||
psa_status_t return_value;
|
||||
} mock_export_data;
|
||||
|
||||
static struct
|
||||
{
|
||||
uint16_t called;
|
||||
psa_key_slot_number_t slot_number;
|
||||
size_t data_size;
|
||||
psa_status_t return_value;
|
||||
} mock_export_public_data;
|
||||
|
||||
static struct
|
||||
{
|
||||
uint16_t called;
|
||||
|
@ -47,6 +55,7 @@ static void mock_teardown( void )
|
|||
{
|
||||
memset( &mock_import_data, 0, sizeof( mock_import_data ) );
|
||||
memset( &mock_export_data, 0, sizeof( mock_export_data ) );
|
||||
memset( &mock_export_public_data, 0, sizeof( mock_export_public_data ) );
|
||||
memset( &mock_allocate_data, 0, sizeof( mock_allocate_data ) );
|
||||
memset( &mock_destroy_data, 0, sizeof( mock_destroy_data ) );
|
||||
memset( &mock_generate_data, 0, sizeof( mock_generate_data ) );
|
||||
|
@ -107,6 +116,23 @@ psa_status_t mock_export( psa_drv_se_context_t *context,
|
|||
return( mock_export_data.return_value );
|
||||
}
|
||||
|
||||
psa_status_t mock_export_public( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number,
|
||||
uint8_t *p_data,
|
||||
size_t data_size,
|
||||
size_t *p_data_length )
|
||||
{
|
||||
(void) context;
|
||||
(void) p_data;
|
||||
(void) p_data_length;
|
||||
|
||||
mock_export_public_data.called++;
|
||||
mock_export_public_data.slot_number = slot_number;
|
||||
mock_export_public_data.data_size = data_size;
|
||||
|
||||
return( mock_export_public_data.return_value );
|
||||
}
|
||||
|
||||
psa_status_t mock_allocate( psa_drv_se_context_t *drv_context,
|
||||
void *persistent_data,
|
||||
const psa_key_attributes_t *attributes,
|
||||
|
@ -305,3 +331,52 @@ exit:
|
|||
mock_teardown( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mock_export_public( int mock_export_public_return_value,
|
||||
int expected_result )
|
||||
{
|
||||
psa_drv_se_t driver;
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = 2;
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
|
||||
uint8_t exported[sizeof( key_material )];
|
||||
size_t exported_length;
|
||||
|
||||
mock_export_public_data.return_value = mock_export_public_return_value;
|
||||
memset( &driver, 0, sizeof( driver ) );
|
||||
memset( &key_management, 0, sizeof( key_management ) );
|
||||
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
|
||||
driver.key_management = &key_management;
|
||||
key_management.p_import = mock_import;
|
||||
key_management.p_export_public = mock_export_public;
|
||||
key_management.p_destroy = mock_destroy;
|
||||
key_management.p_allocate = mock_allocate;
|
||||
|
||||
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
|
||||
psa_set_key_id( &attributes, id );
|
||||
psa_set_key_lifetime( &attributes, lifetime );
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
|
||||
psa_set_key_type( &attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY );
|
||||
|
||||
PSA_ASSERT( psa_import_key( &attributes,
|
||||
key_material, sizeof( key_material ),
|
||||
&handle ) );
|
||||
|
||||
TEST_ASSERT( psa_export_public_key( handle, exported, sizeof(exported),
|
||||
&exported_length ) == expected_result );
|
||||
TEST_ASSERT( mock_export_public_data.called == 1 );
|
||||
|
||||
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||
TEST_ASSERT( mock_destroy_data.called == 1 );
|
||||
|
||||
exit:
|
||||
PSA_DONE( );
|
||||
mock_teardown( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
|
Loading…
Reference in a new issue