Skip to content

bootutil: init PSA crypto before ECDSA key import - #2969

Merged
nordicjm merged 2 commits into
mcu-tools:mainfrom
Tolt-Technologies:fix/ecdsa-psa-crypto-init
Nov 18, 2026
Merged

nordicjm merged 2 commits into
mcu-tools:mainfrom
Tolt-Technologies:fix/ecdsa-psa-crypto-init

Conversation

@JayToltTech

@JayToltTech JayToltTech commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

The PSA ECDSA path imports the public key without ever calling psa_crypto_init(). Ed25519, the encryption code and the FIH delay RNG all init PSA themselves. ECDSA just assumes someone else did.

On Zephyr the mbedtls module's SYS_INIT usually has, so you don't see it. Tripped over it moving a Zephyr boot signature from tinycrypt ECDSA-P256 to PSA ECDSA-P384, on v2.4.0 with TF-PSA-Crypto 1.x. P-384 has no tinycrypt path, so that's also the first time the build goes through PSA at all, and the bootloader stopped validating anything.

The trigger was a missing CONFIG_MBEDTLS_ENABLE_HEAP. Zephyr's own psa_crypto_init() failed with PSA_ERROR_INSUFFICIENT_MEMORY, SYS_INIT drops the return code of a non-device init so nothing said so, and MCUboot carried on into psa_import_key() with PSA never initialized. Adding the init exposed the config error. The bug manifests the same way with CONFIG_MBEDTLS_INIT=n or on a port that doesn't init PSA before boot_go().

The sim never caught it because init_crypto() called psa_crypto_init() before every boot, which assumed the code under test would leave that to its caller. So I took that out of the sim first, and sig-ecdsa-psa and sig-ecdsa-psa mbedtls-v4 each failed 12 of 31 core tests with 'Unable to perform basic upgrade'. Then added the init to bootutil_ecdsa_parse_public_key() and they passed again, along with every other PSA row in sim.yaml.

The commits are in the other order so nothing in between is red for bisect.

FYI #2557 is heading in a similar direction with a single backend init hook, currently for Ed25519. If that ends up covering ECDSA too, this could fold into it.

@JayToltTech
JayToltTech force-pushed the fix/ecdsa-psa-crypto-init branch from 6af9992 to 8e6ccf8 Compare November 13, 2026 05:22
@JayToltTech JayToltTech changed the title bootutil: init PSA crypto before ECDSA public key import bootutil: init PSA crypto before ECDSA key use Nov 13, 2026
@JayToltTech
JayToltTech marked this pull request as ready for review November 13, 2026 05:26
Copilot AI balanced review requested due to automatic review settings November 13, 2026 05:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@JayToltTech
JayToltTech marked this pull request as draft November 13, 2026 05:28
@JayToltTech
JayToltTech force-pushed the fix/ecdsa-psa-crypto-init branch from 8e6ccf8 to 0254ad1 Compare November 13, 2026 05:38
@JayToltTech JayToltTech changed the title bootutil: init PSA crypto before ECDSA key use bootutil: init PSA crypto before ECDSA key import Nov 13, 2026
@JayToltTech
JayToltTech marked this pull request as ready for review November 13, 2026 05:39
@de-nordic de-nordic added bug area: sim Affects the simulator crypto Encryption support labels Nov 13, 2026
The PSA ECDSA path never calls psa_crypto_init().  Ed25519, the
encryption code and the FIH delay RNG all init PSA themselves, ECDSA
just assumes someone else did.

On Zephyr the mbedtls module's SYS_INIT usually has, so it doesn't
show.  With CONFIG_MBEDTLS_INIT=n, or a port that doesn't init PSA
before boot_go(), psa_import_key() returns PSA_ERROR_BAD_STATE and
nothing ECDSA-signed validates.  Same on Mbed TLS 3.6 and 4.1.

psa_crypto_init() is a no-op when PSA is already up.

Signed-off-by: Jay Beavers <jay@tolttechnologies.com>
init_crypto() called psa_crypto_init() before every boot, which
assumed the code under test would never need to do it itself.  That's
what hid the missing init in the PSA ECDSA path.  Without the previous
commit, sig-ecdsa-psa fails 12 of 31 core tests on both 3.6 and
mbedtls-v4.

The external RNG enable stays, that's harness setup.

Signed-off-by: Jay Beavers <jay@tolttechnologies.com>
@JayToltTech
JayToltTech force-pushed the fix/ecdsa-psa-crypto-init branch from 0254ad1 to d6873f9 Compare November 15, 2026 00:37
@nordicjm
nordicjm merged commit 22b9be6 into mcu-tools:main Nov 18, 2026
75 checks passed
@JayToltTech
JayToltTech deleted the fix/ecdsa-psa-crypto-init branch November 24, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: sim Affects the simulator bug crypto Encryption support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants