Skip to content

Commit 95aaa97

Browse files
valeriosettikartben
authored andcommitted
mbedtls: add Kconfig to select the number of key slot in PSA Crypto core
Adding new CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT to select the number of key slots in PSA Crypto core. The default value is 16. Be aware that key slots consume RAM memory even if unused, so the proper value should be a compromise between the number of slots required by the application and the available RAM in the system. This commit also: - updates tests/crypto/secp256r1/mbedtls.conf to showcase how to use this new symbol to reduce RAM footprint. - tests/bsim/bluetooth/mesh/overlay_psa.conf to support all the keys used in the test. Signed-off-by: Valerio Setti <[email protected]>
1 parent 2f6ea8e commit 95aaa97

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

doc/releases/migration-guide-4.1.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ Mbed TLS
3636
:kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_LEGACY_RNG`. This helps in reducing
3737
ROM/RAM footprint of the Mbed TLS library.
3838

39+
* The newly-added Kconfig option :kconfig:option:`CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT`
40+
allows to specify the number of key slots available in the PSA Crypto core.
41+
Previously this value was not explicitly set, so Mbed TLS's default value of
42+
32 was used. The new Kconfig option defaults to 16 instead in order to find
43+
a reasonable compromise between RAM consumption and most common use cases.
44+
It can be further trimmed down to reduce RAM consumption if the final
45+
application doesn't need that many key slots simultaneously.
46+
3947
Trusted Firmware-M
4048
==================
4149

doc/releases/release-notes-4.1.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ Libraries / Subsystems
273273
(or remove, if no other component makes use of it) heap memory requirements
274274
from the final application.
275275

276+
* The Kconfig symbol :kconfig:option:`CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT` was
277+
added to allow selecting the number of key slots available in the Mbed TLS
278+
implementation of the PSA Crypto core. It defaults to 16. Since each
279+
slot consumes RAM memory even if unused, this value can be tweaked in order
280+
to minimize RAM usage.
281+
276282
* CMSIS-NN
277283

278284
* FPGA

modules/mbedtls/Kconfig.tls-generic

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,19 @@ config MBEDTLS_PSA_STATIC_KEY_SLOTS
585585
contain the largest asymmetric/symmetric key type enabled in the build
586586
through PSA_WANT symbols.
587587

588+
config MBEDTLS_PSA_KEY_SLOT_COUNT
589+
int "Number of key slots in PSA Crypto core"
590+
default 16
591+
help
592+
Set the number of key slots that are available in the PSA Crypto core.
593+
Be aware that each slot, even if unused, increases RAM consumption
594+
by ~40 bytes plus:
595+
* the length of the largest asymmetric/symmetric key type enabled in
596+
the build through PSA_WANT symbols, if MBEDTLS_PSA_STATIC_KEY_SLOTS
597+
is set. (This is all defined statically at build time).
598+
* the heap-allocated memory to store the key material of a given slot,
599+
if it is used and MBEDTLS_PSA_STATIC_KEY_SLOTS is not set.
600+
588601
endif # MBEDTLS_PSA_CRYPTO_C
589602

590603
config MBEDTLS_SSL_DTLS_CONNECTION_ID

modules/mbedtls/configs/config-tls-generic.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@
483483
#endif
484484

485485
#if defined(CONFIG_ARCH_POSIX) && !defined(CONFIG_PICOLIBC)
486-
#define MBEDTLS_PSA_KEY_SLOT_COUNT 64 /* for BLE Mesh tests */
487486
#define MBEDTLS_PSA_ITS_FILE_C
488487
#define MBEDTLS_FS_IO
489488
#endif
@@ -498,6 +497,10 @@
498497
#define MBEDTLS_PSA_STATIC_KEY_SLOTS
499498
#endif
500499

500+
#if defined(CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT)
501+
#define MBEDTLS_PSA_KEY_SLOT_COUNT CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT
502+
#endif
503+
501504
#if defined(CONFIG_MBEDTLS_USE_PSA_CRYPTO)
502505
#define MBEDTLS_USE_PSA_CRYPTO
503506
#endif
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Enable PSA as a crypto backend in host
22
CONFIG_BT_USE_PSA_API=y
33

4+
# Increase the number of key slots in PSA Crypto core
5+
CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=64
6+
47
# Enable mbedTLS PSA as a crypto backend
58
CONFIG_BT_MESH_USES_MBEDTLS_PSA=y

tests/crypto/secp256r1/mbedtls.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ CONFIG_MBEDTLS=y
22
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
33
CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED=y
44
CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS=y
5+
CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=2
56

67
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT=y
78
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE=y

0 commit comments

Comments
 (0)