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 "PCR_Event_fp.h" 10 // 11 // 12 // Error Returns Meaning 13 // 14 // TPM_RC_LOCALITY current command locality is not allowed to extend the PCR 15 // referenced by pcrHandle 16 // 17 TPM_RC 18 TPM2_PCR_Event( 19 PCR_Event_In *in, // IN: input parameter list 20 PCR_Event_Out *out // OUT: output parameter list 21 ) 22 { 23 TPM_RC result; 24 HASH_STATE hashState; 25 UINT32 i; 26 UINT16 size; 27 28 // Input Validation 29 30 // If a PCR extend is required 31 if(in->pcrHandle != TPM_RH_NULL) 32 { 33 // If the PCR is not allow to extend, return error 34 if(!PCRIsExtendAllowed(in->pcrHandle)) 35 return TPM_RC_LOCALITY; 36 37 // If PCR is state saved and we need to update orderlyState, check NV 38 // availability 39 if(PCRIsStateSaved(in->pcrHandle) && gp.orderlyState != SHUTDOWN_NONE) 40 { 41 result = NvIsAvailable(); 42 if(result != TPM_RC_SUCCESS) return result; 43 g_clearOrderly = TRUE; 44 } 45 } 46 47 // Internal Data Update 48 49 out->digests.count = HASH_COUNT; 50 51 // Iterate supported PCR bank algorithms to extend 52 for(i = 0; i < HASH_COUNT; i++) 53 { 54 TPM_ALG_ID hash = CryptGetHashAlgByIndex(i); 55 out->digests.digests[i].hashAlg = hash; 56 size = CryptStartHash(hash, &hashState); 57 CryptUpdateDigest2B(&hashState, &in->eventData.b); 58 CryptCompleteHash(&hashState, size, 59 (BYTE *) &out->digests.digests[i].digest); 60 if(in->pcrHandle != TPM_RH_NULL) 61 PCRExtend(in->pcrHandle, hash, size, 62 (BYTE *) &out->digests.digests[i].digest); 63 } 64 65 return TPM_RC_SUCCESS; 66 } 67