Skip to content

boot: SHA512 verification #1967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2024
Merged

Conversation

michalek-no
Copy link
Collaborator

@michalek-no michalek-no commented May 28, 2024

adds TLV and Kconfig to decouple verification from other options.

@nvlsianpu nvlsianpu self-requested a review May 28, 2024 13:50
@nvlsianpu nvlsianpu added the area: core Affects core functionality label May 28, 2024
@michalek-no michalek-no reopened this Jun 26, 2024
@michalek-no michalek-no force-pushed the mb-psa-patch branch 2 times, most recently from 4153784 to 9de733a Compare June 26, 2024 12:13
@michalek-no michalek-no marked this pull request as ready for review June 26, 2024 12:13
@michalek-no michalek-no changed the title wip boot: SHA512 verification Jun 26, 2024
@de-nordic de-nordic requested review from nordicjm and d3zd3z July 24, 2024 11:50
Comment on lines 76 to 78

config BOOT_SIGNATURE_TYPE_NONE_SHA512
bool "No signature; use only sha512 check"
Copy link
Collaborator

@nordicjm nordicjm Jul 25, 2024

Choose a reason for hiding this comment

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

Not really sure what the point of this change is? The hash would only be for detecting bit flips, the chance of having a bit flip and a sha256 hash still matching is basically impossible, so not sure why allowing a sha512 for this would improve anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In general yes, but it's security requirement we got.

Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAIK BOOT_SIGNATURE_TYPE_NONE was introduced for giving SW evaluation (for development testing) value. It is not intended to use in any real product. If we are not going to use BOOT_SIGNATURE_TYPE_NONE_SHA512 for anything like this - then it is not needed.

@de-nordic de-nordic force-pushed the mb-psa-patch branch 2 times, most recently from 4b1d4b8 to 4bbfc04 Compare August 29, 2024 16:15
@de-nordic
Copy link
Collaborator

Sorry, got to add own sign off on the thing because I just added one line.

config BOOT_USE_PSA_CRYPTO
bool
# Hidden option
default n
Copy link
Collaborator

Choose a reason for hiding this comment

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

default n is never needed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not addressed

Hash algorithm used for image verification. Selection
here may be limited by other configurations, like for
example selected cryptographic signature.
default BOOT_IMG_HASH_ALG_SHA256 if BOOT_IMG_HASH_ALG_SHA256_ALLOW
Copy link
Collaborator

Choose a reason for hiding this comment

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

default goes above help text, help text is always last. In addition the list of options seems reversed, this means if you supported sha512 and sha256, you would always default to sha256

Copy link
Collaborator

Choose a reason for hiding this comment

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

will fix.

config BOOT_IMG_HASH_ALG_SHA512
bool "SHA512"
depends on BOOT_IMG_HASH_ALG_SHA512_ALLOW
depends on BOOT_USE_PSA_CRYPT
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be part of the depends on for the allow part

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok will move to allow.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Moved it back, I have wasted too much time fighting with conflicts in Kconfig.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, fixed it finally.

select BOOT_USE_TINYCRYPT
select BOOT_IMG_HASH_ALG_SHA256_ALLOW
select BOOT_IMG_HASH_ALG_SHA512_ALLOW
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't see the point in sha512 here, this means you have no signature, so you could use a crc16 really, sha512 from sha256 adds nothing in this configuration

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually there is significant difference between sha and crc in this context, although I admit that with the sha256 vs sha512 not so much, without signature verification.
But, because there is always one, user may have hardware accelerator that only supports sha512 calculation, which is often the case with hardware with ed25519 accelerators, as the sha512 is the sha of choice for that signature.

Such hardware will often not have the sha256, so, even if ed25519 is not used in the end, the hashing of image will be faster when sha512 is used.

Copy link
Collaborator

@nordicjm nordicjm Sep 3, 2024

Choose a reason for hiding this comment

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

