Skip to content

Commit

Permalink
Fix native test TPM2_PolicyPCR.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Dec 29, 2023
1 parent 6322c91 commit 4c75368
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
25 changes: 4 additions & 21 deletions examples/native/native_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
#endif
TPM2B_PUBLIC_KEY_RSA message;

#ifndef WOLFTPM2_NO_WOLFCRYPT
byte pcr[TPM_SHA256_DIGEST_SIZE];
int pcr_len = TPM_SHA256_DIGEST_SIZE;
byte hash[TPM_SHA256_DIGEST_SIZE];
int hash_len = TPM_SHA256_DIGEST_SIZE;
#endif

TpmRsaKey endorse;
TpmRsaKey storage;
TpmHmacKey hmacKey;
Expand Down Expand Up @@ -564,18 +557,9 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
(int)cmdOut.pcrRead.pcrValues.digests[0].size,
(int)cmdOut.pcrRead.pcrUpdateCounter);
TPM2_PrintBin(cmdOut.pcrRead.pcrValues.digests[0].buffer,
cmdOut.pcrRead.pcrValues.digests[0].size);
cmdOut.pcrRead.pcrValues.digests[0].size);

#ifndef WOLFTPM2_NO_WOLFCRYPT
/* Hash SHA256 PCR[0] */
rc = wc_Hash(WC_HASH_TYPE_SHA256, pcr, pcr_len, hash, hash_len);
if (rc < 0) {
printf("wc_Hash failed 0x%x: %s\n", rc, TPM2_GetRCString(rc));
goto exit;
}
printf("wc_Hash of PCR[0]: size %d\n", hash_len);
TPM2_PrintBin(hash, hash_len);

/* Set Auth Session index 0 */
session[0].sessionHandle = sessionHandle;
session[0].sessionAttributes = (TPMA_SESSION_decrypt | TPMA_SESSION_encrypt |
Expand All @@ -587,18 +571,17 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
session[0].nonceCaller.size = TPM2_GetHashDigestSize(WOLFTPM2_WRAP_DIGEST);
session[0].auth = sessionAuth;

/* Policy PCR */
/* Policy PCR (Get) */
pcrIndex = 0;
XMEMSET(&cmdIn.policyPCR, 0, sizeof(cmdIn.policyPCR));
cmdIn.policyPCR.policySession = sessionHandle;
cmdIn.policyPCR.pcrDigest.size = hash_len;
XMEMCPY(cmdIn.policyPCR.pcrDigest.buffer, hash, hash_len);
cmdIn.policyPCR.pcrDigest.size = 0;
TPM2_SetupPCRSel(&cmdIn.policyPCR.pcrs, TPM_ALG_SHA1, pcrIndex);
rc = TPM2_PolicyPCR(&cmdIn.policyPCR);
if (rc != TPM_RC_SUCCESS) {
printf("TPM2_PolicyPCR failed 0x%x: %s\n", rc,
TPM2_GetRCString(rc));
//goto exit; /* TODO: Fix failure on TPM2_PolicyPCR */
goto exit;
}
else {
printf("TPM2_PolicyPCR: Updated\n");
Expand Down
1 change: 0 additions & 1 deletion examples/pcr/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ int TPM2_PCR_Policy_Test(void* userCtx, int argc, char *argv[])
XMEMCPY(cmdIn.pcrPolicy.pcrDigest.buffer, digest, digestLen);
}
TPM2_SetupPCRSel(&cmdIn.pcrPolicy.pcrs, TPM_ALG_SHA256, pcrIndex);
//TPM2_SetupPCRSel(&cmdIn.pcrPolicy.pcrs, TPM_ALG_SHA384, pcrIndex);
rc = TPM2_PolicyPCR(&cmdIn.pcrPolicy);
if (rc != TPM_RC_SUCCESS) {
printf("TPM2_PolicyPCR failed 0x%x: %s\n", rc,
Expand Down

0 comments on commit 4c75368

Please sign in to comment.