vTPM/TPM2: TPM 2.0 PCRs read
PATCH v3 10/14 vTPM/TPM2: TPM 2.0 PCRs read
Signed-off-by Quan Xu <[email protected]>
--- stubdom/vtpmmgr/init.c | 34 ++++++++++++++++++++++++++++++++++ stubdom/vtpmmgr/tpm2_types.h | 2 ++ stubdom/vtpmmgr/vtpmmgr.h | 1 + 3 files changed, 37 insertions(+)
stubdom/vtpmmgr/init.c +34 -0
@@ -51,6 +51,7 @@#include "vtpm_disk.h" #include "tpm.h" #include "marshal.h" +#include "tpm2_marshal.h" #include "tpm2.h" struct Opts {
@@ -790,3 +791,36 @@ abort_egress: egress:return status; } + +TPM_RC tpm2_pcr_read (int index,uint8_t *buf) +{ +TPM_RESULT status =TPM_SUCCESS ; +TPML_PCR_SELECTION pcrSelectionIn = { + .count =1 ,}; + +TPMS_PCR_SELECTION tpms_pcr_selection = { + .hash =TPM2_ALG_SHA1 , + .sizeofSelect =PCR_SELECT_MAX ,}; + +UINT32 pcrUpdateCounter; +TPML_PCR_SELECTION pcrSelectionOut; +TPML_DIGEST pcrValues; +TPM2B_DIGEST tpm2b_digest; + + tpms_pcr_selection.pcrSelect[PCR_SELECT_NUM (index)] =PCR_SELECT_VALUE (index); +memcpy (&pcrSelectionIn.pcrSelections[0 ], &tpms_pcr_selection, +sizeof (TPMS_PCR_SELECTION )); + +TPMTRYRETURN (TPM2_PCR_Read (pcrSelectionIn, &pcrUpdateCounter, + &pcrSelectionOut, &pcrValues)); + +if (pcrValues.count <1 ) + goto egress; + +unpack_TPM2B_DIGEST ((uint8_t *) &pcrValues, &tpm2b_digest); +memcpy (buf, tpm2b_digest.buffer,SHA1_DIGEST_SIZE ); + +abort_egress: +egress: +return status; +}
stubdom/vtpmmgr/tpm2_types.h +2 -0
@@ -432,6 +432,8 @@ typedef struct {#define IMPLEMENTATION_PCR 24#define PLATFORM_PCR 24#define PCR_SELECT_MAX ((IMPLEMENTATION_PCR+7)/8) +#define PCR_SELECT_NUM (x) (uint8_t)(x/8) +#define PCR_SELECT_VALUE (x) (uint8_t)(0x1)<<(x%8)//Table 79 -- TPMS_PCR_SELECT Structure <I/O> typedef struct {
stubdom/vtpmmgr/vtpmmgr.h +1 -0
@@ -107,6 +107,7 @@ inline TPM_RESULT vtpmmgr_rand(unsigned char* bytes, size_t num_bytes) {/* TPM 2.0 */ TPM_RC tpm2_take_ownership (void ); +TPM_RC tpm2_pcr_read (int index,uint8_t *buf);TPM_RESULT vtpmmgr2_create (void );TPM_RESULT vtpmmgr2_init (int argc,char ** argv);int parse_cmdline_hw (int argc,char ** argv);
Signature · 1 line
1.8.3.2