Vadim Bendebury | 5679752 | 2015-05-20 10:32:25 -0700 | [diff] [blame] | 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); |
Jocelyn Bohr | a4ed3aa | 2015-07-30 10:44:16 -0700 | [diff] [blame] | 55 | out->digests.digests[i].hashAlg = hash; |
Vadim Bendebury | 5679752 | 2015-05-20 10:32:25 -0700 | [diff] [blame] | 56 | size = CryptStartHash(hash, &hashState); |
| 57 | CryptUpdateDigest2B(&hashState, &in->eventData.b); |
| 58 | CryptCompleteHash(&hashState, size, |
Jocelyn Bohr | a4ed3aa | 2015-07-30 10:44:16 -0700 | [diff] [blame] | 59 | (BYTE *) &out->digests.digests[i].digest); |
Vadim Bendebury | 5679752 | 2015-05-20 10:32:25 -0700 | [diff] [blame] | 60 | if(in->pcrHandle != TPM_RH_NULL) |
| 61 | PCRExtend(in->pcrHandle, hash, size, |
Jocelyn Bohr | a4ed3aa | 2015-07-30 10:44:16 -0700 | [diff] [blame] | 62 | (BYTE *) &out->digests.digests[i].digest); |
Vadim Bendebury | 5679752 | 2015-05-20 10:32:25 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | return TPM_RC_SUCCESS; |
| 66 | } |