]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tpm: Move TCG headers into a separate file
authorIlias Apalodimas <ilias.apalodimas@linaro.org>
Sun, 23 Jun 2024 11:48:14 +0000 (14:48 +0300)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 30 Jun 2024 11:58:31 +0000 (13:58 +0200)
commit 97707f12fdab ("tpm: Support boot measurements") moved out code
from the EFI subsystem into the TPM one to support measurements when
booting with !EFI.

Those were moved directly into the TPM subsystem and in the tpm-v2.c
library. In hindsight, it would have been better to move it in new
files since the TCG2 is governed by its own spec, it's overeall cleaner
and also easier to enable certain parts of the TPM functionality.

So let's start moving the headers in a new file containing the TCG
specific bits.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
boot/bootm.c
include/efi_tcg2.h
include/tpm-v2.h
include/tpm_tcg2.h [new file with mode: 0644]
lib/tpm-v2.c

index 3de87eb185d72825fb521bd0eba24b833cb9d729..376d63aafc952a1c928084fabdb285402578a0cd 100644 (file)
@@ -24,6 +24,7 @@
 #include <asm/io.h>
 #include <linux/sizes.h>
 #include <tpm-v2.h>
+#include <tpm_tcg2.h>
 #if defined(CONFIG_CMD_USB)
 #include <usb.h>
 #endif
index 54490969b2d135a4a8d163b37f6039e2332d1d71..8dfb1bc9527b0d8659743bb7ac8fbbe05d30bea7 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <efi_api.h>
 #include <tpm-v2.h>
+#include <tpm_tcg2.h>
 
 /* TPMV2 only */
 #define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002
index c9d5cb6d3e5a86937299205779fcba563ab7fc99..38d79207e321a2d3c15e1074032628d1f09f9eee 100644 (file)
@@ -55,59 +55,6 @@ struct udevice;
 #define TPM2_PT_MAX_COMMAND_SIZE       (u32)(TPM2_PT_FIXED + 30)
 #define TPM2_PT_MAX_RESPONSE_SIZE      (u32)(TPM2_PT_FIXED + 31)
 
