Skip to content

Commit 2f6ea8e

Browse files
valeriosettikartben
authored andcommitted
mbedtls: add Kconfig symbol CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS
Adding the Kconfig symbol CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS to allow Mbed TLS's PSA Crypto core to use static key buffers to store key's material. This helps reducing heap memory usage and, potentially, it also discard code implementing heap memory management if there's no other module in the build that makes use of it. Signed-off-by: Valerio Setti <[email protected]>
1 parent f0944a2 commit 2f6ea8e

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

doc/releases/release-notes-4.1.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ Libraries / Subsystems
267267

268268
* Crypto
269269

270+
* The Kconfig symbol :kconfig:option:`CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS` was
271+
added to allow Mbed TLS to use statically allocated buffers to store key material
272+
in its PSA Crypto core instead of heap-allocated ones. This can help reduce
273+
(or remove, if no other component makes use of it) heap memory requirements
274+
from the final application.
275+
270276
* CMSIS-NN
271277

272278
* FPGA

modules/mbedtls/Kconfig.tls-generic

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,10 @@ config MBEDTLS_LMS
554554
depends on MBEDTLS_SHA256
555555
select PSA_WANT_ALG_SHA_256
556556

557+
if MBEDTLS_PSA_CRYPTO_C
558+
557559
config MBEDTLS_PSA_P256M_DRIVER_ENABLED
558560
bool "P256-M driver"
559-
depends on MBEDTLS_PSA_CRYPTO_C
560561
imply PSA_WANT_ALG_SHA_256
561562
help
562563
Enable support for the optimized sofware implementation of the secp256r1
@@ -570,6 +571,22 @@ config MBEDTLS_PSA_P256M_DRIVER_RAW
570571
Warning: Usage of this Kconfig option is prohibited in Zephyr's codebase.
571572
Users can enable it in case of very memory-constrained devices, but be aware that the p256-m interface is absolutely not guaranted to remain stable over time.
572573

574+
config MBEDTLS_PSA_STATIC_KEY_SLOTS
575+
bool "Use statically allocated key buffers to store key material"
576+
default y if !MBEDTLS_ENABLE_HEAP
577+
help
578+
By default Mbed TLS's PSA Crypto core uses heap memory to store the
579+
key material for each key slot. This might impose an undesired
580+
requirement to support heap memory and its management code, affecting
581+
RAM and ROM footprints at the same time.
582+
Enabling this symbol causes Mbed TLS to pre-allocate all the key slot
583+
buffers that are used to store the key material at build time, thus
584+
removing the need for heap memory. Each buffer will be sized to
585+
contain the largest asymmetric/symmetric key type enabled in the build
586+
through PSA_WANT symbols.
587+
588+
endif # MBEDTLS_PSA_CRYPTO_C
589+
573590
config MBEDTLS_SSL_DTLS_CONNECTION_ID
574591
bool "DTLS Connection ID extension"
575592
depends on MBEDTLS_DTLS

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@
494494

495495
#endif /* CONFIG_MBEDTLS_PSA_CRYPTO_C */
496496

497+
#if defined(CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS)
498+
#define MBEDTLS_PSA_STATIC_KEY_SLOTS
499+
#endif
500+
497501
#if defined(CONFIG_MBEDTLS_USE_PSA_CRYPTO)
498502
#define MBEDTLS_USE_PSA_CRYPTO
499503
#endif

tests/crypto/secp256r1/mbedtls.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG_MBEDTLS=y
22
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
33
CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED=y
4+
CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS=y
45

56
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT=y
67
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE=y

0 commit comments

Comments
 (0)