Skip to content

Commit b22d6cc

Browse files
author
Nir Sonnenschein
committed
Make number of key slots externally configurable
changes to make number of key slots externally configurable changed define name from PSA_KEY_SLOT_COUNT to MBEDTLS_PSA_KEY_SLOT_COUNT
1 parent d668bae commit b22d6cc

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

include/psa/crypto_extra.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ psa_status_t mbedtls_psa_inject_entropy(const unsigned char *seed,
121121
size_t seed_size);
122122

123123

124+
/* The Number of key slots (plus one because 0 is not used).
125+
* The value is a compile-time constant for now, for simplicity. */
126+
#if defined(MBEDTLS_PSA_KEY_SLOT_COUNT)
127+
#else
128+
#define MBEDTLS_PSA_KEY_SLOT_COUNT 32
129+
#endif /*MBEDTLS_PSA_KEY_SLOT_COUNT*/
130+
131+
124132
#ifdef __cplusplus
125133
}
126134
#endif

library/psa_crypto_slot_management.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
typedef struct
4848
{
49-
psa_key_slot_t key_slots[PSA_KEY_SLOT_COUNT];
49+
psa_key_slot_t key_slots[MBEDTLS_PSA_KEY_SLOT_COUNT];
5050
unsigned key_slots_initialized : 1;
5151
} psa_global_data_t;
5252

@@ -90,7 +90,7 @@ psa_status_t psa_initialize_key_slots( void )
9090
void psa_wipe_all_key_slots( void )
9191
{
9292
psa_key_handle_t key;
93-
for( key = 1; key <= PSA_KEY_SLOT_COUNT; key++ )
93+
for( key = 1; key <= MBEDTLS_PSA_KEY_SLOT_COUNT; key++ )
9494
{
9595
psa_key_slot_t *slot = &global_data.key_slots[key - 1];
9696
(void) psa_wipe_key_slot( slot );
@@ -108,7 +108,7 @@ void psa_wipe_all_key_slots( void )
108108
*/
109109
static psa_status_t psa_internal_allocate_key_slot( psa_key_handle_t *handle )
110110
{
111-
for( *handle = PSA_KEY_SLOT_COUNT; *handle != 0; --( *handle ) )
111+
for( *handle = MBEDTLS_PSA_KEY_SLOT_COUNT; *handle != 0; --( *handle ) )
112112
{
113113
psa_key_slot_t *slot = &global_data.key_slots[*handle - 1];
114114
if( ! slot->allocated )

library/psa_crypto_slot_management.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
#ifndef PSA_CRYPTO_SLOT_MANAGEMENT_H
2323
#define PSA_CRYPTO_SLOT_MANAGEMENT_H
2424

25-
/* Number of key slots (plus one because 0 is not used).
26-
* The value is a compile-time constant for now, for simplicity. */
27-
#define PSA_KEY_SLOT_COUNT 32
28-
2925
/** Access a key slot at the given handle.
3026
*
3127
* \param handle Key handle to query.

library/psa_crypto_storage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern "C" {
5151
* - Using the ITS backend, all key ids are ok except 0xFFFFFF52
5252
* (#PSA_CRYPTO_ITS_RANDOM_SEED_UID) for which the file contains the
5353
* device's random seed (if this feature is enabled).
54-
* - Only key ids from 1 to #PSA_KEY_SLOT_COUNT are actually used.
54+
* - Only key ids from 1 to #MBEDTLS_PSA_KEY_SLOT_COUNT are actually used.
5555
*
5656
* Since we need to preserve the random seed, avoid using that key slot.
5757
* Reserve a whole range of key slots just in case something else comes up.

0 commit comments

Comments
 (0)