Refactor the tpml_digest_values_sha1 structure so we can later cast it to the more general tpml_digest_values structure. Move the count member into this structure.
Signed-off-by: Stefan Berger stefanb@linux.vnet.ibm.com --- src/std/tcg.h | 6 +++--- src/tcgbios.c | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/src/std/tcg.h b/src/std/tcg.h index 1644684..730b39c 100644 --- a/src/std/tcg.h +++ b/src/std/tcg.h @@ -507,15 +507,15 @@ struct tpml_pcr_selection { /* TPM 2 log entry */
struct tpml_digest_values_sha1 { + u32 count; /* number of digests */ u16 hashtype; u8 sha1[SHA1_BUFSIZE]; -}; +} PACKED;
struct tcg_pcr_event2_sha1 { u32 pcrindex; u32 eventtype; - u32 count; /* number of digests */ - struct tpml_digest_values_sha1 digests[1]; + struct tpml_digest_values_sha1 digest; u32 eventdatasize; u8 event[0]; } PACKED; diff --git a/src/tcgbios.c b/src/tcgbios.c index 98bab9d..9dddc4b 100644 --- a/src/tcgbios.c +++ b/src/tcgbios.c @@ -166,7 +166,7 @@ tpm_log_event(struct tcg_pcr_event2_sha1 *entry, const void *event struct pcpes *pcpes = (void*)tpm_state.log_area_next_entry; pcpes->pcrindex = entry->pcrindex; pcpes->eventtype = entry->eventtype; - memcpy(pcpes->digest, entry->digests[0].sha1, sizeof(pcpes->digest)); + memcpy(pcpes->digest, entry->digest.sha1, sizeof(pcpes->digest)); pcpes->eventdatasize = entry->eventdatasize; memcpy(pcpes->event, event, entry->eventdatasize); size = sizeof(*pcpes) + entry->eventdatasize; @@ -567,11 +567,13 @@ tpm_add_measurement_to_log(u32 pcrindex, u32 event_type, .pcrindex = pcrindex, .eventtype = event_type, .eventdatasize = event_length, - .count = 1, - .digests[0].hashtype = TPM2_ALG_SHA1, + .digest = { + .count = 1, + .hashtype = TPM2_ALG_SHA1, + } }; - sha1(hashdata, hashdata_length, entry.digests[0].sha1); - int ret = tpm_extend(entry.pcrindex, entry.digests[0].sha1); + sha1(hashdata, hashdata_length, entry.digest.sha1); + int ret = tpm_extend(entry.pcrindex, entry.digest.sha1); if (ret) { tpm_set_failure(); return; @@ -1110,10 +1112,12 @@ hash_log_extend(struct pcpes *pcpes, const void *hashdata, u32 hashdata_length .pcrindex = pcpes->pcrindex, .eventtype = pcpes->eventtype, .eventdatasize = pcpes->eventdatasize, - .count = 1, - .digests[0].hashtype = TPM2_ALG_SHA1, + .digest = { + .count = 1, + .hashtype = TPM2_ALG_SHA1, + } }; - memcpy(entry.digests[0].sha1, pcpes->digest, sizeof(entry.digests[0].sha1)); + memcpy(entry.digest.sha1, pcpes->digest, sizeof(entry.digest.sha1)); int ret = tpm_log_event(&entry, pcpes->event, TPM_version); if (ret) return TCG_PC_LOGOVERFLOW;