]> xenbits.xensource.com Git - people/andrewcoop/seabios.git/commitdiff
tpm: Restructure tpm20_extend to use buffer and take hash as parameter
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Fri, 5 Aug 2016 15:07:09 +0000 (11:07 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 10 Aug 2016 19:01:04 +0000 (15:01 -0400)
Restructure the tpm20_extend function to use a buffer for the
command to send to the TPM. The size of the buffer is calculated
from the size of tpm2_req_extend structure and the appended SHA1
hash.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
src/std/tcg.h
src/tcgbios.c

index d60ee09aff1353db7ce03d36272f75e964dfbb5b..16446841ec395b5dc9c247c3fde96ac061a8f227 100644 (file)
@@ -442,7 +442,6 @@ struct tpm2_req_hierarchychangeauth {
 } PACKED;
 
 struct tpm2_digest_value {
-    u32 count; /* 1 entry only */
     u16 hashalg; /* TPM2_ALG_SHA1 */
     u8 sha1[SHA1_BUFSIZE];
 } PACKED;
@@ -452,6 +451,7 @@ struct tpm2_req_extend {
     u32 pcrindex;
     u32 authblocksize;
     struct tpm2_authblock authblock;
+    u32 count;
     struct tpm2_digest_value digest;
 } PACKED;
 
index f9c6f74dd60c835073063eb3681c5f4dc8805efb..98bab9d69e9185acdc5f01224023111f22f9d979 100644 (file)
@@ -499,28 +499,31 @@ tpm12_extend(u32 pcrindex, const u8 *digest)
 
 static int tpm20_extend(u32 pcrindex, const u8 *digest)
 {
-    struct tpm2_req_extend tre = {
+    struct tpm2_req_extend tmp_tre = {
         .hdr.tag     = cpu_to_be16(TPM2_ST_SESSIONS),
-        .hdr.totlen  = cpu_to_be32(sizeof(tre)),
+        .hdr.totlen  = cpu_to_be32(sizeof(tmp_tre)),
         .hdr.ordinal = cpu_to_be32(TPM2_CC_PCR_Extend),
         .pcrindex    = cpu_to_be32(pcrindex),
-        .authblocksize = cpu_to_be32(sizeof(tre.authblock)),
+        .authblocksize = cpu_to_be32(sizeof(tmp_tre.authblock)),
         .authblock = {
             .handle = cpu_to_be32(TPM2_RS_PW),
             .noncesize = cpu_to_be16(0),
             .contsession = TPM2_YES,
             .pwdsize = cpu_to_be16(0),
         },
-        .digest = {
-            .count = cpu_to_be32(1),
-            .hashalg = cpu_to_be16(TPM2_ALG_SHA1),
-        },
     };
-    memcpy(tre.digest.sha1, digest, sizeof(tre.digest.sha1));
+    u32 count = 1;
+    u8 buffer[sizeof(tmp_tre) + sizeof(struct tpm2_digest_value)];
+    struct tpm2_req_extend *tre = (struct tpm2_req_extend *)buffer;
+
+    memcpy(tre, &tmp_tre, sizeof(tmp_tre));
+    tre->count = cpu_to_be32(count);
+    tre->digest.hashalg = cpu_to_be16(TPM2_ALG_SHA1);
+    memcpy(tre->digest.sha1, digest, sizeof(tmp_tre.digest.sha1));
 
     struct tpm_rsp_header rsp;
     u32 resp_length = sizeof(rsp);
-    int ret = tpmhw_transmit(0, &tre.hdr, &rsp, &resp_length,
+    int ret = tpmhw_transmit(0, &tre->hdr, &rsp, &resp_length,
                              TPM_DURATION_TYPE_SHORT);
     if (ret || resp_length != sizeof(rsp) || rsp.errcode)
         return -1;