Skip to content

Commit 4594a86

Browse files
de-nordicrlubos
authored andcommitted
[nrf fromlist] boot_serial: Support sha256, sha384 and sha512
Add support for reporting various sha in image list. There is always only one sha compiled in, but serial recovery has been previously hardcoded to support sha256 only. Upstream PR #: 2116 Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no> (cherry picked from commit bcdf6e2)
1 parent b1cbeef commit 4594a86

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

boot/boot_serial/src/boot_serial.c

+18-7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);
8181
#define ARRAY_SIZE ZCBOR_ARRAY_SIZE
8282
#endif
8383

84+
#if defined(MCUBOOT_SHA512)
85+
#define IMAGE_HASH_SIZE (64)
86+
#define IMAGE_SHA_TLV IMAGE_TLV_SHA512
87+
#elif defined(MCUBOOT_SIGN_EC384)
88+
#define IMAGE_HASH_SIZE (48)
89+
#define IMAGE_SHA_TLV IMAGE_TLV_SHA384
90+
#else
91+
#define IMAGE_HASH_SIZE (32)
92+
#define IMAGE_SHA_TLV IMAGE_TLV_SHA256
93+
#endif
94+
8495
#ifndef MCUBOOT_SERIAL_MAX_RECEIVE_SIZE
8596
#define MCUBOOT_SERIAL_MAX_RECEIVE_SIZE 512
8697
#endif
@@ -91,7 +102,7 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);
91102
#define BOOT_SERIAL_IMAGE_STATE_SIZE_MAX 0
92103
#endif
93104
#ifdef MCUBOOT_SERIAL_IMG_GRP_HASH
94-
#define BOOT_SERIAL_HASH_SIZE_MAX 36
105+
#define BOOT_SERIAL_HASH_SIZE_MAX (IMAGE_HASH_SIZE + 4)
95106
#else
96107
#define BOOT_SERIAL_HASH_SIZE_MAX 0
97108
#endif
@@ -263,7 +274,7 @@ bs_list(char *buf, int len)
263274
const struct flash_area *fap;
264275
uint8_t image_index;
265276
#ifdef MCUBOOT_SERIAL_IMG_GRP_HASH
266-
uint8_t hash[32];
277+
uint8_t hash[IMAGE_HASH_SIZE];
267278
#endif
268279

269280
zcbor_map_start_encode(cbor_state, 1);
@@ -336,7 +347,7 @@ bs_list(char *buf, int len)
336347
}
337348

338349
#ifdef MCUBOOT_SERIAL_IMG_GRP_HASH
339-
/* Retrieve SHA256 hash of image for identification */
350+
/* Retrieve hash of image for identification */
340351
rc = boot_serial_get_hash(&hdr, fap, hash);
341352
#endif
342353

@@ -440,7 +451,7 @@ bs_set(char *buf, int len)
440451
*/
441452
uint8_t image_index = 0;
442453
size_t decoded = 0;
443-
uint8_t hash[32];
454+
uint8_t hash[IMAGE_HASH_SIZE];
444455
bool confirm;
445456
struct zcbor_string img_hash;
446457
bool ok;
@@ -523,7 +534,7 @@ bs_set(char *buf, int len)
523534
}
524535
}
525536

526-
/* Retrieve SHA256 hash of image for identification */
537+
/* Retrieve hash of image for identification */
527538
rc = boot_serial_get_hash(&hdr, fap, hash);
528539
flash_area_close(fap);
529540

@@ -1467,9 +1478,9 @@ static int boot_serial_get_hash(const struct image_header *hdr,
14671478
break;
14681479
}
14691480

1470-
if (type == IMAGE_TLV_SHA256) {
1481+
if (type == IMAGE_SHA_TLV) {
14711482
/* Get the image's hash value from the manifest section. */
1472-
if (len != 32) {
1483+
if (len != IMAGE_HASH_SIZE) {
14731484
return -1;
14741485
}
14751486

0 commit comments

Comments
 (0)