1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************
3 * Copyright (c) 2015 - 2017, Intel Corporation
4 *
5 * All rights reserved.
6 ***********************************************************************/
7
8 #ifdef HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <inttypes.h>
13 #include <string.h>
14
15 #include "tss2_mu.h"
16
17 #include "util/tss2_endian.h"
18 #define LOGMODULE marshal
19 #include "util/log.h"
20
21 #define ADDR &
22 #define VAL
23
marshal_tab(BYTE const * src,uint8_t buffer[],size_t buffer_size,size_t * offset,size_t size)24 static TSS2_RC marshal_tab(BYTE const *src, uint8_t buffer[],
25 size_t buffer_size, size_t *offset, size_t size)
26 {
27 size_t local_offset = 0;
28
29 if (src == NULL) { \
30 LOG_WARNING("src param is NULL"); \
31 return TSS2_MU_RC_BAD_REFERENCE; \
32 }
33
34 if (offset != NULL) {
35 LOG_DEBUG("offset non-NULL, initial value: %zu", *offset);
36 local_offset = *offset;
37 }
38
39 if (buffer == NULL && offset == NULL) {
40 LOG_WARNING("buffer and offset parameter are NULL");
41 return TSS2_MU_RC_BAD_REFERENCE;
42 } else if (buffer == NULL && offset != NULL) {
43 *offset += size;
44 LOG_TRACE("buffer NULL and offset non-NULL, updating offset to %zu",
45 *offset);
46 return TSS2_RC_SUCCESS;
47 } else if (buffer_size < local_offset || buffer_size - local_offset < size) {
48 LOG_ERROR("buffer_size: %zu with offset: %zu are insufficient for "
49 "object of size %zu", buffer_size, local_offset, size);
50 return TSS2_MU_RC_INSUFFICIENT_BUFFER;
51 }
52
53 LOG_DEBUG("Marshalling TPMU tab of %d bytes from 0x%" PRIxPTR " to buffer 0x%"
54 PRIxPTR " at index 0x%zx", (int)size, (uintptr_t)src, (uintptr_t)buffer,
55 local_offset);
56
57 memcpy(&buffer[local_offset], src, size);
58 local_offset += size;
59
60 if (offset) {
61 *offset = local_offset;
62 LOG_DEBUG("offset parameter non-NULL, updated to %zu", *offset);
63 }
64 return TSS2_RC_SUCCESS;
65 }
66
marshal_hash_sha(BYTE const * src,uint8_t buffer[],size_t buffer_size,size_t * offset)67 static TSS2_RC marshal_hash_sha(BYTE const *src, uint8_t buffer[],
68 size_t buffer_size, size_t *offset)
69 {
70 return marshal_tab(src, buffer, buffer_size, offset, TPM2_SHA1_DIGEST_SIZE);
71 }
72
marshal_hash_sha256(BYTE const * src,uint8_t buffer[],size_t buffer_size,size_t * offset)73 static TSS2_RC marshal_hash_sha256(BYTE const *src, uint8_t buffer[],
74 size_t buffer_size, size_t *offset)
75 {
76 return marshal_tab(src, buffer, buffer_size, offset, TPM2_SHA256_DIGEST_SIZE);
77 }
78
marshal_hash_sha384(BYTE const * src,uint8_t buffer[],size_t buffer_size,size_t * offset)79 static TSS2_RC marshal_hash_sha384(BYTE const *src, uint8_t buffer[],
80 size_t buffer_size, size_t *offset)
81 {
82 return marshal_tab(src, buffer, buffer_size, offset, TPM2_SHA384_DIGEST_SIZE);
83 }
84
marshal_hash_sha512(BYTE const * src,uint8_t buffer[],size_t buffer_size,size_t * offset)85 static TSS2_RC marshal_hash_sha512(BYTE const *src, uint8_t buffer[],
86 size_t buffer_size, size_t *offset)
87 {
88 return marshal_tab(src, buffer, buffer_size, offset, TPM2_SHA512_DIGEST_SIZE);
89 }
90
marshal_sm3_256(BYTE const * src,uint8_t buffer[],size_t buffer_size,size_t * offset)91 static TSS2_RC marshal_sm3_256(BYTE const *src, uint8_t buffer[],
92 size_t buffer_size, size_t *offset)
93 {
94 return marshal_tab(src, buffer, buffer_size, offset, TPM2_SM3_256_DIGEST_SIZE);
95 }
96
marshal_ecc(BYTE const * src,uint8_t buffer[],size_t buffer_size,size_t * offset)97 static TSS2_RC marshal_ecc(BYTE const *src, uint8_t buffer[],
98 size_t buffer_size, size_t *offset)
99 {
100 return marshal_tab(src, buffer, buffer_size, offset, sizeof(TPMS_ECC_POINT));
101 }
102
marshal_rsa(BYTE const * src,uint8_t buffer[],size_t buffer_size,size_t * offset)103 static TSS2_RC marshal_rsa(BYTE const *src, uint8_t buffer[],
104 size_t buffer_size, size_t *offset)
105 {
106 return marshal_tab(src, buffer, buffer_size, offset, TPM2_MAX_RSA_KEY_BYTES);
107 }
108
marshal_symmetric(BYTE const * src,uint8_t buffer[],size_t buffer_size,size_t * offset)109 static TSS2_RC marshal_symmetric(BYTE const *src, uint8_t buffer[],
110 size_t buffer_size, size_t *offset)
111 {
112 return marshal_tab(src, buffer, buffer_size, offset, sizeof(TPM2B_DIGEST));
113 }
114
marshal_keyedhash(BYTE const * src,uint8_t buffer[],size_t buffer_size,size_t * offset)115 static TSS2_RC marshal_keyedhash(BYTE const *src, uint8_t buffer[],
116 size_t buffer_size, size_t *offset)
117 {
118 return marshal_tab(src, buffer, buffer_size, offset, sizeof(TPM2B_DIGEST));
119 }
120
121
marshal_null(void const * src,uint8_t buffer[],size_t buffer_size,size_t * offset)122 static TSS2_RC marshal_null(void const *src, uint8_t buffer[],
123 size_t buffer_size, size_t *offset)
124 {
125 (void)(src);
126 (void)(buffer);
127 (void)(buffer_size);
128 (void)(offset);
129 return TSS2_RC_SUCCESS;
130 }
131
unmarshal_tab(uint8_t const buffer[],size_t buffer_size,size_t * offset,BYTE * dest,size_t size)132 static TSS2_RC unmarshal_tab(uint8_t const buffer[], size_t buffer_size,
133 size_t *offset, BYTE *dest, size_t size)
134 {
135 size_t local_offset = 0;
136
137 if (offset != NULL) {
138 LOG_DEBUG("offset non-NULL, initial value: %zu", *offset);
139 local_offset = *offset;
140 }
141
142 if (buffer == NULL || (dest == NULL && offset == NULL)) {
143 LOG_WARNING("buffer or dest and offset parameter are NULL");
144 return TSS2_MU_RC_BAD_REFERENCE;
145 } else if (dest == NULL && offset != NULL) {
146 *offset += size;
147 LOG_TRACE("buffer NULL and offset non-NULL, updating offset to %zu",
148 *offset);
149 return TSS2_RC_SUCCESS;
150 } else if (buffer_size < local_offset || size > buffer_size - local_offset) {
151 LOG_WARNING("buffer_size: %zu with offset: %zu are insufficient for "
152 "object of size %zu", buffer_size, local_offset, size);
153 return TSS2_MU_RC_INSUFFICIENT_BUFFER;
154 }
155
156 LOG_DEBUG("Marshalling TPMU tab of %d bytes from buffer 0x%" PRIxPTR
157 " at index 0x%zx to dest 0x%" PRIxPTR, (int)size, (uintptr_t)buffer,
158 local_offset, (uintptr_t)dest);
159
160 memcpy(dest, &buffer[local_offset], size);
161 local_offset += size;
162
163 if (offset) {
164 *offset = local_offset;
165 LOG_DEBUG("offset parameter non-NULL, updated to %zu", *offset);
166 }
167 return TSS2_RC_SUCCESS;
168 }
169
unmarshal_hash_sha(uint8_t const buffer[],size_t buffer_size,size_t * offset,BYTE * dest)170 static TSS2_RC unmarshal_hash_sha(uint8_t const buffer[], size_t buffer_size,
171 size_t *offset, BYTE *dest)
172 {
173 return unmarshal_tab(buffer, buffer_size, offset, dest, TPM2_SHA1_DIGEST_SIZE);
174 }
175
unmarshal_hash_sha256(uint8_t const buffer[],size_t buffer_size,size_t * offset,BYTE * dest)176 static TSS2_RC unmarshal_hash_sha256(uint8_t const buffer[], size_t buffer_size,
177 size_t *offset, BYTE *dest)
178 {
179 return unmarshal_tab(buffer, buffer_size, offset, dest, TPM2_SHA256_DIGEST_SIZE);
180 }
181
unmarshal_hash_sha384(uint8_t const buffer[],size_t buffer_size,size_t * offset,BYTE * dest)182 static TSS2_RC unmarshal_hash_sha384(uint8_t const buffer[], size_t buffer_size,
183 size_t *offset, BYTE *dest)
184 {
185 return unmarshal_tab(buffer, buffer_size, offset, dest, TPM2_SHA384_DIGEST_SIZE);
186 }
187
unmarshal_hash_sha512(uint8_t const buffer[],size_t buffer_size,size_t * offset,BYTE * dest)188 static TSS2_RC unmarshal_hash_sha512(uint8_t const buffer[], size_t buffer_size,
189 size_t *offset, BYTE *dest)
190 {
191 return unmarshal_tab(buffer, buffer_size, offset, dest, TPM2_SHA512_DIGEST_SIZE);
192 }
193
unmarshal_sm3_256(uint8_t const buffer[],size_t buffer_size,size_t * offset,BYTE * dest)194 static TSS2_RC unmarshal_sm3_256(uint8_t const buffer[], size_t buffer_size,
195 size_t *offset, BYTE *dest)
196 {
197 return unmarshal_tab(buffer, buffer_size, offset, dest, TPM2_SM3_256_DIGEST_SIZE);
198 }
199
unmarshal_ecc(uint8_t const buffer[],size_t buffer_size,size_t * offset,BYTE * dest)200 static TSS2_RC unmarshal_ecc(uint8_t const buffer[], size_t buffer_size,
201 size_t *offset, BYTE *dest)
202 {
203 return unmarshal_tab(buffer, buffer_size, offset, dest, sizeof(TPMS_ECC_POINT));
204 }
205
unmarshal_rsa(uint8_t const buffer[],size_t buffer_size,size_t * offset,BYTE * dest)206 static TSS2_RC unmarshal_rsa(uint8_t const buffer[], size_t buffer_size,
207 size_t *offset, BYTE *dest)
208 {
209 return unmarshal_tab(buffer, buffer_size, offset, dest, TPM2_MAX_RSA_KEY_BYTES);
210 }
211
unmarshal_symmetric(uint8_t const buffer[],size_t buffer_size,size_t * offset,BYTE * dest)212 static TSS2_RC unmarshal_symmetric(uint8_t const buffer[], size_t buffer_size,
213 size_t *offset, BYTE *dest)
214 {
215 return unmarshal_tab(buffer, buffer_size, offset, dest, sizeof(TPM2B_DIGEST));
216 }
217
unmarshal_keyedhash(uint8_t const buffer[],size_t buffer_size,size_t * offset,BYTE * dest)218 static TSS2_RC unmarshal_keyedhash(uint8_t const buffer[], size_t buffer_size,
219 size_t *offset, BYTE *dest)
220 {
221 return unmarshal_tab(buffer, buffer_size, offset, dest, sizeof(TPM2B_DIGEST));
222 }
223
unmarshal_null(uint8_t const buffer[],size_t buffer_size,size_t * offset,void * dest)224 static TSS2_RC unmarshal_null(uint8_t const buffer[], size_t buffer_size,
225 size_t *offset, void *dest)
226 {
227 (void)(buffer);
228 (void)(buffer_size);
229 (void)(offset);
230 (void)(dest);
231 return TSS2_RC_SUCCESS;
232 }
233
234 /*
235 * The TPMU_* types are unions with some number of members. The marshal
236 * function for each union uses the provided selector value to identify the
237 * member from the union that's written to the buffer. This is a pattern
238 * that can be leveraged to generate the function bodies using macros.
239 *
240 * The TPMU_MARSHAL macro is used to generate these function bodies. It is
241 * used below, once to define the marshaling function for each of the 15
242 * unique TPMU_* types. The parameters are:
243 * type - The type of the TPMU_* being marshaled. This is used to
244 * generate the name of the function and the type of its first
245 * parameter.
246 * The remaining parameters are grouped as 4-tuples. There are 11 of them,
247 * each defined as <selector, operator, member, function> where:
248 * selector - The constant value, typically from a table in some TCG
249 * registry, that the generated function will use to select the
250 * member marshaled / written in network byte order to the buffer.
251 * operator - The member being marshaled may be passed by value or
252 * reference to its marshaling function. If it's by value this
253 * should be 'VAL', if by reference 'ADDR'.
254 * member - The name of the member data from the union passed to the
255 * marshaling function (the next parameter).
256 * function - A function capable of marshaling the 'member' from the
257 * TPMU_* being marshaled.
258 *
259 * This macro takes 11 such 4-tuples. This is the maximum number of members
260 * in the TPMU_* types. All parameters after the first 45 parameters (11*4+1)
261 * are taken as variadic arguments (...) but they are ignored. The reason for
262 * this is documented with the TPMU_MARSHAL2 macro below.
263 *
264 * NOTE: this macro must be passed 11 4-tuples even when defining TPMU_* types
265 * with fewer than 11 members. The extra tuples should be defined as:
266 * <-X, ADDR, m, marshal_null> where:
267 * -X - A unique negative constant value.
268 * ADDR - The macro defined at the top of this file.
269 * m - Any valid member from the TPMU_* being marshaled.
270 * marshal_null - A function defined above that is effectively a
271 * marshaling no-op.
272 */
273 #define TPMU_MARSHAL(type, sel, op, m, fn, sel2, op2, m2, fn2, sel3, op3, m3, fn3, \
274 sel4, op4, m4, fn4, sel5, op5, m5, fn5, sel6, op6, m6, fn6, \
275 sel7, op7, m7, fn7, sel8, op8, m8, fn8, sel9, op9, m9, fn9, \
276 sel10, op10, m10, fn10, sel11, op11, m11, fn11, ...) \
277 TSS2_RC Tss2_MU_##type##_Marshal(type const *src, uint32_t selector, uint8_t buffer[], \
278 size_t buffer_size, size_t *offset) \
279 { \
280 TSS2_RC ret = TSS2_RC_SUCCESS; \
281 \
282 if (src == NULL) { \
283 LOG_WARNING("src param is NULL"); \
284 return TSS2_MU_RC_BAD_REFERENCE; \
285 } \
286 \
287 switch (selector) { \
288 case sel: \
289 ret = fn(op src->m, buffer, buffer_size, offset); \
290 break; \
291 case sel2: \
292 ret = fn2(op2 src->m2, buffer, buffer_size, offset); \
293 break; \
294 case sel3: \
295 ret = fn3(op3 src->m3, buffer, buffer_size, offset); \
296 break; \
297 case sel4: \
298 ret = fn4(op4 src->m4, buffer, buffer_size, offset); \
299 break; \
300 case sel5: \
301 ret = fn5(op5 src->m5, buffer, buffer_size, offset); \
302 break; \
303 case sel6: \
304 ret = fn6(op6 src->m6, buffer, buffer_size, offset); \
305 break; \
306 case sel7: \
307 ret = fn7(op7 src->m7, buffer, buffer_size, offset); \
308 break; \
309 case sel8: \
310 ret = fn8(op8 src->m8, buffer, buffer_size, offset); \
311 break; \
312 case sel9: \
313 ret = fn9(op9 src->m9, buffer, buffer_size, offset); \
314 break; \
315 case sel10: \
316 ret = fn10(op10 src->m10, buffer, buffer_size, offset); \
317 break; \
318 case sel11: \
319 ret = fn11(op11 src->m11, buffer, buffer_size, offset); \
320 break; \
321 default: \
322 break; \
323 } \
324 return ret; \
325 }
326
327 /*
328 * The TPMU_MARSHAL2 macro is a thin wrapper around the TPMU_MARSHAL macro.
329 * This macro is designed to keep us from having to provide dummy 4-tuples
330 * to satisfy the required 45 (11*4+1) parameters required by TPMU_MARSHAL.
331 *
332 * It does this by accepting the tuples describing the variable number of
333 * members in a TPMU_* union (except for the first one) as variadic
334 * arguments. It passes the supplied tuples to TPMU_MARSHAL while providing
335 * additional no-op tuples to pad out the remaining required parameters to
336 * the TPMU_MARSHAL macro.
337 *
338 * NOTE: Remember that all parameters to the TPMU_MARSHAL macro beyond the
339 * first 45 are variadic parameters and are ignored by the macro. This
340 * allows the TPMU_MARSHAL2 macro to provide the maximum required no-op
341 * tuples.
342 * e.g. The TPMU_* unions have between 2 and 11 members. A 2 member
343 * TPMU_* will require 9 no-op tuples to provide 45 parameters to the
344 * TPMU_MARSHAL macro (note the 9 no-op tuples used in the TPMU_MARSHAL2
345 * macro). The largest TPMU_* with 11 members will need to provide 0 no-op
346 * tuples. In this last case the 9 no-op tuples provided by the
347 * TPMU_MARSHAL2 macro will fall into the variadic parameters accepted by
348 * TPMU_MARSHAL and they will be ignored.
349 */
350 #define TPMU_MARSHAL2(type, sel, op, m, fn, ...) \
351 TPMU_MARSHAL(type, sel, op, m, fn, __VA_ARGS__, -1, ADDR, m, marshal_null, \
352 -2, ADDR, m, marshal_null, -3, ADDR, m, marshal_null, \
353 -4, ADDR, m, marshal_null, -5, ADDR, m, marshal_null, \
354 -6, ADDR, m, marshal_null, -7, ADDR, m, marshal_null, \
355 -8, ADDR, m, marshal_null, -9, ADDR, m, marshal_null)
356
357 /*
358 * The TPMU_UNMARSHAL macro functions in the same way as the TPMU_MARSHAL
359 * macro. The main difference is that instead of a 4-tuple of <selector,
360 * operator, member, function> we remove the operator element and have
361 * a 3-tuple of <selector, member, function>. The operator element isn't
362 * needed because the first parameter to the function element is always a
363 * reference (never a value).
364 */
365 #define TPMU_UNMARSHAL(type, sel, m, fn, sel2, m2, fn2, sel3, m3, fn3, \
366 sel4, m4, fn4, sel5, m5, fn5, sel6, m6, fn6, sel7, m7, fn7, \
367 sel8, m8, fn8, sel9, m9, fn9, sel10, m10, fn10, sel11, m11, fn11, ...) \
368 TSS2_RC Tss2_MU_##type##_Unmarshal(uint8_t const buffer[], size_t buffer_size, \
369 size_t *offset, uint32_t selector, type *dest) \
370 { \
371 TSS2_RC ret = TSS2_RC_SUCCESS; \
372 \
373 switch (selector) { \
374 case sel: \
375 ret = fn(buffer, buffer_size, offset, dest ? &dest->m : NULL); \
376 break; \
377 case sel2: \
378 ret = fn2(buffer, buffer_size, offset, dest ? &dest->m2 : NULL); \
379 break; \
380 case sel3: \
381 ret = fn3(buffer, buffer_size, offset, dest ? &dest->m3 : NULL); \
382 break; \
383 case sel4: \
384 ret = fn4(buffer, buffer_size, offset, dest ? &dest->m4 : NULL); \
385 break; \
386 case sel5: \
387 ret = fn5(buffer, buffer_size, offset, dest ? &dest->m5 : NULL); \
388 break; \
389 case sel6: \
390 ret = fn6(buffer, buffer_size, offset, dest ? &dest->m6 : NULL); \
391 break; \
392 case sel7: \
393 ret = fn7(buffer, buffer_size, offset, dest ? &dest->m7 : NULL); \
394 break; \
395 case sel8: \
396 ret = fn8(buffer, buffer_size, offset, dest ? &dest->m8 : NULL); \
397 break; \
398 case sel9: \
399 ret = fn9(buffer, buffer_size, offset, dest ? &dest->m9 : NULL); \
400 break; \
401 case sel10: \
402 ret = fn10(buffer, buffer_size, offset, dest ? &dest->m10 : NULL); \
403 break; \
404 case sel11: \
405 ret = fn11(buffer, buffer_size, offset, dest ? &dest->m11 : NULL); \
406 break; \
407 default: \
408 break; \
409 } \
410 return ret; \
411 }
412
413 /*
414 * The TPMU_UNMARSHAL2 operates on the same principles as the TPMU_MARSHAL2
415 * function. The difference again is that the <selector, member, function>
416 * tuple is a 3-tuple (not the 4-tuple used by TPMU_MARSHAL2).
417 */
418 #define TPMU_UNMARSHAL2(type, sel, m, fn, ...) \
419 TPMU_UNMARSHAL(type, sel, m, fn, __VA_ARGS__, -1, m, unmarshal_null, \
420 -2, m, unmarshal_null, -3, m, unmarshal_null, -4, m, unmarshal_null, \
421 -5, m, unmarshal_null, -6, m, unmarshal_null, -7, m, unmarshal_null, \
422 -8, m, unmarshal_null, -9, m, unmarshal_null)
423
424 /*
425 * Following are invocations of the TPMU_MARSHAL2 and TPMU_UNMARSHAL2 macros.
426 * These generate the marshaling and unmarshaling functions for the TPMU_*
427 * types. They are grouped by TPMU_* with the TPMU_* being the first parameter
428 * to each and on the first line with the macro name. The remaining parameters
429 * are grouped, one 4-tuple per line for the TPMU_MARSHAL2 macro and one
430 * 3-tuple per line for the TPMU_UNMARSHAL2 macro.
431 */
432 TPMU_MARSHAL2(TPMU_HA,
433 TPM2_ALG_SHA1, ADDR, sha1[0], marshal_hash_sha,
434 TPM2_ALG_SHA256, ADDR, sha256[0], marshal_hash_sha256,
435 TPM2_ALG_SHA384, ADDR, sha384[0], marshal_hash_sha384,
436 TPM2_ALG_SHA512, ADDR, sha512[0], marshal_hash_sha512,
437 TPM2_ALG_SM3_256, ADDR, sm3_256[0], marshal_sm3_256)
438 TPMU_UNMARSHAL2(TPMU_HA,
439 TPM2_ALG_SHA1, sha1[0], unmarshal_hash_sha,
440 TPM2_ALG_SHA256, sha256[0], unmarshal_hash_sha256,
441 TPM2_ALG_SHA384, sha384[0], unmarshal_hash_sha384,
442 TPM2_ALG_SHA512, sha512[0], unmarshal_hash_sha512,
443 TPM2_ALG_SM3_256, sm3_256[0], unmarshal_sm3_256)
444
445 TPMU_MARSHAL2(TPMU_CAPABILITIES,
446 TPM2_CAP_ALGS, ADDR, algorithms, Tss2_MU_TPML_ALG_PROPERTY_Marshal,
447 TPM2_CAP_HANDLES, ADDR, handles, Tss2_MU_TPML_HANDLE_Marshal,
448 TPM2_CAP_COMMANDS, ADDR, command, Tss2_MU_TPML_CCA_Marshal,
449 TPM2_CAP_PP_COMMANDS, ADDR, ppCommands, Tss2_MU_TPML_CC_Marshal,
450 TPM2_CAP_AUDIT_COMMANDS, ADDR, auditCommands, Tss2_MU_TPML_CC_Marshal,
451 TPM2_CAP_PCRS, ADDR, assignedPCR, Tss2_MU_TPML_PCR_SELECTION_Marshal,
452 TPM2_CAP_TPM_PROPERTIES, ADDR, tpmProperties, Tss2_MU_TPML_TAGGED_TPM_PROPERTY_Marshal,
453 TPM2_CAP_PCR_PROPERTIES, ADDR, pcrProperties, Tss2_MU_TPML_TAGGED_PCR_PROPERTY_Marshal,
454 TPM2_CAP_ECC_CURVES, ADDR, eccCurves, Tss2_MU_TPML_ECC_CURVE_Marshal,
455 TPM2_CAP_VENDOR_PROPERTY, ADDR, intelPttProperty, Tss2_MU_TPML_INTEL_PTT_PROPERTY_Marshal)
456 TPMU_UNMARSHAL2(TPMU_CAPABILITIES,
457 TPM2_CAP_ALGS, algorithms, Tss2_MU_TPML_ALG_PROPERTY_Unmarshal,
458 TPM2_CAP_HANDLES, handles, Tss2_MU_TPML_HANDLE_Unmarshal,
459 TPM2_CAP_COMMANDS, command, Tss2_MU_TPML_CCA_Unmarshal,
460 TPM2_CAP_PP_COMMANDS, ppCommands, Tss2_MU_TPML_CC_Unmarshal,
461 TPM2_CAP_AUDIT_COMMANDS, auditCommands, Tss2_MU_TPML_CC_Unmarshal,
462 TPM2_CAP_PCRS, assignedPCR, Tss2_MU_TPML_PCR_SELECTION_Unmarshal,
463 TPM2_CAP_TPM_PROPERTIES, tpmProperties, Tss2_MU_TPML_TAGGED_TPM_PROPERTY_Unmarshal,
464 TPM2_CAP_PCR_PROPERTIES, pcrProperties, Tss2_MU_TPML_TAGGED_PCR_PROPERTY_Unmarshal,
465 TPM2_CAP_ECC_CURVES, eccCurves, Tss2_MU_TPML_ECC_CURVE_Unmarshal,
466 TPM2_CAP_VENDOR_PROPERTY, intelPttProperty, Tss2_MU_TPML_INTEL_PTT_PROPERTY_Unmarshal)
467
468 TPMU_MARSHAL2(TPMU_ATTEST,
469 TPM2_ST_ATTEST_CERTIFY, ADDR, certify, Tss2_MU_TPMS_CERTIFY_INFO_Marshal,
470 TPM2_ST_ATTEST_CREATION, ADDR, creation, Tss2_MU_TPMS_CREATION_INFO_Marshal,
471 TPM2_ST_ATTEST_QUOTE, ADDR, quote, Tss2_MU_TPMS_QUOTE_INFO_Marshal,
472 TPM2_ST_ATTEST_COMMAND_AUDIT, ADDR, commandAudit, Tss2_MU_TPMS_COMMAND_AUDIT_INFO_Marshal,
473 TPM2_ST_ATTEST_SESSION_AUDIT, ADDR, sessionAudit, Tss2_MU_TPMS_SESSION_AUDIT_INFO_Marshal,
474 TPM2_ST_ATTEST_TIME, ADDR, time, Tss2_MU_TPMS_TIME_ATTEST_INFO_Marshal,
475 TPM2_ST_ATTEST_NV, ADDR, nv, Tss2_MU_TPMS_NV_CERTIFY_INFO_Marshal)
476 TPMU_UNMARSHAL2(TPMU_ATTEST,
477 TPM2_ST_ATTEST_CERTIFY, certify, Tss2_MU_TPMS_CERTIFY_INFO_Unmarshal,
478 TPM2_ST_ATTEST_CREATION, creation, Tss2_MU_TPMS_CREATION_INFO_Unmarshal,
479 TPM2_ST_ATTEST_QUOTE, quote, Tss2_MU_TPMS_QUOTE_INFO_Unmarshal,
480 TPM2_ST_ATTEST_COMMAND_AUDIT, commandAudit, Tss2_MU_TPMS_COMMAND_AUDIT_INFO_Unmarshal,
481 TPM2_ST_ATTEST_SESSION_AUDIT, sessionAudit, Tss2_MU_TPMS_SESSION_AUDIT_INFO_Unmarshal,
482 TPM2_ST_ATTEST_TIME, time, Tss2_MU_TPMS_TIME_ATTEST_INFO_Unmarshal,
483 TPM2_ST_ATTEST_NV, nv, Tss2_MU_TPMS_NV_CERTIFY_INFO_Unmarshal)
484
485 TPMU_MARSHAL2(TPMU_SYM_KEY_BITS,
486 TPM2_ALG_AES, VAL, aes, Tss2_MU_UINT16_Marshal,
487 TPM2_ALG_SM4, VAL, sm4, Tss2_MU_UINT16_Marshal,
488 TPM2_ALG_CAMELLIA, VAL, camellia, Tss2_MU_UINT16_Marshal,
489 TPM2_ALG_XOR, VAL, exclusiveOr, Tss2_MU_UINT16_Marshal)
490 TPMU_UNMARSHAL2(TPMU_SYM_KEY_BITS,
491 TPM2_ALG_AES, aes, Tss2_MU_UINT16_Unmarshal,
492 TPM2_ALG_SM4, sm4, Tss2_MU_UINT16_Unmarshal,
493 TPM2_ALG_CAMELLIA, camellia, Tss2_MU_UINT16_Unmarshal,
494 TPM2_ALG_XOR, exclusiveOr, Tss2_MU_UINT16_Unmarshal)
495
496 TPMU_MARSHAL2(TPMU_SYM_MODE,
497 TPM2_ALG_AES, VAL, aes, Tss2_MU_UINT16_Marshal,
498 TPM2_ALG_SM4, VAL, sm4, Tss2_MU_UINT16_Marshal,
499 TPM2_ALG_CAMELLIA, VAL, camellia, Tss2_MU_UINT16_Marshal)
500 TPMU_UNMARSHAL2(TPMU_SYM_MODE,
501 TPM2_ALG_AES, aes, Tss2_MU_UINT16_Unmarshal,
502 TPM2_ALG_SM4, sm4, Tss2_MU_UINT16_Unmarshal,
503 TPM2_ALG_CAMELLIA, camellia, Tss2_MU_UINT16_Unmarshal)
504
505 TPMU_MARSHAL2(TPMU_SIG_SCHEME,
506 TPM2_ALG_RSASSA, ADDR, rsassa, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
507 TPM2_ALG_RSAPSS, ADDR, rsapss, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
508 TPM2_ALG_ECDSA, ADDR, ecdsa, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
509 TPM2_ALG_ECDAA, ADDR, ecdaa, Tss2_MU_TPMS_SCHEME_ECDAA_Marshal,
510 TPM2_ALG_SM2, ADDR, sm2, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
511 TPM2_ALG_ECSCHNORR, ADDR, ecschnorr, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
512 TPM2_ALG_HMAC, ADDR, hmac, Tss2_MU_TPMS_SCHEME_HASH_Marshal)
513 TPMU_UNMARSHAL2(TPMU_SIG_SCHEME,
514 TPM2_ALG_RSASSA, rsassa, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
515 TPM2_ALG_RSAPSS, rsapss, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
516 TPM2_ALG_ECDSA, ecdsa, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
517 TPM2_ALG_ECDAA, ecdaa, Tss2_MU_TPMS_SCHEME_ECDAA_Unmarshal,
518 TPM2_ALG_SM2, sm2, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
519 TPM2_ALG_ECSCHNORR, ecschnorr, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
520 TPM2_ALG_HMAC, hmac, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal)
521
522 TPMU_MARSHAL2(TPMU_KDF_SCHEME,
523 TPM2_ALG_MGF1, ADDR, mgf1, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
524 TPM2_ALG_KDF1_SP800_56A, ADDR, kdf1_sp800_56a, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
525 TPM2_ALG_KDF1_SP800_108, ADDR, kdf1_sp800_108, Tss2_MU_TPMS_SCHEME_HASH_Marshal)
526 TPMU_UNMARSHAL2(TPMU_KDF_SCHEME,
527 TPM2_ALG_MGF1, mgf1, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
528 TPM2_ALG_KDF1_SP800_56A, kdf1_sp800_56a, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
529 TPM2_ALG_KDF1_SP800_108, kdf1_sp800_108, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal)
530
531 TPMU_MARSHAL2(TPMU_ASYM_SCHEME,
532 TPM2_ALG_ECDH, ADDR, ecdh, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
533 TPM2_ALG_ECMQV, ADDR, ecmqv, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
534 TPM2_ALG_RSASSA, ADDR, rsassa, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
535 TPM2_ALG_RSAPSS, ADDR, rsapss, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
536 TPM2_ALG_ECDSA, ADDR, ecdsa, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
537 TPM2_ALG_ECDAA, ADDR, ecdaa, Tss2_MU_TPMS_SCHEME_ECDAA_Marshal,
538 TPM2_ALG_SM2, ADDR, sm2, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
539 TPM2_ALG_ECSCHNORR, ADDR, ecschnorr, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
540 TPM2_ALG_OAEP, ADDR, oaep, Tss2_MU_TPMS_SCHEME_HASH_Marshal)
541 TPMU_UNMARSHAL2(TPMU_ASYM_SCHEME,
542 TPM2_ALG_ECDH, ecdh, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
543 TPM2_ALG_ECMQV, ecmqv, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
544 TPM2_ALG_RSASSA, rsassa, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
545 TPM2_ALG_RSAPSS, rsapss, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
546 TPM2_ALG_ECDSA, ecdsa, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
547 TPM2_ALG_ECDAA, ecdaa, Tss2_MU_TPMS_SCHEME_ECDAA_Unmarshal,
548 TPM2_ALG_SM2, sm2, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
549 TPM2_ALG_ECSCHNORR, ecschnorr, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
550 TPM2_ALG_OAEP, oaep, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal)
551
552 TPMU_MARSHAL2(TPMU_SCHEME_KEYEDHASH,
553 TPM2_ALG_HMAC, ADDR, hmac, Tss2_MU_TPMS_SCHEME_HASH_Marshal,
554 TPM2_ALG_XOR, ADDR, exclusiveOr, Tss2_MU_TPMS_SCHEME_XOR_Marshal)
555 TPMU_UNMARSHAL2(TPMU_SCHEME_KEYEDHASH,
556 TPM2_ALG_HMAC, hmac, Tss2_MU_TPMS_SCHEME_HASH_Unmarshal,
557 TPM2_ALG_XOR, exclusiveOr, Tss2_MU_TPMS_SCHEME_XOR_Unmarshal)
558
559 TPMU_MARSHAL2(TPMU_SIGNATURE,
560 TPM2_ALG_RSASSA, ADDR, rsassa, Tss2_MU_TPMS_SIGNATURE_RSA_Marshal,
561 TPM2_ALG_RSAPSS, ADDR, rsapss, Tss2_MU_TPMS_SIGNATURE_RSA_Marshal,
562 TPM2_ALG_ECDSA, ADDR, ecdsa, Tss2_MU_TPMS_SIGNATURE_ECC_Marshal,
563 TPM2_ALG_ECDAA, ADDR, ecdaa, Tss2_MU_TPMS_SIGNATURE_ECC_Marshal,
564 TPM2_ALG_SM2, ADDR, sm2, Tss2_MU_TPMS_SIGNATURE_ECC_Marshal,
565 TPM2_ALG_ECSCHNORR, ADDR, ecschnorr, Tss2_MU_TPMS_SIGNATURE_ECC_Marshal,
566 TPM2_ALG_HMAC, ADDR, hmac, Tss2_MU_TPMT_HA_Marshal)
567 TPMU_UNMARSHAL2(TPMU_SIGNATURE,
568 TPM2_ALG_RSASSA, rsassa, Tss2_MU_TPMS_SIGNATURE_RSA_Unmarshal,
569 TPM2_ALG_RSAPSS, rsapss, Tss2_MU_TPMS_SIGNATURE_RSA_Unmarshal,
570 TPM2_ALG_ECDSA, ecdsa, Tss2_MU_TPMS_SIGNATURE_ECC_Unmarshal,
571 TPM2_ALG_ECDAA, ecdaa, Tss2_MU_TPMS_SIGNATURE_ECC_Unmarshal,
572 TPM2_ALG_SM2, sm2, Tss2_MU_TPMS_SIGNATURE_ECC_Unmarshal,
573 TPM2_ALG_ECSCHNORR, ecschnorr, Tss2_MU_TPMS_SIGNATURE_ECC_Unmarshal,
574 TPM2_ALG_HMAC, hmac, Tss2_MU_TPMT_HA_Unmarshal)
575
576 TPMU_MARSHAL2(TPMU_SENSITIVE_COMPOSITE,
577 TPM2_ALG_RSA, ADDR, rsa, Tss2_MU_TPM2B_PRIVATE_KEY_RSA_Marshal,
578 TPM2_ALG_ECC, ADDR, ecc, Tss2_MU_TPM2B_ECC_PARAMETER_Marshal,
579 TPM2_ALG_KEYEDHASH, ADDR, bits, Tss2_MU_TPM2B_SENSITIVE_DATA_Marshal,
580 TPM2_ALG_SYMCIPHER, ADDR, sym, Tss2_MU_TPM2B_SYM_KEY_Marshal)
581 TPMU_UNMARSHAL2(TPMU_SENSITIVE_COMPOSITE,
582 TPM2_ALG_RSA, rsa, Tss2_MU_TPM2B_PRIVATE_KEY_RSA_Unmarshal,
583 TPM2_ALG_ECC, ecc, Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal,
584 TPM2_ALG_KEYEDHASH, bits, Tss2_MU_TPM2B_SENSITIVE_DATA_Unmarshal,
585 TPM2_ALG_SYMCIPHER, sym, Tss2_MU_TPM2B_SYM_KEY_Unmarshal)
586
587 TPMU_MARSHAL2(TPMU_ENCRYPTED_SECRET,
588 TPM2_ALG_ECC, ADDR, ecc[0], marshal_ecc,
589 TPM2_ALG_RSA, ADDR, rsa[0], marshal_rsa,
590 TPM2_ALG_SYMCIPHER, ADDR, symmetric[0], marshal_symmetric,
591 TPM2_ALG_KEYEDHASH, ADDR, keyedHash[0], marshal_keyedhash)
592 TPMU_UNMARSHAL2(TPMU_ENCRYPTED_SECRET,
593 TPM2_ALG_ECC, ecc[0], unmarshal_ecc,
594 TPM2_ALG_RSA, rsa[0], unmarshal_rsa,
595 TPM2_ALG_SYMCIPHER, symmetric[0], unmarshal_symmetric,
596 TPM2_ALG_KEYEDHASH, keyedHash[0], unmarshal_keyedhash)
597
598 TPMU_MARSHAL2(TPMU_PUBLIC_ID,
599 TPM2_ALG_KEYEDHASH, ADDR, keyedHash, Tss2_MU_TPM2B_DIGEST_Marshal,
600 TPM2_ALG_SYMCIPHER, ADDR, sym, Tss2_MU_TPM2B_DIGEST_Marshal,
601 TPM2_ALG_RSA, ADDR, rsa, Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Marshal,
602 TPM2_ALG_ECC, ADDR, ecc, Tss2_MU_TPMS_ECC_POINT_Marshal)
603 TPMU_UNMARSHAL2(TPMU_PUBLIC_ID,
604 TPM2_ALG_KEYEDHASH, keyedHash, Tss2_MU_TPM2B_DIGEST_Unmarshal,
605 TPM2_ALG_SYMCIPHER, sym, Tss2_MU_TPM2B_DIGEST_Unmarshal,
606 TPM2_ALG_RSA, rsa, Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Unmarshal,
607 TPM2_ALG_ECC, ecc, Tss2_MU_TPMS_ECC_POINT_Unmarshal)
608
609 TPMU_MARSHAL2(TPMU_PUBLIC_PARMS,
610 TPM2_ALG_KEYEDHASH, ADDR, keyedHashDetail, Tss2_MU_TPMS_KEYEDHASH_PARMS_Marshal,
611 TPM2_ALG_SYMCIPHER, ADDR, symDetail, Tss2_MU_TPMS_SYMCIPHER_PARMS_Marshal,
612 TPM2_ALG_RSA, ADDR, rsaDetail, Tss2_MU_TPMS_RSA_PARMS_Marshal,
613 TPM2_ALG_ECC, ADDR, eccDetail, Tss2_MU_TPMS_ECC_PARMS_Marshal)
614 TPMU_UNMARSHAL2(TPMU_PUBLIC_PARMS,
615 TPM2_ALG_KEYEDHASH, keyedHashDetail, Tss2_MU_TPMS_KEYEDHASH_PARMS_Unmarshal,
616 TPM2_ALG_SYMCIPHER, symDetail, Tss2_MU_TPMS_SYMCIPHER_PARMS_Unmarshal,
617 TPM2_ALG_RSA, rsaDetail, Tss2_MU_TPMS_RSA_PARMS_Unmarshal,
618 TPM2_ALG_ECC, eccDetail, Tss2_MU_TPMS_ECC_PARMS_Unmarshal)
619
620 TPMU_MARSHAL2(TPMU_NAME,
621 sizeof(TPM2_HANDLE), VAL, handle, Tss2_MU_UINT32_Marshal,
622 sizeof(TPM2_ALG_ID) + TPM2_SHA1_DIGEST_SIZE, ADDR, digest, Tss2_MU_TPMT_HA_Marshal,
623 sizeof(TPM2_ALG_ID) + TPM2_SHA256_DIGEST_SIZE, ADDR, digest, Tss2_MU_TPMT_HA_Marshal,
624 sizeof(TPM2_ALG_ID) + TPM2_SHA384_DIGEST_SIZE, ADDR, digest, Tss2_MU_TPMT_HA_Marshal,
625 sizeof(TPM2_ALG_ID) + TPM2_SHA512_DIGEST_SIZE, ADDR, digest, Tss2_MU_TPMT_HA_Marshal)
626 TPMU_UNMARSHAL2(TPMU_NAME,
627 sizeof(TPM2_HANDLE), handle, Tss2_MU_UINT32_Unmarshal,
628 sizeof(TPM2_ALG_ID) + TPM2_SHA1_DIGEST_SIZE, digest, Tss2_MU_TPMT_HA_Unmarshal,
629 sizeof(TPM2_ALG_ID) + TPM2_SHA256_DIGEST_SIZE, digest, Tss2_MU_TPMT_HA_Unmarshal,
630 sizeof(TPM2_ALG_ID) + TPM2_SHA384_DIGEST_SIZE, digest, Tss2_MU_TPMT_HA_Unmarshal,
631 sizeof(TPM2_ALG_ID) + TPM2_SHA512_DIGEST_SIZE, digest, Tss2_MU_TPMT_HA_Unmarshal)
632