Skip to content

Commit fc9e7a3

Browse files
committed
Use constant-time delta base hash compare
F/2253
1 parent 435e8d4 commit fc9e7a3

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

include/image.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,8 @@ static void UNUSEDFUNCTION wolfBoot_image_clear_signature_ok(
12521252
#endif
12531253

12541254
/* Defined in image.c */
1255+
int image_CT_compare(const uint8_t *expected, const uint8_t *actual,
1256+
uint32_t len);
12551257
int wolfBoot_open_image(struct wolfBoot_image *img, uint8_t part);
12561258
#ifdef EXT_FLASH
12571259
int wolfBoot_open_image_external(struct wolfBoot_image* img, uint8_t part, uint8_t* addr);

src/image.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
/* Globals */
5959
static uint8_t digest[WOLFBOOT_SHA_DIGEST_SIZE] XALIGNED(4);
6060

61-
static int __attribute__((noinline)) image_CT_compare(
61+
int __attribute__((noinline)) image_CT_compare(
6262
const uint8_t *expected, const uint8_t *actual, uint32_t len)
6363
{
6464
uint8_t diff = 0;

src/update_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
642642
cur_v, delta_base_v);
643643
ret = -1;
644644
} else if (!resume && delta_base_hash &&
645-
memcmp(base_hash, delta_base_hash, base_hash_sz) != 0) {
645+
!image_CT_compare(base_hash, delta_base_hash, base_hash_sz)) {
646646
/* Wrong base image digest, cannot apply delta patch */
647647
wolfBoot_printf("Delta Base hash mismatch\n");
648648
ret = -1;

0 commit comments

Comments
 (0)