Skip to content

Commit c1b2c40

Browse files
committed
image: restore ct compare contract
Make image_CT_compare return 0 on match again and update RSA hash checks plus delta base-hash validation to use the original semantics. F/CI
1 parent 0d6ad20 commit c1b2c40

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

include/image.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static void __attribute__((noinline)) wolfBoot_image_clear_signature_ok(
426426
asm volatile("mov r0, #50":::"r0"); \
427427
compare_res = image_CT_compare(digest, img->sha_hash, \
428428
WOLFBOOT_SHA_DIGEST_SIZE); \
429-
/* Redundant checks that ensure the function actually returned 1 */ \
429+
/* Redundant checks that ensure the function actually returned 0 */ \
430430
asm volatile("cmp r0, #0":::"cc"); \
431431
asm volatile("cmp r0, #0":::"cc"); \
432432
asm volatile("cmp r0, #0":::"cc"); \
@@ -447,7 +447,7 @@ static void __attribute__((noinline)) wolfBoot_image_clear_signature_ok(
447447
compare_res = image_CT_compare(digest, img->sha_hash, \
448448
WOLFBOOT_SHA_DIGEST_SIZE); \
449449
compare_res; \
450-
/* Redundant checks that ensure the function actually returned 1 */ \
450+
/* Redundant checks that ensure the function actually returned 0 */ \
451451
asm volatile("cmp r0, #0":::"cc"); \
452452
asm volatile("cmp r0, #0":::"cc"); \
453453
asm volatile("cmp r0, #0":::"cc"); \
@@ -1236,7 +1236,7 @@ static void UNUSEDFUNCTION wolfBoot_image_clear_signature_ok(
12361236
ret = fn(__VA_ARGS__);
12371237

12381238
#define RSA_VERIFY_HASH(img,digest) \
1239-
if (image_CT_compare(img->sha_hash, digest, WOLFBOOT_SHA_DIGEST_SIZE)) \
1239+
if (image_CT_compare(img->sha_hash, digest, WOLFBOOT_SHA_DIGEST_SIZE) == 0) \
12401240
wolfBoot_image_confirm_signature_ok(img);
12411241

12421242
#define PART_SANITY_CHECK(p) \

src/image.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int __attribute__((noinline)) image_CT_compare(
6868
diff |= expected[i] ^ actual[i];
6969
}
7070

71-
return diff == 0;
71+
return diff;
7272
}
7373

7474
#if defined(WOLFBOOT_CERT_CHAIN_VERIFY) && \
@@ -1551,7 +1551,7 @@ int wolfBoot_verify_integrity(struct wolfBoot_image *img)
15511551
return -1;
15521552
if (image_hash(img, digest) != 0)
15531553
return -1;
1554-
if (!image_CT_compare(digest, stored_sha, stored_sha_len))
1554+
if (image_CT_compare(digest, stored_sha, stored_sha_len) != 0)
15551555
return -1;
15561556
img->sha_ok = 1;
15571557
img->sha_hash = stored_sha;
@@ -1990,7 +1990,7 @@ int wolfBoot_check_flash_image_elf(uint8_t part, unsigned long* entry_out)
19901990

19911991
/* Finalize SHA calculation */
19921992
final_hash(&ctx, calc_digest);
1993-
if (!image_CT_compare(exp_digest, calc_digest, WOLFBOOT_SHA_DIGEST_SIZE)) {
1993+
if (image_CT_compare(exp_digest, calc_digest, WOLFBOOT_SHA_DIGEST_SIZE) != 0) {
19941994
wolfBoot_printf("ELF: [CHECK] SHA verification FAILED\n");
19951995
wolfBoot_printf(
19961996
"ELF: [CHECK] Expected %02x%02x%02x%02x%02x%02x%02x%02x\n",

src/update_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
667667
cur_v, delta_base_v);
668668
ret = -1;
669669
} else if (!resume && delta_base_hash &&
670-
!image_CT_compare(base_hash, delta_base_hash, base_hash_sz)) {
670+
image_CT_compare(base_hash, delta_base_hash, base_hash_sz) != 0) {
671671
/* Wrong base image digest, cannot apply delta patch */
672672
wolfBoot_printf("Delta Base hash mismatch\n");
673673
ret = -1;

0 commit comments

Comments
 (0)