aboutsummaryrefslogtreecommitdiff
path: root/PolicyPCR.c
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2015-05-20 10:32:25 -0700
committerVadim Bendebury <vbendeb@chromium.org>2015-05-20 22:32:05 -0700
commit5679752bf24c21135884e987c4077e2f71848971 (patch)
tree3e680dd91a7af84c45ea1170ee88225bd4ad32c8 /PolicyPCR.c
downloadtpm2-5679752bf24c21135884e987c4077e2f71848971.tar.gz
Initial commit to seed TPM2.0 source code directory
LICENSE file text copied from TCG library specification. README describes the procedure used to extract source code from parts 3 and 4 of the specification. The python scripts and part{34}.txt files will be removed in the following commits. Change-Id: Ie281e6e988481831f33483053455e8aff8f3f75f Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'PolicyPCR.c')
-rw-r--r--PolicyPCR.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/PolicyPCR.c b/PolicyPCR.c
new file mode 100644
index 0000000..a9400fc
--- /dev/null
+++ b/PolicyPCR.c
@@ -0,0 +1,90 @@
+// This file was extracted from the TCG Published
+// Trusted Platform Module Library
+// Part 3: Commands
+// Family "2.0"
+// Level 00 Revision 01.16
+// October 30, 2014
+
+#include "InternalRoutines.h"
+#include "PolicyPCR_fp.h"
+//
+//
+// Error Returns Meaning
+//
+// TPM_RC_VALUE if provided, pcrDigest does not match the current PCR settings
+// TPM_RC_PCR_CHANGED a previous TPM2_PolicyPCR() set pcrCounter and it has changed
+//
+TPM_RC
+TPM2_PolicyPCR(
+ PolicyPCR_In *in // IN: input parameter list
+ )
+{
+ SESSION *session;
+ TPM2B_DIGEST pcrDigest;
+ BYTE pcrs[sizeof(TPML_PCR_SELECTION)];
+ UINT32 pcrSize;
+ BYTE *buffer;
+ TPM_CC commandCode = TPM_CC_PolicyPCR;
+ HASH_STATE hashState;
+
+// Input Validation
+
+ // Get pointer to the session structure
+ session = SessionGet(in->policySession);
+
+ // Do validation for non trial session
+ if(session->attributes.isTrialPolicy == CLEAR)
+ {
+ // Make sure that this is not going to invalidate a previous PCR check
+ if(session->pcrCounter != 0 && session->pcrCounter != gr.pcrCounter)
+ return TPM_RC_PCR_CHANGED;
+
+ // Compute current PCR digest
+ PCRComputeCurrentDigest(session->authHashAlg, &in->pcrs, &pcrDigest);
+
+ // If the caller specified the PCR digest and it does not
+ // match the current PCR settings, return an error..
+ if(in->pcrDigest.t.size != 0)
+ {
+ if(!Memory2BEqual(&in->pcrDigest.b, &pcrDigest.b))
+ return TPM_RC_VALUE + RC_PolicyPCR_pcrDigest;
+ }
+ }
+ else
+ {
+ // For trial session, just use the input PCR digest
+ pcrDigest = in->pcrDigest;
+ }
+// Internal Data Update
+
+ // Update policy hash
+ // policyDigestnew = hash( policyDigestold || TPM_CC_PolicyPCR
+ // || pcrs || pcrDigest)
+ // Start hash
+ CryptStartHash(session->authHashAlg, &hashState);
+
+ // add old digest
+ CryptUpdateDigest2B(&hashState, &session->u2.policyDigest.b);
+
+ // add commandCode
+ CryptUpdateDigestInt(&hashState, sizeof(TPM_CC), &commandCode);
+
+ // add PCRS
+ buffer = pcrs;
+ pcrSize = TPML_PCR_SELECTION_Marshal(&in->pcrs, &buffer, NULL);
+ CryptUpdateDigest(&hashState, pcrSize, pcrs);
+
+ // add PCR digest
+ CryptUpdateDigest2B(&hashState, &pcrDigest.b);
+
+ // complete the hash and get the results
+ CryptCompleteHash2B(&hashState, &session->u2.policyDigest.b);
+
+ // update pcrCounter in session context for non trial session
+ if(session->attributes.isTrialPolicy == CLEAR)
+ {
+ session->pcrCounter = gr.pcrCounter;
+ }
+
+ return TPM_RC_SUCCESS;
+}