Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mbedtls: some enhancement for PSA crypto core #80136

Merged
merged 3 commits into from
Nov 20, 2024

Conversation

valeriosetti
Copy link
Collaborator

@valeriosetti valeriosetti commented Oct 21, 2024

  • Enable legacy CONFIG_MBEDTLS_CIPHER_AES_ENABLED when CONFIG_PSA_WANT_KEY_TYPE_AES is set and Mbed TLS is the PSA crypto API provider (i.e. CONFIG_MBEDTLS_PSA_CRYPTO_C). This mimic what happens in Mbed TLS at build time.
  • Enable CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG instead of CONFIG_MBEDTLS_PSA_CRYPTO_LEGACY_RNG if the platform has any CSPRNG enabled. This helps reducing RAM/ROM footprint.

ceolin
ceolin previously approved these changes Nov 3, 2024
jhedberg
jhedberg previously approved these changes Nov 3, 2024
jhedberg
jhedberg previously approved these changes Nov 6, 2024
nashif
nashif previously approved these changes Nov 6, 2024
@tomi-font tomi-font added this to the v4.0.0 milestone Nov 6, 2024
tomi-font
tomi-font previously approved these changes Nov 6, 2024
Comment on lines 79 to 81
is set), then the Kconfig option :kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG`
is the default choice for random number source instead of
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
is set), then the Kconfig option :kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG`
is the default choice for random number source instead of
is set), the Kconfig option :kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG`
is now the default choice for the random number source instead of

@tomi-font
Copy link
Collaborator

please review @ceolin

str4t0m
str4t0m previously approved these changes Nov 7, 2024
Copy link
Collaborator

@frkv frkv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enhancements! Hope this gets in quickly

@mmahadevan108 mmahadevan108 modified the milestones: v4.0.0, v4.1.0 Nov 8, 2024
d3zd3z
d3zd3z previously approved these changes Nov 13, 2024
Auto-select MBEDTLS_CIPHER_AES_ENABLED when AES support is requested
through PSA (i.e. CONFIG_PSA_WANT_KEY_TYPE_AES) and the PSA support is
provided through Mbed TLS itself (i.e. CONFIG_MBEDTLS_PSA_CRYPTO_C).

This mimic what happens in Mbed TLS at build time: if AES support
is required through PSA, but there's no one else providing it
(i.e. no TF-M in Zephyr) then provide this support through legacy
AES module.

This is useful in samples/tests so that the user can simply use the
PSA_WANT symbol to ask for AES support in PSA crypto and then tune
the AES features (ex: CONFIG_MBEDTLS_AES_ROM_TABLES) without the need
to also define CONFIG_MBEDTLS_CIPHER_AES_ENABLED.

Signed-off-by: Valerio Setti <[email protected]>
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]>
As long as MBEDTLS_ENTROPY_C is enabled, Mbed TLS needs to
poll some entropy source to gather data that will then be
processed by CTR/HMAC-DRBG modules. This means that in most
of the cases, once MBEDTLS_ENTROPY_C is enabled then also
MBEDTLS_ENTROPY_POLL_ZEPHYR needs to be enabled. This was
done manually until now, as the long list of samples/tests
demonstrate.

This commit solves this dependency by defaulting
MBEDTLS_ENTROPY_POLL_ZEPHYR to on as soon as
MBEDTLS_ENTROPY_C is set. As a consequence, all manual
enablement of MBEDTLS_ENTROPY_POLL_ZEPHYR in samples/tests
are removed.

Signed-off-by: Valerio Setti <[email protected]>
@valeriosetti
Copy link
Collaborator Author

Sorry for the double rebase, but since 4.0 release was published last week, I need to move documentation updates in this PR from migration-guide-4.0 to migration-guide-4.1. The 2 rebase are as follows:

This way it should be easier to check the changes that I did.

Copy link
Collaborator

@tomi-font tomi-font left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit I just realized. Thanks for the double rebase!

@@ -30,6 +30,12 @@ Modules
Mbed TLS
========

* If a platform has a CSPRNG source available (i.e. :kconfig:option:`CONFIG_CSPRNG_ENABLED`
is set), then the Kconfig option :kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG`
is the default choice for random number source instead of
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
is the default choice for random number source instead of
is now the default choice for random number source instead of

is set), then the Kconfig option :kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG`
is the default choice for random number source instead of
:kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_LEGACY_RNG`. This helps in reducing
ROM/RAM footprint of the Mbed TLS library.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ROM/RAM footprint of the Mbed TLS library.
the ROM/RAM footprint of the Mbed TLS library.

@valeriosetti
Copy link
Collaborator Author

@ceolin now that 4.0 is out, the CI of this PR is green and we have some approval, can we please merge it?
This would reduce the dependency chain for #79931

@tomi-font
Copy link
Collaborator

@ceolin now that 4.0 is out, the CI of this PR is green and we have some approval, can we please merge it? This would reduce the dependency chain for #79931

As per the rules the assignee (so @ceolin) needs to approve the PR for it to be mergeable.

@nashif nashif merged commit 516886b into zephyrproject-rtos:main Nov 20, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants