Skip to content
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

Conversation

gilles-peskine-arm
Copy link
Collaborator

@gilles-peskine-arm gilles-peskine-arm commented Jul 29, 2019

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

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.
@gilles-peskine-arm gilles-peskine-arm changed the base branch from development to psa-api-1.0-beta July 29, 2019 16:13
@gilles-peskine-arm gilles-peskine-arm changed the title Psa se driver key bits Secure element keys: save the key size Jul 29, 2019
@gilles-peskine-arm gilles-peskine-arm added api-spec Issue or PR about the PSA specifications enhancement New feature or request needs: review The pull request is ready for review. This generally means that it has no known issues. labels Jul 29, 2019
Copy link
Collaborator

@yanesca yanesca left a 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.

library/psa_crypto_core.h Show resolved Hide resolved
Copy link
Contributor

@k-stachowiak k-stachowiak left a 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 ) )
Copy link
Contributor

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.

Copy link
Collaborator Author

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 ) )
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

@gilles-peskine-arm gilles-peskine-arm removed the needs: review The pull request is ready for review. This generally means that it has no known issues. label Aug 5, 2019
@gilles-peskine-arm gilles-peskine-arm merged commit 640804b into ARMmbed:psa-api-1.0-beta Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-spec Issue or PR about the PSA specifications enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants