summaryrefslogtreecommitdiff
path: root/tpm.c
diff options
context:
space:
mode:
authorJavier Martinez Canillas <javierm@redhat.com>2017-06-15 15:16:04 +0200
committerPeter Jones <pjones@redhat.com>2017-06-15 11:30:22 -0400
commit9c40fb7c0570430e28c8e5bc34223d6e3a59a929 (patch)
tree71461485f8c526555b8c3389ce0bf965d207b720 /tpm.c
parent6d4498fb3b66621992ef61f163befd1c8374781b (diff)
downloadefi-boot-shim-9c40fb7c0570430e28c8e5bc34223d6e3a59a929.tar.gz
efi-boot-shim-9c40fb7c0570430e28c8e5bc34223d6e3a59a929.zip
shim/tpm: Remove magic numbers
When measuring data into the TPM and generating events logs, the event type is set to EV_IPL (0xd), and for TPM1.2 the algorithm will always be set to SHA-1 (0x4). So, add some macro-defined constants for these instead of having them as magic numbers to make the code more readable. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Diffstat (limited to 'tpm.c')
-rw-r--r--tpm.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/tpm.c b/tpm.c
index 88920bbf..99486b10 100644
--- a/tpm.c
+++ b/tpm.c
@@ -110,7 +110,7 @@ EFI_STATUS tpm_log_event(EFI_PHYSICAL_ADDRESS buf, UINTN size, UINT8 pcr,
event->Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER);
event->Header.HeaderVersion = 1;
event->Header.PCRIndex = pcr;
- event->Header.EventType = 0x0d;
+ event->Header.EventType = EV_IPL;
event->Size = sizeof(*event) - sizeof(event->Event) + strlen(description) + 1;
memcpy(event->Event, description, strlen(description) + 1);
status = uefi_call_wrapper(tpm2->hash_log_extend_event, 5, tpm2,
@@ -119,7 +119,7 @@ EFI_STATUS tpm_log_event(EFI_PHYSICAL_ADDRESS buf, UINTN size, UINT8 pcr,
return status;
} else {
TCG_PCR_EVENT *event;
- UINT32 algorithm, eventnum = 0;
+ UINT32 eventnum = 0;
EFI_PHYSICAL_ADDRESS lastevent;
status = LibLocateProtocol(&tpm_guid, (VOID **)&tpm);
@@ -138,11 +138,10 @@ EFI_STATUS tpm_log_event(EFI_PHYSICAL_ADDRESS buf, UINTN size, UINT8 pcr,
}
event->PCRIndex = pcr;
- event->EventType = 0x0d;
+ event->EventType = EV_IPL;
event->EventSize = strlen(description) + 1;
- algorithm = 0x00000004;
status = uefi_call_wrapper(tpm->log_extend_event, 7, tpm, buf,
- (UINT64)size, algorithm, event,
+ (UINT64)size, TPM_ALG_SHA, event,
&eventnum, &lastevent);
FreePool(event);
return status;