[SeaBIOS] [PATCH 3/8] tpm: Perform hashing separately from logging

Kevin O'Connor kevin at koconnor.net
Mon Nov 23 02:02:33 CET 2015


Instead of calculating the hash in hash_log_event(), create a new
function (tpm_fill_hash) that will create the hash, and update all
callers to use tpm_fill_hash() before calling hash_log_event().  This
reduce the number of parameters to hash_log_event().

Rename hash_log_event() and hash_log_extent_event() to tpm_log_event()
and tpm_log_extend_event() now that these functions no longer
implement the hashing.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/tcgbios.c | 54 +++++++++++++++++++++---------------------------------
 1 file changed, 21 insertions(+), 33 deletions(-)

diff --git a/src/tcgbios.c b/src/tcgbios.c
index 1fb8e5c..0c28935 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -513,45 +513,36 @@ tpm_extend(u8 *hash, u32 pcrindex)
 }
 
 static u32
-hash_log_event(const void *hashdata, u32 hashdata_length,
-               struct pcpes *pcpes,
-               const char *event, u32 event_length)
+tpm_log_event(struct pcpes *pcpes, const char *event, u32 event_length)
 {
-    u32 rc = 0;
-
     if (pcpes->pcrindex >= 24)
         return TCG_INVALID_INPUT_PARA;
 
-    if (hashdata) {
-        rc = sha1(hashdata, hashdata_length, pcpes->digest);
-        if (rc)
-            return rc;
-    }
-
     if (!has_working_tpm())
         return TCG_GENERAL_ERROR;
 
-    rc = tpm_extend_acpi_log(pcpes, event, event_length);
+    u32 rc = tpm_extend_acpi_log(pcpes, event, event_length);
     if (rc)
         tpm_set_failure();
     return rc;
 }
 
 static u32
-hash_log_extend_event(const void *hashdata, u32 hashdata_length,
-                      struct pcpes *pcpes,
-                      const char *event, u32 event_length)
+tpm_log_extend_event(struct pcpes *pcpes, const char *event, u32 event_length)
 {
-    u32 rc;
-
-    rc = hash_log_event(hashdata, hashdata_length, pcpes,
-                        event, event_length);
+    u32 rc = tpm_log_event(pcpes, event, event_length);
     if (rc)
         return rc;
-
     return tpm_extend(pcpes->digest, pcpes->pcrindex);
 }
 
+static void
+tpm_fill_hash(struct pcpes *pcpes, const void *hashdata, u32 hashdata_length)
+{
+    if (hashdata)
+        sha1(hashdata, hashdata_length, pcpes->digest);
+}
+
 /*
  * Add a measurement to the log; the data at data_seg:data/length are
  * appended to the TCG_PCClientPCREventStruct
@@ -573,8 +564,8 @@ tpm_add_measurement_to_log(u32 pcrindex, u32 event_type,
         .pcrindex = pcrindex,
         .eventtype = event_type,
     };
-    return hash_log_extend_event(hashdata, hashdata_length, &pcpes,
-                                 event, event_length);
+    tpm_fill_hash(&pcpes, hashdata, hashdata_length);
+    return tpm_log_extend_event(&pcpes, event, event_length);
 }
 
 
@@ -991,9 +982,9 @@ hash_log_extend_event_int(const struct hleei_short *hleei_s,
         goto err_exit;
     }
 
-    rc = hash_log_extend_event(hleei_s->hashdataptr, hleei_s->hashdatalen,
-                               pcpes,
-                               (char *)&pcpes->event, pcpes->eventdatasize);
+    tpm_fill_hash(pcpes, hleei_s->hashdataptr, hleei_s->hashdatalen);
+    rc = tpm_log_extend_event(pcpes
+                              , (char *)&pcpes->event, pcpes->eventdatasize);
     if (rc)
         goto err_exit;
 
@@ -1008,7 +999,6 @@ err_exit:
     }
 
     return rc;
-
 }
 
 static u32
@@ -1096,8 +1086,8 @@ hash_log_event_int(const struct hlei *hlei, struct hleo *hleo)
         goto err_exit;
     }
 
-    rc = hash_log_event(hlei->hashdataptr, hlei->hashdatalen,
-                        pcpes, (char *)&pcpes->event, pcpes->eventdatasize);
+    tpm_fill_hash(pcpes, hlei->hashdataptr, hlei->hashdatalen);
+    rc = tpm_log_event(pcpes, (char *)&pcpes->event, pcpes->eventdatasize);
     if (rc)
         goto err_exit;
 
@@ -1154,7 +1144,6 @@ compact_hash_log_extend_event_int(u8 *buffer,
                                   u32 pcrindex,
                                   u32 *edx_ptr)
 {
-    u32 rc = 0;
     struct pcpes pcpes = {
         .pcrindex      = pcrindex,
         .eventtype     = EV_COMPACT_HASH,
@@ -1165,10 +1154,9 @@ compact_hash_log_extend_event_int(u8 *buffer,
     if (is_preboot_if_shutdown() != 0)
         return TCG_INTERFACE_SHUTDOWN;
 
-    rc = hash_log_extend_event(buffer, length,
-                               &pcpes,
-                               (char *)&pcpes.event, pcpes.eventdatasize);
-
+    tpm_fill_hash(&pcpes, buffer, length);
+    u32 rc = tpm_log_extend_event(&pcpes,
+                                  (char *)&pcpes.event, pcpes.eventdatasize);
     if (rc == 0)
         *edx_ptr = tpm_state.entry_count;
 
-- 
2.5.0




More information about the SeaBIOS mailing list