-
Notifications
You must be signed in to change notification settings - Fork 96
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
Secure element keys: save the key size #191
Secure element keys: save the key size #191
Conversation
This commit blindingly copies the size from the attributes. This is not correct for copy and import.
Add a parameter to the key import method of a secure element driver to make it report the key size in bits. This is necessary (otherwise the core has no idea what the bit-size is), and making import report it is easier than adding a separate method (for other key creation methods, this information is an input, not an output).
For a key in a secure element, save the bit size alongside the slot number. This is a quick-and-dirty implementation where the storage format depends on sizeof(size_t), which is fragile. This should be replaced by a more robust implementation before going into production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have two questions but other than that it looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good to me. I only have one question regarding the test code change, that seems a bit suspicious to me.
@@ -1035,6 +1035,11 @@ psa_status_t psa_destroy_key( psa_key_handle_t handle ) | |||
/* Return the size of the key in the given slot, in bits. */ | |||
static size_t psa_get_key_slot_bits( const psa_key_slot_t *slot ) | |||
{ | |||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C) | |||
if( psa_get_se_driver( slot->lifetime, NULL, NULL ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: For the sake of consistency, this could be tested for equality explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function returns a boolean with the type int
(since we're still not using stdbool
). Mbed TLS usually (but not fully consistently) uses explicit comparison to 0 even for booleans, but PSA crypto code doesn't.
@@ -445,6 +480,9 @@ void key_creation_import_export( int min_slot, int restart ) | |||
/* Test that the key was created in the expected slot. */ | |||
TEST_ASSERT( ram_slots[min_slot].type == PSA_KEY_TYPE_RAW_DATA ); | |||
|
|||
/* Test the key attributes and the key data. */ | |||
if( ! check_key_attributes( handle, &attributes ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't this put inside an assertion macro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion macros are in check_key_attributes
. That function returns ok/not-ok, and if it returns not-ok, the test failure data has already been recorded, so test_fail
should not be called again.
For a key in a secure element, the core has no way to compute the bit size. Store it as part of the key metadata in memory and in persistent storage. When importing a key, ask the driver what the bit size is.
Extracted from #183