1use crate::{data, tpm_dispatch, TpmBuild, TpmList, TpmParse, TpmResult, TpmWriter};
6use core::fmt::Debug;
7
8mod asymmetric;
9mod attached;
10mod attestation;
11mod audit;
12mod build;
13mod capability;
14mod clocks_and_timers;
15mod context;
16mod dictionary_attack;
17mod duplication;
18mod enhanced_authorization;
19mod ephemeral;
20mod field_upgrade;
21mod hierarchy;
22mod integrity;
23mod miscellaneous_management;
24mod non_volatile;
25mod object;
26mod parse;
27mod random_number;
28mod sequence;
29mod session;
30mod signing;
31mod startup;
32mod symmetric;
33mod testing;
34mod vendor;
35
36pub use self::{
37 asymmetric::*, attached::*, attestation::*, audit::*, build::*, capability::*,
38 clocks_and_timers::*, context::*, dictionary_attack::*, duplication::*,
39 enhanced_authorization::*, ephemeral::*, field_upgrade::*, hierarchy::*, integrity::*,
40 miscellaneous_management::*, non_volatile::*, object::*, parse::*, random_number::*,
41 sequence::*, session::*, signing::*, startup::*, symmetric::*, testing::*, vendor::*,
42};
43
44pub const MAX_HANDLES: usize = 8;
46pub const MAX_SESSIONS: usize = 8;
48pub type TpmHandles = TpmList<u32, MAX_HANDLES>;
50pub type TpmAuthCommands = TpmList<data::TpmsAuthCommand, MAX_SESSIONS>;
52pub type TpmAuthResponses = TpmList<data::TpmsAuthResponse, MAX_SESSIONS>;
54pub trait TpmHeader: TpmBuild + Debug {
56 const COMMAND: data::TpmCc;
57 const NO_SESSIONS: bool;
58 const WITH_SESSIONS: bool;
59 const HANDLES: usize;
60}
61
62pub trait TpmHeaderCommand: TpmHeader {
64 fn build_handles(&self, writer: &mut TpmWriter) -> TpmResult<()>;
70
71 fn build_parameters(&self, writer: &mut TpmWriter) -> TpmResult<()>;
78}
79
80pub(crate) trait TpmCommandBodyParse: Sized {
83 fn parse_body<'a>(handles: &'a [u8], params: &'a [u8]) -> TpmResult<(Self, &'a [u8])>;
90}
91
92pub const TPM_HEADER_SIZE: usize = 10;
93
94tpm_dispatch! {
95 (TpmNvUndefineSpaceSpecialCommand, TpmNvUndefineSpaceSpecialResponse, NvUndefineSpaceSpecial),
96 (TpmEvictControlCommand, TpmEvictControlResponse, EvictControl),
97 (TpmHierarchyControlCommand, TpmHierarchyControlResponse, HierarchyControl),
98 (TpmNvUndefineSpaceCommand, TpmNvUndefineSpaceResponse, NvUndefineSpace),
99 (TpmChangeEpsCommand, TpmChangeEpsResponse, ChangeEps),
100 (TpmChangePpsCommand, TpmChangePpsResponse, ChangePps),
101 (TpmClearCommand, TpmClearResponse, Clear),
102 (TpmClearControlCommand, TpmClearControlResponse, ClearControl),
103 (TpmClockSetCommand, TpmClockSetResponse, ClockSet),
104 (TpmHierarchyChangeAuthCommand, TpmHierarchyChangeAuthResponse, HierarchyChangeAuth),
105 (TpmNvDefineSpaceCommand, TpmNvDefineSpaceResponse, NvDefineSpace),
106 (TpmPcrAllocateCommand, TpmPcrAllocateResponse, PcrAllocate),
107 (TpmPcrSetAuthPolicyCommand, TpmPcrSetAuthPolicyResponse, PcrSetAuthPolicy),
108 (TpmPpCommandsCommand, TpmPpCommandsResponse, PpCommands),
109 (TpmSetPrimaryPolicyCommand, TpmSetPrimaryPolicyResponse, SetPrimaryPolicy),
110 (TpmFieldUpgradeStartCommand, TpmFieldUpgradeStartResponse, FieldUpgradeStart),
111 (TpmClockRateAdjustCommand, TpmClockRateAdjustResponse, ClockRateAdjust),
112 (TpmCreatePrimaryCommand, TpmCreatePrimaryResponse, CreatePrimary),
113 (TpmNvGlobalWriteLockCommand, TpmNvGlobalWriteLockResponse, NvGlobalWriteLock),
114 (TpmGetCommandAuditDigestCommand, TpmGetCommandAuditDigestResponse, GetCommandAuditDigest),
115 (TpmNvIncrementCommand, TpmNvIncrementResponse, NvIncrement),
116 (TpmNvSetBitsCommand, TpmNvSetBitsResponse, NvSetBits),
117 (TpmNvExtendCommand, TpmNvExtendResponse, NvExtend),
118 (TpmNvWriteCommand, TpmNvWriteResponse, NvWrite),
119 (TpmNvWriteLockCommand, TpmNvWriteLockResponse, NvWriteLock),
120 (TpmDictionaryAttackLockResetCommand, TpmDictionaryAttackLockResetResponse, DictionaryAttackLockReset),
121 (TpmDictionaryAttackParametersCommand, TpmDictionaryAttackParametersResponse, DictionaryAttackParameters),
122 (TpmNvChangeAuthCommand, TpmNvChangeAuthResponse, NvChangeAuth),
123 (TpmPcrEventCommand, TpmPcrEventResponse, PcrEvent),
124 (TpmPcrResetCommand, TpmPcrResetResponse, PcrReset),
125 (TpmSequenceCompleteCommand, TpmSequenceCompleteResponse, SequenceComplete),
126 (TpmSetAlgorithmSetCommand, TpmSetAlgorithmSetResponse, SetAlgorithmSet),
127 (TpmSetCommandCodeAuditStatusCommand, TpmSetCommandCodeAuditStatusResponse, SetCommandCodeAuditStatus),
128 (TpmFieldUpgradeDataCommand, TpmFieldUpgradeDataResponse, FieldUpgradeData),
129 (TpmIncrementalSelfTestCommand, TpmIncrementalSelfTestResponse, IncrementalSelfTest),
130 (TpmSelfTestCommand, TpmSelfTestResponse, SelfTest),
131 (TpmStartupCommand, TpmStartupResponse, Startup),
132 (TpmShutdownCommand, TpmShutdownResponse, Shutdown),
133 (TpmStirRandomCommand, TpmStirRandomResponse, StirRandom),
134 (TpmActivateCredentialCommand, TpmActivateCredentialResponse, ActivateCredential),
135 (TpmCertifyCommand, TpmCertifyResponse, Certify),
136 (TpmPolicyNvCommand, TpmPolicyNvResponse, PolicyNv),
137 (TpmCertifyCreationCommand, TpmCertifyCreationResponse, CertifyCreation),
138 (TpmDuplicateCommand, TpmDuplicateResponse, Duplicate),
139 (TpmGetTimeCommand, TpmGetTimeResponse, GetTime),
140 (TpmGetSessionAuditDigestCommand, TpmGetSessionAuditDigestResponse, GetSessionAuditDigest),
141 (TpmNvReadCommand, TpmNvReadResponse, NvRead),
142 (TpmNvReadLockCommand, TpmNvReadLockResponse, NvReadLock),
143 (TpmObjectChangeAuthCommand, TpmObjectChangeAuthResponse, ObjectChangeAuth),
144 (TpmPolicySecretCommand, TpmPolicySecretResponse, PolicySecret),
145 (TpmRewrapCommand, TpmRewrapResponse, Rewrap),
146 (TpmCreateCommand, TpmCreateResponse, Create),
147 (TpmEcdhZGenCommand, TpmEcdhZGenResponse, EcdhZGen),
148 (TpmHmacCommand, TpmHmacResponse, Hmac),
149 (TpmImportCommand, TpmImportResponse, Import),
150 (TpmLoadCommand, TpmLoadResponse, Load),
151 (TpmQuoteCommand, TpmQuoteResponse, Quote),
152 (TpmRsaDecryptCommand, TpmRsaDecryptResponse, RsaDecrypt),
153 (TpmHmacStartCommand, TpmHmacStartResponse, HmacStart),
154 (TpmSequenceUpdateCommand, TpmSequenceUpdateResponse, SequenceUpdate),
155 (TpmSignCommand, TpmSignResponse, Sign),
156 (TpmUnsealCommand, TpmUnsealResponse, Unseal),
157 (TpmPolicySignedCommand, TpmPolicySignedResponse, PolicySigned),
158 (TpmContextLoadCommand, TpmContextLoadResponse, ContextLoad),
159 (TpmContextSaveCommand, TpmContextSaveResponse, ContextSave),
160 (TpmEcdhKeyGenCommand, TpmEcdhKeyGenResponse, EcdhKeyGen),
161 (TpmEncryptDecryptCommand, TpmEncryptDecryptResponse, EncryptDecrypt),
162 (TpmFlushContextCommand, TpmFlushContextResponse, FlushContext),
163 (TpmLoadExternalCommand, TpmLoadExternalResponse, LoadExternal),
164 (TpmMakeCredentialCommand, TpmMakeCredentialResponse, MakeCredential),
165 (TpmNvReadPublicCommand, TpmNvReadPublicResponse, NvReadPublic),
166 (TpmPolicyAuthorizeCommand, TpmPolicyAuthorizeResponse, PolicyAuthorize),
167 (TpmPolicyAuthValueCommand, TpmPolicyAuthValueResponse, PolicyAuthValue),
168 (TpmPolicyCommandCodeCommand, TpmPolicyCommandCodeResponse, PolicyCommandCode),
169 (TpmPolicyCounterTimerCommand, TpmPolicyCounterTimerResponse, PolicyCounterTimer),
170 (TpmPolicyCpHashCommand, TpmPolicyCpHashResponse, PolicyCpHash),
171 (TpmPolicyLocalityCommand, TpmPolicyLocalityResponse, PolicyLocality),
172 (TpmPolicyNameHashCommand, TpmPolicyNameHashResponse, PolicyNameHash),
173 (TpmPolicyOrCommand, TpmPolicyOrResponse, PolicyOr),
174 (TpmPolicyTicketCommand, TpmPolicyTicketResponse, PolicyTicket),
175 (TpmReadPublicCommand, TpmReadPublicResponse, ReadPublic),
176 (TpmRsaEncryptCommand, TpmRsaEncryptResponse, RsaEncrypt),
177 (TpmStartAuthSessionCommand, TpmStartAuthSessionResponse, StartAuthSession),
178 (TpmVerifySignatureCommand, TpmVerifySignatureResponse, VerifySignature),
179 (TpmEccParametersCommand, TpmEccParametersResponse, EccParameters),
180 (TpmFirmwareReadCommand, TpmFirmwareReadResponse, FirmwareRead),
181 (TpmGetCapabilityCommand, TpmGetCapabilityResponse, GetCapability),
182 (TpmGetRandomCommand, TpmGetRandomResponse, GetRandom),
183 (TpmGetTestResultCommand, TpmGetTestResultResponse, GetTestResult),
184 (TpmHashCommand, TpmHashResponse, Hash),
185 (TpmPcrReadCommand, TpmPcrReadResponse, PcrRead),
186 (TpmPolicyPcrCommand, TpmPolicyPcrResponse, PolicyPcr),
187 (TpmPolicyRestartCommand, TpmPolicyRestartResponse, PolicyRestart),
188 (TpmReadClockCommand, TpmReadClockResponse, ReadClock),
189 (TpmPcrExtendCommand, TpmPcrExtendResponse, PcrExtend),
190 (TpmPcrSetAuthValueCommand, TpmPcrSetAuthValueResponse, PcrSetAuthValue),
191 (TpmNvCertifyCommand, TpmNvCertifyResponse, NvCertify),
192 (TpmEventSequenceCompleteCommand, TpmEventSequenceCompleteResponse, EventSequenceComplete),
193 (TpmHashSequenceStartCommand, TpmHashSequenceStartResponse, HashSequenceStart),
194 (TpmPolicyPhysicalPresenceCommand, TpmPolicyPhysicalPresenceResponse, PolicyPhysicalPresence),
195 (TpmPolicyDuplicationSelectCommand, TpmPolicyDuplicationSelectResponse, PolicyDuplicationSelect),
196 (TpmPolicyGetDigestCommand, TpmPolicyGetDigestResponse, PolicyGetDigest),
197 (TpmTestParmsCommand, TpmTestParmsResponse, TestParms),
198 (TpmCommitCommand, TpmCommitResponse, Commit),
199 (TpmPolicyPasswordCommand, TpmPolicyPasswordResponse, PolicyPassword),
200 (TpmZGen2PhaseCommand, TpmZGen2PhaseResponse, ZGen2Phase),
201 (TpmEcEphemeralCommand, TpmEcEphemeralResponse, EcEphemeral),
202 (TpmPolicyNvWrittenCommand, TpmPolicyNvWrittenResponse, PolicyNvWritten),
203 (TpmPolicyTemplateCommand, TpmPolicyTemplateResponse, PolicyTemplate),
204 (TpmCreateLoadedCommand, TpmCreateLoadedResponse, CreateLoaded),
205 (TpmPolicyAuthorizeNvCommand, TpmPolicyAuthorizeNvResponse, PolicyAuthorizeNv),
206 (TpmEncryptDecrypt2Command, TpmEncryptDecrypt2Response, EncryptDecrypt2),
207 (TpmAcGetCapabilityCommand, TpmAcGetCapabilityResponse, AcGetCapability),
208 (TpmAcSendCommand, TpmAcSendResponse, AcSend),
209 (TpmPolicyAcSendSelectCommand, TpmPolicyAcSendSelectResponse, PolicyAcSendSelect),
210 (TpmActSetTimeoutCommand, TpmActSetTimeoutResponse, ActSetTimeout),
211 (TpmPolicyCapabilityCommand, TpmPolicyCapabilityResponse, PolicyCapability),
212 (TpmPolicyParametersCommand, TpmPolicyParametersResponse, PolicyParameters),
213 (TpmNvDefineSpace2Command, TpmNvDefineSpace2Response, NvDefineSpace2),
214 (TpmNvReadPublic2Command, TpmNvReadPublic2Response, NvReadPublic2),
215 (TpmReadOnlyControlCommand, TpmReadOnlyControlResponse, ReadOnlyControl),
216 (TpmPolicyTransportSpdmCommand, TpmPolicyTransportSpdmResponse, PolicyTransportSpdm),
217 (TpmVendorTcgTestCommand, TpmVendorTcgTestResponse, VendorTcgTest),
218}