But that's the point, this is only used either for development where you want nil security or whereby you have a project that has nil security, it doesn't really have any real world use for a product, so even if it is slower, that doesn't matter, this is working fine on an nrf51 which is a cortex m0 from over a decade ago, I don't see the speed of verifying this ever being a problem for it's intended purposes, especially on more modern architectures. Plus it has absolutely no support in MCUmgr tools

Copy link
Collaborator

Choose a reason for hiding this comment

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

imgtool support is here: #2048, it is based on older version of this PR.
MCUmgr support could be added at some point, and it could also use the sha512 coprocessor on devices that have it.

Crypto engines often have better power characteristics than doing the same hashing on CPU, and the reduction of time may be significant.
In my experimentation with 32kB image, I had following results:

  • by chunks with read to mem by flash_read - 5 to 6ms
  • by chunks, but with direct access to storage, crypto engine doing the DMA - 3ms
  • by whole image at once, crypto doing DMA - 0ms

I probably should repeat the experiment with ticks or some smaller units, but this already show improvement.

Of course, we can restrict usage of sha512 to ed25519 kinda prehashing, but still we will have sha512 TLV added.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, sha512 TLV support is fine but to me no signature mode is just for development or "I don't care about security" and a few extra ms speed there is not of concern, it should be limited to sha256, then use sha512 when using a signature that needs it. The sha256 is baseline "no thrills" and everything else is good security

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fine, I will move the line to some limbo PR.

@de-nordic de-nordic force-pushed the mb-psa-patch branch 6 times, most recently from 1a3a943 to f75fb90 Compare September 5, 2024 09:54
@@ -131,7 +138,6 @@ static inline int bootutil_sha_drop(bootutil_sha_context *ctx)
(void)ctx;
return 0;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

unrelated? Can we add it back?

Copy link
Collaborator

@nordicjm nordicjm left a comment

Choose a reason for hiding this comment

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

Minor nit.

Comment on lines 29 to 31
# Hidden option
help
Use PSA crypt for supporting cryptography functions
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use same style as below e.g.

	help
	  Hidden option set if using PSA crypt for cryptography functionality

Comment on lines 79 to 90
Hidden option to set by configurations that allow SHA256

config BOOT_IMG_HASH_ALG_SHA384_ALLOW
bool
help
Hidden option to set by configurations that allow SHA384

config BOOT_IMG_HASH_ALG_SHA512_ALLOW
bool
depends on BOOT_USE_PSA_CRYPTO
help
Hidden option to set by configurations that allow SHA512
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hidden option to set by

adds TLV and Kconfig to decouple verification from
other options.

Signed-off-by: Mateusz Michalek <[email protected]>
Signed-off-by: Dominik Ermel <[email protected]>
de-nordic pushed a commit to de-nordic/sdk-mcuboot that referenced this pull request Sep 6, 2024
adds TLV and Kconfig to decouple verification from
other options.

Upstream PR: mcu-tools/mcuboot#1967

Signed-off-by: Mateusz Michalek <[email protected]>
Signed-off-by: Dominik Ermel <[email protected]>
@d3zd3z
Copy link
Member

d3zd3z commented Sep 9, 2024

Do we want this or #2048?

@de-nordic
Copy link
Collaborator

de-nordic commented Sep 12, 2024

Do we want this or #2048?

Yes, this is the verification of SHA512 the #2048 adds. This is MCUboot code, the 2048 is imgtool change.

@de-nordic de-nordic self-requested a review September 13, 2024 15:32
de-nordic pushed a commit to de-nordic/mcuboot that referenced this pull request Sep 18, 2024
adds TLV and Kconfig to decouple verification from
other options.

Upstream PR: mcu-tools#1967

Signed-off-by: Mateusz Michalek <[email protected]>
Signed-off-by: Dominik Ermel <[email protected]>
@nvlsianpu nvlsianpu merged commit 41df52e into mcu-tools:main Sep 18, 2024
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Affects core functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants