bootutil/crypto: Handle hashing errors and refactorings #2579
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.
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.