Skip to content

Commit 8033366

Browse files
committed
core: make constant compare common
Move wolfBoot_constant_compare out of TPM-only code so AHCI and update paths can use it without TPM feature gating. F/CI
1 parent 8842493 commit 8033366

4 files changed

Lines changed: 13 additions & 17 deletions

File tree

include/image.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ static void UNUSEDFUNCTION wolfBoot_image_clear_signature_ok(
12541254
/* Defined in image.c */
12551255
int image_CT_compare(const uint8_t *expected, const uint8_t *actual,
12561256
uint32_t len);
1257+
int wolfBoot_constant_compare(const uint8_t* a, const uint8_t* b, uint32_t len);
12571258
int wolfBoot_open_image(struct wolfBoot_image *img, uint8_t part);
12581259
#ifdef EXT_FLASH
12591260
int wolfBoot_open_image_external(struct wolfBoot_image* img, uint8_t part, uint8_t* addr);

include/tpm.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ int wolfBoot_load_pubkey(const uint8_t* pubkey_hint, WOLFTPM2_KEY* pubKey,
7979
TPM_ALG_ID* pAlg);
8080
#endif
8181

82-
#if defined(WOLFBOOT_TPM_KEYSTORE) || defined(WOLFBOOT_TPM_SEAL)
83-
int wolfBoot_constant_compare(const uint8_t* a, const uint8_t* b, uint32_t len);
84-
#endif
85-
8682
#ifdef WOLFBOOT_TPM_KEYSTORE
8783
int wolfBoot_check_rot(int key_slot, uint8_t* pubkey_hint);
8884
#endif

src/string.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ int memcmp(const void *_s1, const void *_s2, size_t n)
223223
return diff;
224224
}
225225

226+
int wolfBoot_constant_compare(const uint8_t* a, const uint8_t* b, uint32_t len)
227+
{
228+
uint32_t i;
229+
uint8_t diff = 0;
230+
231+
for (i = 0; i < len; i++) {
232+
diff |= a[i] ^ b[i];
233+
}
234+
235+
return diff;
236+
}
237+
226238
void* memchr(void const *s, int c_in, size_t n)
227239
{
228240
unsigned char c = (unsigned char)c_in;

src/tpm.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,6 @@ WOLFTPM2_KEY wolftpm_srk;
4444
#endif
4545

4646
#if defined(WOLFBOOT_TPM_SEAL) || defined(WOLFBOOT_TPM_KEYSTORE)
47-
int wolfBoot_constant_compare(const uint8_t* a, const uint8_t* b,
48-
uint32_t len)
49-
{
50-
uint32_t i;
51-
uint8_t diff = 0;
52-
53-
for (i = 0; i < len; i++) {
54-
diff |= a[i] ^ b[i];
55-
}
56-
57-
return diff;
58-
}
59-
6047
void wolfBoot_print_hexstr(const unsigned char* bin, unsigned long sz,
6148
unsigned long maxLine)
6249
{

0 commit comments

Comments
 (0)