summaryrefslogtreecommitdiffstats
path: root/tpm-util/duplicate/marshal.c
diff options
context:
space:
mode:
authorArun kumar Sekar <arunkumarsit@gmail.com>2018-03-30 11:20:30 -0700
committerArun kumar sekar <arunkumarsit@gmail.com>2018-04-03 21:14:48 +0000
commit2ac563372735668ac9687c57e35e39c3e4553ff0 (patch)
tree4f276f8feba53a700f73a4aa9f2f55187444dff5 /tpm-util/duplicate/marshal.c
parent3d5e48d877919ec8d33e1d1ee3682fb1f0bc0532 (diff)
Utility to Import external RSA pem key into TPM
Duplicate tool - Takes RSA private key in pem format as input and generates TPM structured buffers as expected by tpm Import Import tool - Takes input buffers from Duplicate tool and results in pub/priv blobs which can be used to load the key in tpm storage heirarchy's as child to primary key Change-Id: I0af6676895ce0cc22c70e5546908e905b78bb71e Issue-ID: AAF-207 Signed-off-by: Arun kumar Sekar <arunkumarsit@gmail.com>
Diffstat (limited to 'tpm-util/duplicate/marshal.c')
-rw-r--r--tpm-util/duplicate/marshal.c4870
1 files changed, 4870 insertions, 0 deletions
diff --git a/tpm-util/duplicate/marshal.c b/tpm-util/duplicate/marshal.c
new file mode 100644
index 0000000..27933ba
--- /dev/null
+++ b/tpm-util/duplicate/marshal.c
@@ -0,0 +1,4870 @@
+/*
+ * Copyright 2018 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+// Author: Arun Kumar Sekar
+
+
+#include "marshal.h"
+
+TPM_RC
+UINT8_Unmarshal(
+ UINT8 *target, BYTE **buffer, INT32 *size
+ )
+{
+ if((*size -= 1) < 0)
+ return TPM_RC_INSUFFICIENT;
+ *target = BYTE_ARRAY_TO_UINT8(*buffer);
+ *buffer += 1;
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+UINT8_Marshal(
+ UINT8 *source, BYTE **buffer, INT32 *size
+ )
+{
+ if (buffer != 0)
+ {
+ if ((size == 0) || ((*size -= 1) >= 0))
+ {
+ UINT8_TO_BYTE_ARRAY(*source, *buffer);
+ *buffer += 1;
+ }
+ pAssert(size == 0 || (*size >= 0));
+ }
+ return (1);
+}
+
+// BYTE definition from table 2:3
+// BYTE_Unmarshal changed to #define
+// BYTE_Marshal changed to #define
+// INT8 definition from table 2:3
+// INT8_Unmarshal changed to #define
+// INT8_Marshal not referenced
+// UINT16 definition from table 2:3
+TPM_RC
+UINT16_Unmarshal(
+ UINT16 *target, BYTE **buffer, INT32 *size
+ )
+{
+ if((*size -= 2) < 0)
+ return TPM_RC_INSUFFICIENT;
+ *target = BYTE_ARRAY_TO_UINT16(*buffer);
+ *buffer += 2;
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+UINT16_Marshal(
+ UINT16 *source, BYTE **buffer, INT32 *size
+ )
+{
+ if (buffer != 0)
+ {
+ if ((size == 0) || ((*size -= 2) >= 0))
+ {
+ UINT16_TO_BYTE_ARRAY(*source, *buffer);
+ *buffer += 2;
+ }
+ pAssert(size == 0 || (*size >= 0));
+ }
+ return (2);
+}
+
+// INT16 definition from table 2:3
+// INT16_Unmarshal not referenced
+// INT16_Marshal not referenced
+// UINT32 definition from table 2:3
+TPM_RC
+UINT32_Unmarshal(
+ UINT32 *target, BYTE **buffer, INT32 *size
+ )
+{
+ if((*size -= 4) < 0)
+ return TPM_RC_INSUFFICIENT;
+ *target = BYTE_ARRAY_TO_UINT32(*buffer);
+ *buffer += 4;
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+UINT32_Marshal(
+ UINT32 *source, BYTE **buffer, INT32 *size
+ )
+{
+ if (buffer != 0)
+ {
+ if ((size == 0) || ((*size -= 4) >= 0))
+ {
+ UINT32_TO_BYTE_ARRAY(*source, *buffer);
+ *buffer += 4;
+ }
+ pAssert(size == 0 || (*size >= 0));
+ }
+ return (4);
+}
+
+// INT32 definition from table 2:3
+// INT32_Unmarshal changed to #define
+// INT32_Marshal not referenced
+// UINT64 definition from table 2:3
+TPM_RC
+UINT64_Unmarshal(
+ UINT64 *target, BYTE **buffer, INT32 *size
+ )
+{
+ if((*size -= 8) < 0)
+ return TPM_RC_INSUFFICIENT;
+ *target = BYTE_ARRAY_TO_UINT64(*buffer);
+ *buffer += 8;
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+UINT64_Marshal(
+ UINT64 *source, BYTE **buffer, INT32 *size
+ )
+{
+ if (buffer != 0)
+ {
+ if ((size == 0) || ((*size -= 8) >= 0))
+ {
+ UINT64_TO_BYTE_ARRAY(*source, *buffer);
+ *buffer += 8;
+ }
+ pAssert(size == 0 || (*size >= 0));
+ }
+ return (8);
+}
+
+// INT64 definition from table 2:3
+// INT64_Unmarshal not referenced
+// INT64_Marshal not referenced
+
+
+// Table 2:4 - Defines for Logic Values (DefinesTable)
+
+
+// Table 2:5 - Definition of Types for Documentation Clarity (TypesTable)
+// UINT32 definition from table 2:5
+// TPM_ALGORITHM_ID_Unmarshal not referenced
+// TPM_ALGORITHM_ID_Marshal not referenced
+// UINT32 definition from table 2:5
+// TPM_MODIFIER_INDICATOR_Unmarshal not referenced
+// TPM_MODIFIER_INDICATOR_Marshal not referenced
+// UINT32 definition from table 2:5
+// TPM_AUTHORIZATION_SIZE_Unmarshal not referenced
+// TPM_AUTHORIZATION_SIZE_Marshal not referenced
+// UINT32 definition from table 2:5
+// TPM_PARAMETER_SIZE_Unmarshal not referenced
+// TPM_PARAMETER_SIZE_Marshal not referenced
+// UINT16 definition from table 2:5
+// TPM_KEY_SIZE_Unmarshal not referenced
+// TPM_KEY_SIZE_Marshal not referenced
+// UINT16 definition from table 2:5
+// TPM_KEY_BITS_Unmarshal changed to #define
+// TPM_KEY_BITS_Marshal changed to #define
+
+
+// Table 2:6 - Definition of TPM_SPEC Constants (ConstantsTable)
+// TPM_SPEC_Unmarshal not referenced
+// TPM_SPEC_Marshal not referenced
+
+
+// Table 2:7 - Definition of TPM_GENERATED Constants (ConstantsTable)
+// TPM_GENERATED_Unmarshal not referenced
+// TPM_GENERATED_Marshal changed to #define
+
+
+// Table 2:9 - Definition of TPM_ALG_ID Constants (ConstantsTable)
+// TPM_ALG_ID_Unmarshal changed to #define
+// TPM_ALG_ID_Marshal changed to #define
+
+
+// Table 2:10 - Definition of TPM_ECC_CURVE Constants (ConstantsTable)
+#ifdef TPM_ALG_ECC
+// TPM_ECC_CURVE_Unmarshal changed to #define
+// TPM_ECC_CURVE_Marshal changed to #define
+#endif // TPM_ALG_ECC
+
+
+// Table 2:13 - Definition of TPM_CC Constants (ConstantsTable)
+// TPM_CC_Unmarshal changed to #define
+// TPM_CC_Marshal changed to #define
+
+
+// Table 2:17 - Definition of TPM_RC Constants (ConstantsTable)
+// TPM_RC_Unmarshal not referenced
+// TPM_RC_Marshal changed to #define
+
+
+// Table 2:18 - Definition of TPM_CLOCK_ADJUST Constants (ConstantsTable)
+TPM_RC
+TPM_CLOCK_ADJUST_Unmarshal(
+ TPM_CLOCK_ADJUST *target, BYTE **buffer, INT32 *size
+ )
+{
+ return TPM_RC_SUCCESS;
+}
+
+// TPM_CLOCK_ADJUST_Marshal not referenced
+
+
+// Table 2:19 - Definition of TPM_EO Constants (ConstantsTable)
+TPM_RC
+TPM_EO_Unmarshal(
+ TPM_EO *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch(*target) {
+ case TPM_EO_EQ :
+ case TPM_EO_NEQ :
+ case TPM_EO_SIGNED_GT :
+ case TPM_EO_UNSIGNED_GT :
+ case TPM_EO_SIGNED_LT :
+ case TPM_EO_UNSIGNED_LT :
+ case TPM_EO_SIGNED_GE :
+ case TPM_EO_UNSIGNED_GE :
+ case TPM_EO_SIGNED_LE :
+ case TPM_EO_UNSIGNED_LE :
+ case TPM_EO_BITSET :
+ case TPM_EO_BITCLEAR :
+ break;
+ default :
+ return TPM_RC_VALUE;
+ break;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPM_EO_Marshal not referenced
+
+
+// Table 2:20 - Definition of TPM_ST Constants (ConstantsTable)
+// TPM_ST_Unmarshal changed to #define
+// TPM_ST_Marshal changed to #define
+
+
+// Table 2:21 - Definition of TPM_SU Constants (ConstantsTable)
+TPM_RC
+TPM_SU_Unmarshal(
+ TPM_SU *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch(*target) {
+ case TPM_SU_CLEAR :
+ case TPM_SU_STATE :
+ break;
+ default :
+ return TPM_RC_VALUE;
+ break;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPM_SU_Marshal not referenced
+
+
+// Table 2:22 - Definition of TPM_SE Constants (ConstantsTable)
+TPM_RC
+TPM_SE_Unmarshal(
+ TPM_SE *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT8_Unmarshal((UINT8 *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch(*target) {
+ case TPM_SE_HMAC :
+ case TPM_SE_POLICY :
+ case TPM_SE_TRIAL :
+ break;
+ default :
+ return TPM_RC_VALUE;
+ break;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPM_SE_Marshal not referenced
+
+
+// Table 2:23 - Definition of TPM_CAP Constants (ConstantsTable)
+TPM_RC
+TPM_CAP_Unmarshal(
+ TPM_CAP *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT32_Unmarshal((UINT32 *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch(*target) {
+ case TPM_CAP_ALGS :
+ case TPM_CAP_HANDLES :
+ case TPM_CAP_COMMANDS :
+ case TPM_CAP_PP_COMMANDS :
+ case TPM_CAP_AUDIT_COMMANDS :
+ case TPM_CAP_PCRS :
+ case TPM_CAP_TPM_PROPERTIES :
+ case TPM_CAP_PCR_PROPERTIES :
+ case TPM_CAP_ECC_CURVES :
+ case TPM_CAP_VENDOR_PROPERTY :
+ break;
+ default :
+ return TPM_RC_VALUE;
+ break;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPM_CAP_Marshal changed to #define
+
+
+// Table 2:24 - Definition of TPM_PT Constants (ConstantsTable)
+// TPM_PT_Unmarshal not referenced
+// TPM_PT_Marshal changed to #define
+
+
+// Table 2:25 - Definition of TPM_PT_PCR Constants (ConstantsTable)
+// TPM_PT_PCR_Unmarshal not referenced
+// TPM_PT_PCR_Marshal not referenced
+
+
+// Table 2:26 - Definition of TPM_PS Constants (ConstantsTable)
+// TPM_PS_Unmarshal not referenced
+// TPM_PS_Marshal not referenced
+
+
+// Table 2:27 - Definition of Types for Handles (TypesTable)
+// UINT32 definition from table 2:27
+// TPM_HANDLE_Unmarshal changed to #define
+// TPM_HANDLE_Marshal changed to #define
+
+
+// Table 2:28 - Definition of TPM_HT Constants (ConstantsTable)
+// TPM_HT_Unmarshal not referenced
+// TPM_HT_Marshal not referenced
+
+
+// Table 2:29 - Definition of TPM_RH Constants (ConstantsTable)
+// TPM_RH_Unmarshal not referenced
+// TPM_RH_Marshal not referenced
+
+
+// Table 2:30 - Definition of TPM_HC Constants (ConstantsTable)
+// TPM_HC_Unmarshal not referenced
+// TPM_HC_Marshal not referenced
+
+
+// Table 2:31 - Definition of TPMA_ALGORITHM Bits (BitsTable)
+// TPMA_ALGORITHM_Unmarshal not referenced
+// TPMA_ALGORITHM_Marshal changed to #define
+
+
+// Table 2:32 - Definition of TPMA_OBJECT Bits (BitsTable)
+TPM_RC
+TPMA_OBJECT_Unmarshal(
+ TPMA_OBJECT *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT32_Unmarshal((UINT32 *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if(*((UINT32 *)target) & (UINT32)0xfff8f309)
+ return TPM_RC_RESERVED_BITS;
+ return TPM_RC_SUCCESS;
+}
+
+// TPMA_OBJECT_Marshal changed to #define
+
+
+// Table 2:33 - Definition of TPMA_SESSION Bits (BitsTable)
+TPM_RC
+TPMA_SESSION_Unmarshal(
+ TPMA_SESSION *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT8_Unmarshal((UINT8 *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if(*((UINT8 *)target) & (UINT8)0x18)
+ return TPM_RC_RESERVED_BITS;
+ return TPM_RC_SUCCESS;
+}
+
+// TPMA_SESSION_Marshal changed to #define
+
+
+// Table 2:34 - Definition of TPMA_LOCALITY Bits (BitsTable)
+// TPMA_LOCALITY_Unmarshal changed to #define
+// TPMA_LOCALITY_Marshal changed to #define
+
+
+// Table 2:35 - Definition of TPMA_PERMANENT Bits (BitsTable)
+// TPMA_PERMANENT_Unmarshal not referenced
+// TPMA_PERMANENT_Marshal not referenced
+
+
+// Table 2:36 - Definition of TPMA_STARTUP_CLEAR Bits (BitsTable)
+// TPMA_STARTUP_CLEAR_Unmarshal not referenced
+// TPMA_STARTUP_CLEAR_Marshal not referenced
+
+
+// Table 2:37 - Definition of TPMA_MEMORY Bits (BitsTable)
+// TPMA_MEMORY_Unmarshal not referenced
+// TPMA_MEMORY_Marshal not referenced
+
+
+// Table 2:38 - Definition of TPMA_CC Bits (BitsTable)
+// TPMA_CC_Unmarshal not referenced
+// TPMA_CC_Marshal changed to #define
+
+
+// Table 2:39 - Definition of TPMI_YES_NO Type (TypeTable)
+TPM_RC
+TPMI_YES_NO_Unmarshal(
+ TPMI_YES_NO *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = BYTE_Unmarshal((BYTE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case NO:
+ case YES:
+ break;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_YES_NO_Marshal changed to #define
+
+
+// Table 2:40 - Definition of TPMI_DH_OBJECT Type (TypeTable)
+TPM_RC
+TPMI_DH_OBJECT_Unmarshal(
+ TPMI_DH_OBJECT *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if (*target == TPM_RH_NULL) {
+ if(flag)
+ return TPM_RC_SUCCESS;
+ else
+ return TPM_RC_VALUE;
+ }
+
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_DH_OBJECT_Marshal changed to #define
+
+
+// Table 2:41 - Definition of TPMI_DH_PERSISTENT Type (TypeTable)
+TPM_RC
+TPMI_DH_PERSISTENT_Unmarshal(
+ TPMI_DH_PERSISTENT *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if((*target < PERSISTENT_FIRST) || (*target > PERSISTENT_LAST))
+ return TPM_RC_VALUE;
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_DH_PERSISTENT_Marshal not referenced
+
+
+// Table 2:42 - Definition of TPMI_DH_ENTITY Type (TypeTable)
+TPM_RC
+TPMI_DH_ENTITY_Unmarshal(
+ TPMI_DH_ENTITY *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_DH_ENTITY_Marshal not referenced
+
+
+// Table 2:43 - Definition of TPMI_DH_PCR Type (TypeTable)
+TPM_RC
+TPMI_DH_PCR_Unmarshal(
+ TPMI_DH_PCR *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if (*target == TPM_RH_NULL) {
+ if(flag)
+ return TPM_RC_SUCCESS;
+ else
+ return TPM_RC_VALUE;
+ }
+
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_DH_PCR_Marshal not referenced
+
+
+// Table 2:44 - Definition of TPMI_SH_AUTH_SESSION Type (TypeTable)
+TPM_RC
+TPMI_SH_AUTH_SESSION_Unmarshal(
+ TPMI_SH_AUTH_SESSION *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if (*target == TPM_RS_PW) {
+ if(flag)
+ return TPM_RC_SUCCESS;
+ else
+ return TPM_RC_VALUE;
+ }
+
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_SH_AUTH_SESSION_Marshal changed to #define
+
+
+// Table 2:45 - Definition of TPMI_SH_HMAC Type (TypeTable)
+TPM_RC
+TPMI_SH_HMAC_Unmarshal(
+ TPMI_SH_HMAC *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_SH_HMAC_Marshal not referenced
+
+
+// Table 2:46 - Definition of TPMI_SH_POLICY Type (TypeTable)
+TPM_RC
+TPMI_SH_POLICY_Unmarshal(
+ TPMI_SH_POLICY *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_SH_POLICY_Marshal not referenced
+
+
+// Table 2:47 - Definition of TPMI_DH_CONTEXT Type (TypeTable)
+TPM_RC
+TPMI_DH_CONTEXT_Unmarshal(
+ TPMI_DH_CONTEXT *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_DH_CONTEXT_Marshal changed to #define
+
+
+// Table 2:48 - Definition of TPMI_RH_HIERARCHY Type (TypeTable)
+TPM_RC
+TPMI_RH_HIERARCHY_Unmarshal(
+ TPMI_RH_HIERARCHY *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_RH_OWNER:
+ case TPM_RH_PLATFORM:
+ case TPM_RH_ENDORSEMENT:
+ break;
+ case TPM_RH_NULL:
+ if (flag)
+ break;
+ return TPM_RC_VALUE;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RH_HIERARCHY_Marshal changed to #define
+
+
+// Table 2:49 - Definition of TPMI_RH_ENABLES Type (TypeTable)
+TPM_RC
+TPMI_RH_ENABLES_Unmarshal(
+ TPMI_RH_ENABLES *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_RH_OWNER:
+ case TPM_RH_PLATFORM:
+ case TPM_RH_ENDORSEMENT:
+ case TPM_RH_PLATFORM_NV:
+ break;
+ case TPM_RH_NULL:
+ if (flag)
+ break;
+ return TPM_RC_VALUE;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RH_ENABLES_Marshal not referenced
+
+
+// Table 2:50 - Definition of TPMI_RH_HIERARCHY_AUTH Type (TypeTable)
+TPM_RC
+TPMI_RH_HIERARCHY_AUTH_Unmarshal(
+ TPMI_RH_HIERARCHY_AUTH *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_RH_OWNER:
+ case TPM_RH_PLATFORM:
+ case TPM_RH_ENDORSEMENT:
+ case TPM_RH_LOCKOUT:
+ break;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RH_HIERARCHY_AUTH_Marshal not referenced
+
+
+// Table 2:51 - Definition of TPMI_RH_PLATFORM Type (TypeTable)
+TPM_RC
+TPMI_RH_PLATFORM_Unmarshal(
+ TPMI_RH_PLATFORM *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_RH_PLATFORM:
+ break;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RH_PLATFORM_Marshal not referenced
+
+
+// Table 2:52 - Definition of TPMI_RH_OWNER Type (TypeTable)
+// TPMI_RH_OWNER_Unmarshal not referenced
+// TPMI_RH_OWNER_Marshal not referenced
+
+
+// Table 2:53 - Definition of TPMI_RH_ENDORSEMENT Type (TypeTable)
+TPM_RC
+TPMI_RH_ENDORSEMENT_Unmarshal(
+ TPMI_RH_ENDORSEMENT *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_RH_ENDORSEMENT:
+ break;
+ case TPM_RH_NULL:
+ if (flag)
+ break;
+ return TPM_RC_VALUE;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RH_ENDORSEMENT_Marshal not referenced
+
+
+// Table 2:54 - Definition of TPMI_RH_PROVISION Type (TypeTable)
+TPM_RC
+TPMI_RH_PROVISION_Unmarshal(
+ TPMI_RH_PROVISION *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_RH_OWNER:
+ case TPM_RH_PLATFORM:
+ break;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RH_PROVISION_Marshal not referenced
+
+
+// Table 2:55 - Definition of TPMI_RH_CLEAR Type (TypeTable)
+TPM_RC
+TPMI_RH_CLEAR_Unmarshal(
+ TPMI_RH_CLEAR *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_RH_LOCKOUT:
+ case TPM_RH_PLATFORM:
+ break;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RH_CLEAR_Marshal not referenced
+
+
+// Table 2:56 - Definition of TPMI_RH_NV_AUTH Type (TypeTable)
+TPM_RC
+TPMI_RH_NV_AUTH_Unmarshal(
+ TPMI_RH_NV_AUTH *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_RH_PLATFORM:
+ case TPM_RH_OWNER:
+ break;
+ default:
+ if((*target < NV_INDEX_FIRST) || (*target > NV_INDEX_LAST))
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RH_NV_AUTH_Marshal not referenced
+
+
+// Table 2:57 - Definition of TPMI_RH_LOCKOUT Type (TypeTable)
+TPM_RC
+TPMI_RH_LOCKOUT_Unmarshal(
+ TPMI_RH_LOCKOUT *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_RH_LOCKOUT:
+ break;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RH_LOCKOUT_Marshal not referenced
+
+
+// Table 2:58 - Definition of TPMI_RH_NV_INDEX Type (TypeTable)
+TPM_RC
+TPMI_RH_NV_INDEX_Unmarshal(
+ TPMI_RH_NV_INDEX *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if((*target < NV_INDEX_FIRST) || (*target > NV_INDEX_LAST))
+ return TPM_RC_VALUE;
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RH_NV_INDEX_Marshal changed to #define
+
+
+// Table 2:59 - Definition of TPMI_ALG_HASH Type (TypeTable)
+TPM_RC
+TPMI_ALG_HASH_Unmarshal(
+ TPMI_ALG_HASH *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_SHA1
+ case TPM_ALG_SHA1:
+#endif // TPM_ALG_SHA1
+#ifdef TPM_ALG_SHA256
+ case TPM_ALG_SHA256:
+#endif // TPM_ALG_SHA256
+#ifdef TPM_ALG_SHA384
+ case TPM_ALG_SHA384:
+#endif // TPM_ALG_SHA384
+#ifdef TPM_ALG_SHA512
+ case TPM_ALG_SHA512:
+#endif // TPM_ALG_SHA512
+#ifdef TPM_ALG_SM3_256
+ case TPM_ALG_SM3_256:
+#endif // TPM_ALG_SM3_256
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_HASH;
+ default:
+ return TPM_RC_HASH;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_HASH_Marshal changed to #define
+
+
+// Table 2:60 - Definition of TPMI_ALG_ASYM Type (TypeTable)
+// TPMI_ALG_ASYM_Unmarshal not referenced
+// TPMI_ALG_ASYM_Marshal not referenced
+
+
+// Table 2:61 - Definition of TPMI_ALG_SYM Type (TypeTable)
+TPM_RC
+TPMI_ALG_SYM_Unmarshal(
+ TPMI_ALG_SYM *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_AES
+ case TPM_ALG_AES:
+#endif // TPM_ALG_AES
+#ifdef TPM_ALG_SM4
+ case TPM_ALG_SM4:
+#endif // TPM_ALG_SM4
+#ifdef TPM_ALG_CAMELLIA
+ case TPM_ALG_CAMELLIA:
+#endif // TPM_ALG_CAMELLIA
+#ifdef TPM_ALG_XOR
+ case TPM_ALG_XOR:
+#endif // TPM_ALG_XOR
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_SYMMETRIC;
+ default:
+ return TPM_RC_SYMMETRIC;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_SYM_Marshal not referenced
+
+
+// Table 2:62 - Definition of TPMI_ALG_SYM_OBJECT Type (TypeTable)
+TPM_RC
+TPMI_ALG_SYM_OBJECT_Unmarshal(
+ TPMI_ALG_SYM_OBJECT *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_AES
+ case TPM_ALG_AES:
+#endif // TPM_ALG_AES
+#ifdef TPM_ALG_SM4
+ case TPM_ALG_SM4:
+#endif // TPM_ALG_SM4
+#ifdef TPM_ALG_CAMELLIA
+ case TPM_ALG_CAMELLIA:
+#endif // TPM_ALG_CAMELLIA
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_SYMMETRIC;
+ default:
+ return TPM_RC_SYMMETRIC;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_SYM_OBJECT_Marshal changed to #define
+
+
+// Table 2:63 - Definition of TPMI_ALG_SYM_MODE Type (TypeTable)
+TPM_RC
+TPMI_ALG_SYM_MODE_Unmarshal(
+ TPMI_ALG_SYM_MODE *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_CTR
+ case TPM_ALG_CTR:
+#endif // TPM_ALG_CTR
+#ifdef TPM_ALG_OFB
+ case TPM_ALG_OFB:
+#endif // TPM_ALG_OFB
+#ifdef TPM_ALG_CBC
+ case TPM_ALG_CBC:
+#endif // TPM_ALG_CBC
+#ifdef TPM_ALG_CFB
+ case TPM_ALG_CFB:
+#endif // TPM_ALG_CFB
+#ifdef TPM_ALG_ECB
+ case TPM_ALG_ECB:
+#endif // TPM_ALG_ECB
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_MODE;
+ default:
+ return TPM_RC_MODE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_SYM_MODE_Marshal changed to #define
+
+
+// Table 2:64 - Definition of TPMI_ALG_KDF Type (TypeTable)
+TPM_RC
+TPMI_ALG_KDF_Unmarshal(
+ TPMI_ALG_KDF *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_MGF1
+ case TPM_ALG_MGF1:
+#endif // TPM_ALG_MGF1
+#ifdef TPM_ALG_KDF1_SP800_56A
+ case TPM_ALG_KDF1_SP800_56A:
+#endif // TPM_ALG_KDF1_SP800_56A
+#ifdef TPM_ALG_KDF2
+ case TPM_ALG_KDF2:
+#endif // TPM_ALG_KDF2
+#ifdef TPM_ALG_KDF1_SP800_108
+ case TPM_ALG_KDF1_SP800_108:
+#endif // TPM_ALG_KDF1_SP800_108
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_KDF;
+ default:
+ return TPM_RC_KDF;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_KDF_Marshal changed to #define
+
+
+// Table 2:65 - Definition of TPMI_ALG_SIG_SCHEME Type (TypeTable)
+TPM_RC
+TPMI_ALG_SIG_SCHEME_Unmarshal(
+ TPMI_ALG_SIG_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_RSASSA
+ case TPM_ALG_RSASSA:
+#endif // TPM_ALG_RSASSA
+#ifdef TPM_ALG_RSAPSS
+ case TPM_ALG_RSAPSS:
+#endif // TPM_ALG_RSAPSS
+#ifdef TPM_ALG_ECDSA
+ case TPM_ALG_ECDSA:
+#endif // TPM_ALG_ECDSA
+#ifdef TPM_ALG_SM2
+ case TPM_ALG_SM2:
+#endif // TPM_ALG_SM2
+#ifdef TPM_ALG_ECSCHNORR
+ case TPM_ALG_ECSCHNORR:
+#endif // TPM_ALG_ECSCHNORR
+#ifdef TPM_ALG_ECDAA
+ case TPM_ALG_ECDAA:
+#endif // TPM_ALG_ECDAA
+#ifdef TPM_ALG_HMAC
+ case TPM_ALG_HMAC:
+#endif // TPM_ALG_HMAC
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_SCHEME;
+ default:
+ return TPM_RC_SCHEME;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_SIG_SCHEME_Marshal changed to #define
+
+
+// Table 2:66 - Definition of TPMI_ECC_KEY_EXCHANGE Type (TypeTable)
+#ifdef TPM_ALG_ECC
+TPM_RC
+TPMI_ECC_KEY_EXCHANGE_Unmarshal(
+ TPMI_ECC_KEY_EXCHANGE *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_ECDH
+ case TPM_ALG_ECDH:
+#endif // TPM_ALG_ECDH
+#ifdef TPM_ALG_ECMQV
+ case TPM_ALG_ECMQV:
+#endif // TPM_ALG_ECMQV
+#ifdef TPM_ALG_SM2
+ case TPM_ALG_SM2:
+#endif // TPM_ALG_SM2
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_SCHEME;
+ default:
+ return TPM_RC_SCHEME;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ECC_KEY_EXCHANGE_Marshal not referenced
+#endif // TPM_ALG_ECC
+
+
+// Table 2:67 - Definition of TPMI_ST_COMMAND_TAG Type (TypeTable)
+TPM_RC
+TPMI_ST_COMMAND_TAG_Unmarshal(
+ TPMI_ST_COMMAND_TAG *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_ST_Unmarshal((TPM_ST *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_ST_NO_SESSIONS:
+ case TPM_ST_SESSIONS:
+ break;
+ default:
+ return TPM_RC_BAD_TAG;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ST_COMMAND_TAG_Marshal not referenced
+TPM_RC
+TPMS_EMPTY_Unmarshal(
+ TPMS_EMPTY *target, BYTE **buffer, INT32 *size
+ )
+{
+ // to prevent the compiler from complaining
+ UNREFERENCED(target);
+ UNREFERENCED(buffer);
+ UNREFERENCED(size);
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+TPMS_EMPTY_Marshal(
+ TPMS_EMPTY *source, BYTE **buffer, INT32 *size
+ )
+{
+ // to prevent the compiler from complaining
+ UNREFERENCED(source);
+ UNREFERENCED(buffer);
+ UNREFERENCED(size);
+ return 0;
+}
+
+
+// Table 2:69 - Definition of TPMS_ALGORITHM_DESCRIPTION Structure (StructureTable)
+// TPMS_ALGORITHM_DESCRIPTION_Unmarshal not referenced
+// TPMS_ALGORITHM_DESCRIPTION_Marshal not referenced
+
+
+// Table 2:70 - Definition of TPMU_HA Union (UnionTable)
+TPM_RC
+TPMU_HA_Unmarshal(
+ TPMU_HA *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_SHA1
+ case TPM_ALG_SHA1:
+ return BYTE_Array_Unmarshal((BYTE *)(target->sha1), buffer, size, (INT32)SHA1_DIGEST_SIZE);
+#endif // TPM_ALG_SHA1
+#ifdef TPM_ALG_SHA256
+ case TPM_ALG_SHA256:
+ return BYTE_Array_Unmarshal((BYTE *)(target->sha256), buffer, size, (INT32)SHA256_DIGEST_SIZE);
+#endif // TPM_ALG_SHA256
+#ifdef TPM_ALG_SHA384
+ case TPM_ALG_SHA384:
+ return BYTE_Array_Unmarshal((BYTE *)(target->sha384), buffer, size, (INT32)SHA384_DIGEST_SIZE);
+#endif // TPM_ALG_SHA384
+#ifdef TPM_ALG_SHA512
+ case TPM_ALG_SHA512:
+ return BYTE_Array_Unmarshal((BYTE *)(target->sha512), buffer, size, (INT32)SHA512_DIGEST_SIZE);
+#endif // TPM_ALG_SHA512
+#ifdef TPM_ALG_SM3_256
+ case TPM_ALG_SM3_256:
+ return BYTE_Array_Unmarshal((BYTE *)(target->sm3_256), buffer, size, (INT32)SM3_256_DIGEST_SIZE);
+#endif // TPM_ALG_SM3_256
+ case TPM_ALG_NULL:
+ return TPM_RC_SUCCESS;
+ }
+ return TPM_RC_SELECTOR;
+}
+
+UINT16
+TPMU_HA_Marshal(
+ TPMU_HA *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_SHA1
+ case TPM_ALG_SHA1:
+ return BYTE_Array_Marshal((BYTE *)(source->sha1), buffer, size, (INT32)SHA1_DIGEST_SIZE);
+#endif // TPM_ALG_SHA1
+#ifdef TPM_ALG_SHA256
+ case TPM_ALG_SHA256:
+ return BYTE_Array_Marshal((BYTE *)(source->sha256), buffer, size, (INT32)SHA256_DIGEST_SIZE);
+#endif // TPM_ALG_SHA256
+#ifdef TPM_ALG_SHA384
+ case TPM_ALG_SHA384:
+ return BYTE_Array_Marshal((BYTE *)(source->sha384), buffer, size, (INT32)SHA384_DIGEST_SIZE);
+#endif // TPM_ALG_SHA384
+#ifdef TPM_ALG_SHA512
+ case TPM_ALG_SHA512:
+ return BYTE_Array_Marshal((BYTE *)(source->sha512), buffer, size, (INT32)SHA512_DIGEST_SIZE);
+#endif // TPM_ALG_SHA512
+#ifdef TPM_ALG_SM3_256
+ case TPM_ALG_SM3_256:
+ return BYTE_Array_Marshal((BYTE *)(source->sm3_256), buffer, size, (INT32)SM3_256_DIGEST_SIZE);
+#endif // TPM_ALG_SM3_256
+ case TPM_ALG_NULL:
+ return 0;
+ }
+ return 0;
+}
+
+
+// Table 2:71 - Definition of TPMT_HA Structure (StructureTable)
+TPM_RC
+TPMT_HA_Unmarshal(
+ TPMT_HA *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hashAlg), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_HA_Unmarshal((TPMU_HA *)&(target->digest), buffer, size, (UINT32)target->hashAlg);
+ return result;
+}
+
+UINT16
+TPMT_HA_Marshal(
+ TPMT_HA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hashAlg), buffer, size));
+ result = (UINT16)(result + TPMU_HA_Marshal((TPMU_HA *)&(source->digest), buffer, size, (UINT32)source->hashAlg));
+ return result;
+}
+
+
+// Table 2:72 - Definition of TPM2B_DIGEST Structure (StructureTable)
+TPM_RC
+TPM2B_DIGEST_Unmarshal(
+ TPM2B_DIGEST *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > sizeof(TPMU_HA))
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_DIGEST_Marshal(
+ TPM2B_DIGEST *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:73 - Definition of TPM2B_DATA Structure (StructureTable)
+TPM_RC
+TPM2B_DATA_Unmarshal(
+ TPM2B_DATA *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > sizeof(TPMT_HA))
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_DATA_Marshal(
+ TPM2B_DATA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:74 - Definition of Types for TPM2B_NONCE (TypesTable)
+// TPM2B_DIGEST definition from table 2:74
+// TPM2B_NONCE_Unmarshal changed to #define
+// TPM2B_NONCE_Marshal changed to #define
+
+
+// Table 2:75 - Definition of Types for TPM2B_AUTH (TypesTable)
+// TPM2B_DIGEST definition from table 2:75
+// TPM2B_AUTH_Unmarshal changed to #define
+// TPM2B_AUTH_Marshal changed to #define
+
+
+// Table 2:76 - Definition of Types for TPM2B_OPERAND (TypesTable)
+// TPM2B_DIGEST definition from table 2:76
+// TPM2B_OPERAND_Unmarshal changed to #define
+// TPM2B_OPERAND_Marshal not referenced
+
+
+// Table 2:77 - Definition of TPM2B_EVENT Structure (StructureTable)
+TPM_RC
+TPM2B_EVENT_Unmarshal(
+ TPM2B_EVENT *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > 1024)
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+// TPM2B_EVENT_Marshal not referenced
+
+
+// Table 2:78 - Definition of TPM2B_MAX_BUFFER Structure (StructureTable)
+TPM_RC
+TPM2B_MAX_BUFFER_Unmarshal(
+ TPM2B_MAX_BUFFER *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > MAX_DIGEST_BUFFER)
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_MAX_BUFFER_Marshal(
+ TPM2B_MAX_BUFFER *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:79 - Definition of TPM2B_MAX_NV_BUFFER Structure (StructureTable)
+TPM_RC
+TPM2B_MAX_NV_BUFFER_Unmarshal(
+ TPM2B_MAX_NV_BUFFER *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > MAX_NV_BUFFER_SIZE)
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_MAX_NV_BUFFER_Marshal(
+ TPM2B_MAX_NV_BUFFER *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:80 - Definition of TPM2B_TIMEOUT Structure (StructureTable)
+TPM_RC
+TPM2B_TIMEOUT_Unmarshal(
+ TPM2B_TIMEOUT *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > sizeof(UINT64))
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_TIMEOUT_Marshal(
+ TPM2B_TIMEOUT *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:81 - Definition of TPM2B_IV Structure (StructureTable)
+TPM_RC
+TPM2B_IV_Unmarshal(
+ TPM2B_IV *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > MAX_SYM_BLOCK_SIZE)
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_IV_Marshal(
+ TPM2B_IV *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:82 - Definition of TPMU_NAME Union (UnionTable)
+
+
+// Table 2:83 - Definition of TPM2B_NAME Structure (StructureTable)
+TPM_RC
+TPM2B_NAME_Unmarshal(
+ TPM2B_NAME *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > sizeof(TPMU_NAME))
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.name), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_NAME_Marshal(
+ TPM2B_NAME *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.name), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:84 - Definition of TPMS_PCR_SELECT Structure (StructureTable)
+// TPMS_PCR_SELECT_Unmarshal not referenced
+// TPMS_PCR_SELECT_Marshal not referenced
+
+
+// Table 2:85 - Definition of TPMS_PCR_SELECTION Structure (StructureTable)
+TPM_RC
+TPMS_PCR_SELECTION_Unmarshal(
+ TPMS_PCR_SELECTION *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hash), buffer, size, 0);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = UINT8_Unmarshal((UINT8 *)&(target->sizeofSelect), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if( (target->sizeofSelect < PCR_SELECT_MIN))
+ return TPM_RC_VALUE;
+ if((target->sizeofSelect) > PCR_SELECT_MAX)
+ return TPM_RC_VALUE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->pcrSelect), buffer, size, (INT32)(target->sizeofSelect));
+ return result;
+}
+
+UINT16
+TPMS_PCR_SELECTION_Marshal(
+ TPMS_PCR_SELECTION *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hash), buffer, size));
+ result = (UINT16)(result + UINT8_Marshal((UINT8 *)&(source->sizeofSelect), buffer, size));
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->pcrSelect), buffer, size, (INT32)(source->sizeofSelect)));
+ return result;
+}
+
+
+// Table 2:88 - Definition of TPMT_TK_CREATION Structure (StructureTable)
+TPM_RC
+TPMT_TK_CREATION_Unmarshal(
+ TPMT_TK_CREATION *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_ST_Unmarshal((TPM_ST *)&(target->tag), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if( ((target->tag) != TPM_ST_CREATION))
+ return TPM_RC_TAG;
+ result = TPMI_RH_HIERARCHY_Unmarshal((TPMI_RH_HIERARCHY *)&(target->hierarchy), buffer, size, 1);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->digest), buffer, size);
+ return result;
+}
+
+UINT16
+TPMT_TK_CREATION_Marshal(
+ TPMT_TK_CREATION *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM_ST_Marshal((TPM_ST *)&(source->tag), buffer, size));
+ result = (UINT16)(result + TPMI_RH_HIERARCHY_Marshal((TPMI_RH_HIERARCHY *)&(source->hierarchy), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->digest), buffer, size));
+ return result;
+}
+
+
+// Table 2:89 - Definition of TPMT_TK_VERIFIED Structure (StructureTable)
+TPM_RC
+TPMT_TK_VERIFIED_Unmarshal(
+ TPMT_TK_VERIFIED *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_ST_Unmarshal((TPM_ST *)&(target->tag), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if( ((target->tag) != TPM_ST_VERIFIED))
+ return TPM_RC_TAG;
+ result = TPMI_RH_HIERARCHY_Unmarshal((TPMI_RH_HIERARCHY *)&(target->hierarchy), buffer, size, 1);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->digest), buffer, size);
+ return result;
+}
+
+UINT16
+TPMT_TK_VERIFIED_Marshal(
+ TPMT_TK_VERIFIED *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM_ST_Marshal((TPM_ST *)&(source->tag), buffer, size));
+ result = (UINT16)(result + TPMI_RH_HIERARCHY_Marshal((TPMI_RH_HIERARCHY *)&(source->hierarchy), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->digest), buffer, size));
+ return result;
+}
+
+
+// Table 2:90 - Definition of TPMT_TK_AUTH Structure (StructureTable)
+TPM_RC
+TPMT_TK_AUTH_Unmarshal(
+ TPMT_TK_AUTH *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_ST_Unmarshal((TPM_ST *)&(target->tag), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if( ((target->tag) != TPM_ST_AUTH_SIGNED)
+ && ((target->tag) != TPM_ST_AUTH_SECRET))
+ return TPM_RC_TAG;
+ result = TPMI_RH_HIERARCHY_Unmarshal((TPMI_RH_HIERARCHY *)&(target->hierarchy), buffer, size, 1);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->digest), buffer, size);
+ return result;
+}
+
+UINT16
+TPMT_TK_AUTH_Marshal(
+ TPMT_TK_AUTH *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM_ST_Marshal((TPM_ST *)&(source->tag), buffer, size));
+ result = (UINT16)(result + TPMI_RH_HIERARCHY_Marshal((TPMI_RH_HIERARCHY *)&(source->hierarchy), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->digest), buffer, size));
+ return result;
+}
+
+
+// Table 2:91 - Definition of TPMT_TK_HASHCHECK Structure (StructureTable)
+TPM_RC
+TPMT_TK_HASHCHECK_Unmarshal(
+ TPMT_TK_HASHCHECK *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_ST_Unmarshal((TPM_ST *)&(target->tag), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if( ((target->tag) != TPM_ST_HASHCHECK))
+ return TPM_RC_TAG;
+ result = TPMI_RH_HIERARCHY_Unmarshal((TPMI_RH_HIERARCHY *)&(target->hierarchy), buffer, size, 1);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->digest), buffer, size);
+ return result;
+}
+
+UINT16
+TPMT_TK_HASHCHECK_Marshal(
+ TPMT_TK_HASHCHECK *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM_ST_Marshal((TPM_ST *)&(source->tag), buffer, size));
+ result = (UINT16)(result + TPMI_RH_HIERARCHY_Marshal((TPMI_RH_HIERARCHY *)&(source->hierarchy), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->digest), buffer, size));
+ return result;
+}
+
+
+// Table 2:92 - Definition of TPMS_ALG_PROPERTY Structure (StructureTable)
+// TPMS_ALG_PROPERTY_Unmarshal not referenced
+UINT16
+TPMS_ALG_PROPERTY_Marshal(
+ TPMS_ALG_PROPERTY *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM_ALG_ID_Marshal((TPM_ALG_ID *)&(source->alg), buffer, size));
+ result = (UINT16)(result + TPMA_ALGORITHM_Marshal((TPMA_ALGORITHM *)&(source->algProperties), buffer, size));
+ return result;
+}
+
+
+// Table 2:93 - Definition of TPMS_TAGGED_PROPERTY Structure (StructureTable)
+// TPMS_TAGGED_PROPERTY_Unmarshal not referenced
+UINT16
+TPMS_TAGGED_PROPERTY_Marshal(
+ TPMS_TAGGED_PROPERTY *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM_PT_Marshal((TPM_PT *)&(source->property), buffer, size));
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->value), buffer, size));
+ return result;
+}
+
+
+// Table 2:94 - Definition of TPMS_TAGGED_PCR_SELECT Structure (StructureTable)
+// TPMS_TAGGED_PCR_SELECT_Unmarshal not referenced
+UINT16
+TPMS_TAGGED_PCR_SELECT_Marshal(
+ TPMS_TAGGED_PCR_SELECT *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM_PT_Marshal((TPM_PT *)&(source->tag), buffer, size));
+ result = (UINT16)(result + UINT8_Marshal((UINT8 *)&(source->sizeofSelect), buffer, size));
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->pcrSelect), buffer, size, (INT32)(source->sizeofSelect)));
+ return result;
+}
+
+
+// Table 2:95 - Definition of TPML_CC Structure (StructureTable)
+TPM_RC
+TPML_CC_Unmarshal(
+ TPML_CC *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT32_Unmarshal((UINT32 *)&(target->count), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if((target->count) > MAX_CAP_CC)
+ return TPM_RC_SIZE;
+ result = TPM_CC_Array_Unmarshal((TPM_CC *)(target->commandCodes), buffer, size, (INT32)(target->count));
+ return result;
+}
+
+UINT16
+TPML_CC_Marshal(
+ TPML_CC *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPM_CC_Array_Marshal((TPM_CC *)(source->commandCodes), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+
+// Table 2:96 - Definition of TPML_CCA Structure (StructureTable)
+// TPML_CCA_Unmarshal not referenced
+UINT16
+TPML_CCA_Marshal(
+ TPML_CCA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPMA_CC_Array_Marshal((TPMA_CC *)(source->commandAttributes), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+
+// Table 2:97 - Definition of TPML_ALG Structure (StructureTable)
+TPM_RC
+TPML_ALG_Unmarshal(
+ TPML_ALG *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT32_Unmarshal((UINT32 *)&(target->count), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if((target->count) > MAX_ALG_LIST_SIZE)
+ return TPM_RC_SIZE;
+ result = TPM_ALG_ID_Array_Unmarshal((TPM_ALG_ID *)(target->algorithms), buffer, size, (INT32)(target->count));
+ return result;
+}
+
+UINT16
+TPML_ALG_Marshal(
+ TPML_ALG *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPM_ALG_ID_Array_Marshal((TPM_ALG_ID *)(source->algorithms), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+
+// Table 2:98 - Definition of TPML_HANDLE Structure (StructureTable)
+// TPML_HANDLE_Unmarshal not referenced
+UINT16
+TPML_HANDLE_Marshal(
+ TPML_HANDLE *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPM_HANDLE_Array_Marshal((TPM_HANDLE *)(source->handle), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+
+// Table 2:99 - Definition of TPML_DIGEST Structure (StructureTable)
+TPM_RC
+TPML_DIGEST_Unmarshal(
+ TPML_DIGEST *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT32_Unmarshal((UINT32 *)&(target->count), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if( (target->count < 2))
+ return TPM_RC_SIZE;
+ if((target->count) > 8)
+ return TPM_RC_SIZE;
+ result = TPM2B_DIGEST_Array_Unmarshal((TPM2B_DIGEST *)(target->digests), buffer, size, (INT32)(target->count));
+ return result;
+}
+
+UINT16
+TPML_DIGEST_Marshal(
+ TPML_DIGEST *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Array_Marshal((TPM2B_DIGEST *)(source->digests), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+
+// Table 2:100 - Definition of TPML_DIGEST_VALUES Structure (StructureTable)
+TPM_RC
+TPML_DIGEST_VALUES_Unmarshal(
+ TPML_DIGEST_VALUES *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT32_Unmarshal((UINT32 *)&(target->count), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if((target->count) > HASH_COUNT)
+ return TPM_RC_SIZE;
+ result = TPMT_HA_Array_Unmarshal((TPMT_HA *)(target->digests), buffer, size, 0, (INT32)(target->count));
+ return result;
+}
+
+UINT16
+TPML_DIGEST_VALUES_Marshal(
+ TPML_DIGEST_VALUES *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPMT_HA_Array_Marshal((TPMT_HA *)(source->digests), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+
+// Table 2:101 - Definition of TPM2B_DIGEST_VALUES Structure (StructureTable)
+// TPM2B_DIGEST_VALUES_Unmarshal not referenced
+// TPM2B_DIGEST_VALUES_Marshal not referenced
+
+
+// Table 2:102 - Definition of TPML_PCR_SELECTION Structure (StructureTable)
+TPM_RC
+TPML_PCR_SELECTION_Unmarshal(
+ TPML_PCR_SELECTION *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT32_Unmarshal((UINT32 *)&(target->count), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if((target->count) > HASH_COUNT)
+ return TPM_RC_SIZE;
+ result = TPMS_PCR_SELECTION_Array_Unmarshal((TPMS_PCR_SELECTION *)(target->pcrSelections), buffer, size, (INT32)(target->count));
+ return result;
+}
+
+UINT16
+TPML_PCR_SELECTION_Marshal(
+ TPML_PCR_SELECTION *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPMS_PCR_SELECTION_Array_Marshal((TPMS_PCR_SELECTION *)(source->pcrSelections), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+
+// Table 2:103 - Definition of TPML_ALG_PROPERTY Structure (StructureTable)
+// TPML_ALG_PROPERTY_Unmarshal not referenced
+UINT16
+TPML_ALG_PROPERTY_Marshal(
+ TPML_ALG_PROPERTY *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPMS_ALG_PROPERTY_Array_Marshal((TPMS_ALG_PROPERTY *)(source->algProperties), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+
+// Table 2:104 - Definition of TPML_TAGGED_TPM_PROPERTY Structure (StructureTable)
+// TPML_TAGGED_TPM_PROPERTY_Unmarshal not referenced
+UINT16
+TPML_TAGGED_TPM_PROPERTY_Marshal(
+ TPML_TAGGED_TPM_PROPERTY *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPMS_TAGGED_PROPERTY_Array_Marshal((TPMS_TAGGED_PROPERTY *)(source->tpmProperty), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+
+// Table 2:105 - Definition of TPML_TAGGED_PCR_PROPERTY Structure (StructureTable)
+// TPML_TAGGED_PCR_PROPERTY_Unmarshal not referenced
+UINT16
+TPML_TAGGED_PCR_PROPERTY_Marshal(
+ TPML_TAGGED_PCR_PROPERTY *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPMS_TAGGED_PCR_SELECT_Array_Marshal((TPMS_TAGGED_PCR_SELECT *)(source->pcrProperty), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+
+// Table 2:106 - Definition of TPML_ECC_CURVE Structure (StructureTable)
+#ifdef TPM_ALG_ECC
+// TPML_ECC_CURVE_Unmarshal not referenced
+UINT16
+TPML_ECC_CURVE_Marshal(
+ TPML_ECC_CURVE *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + TPM_ECC_CURVE_Array_Marshal((TPM_ECC_CURVE *)(source->eccCurves), buffer, size, (INT32)(source->count)));
+ return result;
+}
+
+#endif // TPM_ALG_ECC
+
+#ifdef ME11_SIM
+UINT16
+INTEL_PROP_VALUE_Marshal(INTEL_PROP_VALUE *source, BYTE **buffer, INT32 *size)
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)source, buffer, size));
+ return result;
+}
+
+UINT16
+INTEL_PROPERTY_Marshal(INTEL_PROPERTY *source, BYTE **buffer, INT32 *size)
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size));
+ result = (UINT16)(result + INTEL_PROP_VALUE_Marshal(&(source->property), buffer, size));
+
+ return result;
+}
+#endif
+
+// Table 2:107 - Definition of TPMU_CAPABILITIES Union (UnionTable)
+// TPMU_CAPABILITIES_Unmarshal not referenced
+UINT16
+TPMU_CAPABILITIES_Marshal(
+ TPMU_CAPABILITIES *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+ case TPM_CAP_ALGS:
+ return TPML_ALG_PROPERTY_Marshal((TPML_ALG_PROPERTY *)&(source->algorithms), buffer, size);
+ case TPM_CAP_HANDLES:
+ return TPML_HANDLE_Marshal((TPML_HANDLE *)&(source->handles), buffer, size);
+ case TPM_CAP_COMMANDS:
+ return TPML_CCA_Marshal((TPML_CCA *)&(source->command), buffer, size);
+ case TPM_CAP_PP_COMMANDS:
+ return TPML_CC_Marshal((TPML_CC *)&(source->ppCommands), buffer, size);
+ case TPM_CAP_AUDIT_COMMANDS:
+ return TPML_CC_Marshal((TPML_CC *)&(source->auditCommands), buffer, size);
+ case TPM_CAP_PCRS:
+ return TPML_PCR_SELECTION_Marshal((TPML_PCR_SELECTION *)&(source->assignedPCR), buffer, size);
+ case TPM_CAP_TPM_PROPERTIES:
+ return TPML_TAGGED_TPM_PROPERTY_Marshal((TPML_TAGGED_TPM_PROPERTY *)&(source->tpmProperties), buffer, size);
+ case TPM_CAP_PCR_PROPERTIES:
+ return TPML_TAGGED_PCR_PROPERTY_Marshal((TPML_TAGGED_PCR_PROPERTY *)&(source->pcrProperties), buffer, size);
+#ifdef TPM_ALG_ECC
+ case TPM_CAP_ECC_CURVES:
+ return TPML_ECC_CURVE_Marshal((TPML_ECC_CURVE *)&(source->eccCurves), buffer, size);
+#endif // TPM_ALG_ECC
+#ifdef ME11_SIM
+ case TPM_CAP_VENDOR_PROPERTY:
+ return INTEL_PROPERTY_Marshal((INTEL_PROPERTY *)&(source->intelProperty), buffer, size);
+#endif
+ }
+ return 0;
+}
+
+
+// Table 2:108 - Definition of TPMS_CAPABILITY_DATA Structure (StructureTable)
+// TPMS_CAPABILITY_DATA_Unmarshal not referenced
+UINT16
+TPMS_CAPABILITY_DATA_Marshal(
+ TPMS_CAPABILITY_DATA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM_CAP_Marshal((TPM_CAP *)&(source->capability), buffer, size));
+ result = (UINT16)(result + TPMU_CAPABILITIES_Marshal((TPMU_CAPABILITIES *)&(source->data), buffer, size, (UINT32)source->capability));
+ return result;
+}
+
+
+// Table 2:109 - Definition of TPMS_CLOCK_INFO Structure (StructureTable)
+// TPMS_CLOCK_INFO_Unmarshal not referenced
+UINT16
+TPMS_CLOCK_INFO_Marshal(
+ TPMS_CLOCK_INFO *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->clock), buffer, size));
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->resetCount), buffer, size));
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->restartCount), buffer, size));
+ result = (UINT16)(result + TPMI_YES_NO_Marshal((TPMI_YES_NO *)&(source->safe), buffer, size));
+ return result;
+}
+
+
+// Table 2:110 - Definition of TPMS_TIME_INFO Structure (StructureTable)
+// TPMS_TIME_INFO_Unmarshal not referenced
+UINT16
+TPMS_TIME_INFO_Marshal(
+ TPMS_TIME_INFO *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->time), buffer, size));
+ result = (UINT16)(result + TPMS_CLOCK_INFO_Marshal((TPMS_CLOCK_INFO *)&(source->clockInfo), buffer, size));
+ return result;
+}
+
+
+// Table 2:111 - Definition of TPMS_TIME_ATTEST_INFO Structure (StructureTable)
+// TPMS_TIME_ATTEST_INFO_Unmarshal not referenced
+UINT16
+TPMS_TIME_ATTEST_INFO_Marshal(
+ TPMS_TIME_ATTEST_INFO *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMS_TIME_INFO_Marshal((TPMS_TIME_INFO *)&(source->time), buffer, size));
+ result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->firmwareVersion), buffer, size));
+ return result;
+}
+
+
+// Table 2:112 - Definition of TPMS_CERTIFY_INFO Structure (StructureTable)
+// TPMS_CERTIFY_INFO_Unmarshal not referenced
+UINT16
+TPMS_CERTIFY_INFO_Marshal(
+ TPMS_CERTIFY_INFO *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->name), buffer, size));
+ result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->qualifiedName), buffer, size));
+ return result;
+}
+
+
+// Table 2:113 - Definition of TPMS_QUOTE_INFO Structure (StructureTable)
+// TPMS_QUOTE_INFO_Unmarshal not referenced
+UINT16
+TPMS_QUOTE_INFO_Marshal(
+ TPMS_QUOTE_INFO *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPML_PCR_SELECTION_Marshal((TPML_PCR_SELECTION *)&(source->pcrSelect), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->pcrDigest), buffer, size));
+ return result;
+}
+
+
+// Table 2:114 - Definition of TPMS_COMMAND_AUDIT_INFO Structure (StructureTable)
+// TPMS_COMMAND_AUDIT_INFO_Unmarshal not referenced
+UINT16
+TPMS_COMMAND_AUDIT_INFO_Marshal(
+ TPMS_COMMAND_AUDIT_INFO *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->auditCounter), buffer, size));
+ result = (UINT16)(result + TPM_ALG_ID_Marshal((TPM_ALG_ID *)&(source->digestAlg), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->auditDigest), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->commandDigest), buffer, size));
+ return result;
+}
+
+
+// Table 2:115 - Definition of TPMS_SESSION_AUDIT_INFO Structure (StructureTable)
+// TPMS_SESSION_AUDIT_INFO_Unmarshal not referenced
+UINT16
+TPMS_SESSION_AUDIT_INFO_Marshal(
+ TPMS_SESSION_AUDIT_INFO *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_YES_NO_Marshal((TPMI_YES_NO *)&(source->exclusiveSession), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->sessionDigest), buffer, size));
+ return result;
+}
+
+
+// Table 2:116 - Definition of TPMS_CREATION_INFO Structure (StructureTable)
+// TPMS_CREATION_INFO_Unmarshal not referenced
+UINT16
+TPMS_CREATION_INFO_Marshal(
+ TPMS_CREATION_INFO *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->objectName), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->creationHash), buffer, size));
+ return result;
+}
+
+
+// Table 2:117 - Definition of TPMS_NV_CERTIFY_INFO Structure (StructureTable)
+// TPMS_NV_CERTIFY_INFO_Unmarshal not referenced
+UINT16
+TPMS_NV_CERTIFY_INFO_Marshal(
+ TPMS_NV_CERTIFY_INFO *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->indexName), buffer, size));
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->offset), buffer, size));
+ result = (UINT16)(result + TPM2B_MAX_NV_BUFFER_Marshal((TPM2B_MAX_NV_BUFFER *)&(source->nvContents), buffer, size));
+ return result;
+}
+
+
+// Table 2:118 - Definition of TPMI_ST_ATTEST Type (TypeTable)
+// TPMI_ST_ATTEST_Unmarshal not referenced
+// TPMI_ST_ATTEST_Marshal changed to #define
+
+
+// Table 2:119 - Definition of TPMU_ATTEST Union (UnionTable)
+// TPMU_ATTEST_Unmarshal not referenced
+UINT16
+TPMU_ATTEST_Marshal(
+ TPMU_ATTEST *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+ case TPM_ST_ATTEST_CERTIFY:
+ return TPMS_CERTIFY_INFO_Marshal((TPMS_CERTIFY_INFO *)&(source->certify), buffer, size);
+ case TPM_ST_ATTEST_CREATION:
+ return TPMS_CREATION_INFO_Marshal((TPMS_CREATION_INFO *)&(source->creation), buffer, size);
+ case TPM_ST_ATTEST_QUOTE:
+ return TPMS_QUOTE_INFO_Marshal((TPMS_QUOTE_INFO *)&(source->quote), buffer, size);
+ case TPM_ST_ATTEST_COMMAND_AUDIT:
+ return TPMS_COMMAND_AUDIT_INFO_Marshal((TPMS_COMMAND_AUDIT_INFO *)&(source->commandAudit), buffer, size);
+ case TPM_ST_ATTEST_SESSION_AUDIT:
+ return TPMS_SESSION_AUDIT_INFO_Marshal((TPMS_SESSION_AUDIT_INFO *)&(source->sessionAudit), buffer, size);
+ case TPM_ST_ATTEST_TIME:
+ return TPMS_TIME_ATTEST_INFO_Marshal((TPMS_TIME_ATTEST_INFO *)&(source->time), buffer, size);
+ case TPM_ST_ATTEST_NV:
+ return TPMS_NV_CERTIFY_INFO_Marshal((TPMS_NV_CERTIFY_INFO *)&(source->nv), buffer, size);
+ }
+ return 0;
+}
+
+
+// Table 2:120 - Definition of TPMS_ATTEST Structure (StructureTable)
+// TPMS_ATTEST_Unmarshal not referenced
+UINT16
+TPMS_ATTEST_Marshal(
+ TPMS_ATTEST *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM_GENERATED_Marshal((TPM_GENERATED *)&(source->magic), buffer, size));
+ result = (UINT16)(result + TPMI_ST_ATTEST_Marshal((TPMI_ST_ATTEST *)&(source->type), buffer, size));
+ result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->qualifiedSigner), buffer, size));
+ result = (UINT16)(result + TPM2B_DATA_Marshal((TPM2B_DATA *)&(source->extraData), buffer, size));
+ result = (UINT16)(result + TPMS_CLOCK_INFO_Marshal((TPMS_CLOCK_INFO *)&(source->clockInfo), buffer, size));
+ result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->firmwareVersion), buffer, size));
+ result = (UINT16)(result + TPMU_ATTEST_Marshal((TPMU_ATTEST *)&(source->attested), buffer, size, (UINT32)source->type));
+ return result;
+}
+
+
+// Table 2:121 - Definition of TPM2B_ATTEST Structure (StructureTable)
+// TPM2B_ATTEST_Unmarshal not referenced
+UINT16
+TPM2B_ATTEST_Marshal(
+ TPM2B_ATTEST *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.attestationData), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:122 - Definition of TPMS_AUTH_COMMAND Structure (StructureTable)
+// TPMS_AUTH_COMMAND_Unmarshal not referenced
+// TPMS_AUTH_COMMAND_Marshal not referenced
+
+
+// Table 2:123 - Definition of TPMS_AUTH_RESPONSE Structure (StructureTable)
+// TPMS_AUTH_RESPONSE_Unmarshal not referenced
+// TPMS_AUTH_RESPONSE_Marshal not referenced
+
+
+// Table 2:124 - Definition of TPMI_AES_KEY_BITS Type (TypeTable)
+#ifdef TPM_ALG_AES
+TPM_RC
+TPMI_AES_KEY_BITS_Unmarshal(
+ TPMI_AES_KEY_BITS *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_KEY_BITS_Unmarshal((TPM_KEY_BITS *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case 128:
+ case 256:
+ break;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_AES_KEY_BITS_Marshal changed to #define
+#endif // TPM_ALG_AES
+
+
+// Table 2:124 - Definition of TPMI_SM4_KEY_BITS Type (TypeTable)
+#ifdef TPM_ALG_SM4
+TPM_RC
+TPMI_SM4_KEY_BITS_Unmarshal(
+ TPMI_SM4_KEY_BITS *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_KEY_BITS_Unmarshal((TPM_KEY_BITS *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case 128:
+ break;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_SM4_KEY_BITS_Marshal changed to #define
+#endif // TPM_ALG_SM4
+
+
+// Table 2:124 - Definition of TPMI_CAMELLIA_KEY_BITS Type (TypeTable)
+#ifdef TPM_ALG_CAMELLIA
+TPM_RC
+TPMI_CAMELLIA_KEY_BITS_Unmarshal(
+ TPMI_CAMELLIA_KEY_BITS *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_KEY_BITS_Unmarshal((TPM_KEY_BITS *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case 128:
+ break;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_CAMELLIA_KEY_BITS_Marshal changed to #define
+#endif // TPM_ALG_CAMELLIA
+
+
+// Table 2:125 - Definition of TPMU_SYM_KEY_BITS Union (UnionTable)
+TPM_RC
+TPMU_SYM_KEY_BITS_Unmarshal(
+ TPMU_SYM_KEY_BITS *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_AES
+ case TPM_ALG_AES:
+ return TPMI_AES_KEY_BITS_Unmarshal((TPMI_AES_KEY_BITS *)&(target->aes), buffer, size);
+#endif // TPM_ALG_AES
+#ifdef TPM_ALG_SM4
+ case TPM_ALG_SM4:
+ return TPMI_SM4_KEY_BITS_Unmarshal((TPMI_SM4_KEY_BITS *)&(target->sm4), buffer, size);
+#endif // TPM_ALG_SM4
+#ifdef TPM_ALG_CAMELLIA
+ case TPM_ALG_CAMELLIA:
+ return TPMI_CAMELLIA_KEY_BITS_Unmarshal((TPMI_CAMELLIA_KEY_BITS *)&(target->camellia), buffer, size);
+#endif // TPM_ALG_CAMELLIA
+#ifdef TPM_ALG_XOR
+ case TPM_ALG_XOR:
+ return TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->exclusiveOr
+ ), buffer, size, 0);
+#endif // TPM_ALG_XOR
+ case TPM_ALG_NULL:
+ return TPM_RC_SUCCESS;
+ }
+ return TPM_RC_SELECTOR;
+}
+
+UINT16
+TPMU_SYM_KEY_BITS_Marshal(
+ TPMU_SYM_KEY_BITS *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_AES
+ case TPM_ALG_AES:
+ return TPMI_AES_KEY_BITS_Marshal((TPMI_AES_KEY_BITS *)&(source->aes), buffer, size);
+#endif // TPM_ALG_AES
+#ifdef TPM_ALG_SM4
+ case TPM_ALG_SM4:
+ return TPMI_SM4_KEY_BITS_Marshal((TPMI_SM4_KEY_BITS *)&(source->sm4), buffer, size);
+#endif // TPM_ALG_SM4
+#ifdef TPM_ALG_CAMELLIA
+ case TPM_ALG_CAMELLIA:
+ return TPMI_CAMELLIA_KEY_BITS_Marshal((TPMI_CAMELLIA_KEY_BITS *)&(source->camellia), buffer, size);
+#endif // TPM_ALG_CAMELLIA
+#ifdef TPM_ALG_XOR
+ case TPM_ALG_XOR:
+ return TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->exclusiveOr
+ ), buffer, size);
+#endif // TPM_ALG_XOR
+ case TPM_ALG_NULL:
+ return 0;
+ }
+ return 0;
+}
+
+
+// Table 2:126 - Definition of TPMU_SYM_MODE Union (UnionTable)
+TPM_RC
+TPMU_SYM_MODE_Unmarshal(
+ TPMU_SYM_MODE *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_AES
+ case TPM_ALG_AES:
+ return TPMI_ALG_SYM_MODE_Unmarshal((TPMI_ALG_SYM_MODE *)&(target->aes), buffer, size, 1);
+#endif // TPM_ALG_AES
+#ifdef TPM_ALG_SM4
+ case TPM_ALG_SM4:
+ return TPMI_ALG_SYM_MODE_Unmarshal((TPMI_ALG_SYM_MODE *)&(target->sm4), buffer, size, 1);
+#endif // TPM_ALG_SM4
+#ifdef TPM_ALG_CAMELLIA
+ case TPM_ALG_CAMELLIA:
+ return TPMI_ALG_SYM_MODE_Unmarshal((TPMI_ALG_SYM_MODE *)&(target->camellia), buffer, size, 1);
+#endif // TPM_ALG_CAMELLIA
+#ifdef TPM_ALG_XOR
+ case TPM_ALG_XOR:
+ return TPM_RC_SUCCESS;
+#endif // TPM_ALG_XOR
+ case TPM_ALG_NULL:
+ return TPM_RC_SUCCESS;
+ }
+ return TPM_RC_SELECTOR;
+}
+
+UINT16
+TPMU_SYM_MODE_Marshal(
+ TPMU_SYM_MODE *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_AES
+ case TPM_ALG_AES:
+ return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE *)&(source->aes), buffer, size);
+#endif // TPM_ALG_AES
+#ifdef TPM_ALG_SM4
+ case TPM_ALG_SM4:
+ return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE *)&(source->sm4), buffer, size);
+#endif // TPM_ALG_SM4
+#ifdef TPM_ALG_CAMELLIA
+ case TPM_ALG_CAMELLIA:
+ return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE *)&(source->camellia), buffer, size);
+#endif // TPM_ALG_CAMELLIA
+#ifdef TPM_ALG_XOR
+ case TPM_ALG_XOR:
+ return 0;
+#endif // TPM_ALG_XOR
+ case TPM_ALG_NULL:
+ return 0;
+ }
+ return 0;
+}
+
+
+// Table 2:128 - Definition of TPMT_SYM_DEF Structure (StructureTable)
+TPM_RC
+TPMT_SYM_DEF_Unmarshal(
+ TPMT_SYM_DEF *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_SYM_Unmarshal((TPMI_ALG_SYM *)&(target->algorithm), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_SYM_KEY_BITS_Unmarshal((TPMU_SYM_KEY_BITS *)&(target->keyBits), buffer, size, (UINT32)target->algorithm);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_SYM_MODE_Unmarshal((TPMU_SYM_MODE *)&(target->mode), buffer, size, (UINT32)target->algorithm);
+ return result;
+}
+
+// TPMT_SYM_DEF_Marshal not referenced
+
+
+// Table 2:129 - Definition of TPMT_SYM_DEF_OBJECT Structure (StructureTable)
+TPM_RC
+TPMT_SYM_DEF_OBJECT_Unmarshal(
+ TPMT_SYM_DEF_OBJECT *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_SYM_OBJECT_Unmarshal((TPMI_ALG_SYM_OBJECT *)&(target->algorithm), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_SYM_KEY_BITS_Unmarshal((TPMU_SYM_KEY_BITS *)&(target->keyBits), buffer, size, (UINT32)target->algorithm);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_SYM_MODE_Unmarshal((TPMU_SYM_MODE *)&(target->mode), buffer, size, (UINT32)target->algorithm);
+ return result;
+}
+
+UINT16
+TPMT_SYM_DEF_OBJECT_Marshal(
+ TPMT_SYM_DEF_OBJECT *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_SYM_OBJECT_Marshal((TPMI_ALG_SYM_OBJECT *)&(source->algorithm), buffer, size));
+ result = (UINT16)(result + TPMU_SYM_KEY_BITS_Marshal((TPMU_SYM_KEY_BITS *)&(source->keyBits), buffer, size, (UINT32)source->algorithm));
+ result = (UINT16)(result + TPMU_SYM_MODE_Marshal((TPMU_SYM_MODE *)&(source->mode), buffer, size, (UINT32)source->algorithm));
+ return result;
+}
+
+
+// Table 2:130 - Definition of TPM2B_SYM_KEY Structure (StructureTable)
+TPM_RC
+TPM2B_SYM_KEY_Unmarshal(
+ TPM2B_SYM_KEY *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > MAX_SYM_KEY_BYTES)
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_SYM_KEY_Marshal(
+ TPM2B_SYM_KEY *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:131 - Definition of TPMS_SYMCIPHER_PARMS Structure (StructureTable)
+// TPMS_SYMCIPHER_PARMS_Unmarshal changed to #define
+// TPMS_SYMCIPHER_PARMS_Marshal changed to #define
+
+
+// Table 2:132 - Definition of TPM2B_SENSITIVE_DATA Structure (StructureTable)
+TPM_RC
+TPM2B_SENSITIVE_DATA_Unmarshal(
+ TPM2B_SENSITIVE_DATA *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > MAX_SYM_DATA)
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_SENSITIVE_DATA_Marshal(
+ TPM2B_SENSITIVE_DATA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:133 - Definition of TPMS_SENSITIVE_CREATE Structure (StructureTable)
+TPM_RC
+TPMS_SENSITIVE_CREATE_Unmarshal(
+ TPMS_SENSITIVE_CREATE *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM2B_AUTH_Unmarshal((TPM2B_AUTH *)&(target->userAuth), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_SENSITIVE_DATA_Unmarshal((TPM2B_SENSITIVE_DATA *)&(target->data), buffer, size);
+ return result;
+}
+
+// TPMS_SENSITIVE_CREATE_Marshal not referenced
+
+
+// Table 2:134 - Definition of TPM2B_SENSITIVE_CREATE Structure (StructureTable)
+TPM_RC
+TPM2B_SENSITIVE_CREATE_Unmarshal(
+ TPM2B_SENSITIVE_CREATE *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ INT32 startSize;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size is zero, then the required structure is missing
+ if(target->t.size == 0)
+ return TPM_RC_SIZE;
+ startSize = *size;
+ result = TPMS_SENSITIVE_CREATE_Unmarshal((TPMS_SENSITIVE_CREATE *)&(target->t.sensitive), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if(target->t.size != (startSize - *size)) return TPM_RC_SIZE;
+ return TPM_RC_SUCCESS;
+}
+
+// TPM2B_SENSITIVE_CREATE_Marshal not referenced
+
+
+// Table 2:135 - Definition of TPMS_SCHEME_HASH Structure (StructureTable)
+// TPMS_SCHEME_HASH_Unmarshal changed to #define
+// TPMS_SCHEME_HASH_Marshal changed to #define
+
+
+// Table 2:136 - Definition of TPMS_SCHEME_ECDAA Structure (StructureTable)
+#ifdef TPM_ALG_ECC
+TPM_RC
+TPMS_SCHEME_ECDAA_Unmarshal(
+ TPMS_SCHEME_ECDAA *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hashAlg), buffer, size, 0);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->count), buffer, size);
+ return result;
+}
+
+UINT16
+TPMS_SCHEME_ECDAA_Marshal(
+ TPMS_SCHEME_ECDAA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hashAlg), buffer, size));
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->count), buffer, size));
+ return result;
+}
+
+#endif // TPM_ALG_ECC
+
+
+// Table 2:137 - Definition of TPMI_ALG_KEYEDHASH_SCHEME Type (TypeTable)
+TPM_RC
+TPMI_ALG_KEYEDHASH_SCHEME_Unmarshal(
+ TPMI_ALG_KEYEDHASH_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_HMAC
+ case TPM_ALG_HMAC:
+#endif // TPM_ALG_HMAC
+#ifdef TPM_ALG_XOR
+ case TPM_ALG_XOR:
+#endif // TPM_ALG_XOR
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_VALUE;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_KEYEDHASH_SCHEME_Marshal changed to #define
+
+
+// Table 2:138 - Definition of Types for HMAC_SIG_SCHEME (TypesTable)
+// TPMS_SCHEME_HASH definition from table 2:138
+// TPMS_SCHEME_HMAC_Unmarshal changed to #define
+// TPMS_SCHEME_HMAC_Marshal changed to #define
+
+
+// Table 2:139 - Definition of TPMS_SCHEME_XOR Structure (StructureTable)
+TPM_RC
+TPMS_SCHEME_XOR_Unmarshal(
+ TPMS_SCHEME_XOR *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hashAlg), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMI_ALG_KDF_Unmarshal((TPMI_ALG_KDF *)&(target->kdf), buffer, size, 1);
+ return result;
+}
+
+UINT16
+TPMS_SCHEME_XOR_Marshal(
+ TPMS_SCHEME_XOR *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hashAlg), buffer, size));
+ result = (UINT16)(result + TPMI_ALG_KDF_Marshal((TPMI_ALG_KDF *)&(source->kdf), buffer, size));
+ return result;
+}
+
+
+// Table 2:140 - Definition of TPMU_SCHEME_KEYEDHASH Union (UnionTable)
+TPM_RC
+TPMU_SCHEME_KEYEDHASH_Unmarshal(
+ TPMU_SCHEME_KEYEDHASH *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_HMAC
+ case TPM_ALG_HMAC:
+ return TPMS_SCHEME_HMAC_Unmarshal((TPMS_SCHEME_HMAC *)&(target->hmac), buffer, size);
+#endif // TPM_ALG_HMAC
+#ifdef TPM_ALG_XOR
+ case TPM_ALG_XOR:
+ return TPMS_SCHEME_XOR_Unmarshal((TPMS_SCHEME_XOR *)&(target->exclusiveOr
+ ), buffer, size, 1);
+#endif // TPM_ALG_XOR
+ case TPM_ALG_NULL:
+ return TPM_RC_SUCCESS;
+ }
+ return TPM_RC_SELECTOR;
+}
+
+UINT16
+TPMU_SCHEME_KEYEDHASH_Marshal(
+ TPMU_SCHEME_KEYEDHASH *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_HMAC
+ case TPM_ALG_HMAC:
+ return TPMS_SCHEME_HMAC_Marshal((TPMS_SCHEME_HMAC *)&(source->hmac), buffer, size);
+#endif // TPM_ALG_HMAC
+#ifdef TPM_ALG_XOR
+ case TPM_ALG_XOR:
+ return TPMS_SCHEME_XOR_Marshal((TPMS_SCHEME_XOR *)&(source->exclusiveOr
+ ), buffer, size);
+#endif // TPM_ALG_XOR
+ case TPM_ALG_NULL:
+ return 0;
+ }
+ return 0;
+}
+
+
+// Table 2:141 - Definition of TPMT_KEYEDHASH_SCHEME Structure (StructureTable)
+TPM_RC
+TPMT_KEYEDHASH_SCHEME_Unmarshal(
+ TPMT_KEYEDHASH_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_KEYEDHASH_SCHEME_Unmarshal((TPMI_ALG_KEYEDHASH_SCHEME *)&(target->scheme), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_SCHEME_KEYEDHASH_Unmarshal((TPMU_SCHEME_KEYEDHASH *)&(target->details), buffer, size, (UINT32)target->scheme);
+ return result;
+}
+
+UINT16
+TPMT_KEYEDHASH_SCHEME_Marshal(
+ TPMT_KEYEDHASH_SCHEME *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_KEYEDHASH_SCHEME_Marshal((TPMI_ALG_KEYEDHASH_SCHEME *)&(source->scheme), buffer, size));
+ result = (UINT16)(result + TPMU_SCHEME_KEYEDHASH_Marshal((TPMU_SCHEME_KEYEDHASH *)&(source->details), buffer, size, (UINT32)source->scheme));
+ return result;
+}
+
+
+// Table 2:142 - Definition of Types for RSA Signature Schemes (TypesTable)
+#ifdef TPM_ALG_RSA
+// TPMS_SCHEME_HASH definition from table 2:142
+#ifdef TPM_ALG_RSA
+// TPMS_SIG_SCHEME_RSASSA_Unmarshal changed to #define
+// TPMS_SIG_SCHEME_RSASSA_Marshal changed to #define
+#endif // TPM_ALG_RSA
+// TPMS_SCHEME_HASH definition from table 2:142
+#ifdef TPM_ALG_RSA
+// TPMS_SIG_SCHEME_RSAPSS_Unmarshal changed to #define
+// TPMS_SIG_SCHEME_RSAPSS_Marshal changed to #define
+#endif // TPM_ALG_RSA
+#endif // TPM_ALG_RSA
+
+
+// Table 2:143 - Definition of Types for ECC Signature Schemes (TypesTable)
+#ifdef TPM_ALG_ECC
+// TPMS_SCHEME_HASH definition from table 2:143
+#ifdef TPM_ALG_ECC
+// TPMS_SIG_SCHEME_ECDSA_Unmarshal changed to #define
+// TPMS_SIG_SCHEME_ECDSA_Marshal changed to #define
+#endif // TPM_ALG_ECC
+// TPMS_SCHEME_HASH definition from table 2:143
+#ifdef TPM_ALG_ECC
+// TPMS_SIG_SCHEME_SM2_Unmarshal changed to #define
+// TPMS_SIG_SCHEME_SM2_Marshal changed to #define
+#endif // TPM_ALG_ECC
+// TPMS_SCHEME_HASH definition from table 2:143
+#ifdef TPM_ALG_ECC
+// TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal changed to #define
+// TPMS_SIG_SCHEME_ECSCHNORR_Marshal changed to #define
+#endif // TPM_ALG_ECC
+// TPMS_SCHEME_ECDAA definition from table 2:143
+#ifdef TPM_ALG_ECC
+// TPMS_SIG_SCHEME_ECDAA_Unmarshal changed to #define
+// TPMS_SIG_SCHEME_ECDAA_Marshal changed to #define
+#endif // TPM_ALG_ECC
+#endif // TPM_ALG_ECC
+
+
+// Table 2:144 - Definition of TPMU_SIG_SCHEME Union (UnionTable)
+TPM_RC
+TPMU_SIG_SCHEME_Unmarshal(
+ TPMU_SIG_SCHEME *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_RSASSA
+ case TPM_ALG_RSASSA:
+ return TPMS_SIG_SCHEME_RSASSA_Unmarshal((TPMS_SIG_SCHEME_RSASSA *)&(target->rsassa), buffer, size);
+#endif // TPM_ALG_RSASSA
+#ifdef TPM_ALG_RSAPSS
+ case TPM_ALG_RSAPSS:
+ return TPMS_SIG_SCHEME_RSAPSS_Unmarshal((TPMS_SIG_SCHEME_RSAPSS *)&(target->rsapss), buffer, size);
+#endif // TPM_ALG_RSAPSS
+#ifdef TPM_ALG_ECDSA
+ case TPM_ALG_ECDSA:
+ return TPMS_SIG_SCHEME_ECDSA_Unmarshal((TPMS_SIG_SCHEME_ECDSA *)&(target->ecdsa), buffer, size);
+#endif // TPM_ALG_ECDSA
+#ifdef TPM_ALG_SM2
+ case TPM_ALG_SM2:
+ return TPMS_SIG_SCHEME_SM2_Unmarshal((TPMS_SIG_SCHEME_SM2 *)&(target->sm2), buffer, size);
+#endif // TPM_ALG_SM2
+#ifdef TPM_ALG_ECSCHNORR
+ case TPM_ALG_ECSCHNORR:
+ return TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal((TPMS_SIG_SCHEME_ECSCHNORR *)&(target->ecschnorr), buffer, size);
+#endif // TPM_ALG_ECSCHNORR
+#ifdef TPM_ALG_ECDAA
+ case TPM_ALG_ECDAA:
+ return TPMS_SIG_SCHEME_ECDAA_Unmarshal((TPMS_SIG_SCHEME_ECDAA *)&(target->ecdaa), buffer, size);
+#endif // TPM_ALG_ECDAA
+#ifdef TPM_ALG_HMAC
+ case TPM_ALG_HMAC:
+ return TPMS_SCHEME_HMAC_Unmarshal((TPMS_SCHEME_HMAC *)&(target->hmac), buffer, size);
+#endif // TPM_ALG_HMAC
+ case TPM_ALG_NULL:
+ return TPM_RC_SUCCESS;
+ }
+ return TPM_RC_SELECTOR;
+}
+
+// TPMU_SIG_SCHEME_Marshal not referenced
+
+
+// Table 2:145 - Definition of TPMT_SIG_SCHEME Structure (StructureTable)
+TPM_RC
+TPMT_SIG_SCHEME_Unmarshal(
+ TPMT_SIG_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_SIG_SCHEME_Unmarshal((TPMI_ALG_SIG_SCHEME *)&(target->scheme), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_SIG_SCHEME_Unmarshal((TPMU_SIG_SCHEME *)&(target->details), buffer, size, (UINT32)target->scheme);
+ return result;
+}
+
+// TPMT_SIG_SCHEME_Marshal not referenced
+
+
+// Table 2:146 - Definition of Types for Encryption Schemes (TypesTable)
+#ifdef TPM_ALG_RSA
+// TPMS_SCHEME_HASH definition from table 2:146
+#ifdef TPM_ALG_RSA
+// TPMS_ENC_SCHEME_OAEP_Unmarshal changed to #define
+// TPMS_ENC_SCHEME_OAEP_Marshal changed to #define
+#endif // TPM_ALG_RSA
+// TPMS_EMPTY definition from table 2:146
+#ifdef TPM_ALG_RSA
+// TPMS_ENC_SCHEME_RSAES_Unmarshal changed to #define
+// TPMS_ENC_SCHEME_RSAES_Marshal changed to #define
+#endif // TPM_ALG_RSA
+#endif // TPM_ALG_RSA
+
+
+// Table 2:147 - Definition of Types for ECC Key Exchange (TypesTable)
+#ifdef TPM_ALG_ECC
+// TPMS_SCHEME_HASH definition from table 2:147
+#ifdef TPM_ALG_ECC
+// TPMS_KEY_SCHEME_ECDH_Unmarshal changed to #define
+// TPMS_KEY_SCHEME_ECDH_Marshal changed to #define
+#endif // TPM_ALG_ECC
+// TPMS_SCHEME_HASH definition from table 2:147
+#ifdef TPM_ALG_ECC
+// TPMS_KEY_SCHEME_ECMQV_Unmarshal changed to #define
+// TPMS_KEY_SCHEME_ECMQV_Marshal changed to #define
+#endif // TPM_ALG_ECC
+#endif // TPM_ALG_ECC
+
+
+// Table 2:148 - Definition of Types for KDF Schemes (TypesTable)
+// TPMS_SCHEME_HASH definition from table 2:148
+// TPMS_SCHEME_MGF1_Unmarshal changed to #define
+// TPMS_SCHEME_MGF1_Marshal changed to #define
+// TPMS_SCHEME_HASH definition from table 2:148
+// TPMS_SCHEME_KDF1_SP800_56A_Unmarshal changed to #define
+// TPMS_SCHEME_KDF1_SP800_56A_Marshal changed to #define
+// TPMS_SCHEME_HASH definition from table 2:148
+// TPMS_SCHEME_KDF2_Unmarshal changed to #define
+// TPMS_SCHEME_KDF2_Marshal changed to #define
+// TPMS_SCHEME_HASH definition from table 2:148
+// TPMS_SCHEME_KDF1_SP800_108_Unmarshal changed to #define
+// TPMS_SCHEME_KDF1_SP800_108_Marshal changed to #define
+
+
+// Table 2:149 - Definition of TPMU_KDF_SCHEME Union (UnionTable)
+TPM_RC
+TPMU_KDF_SCHEME_Unmarshal(
+ TPMU_KDF_SCHEME *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_MGF1
+ case TPM_ALG_MGF1:
+ return TPMS_SCHEME_MGF1_Unmarshal((TPMS_SCHEME_MGF1 *)&(target->mgf1), buffer, size);
+#endif // TPM_ALG_MGF1
+#ifdef TPM_ALG_KDF1_SP800_56A
+ case TPM_ALG_KDF1_SP800_56A:
+ return TPMS_SCHEME_KDF1_SP800_56A_Unmarshal((TPMS_SCHEME_KDF1_SP800_56A *)&(target->kdf1_sp800_56a), buffer, size);
+#endif // TPM_ALG_KDF1_SP800_56A
+#ifdef TPM_ALG_KDF2
+ case TPM_ALG_KDF2:
+ return TPMS_SCHEME_KDF2_Unmarshal((TPMS_SCHEME_KDF2 *)&(target->kdf2), buffer, size);
+#endif // TPM_ALG_KDF2
+#ifdef TPM_ALG_KDF1_SP800_108
+ case TPM_ALG_KDF1_SP800_108:
+ return TPMS_SCHEME_KDF1_SP800_108_Unmarshal((TPMS_SCHEME_KDF1_SP800_108 *)&(target->kdf1_sp800_108), buffer, size);
+#endif // TPM_ALG_KDF1_SP800_108
+ case TPM_ALG_NULL:
+ return TPM_RC_SUCCESS;
+ }
+ return TPM_RC_SELECTOR;
+}
+
+UINT16
+TPMU_KDF_SCHEME_Marshal(
+ TPMU_KDF_SCHEME *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_MGF1
+ case TPM_ALG_MGF1:
+ return TPMS_SCHEME_MGF1_Marshal((TPMS_SCHEME_MGF1 *)&(source->mgf1), buffer, size);
+#endif // TPM_ALG_MGF1
+#ifdef TPM_ALG_KDF1_SP800_56A
+ case TPM_ALG_KDF1_SP800_56A:
+ return TPMS_SCHEME_KDF1_SP800_56A_Marshal((TPMS_SCHEME_KDF1_SP800_56A *)&(source->kdf1_sp800_56a), buffer, size);
+#endif // TPM_ALG_KDF1_SP800_56A
+#ifdef TPM_ALG_KDF2
+ case TPM_ALG_KDF2:
+ return TPMS_SCHEME_KDF2_Marshal((TPMS_SCHEME_KDF2 *)&(source->kdf2), buffer, size);
+#endif // TPM_ALG_KDF2
+#ifdef TPM_ALG_KDF1_SP800_108
+ case TPM_ALG_KDF1_SP800_108:
+ return TPMS_SCHEME_KDF1_SP800_108_Marshal((TPMS_SCHEME_KDF1_SP800_108 *)&(source->kdf1_sp800_108), buffer, size);
+#endif // TPM_ALG_KDF1_SP800_108
+ case TPM_ALG_NULL:
+ return 0;
+ }
+ return 0;
+}
+
+
+// Table 2:150 - Definition of TPMT_KDF_SCHEME Structure (StructureTable)
+TPM_RC
+TPMT_KDF_SCHEME_Unmarshal(
+ TPMT_KDF_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_KDF_Unmarshal((TPMI_ALG_KDF *)&(target->scheme), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_KDF_SCHEME_Unmarshal((TPMU_KDF_SCHEME *)&(target->details), buffer, size, (UINT32)target->scheme);
+ return result;
+}
+
+UINT16
+TPMT_KDF_SCHEME_Marshal(
+ TPMT_KDF_SCHEME *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_KDF_Marshal((TPMI_ALG_KDF *)&(source->scheme), buffer, size));
+ result = (UINT16)(result + TPMU_KDF_SCHEME_Marshal((TPMU_KDF_SCHEME *)&(source->details), buffer, size, (UINT32)source->scheme));
+ return result;
+}
+
+
+// Table 2:151 - Definition of TPMI_ALG_ASYM_SCHEME Type (TypeTable)
+// TPMI_ALG_ASYM_SCHEME_Unmarshal not referenced
+// TPMI_ALG_ASYM_SCHEME_Marshal not referenced
+
+
+// Table 2:152 - Definition of TPMU_ASYM_SCHEME Union (UnionTable)
+TPM_RC
+TPMU_ASYM_SCHEME_Unmarshal(
+ TPMU_ASYM_SCHEME *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_ECDH
+ case TPM_ALG_ECDH:
+ return TPMS_KEY_SCHEME_ECDH_Unmarshal((TPMS_KEY_SCHEME_ECDH *)&(target->ecdh), buffer, size);
+#endif // TPM_ALG_ECDH
+#ifdef TPM_ALG_ECMQV
+ case TPM_ALG_ECMQV:
+ return TPMS_KEY_SCHEME_ECMQV_Unmarshal((TPMS_KEY_SCHEME_ECMQV *)&(target->ecmqv), buffer, size);
+#endif // TPM_ALG_ECMQV
+#ifdef TPM_ALG_RSASSA
+ case TPM_ALG_RSASSA:
+ return TPMS_SIG_SCHEME_RSASSA_Unmarshal((TPMS_SIG_SCHEME_RSASSA *)&(target->rsassa), buffer, size);
+#endif // TPM_ALG_RSASSA
+#ifdef TPM_ALG_RSAPSS
+ case TPM_ALG_RSAPSS:
+ return TPMS_SIG_SCHEME_RSAPSS_Unmarshal((TPMS_SIG_SCHEME_RSAPSS *)&(target->rsapss), buffer, size);
+#endif // TPM_ALG_RSAPSS
+#ifdef TPM_ALG_ECDSA
+ case TPM_ALG_ECDSA:
+ return TPMS_SIG_SCHEME_ECDSA_Unmarshal((TPMS_SIG_SCHEME_ECDSA *)&(target->ecdsa), buffer, size);
+#endif // TPM_ALG_ECDSA
+#ifdef TPM_ALG_SM2
+ case TPM_ALG_SM2:
+ return TPMS_SIG_SCHEME_SM2_Unmarshal((TPMS_SIG_SCHEME_SM2 *)&(target->sm2), buffer, size);
+#endif // TPM_ALG_SM2
+#ifdef TPM_ALG_ECSCHNORR
+ case TPM_ALG_ECSCHNORR:
+ return TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal((TPMS_SIG_SCHEME_ECSCHNORR *)&(target->ecschnorr), buffer, size);
+#endif // TPM_ALG_ECSCHNORR
+#ifdef TPM_ALG_ECDAA
+ case TPM_ALG_ECDAA:
+ return TPMS_SIG_SCHEME_ECDAA_Unmarshal((TPMS_SIG_SCHEME_ECDAA *)&(target->ecdaa), buffer, size);
+#endif // TPM_ALG_ECDAA
+#ifdef TPM_ALG_OAEP
+ case TPM_ALG_OAEP:
+ return TPMS_ENC_SCHEME_OAEP_Unmarshal((TPMS_ENC_SCHEME_OAEP *)&(target->oaep), buffer, size);
+#endif // TPM_ALG_OAEP
+#ifdef TPM_ALG_RSAES
+ case TPM_ALG_RSAES:
+ return TPMS_ENC_SCHEME_RSAES_Unmarshal((TPMS_ENC_SCHEME_RSAES *)&(target->rsaes), buffer, size);
+#endif // TPM_ALG_RSAES
+ case TPM_ALG_NULL:
+ return TPM_RC_SUCCESS;
+ }
+ return TPM_RC_SELECTOR;
+}
+
+UINT16
+TPMU_ASYM_SCHEME_Marshal(
+ TPMU_ASYM_SCHEME *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_ECDH
+ case TPM_ALG_ECDH:
+ return TPMS_KEY_SCHEME_ECDH_Marshal((TPMS_KEY_SCHEME_ECDH *)&(source->ecdh), buffer, size);
+#endif // TPM_ALG_ECDH
+#ifdef TPM_ALG_ECMQV
+ case TPM_ALG_ECMQV:
+ return TPMS_KEY_SCHEME_ECMQV_Marshal((TPMS_KEY_SCHEME_ECMQV *)&(source->ecmqv), buffer, size);
+#endif // TPM_ALG_ECMQV
+#ifdef TPM_ALG_RSASSA
+ case TPM_ALG_RSASSA:
+ return TPMS_SIG_SCHEME_RSASSA_Marshal((TPMS_SIG_SCHEME_RSASSA *)&(source->rsassa), buffer, size);
+#endif // TPM_ALG_RSASSA
+#ifdef TPM_ALG_RSAPSS
+ case TPM_ALG_RSAPSS:
+ return TPMS_SIG_SCHEME_RSAPSS_Marshal((TPMS_SIG_SCHEME_RSAPSS *)&(source->rsapss), buffer, size);
+#endif // TPM_ALG_RSAPSS
+#ifdef TPM_ALG_ECDSA
+ case TPM_ALG_ECDSA:
+ return TPMS_SIG_SCHEME_ECDSA_Marshal((TPMS_SIG_SCHEME_ECDSA *)&(source->ecdsa), buffer, size);
+#endif // TPM_ALG_ECDSA
+#ifdef TPM_ALG_SM2
+ case TPM_ALG_SM2:
+ return TPMS_SIG_SCHEME_SM2_Marshal((TPMS_SIG_SCHEME_SM2 *)&(source->sm2), buffer, size);
+#endif // TPM_ALG_SM2
+#ifdef TPM_ALG_ECSCHNORR
+ case TPM_ALG_ECSCHNORR:
+ return TPMS_SIG_SCHEME_ECSCHNORR_Marshal((TPMS_SIG_SCHEME_ECSCHNORR *)&(source->ecschnorr), buffer, size);
+#endif // TPM_ALG_ECSCHNORR
+#ifdef TPM_ALG_ECDAA
+ case TPM_ALG_ECDAA:
+ return TPMS_SIG_SCHEME_ECDAA_Marshal((TPMS_SIG_SCHEME_ECDAA *)&(source->ecdaa), buffer, size);
+#endif // TPM_ALG_ECDAA
+#ifdef TPM_ALG_OAEP
+ case TPM_ALG_OAEP:
+ return TPMS_ENC_SCHEME_OAEP_Marshal((TPMS_ENC_SCHEME_OAEP *)&(source->oaep), buffer, size);
+#endif // TPM_ALG_OAEP
+#ifdef TPM_ALG_RSAES
+ case TPM_ALG_RSAES:
+ return TPMS_ENC_SCHEME_RSAES_Marshal((TPMS_ENC_SCHEME_RSAES *)&(source->rsaes), buffer, size);
+#endif // TPM_ALG_RSAES
+ case TPM_ALG_NULL:
+ return 0;
+ }
+ return 0;
+}
+
+
+// Table 2:153 - Definition of TPMT_ASYM_SCHEME Structure (StructureTable)
+// TPMT_ASYM_SCHEME_Unmarshal not referenced
+// TPMT_ASYM_SCHEME_Marshal not referenced
+
+
+// Table 2:154 - Definition of TPMI_ALG_RSA_SCHEME Type (TypeTable)
+#ifdef TPM_ALG_RSA
+TPM_RC
+TPMI_ALG_RSA_SCHEME_Unmarshal(
+ TPMI_ALG_RSA_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_OAEP
+ case TPM_ALG_OAEP:
+#endif // TPM_ALG_OAEP
+#ifdef TPM_ALG_RSASSA
+ case TPM_ALG_RSASSA:
+#endif // TPM_ALG_RSASSA
+#ifdef TPM_ALG_RSAPSS
+ case TPM_ALG_RSAPSS:
+#endif // TPM_ALG_RSAPSS
+#ifdef TPM_ALG_RSAES
+ case TPM_ALG_RSAES:
+#endif // TPM_ALG_RSAES
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_VALUE;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_RSA_SCHEME_Marshal changed to #define
+#endif // TPM_ALG_RSA
+
+
+// Table 2:155 - Definition of TPMT_RSA_SCHEME Structure (StructureTable)
+#ifdef TPM_ALG_RSA
+TPM_RC
+TPMT_RSA_SCHEME_Unmarshal(
+ TPMT_RSA_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_RSA_SCHEME_Unmarshal((TPMI_ALG_RSA_SCHEME *)&(target->scheme), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_ASYM_SCHEME_Unmarshal((TPMU_ASYM_SCHEME *)&(target->details), buffer, size, (UINT32)target->scheme);
+ return result;
+}
+
+UINT16
+TPMT_RSA_SCHEME_Marshal(
+ TPMT_RSA_SCHEME *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_RSA_SCHEME_Marshal((TPMI_ALG_RSA_SCHEME *)&(source->scheme), buffer, size));
+ result = (UINT16)(result + TPMU_ASYM_SCHEME_Marshal((TPMU_ASYM_SCHEME *)&(source->details), buffer, size, (UINT32)source->scheme));
+ return result;
+}
+
+#endif // TPM_ALG_RSA
+
+
+// Table 2:156 - Definition of TPMI_ALG_RSA_DECRYPT Type (TypeTable)
+#ifdef TPM_ALG_RSA
+TPM_RC
+TPMI_ALG_RSA_DECRYPT_Unmarshal(
+ TPMI_ALG_RSA_DECRYPT *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_OAEP
+ case TPM_ALG_OAEP:
+#endif // TPM_ALG_OAEP
+#ifdef TPM_ALG_RSAES
+ case TPM_ALG_RSAES:
+#endif // TPM_ALG_RSAES
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_VALUE;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_RSA_DECRYPT_Marshal not referenced
+#endif // TPM_ALG_RSA
+
+
+// Table 2:157 - Definition of TPMT_RSA_DECRYPT Structure (StructureTable)
+#ifdef TPM_ALG_RSA
+TPM_RC
+TPMT_RSA_DECRYPT_Unmarshal(
+ TPMT_RSA_DECRYPT *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_RSA_DECRYPT_Unmarshal((TPMI_ALG_RSA_DECRYPT *)&(target->scheme), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_ASYM_SCHEME_Unmarshal((TPMU_ASYM_SCHEME *)&(target->details), buffer, size, (UINT32)target->scheme);
+ return result;
+}
+
+// TPMT_RSA_DECRYPT_Marshal not referenced
+#endif // TPM_ALG_RSA
+
+
+// Table 2:158 - Definition of TPM2B_PUBLIC_KEY_RSA Structure (StructureTable)
+#ifdef TPM_ALG_RSA
+TPM_RC
+TPM2B_PUBLIC_KEY_RSA_Unmarshal(
+ TPM2B_PUBLIC_KEY_RSA *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > MAX_RSA_KEY_BYTES)
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_PUBLIC_KEY_RSA_Marshal(
+ TPM2B_PUBLIC_KEY_RSA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+#endif // TPM_ALG_RSA
+
+
+// Table 2:159 - Definition of TPMI_RSA_KEY_BITS Type (TypeTable)
+#ifdef TPM_ALG_RSA
+TPM_RC
+TPMI_RSA_KEY_BITS_Unmarshal(
+ TPMI_RSA_KEY_BITS *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_KEY_BITS_Unmarshal((TPM_KEY_BITS *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case 1024:
+ case 2048:
+ break;
+ default:
+ return TPM_RC_VALUE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_RSA_KEY_BITS_Marshal changed to #define
+#endif // TPM_ALG_RSA
+
+
+// Table 2:160 - Definition of TPM2B_PRIVATE_KEY_RSA Structure (StructureTable)
+#ifdef TPM_ALG_RSA
+TPM_RC
+TPM2B_PRIVATE_KEY_RSA_Unmarshal(
+ TPM2B_PRIVATE_KEY_RSA *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > MAX_RSA_KEY_BYTES/2)
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_PRIVATE_KEY_RSA_Marshal(
+ TPM2B_PRIVATE_KEY_RSA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+#endif // TPM_ALG_RSA
+
+
+// Table 2:161 - Definition of TPM2B_ECC_PARAMETER Structure (StructureTable)
+#ifdef TPM_ALG_ECC
+TPM_RC
+TPM2B_ECC_PARAMETER_Unmarshal(
+ TPM2B_ECC_PARAMETER *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > MAX_ECC_KEY_BYTES)
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_ECC_PARAMETER_Marshal(
+ TPM2B_ECC_PARAMETER *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+#endif // TPM_ALG_ECC
+
+
+// Table 2:162 - Definition of TPMS_ECC_POINT Structure (StructureTable)
+#ifdef TPM_ALG_ECC
+TPM_RC
+TPMS_ECC_POINT_Unmarshal(
+ TPMS_ECC_POINT *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER *)&(target->x), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER *)&(target->y), buffer, size);
+ return result;
+}
+
+UINT16
+TPMS_ECC_POINT_Marshal(
+ TPMS_ECC_POINT *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->x), buffer, size));
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->y), buffer, size));
+ return result;
+}
+
+#endif // TPM_ALG_ECC
+
+
+// Table 2:163 - Definition of TPM2B_ECC_POINT Structure (StructureTable)
+#ifdef TPM_ALG_ECC
+TPM_RC
+TPM2B_ECC_POINT_Unmarshal(
+ TPM2B_ECC_POINT *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ INT32 startSize;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size is zero, then the required structure is missing
+ if(target->t.size == 0)
+ return TPM_RC_SIZE;
+ startSize = *size;
+ result = TPMS_ECC_POINT_Unmarshal((TPMS_ECC_POINT *)&(target->t.point), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if(target->t.size != (startSize - *size)) return TPM_RC_SIZE;
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+TPM2B_ECC_POINT_Marshal(
+ TPM2B_ECC_POINT *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ BYTE *sizeField = *buffer;
+ // Advance buffer pointer by cononical size of a UINT16
+ *buffer += 2;
+ // Marshal the structure
+ result = (UINT16)(result + TPMS_ECC_POINT_Marshal((TPMS_ECC_POINT *)&(source->t.point), buffer, size));
+ // Marshal the size
+ result = (UINT16)(result + UINT16_Marshal(&result, &sizeField, size));
+ return result;
+}
+
+#endif // TPM_ALG_ECC
+
+
+// Table 2:164 - Definition of TPMI_ALG_ECC_SCHEME Type (TypeTable)
+#ifdef TPM_ALG_ECC
+TPM_RC
+TPMI_ALG_ECC_SCHEME_Unmarshal(
+ TPMI_ALG_ECC_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_ECDSA
+ case TPM_ALG_ECDSA:
+#endif // TPM_ALG_ECDSA
+#ifdef TPM_ALG_SM2
+ case TPM_ALG_SM2:
+#endif // TPM_ALG_SM2
+#ifdef TPM_ALG_ECSCHNORR
+ case TPM_ALG_ECSCHNORR:
+#endif // TPM_ALG_ECSCHNORR
+#ifdef TPM_ALG_ECDAA
+ case TPM_ALG_ECDAA:
+#endif // TPM_ALG_ECDAA
+#ifdef TPM_ALG_ECDH
+ case TPM_ALG_ECDH:
+#endif // TPM_ALG_ECDH
+#ifdef TPM_ALG_ECMQV
+ case TPM_ALG_ECMQV:
+#endif // TPM_ALG_ECMQV
+ break;
+ case TPM_ALG_NULL:
+ if (flag)
+ break;
+ return TPM_RC_SCHEME;
+ default:
+ return TPM_RC_SCHEME;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_ECC_SCHEME_Marshal changed to #define
+#endif // TPM_ALG_ECC
+
+
+// Table 2:165 - Definition of TPMI_ECC_CURVE Type (TypeTable)
+#ifdef TPM_ALG_ECC
+TPM_RC
+TPMI_ECC_CURVE_Unmarshal(
+ TPMI_ECC_CURVE *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_ECC_CURVE_Unmarshal((TPM_ECC_CURVE *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+ case TPM_ECC_BN_P256:
+ case TPM_ECC_NIST_P256:
+#if defined ME11_SIM
+#elif defined INTEL_SMX
+ case TPM_ECC_SM2_P256:
+#else
+ case TPM_ECC_NIST_P384:
+#endif
+ break;
+ default:
+ return TPM_RC_CURVE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ECC_CURVE_Marshal changed to #define
+#endif // TPM_ALG_ECC
+
+
+// Table 2:166 - Definition of TPMT_ECC_SCHEME Structure (StructureTable)
+#ifdef TPM_ALG_ECC
+TPM_RC
+TPMT_ECC_SCHEME_Unmarshal(
+ TPMT_ECC_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_ECC_SCHEME_Unmarshal((TPMI_ALG_ECC_SCHEME *)&(target->scheme), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_ASYM_SCHEME_Unmarshal((TPMU_ASYM_SCHEME *)&(target->details), buffer, size, (UINT32)target->scheme);
+ return result;
+}
+
+UINT16
+TPMT_ECC_SCHEME_Marshal(
+ TPMT_ECC_SCHEME *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_ECC_SCHEME_Marshal((TPMI_ALG_ECC_SCHEME *)&(source->scheme), buffer, size));
+ result = (UINT16)(result + TPMU_ASYM_SCHEME_Marshal((TPMU_ASYM_SCHEME *)&(source->details), buffer, size, (UINT32)source->scheme));
+ return result;
+}
+
+#endif // TPM_ALG_ECC
+
+
+// Table 2:167 - Definition of TPMS_ALGORITHM_DETAIL_ECC Structure (StructureTable)
+#ifdef TPM_ALG_ECC
+// TPMS_ALGORITHM_DETAIL_ECC_Unmarshal not referenced
+UINT16
+TPMS_ALGORITHM_DETAIL_ECC_Marshal(
+ TPMS_ALGORITHM_DETAIL_ECC *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPM_ECC_CURVE_Marshal((TPM_ECC_CURVE *)&(source->curveID), buffer, size));
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->keySize), buffer, size));
+ result = (UINT16)(result + TPMT_KDF_SCHEME_Marshal((TPMT_KDF_SCHEME *)&(source->kdf), buffer, size));
+ result = (UINT16)(result + TPMT_ECC_SCHEME_Marshal((TPMT_ECC_SCHEME *)&(source->sign), buffer, size));
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->p), buffer, size));
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->a), buffer, size));
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->b), buffer, size));
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->gX), buffer, size));
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->gY), buffer, size));
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->n), buffer, size));
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->h), buffer, size));
+ return result;
+}
+
+#endif // TPM_ALG_ECC
+
+
+// Table 2:168 - Definition of TPMS_SIGNATURE_RSA Structure (StructureTable)
+#ifdef TPM_ALG_RSA
+TPM_RC
+TPMS_SIGNATURE_RSA_Unmarshal(
+ TPMS_SIGNATURE_RSA *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hash), buffer, size, 0);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_PUBLIC_KEY_RSA_Unmarshal((TPM2B_PUBLIC_KEY_RSA *)&(target->sig), buffer, size);
+ return result;
+}
+
+UINT16
+TPMS_SIGNATURE_RSA_Marshal(
+ TPMS_SIGNATURE_RSA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hash), buffer, size));
+ result = (UINT16)(result + TPM2B_PUBLIC_KEY_RSA_Marshal((TPM2B_PUBLIC_KEY_RSA *)&(source->sig), buffer, size));
+ return result;
+}
+
+#endif // TPM_ALG_RSA
+
+
+// Table 2:169 - Definition of Types for Signature (TypesTable)
+#ifdef TPM_ALG_RSA
+// TPMS_SIGNATURE_RSA definition from table 2:169
+#ifdef TPM_ALG_RSA
+// TPMS_SIGNATURE_RSASSA_Unmarshal changed to #define
+// TPMS_SIGNATURE_RSASSA_Marshal changed to #define
+#endif // TPM_ALG_RSA
+// TPMS_SIGNATURE_RSA definition from table 2:169
+#ifdef TPM_ALG_RSA
+// TPMS_SIGNATURE_RSAPSS_Unmarshal changed to #define
+// TPMS_SIGNATURE_RSAPSS_Marshal changed to #define
+#endif // TPM_ALG_RSA
+#endif // TPM_ALG_RSA
+
+
+// Table 2:170 - Definition of TPMS_SIGNATURE_ECC Structure (StructureTable)
+#ifdef TPM_ALG_ECC
+TPM_RC
+TPMS_SIGNATURE_ECC_Unmarshal(
+ TPMS_SIGNATURE_ECC *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hash), buffer, size, 0);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER *)&(target->signatureR), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER *)&(target->signatureS), buffer, size);
+ return result;
+}
+
+UINT16
+TPMS_SIGNATURE_ECC_Marshal(
+ TPMS_SIGNATURE_ECC *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hash), buffer, size));
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->signatureR), buffer, size));
+ result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->signatureS), buffer, size));
+ return result;
+}
+
+#endif // TPM_ALG_ECC
+
+
+// Table 2:171 - Definition of Types for TPMS_SIGNATUE_ECC (TypesTable)
+#ifdef TPM_ALG_ECC
+// TPMS_SIGNATURE_ECC definition from table 2:171
+#ifdef TPM_ALG_ECC
+// TPMS_SIGNATURE_ECDSA_Unmarshal changed to #define
+// TPMS_SIGNATURE_ECDSA_Marshal changed to #define
+#endif // TPM_ALG_ECC
+// TPMS_SIGNATURE_ECC definition from table 2:171
+#ifdef TPM_ALG_ECC
+// TPMS_SIGNATURE_SM2_Unmarshal changed to #define
+// TPMS_SIGNATURE_SM2_Marshal changed to #define
+#endif // TPM_ALG_ECC
+// TPMS_SIGNATURE_ECC definition from table 2:171
+#ifdef TPM_ALG_ECC
+// TPMS_SIGNATURE_ECSCHNORR_Unmarshal changed to #define
+// TPMS_SIGNATURE_ECSCHNORR_Marshal changed to #define
+#endif // TPM_ALG_ECC
+// TPMS_SIGNATURE_ECC definition from table 2:171
+#ifdef TPM_ALG_ECC
+// TPMS_SIGNATURE_ECDAA_Unmarshal changed to #define
+// TPMS_SIGNATURE_ECDAA_Marshal changed to #define
+#endif // TPM_ALG_ECC
+#endif // TPM_ALG_ECC
+
+
+// Table 2:172 - Definition of TPMU_SIGNATURE Union (UnionTable)
+TPM_RC
+TPMU_SIGNATURE_Unmarshal(
+ TPMU_SIGNATURE *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_RSASSA
+ case TPM_ALG_RSASSA:
+ return TPMS_SIGNATURE_RSASSA_Unmarshal((TPMS_SIGNATURE_RSASSA *)&(target->rsassa), buffer, size);
+#endif // TPM_ALG_RSASSA
+#ifdef TPM_ALG_RSAPSS
+ case TPM_ALG_RSAPSS:
+ return TPMS_SIGNATURE_RSAPSS_Unmarshal((TPMS_SIGNATURE_RSAPSS *)&(target->rsapss), buffer, size);
+#endif // TPM_ALG_RSAPSS
+#ifdef TPM_ALG_ECDSA
+ case TPM_ALG_ECDSA:
+ return TPMS_SIGNATURE_ECDSA_Unmarshal((TPMS_SIGNATURE_ECDSA *)&(target->ecdsa), buffer, size);
+#endif // TPM_ALG_ECDSA
+#ifdef TPM_ALG_SM2
+ case TPM_ALG_SM2:
+ return TPMS_SIGNATURE_SM2_Unmarshal((TPMS_SIGNATURE_SM2 *)&(target->sm2), buffer, size);
+#endif // TPM_ALG_SM2
+#ifdef TPM_ALG_ECSCHNORR
+ case TPM_ALG_ECSCHNORR:
+ return TPMS_SIGNATURE_ECSCHNORR_Unmarshal((TPMS_SIGNATURE_ECSCHNORR *)&(target->ecschnorr), buffer, size);
+#endif // TPM_ALG_ECSCHNORR
+#ifdef TPM_ALG_ECDAA
+ case TPM_ALG_ECDAA:
+ return TPMS_SIGNATURE_ECDAA_Unmarshal((TPMS_SIGNATURE_ECDAA *)&(target->ecdaa), buffer, size);
+#endif // TPM_ALG_ECDAA
+#ifdef TPM_ALG_HMAC
+ case TPM_ALG_HMAC:
+ return TPMT_HA_Unmarshal((TPMT_HA *)&(target->hmac), buffer, size, 0);
+#endif // TPM_ALG_HMAC
+ case TPM_ALG_NULL:
+ return TPM_RC_SUCCESS;
+ }
+ return TPM_RC_SELECTOR;
+}
+
+UINT16
+TPMU_SIGNATURE_Marshal(
+ TPMU_SIGNATURE *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_RSASSA
+ case TPM_ALG_RSASSA:
+ return TPMS_SIGNATURE_RSASSA_Marshal((TPMS_SIGNATURE_RSASSA *)&(source->rsassa), buffer, size);
+#endif // TPM_ALG_RSASSA
+#ifdef TPM_ALG_RSAPSS
+ case TPM_ALG_RSAPSS:
+ return TPMS_SIGNATURE_RSAPSS_Marshal((TPMS_SIGNATURE_RSAPSS *)&(source->rsapss), buffer, size);
+#endif // TPM_ALG_RSAPSS
+#ifdef TPM_ALG_ECDSA
+ case TPM_ALG_ECDSA:
+ return TPMS_SIGNATURE_ECDSA_Marshal((TPMS_SIGNATURE_ECDSA *)&(source->ecdsa), buffer, size);
+#endif // TPM_ALG_ECDSA
+#ifdef TPM_ALG_SM2
+ case TPM_ALG_SM2:
+ return TPMS_SIGNATURE_SM2_Marshal((TPMS_SIGNATURE_SM2 *)&(source->sm2), buffer, size);
+#endif // TPM_ALG_SM2
+#ifdef TPM_ALG_ECSCHNORR
+ case TPM_ALG_ECSCHNORR:
+ return TPMS_SIGNATURE_ECSCHNORR_Marshal((TPMS_SIGNATURE_ECSCHNORR *)&(source->ecschnorr), buffer, size);
+#endif // TPM_ALG_ECSCHNORR
+#ifdef TPM_ALG_ECDAA
+ case TPM_ALG_ECDAA:
+ return TPMS_SIGNATURE_ECDAA_Marshal((TPMS_SIGNATURE_ECDAA *)&(source->ecdaa), buffer, size);
+#endif // TPM_ALG_ECDAA
+#ifdef TPM_ALG_HMAC
+ case TPM_ALG_HMAC:
+ return TPMT_HA_Marshal((TPMT_HA *)&(source->hmac), buffer, size);
+#endif // TPM_ALG_HMAC
+ case TPM_ALG_NULL:
+ return 0;
+ }
+ return 0;
+}
+
+
+// Table 2:173 - Definition of TPMT_SIGNATURE Structure (StructureTable)
+TPM_RC
+TPMT_SIGNATURE_Unmarshal(
+ TPMT_SIGNATURE *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_SIG_SCHEME_Unmarshal((TPMI_ALG_SIG_SCHEME *)&(target->sigAlg), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_SIGNATURE_Unmarshal((TPMU_SIGNATURE *)&(target->signature), buffer, size, (UINT32)target->sigAlg);
+ return result;
+}
+
+UINT16
+TPMT_SIGNATURE_Marshal(
+ TPMT_SIGNATURE *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_SIG_SCHEME_Marshal((TPMI_ALG_SIG_SCHEME *)&(source->sigAlg), buffer, size));
+ result = (UINT16)(result + TPMU_SIGNATURE_Marshal((TPMU_SIGNATURE *)&(source->signature), buffer, size, (UINT32)source->sigAlg));
+ return result;
+}
+
+
+// Table 2:174 - Definition of TPMU_ENCRYPTED_SECRET Union (UnionTable)
+// TPMU_ENCRYPTED_SECRET_Unmarshal not referenced
+// TPMU_ENCRYPTED_SECRET_Marshal not referenced
+
+
+// Table 2:175 - Definition of TPM2B_ENCRYPTED_SECRET Structure (StructureTable)
+TPM_RC
+TPM2B_ENCRYPTED_SECRET_Unmarshal(
+ TPM2B_ENCRYPTED_SECRET *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > sizeof(TPMU_ENCRYPTED_SECRET))
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.secret), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_ENCRYPTED_SECRET_Marshal(
+ TPM2B_ENCRYPTED_SECRET *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.secret), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:176 - Definition of TPMI_ALG_PUBLIC Type (TypeTable)
+TPM_RC
+TPMI_ALG_PUBLIC_Unmarshal(
+ TPMI_ALG_PUBLIC *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ switch (*target) {
+#ifdef TPM_ALG_SYMCIPHER
+ case TPM_ALG_SYMCIPHER:
+#endif // TPM_ALG_SYMCIPHER
+#ifdef TPM_ALG_RSA
+ case TPM_ALG_RSA:
+#endif // TPM_ALG_RSA
+#ifdef TPM_ALG_ECC
+ case TPM_ALG_ECC:
+#endif // TPM_ALG_ECC
+#ifdef TPM_ALG_KEYEDHASH
+ case TPM_ALG_KEYEDHASH:
+#endif // TPM_ALG_KEYEDHASH
+ break;
+ default:
+ return TPM_RC_TYPE;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+// TPMI_ALG_PUBLIC_Marshal changed to #define
+
+
+// Table 2:177 - Definition of TPMU_PUBLIC_ID Union (UnionTable)
+TPM_RC
+TPMU_PUBLIC_ID_Unmarshal(
+ TPMU_PUBLIC_ID *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_KEYEDHASH
+ case TPM_ALG_KEYEDHASH:
+ return TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->keyedHash), buffer, size);
+#endif // TPM_ALG_KEYEDHASH
+#ifdef TPM_ALG_SYMCIPHER
+ case TPM_ALG_SYMCIPHER:
+ return TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->sym), buffer, size);
+#endif // TPM_ALG_SYMCIPHER
+#ifdef TPM_ALG_RSA
+ case TPM_ALG_RSA:
+ return TPM2B_PUBLIC_KEY_RSA_Unmarshal((TPM2B_PUBLIC_KEY_RSA *)&(target->rsa), buffer, size);
+#endif // TPM_ALG_RSA
+#ifdef TPM_ALG_ECC
+ case TPM_ALG_ECC:
+ return TPMS_ECC_POINT_Unmarshal((TPMS_ECC_POINT *)&(target->ecc), buffer, size);
+#endif // TPM_ALG_ECC
+ }
+ return TPM_RC_SELECTOR;
+}
+
+UINT16
+TPMU_PUBLIC_ID_Marshal(
+ TPMU_PUBLIC_ID *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_KEYEDHASH
+ case TPM_ALG_KEYEDHASH:
+ return TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->keyedHash), buffer, size);
+#endif // TPM_ALG_KEYEDHASH
+#ifdef TPM_ALG_SYMCIPHER
+ case TPM_ALG_SYMCIPHER:
+ return TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->sym), buffer, size);
+#endif // TPM_ALG_SYMCIPHER
+#ifdef TPM_ALG_RSA
+ case TPM_ALG_RSA:
+ return TPM2B_PUBLIC_KEY_RSA_Marshal((TPM2B_PUBLIC_KEY_RSA *)&(source->rsa), buffer, size);
+#endif // TPM_ALG_RSA
+#ifdef TPM_ALG_ECC
+ case TPM_ALG_ECC:
+ return TPMS_ECC_POINT_Marshal((TPMS_ECC_POINT *)&(source->ecc), buffer, size);
+#endif // TPM_ALG_ECC
+ }
+ return 0;
+}
+
+
+// Table 2:178 - Definition of TPMS_KEYEDHASH_PARMS Structure (StructureTable)
+// TPMS_KEYEDHASH_PARMS_Unmarshal changed to #define
+// TPMS_KEYEDHASH_PARMS_Marshal changed to #define
+
+
+// Table 2:179 - Definition of TPMS_ASYM_PARMS Structure (StructureTable)
+// TPMS_ASYM_PARMS_Unmarshal not referenced
+// TPMS_ASYM_PARMS_Marshal not referenced
+
+
+// Table 2:180 - Definition of TPMS_RSA_PARMS Structure (StructureTable)
+#ifdef TPM_ALG_RSA
+TPM_RC
+TPMS_RSA_PARMS_Unmarshal(
+ TPMS_RSA_PARMS *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPMT_SYM_DEF_OBJECT_Unmarshal((TPMT_SYM_DEF_OBJECT *)&(target->symmetric), buffer, size, 1);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMT_RSA_SCHEME_Unmarshal((TPMT_RSA_SCHEME *)&(target->scheme), buffer, size, 1);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMI_RSA_KEY_BITS_Unmarshal((TPMI_RSA_KEY_BITS *)&(target->keyBits), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = UINT32_Unmarshal((UINT32 *)&(target->exponent), buffer, size);
+ return result;
+}
+
+UINT16
+TPMS_RSA_PARMS_Marshal(
+ TPMS_RSA_PARMS *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMT_SYM_DEF_OBJECT_Marshal((TPMT_SYM_DEF_OBJECT *)&(source->symmetric), buffer, size));
+ result = (UINT16)(result + TPMT_RSA_SCHEME_Marshal((TPMT_RSA_SCHEME *)&(source->scheme), buffer, size));
+ result = (UINT16)(result + TPMI_RSA_KEY_BITS_Marshal((TPMI_RSA_KEY_BITS *)&(source->keyBits), buffer, size));
+ result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->exponent), buffer, size));
+ return result;
+}
+
+#endif // TPM_ALG_RSA
+
+
+// Table 2:181 - Definition of TPMS_ECC_PARMS Structure (StructureTable)
+#ifdef TPM_ALG_ECC
+TPM_RC
+TPMS_ECC_PARMS_Unmarshal(
+ TPMS_ECC_PARMS *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPMT_SYM_DEF_OBJECT_Unmarshal((TPMT_SYM_DEF_OBJECT *)&(target->symmetric), buffer, size, 1);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMT_ECC_SCHEME_Unmarshal((TPMT_ECC_SCHEME *)&(target->scheme), buffer, size, 1);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMI_ECC_CURVE_Unmarshal((TPMI_ECC_CURVE *)&(target->curveID), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMT_KDF_SCHEME_Unmarshal((TPMT_KDF_SCHEME *)&(target->kdf), buffer, size, 1);
+ return result;
+}
+
+UINT16
+TPMS_ECC_PARMS_Marshal(
+ TPMS_ECC_PARMS *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMT_SYM_DEF_OBJECT_Marshal((TPMT_SYM_DEF_OBJECT *)&(source->symmetric), buffer, size));
+ result = (UINT16)(result + TPMT_ECC_SCHEME_Marshal((TPMT_ECC_SCHEME *)&(source->scheme), buffer, size));
+ result = (UINT16)(result + TPMI_ECC_CURVE_Marshal((TPMI_ECC_CURVE *)&(source->curveID), buffer, size));
+ result = (UINT16)(result + TPMT_KDF_SCHEME_Marshal((TPMT_KDF_SCHEME *)&(source->kdf), buffer, size));
+ return result;
+}
+
+#endif // TPM_ALG_ECC
+
+
+// Table 2:182 - Definition of TPMU_PUBLIC_PARMS Union (UnionTable)
+TPM_RC
+TPMU_PUBLIC_PARMS_Unmarshal(
+ TPMU_PUBLIC_PARMS *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_KEYEDHASH
+ case TPM_ALG_KEYEDHASH:
+ return TPMS_KEYEDHASH_PARMS_Unmarshal((TPMS_KEYEDHASH_PARMS *)&(target->keyedHashDetail), buffer, size);
+#endif // TPM_ALG_KEYEDHASH
+#ifdef TPM_ALG_SYMCIPHER
+ case TPM_ALG_SYMCIPHER:
+ return TPMS_SYMCIPHER_PARMS_Unmarshal((TPMS_SYMCIPHER_PARMS *)&(target->symDetail), buffer, size);
+#endif // TPM_ALG_SYMCIPHER
+#ifdef TPM_ALG_RSA
+ case TPM_ALG_RSA:
+ return TPMS_RSA_PARMS_Unmarshal((TPMS_RSA_PARMS *)&(target->rsaDetail), buffer, size);
+#endif // TPM_ALG_RSA
+#ifdef TPM_ALG_ECC
+ case TPM_ALG_ECC:
+ return TPMS_ECC_PARMS_Unmarshal((TPMS_ECC_PARMS *)&(target->eccDetail), buffer, size);
+#endif // TPM_ALG_ECC
+ }
+ return TPM_RC_SELECTOR;
+}
+
+UINT16
+TPMU_PUBLIC_PARMS_Marshal(
+ TPMU_PUBLIC_PARMS *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_KEYEDHASH
+ case TPM_ALG_KEYEDHASH:
+ return TPMS_KEYEDHASH_PARMS_Marshal((TPMS_KEYEDHASH_PARMS *)&(source->keyedHashDetail), buffer, size);
+#endif // TPM_ALG_KEYEDHASH
+#ifdef TPM_ALG_SYMCIPHER
+ case TPM_ALG_SYMCIPHER:
+ return TPMS_SYMCIPHER_PARMS_Marshal((TPMS_SYMCIPHER_PARMS *)&(source->symDetail), buffer, size);
+#endif // TPM_ALG_SYMCIPHER
+#ifdef TPM_ALG_RSA
+ case TPM_ALG_RSA:
+ return TPMS_RSA_PARMS_Marshal((TPMS_RSA_PARMS *)&(source->rsaDetail), buffer, size);
+#endif // TPM_ALG_RSA
+#ifdef TPM_ALG_ECC
+ case TPM_ALG_ECC:
+ return TPMS_ECC_PARMS_Marshal((TPMS_ECC_PARMS *)&(source->eccDetail), buffer, size);
+#endif // TPM_ALG_ECC
+ }
+ return 0;
+}
+
+
+// Table 2:183 - Definition of TPMT_PUBLIC_PARMS Structure (StructureTable)
+TPM_RC
+TPMT_PUBLIC_PARMS_Unmarshal(
+ TPMT_PUBLIC_PARMS *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_PUBLIC_Unmarshal((TPMI_ALG_PUBLIC *)&(target->type), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_PUBLIC_PARMS_Unmarshal((TPMU_PUBLIC_PARMS *)&(target->parameters), buffer, size, (UINT32)target->type);
+ return result;
+}
+
+// TPMT_PUBLIC_PARMS_Marshal not referenced
+
+
+// Table 2:184 - Definition of TPMT_PUBLIC Structure (StructureTable)
+TPM_RC
+TPMT_PUBLIC_Unmarshal(
+ TPMT_PUBLIC *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_PUBLIC_Unmarshal((TPMI_ALG_PUBLIC *)&(target->type), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->nameAlg), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMA_OBJECT_Unmarshal((TPMA_OBJECT *)&(target->objectAttributes), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->authPolicy), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_PUBLIC_PARMS_Unmarshal((TPMU_PUBLIC_PARMS *)&(target->parameters), buffer, size, (UINT32)target->type);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_PUBLIC_ID_Unmarshal((TPMU_PUBLIC_ID *)&(target->unique), buffer, size, (UINT32)target->type);
+ return result;
+}
+
+UINT16
+TPMT_PUBLIC_Marshal(
+ TPMT_PUBLIC *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_PUBLIC_Marshal((TPMI_ALG_PUBLIC *)&(source->type), buffer, size));
+ result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->nameAlg), buffer, size));
+ result = (UINT16)(result + TPMA_OBJECT_Marshal((TPMA_OBJECT *)&(source->objectAttributes), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->authPolicy), buffer, size));
+ result = (UINT16)(result + TPMU_PUBLIC_PARMS_Marshal((TPMU_PUBLIC_PARMS *)&(source->parameters), buffer, size, (UINT32)source->type));
+ result = (UINT16)(result + TPMU_PUBLIC_ID_Marshal((TPMU_PUBLIC_ID *)&(source->unique), buffer, size, (UINT32)source->type));
+ return result;
+}
+
+
+// Table 2:185 - Definition of TPM2B_PUBLIC Structure (StructureTable)
+TPM_RC
+TPM2B_PUBLIC_Unmarshal(
+ TPM2B_PUBLIC *target, BYTE **buffer, INT32 *size, BOOL flag
+ )
+{
+ TPM_RC result;
+ INT32 startSize;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size is zero, then the required structure is missing
+ if(target->t.size == 0)
+ return TPM_RC_SIZE;
+ startSize = *size;
+ result = TPMT_PUBLIC_Unmarshal((TPMT_PUBLIC *)&(target->t.publicArea), buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if(target->t.size != (startSize - *size)) return TPM_RC_SIZE;
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+TPM2B_PUBLIC_Marshal(
+ TPM2B_PUBLIC *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ BYTE *sizeField = *buffer;
+ // Advance buffer pointer by cononical size of a UINT16
+ *buffer += 2;
+ // Marshal the structure
+ result = (UINT16)(result + TPMT_PUBLIC_Marshal((TPMT_PUBLIC *)&(source->t.publicArea), buffer, size));
+ // Marshal the size
+ result = (UINT16)(result + UINT16_Marshal(&result, &sizeField, size));
+ return result;
+}
+
+
+// Table 2:186 - Definition of TPM2B_PRIVATE_VENDOR_SPECIFIC Structure (StructureTable)
+// TPM2B_PRIVATE_VENDOR_SPECIFIC_Unmarshal not referenced
+// TPM2B_PRIVATE_VENDOR_SPECIFIC_Marshal not referenced
+
+
+// Table 2:187 - Definition of TPMU_SENSITIVE_COMPOSITE Union (UnionTable)
+TPM_RC
+TPMU_SENSITIVE_COMPOSITE_Unmarshal(
+ TPMU_SENSITIVE_COMPOSITE *target, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_RSA
+ case TPM_ALG_RSA:
+ return TPM2B_PRIVATE_KEY_RSA_Unmarshal((TPM2B_PRIVATE_KEY_RSA *)&(target->rsa), buffer, size);
+#endif // TPM_ALG_RSA
+#ifdef TPM_ALG_ECC
+ case TPM_ALG_ECC:
+ return TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER *)&(target->ecc), buffer, size);
+#endif // TPM_ALG_ECC
+#ifdef TPM_ALG_KEYEDHASH
+ case TPM_ALG_KEYEDHASH:
+ return TPM2B_SENSITIVE_DATA_Unmarshal((TPM2B_SENSITIVE_DATA *)&(target->bits), buffer, size);
+#endif // TPM_ALG_KEYEDHASH
+#ifdef TPM_ALG_SYMCIPHER
+ case TPM_ALG_SYMCIPHER:
+ return TPM2B_SYM_KEY_Unmarshal((TPM2B_SYM_KEY *)&(target->sym), buffer, size);
+#endif // TPM_ALG_SYMCIPHER
+ }
+ return TPM_RC_SELECTOR;
+}
+
+UINT16
+TPMU_SENSITIVE_COMPOSITE_Marshal(
+ TPMU_SENSITIVE_COMPOSITE *source, BYTE **buffer, INT32 *size, UINT32 selector
+ )
+{
+ switch(selector) {
+#ifdef TPM_ALG_RSA
+ case TPM_ALG_RSA:
+ return TPM2B_PRIVATE_KEY_RSA_Marshal((TPM2B_PRIVATE_KEY_RSA *)&(source->rsa), buffer, size);
+#endif // TPM_ALG_RSA
+#ifdef TPM_ALG_ECC
+ case TPM_ALG_ECC:
+ return TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->ecc), buffer, size);
+#endif // TPM_ALG_ECC
+#ifdef TPM_ALG_KEYEDHASH
+ case TPM_ALG_KEYEDHASH:
+ return TPM2B_SENSITIVE_DATA_Marshal((TPM2B_SENSITIVE_DATA *)&(source->bits), buffer, size);
+#endif // TPM_ALG_KEYEDHASH
+#ifdef TPM_ALG_SYMCIPHER
+ case TPM_ALG_SYMCIPHER:
+ return TPM2B_SYM_KEY_Marshal((TPM2B_SYM_KEY *)&(source->sym), buffer, size);
+#endif // TPM_ALG_SYMCIPHER
+ }
+ return 0;
+}
+
+
+// Table 2:188 - Definition of TPMT_SENSITIVE Structure (StructureTable)
+TPM_RC
+TPMT_SENSITIVE_Unmarshal(
+ TPMT_SENSITIVE *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPMI_ALG_PUBLIC_Unmarshal((TPMI_ALG_PUBLIC *)&(target->sensitiveType), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_AUTH_Unmarshal((TPM2B_AUTH *)&(target->authValue), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->seedValue), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMU_SENSITIVE_COMPOSITE_Unmarshal((TPMU_SENSITIVE_COMPOSITE *)&(target->sensitive), buffer, size, (UINT32)target->sensitiveType);
+ return result;
+}
+
+UINT16
+TPMT_SENSITIVE_Marshal(
+ TPMT_SENSITIVE *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_ALG_PUBLIC_Marshal((TPMI_ALG_PUBLIC *)&(source->sensitiveType), buffer, size));
+ result = (UINT16)(result + TPM2B_AUTH_Marshal((TPM2B_AUTH *)&(source->authValue), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->seedValue), buffer, size));
+ result = (UINT16)(result + TPMU_SENSITIVE_COMPOSITE_Marshal((TPMU_SENSITIVE_COMPOSITE *)&(source->sensitive), buffer, size, (UINT32)source->sensitiveType));
+ return result;
+}
+
+
+// Table 2:189 - Definition of TPM2B_SENSITIVE Structure (StructureTable)
+TPM_RC
+TPM2B_SENSITIVE_Unmarshal(
+ TPM2B_SENSITIVE *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ INT32 startSize;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ startSize = *size;
+ result = TPMT_SENSITIVE_Unmarshal((TPMT_SENSITIVE *)&(target->t.sensitiveArea), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if(target->t.size != (startSize - *size)) return TPM_RC_SIZE;
+ return TPM_RC_SUCCESS;
+}
+
+// TPM2B_SENSITIVE_Marshal not referenced
+
+
+// Table 2:190 - Definition of _PRIVATE Structure (StructureTable)
+// _PRIVATE_Unmarshal not referenced
+// _PRIVATE_Marshal not referenced
+
+
+// Table 2:191 - Definition of TPM2B_PRIVATE Structure (StructureTable)
+TPM_RC
+TPM2B_PRIVATE_Unmarshal(
+ TPM2B_PRIVATE *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > sizeof(_PRIVATE))
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_PRIVATE_Marshal(
+ TPM2B_PRIVATE *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:192 - Definition of _ID_OBJECT Structure (StructureTable)
+// _ID_OBJECT_Unmarshal not referenced
+// _ID_OBJECT_Marshal not referenced
+
+
+// Table 2:193 - Definition of TPM2B_ID_OBJECT Structure (StructureTable)
+TPM_RC
+TPM2B_ID_OBJECT_Unmarshal(
+ TPM2B_ID_OBJECT *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > sizeof(_ID_OBJECT))
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.credential), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_ID_OBJECT_Marshal(
+ TPM2B_ID_OBJECT *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.credential), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:194 - Definition of TPM_NV_INDEX Bits (BitsTable)
+// TPM_NV_INDEX_Unmarshal not referenced
+// TPM_NV_INDEX_Marshal not referenced
+
+
+// Table 2:195 - Definition of TPMA_NV Bits (BitsTable)
+TPM_RC
+TPMA_NV_Unmarshal(
+ TPMA_NV *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT32_Unmarshal((UINT32 *)target, buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if(*((UINT32 *)target) & (UINT32)0x01f00380)
+ return TPM_RC_RESERVED_BITS;
+ return TPM_RC_SUCCESS;
+}
+
+// TPMA_NV_Marshal changed to #define
+
+
+// Table 2:196 - Definition of TPMS_NV_PUBLIC Structure (StructureTable)
+TPM_RC
+TPMS_NV_PUBLIC_Unmarshal(
+ TPMS_NV_PUBLIC *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = TPMI_RH_NV_INDEX_Unmarshal((TPMI_RH_NV_INDEX *)&(target->nvIndex), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->nameAlg), buffer, size, 0);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMA_NV_Unmarshal((TPMA_NV *)&(target->attributes), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->authPolicy), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->dataSize), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if( (target->dataSize> MAX_NV_INDEX_SIZE))
+ return TPM_RC_SIZE;
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+TPMS_NV_PUBLIC_Marshal(
+ TPMS_NV_PUBLIC *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPMI_RH_NV_INDEX_Marshal((TPMI_RH_NV_INDEX *)&(source->nvIndex), buffer, size));
+ result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->nameAlg), buffer, size));
+ result = (UINT16)(result + TPMA_NV_Marshal((TPMA_NV *)&(source->attributes), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->authPolicy), buffer, size));
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->dataSize), buffer, size));
+ return result;
+}
+
+
+// Table 2:197 - Definition of TPM2B_NV_PUBLIC Structure (StructureTable)
+TPM_RC
+TPM2B_NV_PUBLIC_Unmarshal(
+ TPM2B_NV_PUBLIC *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ INT32 startSize;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size is zero, then the required structure is missing
+ if(target->t.size == 0)
+ return TPM_RC_SIZE;
+ startSize = *size;
+ result = TPMS_NV_PUBLIC_Unmarshal((TPMS_NV_PUBLIC *)&(target->t.nvPublic), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ if(target->t.size != (startSize - *size)) return TPM_RC_SIZE;
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+TPM2B_NV_PUBLIC_Marshal(
+ TPM2B_NV_PUBLIC *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ BYTE *sizeField = *buffer;
+ // Advance buffer pointer by cononical size of a UINT16
+ *buffer += 2;
+ // Marshal the structure
+ result = (UINT16)(result + TPMS_NV_PUBLIC_Marshal((TPMS_NV_PUBLIC *)&(source->t.nvPublic), buffer, size));
+ // Marshal the size
+ result = (UINT16)(result + UINT16_Marshal(&result, &sizeField, size));
+ return result;
+}
+
+
+// Table 2:198 - Definition of TPM2B_CONTEXT_SENSITIVE Structure (StructureTable)
+// TPM2B_CONTEXT_SENSITIVE_Unmarshal not referenced
+// TPM2B_CONTEXT_SENSITIVE_Marshal not referenced
+
+
+// Table 2:199 - Definition of TPMS_CONTEXT_DATA Structure (StructureTable)
+// TPMS_CONTEXT_DATA_Unmarshal not referenced
+// TPMS_CONTEXT_DATA_Marshal not referenced
+
+
+// Table 2:200 - Definition of TPM2B_CONTEXT_DATA Structure (StructureTable)
+TPM_RC
+TPM2B_CONTEXT_DATA_Unmarshal(
+ TPM2B_CONTEXT_DATA *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(target->t.size == 0)
+ return TPM_RC_SUCCESS;
+ if((target->t.size) > sizeof(TPMS_CONTEXT_DATA))
+ return TPM_RC_SIZE;
+ result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size));
+ return result;
+}
+
+UINT16
+TPM2B_CONTEXT_DATA_Marshal(
+ TPM2B_CONTEXT_DATA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size));
+ // if size equal to 0, the rest of the structure is a zero buffer. Stop processing
+ if(source->t.size == 0)
+ return result;
+ result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size)));
+ return result;
+}
+
+
+// Table 2:201 - Definition of TPMS_CONTEXT Structure (StructureTable)
+TPM_RC
+TPMS_CONTEXT_Unmarshal(
+ TPMS_CONTEXT *target, BYTE **buffer, INT32 *size
+ )
+{
+ TPM_RC result;
+ result = UINT64_Unmarshal((UINT64 *)&(target->sequence), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMI_DH_CONTEXT_Unmarshal((TPMI_DH_CONTEXT *)&(target->savedHandle), buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPMI_RH_HIERARCHY_Unmarshal((TPMI_RH_HIERARCHY *)&(target->hierarchy), buffer, size, 1);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ result = TPM2B_CONTEXT_DATA_Unmarshal((TPM2B_CONTEXT_DATA *)&(target->contextBlob), buffer, size);
+ return result;
+}
+
+UINT16
+TPMS_CONTEXT_Marshal(
+ TPMS_CONTEXT *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->sequence), buffer, size));
+ result = (UINT16)(result + TPMI_DH_CONTEXT_Marshal((TPMI_DH_CONTEXT *)&(source->savedHandle), buffer, size));
+ result = (UINT16)(result + TPMI_RH_HIERARCHY_Marshal((TPMI_RH_HIERARCHY *)&(source->hierarchy), buffer, size));
+ result = (UINT16)(result + TPM2B_CONTEXT_DATA_Marshal((TPM2B_CONTEXT_DATA *)&(source->contextBlob), buffer, size));
+ return result;
+}
+
+
+// Table 2:203 - Definition of TPMS_CREATION_DATA Structure (StructureTable)
+// TPMS_CREATION_DATA_Unmarshal not referenced
+UINT16
+TPMS_CREATION_DATA_Marshal(
+ TPMS_CREATION_DATA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ result = (UINT16)(result + TPML_PCR_SELECTION_Marshal((TPML_PCR_SELECTION *)&(source->pcrSelect), buffer, size));
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->pcrDigest), buffer, size));
+ result = (UINT16)(result + TPMA_LOCALITY_Marshal((TPMA_LOCALITY *)&(source->locality), buffer, size));
+ result = (UINT16)(result + TPM_ALG_ID_Marshal((TPM_ALG_ID *)&(source->parentNameAlg), buffer, size));
+ result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->parentName), buffer, size));
+ result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->parentQualifiedName), buffer, size));
+ result = (UINT16)(result + TPM2B_DATA_Marshal((TPM2B_DATA *)&(source->outsideInfo), buffer, size));
+ return result;
+}
+
+
+// Table 2:204 - Definition of TPM2B_CREATION_DATA Structure (StructureTable)
+// TPM2B_CREATION_DATA_Unmarshal not referenced
+UINT16
+TPM2B_CREATION_DATA_Marshal(
+ TPM2B_CREATION_DATA *source, BYTE **buffer, INT32 *size
+ )
+{
+ UINT16 result = 0;
+ BYTE *sizeField = *buffer;
+ // Advance buffer pointer by cononical size of a UINT16
+ *buffer += 2;
+ // Marshal the structure
+ result = (UINT16)(result + TPMS_CREATION_DATA_Marshal((TPMS_CREATION_DATA *)&(source->t.creationData), buffer, size));
+ // Marshal the size
+ result = (UINT16)(result + UINT16_Marshal(&result, &sizeField, size));
+ return result;
+}
+
+// Array Marshal/Unmarshal for TPMS_TAGGED_PROPERTY
+// TPMS_TAGGED_PROPERTY_Array_Unmarshal not referenced
+UINT16
+TPMS_TAGGED_PROPERTY_Array_Marshal(
+ TPMS_TAGGED_PROPERTY *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPMS_TAGGED_PROPERTY_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+// Array Marshal/Unmarshal for TPMS_ALG_PROPERTY
+// TPMS_ALG_PROPERTY_Array_Unmarshal not referenced
+UINT16
+TPMS_ALG_PROPERTY_Array_Marshal(
+ TPMS_ALG_PROPERTY *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPMS_ALG_PROPERTY_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+// Array Marshal/Unmarshal for TPMS_PCR_SELECTION
+TPM_RC
+TPMS_PCR_SELECTION_Array_Unmarshal(
+ TPMS_PCR_SELECTION *target, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ TPM_RC result;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = TPMS_PCR_SELECTION_Unmarshal(&target[i], buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+TPMS_PCR_SELECTION_Array_Marshal(
+ TPMS_PCR_SELECTION *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPMS_PCR_SELECTION_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+// Array Marshal/Unmarshal for TPMT_HA
+TPM_RC
+TPMT_HA_Array_Unmarshal(
+ TPMT_HA *target, BYTE **buffer, INT32 *size, BOOL flag, INT32 count
+ )
+{
+ TPM_RC result;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = TPMT_HA_Unmarshal(&target[i], buffer, size, flag);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+TPMT_HA_Array_Marshal(
+ TPMT_HA *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPMT_HA_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+// Array Marshal/Unmarshal for BYTE
+TPM_RC
+BYTE_Array_Unmarshal(
+ BYTE *target, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ TPM_RC result;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = BYTE_Unmarshal(&target[i], buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+BYTE_Array_Marshal(
+ BYTE *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + BYTE_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+// Array Marshal/Unmarshal for TPM_HANDLE
+// TPM_HANDLE_Array_Unmarshal not referenced
+UINT16
+TPM_HANDLE_Array_Marshal(
+ TPM_HANDLE *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPM_HANDLE_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+// Array Marshal/Unmarshal for TPMA_CC
+// TPMA_CC_Array_Unmarshal not referenced
+UINT16
+TPMA_CC_Array_Marshal(
+ TPMA_CC *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPMA_CC_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+// Array Marshal/Unmarshal for TPMS_TAGGED_PCR_SELECT
+// TPMS_TAGGED_PCR_SELECT_Array_Unmarshal not referenced
+UINT16
+TPMS_TAGGED_PCR_SELECT_Array_Marshal(
+ TPMS_TAGGED_PCR_SELECT *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPMS_TAGGED_PCR_SELECT_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+// Array Marshal/Unmarshal for TPM_ECC_CURVE
+#ifdef TPM_ALG_ECC
+// TPM_ECC_CURVE_Array_Unmarshal not referenced
+UINT16
+TPM_ECC_CURVE_Array_Marshal(
+ TPM_ECC_CURVE *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPM_ECC_CURVE_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+#endif // TPM_ALG_ECC
+// Array Marshal/Unmarshal for TPM2B_DIGEST
+TPM_RC
+TPM2B_DIGEST_Array_Unmarshal(
+ TPM2B_DIGEST *target, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ TPM_RC result;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = TPM2B_DIGEST_Unmarshal(&target[i], buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+TPM2B_DIGEST_Array_Marshal(
+ TPM2B_DIGEST *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPM2B_DIGEST_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+// Array Marshal/Unmarshal for TPM_CC
+TPM_RC
+TPM_CC_Array_Unmarshal(
+ TPM_CC *target, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ TPM_RC result;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = TPM_CC_Unmarshal(&target[i], buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+TPM_CC_Array_Marshal(
+ TPM_CC *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPM_CC_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+
+// Array Marshal/Unmarshal for TPM_ALG_ID
+TPM_RC
+TPM_ALG_ID_Array_Unmarshal(
+ TPM_ALG_ID *target, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ TPM_RC result;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = TPM_ALG_ID_Unmarshal(&target[i], buffer, size);
+ if(result != TPM_RC_SUCCESS)
+ return result;
+ }
+ return TPM_RC_SUCCESS;
+}
+
+UINT16
+TPM_ALG_ID_Array_Marshal(
+ TPM_ALG_ID *source, BYTE **buffer, INT32 *size, INT32 count
+ )
+{
+ UINT16 result = 0;
+ INT32 i;
+ for(i = 0; i < count; i++) {
+ result = (UINT16)(result + TPM_ALG_ID_Marshal(&source[i], buffer, size));
+ }
+ return result;
+}
+