summaryrefslogtreecommitdiff
path: root/firmware/lib/tpm2_lite/tlcl.c
diff options
context:
space:
mode:
authorAndrey Pronin <apronin@chromium.org>2017-10-06 20:01:53 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-10-12 16:35:30 -0700
commit3b805725c15022783f0737a72b4f27962abf48cd (patch)
tree901659ef5fe07f9799b298f66871ef49301a782b /firmware/lib/tpm2_lite/tlcl.c
parent5d5b2f16109662dceb55dfbe62772ee41887be82 (diff)
downloadvboot-stabilize-10032.75.B.tar.gz
1) Extend TlclGetVersion to return vendor specific data, if requested. 2) Extend 'tpmc getver' to include vendor specific data. BRANCH=none BUG=chromium:771561 TEST=unit tests, running 'tpmc getver' Change-Id: Ic04c242d4e6f33b45a80479be9ab9777b317ebe2 Reviewed-on: https://chromium-review.googlesource.com/706240 Commit-Ready: Andrey Pronin <apronin@chromium.org> Tested-by: Andrey Pronin <apronin@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org>
Diffstat (limited to 'firmware/lib/tpm2_lite/tlcl.c')
-rw-r--r--firmware/lib/tpm2_lite/tlcl.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/firmware/lib/tpm2_lite/tlcl.c b/firmware/lib/tpm2_lite/tlcl.c
index bb212d24..89bf25a7 100644
--- a/firmware/lib/tpm2_lite/tlcl.c
+++ b/firmware/lib/tpm2_lite/tlcl.c
@@ -523,7 +523,25 @@ uint32_t TlclGetRandom(uint8_t *data, uint32_t length, uint32_t *size)
return TPM_E_IOERROR;
}
-uint32_t TlclGetVersion(uint32_t* vendor, uint64_t* firmware_version)
+// Converts TPM_PT_VENDOR_STRING_x |value| to an array of bytes in |buf|.
+// Returns the number of bytes in the array.
+// |buf| should be at least 4 bytes long.
+size_t tlcl_vendor_string_parse(uint32_t value, uint8_t* buf)
+{
+ size_t len = 0;
+ int shift = 24;
+ for (; len < 4; shift -= 8) {
+ uint8_t byte = (value >> shift) & 0xffu;
+ if (!byte)
+ break;
+ buf[len++] = byte;
+ }
+ return len;
+}
+
+uint32_t TlclGetVersion(uint32_t* vendor, uint64_t* firmware_version,
+ uint8_t* vendor_specific_buf,
+ size_t* vendor_specific_buf_size)
{
uint32_t result = tlcl_get_tpm_property(TPM_PT_MANUFACTURER, vendor);
if (result != TPM_SUCCESS)
@@ -539,6 +557,35 @@ uint32_t TlclGetVersion(uint32_t* vendor, uint64_t* firmware_version)
return result;
*firmware_version = ((uint64_t) version_1 << 32) | version_2;
+
+ if (!vendor_specific_buf_size)
+ return TPM_SUCCESS;
+
+ size_t total_size = 0;
+ uint32_t prop_id;
+ uint8_t prop_string[16];
+ for (prop_id = TPM_PT_VENDOR_STRING_1;
+ prop_id <= TPM_PT_VENDOR_STRING_4;
+ ++prop_id) {
+ uint32_t prop_value;
+ result = tlcl_get_tpm_property(prop_id, &prop_value);
+ if (result != TPM_SUCCESS)
+ break;
+
+ size_t prop_len = tlcl_vendor_string_parse(
+ prop_value, prop_string + total_size);
+ VbAssert(prop_len <= 4 &&
+ total_size + prop_len <= sizeof(prop_string));
+ total_size += prop_len;
+ if (prop_len < 4)
+ break;
+ }
+ if (vendor_specific_buf) {
+ if (total_size > *vendor_specific_buf_size)
+ total_size = *vendor_specific_buf_size;
+ memcpy(vendor_specific_buf, prop_string, total_size);
+ }
+ *vendor_specific_buf_size = total_size;
return TPM_SUCCESS;
}