boot: bootutil: fixes for image encryption support with PSA crypto - #2790
Open
tpambor wants to merge 4 commits into
Open
boot: bootutil: fixes for image encryption support with PSA crypto#2790tpambor wants to merge 4 commits into
tpambor wants to merge 4 commits into
Conversation
Replace the zephyr-specific CONFIG_BOOT_USE_PSA_CRYPTO option with the more generic MCUBOOT_USE_PSA_CRYPTO option. This allows to use the PSA crypto backend for fault injection hardening in non-zephyr builds. E.g. compiling Trusted Firmware-M with MCUBOOT_USE_PSA_CRYPTO set, will now correctly use the PSA crypto backend for fault injection hardening. Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
When the bootloader uses PSA Crypto (MCUBOOT_USE_PSA_CRYPTO), include encrypted_psa.c in addition to encrypted.c, which still provides the common encrypted image support, when using the PSA Crypto APIs. Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Trusted Firmware-M starting with v2.3.0 always defines MCUBOOT_USE_PSA_CRYPTO, while MCUBOOT_USE_MBED_TLS remained defined until 11e9f28. This causes compile errors when image encryption (MCUBOOT_ENC_IMAGES) is enabled, as only one backend is allowed. Relax this requirement, similar to RSA and ECDSA, and allow both MCUBOOT_USE_PSA_CRYPTO and MCUBOOT_USE_MBED_TLS to be defined at the same time. In this case, the PSA_CRYPTO backend will take precedence over MBED_TLS. Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
boot_decrypt_key() is only utilized when decrypting an image that was encrypted with ECIES-P256/ECIES-X25519. Guard the code to only include it when the feature is enabled. Additionally, conditionally include bootutil/crypto/common.h only when EC256/X25519 encryption is enabled, since only these algorithms depend on mbedTLS for ASN1 parsing. Other algorithms, e.g., AES-KW, have no mbedTLS dependency, so this change enables building with a pure PSA API implementation without requiring mbedTLS headers. Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
| # psa_generate_random() instead of the legacy mbedTLS entropy + CTR-DRBG | ||
| # APIs that were removed in tf-psa-crypto 1.0. | ||
| if(CONFIG_BOOT_USE_PSA_CRYPTO) | ||
| if(MCUBOOT_USE_PSA_CRYPTO) |
Contributor
There was a problem hiding this comment.
I see that MCUBOOT_USE_PSA_CRYPTO is set when MCUboot is built from TF-M, but CONFIG_BOOT_USE_PSA_CRYPTO could be set when building from Zephyr (in case TF-M is not enabled in the build). Shouldn't we OR the condition here, so something like:
if(MCUBOOT_USE_PSA_CRYPTO || CONFIG_BOOT_USE_PSA_CRYPTO)
?
Contributor
Author
There was a problem hiding this comment.
This CMakeLists.txt isn't used by Zephyr. Zephyr selects it here:
mcuboot/boot/zephyr/CMakeLists.txt
Lines 133 to 137 in 7ad6710
with
CONFIG_BOOT_USE_PSA_CRYPTO
Contributor
There was a problem hiding this comment.
Oh ok, sorry for the noise.
valeriosetti
approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trusted Firmware-M (TF-M) starting with v2.3.0 is utilizing purely the PSA crypto API. This PR contains fixes for the image encryption support (MCUBOOT_ENC_IMAGES) that have been discovered while working with TF-M v2.3.0+.
bootutil: crypto: aes_ctr: allow PSA_CRYPTO together with MBED_TLSis included to maintain support for older TF-M versions which utilize a mixture of PSA crypto and mbedtls.For details, see the commit messages of the individual commits.