Skip to content

boot: bootutil: fixes for image encryption support with PSA crypto - #2790

Open
tpambor wants to merge 4 commits into
mcu-tools:mainfrom
tpambor:tfm-psa-fixes
Open

boot: bootutil: fixes for image encryption support with PSA crypto#2790
tpambor wants to merge 4 commits into
mcu-tools:mainfrom
tpambor:tfm-psa-fixes

Conversation

@tpambor

@tpambor tpambor commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

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_TLS is 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.

tpambor added 4 commits July 15, 2026 07:46
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>
@tpambor
tpambor requested a review from davidvincze as a code owner July 15, 2026 06:01
@nordicjm
nordicjm requested a review from d3zd3z July 16, 2026 07:18
# 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)
?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This CMakeLists.txt isn't used by Zephyr. Zephyr selects it here:

if(CONFIG_BOOT_USE_PSA_CRYPTO)
zephyr_sources(${BOOT_DIR}/bootutil/src/fault_injection_hardening_delay_rng_psa.c)
else()
zephyr_sources(${BOOT_DIR}/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c)
endif()

with CONFIG_BOOT_USE_PSA_CRYPTO

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh ok, sorry for the noise.

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.

2 participants