Skip to content

Commit 78de4a7

Browse files
committed
Use constant-time TPM secret checks
F/2248
1 parent 7526fd2 commit 78de4a7

4 files changed

Lines changed: 9 additions & 3 deletions

File tree

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/tpm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ WOLFTPM2_KEY wolftpm_srk;
4444
#endif
4545

4646
#if defined(WOLFBOOT_TPM_SEAL) || defined(WOLFBOOT_TPM_KEYSTORE)
47-
static int wolfBoot_constant_compare(const uint8_t* a, const uint8_t* b,
47+
int wolfBoot_constant_compare(const uint8_t* a, const uint8_t* b,
4848
uint32_t len)
4949
{
5050
uint32_t i;

src/update_flash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,8 @@ int wolfBoot_unlock_disk(void)
12651265
secretCheck, &secretCheckSz);
12661266
if (ret == 0) {
12671267
if (secretSz != secretCheckSz ||
1268-
memcmp(secret, secretCheck, secretSz) != 0)
1268+
wolfBoot_constant_compare(secret, secretCheck,
1269+
(uint32_t)secretSz) != 0)
12691270
{
12701271
wolfBoot_printf("secret check mismatch!\n");
12711272
ret = -1;

src/x86/ahci.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ static int sata_create_and_seal_unlock_secret(const uint8_t *pubkey_hint,
296296
secret_check, &secret_check_sz);
297297
if (ret == 0) {
298298
if (*secret_size != secret_check_sz ||
299-
memcmp(secret, secret_check, secret_check_sz) != 0)
299+
wolfBoot_constant_compare(secret, secret_check,
300+
(uint32_t)secret_check_sz) != 0)
300301
{
301302
wolfBoot_printf("secret check mismatch!\n");
302303
ret = -1;

0 commit comments

Comments
 (0)