Skip to content

Commit 8ba0d08

Browse files
committed
Add H5 measured boot to test application
1 parent b1f6bec commit 8ba0d08

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

include/tpm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const char* CSME_NSE_API wolfBoot_tpm2_get_alg_name(TPM_ALG_ID alg,
6262
const char* CSME_NSE_API wolfBoot_tpm2_get_rc_string(int rc,
6363
char* error, int error_sz);
6464
TPM_RC CSME_NSE_API wolfBoot_tpm2_get_capability(GetCapability_In* in, GetCapability_Out* out);
65+
int CSME_NSE_API wolfBoot_tpm2_read_pcr(uint8_t pcrIndex, uint8_t* digest, int* digestSz);
6566

6667
#if defined(WOLFBOOT_TPM_VERIFY) || defined(WOLFBOOT_TPM_SEAL)
6768
int wolfBoot_load_pubkey(const uint8_t* pubkey_hint, WOLFTPM2_KEY* pubKey,

include/user_settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ extern int tolower(int c);
410410
#ifndef XTPM_WAIT
411411
#define XTPM_WAIT() /* no delay */
412412
#endif
413+
#define HASH_COUNT 3 /* enable more PCR hash types */
413414

414415
/* TPM remap printf */
415416
#if defined(DEBUG_WOLFTPM) && !defined(ARCH_SIM)

src/tpm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,14 @@ TPM_RC CSME_NSE_API wolfBoot_tpm2_get_capability(GetCapability_In* in, GetCapabi
11871187
return TPM2_GetCapability(in, out);
11881188
}
11891189

1190+
int CSME_NSE_API wolfBoot_tpm2_read_pcr(uint8_t pcrIndex, uint8_t* digest, int* digestSz)
1191+
{
1192+
return wolfTPM2_ReadPCR(&wolftpm_dev, pcrIndex, WOLFBOOT_TPM_PCR_ALG,
1193+
digest, digestSz);
1194+
}
1195+
1196+
1197+
11901198

11911199

11921200
/**

test-app/app_stm32h5.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ static int TPM2_PCRs_Print(void)
677677
GetCapability_In capIn;
678678
GetCapability_Out capOut;
679679
TPML_PCR_SELECTION* pcrSel;
680-
char buffer[24];
680+
char algName[24];
681681

682682
/* List available PCR's */
683683
XMEMSET(&capIn, 0, sizeof(capIn));
@@ -691,7 +691,7 @@ static int TPM2_PCRs_Print(void)
691691
for (pcrCount=0; pcrCount < (int)pcrSel->count; pcrCount++) {
692692

693693
printf("\t%s: ", wolfBoot_tpm2_get_alg_name(
694-
pcrSel->pcrSelections[pcrCount].hash, buffer, sizeof(buffer)));
694+
pcrSel->pcrSelections[pcrCount].hash, algName, sizeof(algName)));
695695
for (pcrIndex=0;
696696
pcrIndex<pcrSel->pcrSelections[pcrCount].sizeofSelect*8;
697697
pcrIndex++) {
@@ -711,7 +711,10 @@ static int cmd_tpm_info(const char *args)
711711
int rc;
712712
WOLFTPM2_CAPS caps;
713713
TPML_HANDLE handles;
714-
char error[100];
714+
#ifdef WOLFBOOT_MEASURED_PCR_A
715+
byte hashBuf[TPM_MAX_DIGEST_SIZE];
716+
int hashSz;
717+
#endif
715718

716719
printf("Get TPM 2.0 module information\r\n");
717720

@@ -731,11 +734,36 @@ static int cmd_tpm_info(const char *args)
731734
for (i=0; i<(int)handles.count; i++) {
732735
printf("\tHandle 0x%x\r\n", (unsigned int)handles.handle[i]);
733736
}
737+
rc = 0;
734738
}
735739

736740
/* Print the available PCR's */
737-
rc = TPM2_PCRs_Print();
741+
if (rc == 0) {
742+
rc = TPM2_PCRs_Print();
743+
}
744+
745+
#ifdef WOLFBOOT_MEASURED_PCR_A
746+
/* Read measured boot PCR */
747+
if (rc == 0) {
748+
char algName[24];
749+
printf("Measured boot: PCR %s %d\r\n",
750+
wolfBoot_tpm2_get_alg_name(WOLFBOOT_TPM_PCR_ALG, algName, sizeof(algName)),
751+
WOLFBOOT_MEASURED_PCR_A);
752+
hashSz = 0;
753+
rc = wolfBoot_tpm2_read_pcr(WOLFBOOT_MEASURED_PCR_A, hashBuf, &hashSz);
754+
if (rc == 0) {
755+
int i;
756+
printf("PCR (%d bytes): ", hashSz);
757+
for (i = 0; i < hashSz; i++) {
758+
printf("%02x", hashBuf[i]);
759+
}
760+
printf("\r\n");
761+
}
762+
}
763+
#endif
764+
738765
if (rc != 0) {
766+
char error[100];
739767
printf("TPM error 0x%x: %s\r\n",
740768
rc, wolfBoot_tpm2_get_rc_string(rc, error, sizeof(error)));
741769
}

0 commit comments

Comments
 (0)