aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.vnet.ibm.com>2016-08-05 11:07:09 -0400
committerKevin O'Connor <kevin@koconnor.net>2016-08-10 15:01:04 -0400
commit0fb23c327d553049500d251ae9376c3e2ce1f2d1 (patch)
treec1dadbb62cd02d252afc230a7288686196f57678
parent74544faa47b7fefebfe3a65c1419d5e436986d1b (diff)
downloadseabios-0fb23c327d553049500d251ae9376c3e2ce1f2d1.zip
seabios-0fb23c327d553049500d251ae9376c3e2ce1f2d1.tar.gz
seabios-0fb23c327d553049500d251ae9376c3e2ce1f2d1.tar.bz2
tpm: Restructure tpm20_extend to use buffer and take hash as parameter
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>
-rw-r--r--src/std/tcg.h2
-rw-r--r--src/tcgbios.c21
2 files changed, 13 insertions, 10 deletions
diff --git a/src/std/tcg.h b/src/std/tcg.h
index d60ee09..1644684 100644
--- a/src/std/tcg.h
+++ b/src/std/tcg.h
@@ -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;
diff --git a/src/tcgbios.c b/src/tcgbios.c
index f9c6f74..98bab9d 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -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;