Skip to content

Commit 62ee266

Browse files
de-nordicnvlsianpu
authored andcommitted
[nrf fromlist] zephyr: Improve SHA support selectors
Commit introduces BOOT_SOMETHING_USES_SHA<256,384,512> Kconfig options that can be used to control what algorithms should be compiled in with crypto backends. Upstream PR #: 2390 Signed-off-by: Dominik Ermel <[email protected]>
1 parent 212f214 commit 62ee266

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

boot/zephyr/Kconfig

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,20 @@ if BOOT_USE_PSA_CRYPTO
7373

7474
config BOOT_PSA_IMG_HASH_ALG_SHA256_DEPENDENCIES
7575
bool
76-
default y if BOOT_IMG_HASH_ALG_SHA256
76+
default y if BOOT_SOMETHING_USES_SHA256
7777
select PSA_WANT_ALG_SHA_256
7878
help
7979
Dependencies for hashing with SHA256
8080

81-
config BOOT_ED25519_PSA_DEPENDENCIES
81+
config BOOT_PSA_IMG_HASH_ALG_SHA512_DEPENDENCIES
8282
bool
83-
select PSA_WANT_ALG_SHA_256
83+
default y if BOOT_SOMETHING_USES_SHA512
8484
select PSA_WANT_ALG_SHA_512
85+
help
86+
Dependencies for hashing with SHA512
87+
88+
config BOOT_ED25519_PSA_DEPENDENCIES
89+
bool
8590
select PSA_WANT_ALG_PURE_EDDSA
8691
select PSA_WANT_ECC_TWISTED_EDWARDS_255
8792
select PSA_WANT_ECC_MONTGOMERY_255
@@ -131,6 +136,30 @@ config SINGLE_APPLICATION_SLOT
131136
uploading a new application overwrites the one that previously
132137
occupied the area.
133138

139+
config BOOT_SOMETHING_USES_SHA256
140+
bool
141+
help
142+
Hidden option that should be selected when something requires
143+
SHA256 implementation in any form. It should be used by crypto
144+
backends to enable support for SHA256 in code and/or hardware
145+
drivers.
146+
147+
config BOOT_SOMETHING_USES_SHA384
148+
bool
149+
help
150+
Hidden option that should be selected when something requires
151+
SHA384 implementation in any form. It should be used by crypto
152+
backends to enable support for SHA384 in code and/or hardware
153+
drivers.
154+
155+
config BOOT_SOMETHING_USES_SHA512
156+
bool
157+
help
158+
Hidden option that should be selected when something requires
159+
SHA512 implementation in any form. It should be used by crypto
160+
backends to enable support for SHA512 in code and/or hardware
161+
drivers.
162+
134163
config BOOT_IMG_HASH_ALG_SHA256_ALLOW
135164
bool
136165
help
@@ -176,18 +205,21 @@ choice BOOT_IMG_HASH_ALG
176205
config BOOT_IMG_HASH_ALG_SHA256
177206
bool "SHA256"
178207
depends on BOOT_IMG_HASH_ALG_SHA256_ALLOW
208+
select BOOT_SOMETHING_USES_SHA256
179209
help
180210
SHA256 algorithm
181211

182212
config BOOT_IMG_HASH_ALG_SHA384
183213
bool "SHA384"
184214
depends on BOOT_IMG_HASH_ALG_SHA384_ALLOW
215+
select BOOT_SOMETHING_USES_SHA384
185216
help
186217
SHA384 algorithm
187218

188219
config BOOT_IMG_HASH_ALG_SHA512
189220
bool "SHA512"
190221
depends on BOOT_IMG_HASH_ALG_SHA512_ALLOW
222+
select BOOT_SOMETHING_USES_SHA512
191223
help
192224
SHA512 algorithm
193225

@@ -665,14 +697,34 @@ config BOOT_ENCRYPT_X25519
665697
help
666698
Hidden option selecting x25519 encryption.
667699

700+
if BOOT_ENCRYPT_X25519 && BOOT_USE_PSA_CRYPTO
701+
702+
choice BOOT_HMAC_SHA
703+
prompt "SHA used for HMAC and HKDF in encryption key exchange"
704+
default BOOT_HMAC_SHA256
705+
help
706+
HMAC/HKDF sha algorithm may be selected to synchronize sha
707+
usage with other places in code and reduce compiled in
708+
implementations.
709+
710+
config BOOT_HMAC_SHA256
711+
bool "Use SHA256 for HMAC/HKDF"
712+
select BOOT_SOMETHING_USES_SHA256
713+
help
714+
This is default for ED25519.
715+
668716
config BOOT_HMAC_SHA512
669717
bool "Use SHA512 for HMAC/HKDF"
670718
depends on BOOT_ENCRYPT_X25519
671719
depends on BOOT_USE_PSA_CRYPTO
720+
select BOOT_SOMETHING_USES_SHA512
672721
help
673-
By default SHA256 is used for HKDF/HMAC in key exchange expansion
674-
and verification. This options switches to SHA512. The option is
675-
mainly useful to reduce numer of compiled in SHA algorithms.
722+
With ED25519, this option is worth selecting when SHA512 is used
723+
for hashing of an image to reduce number of compiled sha algorithms.
724+
725+
endchoice # BOOT_HMAC_SHA
726+
727+
endif # BOOT_ENCRYPT_X25519 && BOOT_USE_PSA_CRYPTO
676728

677729
config BOOT_ENCRYPTION_KEY_FILE
678730
string "Encryption key file"

0 commit comments

Comments
 (0)