tpm2_protocol/message/
non_volatile.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//! 23 Non-Volatile (NV) Storage
6
7use crate::{
8    data::{
9        Tpm2bAttest, Tpm2bAuth, Tpm2bData, Tpm2bMaxNvBuffer, Tpm2bName, Tpm2bNvPublic, TpmCc,
10        TpmtSignature,
11    },
12    tpm_struct,
13};
14use core::fmt::Debug;
15
16tpm_struct! {
17    #[derive(Debug, PartialEq, Eq, Clone)]
18    kind: Command,
19    name: TpmNvDefineSpaceCommand,
20    cc: TpmCc::NvDefineSpace,
21    handles: {
22        pub auth_handle: crate::data::TpmiRhHierarchy,
23    },
24    parameters: {
25        pub auth: Tpm2bAuth,
26        pub public_info: Tpm2bNvPublic,
27    }
28}
29
30tpm_struct! {
31    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
32    kind: Response,
33    name: TpmNvDefineSpaceResponse,
34    cc: TpmCc::NvDefineSpace,
35    handles: {},
36    parameters: {}
37}
38
39tpm_struct! {
40    #[derive(Debug, PartialEq, Eq, Copy, Clone)]
41    kind: Command,
42    name: TpmNvUndefineSpaceCommand,
43    cc: TpmCc::NvUndefineSpace,
44    handles: {
45        pub auth_handle: crate::data::TpmiRhHierarchy,
46        pub nv_index: u32,
47    },
48    parameters: {}
49}
50
51tpm_struct! {
52    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
53    kind: Response,
54    name: TpmNvUndefineSpaceResponse,
55    cc: TpmCc::NvUndefineSpace,
56    handles: {},
57    parameters: {}
58}
59
60tpm_struct! {
61    #[derive(Debug, PartialEq, Eq, Copy, Clone)]
62    kind: Command,
63    name: TpmNvUndefineSpaceSpecialCommand,
64    cc: TpmCc::NvUndefineSpaceSpecial,
65    handles: {
66        pub nv_index: u32,
67        pub platform: crate::data::TpmiRhHierarchy,
68    },
69    parameters: {}
70}
71
72tpm_struct! {
73    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
74    kind: Response,
75    name: TpmNvUndefineSpaceSpecialResponse,
76    cc: TpmCc::NvUndefineSpaceSpecial,
77    handles: {},
78    parameters: {}
79}
80
81tpm_struct! {
82    #[derive(Debug, PartialEq, Eq, Copy, Clone)]
83    kind: Command,
84    name: TpmNvReadPublicCommand,
85    cc: TpmCc::NvReadPublic,
86    handles: {
87        pub nv_index: u32,
88    },
89    parameters: {}
90}
91
92tpm_struct! {
93    #[derive(Debug, PartialEq, Eq, Clone)]
94    kind: Response,
95    name: TpmNvReadPublicResponse,
96    cc: TpmCc::NvReadPublic,
97    handles: {},
98    parameters: {
99        pub nv_public: Tpm2bNvPublic,
100        pub nv_name: Tpm2bName,
101    }
102}
103
104tpm_struct! {
105    #[derive(Debug, PartialEq, Eq, Clone)]
106    kind: Command,
107    name: TpmNvWriteCommand,
108    cc: TpmCc::NvWrite,
109    handles: {
110        pub auth_handle: crate::data::TpmiDhObject,
111        pub nv_index: u32,
112    },
113    parameters: {
114        pub data: Tpm2bMaxNvBuffer,
115        pub offset: u16,
116    }
117}
118
119tpm_struct! {
120    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
121    kind: Response,
122    name: TpmNvWriteResponse,
123    cc: TpmCc::NvWrite,
124    handles: {},
125    parameters: {}
126}
127
128tpm_struct! {
129    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
130    kind: Command,
131    name: TpmNvIncrementCommand,
132    cc: TpmCc::NvIncrement,
133    handles: {
134        pub auth_handle: crate::data::TpmiDhObject,
135        pub nv_index: u32,
136    },
137    parameters: {}
138}
139
140tpm_struct! {
141    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
142    kind: Response,
143    name: TpmNvIncrementResponse,
144    cc: TpmCc::NvIncrement,
145    handles: {},
146    parameters: {}
147}
148
149tpm_struct! {
150    #[derive(Debug, PartialEq, Eq, Clone)]
151    kind: Command,
152    name: TpmNvExtendCommand,
153    cc: TpmCc::NvExtend,
154    handles: {
155        pub auth_handle: crate::data::TpmiDhObject,
156        pub nv_index: u32,
157    },
158    parameters: {
159        pub data: Tpm2bMaxNvBuffer,
160    }
161}
162
163tpm_struct! {
164    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
165    kind: Response,
166    name: TpmNvExtendResponse,
167    cc: TpmCc::NvExtend,
168    handles: {},
169    parameters: {}
170}
171
172tpm_struct! {
173    #[derive(Debug, PartialEq, Eq, Copy, Clone)]
174    kind: Command,
175    name: TpmNvSetBitsCommand,
176    cc: TpmCc::NvSetBits,
177    handles: {
178        pub auth_handle: crate::data::TpmiDhObject,
179        pub nv_index: u32,
180    },
181    parameters: {
182        pub bits: u64,
183    }
184}
185
186tpm_struct! {
187    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
188    kind: Response,
189    name: TpmNvSetBitsResponse,
190    cc: TpmCc::NvSetBits,
191    handles: {},
192    parameters: {}
193}
194
195tpm_struct! {
196    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
197    kind: Command,
198    name: TpmNvWriteLockCommand,
199    cc: TpmCc::NvWriteLock,
200    handles: {
201        pub auth_handle: crate::data::TpmiDhObject,
202        pub nv_index: u32,
203    },
204    parameters: {}
205}
206
207tpm_struct! {
208    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
209    kind: Response,
210    name: TpmNvWriteLockResponse,
211    cc: TpmCc::NvWriteLock,
212    handles: {},
213    parameters: {}
214}
215
216tpm_struct! {
217    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
218    kind: Command,
219    name: TpmNvGlobalWriteLockCommand,
220    cc: TpmCc::NvGlobalWriteLock,
221    handles: {
222        pub auth_handle: crate::data::TpmiRhHierarchy,
223    },
224    parameters: {}
225}
226
227tpm_struct! {
228    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
229    kind: Response,
230    name: TpmNvGlobalWriteLockResponse,
231    cc: TpmCc::NvGlobalWriteLock,
232    handles: {},
233    parameters: {}
234}
235
236tpm_struct! {
237    #[derive(Debug, PartialEq, Eq, Copy, Clone)]
238    kind: Command,
239    name: TpmNvReadCommand,
240    cc: TpmCc::NvRead,
241    handles: {
242        pub auth_handle: crate::data::TpmiDhObject,
243        pub nv_index: u32,
244    },
245    parameters: {
246        pub size: u16,
247        pub offset: u16,
248    }
249}
250
251tpm_struct! {
252    #[derive(Debug, Default, PartialEq, Eq, Clone)]
253    kind: Response,
254    name: TpmNvReadResponse,
255    cc: TpmCc::NvRead,
256    handles: {},
257    parameters: {
258        pub data: Tpm2bMaxNvBuffer,
259    }
260}
261
262tpm_struct! {
263    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
264    kind: Command,
265    name: TpmNvReadLockCommand,
266    cc: TpmCc::NvReadLock,
267    handles: {
268        pub auth_handle: crate::data::TpmiDhObject,
269        pub nv_index: u32,
270    },
271    parameters: {}
272}
273
274tpm_struct! {
275    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
276    kind: Response,
277    name: TpmNvReadLockResponse,
278    cc: TpmCc::NvReadLock,
279    handles: {},
280    parameters: {}
281}
282
283tpm_struct! {
284    #[derive(Debug, PartialEq, Eq, Clone)]
285    kind: Command,
286    name: TpmNvChangeAuthCommand,
287    cc: TpmCc::NvChangeAuth,
288    handles: {
289        pub nv_index: u32,
290    },
291    parameters: {
292        pub new_auth: Tpm2bAuth,
293    }
294}
295
296tpm_struct! {
297    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
298    kind: Response,
299    name: TpmNvChangeAuthResponse,
300    cc: TpmCc::NvChangeAuth,
301    handles: {},
302    parameters: {}
303}
304
305tpm_struct! {
306    #[derive(Debug, PartialEq, Eq, Clone)]
307    kind: Command,
308    name: TpmNvCertifyCommand,
309    cc: TpmCc::NvCertify,
310    handles: {
311        pub sign_handle: crate::data::TpmiDhObject,
312        pub auth_handle: crate::data::TpmiDhObject,
313        pub nv_index: u32,
314    },
315    parameters: {
316        pub qualifying_data: Tpm2bData,
317        pub in_scheme: TpmtSignature,
318        pub size: u16,
319        pub offset: u16,
320    }
321}
322
323tpm_struct! {
324    #[derive(Debug, PartialEq, Eq, Clone)]
325    kind: Response,
326    name: TpmNvCertifyResponse,
327    cc: TpmCc::NvCertify,
328    handles: {},
329    parameters: {
330        pub certify_info: Tpm2bAttest,
331        pub signature: TpmtSignature,
332    }
333}
334
335tpm_struct! {
336    #[derive(Debug, PartialEq, Eq, Clone)]
337    kind: Command,
338    name: TpmNvDefineSpace2Command,
339    cc: TpmCc::NvDefineSpace2,
340    handles: {
341        pub auth_handle: crate::data::TpmiRhHierarchy,
342    },
343    parameters: {
344        pub auth: Tpm2bAuth,
345        pub public_info: crate::data::Tpm2bNvPublic2,
346    }
347}
348
349tpm_struct! {
350    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
351    kind: Response,
352    name: TpmNvDefineSpace2Response,
353    cc: TpmCc::NvDefineSpace2,
354    handles: {},
355    parameters: {}
356}
357
358tpm_struct! {
359    #[derive(Debug, PartialEq, Eq, Copy, Clone)]
360    kind: Command,
361    name: TpmNvReadPublic2Command,
362    cc: TpmCc::NvReadPublic2,
363    handles: {
364        pub nv_index: u32,
365    },
366    parameters: {}
367}
368
369tpm_struct! {
370    #[derive(Debug, PartialEq, Eq, Clone)]
371    kind: Response,
372    name: TpmNvReadPublic2Response,
373    cc: TpmCc::NvReadPublic2,
374    handles: {},
375    parameters: {
376        pub nv_public: crate::data::Tpm2bNvPublic2,
377        pub nv_name: Tpm2bName,
378    }
379}