tpm2_protocol/message/
enhanced_authorization.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// Copyright (c) 2025 Opinsys Oy
3// Copyright (c) 2024-2025 Jarkko Sakkinen
4
5//! 28 Policy Commands
6
7use crate::{
8    data::{
9        Tpm2b, Tpm2bDigest, Tpm2bName, Tpm2bNonce, Tpm2bTimeout, TpmAlgId, TpmCc, TpmaLocality,
10        TpmlDigest, TpmlPcrSelection, TpmtSignature, TpmtTkAuth,
11    },
12    tpm_response, tpm_struct,
13};
14use core::fmt::Debug;
15
16tpm_struct!(
17    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
18    TpmPolicyAuthValueCommand,
19    TpmCc::PolicyAuthValue,
20    false,
21    true,
22    1,
23    {}
24);
25
26tpm_struct!(
27    #[derive(Debug, PartialEq, Eq, Clone)]
28    TpmPolicyCommandCodeCommand,
29    TpmCc::PolicyCommandCode,
30    false,
31    true,
32    1,
33    {
34        pub code: TpmCc,
35    }
36);
37
38tpm_struct!(
39    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
40    TpmPolicyGetDigestCommand,
41    TpmCc::PolicyGetDigest,
42    false,
43    true,
44    1,
45    {}
46);
47
48tpm_struct!(
49    #[derive(Debug, Default, PartialEq, Eq, Clone)]
50    TpmPolicyOrCommand,
51    TpmCc::PolicyOR,
52    false,
53    true,
54    1,
55    {
56        pub p_hash_list: TpmlDigest,
57    }
58);
59
60tpm_struct!(
61    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
62    TpmPolicyPasswordCommand,
63    TpmCc::PolicyPassword,
64    false,
65    true,
66    1,
67    {}
68);
69
70tpm_struct!(
71    #[derive(Debug, Default, PartialEq, Eq, Clone)]
72    TpmPolicyPcrCommand,
73    TpmCc::PolicyPcr,
74    false,
75    true,
76    1,
77    {
78        pub pcr_digest: Tpm2bDigest,
79        pub pcrs: TpmlPcrSelection,
80    }
81);
82
83tpm_struct!(
84    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
85    TpmPolicyRestartCommand,
86    TpmCc::PolicyRestart,
87    false,
88    true,
89    0,
90    {}
91);
92
93tpm_struct!(
94    #[derive(Debug, Default, PartialEq, Eq, Clone)]
95    TpmPolicySecretCommand,
96    TpmCc::PolicySecret,
97    false,
98    true,
99    2,
100    {
101        pub nonce_tpm: Tpm2b,
102        pub cp_hash_a: Tpm2bDigest,
103        pub policy_ref: Tpm2b,
104        pub expiration: i32,
105    }
106);
107
108tpm_struct!(
109    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
110    TpmPolicyAuthValueResponse,
111    TpmCc::PolicyAuthValue,
112    false,
113    true,
114    0,
115    {}
116);
117
118tpm_struct!(
119    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
120    TpmPolicyCommandCodeResponse,
121    TpmCc::PolicyCommandCode,
122    false,
123    true,
124    0,
125    {}
126);
127
128tpm_struct!(
129    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
130    TpmPolicyOrResponse,
131    TpmCc::PolicyOR,
132    false,
133    true,
134    0,
135    {}
136);
137
138tpm_struct!(
139    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
140    TpmPolicyPasswordResponse,
141    TpmCc::PolicyPassword,
142    false,
143    true,
144    0,
145    {}
146);
147
148tpm_struct!(
149    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
150    TpmPolicyPcrResponse,
151    TpmCc::PolicyPcr,
152    false,
153    true,
154    0,
155    {}
156);
157
158tpm_struct!(
159    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
160    TpmPolicyRestartResponse,
161    TpmCc::PolicyRestart,
162    false,
163    true,
164    0,
165    {}
166);
167
168tpm_struct!(
169    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
170    TpmPolicySecretResponse,
171    TpmCc::PolicySecret,
172    false,
173    true,
174    0,
175    {}
176);
177
178tpm_struct! (
179    #[derive(Debug, PartialEq, Eq, Clone)]
180    TpmPolicySignedCommand,
181    TpmCc::PolicySigned,
182    false,
183    true,
184    2,
185    {
186        pub nonce_tpm: Tpm2bNonce,
187        pub cp_hash_a: Tpm2bDigest,
188        pub policy_ref: Tpm2bNonce,
189        pub expiration: i32,
190        pub auth: TpmtSignature,
191    }
192);
193
194tpm_response!(
195    #[derive(Debug, PartialEq, Eq, Clone)]
196    TpmPolicySignedResponse,
197    TpmCc::PolicySigned,
198    false,
199    true,
200    {
201        pub timeout: Tpm2bTimeout,
202        pub policy_ticket: TpmtTkAuth,
203    }
204);
205
206tpm_struct! (
207    #[derive(Debug, PartialEq, Eq, Clone)]
208    TpmPolicyTicketCommand,
209    TpmCc::PolicyTicket,
210    false,
211    true,
212    1,
213    {
214        pub timeout: Tpm2bTimeout,
215        pub cp_hash_a: Tpm2bDigest,
216        pub policy_ref: Tpm2bNonce,
217        pub auth_name: Tpm2bName,
218        pub ticket: TpmtTkAuth,
219    }
220);
221
222tpm_response!(
223    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
224    TpmPolicyTicketResponse,
225    TpmCc::PolicyTicket,
226    false,
227    true,
228    {}
229);
230
231tpm_struct! (
232    #[derive(Debug, PartialEq, Eq, Copy, Clone)]
233    TpmPolicyLocalityCommand,
234    TpmCc::PolicyLocality,
235    false,
236    true,
237    1,
238    {
239        pub locality: TpmaLocality,
240    }
241);
242
243tpm_response!(
244    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
245    TpmPolicyLocalityResponse,
246    TpmCc::PolicyLocality,
247    false,
248    true,
249    {}
250);
251
252tpm_struct! (
253    #[derive(Debug, PartialEq, Eq, Clone)]
254    TpmPolicyCpHashCommand,
255    TpmCc::PolicyCpHash,
256    false,
257    true,
258    1,
259    {
260        pub cp_hash_a: Tpm2bDigest,
261    }
262);
263
264tpm_response!(
265    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
266    TpmPolicyCpHashResponse,
267    TpmCc::PolicyCpHash,
268    false,
269    true,
270    {}
271);
272
273tpm_struct!(
274    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
275    TpmPolicyPhysicalPresenceCommand,
276    TpmCc::PolicyPhysicalPresence,
277    false,
278    true,
279    1,
280    {}
281);
282
283tpm_response!(
284    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
285    TpmPolicyPhysicalPresenceResponse,
286    TpmCc::PolicyPhysicalPresence,
287    false,
288    true,
289    {}
290);
291
292tpm_struct!(
293    #[derive(Debug, PartialEq, Eq, Clone)]
294    TpmSetPrimaryPolicyCommand,
295    TpmCc::SetPrimaryPolicy,
296    false,
297    true,
298    1,
299    {
300        pub auth_policy: Tpm2bDigest,
301        pub hash_alg: TpmAlgId,
302    }
303);
304
305tpm_response!(
306    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
307    TpmSetPrimaryPolicyResponse,
308    TpmCc::SetPrimaryPolicy,
309    false,
310    true,
311    {}
312);