crypto_se_driver: add public key exporting test
diff --git a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.data b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.data
index 7cdbc71..445a97a 100644
--- a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.data
+++ b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.data
@@ -13,6 +13,12 @@
Key exporting mock test: export failed
mock_export:PSA_ERROR_HARDWARE_FAILURE:PSA_ERROR_HARDWARE_FAILURE
+Public key exporting mock test
+mock_export_public:PSA_SUCCESS:PSA_SUCCESS
+
+Public key exporting mock test: export failed
+mock_export_public:PSA_ERROR_HARDWARE_FAILURE:PSA_ERROR_HARDWARE_FAILURE
+
Key generating mock test
mock_generate:PSA_SUCCESS:PSA_SUCCESS
diff --git a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function
index 58f8aa4..4f14f70 100644
--- a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function
+++ b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function
@@ -39,6 +39,14 @@
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;
psa_status_t return_value;
} mock_allocate_data;
@@ -53,6 +61,7 @@
{
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 ) );
@@ -119,6 +128,21 @@
return( mock_export_data.return_value );
}
+psa_status_t mock_export_public( psa_key_slot_number_t slot_number,
+ uint8_t *p_data,
+ size_t data_size,
+ size_t *p_data_length )
+{
+ (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( const psa_key_attributes_t *attributes,
const psa_drv_se_slot_usage_t *slot_usage,
psa_key_slot_number_t *slot_number )
@@ -286,3 +310,50 @@
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.slot_count = 1;
+ 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_RAW_DATA );
+
+ 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 );
+
+exit:
+ PSA_DONE( );
+ mock_teardown( );
+}
+/* END_CASE */