| 1 |
/* |
| 2 |
* Copyright (c) 2010-2012 United States Government, as represented by |
| 3 |
* the Secretary of Defense. All rights reserved. |
| 4 |
* |
| 5 |
* THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT |
| 6 |
* ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES |
| 7 |
* INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS |
| 8 |
* FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT ARE HEREBY |
| 9 |
* DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE |
| 10 |
* SOFTWARE. |
| 11 |
*/ |
| 12 |
|
| 13 |
#include "vtpm_pcrs.h" |
| 14 |
#include "vtpm_cmd.h" |
| 15 |
#include "tpm/tpm_data.h" |
| 16 |
|
| 17 |
#define PCR_VALUE tpmData.permanent.data.pcrValue |
| 18 |
|
| 19 |
static int write_pcr_direct(unsigned int pcrIndex, uint8_t* val) { |
| 20 |
if(pcrIndex > TPM_NUM_PCR) { |
| 21 |
return TPM_BADINDEX; |
| 22 |
} |
| 23 |
memcpy(&PCR_VALUE[pcrIndex], val, sizeof(TPM_PCRVALUE)); |
| 24 |
return TPM_SUCCESS; |
| 25 |
} |
| 26 |
|
| 27 |
TPM_RESULT vtpm_initialize_hw_pcrs(struct tpmfront_dev* tpmfront_dev, unsigned long pcrs) |
| 28 |
{ |
| 29 |
TPM_RESULT rc = TPM_SUCCESS; |
| 30 |
uint8_t digest[sizeof(TPM_PCRVALUE)]; |
| 31 |
|
| 32 |
for(unsigned int i = 0; i < TPM_NUM_PCR; ++i) { |
| 33 |
if(pcrs & 1 << i) { |
| 34 |
if((rc = VTPM_PCRRead(tpmfront_dev, i, digest)) != TPM_SUCCESS) { |
| 35 |
error("TPM_PCRRead failed with error : %d", rc); |
| 36 |
return rc; |
| 37 |
} |
| 38 |
write_pcr_direct(i, digest); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
return rc; |
| 43 |
} |