1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 3 #ifndef __TPM2_LOG_SERIALIZED_H__ 4 #define __TPM2_LOG_SERIALIZED_H__ 5 6 #include <commonlib/bsd/tpm_log_defs.h> 7 8 #define TPM_20_SPEC_ID_EVENT_SIGNATURE "Spec ID Event03" 9 #define TPM_20_LOG_DATA_MAX_LENGTH 50 10 11 #define TPM_20_LOG_VI_MAGIC 0x32544243 /* "CBT2" in LE */ 12 #define TPM_20_LOG_VI_MAJOR 1 13 #define TPM_20_LOG_VI_MINOR 0 14 15 /* 16 * TPM2.0 log entries can't be generally represented as C structures due to 17 * varying number of digests and their sizes. However, it works as long as 18 * we're only using single kind of digests. 19 */ 20 #if CONFIG(TPM_LOG_TPM2) 21 # if CONFIG(TPM_HASH_SHA1) 22 # define TPM_20_LOG_DIGEST_MAX_LENGTH SHA1_DIGEST_SIZE 23 # endif 24 # if CONFIG(TPM_HASH_SHA256) 25 # define TPM_20_LOG_DIGEST_MAX_LENGTH SHA256_DIGEST_SIZE 26 # endif 27 # if CONFIG(TPM_HASH_SHA384) 28 # define TPM_20_LOG_DIGEST_MAX_LENGTH SHA384_DIGEST_SIZE 29 # endif 30 # if CONFIG(TPM_HASH_SHA512) 31 # define TPM_20_LOG_DIGEST_MAX_LENGTH SHA512_DIGEST_SIZE 32 # endif 33 34 # ifndef TPM_20_LOG_DIGEST_MAX_LENGTH 35 # error "Misconfiguration: failed to determine TPM hashing algorithm" 36 # endif 37 #else 38 # define TPM_20_LOG_DIGEST_MAX_LENGTH 1 /* To avoid compilation error */ 39 #endif 40 41 /* TCG_PCR_EVENT2 */ 42 struct tpm_2_log_entry { 43 uint32_t pcr; 44 uint32_t event_type; 45 uint32_t digest_count; /* Always 1 in current implementation */ 46 uint16_t digest_type; 47 uint8_t digest[TPM_20_LOG_DIGEST_MAX_LENGTH]; 48 uint32_t data_length; 49 uint8_t data[TPM_20_LOG_DATA_MAX_LENGTH]; 50 } __packed; 51 52 struct tpm_2_vendor { 53 uint8_t reserved; 54 uint8_t version_major; 55 uint8_t version_minor; 56 uint32_t magic; 57 uint16_t max_entries; 58 uint16_t num_entries; 59 uint32_t entry_size; 60 } __packed; 61 62 struct tpm_2_log_table { 63 struct tcg_efi_spec_id_event header; /* TCG_PCR_EVENT actually */ 64 struct tpm_digest_sizes digest_sizes[1]; 65 uint8_t vendor_info_size; 66 struct tpm_2_vendor vendor; 67 struct tpm_2_log_entry entries[]; /* Variable number of entries */ 68 } __packed; 69 70 #endif 71