tpm_lite: Add function to read PCRs
Change-Id: I9e3a2eebcf30dc6118900d805122b049d229958c
diff --git a/common/tlcl.c b/common/tlcl.c
index bcba16d..ead5256 100644
--- a/common/tlcl.c
+++ b/common/tlcl.c
@@ -334,3 +334,21 @@
kPcrDigestLength);
return result;
}
+
+uint32_t tlcl_read_pcr(int pcr_num, uint8_t* out_digest)
+{
+ struct s_tpm_pcr_read_cmd cmd;
+ uint8_t response[kTpmResponseHeaderLength + kPcrDigestLength];
+ uint32_t result;
+
+ memcpy(&cmd, &tpm_pcr_read_cmd, sizeof(cmd));
+ to_tpm_uint32(cmd.buffer + tpm_pcr_read_cmd.pcrNum, pcr_num);
+
+ result = tlcl_send_receive(cmd.buffer, response, sizeof(response));
+ if (result != TPM_SUCCESS)
+ return result;
+
+ memcpy(out_digest, response + kTpmResponseHeaderLength,
+ kPcrDigestLength);
+ return result;
+}
diff --git a/include/tpm_lite/tlcl.h b/include/tpm_lite/tlcl.h
index 7724592..47fc76b 100644
--- a/include/tpm_lite/tlcl.h
+++ b/include/tpm_lite/tlcl.h
@@ -134,4 +134,9 @@
*/
uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags);
+/**
+ * Read a PCR
+ */
+uint32_t tlcl_read_pcr(int pcr_num, uint8_t* out_digest);
+
#endif /* TPM_LITE_TLCL_H_ */