Skip to content

Commit 08bd9c7

Browse files
valeriosettinashif
authored andcommitted
mbedtls: use CSPRNG whenever possible as PSA random source
The main problem of MBEDTLS_PSA_CRYPTO_LEGACY_RNG is that it brings in some legacy modules (entropy + ctr_drbg/hmac_drbg) which means extra ROM/RAM footprint. MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG instead simply calls to the CSPRNG which makes it definitely smaller. Signed-off-by: Valerio Setti <[email protected]>
1 parent ac6d834 commit 08bd9c7

File tree

12 files changed

+16
-10
lines changed

12 files changed

+16
-10
lines changed

doc/releases/migration-guide-4.1.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Modules
3030
Mbed TLS
3131
========
3232

33+
* If a platform has a CSPRNG source available (i.e. :kconfig:option:`CONFIG_CSPRNG_ENABLED`
34+
is set), then the Kconfig option :kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG`
35+
is the default choice for random number source instead of
36+
:kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_LEGACY_RNG`. This helps in reducing
37+
ROM/RAM footprint of the Mbed TLS library.
38+
3339
Trusted Firmware-M
3440
==================
3541

modules/mbedtls/Kconfig.tls-generic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ config MBEDTLS_SSL_EXTENDED_MASTER_SECRET
481481
choice MBEDTLS_PSA_CRYPTO_RNG_SOURCE
482482
prompt "Select random source for built-in PSA crypto"
483483
depends on MBEDTLS_PSA_CRYPTO_C
484+
default MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG if CSPRNG_ENABLED
484485
default MBEDTLS_PSA_CRYPTO_LEGACY_RNG
485486

486487
config MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
CONFIG_ENTROPY_GENERATOR=y
4-
CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
CONFIG_ENTROPY_GENERATOR=y
4-
CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y

tests/bsim/bluetooth/host/gatt/caching/psa_overlay.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ CONFIG_MBEDTLS_PSA_CRYPTO_C=y
44
CONFIG_PSA_CRYPTO_ENABLE_ALL=y
55

66
CONFIG_ENTROPY_GENERATOR=y
7-
CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y

tests/bsim/bluetooth/ll/conn/psa_overlay.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ CONFIG_MBEDTLS_PSA_CRYPTO_C=y
44
CONFIG_PSA_CRYPTO_ENABLE_ALL=y
55

66
CONFIG_ENTROPY_GENERATOR=y
7-
CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y

tests/crypto/mbedtls_psa/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ CONFIG_ZTEST=y
33

44
CONFIG_MBEDTLS=y
55
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
6-
CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y

tests/crypto/mbedtls_psa/testcase.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
# - no TF-M enabled devices because we assume that the TF-M implementation
1212
# of PSA crypto is working fine on the platforms that support TF-M.
1313
# - platform should be testable by the CI.
14-
# - enable CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG in order to reduce as much
15-
# as possible usage of legacy modules in Mbed TLS.
1614
# - pick 1 platform which supports entropy driver and 1 which does not. The
1715
# latter case will allow to test
1816
# CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG.
@@ -34,8 +32,11 @@ tests:
3432
# Pick a platform which does not have an entropy driver. In this case we
3533
# enable the timer random generator because it's always available on all
3634
# platforms.
35+
# Explicitly select CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG because this is
36+
# not "automatically selected" when there is no CSPRNG available.
3737
integration_platforms:
3838
- qemu_x86
3939
extra_configs:
40+
- CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y
4041
- CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG=y
4142
- CONFIG_TEST_RANDOM_GENERATOR=y

tests/crypto/secp256r1/mbedtls.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
CONFIG_MBEDTLS=y
2-
CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y
32
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
43
CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED=y
54

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
CONFIG_MBEDTLS=y
2-
CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y
32
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
43
CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED=y
54
CONFIG_MBEDTLS_PSA_P256M_DRIVER_RAW=y

0 commit comments

Comments
 (0)