1 // This file was extracted from the TCG Published 2 // Trusted Platform Module Library 3 // Part 3: Commands 4 // Family "2.0" 5 // Level 00 Revision 01.16 6 // October 30, 2014 7 8 #include "InternalRoutines.h" 9 #include "PolicyCommandCode_fp.h" 10 // 11 // 12 // Error Returns Meaning 13 // 14 // TPM_RC_VALUE commandCode of policySession previously set to a different value 15 // 16 TPM_RC TPM2_PolicyCommandCode(PolicyCommandCode_In * in)17TPM2_PolicyCommandCode( 18 PolicyCommandCode_In *in // IN: input parameter list 19 ) 20 { 21 SESSION *session; 22 TPM_CC commandCode = TPM_CC_PolicyCommandCode; 23 HASH_STATE hashState; 24 25 // Input validation 26 27 // Get pointer to the session structure 28 session = SessionGet(in->policySession); 29 30 if(session->commandCode != 0 && session->commandCode != in->code) 31 return TPM_RC_VALUE + RC_PolicyCommandCode_code; 32 if(!CommandIsImplemented(in->code)) 33 return TPM_RC_POLICY_CC + RC_PolicyCommandCode_code; 34 35 // Internal Data Update 36 // Update policy hash 37 // policyDigestnew = hash(policyDigestold || TPM_CC_PolicyCommandCode || code) 38 // Start hash 39 CryptStartHash(session->authHashAlg, &hashState); 40 41 // add old digest 42 CryptUpdateDigest2B(&hashState, &session->u2.policyDigest.b); 43 44 // add commandCode 45 CryptUpdateDigestInt(&hashState, sizeof(TPM_CC), &commandCode); 46 47 // add input commandCode 48 CryptUpdateDigestInt(&hashState, sizeof(TPM_CC), &in->code); 49 50 // complete the hash and get the results 51 CryptCompleteHash2B(&hashState, &session->u2.policyDigest.b); 52 53 // update commandCode value in session context 54 session->commandCode = in->code; 55 56 return TPM_RC_SUCCESS; 57 } 58