-/*
- * event types, cf.
- * "TCG Server Management Domain Firmware Profile Specification",
- * rev 1.00, 2020-05-01
- */
-#define EV_POST_CODE                   ((u32)0x00000001)
-#define EV_NO_ACTION                   ((u32)0x00000003)
-#define EV_SEPARATOR                   ((u32)0x00000004)
-#define EV_ACTION                      ((u32)0x00000005)
-#define EV_TAG                         ((u32)0x00000006)
-#define EV_S_CRTM_CONTENTS             ((u32)0x00000007)
-#define EV_S_CRTM_VERSION              ((u32)0x00000008)
-#define EV_CPU_MICROCODE               ((u32)0x00000009)
-#define EV_PLATFORM_CONFIG_FLAGS       ((u32)0x0000000A)
-#define EV_TABLE_OF_DEVICES            ((u32)0x0000000B)
-#define EV_COMPACT_HASH                        ((u32)0x0000000C)
-
-/*
- * event types, cf.
- * "TCG PC Client Platform Firmware Profile Specification", Family "2.0"
- * Level 00 Version 1.05 Revision 23, May 7, 2021
- */
-#define EV_EFI_EVENT_BASE                      ((u32)0x80000000)
-#define EV_EFI_VARIABLE_DRIVER_CONFIG          ((u32)0x80000001)
-#define EV_EFI_VARIABLE_BOOT                   ((u32)0x80000002)
-#define EV_EFI_BOOT_SERVICES_APPLICATION       ((u32)0x80000003)
-#define EV_EFI_BOOT_SERVICES_DRIVER            ((u32)0x80000004)
-#define EV_EFI_RUNTIME_SERVICES_DRIVER         ((u32)0x80000005)
-#define EV_EFI_GPT_EVENT                       ((u32)0x80000006)
-#define EV_EFI_ACTION                          ((u32)0x80000007)
-#define EV_EFI_PLATFORM_FIRMWARE_BLOB          ((u32)0x80000008)
-#define EV_EFI_HANDOFF_TABLES                  ((u32)0x80000009)
-#define EV_EFI_PLATFORM_FIRMWARE_BLOB2         ((u32)0x8000000A)
-#define EV_EFI_HANDOFF_TABLES2                 ((u32)0x8000000B)
-#define EV_EFI_VARIABLE_BOOT2                  ((u32)0x8000000C)
-#define EV_EFI_HCRTM_EVENT                     ((u32)0x80000010)
-#define EV_EFI_VARIABLE_AUTHORITY              ((u32)0x800000E0)
-#define EV_EFI_SPDM_FIRMWARE_BLOB              ((u32)0x800000E1)
-#define EV_EFI_SPDM_FIRMWARE_CONFIG            ((u32)0x800000E2)
-
-#define EFI_CALLING_EFI_APPLICATION         \
-       "Calling EFI Application from Boot Option"
-#define EFI_RETURNING_FROM_EFI_APPLICATION  \
-       "Returning from EFI Application from Boot Option"
-#define EFI_EXIT_BOOT_SERVICES_INVOCATION   \
-       "Exit Boot Services Invocation"
-#define EFI_EXIT_BOOT_SERVICES_FAILED       \
-       "Exit Boot Services Returned with Failure"
-#define EFI_EXIT_BOOT_SERVICES_SUCCEEDED    \
-       "Exit Boot Services Returned with Success"
-#define EFI_DTB_EVENT_STRING \
-       "DTB DATA"
-
 /* TPMS_TAGGED_PROPERTY Structure */
 struct tpms_tagged_property {
        u32 property;
@@ -149,23 +96,6 @@ struct tpms_capability_data {
        union tpmu_capabilities data;
 } __packed;
 
-/**
- * SHA1 Event Log Entry Format
- *
- * @pcr_index: PCRIndex event extended to
- * @event_type:        Type of event (see EFI specs)
- * @digest:    Value extended into PCR index
- * @event_size:        Size of event
- * @event:     Event data
- */
-struct tcg_pcr_event {
-       u32 pcr_index;
-       u32 event_type;
-       u8 digest[TPM2_SHA1_DIGEST_SIZE];
-       u32 event_size;
-       u8 event[];
-} __packed;
-
 /**
  * Definition of TPMU_HA Union
  */
@@ -199,67 +129,6 @@ struct tpml_digest_values {
        struct tpmt_ha digests[TPM2_NUM_PCR_BANKS];
 } __packed;
 
-/**
- * Crypto Agile Log Entry Format
- *
- * @pcr_index: PCRIndex event extended to
- * @event_type:        Type of event
- * @digests:   List of digestsextended to PCR index
- * @event_size: Size of the event data
- * @event:     Event data
- */
-struct tcg_pcr_event2 {
-       u32 pcr_index;
-       u32 event_type;
-       struct tpml_digest_values digests;
-       u32 event_size;
-       u8 event[];
-} __packed;
-
-/**
- *  struct TCG_EfiSpecIdEventAlgorithmSize - hashing algorithm information
- *
- *  @algorithm_id:     algorithm defined in enum tpm2_algorithms
- *  @digest_size:      size of the algorithm
- */
-struct tcg_efi_spec_id_event_algorithm_size {
-       u16      algorithm_id;
-       u16      digest_size;
-} __packed;
-
-#define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03"
-#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2
-#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0
-#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2
-
-/**
- * struct TCG_EfiSpecIDEventStruct - content of the event log header
- *
- * @signature:                 signature, set to Spec ID Event03
- * @platform_class:            class defined in TCG ACPI Specification
- *                             Client  Common Header.
- * @spec_version_minor:                minor version
- * @spec_version_major:                major version
- * @spec_version_errata:       major version
- * @uintn_size:                        size of the efi_uintn_t fields used in various
- *                             data structures used in this specification.
- *                             0x01 indicates u32  and 0x02  indicates u64
- * @number_of_algorithms:      hashing algorithms used in this event log
- * @digest_sizes:              array of number_of_algorithms pairs
- *                             1st member defines the algorithm id
- *                             2nd member defines the algorithm size
- */
-struct tcg_efi_spec_id_event {
-       u8 signature[16];
-       u32 platform_class;
-       u8 spec_version_minor;
-       u8 spec_version_major;
-       u8 spec_errata;
-       u8 uintn_size;
-       u32 number_of_algorithms;
-       struct tcg_efi_spec_id_event_algorithm_size digest_sizes[];
-} __packed;
-
 /**
  * TPM2 Structure Tags for command/response buffers.
  *
diff --git a/include/tpm_tcg2.h b/include/tpm_tcg2.h
new file mode 100644 (file)
index 0000000..581ff6f
--- /dev/null
@@ -0,0 +1,146 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Defines APIs and structures that adhere to
+ * https://trustedcomputinggroup.org/resource/pc-client-specific-platform-firmware-profile-specification/
+ * https://trustedcomputinggroup.org/resource/tcg-efi-protocol-specification/
+ *
+ * Copyright (c) 2020 Linaro Limited
+ */
+
+#ifndef __TPM_TCG_V2_H
+#define __TPM_TCG_V2_H
+
+#include <tpm-v2.h>
+
+/*
+ * event types, cf.
+ * "TCG Server Management Domain Firmware Profile Specification",
+ * rev 1.00, 2020-05-01
+ */
+#define EV_POST_CODE                   ((u32)0x00000001)
+#define EV_NO_ACTION                   ((u32)0x00000003)
+#define EV_SEPARATOR                   ((u32)0x00000004)
+#define EV_ACTION                      ((u32)0x00000005)
+#define EV_TAG                         ((u32)0x00000006)
+#define EV_S_CRTM_CONTENTS             ((u32)0x00000007)
+#define EV_S_CRTM_VERSION              ((u32)0x00000008)
+#define EV_CPU_MICROCODE               ((u32)0x00000009)
+#define EV_PLATFORM_CONFIG_FLAGS       ((u32)0x0000000A)
+#define EV_TABLE_OF_DEVICES            ((u32)0x0000000B)
+#define EV_COMPACT_HASH                        ((u32)0x0000000C)
+
+/*
+ * event types, cf.
+ * "TCG PC Client Platform Firmware Profile Specification", Family "2.0"
+ * Level 00 Version 1.05 Revision 23, May 7, 2021
+ */
+#define EV_EFI_EVENT_BASE                      ((u32)0x80000000)
+#define EV_EFI_VARIABLE_DRIVER_CONFIG          ((u32)0x80000001)
+#define EV_EFI_VARIABLE_BOOT                   ((u32)0x80000002)
+#define EV_EFI_BOOT_SERVICES_APPLICATION       ((u32)0x80000003)
+#define EV_EFI_BOOT_SERVICES_DRIVER            ((u32)0x80000004)
+#define EV_EFI_RUNTIME_SERVICES_DRIVER         ((u32)0x80000005)
+#define EV_EFI_GPT_EVENT                       ((u32)0x80000006)
+#define EV_EFI_ACTION                          ((u32)0x80000007)
+#define EV_EFI_PLATFORM_FIRMWARE_BLOB          ((u32)0x80000008)
+#define EV_EFI_HANDOFF_TABLES                  ((u32)0x80000009)
+#define EV_EFI_PLATFORM_FIRMWARE_BLOB2         ((u32)0x8000000A)
+#define EV_EFI_HANDOFF_TABLES2                 ((u32)0x8000000B)
+#define EV_EFI_VARIABLE_BOOT2                  ((u32)0x8000000C)
+#define EV_EFI_HCRTM_EVENT                     ((u32)0x80000010)
+#define EV_EFI_VARIABLE_AUTHORITY              ((u32)0x800000E0)
+#define EV_EFI_SPDM_FIRMWARE_BLOB              ((u32)0x800000E1)
+#define EV_EFI_SPDM_FIRMWARE_CONFIG            ((u32)0x800000E2)
+
+#define EFI_CALLING_EFI_APPLICATION         \
+       "Calling EFI Application from Boot Option"
+#define EFI_RETURNING_FROM_EFI_APPLICATION  \
+       "Returning from EFI Application from Boot Option"
+#define EFI_EXIT_BOOT_SERVICES_INVOCATION   \
+       "Exit Boot Services Invocation"
+#define EFI_EXIT_BOOT_SERVICES_FAILED       \
+       "Exit Boot Services Returned with Failure"
+#define EFI_EXIT_BOOT_SERVICES_SUCCEEDED    \
+       "Exit Boot Services Returned with Success"
+#define EFI_DTB_EVENT_STRING \
+       "DTB DATA"
+
+/**
+ *  struct TCG_EfiSpecIdEventAlgorithmSize - hashing algorithm information
+ *
+ *  @algorithm_id:     algorithm defined in enum tpm2_algorithms
+ *  @digest_size:      size of the algorithm
+ */
+struct tcg_efi_spec_id_event_algorithm_size {
+       u16      algorithm_id;
+       u16      digest_size;
+} __packed;
+
+/**
+ * SHA1 Event Log Entry Format
+ *
+ * @pcr_index: PCRIndex event extended to
+ * @event_type:        Type of event (see EFI specs)
+ * @digest:    Value extended into PCR index
+ * @event_size:        Size of event
+ * @event:     Event data
+ */
+struct tcg_pcr_event {
+       u32 pcr_index;
+       u32 event_type;
+       u8 digest[TPM2_SHA1_DIGEST_SIZE];
+       u32 event_size;
+       u8 event[];
+} __packed;
+
+/**
+ * Crypto Agile Log Entry Format
+ *
+ * @pcr_index: PCRIndex event extended to
+ * @event_type:        Type of event
+ * @digests:   List of digestsextended to PCR index
+ * @event_size: Size of the event data
+ * @event:     Event data
+ */
+struct tcg_pcr_event2 {
+       u32 pcr_index;
+       u32 event_type;
+       struct tpml_digest_values digests;
+       u32 event_size;
+       u8 event[];
+} __packed;
+
+/**
+ * struct TCG_EfiSpecIDEventStruct - content of the event log header
+ *
+ * @signature:                 signature, set to Spec ID Event03
+ * @platform_class:            class defined in TCG ACPI Specification
+ *                             Client  Common Header.
+ * @spec_version_minor:                minor version
+ * @spec_version_major:                major version
+ * @spec_version_errata:       major version
+ * @uintn_size:                        size of the efi_uintn_t fields used in various
+ *                             data structures used in this specification.
+ *                             0x01 indicates u32  and 0x02  indicates u64
+ * @number_of_algorithms:      hashing algorithms used in this event log
+ * @digest_sizes:              array of number_of_algorithms pairs
+ *                             1st member defines the algorithm id
+ *                             2nd member defines the algorithm size
+ */
+struct tcg_efi_spec_id_event {
+       u8 signature[16];
+       u32 platform_class;
+       u8 spec_version_minor;
+       u8 spec_version_major;
+       u8 spec_errata;
+       u8 uintn_size;
+       u32 number_of_algorithms;
+       struct tcg_efi_spec_id_event_algorithm_size digest_sizes[];
+} __packed;
+
+#define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03"
+#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2
+#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0
+#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2
+
+#endif /* __TPM_TCG_V2_H */
index 91526af33acb22b35cacc2051adf6353756c98ac..c3832bb7f767d2b472fb1946aee489274e51e378 100644 (file)
@@ -10,6 +10,7 @@
 #include <tpm_api.h>
 #include <tpm-common.h>
 #include <tpm-v2.h>
+#include <tpm_tcg2.h>
 #include <u-boot/sha1.h>
 #include <u-boot/sha256.h>
 #include <u-boot/sha512.h>