psa-core: remove unnecessary element in psa_key_slot_t
Instead of checking for "in_use" to be true/false or "key.data"
to be not NULL, simply check that "key.bytes" is 0/not-0.
psa_allocate_buffer_to_slot() will update this value whenever
a new slot is allocated (for the fully static case "allocated"
actually mean "taken").
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index 696e830..8c2c543 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -706,15 +706,9 @@
size_t buffer_length)
{
#if defined(MBEDTLS_PSA_STATIC_KEY_SLOTS)
- if (slot->key.in_use) {
- return PSA_ERROR_ALREADY_EXISTS;
- }
-
if (buffer_length > ((size_t) MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE)) {
return PSA_ERROR_NOT_SUPPORTED;
}
-
- slot->key.in_use = 1;
#else
if (slot->key.data != NULL) {
return PSA_ERROR_ALREADY_EXISTS;
@@ -1189,9 +1183,7 @@
psa_status_t psa_remove_key_data_from_memory(psa_key_slot_t *slot)
{
-#if defined(MBEDTLS_PSA_STATIC_KEY_SLOTS)
- slot->key.in_use = 0;
-#else /* MBEDTLS_PSA_STATIC_KEY_SLOTS */
+#if !defined(MBEDTLS_PSA_STATIC_KEY_SLOTS)
if (slot->key.data != NULL) {
mbedtls_zeroize_and_free(slot->key.data, slot->key.bytes);
}
@@ -2113,13 +2105,7 @@
* storage ( thus not in the case of importing a key in a secure element
* with storage ( MBEDTLS_PSA_CRYPTO_SE_C ) ),we have to allocate a
* buffer to hold the imported key material. */
-#if defined(MBEDTLS_PSA_STATIC_KEY_SLOTS)
- int is_slot_unused = (slot->key.in_use == 0);
-#else
- int is_slot_unused = (slot->key.data == NULL);
-#endif
-
- if (is_slot_unused) {
+ if (slot->key.bytes == 0) {
if (psa_key_lifetime_is_external(attributes->lifetime)) {
status = psa_driver_wrapper_get_key_buffer_size_from_key_data(
attributes, data, data_length, &storage_size);
@@ -8036,13 +8022,7 @@
* storage ( thus not in the case of generating a key in a secure element
* with storage ( MBEDTLS_PSA_CRYPTO_SE_C ) ),we have to allocate a
* buffer to hold the generated key material. */
-#if defined(MBEDTLS_PSA_STATIC_KEY_SLOTS)
- int is_slot_unused = (slot->key.in_use == 0);
-#else
- int is_slot_unused = (slot->key.data == NULL);
-#endif
-
- if (is_slot_unused) {
+ if (slot->key.bytes == 0) {
if (PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime) ==
PSA_KEY_LOCATION_LOCAL_STORAGE) {
status = psa_validate_key_type_and_size_for_key_generation(