Skip to content

Commit 0d6ad20

Browse files
committed
tpm: localize constant compare again
Restore wolfBoot_constant_compare to TPM-local code and use file-local helpers in update_flash and AHCI instead of a shared cross-module symbol. F/CI
1 parent 8cdb8e9 commit 0d6ad20

6 files changed

Lines changed: 45 additions & 18 deletions

File tree

include/image.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,6 @@ 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);
12581257
int wolfBoot_open_image(struct wolfBoot_image *img, uint8_t part);
12591258
#ifdef EXT_FLASH
12601259
int wolfBoot_open_image_external(struct wolfBoot_image* img, uint8_t part, uint8_t* addr);

include/tpm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ 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+
8286
#ifdef WOLFBOOT_TPM_KEYSTORE
8387
int wolfBoot_check_rot(int key_slot, uint8_t* pubkey_hint);
8488
#endif

src/string.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
#endif
2828

2929
#include <stddef.h>
30-
#if defined(_RENESAS_RA_)
31-
#include <stdint.h>
32-
#endif
3330
#if !defined(TARGET_library) && defined(__STDC_HOSTED__) && __STDC_HOSTED__ \
3431
&& !defined(__CCRX__)
3532
#include <string.h>
@@ -223,18 +220,6 @@ int memcmp(const void *_s1, const void *_s2, size_t n)
223220
return diff;
224221
}
225222

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-
238223
void* memchr(void const *s, int c_in, size_t n)
239224
{
240225
unsigned char c = (unsigned char)c_in;

src/tpm.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ 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+
4760
void wolfBoot_print_hexstr(const unsigned char* bin, unsigned long sz,
4861
unsigned long maxLine)
4962
{

src/update_flash.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ static void wolfBoot_zeroize(void *ptr, size_t len)
4242
}
4343
}
4444

45+
static int wolfBoot_local_constant_compare(const uint8_t* a, const uint8_t* b,
46+
uint32_t len)
47+
{
48+
uint32_t i;
49+
uint8_t diff = 0;
50+
51+
for (i = 0; i < len; i++) {
52+
diff |= a[i] ^ b[i];
53+
}
54+
55+
return diff;
56+
}
57+
4558
#ifdef EXT_ENCRYPTED
4659
int wolfBoot_force_fallback_iv(int enable);
4760
#include "encrypt.h"
@@ -1293,7 +1306,7 @@ int wolfBoot_unlock_disk(void)
12931306
secretCheck, &secretCheckSz);
12941307
if (ret == 0) {
12951308
if (secretSz != secretCheckSz ||
1296-
wolfBoot_constant_compare(secret, secretCheck,
1309+
wolfBoot_local_constant_compare(secret, secretCheck,
12971310
(uint32_t)secretSz) != 0)
12981311
{
12991312
wolfBoot_printf("secret check mismatch!\n");

src/x86/ahci.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ __attribute__((aligned(HBA_TBL_ALIGN)));
109109
#define AHCI_DEBUG_PRINTF(...) do {} while(0)
110110
#endif /* DEBUG_AHCI */
111111

112+
static int wolfBoot_local_constant_compare(const uint8_t* a, const uint8_t* b,
113+
uint32_t len)
114+
{
115+
uint32_t i;
116+
uint8_t diff = 0;
117+
118+
for (i = 0; i < len; i++) {
119+
diff |= a[i] ^ b[i];
120+
}
121+
122+
return diff;
123+
}
124+
112125
/**
113126
* @brief Sets the AHCI Base Address Register (ABAR) for the given device.
114127
*
@@ -296,7 +309,7 @@ static int sata_create_and_seal_unlock_secret(const uint8_t *pubkey_hint,
296309
secret_check, &secret_check_sz);
297310
if (ret == 0) {
298311
if (*secret_size != secret_check_sz ||
299-
wolfBoot_constant_compare(secret, secret_check,
312+
wolfBoot_local_constant_compare(secret, secret_check,
300313
(uint32_t)secret_check_sz) != 0)
301314
{
302315
wolfBoot_printf("secret check mismatch!\n");

0 commit comments

Comments
 (0)