Skip to content

Add mock tests for hooks for secure element drivers #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 22, 2019
Merged
4 changes: 3 additions & 1 deletion library/psa_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,9 @@ psa_status_t psa_import_key( const psa_key_attributes_t *attributes,
if( driver != NULL )
{
const psa_drv_se_t *drv = psa_get_se_driver_methods( driver );
size_t bits;
/* The driver should set the number of key bits, however in
* case it doesn't, we initialize bits to an invalid value. */
size_t bits = PSA_MAX_KEY_BITS + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a comment in the code explaining the reason, to improve the code's readability. Others will have the same question.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this change was added in commit "Parametrize key bits in import mock test", which doesn't seem right if all one intends to do is updating a test as the title would imply. If the core has to be updated together with the test change, revise the commit message. If the core has a bug, explain it in the commit message and make a change to fix the bug separate from the mock test updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've split this out into a separate commit and added an explanation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment in the code about why you chose the value you did.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a code comment.

if( drv->key_management == NULL ||
drv->key_management->p_import == NULL )
{
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ add_test_suite(psa_crypto_init)
add_test_suite(psa_crypto_metadata)
add_test_suite(psa_crypto_persistent_key)
add_test_suite(psa_crypto_se_driver_hal)
add_test_suite(psa_crypto_se_driver_hal_mocks)
add_test_suite(psa_crypto_slot_management)
add_test_suite(psa_its)
add_test_suite(shax)
Expand Down
47 changes: 47 additions & 0 deletions tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
SE key importing mock test
mock_import:PSA_SUCCESS:PSA_SUCCESS:0:PSA_SUCCESS

SE key importing mock test: max key bits
mock_import:PSA_SUCCESS:PSA_SUCCESS:PSA_MAX_KEY_BITS:PSA_SUCCESS

SE key importing mock test: more than max key bits
mock_import:PSA_SUCCESS:PSA_ERROR_NOT_SUPPORTED:PSA_MAX_KEY_BITS+1:PSA_ERROR_NOT_SUPPORTED

SE key importing mock test: alloc failed
mock_import:PSA_ERROR_HARDWARE_FAILURE:PSA_SUCCESS:0:PSA_ERROR_HARDWARE_FAILURE

SE key importing mock test: import failed
mock_import:PSA_SUCCESS:PSA_ERROR_HARDWARE_FAILURE:0:PSA_ERROR_HARDWARE_FAILURE

SE key exporting mock test
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

SE key generating mock test: alloc failed
mock_generate:PSA_ERROR_HARDWARE_FAILURE:PSA_SUCCESS:PSA_ERROR_HARDWARE_FAILURE

SE key generating mock test: generating failed
mock_generate:PSA_SUCCESS:PSA_ERROR_HARDWARE_FAILURE:PSA_ERROR_HARDWARE_FAILURE

SE signing mock test
mock_sign:PSA_SUCCESS:PSA_SUCCESS

SE signing mock test: sign failed
mock_sign:PSA_ERROR_HARDWARE_FAILURE:PSA_ERROR_HARDWARE_FAILURE

SE verification mock test
mock_verify:PSA_SUCCESS:PSA_SUCCESS

SE verification mock test: verify failed
mock_verify:PSA_ERROR_HARDWARE_FAILURE:PSA_ERROR_HARDWARE_FAILURE
Loading