mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
vTPM/TPM2: TPM 2.0 PCRs read
Signed-off-by: Quan Xu <quan.xu@intel.com> Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
This commit is contained in:
1 parent
71a7c55ad0
commit
98cbe87243
3 files changed
+37
No files matched your search
@@ -51,6 +51,7 @@
|
||||
#include "vtpm_disk.h"
|
||||
#include "tpm.h"
|
||||
#include "marshal.h"
|
||||
#include "tpm2_marshal.h"
|
||||
#include "tpm2.h"
|
||||
|
||||
struct Opts {
|
||||
@@ -754,3 +755,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;
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||