Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/uefi-raw/src/protocol/tcg/v2.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / uefi-raw / src / protocol / tcg / v2.rs` 192 lines ยท 5896 bytes Raw Blame History 1 // SPDX-License-Identifier: MIT OR Apache-2.0 2 3 //! [TCG] (Trusted Computing Group) protocol for [TPM] (Trusted Platform 4 //! Module) 2.0. 5 //! 6 //! This protocol is defined in the [TCG EFI Protocol Specification _TPM 7 //! Family 2.0_][spec]. It is generally implemented only for TPM 2.0 8 //! devices, but the spec indicates it can also be used for older TPM 9 //! devices. 10 //! 11 //! [spec]: https://trustedcomputinggroup.org/resource/tcg-efi-protocol-specification/ 12 //! [TCG]: https://trustedcomputinggroup.org/ 13 //! [TPM]: https://en.wikipedia.org/wiki/Trusted_Platform_Module 14 15 use super::EventType; 16 use crate::{Boolean, Guid, PhysicalAddress, Status, guid}; 17 use bitflags::bitflags; 18 use core::ffi::c_void; 19 20 /// Version information. 21 #[repr(C)] 22 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd)] 23 pub struct Tcg2Version { 24 /// Major version. 25 pub major: u8, 26 /// Minor version. 27 pub minor: u8, 28 } 29 30 bitflags! { 31 /// Event log formats supported by the firmware. 32 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] 33 #[repr(transparent)] 34 pub struct Tcg2EventLogBitmap: u32 { 35 /// Firmware supports the SHA-1 log format. 36 const TCG_1_2 = 0x0000_0001; 37 38 /// Firmware supports the crypto-agile log format. 39 const TCG_2 = 0x0000_0002; 40 } 41 } 42 43 /// Event log formats supported by the firmware. 44 pub type Tcg2EventLogFormat = Tcg2EventLogBitmap; 45 46 bitflags! { 47 /// Hash algorithms the protocol can provide. 48 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] 49 #[repr(transparent)] 50 pub struct Tcg2HashAlgorithmBitmap: u32 { 51 /// SHA-1 hash. 52 const SHA1 = 0x0000_0001; 53 54 /// SHA-256 hash. 55 const SHA256 = 0x0000_0002; 56 57 /// SHA-384 hash. 58 const SHA384 = 0x0000_0004; 59 60 /// SHA-512 hash. 61 const SHA512 = 0x0000_0008; 62 63 /// SM3-256 hash. 64 const SM3_256 = 0x0000_0010; 65 } 66 } 67 68 /// Information about the protocol and the TPM device. 69 #[repr(C)] 70 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd)] 71 pub struct Tcg2BootServiceCapability { 72 /// Size of this structure. 73 pub size: u8, 74 75 /// Version of the EFI TCG2 protocol. 76 pub structure_version: Tcg2Version, 77 78 /// Version of the EFI TCG2 protocol. 79 pub protocol_version: Tcg2Version, 80 81 /// Bitmap of supported hash algorithms. 82 pub hash_algorithm_bitmap: Tcg2HashAlgorithmBitmap, 83 84 /// Event log formats supported by the firmware. 85 pub supported_event_logs: Tcg2EventLogBitmap, 86 87 /// Whether the TPM is present or not. 88 pub tpm_present_flag: u8, 89 90 /// Maximum size (in bytes) of a command that can be sent to the TPM. 91 pub max_command_size: u16, 92 93 /// Maximum size (in bytes) of a response that can be provided by the TPM. 94 pub max_response_size: u16, 95 96 /// Manufacturer ID. 97 /// 98 /// See the [TCG Vendor ID registry]. 99 /// 100 /// [TCG Vendor ID registry]: https://trustedcomputinggroup.org/resource/vendor-id-registry/ 101 pub manufacturer_id: u32, 102 103 /// Maximum number of supported PCR banks (hashing algorithms). 104 pub number_of_pcr_banks: u32, 105 106 /// Bitmap of currently-active PCR banks (hashing algorithms). This 107 /// is a subset of the supported algorithms in [`hash_algorithm_bitmap`]. 108 /// 109 /// [`hash_algorithm_bitmap`]: Self::hash_algorithm_bitmap 110 pub active_pcr_banks: Tcg2HashAlgorithmBitmap, 111 } 112 113 bitflags! { 114 /// Flags for the [`Tcg2Protocol::hash_log_extend_event`] function. 115 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] 116 #[repr(transparent)] 117 pub struct Tcg2HashLogExtendEventFlags: u64 { 118 /// Extend an event but don't log it. 119 const EFI_TCG2_EXTEND_ONLY = 0x0000_0000_0000_0001; 120 121 /// Use when measuring a PE/COFF image. 122 const PE_COFF_IMAGE = 0x0000_0000_0000_0010; 123 } 124 } 125 126 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 127 #[repr(C, packed)] 128 pub struct Tcg2EventHeader { 129 pub header_size: u32, 130 pub header_version: u16, 131 pub pcr_index: u32, 132 pub event_type: EventType, 133 } 134 135 /// Protocol for interacting with TPM devices. 136 /// 137 /// This protocol can be used for interacting with older TPM 1.1/1.2 138 /// devices, but most firmware only uses it for TPM 2.0. 139 /// 140 /// The corresponding C type is `EFI_TCG2_PROTOCOL`. 141 #[derive(Debug)] 142 #[repr(C)] 143 pub struct Tcg2Protocol { 144 pub get_capability: unsafe extern "efiapi" fn( 145 this: *mut Self, 146 protocol_capability: *mut Tcg2BootServiceCapability, 147 ) -> Status, 148 149 pub get_event_log: unsafe extern "efiapi" fn( 150 this: *mut Self, 151 event_log_format: Tcg2EventLogFormat, 152 event_log_location: *mut PhysicalAddress, 153 event_log_last_entry: *mut PhysicalAddress, 154 event_log_truncated: *mut Boolean, 155 ) -> Status, 156 157 pub hash_log_extend_event: unsafe extern "efiapi" fn( 158 this: *mut Self, 159 flags: Tcg2HashLogExtendEventFlags, 160 data_to_hash: PhysicalAddress, 161 data_to_hash_len: u64, 162 event: *const c_void, 163 ) -> Status, 164 165 pub submit_command: unsafe extern "efiapi" fn( 166 this: *mut Self, 167 input_parameter_block_size: u32, 168 input_parameter_block: *const u8, 169 output_parameter_block_size: u32, 170 output_parameter_block: *mut u8, 171 ) -> Status, 172 173 pub get_active_pcr_banks: unsafe extern "efiapi" fn( 174 this: *mut Self, 175 active_pcr_banks: *mut Tcg2HashAlgorithmBitmap, 176 ) -> Status, 177 178 pub set_active_pcr_banks: unsafe extern "efiapi" fn( 179 this: *mut Self, 180 active_pcr_banks: Tcg2HashAlgorithmBitmap, 181 ) -> Status, 182 183 pub get_result_of_set_active_pcr_banks: unsafe extern "efiapi" fn( 184 this: *mut Self, 185 operation_present: *mut u32, 186 response: *mut u32, 187 ) -> Status, 188 } 189 190 impl Tcg2Protocol { 191 pub const GUID: Guid = guid!("`607f766c`-7455-42be-930b-`e4d76db2720f`"); 192 }