Skip to content

Commit 25a71f3

Browse files
valeriosettijhedberg
authored andcommitted
modules: mbedtls: let CSPRNG_AVAILABLE select ENTROPY_GENERATOR
It might happen that some boards have "zephyr,entropy" node set, but under the hood the driver is not available (ex: entropy_bt_hci not being available because CONFIG_BT_HOST is not enabled in the build). This commit changes the behavior so that: 1. if "zephyr,entropy" is set in the DT then CONFIG_CSPRNG_AVAILABLE get enabled; 2. CONFIG_CSPRNG_AVAILABLE selects CONFIG_ENTROPY_GENERATOR 3. if there really is a driver available then CONFIG_ENTROPY_HAS_DRIVER will be enabled by that driver; 4. CONFIG_ENTROPY_HAS_DRIVER selects CONFIG_CSPRNG_ENABLED; 4. Mbed TLS can consume the CONFIG_CSPRNG_ENABLED information to decide whethere to enable CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG or the legacy CONFIG_MBEDTLS_PSA_CRYPTO_LEGACY_RNG. Signed-off-by: Valerio Setti <[email protected]>
1 parent b4556ea commit 25a71f3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

modules/mbedtls/Kconfig.mbedtls

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,13 @@ config MBEDTLS_SSL_EXTENDED_MASTER_SECRET
522522
which ensures that master secrets are different for every
523523
connection and every session.
524524

525+
# CONFIG_CSPRNG_AVAILABLE must automatically enable CONFIG_ENTROPY_GENERATOR.
526+
# But we're doing it here because this enablement should be gated by Mbed TLS
527+
# being also enabled in the build, otherwise this will result in entropy
528+
# drivers being enabled without anyone needing them.
529+
config CSPRNG_AVAILABLE
530+
select ENTROPY_GENERATOR
531+
525532
choice MBEDTLS_PSA_CRYPTO_RNG_SOURCE
526533
prompt "Select random source for built-in PSA crypto"
527534
depends on MBEDTLS_PSA_CRYPTO_C
@@ -530,12 +537,11 @@ choice MBEDTLS_PSA_CRYPTO_RNG_SOURCE
530537
# CONFIG_CSPRNG_ENABLED cannot be used for this because it gets enabled by
531538
# entropy drivers but these are gated by CONFIG_ENTROPY_GENERATOR which
532539
# is disabled by default.
533-
default MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG if CSPRNG_AVAILABLE
540+
default MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG if CSPRNG_ENABLED
534541
default MBEDTLS_PSA_CRYPTO_LEGACY_RNG
535542

536543
config MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
537544
bool "Use a cryptographically secure driver as random source"
538-
select ENTROPY_GENERATOR
539545
help
540546
Use a cryptographically secure random generator to provide random data
541547
instead of legacy Mbed TLS modules. This has a smaller footprint

0 commit comments

Comments
 (0)