github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/txtlog/structures.go (about) 1 // Copyright 2020 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 package txtlog 5 6 import ( 7 "github.com/rekby/gpt" 8 ) 9 10 // IAlgHash is the TPM hash algorithm 11 type IAlgHash uint16 12 13 // We only define TPM hash algorithms here we use 14 const ( 15 // TPMAlgError is an algorithm error 16 TPMAlgError IAlgHash = 0x0000 17 // TPMAlgSha 18 TPMAlgSha IAlgHash = 0x0004 19 TPMAlgSha256 IAlgHash = 0x000B 20 TPMAlgSha384 IAlgHash = 0x000C 21 TPMAlgSha512 IAlgHash = 0x000D 22 TPMAlgSm3s256 IAlgHash = 0x0012 23 ) 24 25 // IAlgHashSize is the TPM hash algorithm length 26 type IAlgHashSize uint8 27 28 const ( 29 // TPMAlgShaSize SHA hash size 30 TPMAlgShaSize IAlgHashSize = 20 31 // TPMAlgSha256Size SHA256 hash size 32 TPMAlgSha256Size IAlgHashSize = 32 33 // TPMAlgSha384Size SHA384 hash size 34 TPMAlgSha384Size IAlgHashSize = 48 35 // TPMAlgSha512Size SHA512 hash size 36 TPMAlgSha512Size IAlgHashSize = 64 37 // TPMAlgSm3s256Size SM3-256 hash size 38 TPMAlgSm3s256Size IAlgHashSize = 32 39 ) 40 41 // [1] https://members.uefi.org/kws/documents/UEFI_Spec_2_7_A_Sept_6.pdf 42 43 // EFIGuid is the EFI Guid format 44 type EFIGuid struct { 45 blockA uint32 46 blockB uint16 47 blockC uint16 48 blockD uint16 49 blockE [6]uint8 50 } 51 52 // EFIConfigurationTable is an internal UEFI structure see [1] 53 type EFIConfigurationTable struct { 54 vendorGUID EFIGuid 55 vendorTable uint64 56 } 57 58 // EFIDevicePath is an internal UEFI structure see [1] 59 type EFIDevicePath struct { 60 pathType uint8 61 pathSubType uint8 62 length [2]uint8 63 } 64 65 // TCGPCClientTaggedEvent is an legacy tag structure 66 type TCGPCClientTaggedEvent struct { 67 taggedEventID uint32 68 taggedEventDataSize uint32 69 taggedEventData []byte 70 } 71 72 // EFIImageLoadEvent is an internal UEFI structure see [1] 73 type EFIImageLoadEvent struct { 74 imageLocationInMemory uint64 75 imageLengthInMemory uint64 76 imageLinkTimeAddress uint64 77 lengthOfDevicePath uint64 78 devicePath []EFIDevicePath 79 } 80 81 // EFIGptData is the GPT structure 82 type EFIGptData struct { 83 uefiPartitionHeader gpt.Header 84 numberOfPartitions uint64 85 uefiPartitions []gpt.Partition 86 } 87 88 // EFIHandoffTablePointers is an internal UEFI structure see [1] 89 type EFIHandoffTablePointers struct { 90 numberOfTables uint64 91 tableEntry []EFIConfigurationTable 92 } 93 94 // EFIPlatformFirmwareBlob is an internal UEFI structure see [1] 95 type EFIPlatformFirmwareBlob struct { 96 blobBase uint64 97 blobLength uint64 98 } 99 100 // EFIVariableData representing UEFI vars 101 type EFIVariableData struct { 102 variableName EFIGuid 103 unicodeNameLength uint64 104 variableDataLength uint64 105 unicodeName []uint16 106 variableData []byte 107 } 108 109 // IHA is a TPM2 structure 110 type IHA struct { 111 hash []byte 112 } 113 114 // THA is a TPM2 structure 115 type THA struct { 116 hashAlg IAlgHash 117 digest IHA 118 } 119 120 // LDigestValues is a TPM2 structure 121 type LDigestValues struct { 122 count uint32 123 digests []THA 124 } 125 126 // TcgEfiSpecIDEventAlgorithmSize is a TPM2 structure 127 type TcgEfiSpecIDEventAlgorithmSize struct { 128 algorithID uint16 129 digestSize uint16 130 } 131 132 // TcgEfiSpecIDEvent is a TPM2 structure 133 type TcgEfiSpecIDEvent struct { 134 signature [16]byte 135 platformClass uint32 136 specVersionMinor uint8 137 specVersionMajor uint8 138 specErrata uint8 139 uintnSize uint8 140 numberOfAlgorithms uint32 141 digestSizes []TcgEfiSpecIDEventAlgorithmSize 142 vendorInfoSize uint8 143 vendorInfo []byte 144 } 145 146 // TcgBiosSpecIDEvent is a TPM2 structure 147 type TcgBiosSpecIDEvent struct { 148 signature [16]byte 149 platformClass uint32 150 specVersionMinor uint8 151 specVersionMajor uint8 152 specErrata uint8 153 uintnSize uint8 154 vendorInfoSize uint8 155 vendorInfo []byte 156 } 157 158 // TcgPcrEvent2 is a TPM2 default log structure (EFI only) 159 type TcgPcrEvent2 struct { 160 pcrIndex uint32 161 eventType uint32 162 digests LDigestValues 163 eventSize uint32 164 event []byte 165 } 166 167 // TcgPcrEvent is the TPM1.2 default log structure (BIOS, EFI compatible) 168 type TcgPcrEvent struct { 169 pcrIndex uint32 170 eventType uint32 171 digest [20]byte 172 eventSize uint32 173 event []byte 174 } 175 176 // PCRDigestValue is the hash and algorithm 177 type PCRDigestValue struct { 178 DigestAlg IAlgHash 179 Digest []byte 180 } 181 182 // PCREvent is a common interface for TcgPcrEvent & TcgPcrEvent2 183 type PCREvent interface { 184 PcrIndex() int 185 PcrEventType() uint32 186 PcrEventName() string 187 PcrEventData() string 188 Digests() *[]PCRDigestValue 189 String() string 190 } 191 192 // PCRLog is a generic PCR eventlog structure 193 type PCRLog struct { 194 Firmware FirmwareType 195 PcrList []PCREvent 196 } 197 198 // [2] http://kib.kiev.ua/x86docs/SDMs/315168-011.pdf (Pre-TrEE MLE Guide) 199 // [3] https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-txt-software-development-guide.pdf 200 201 // TxtEventLogContainer is log header for TPM1.2 TXT log 202 type TxtEventLogContainer struct { 203 Signature [20]uint8 204 Reserved [12]uint8 205 ContainerVerMajor uint8 206 ContainerVerMinor uint8 207 PcrEventVerMajor uint8 208 PcrEventVerMinor uint8 209 Size uint32 210 PcrEventsOffset uint32 211 NextEventOffset uint32 212 }