Skip to content

Conversation

@kkrentz
Copy link
Contributor

@kkrentz kkrentz commented Dec 9, 2025

This PR complements invocations of hashing-related function with error handling. This is important in various occasions, such as when verifying the signature of an image in "pure" mode. In this case, an error during hashing may cause the computed hash digest to become the all-zero string. However, an arbitrary ECDSA signature over the all-zero hash digest will turn out authentic.

Also, this PR adds a new file called sha.c, which encapsulates shorthands for common invocation patterns of SHA and HMAC, as well as an HKDF implementation. This simplifies matters in other files and having HKDF at a reusable place helped us integrate TCG's Device Identifier Composition Engine with MCUboot, too. This is because DICE uses the "expand" subroutine of HKDF.

Besides, this PR makes HMAC available regardless of the crypto backend. Currently, only mbedTLS and TinyCrypt provide this function, thereby limiting firmware encryption to configurations with one of these crypto backends.

@kkrentz kkrentz force-pushed the hashing-pr branch 7 times, most recently from 11cd7cc to 59140a8 Compare December 9, 2025 21:00
@kkrentz kkrentz requested a review from d3zd3z as a code owner December 9, 2025 21:00
@kkrentz kkrentz force-pushed the hashing-pr branch 4 times, most recently from 27a1a66 to 7298a73 Compare December 9, 2025 22:38
@kkrentz kkrentz marked this pull request as draft December 10, 2025 07:30
The current API actually requires checking each call to bootutil_sha_init,
bootutil_sha_update, bootutil_sha_finish, and bootutil_sha_abort for errors.
This would result in a lot of clutter and is not done at the moment. This
commit wraps these functions so as to silently ignore subsequent calls in
a series upon errors. As a result, only bootutil_sha_finish needs error
checking.

Signed-off-by: kkrentz <[email protected]>
This simplifies the API for generating HMACs and deriving keys.

Signed-off-by: kkrentz <[email protected]>
This introduces a shorthand for doing bootutil_sha_init,
bootutil_sha_update, and bootutil_sha_finish at once. This simplifies
matters in bootutil_find_key. Besides, there was no error handling in
bootutil_find_key, which is also fixed.

Signed-off-by: kkrentz <[email protected]>
Using the currently configured crypto back end, this implements HMAC and
HKDF. This implementation serves as a fallback solution for crypto back
ends that do not provide these functions. As there are plans to remove
TinyCrypt from MCUboot, no effort is made to use TinyCrypt when
MCUBOOT_USE_TINYCRYPT is set. Instead, this configuration falls back on
the general-purpose HMAC and HKDF implementations.

Signed-off-by: kkrentz <[email protected]>
Thus far, hashing errors were silently ignored when hashing images.

Signed-off-by: kkrentz <[email protected]>
@kkrentz kkrentz marked this pull request as ready for review December 10, 2025 17:30
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.

1 participant