summaryrefslogtreecommitdiffstats
path: root/tpm-util
diff options
context:
space:
mode:
Diffstat (limited to 'tpm-util')
-rw-r--r--tpm-util/INSTALL8
-rw-r--r--tpm-util/duplicate/crypto_aux.c254
-rw-r--r--tpm-util/duplicate/include/crypto_aux.h60
-rw-r--r--tpm-util/duplicate/include/marshal.h1686
-rw-r--r--tpm-util/duplicate/include/tpm_duplication_aux.h81
-rw-r--r--tpm-util/duplicate/include/util.h38
-rw-r--r--tpm-util/duplicate/main.c281
-rw-r--r--tpm-util/duplicate/marshal.c4870
-rw-r--r--tpm-util/duplicate/sampleMakefile42
-rw-r--r--tpm-util/duplicate/tpm_duplication_aux.c507
-rw-r--r--tpm-util/duplicate/util.c97
-rw-r--r--tpm-util/import/include/tpm_wrapper.h60
-rw-r--r--tpm-util/import/include/util.h25
-rw-r--r--tpm-util/import/main.c244
-rw-r--r--tpm-util/import/sampleMakefile38
-rw-r--r--tpm-util/import/tpm_wrapper.c213
-rw-r--r--tpm-util/import/util.c104
17 files changed, 8606 insertions, 2 deletions
diff --git a/tpm-util/INSTALL b/tpm-util/INSTALL
index a33bc6b..09cb5d4 100644
--- a/tpm-util/INSTALL
+++ b/tpm-util/INSTALL
@@ -1,4 +1,5 @@
-1. Download TPM emulator - ibmtpm974.tar.gz
+1. Download TPM emulator - ibmtpm974.tar.gz
+(Note: Optional. No need to execute this step if the system has real TPM device on it)
a. cd src/
b. make
c. Run tpm_server binary - ./tpm_server –rm
@@ -35,6 +36,7 @@
iii. make && make install
5. Now configure Initialize TPM, configure with Primary key and then save it in TPM’s NV ram
+(Equivalent of script - initandverify/Init_and_create_tpm_primary.sh, you can run that script)
a. Initialize TPM
i. tpm2_startup -clear -T tabrmd –V
b. Take ownership
@@ -47,7 +49,9 @@
i. tpm2_readpublic -H 0x81000011 --opu out_primary_public -T tabrmd –V
f. If all the above commands are successful then TPM emulator, TPM resource manager and TPM tools are working fine
-6. Now compile the TPM duplication tool with "make" command and run it as per instructions. use "./ossl_tpm_util --help" for usage.
+6. Now compile the TPM duplication and import tools with "make" command (after creation of Makefile) and run it as per instructions.
+ use "./ossl_tpm_duplicate --help" for usage.
+ use "./ossl_tpm_import --help" for usage.
7. Note: If you restart tpm_server, then you have to restart TPM resource manager too. And the repeat from step 5.
diff --git a/tpm-util/duplicate/crypto_aux.c b/tpm-util/duplicate/crypto_aux.c
new file mode 100644
index 0000000..2737ded
--- /dev/null
+++ b/tpm-util/duplicate/crypto_aux.c
@@ -0,0 +1,254 @@
+/*
+ * 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 "crypto_aux.h"
+#include "util.h"
+
+UINT32 (*HmacFunctionPtr)( TPMI_ALG_HASH hashAlg, TPM2B *key,TPM2B **bufferList, TPM2B_DIGEST *result ) = OpenSslHmac;
+
+
+int RSA_OAEP_Enc(TPM2B_PUBLIC_KEY_RSA *plain, // plain text to encrypt
+ //Size of plain (0 <= pl <= kl - (2 * hashLen + 2)
+ TPM2B_PUBLIC_KEY_RSA *cipher, // must be same size as key in bytes
+ TPM2B_PUBLIC_KEY_RSA *key, // Key in big endian byte array
+ TPM2B_DATA *encoding_params // Null terminated string like
+ // ((unsigned char*)"DUPLICATE")
+ // length of encoding parameter includes \0
+ // (10 in DUPLICATE case..)
+ )
+{
+ RSA *rsa = NULL;
+ unsigned char encoded[256];
+ int RC;
+ BIGNUM* bne;
+ BIGNUM* n;
+
+ //Encoding
+ RC = RSA_padding_add_PKCS1_OAEP_mgf1(encoded, key->b.size, plain->b.buffer, plain->b.size,
+ encoding_params->b.buffer, encoding_params->b.size, EVP_sha256(), NULL);
+
+ if(RC!=1)goto cleanup;
+
+ // Creating OpenSSL structure with the supplied TPM public:
+ bne = BN_new();
+ RC = BN_set_word(bne,RSA_F4); // the TPM's public exponent (2^16 + 1)
+ if(RC!=1)goto cleanup;
+
+ rsa = RSA_new();
+ RC = RSA_generate_key_ex(rsa, 2048, bne, NULL); // could be done in better way i guess... just for filling up fields..
+ if(RC!=1)goto cleanup;
+
+ // Over-writing the public N:
+ //rsa->n = BN_bin2bn(key->b.buffer, key->b.size, rsa->n);
+ n = BN_bin2bn(key->b.buffer, key->b.size, NULL);
+ RSA_set0_key(rsa,n,NULL, NULL);
+
+ //if(rsa->n == NULL) goto cleanup;
+ if(n == NULL) goto cleanup;
+
+ // Encrypting
+ RC = RSA_public_encrypt(key->b.size, encoded, cipher->b.buffer, rsa, RSA_NO_PADDING);
+
+ //if(RC<0)goto cleanup;
+ cipher->b.size = key->b.size;
+
+cleanup:
+ RSA_free(rsa);
+ BN_free(bne);
+ return RC;
+}
+
+
+
+void AES_128_CFB_enc_dec(
+ TPM2B *in,
+ TPM2B *out,
+ const TPM2B *const key,
+ const TPM2B *const ivIn,
+ TPM2B *ivOut,
+ const TPMI_YES_NO enc)
+{
+ TPM2B_SYM_KEY ivTemp = {{0}};
+ ivTemp.b.size = 16;
+
+ if(ivOut == NULL)
+ ivOut = &(ivTemp.b);
+
+ memccpy(ivOut->buffer, ivIn->buffer, 0, ivIn->size);
+ AES_KEY aes;
+ AES_set_encrypt_key(key->buffer, 128, &aes);
+ int block, j;
+ for(block=0; block < (in->size) ;block+=16)
+ {
+ unsigned char encIV[16];
+ AES_encrypt(ivOut->buffer, encIV, &aes);
+
+ for(j=0;j<16;j++)
+ {
+ if(j+block >= (in->size))
+ ivOut->buffer[j]=0;
+ else if(enc)
+ ivOut->buffer[j] = out->buffer[block+j] = encIV[j]^(in->buffer[block+j]);
+ else
+ {
+ ivOut->buffer[j] = in->buffer[block+j];
+ out->buffer[block+j] = encIV[j]^(in->buffer[block+j]);
+ }
+ }
+ }
+ out->size = in->size;
+
+}
+
+
+UINT32 ChangeEndianDword( UINT32 p )
+{
+ return( ((const UINT32)(((p)& 0xFF) << 24)) | \
+ ((const UINT32)(((p)& 0xFF00) << 8)) | \
+ ((const UINT32)(((p)& 0xFF0000) >> 8)) | \
+ ((const UINT32)(((p)& 0xFF000000) >> 24)));
+}
+
+
+TPM_RC KDFa( TPMI_ALG_HASH hashAlg, TPM2B *key, char *label,
+ TPM2B *contextU, TPM2B *contextV, UINT16 bits, TPM2B_MAX_BUFFER *resultKey )
+{
+
+ TPM2B_DIGEST tmpResult;
+ TPM2B_DIGEST tpm2bLabel, tpm2bBits, tpm2b_i_2;
+ UINT8 *tpm2bBitsPtr = &tpm2bBits.t.buffer[0];
+ UINT8 *tpm2b_i_2Ptr = &tpm2b_i_2.t.buffer[0];
+ TPM2B_DIGEST *bufferList[8];
+ UINT32 bitsSwizzled, i_Swizzled;
+ TPM_RC rval;
+ int i, j;
+ UINT16 bytes = bits / 8;
+
+#ifdef DEBUG
+ DebugPrintf( 0, "KDFA, hashAlg = %4.4x\n", hashAlg );
+ DebugPrintf( 0, "\n\nKDFA, key = \n" );
+ PrintSizedBuffer( key );
+#endif
+
+ resultKey->t .size = 0;
+
+ tpm2b_i_2.t.size = 4;
+
+ tpm2bBits.t.size = 4;
+ bitsSwizzled = ChangeEndianDword( bits );
+ *(UINT32 *)tpm2bBitsPtr = bitsSwizzled;
+
+ for(i = 0; label[i] != 0 ;i++ );
+
+ tpm2bLabel.t.size = i+1;
+ for( i = 0; i < tpm2bLabel.t.size; i++ )
+ {
+ tpm2bLabel.t.buffer[i] = label[i];
+ }
+
+#ifdef DEBUG
+ DebugPrintf( 0, "\n\nKDFA, tpm2bLabel = \n" );
+ PrintSizedBuffer( (TPM2B *)&tpm2bLabel );
+
+ DebugPrintf( 0, "\n\nKDFA, contextU = \n" );
+ PrintSizedBuffer( contextU );
+
+ DebugPrintf( 0, "\n\nKDFA, contextV = \n" );
+ PrintSizedBuffer( contextV );
+#endif
+
+ resultKey->t.size = 0;
+
+ i = 1;
+
+ while( resultKey->t.size < bytes )
+ {
+ // Inner loop
+
+ i_Swizzled = ChangeEndianDword( i );
+ *(UINT32 *)tpm2b_i_2Ptr = i_Swizzled;
+
+ j = 0;
+ bufferList[j++] = (TPM2B_DIGEST *)&(tpm2b_i_2.b);
+ bufferList[j++] = (TPM2B_DIGEST *)&(tpm2bLabel.b);
+ bufferList[j++] = (TPM2B_DIGEST *)contextU;
+ bufferList[j++] = (TPM2B_DIGEST *)contextV;
+ bufferList[j++] = (TPM2B_DIGEST *)&(tpm2bBits.b);
+ bufferList[j++] = (TPM2B_DIGEST *)0;
+#ifdef DEBUG
+ for( j = 0; bufferList[j] != 0; j++ )
+ {
+ DebugPrintf( 0, "\n\nbufferlist[%d]:\n", j );
+ PrintSizedBuffer( &( bufferList[j]->b ) );
+ }
+#endif
+ rval = (*HmacFunctionPtr )( hashAlg, key, (TPM2B **)&( bufferList[0] ), &tmpResult );
+ if( rval != TPM_RC_SUCCESS )
+ {
+ return( rval );
+ }
+
+ ConcatSizedByteBuffer( resultKey, &(tmpResult.b) );
+ }
+
+ // Truncate the result to the desired size.
+ resultKey->t.size = bytes;
+
+#ifdef DEBUG
+ DebugPrintf( 0, "\n\nKDFA, resultKey = \n" );
+ PrintSizedBuffer( &( resultKey->b ) );
+#endif
+
+ return TPM_RC_SUCCESS;
+}
+
+
+UINT32 OpenSslHmac( TPMI_ALG_HASH hashAlg, TPM2B *key,TPM2B **bufferList, TPM2B_DIGEST *result )
+{
+ if(hashAlg != TPM_ALG_SHA256)return -1;
+
+ UINT32 RC = 0;
+ HMAC_CTX *hmac = HMAC_CTX_new();
+ UINT32 resLen=0;
+
+ int i=0;
+
+ HMAC_Init_ex(hmac, key->buffer, key->size, EVP_sha256(), NULL);
+
+ for(i=0;bufferList[i];i++)
+ {
+ HMAC_Update(hmac, bufferList[i]->buffer, bufferList[i]->size);
+ }
+
+ HMAC_Final(hmac, result->b.buffer, &resLen);
+ result->b.size = resLen;
+
+ HMAC_CTX_free(hmac);
+
+ return RC;
+}
+
+void print_buff(char * data, int len, const PBYTE buff)
+{
+ printf("%s \n",data);
+ int i = 0;
+ for(;i<len;i++)
+ printf("0x%02X, ", buff[i]);
+ printf("\n");
+
+}
+
diff --git a/tpm-util/duplicate/include/crypto_aux.h b/tpm-util/duplicate/include/crypto_aux.h
new file mode 100644
index 0000000..272cc39
--- /dev/null
+++ b/tpm-util/duplicate/include/crypto_aux.h
@@ -0,0 +1,60 @@
+/*
+ * 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
+
+#ifndef CRYPTO_AUX
+#define CRYPTO_AUX
+
+#include <string.h>
+#include <sapi/tpm20.h>
+#include <openssl/rsa.h>
+#include <openssl/aes.h>
+#include <openssl/rsa.h>
+#include <openssl/sha.h>
+#include <openssl/hmac.h>
+#include <openssl/evp.h>
+
+typedef BYTE* PBYTE;
+
+int RSA_OAEP_Enc(TPM2B_PUBLIC_KEY_RSA *plain, // plain text to encrypt
+ //Size of plain (0 <= pl <= kl - (2 * hashLen + 2)
+ TPM2B_PUBLIC_KEY_RSA *cipher, // must be same size as key in bytes
+ TPM2B_PUBLIC_KEY_RSA *key, // Key in big endian byte array
+ TPM2B_DATA *encoding_params // Null terminated string like
+ // ((unsigned char*)"DUPLICATE")
+ // length of encoding parameter includes \0
+ // (10 in DUPLICATE case..)
+ );
+
+void AES_128_CFB_enc_dec(
+ TPM2B *in,
+ TPM2B *out,
+ const TPM2B *const key,
+ const TPM2B *const ivIn,
+ TPM2B *ivOut,
+ const TPMI_YES_NO enc);
+
+
+
+TPM_RC KDFa( TPMI_ALG_HASH hashAlg, TPM2B *key, char *label,
+ TPM2B *contextU, TPM2B *contextV, UINT16 bits, TPM2B_MAX_BUFFER *resultKey );
+
+UINT32 OpenSslHmac( TPMI_ALG_HASH hashAlg, TPM2B *key,TPM2B **bufferList, TPM2B_DIGEST *result );
+
+void print_buff(char * data, int len, const PBYTE buff);
+
+#endif
+
diff --git a/tpm-util/duplicate/include/marshal.h b/tpm-util/duplicate/include/marshal.h
new file mode 100644
index 0000000..09d4aed
--- /dev/null
+++ b/tpm-util/duplicate/include/marshal.h
@@ -0,0 +1,1686 @@
+/*
+ * 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
+
+
+#ifndef __MARSHAL_H__
+#define __MARSHAL_H__
+
+#include <sapi/tpm20.h>
+#include <sapi/implementation.h>
+#define pAssert(a) ((void)0)
+#define UNREFERENCED(a) ((void)(a))
+
+#if NO_AUTO_ALIGN == YES || LITTLE_ENDIAN_TPM == YES
+#define BYTE_ARRAY_TO_UINT8(b) (UINT8)((b)[0])
+
+#define BYTE_ARRAY_TO_UINT16(b) (UINT16)( ((b)[0] << 8) \
+ + (b)[1])
+
+#define BYTE_ARRAY_TO_UINT32(b) (UINT32)( ((b)[0] << 24) \
+ + ((b)[1] << 16) \
+ + ((b)[2] << 8 ) \
+ + (b)[3])
+
+#define BYTE_ARRAY_TO_UINT64(b) (UINT64)( ((UINT64)(b)[0] << 56) \
+ + ((UINT64)(b)[1] << 48) \
+ + ((UINT64)(b)[2] << 40) \
+ + ((UINT64)(b)[3] << 32) \
+ + ((UINT64)(b)[4] << 24) \
+ + ((UINT64)(b)[5] << 16) \
+ + ((UINT64)(b)[6] << 8) \
+ + (UINT64)(b)[7])
+
+// Disaggregate a UINT into a byte array
+#define UINT8_TO_BYTE_ARRAY(i, b) ((b)[0] = (BYTE)(i), i)
+
+#define UINT16_TO_BYTE_ARRAY(i, b) ((b)[0] = (BYTE)((i) >> 8), \
+ (b)[1] = (BYTE) (i), \
+ (i))
+
+#define UINT32_TO_BYTE_ARRAY(i, b) ((b)[0] = (BYTE)((i) >> 24), \
+ (b)[1] = (BYTE)((i) >> 16), \
+ (b)[2] = (BYTE)((i) >> 8), \
+ (b)[3] = (BYTE) (i), \
+ (i))
+
+#define UINT64_TO_BYTE_ARRAY(i, b) ((b)[0] = (BYTE)((i) >> 56), \
+ (b)[1] = (BYTE)((i) >> 48), \
+ (b)[2] = (BYTE)((i) >> 40), \
+ (b)[3] = (BYTE)((i) >> 32), \
+ (b)[4] = (BYTE)((i) >> 24), \
+ (b)[5] = (BYTE)((i) >> 16), \
+ (b)[6] = (BYTE)((i) >> 8), \
+ (b)[7] = (BYTE) (i), \
+ (i))
+
+#else
+
+// the big-endian macros for machines that allow unaligned memory access
+// Aggregate a byte array into a UINT
+#define BYTE_ARRAY_TO_UINT8(b) *((UINT8 *)(b))
+#define BYTE_ARRAY_TO_UINT16(b) *((UINT16 *)(b))
+#define BYTE_ARRAY_TO_UINT32(b) *((UINT32 *)(b))
+#define BYTE_ARRAY_TO_UINT64(b) *((UINT64 *)(b))
+
+// Disaggregate a UINT into a byte array
+
+
+#define UINT8_TO_BYTE_ARRAY(i, b) (*((UINT8 *)(b)) = (i))
+#define UINT16_TO_BYTE_ARRAY(i, b) (*((UINT16 *)(b)) = (i))
+#define UINT32_TO_BYTE_ARRAY(i, b) (*((UINT32 *)(b)) = (i))
+#define UINT64_TO_BYTE_ARRAY(i, b) (*((UINT64 *)(b)) = (i))
+
+
+#endif // NO_AUTO_ALIGN == YES
+
+
+
+
+// Table 2:3 - Definition of Base Types (BaseTypes)
+// UINT8 definition from table 2:3
+TPM_RC
+UINT8_Unmarshal(UINT8 *target, BYTE **buffer, INT32 *size);
+UINT16
+UINT8_Marshal(UINT8 *source, BYTE **buffer, INT32 *size);
+
+// BYTE definition from table 2:3
+#define BYTE_Unmarshal(target, buffer, size) \
+ UINT8_Unmarshal((UINT8 *)(target), buffer, size)
+#define BYTE_Marshal(source, buffer, size) \
+ UINT8_Marshal((UINT8 *)(source), buffer, size)
+// INT8 definition from table 2:3
+#define INT8_Unmarshal(target, buffer, size) \
+ UINT8_Unmarshal((UINT8 *)(target), buffer, size)
+// INT8_Marshal not referenced
+// UINT16 definition from table 2:3
+TPM_RC
+UINT16_Unmarshal(UINT16 *target, BYTE **buffer, INT32 *size);
+UINT16
+UINT16_Marshal(UINT16 *source, BYTE **buffer, INT32 *size);
+
+// 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);
+UINT16
+UINT32_Marshal(UINT32 *source, BYTE **buffer, INT32 *size);
+
+// INT32 definition from table 2:3
+#define INT32_Unmarshal(target, buffer, size) \
+ UINT32_Unmarshal((UINT32 *)(target), buffer, size)
+// INT32_Marshal not referenced
+// UINT64 definition from table 2:3
+TPM_RC
+UINT64_Unmarshal(UINT64 *target, BYTE **buffer, INT32 *size);
+UINT16
+UINT64_Marshal(UINT64 *source, BYTE **buffer, INT32 *size);
+
+// 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
+#define TPM_KEY_BITS_Unmarshal(target, buffer, size) \
+ UINT16_Unmarshal((UINT16 *)(target), buffer, size)
+#define TPM_KEY_BITS_Marshal(source, buffer, size) \
+ UINT16_Marshal((UINT16 *)(source), buffer, size)
+
+
+// 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
+#define TPM_GENERATED_Marshal(source, buffer, size) \
+ UINT32_Marshal((UINT32 *)(source), buffer, size)
+
+
+// Table 2:9 - Definition of TPM_ALG_ID Constants (ConstantsTable)
+#define TPM_ALG_ID_Unmarshal(target, buffer, size) \
+ UINT16_Unmarshal((UINT16 *)(target), buffer, size)
+#define TPM_ALG_ID_Marshal(source, buffer, size) \
+ UINT16_Marshal((UINT16 *)(source), buffer, size)
+
+
+// Table 2:10 - Definition of TPM_ECC_CURVE Constants (ConstantsTable)
+#ifdef TPM_ALG_ECC
+#define TPM_ECC_CURVE_Unmarshal(target, buffer, size) \
+ UINT16_Unmarshal((UINT16 *)(target), buffer, size)
+#define TPM_ECC_CURVE_Marshal(source, buffer, size) \
+ UINT16_Marshal((UINT16 *)(source), buffer, size)
+#endif // TPM_ALG_ECC
+
+
+// Table 2:13 - Definition of TPM_CC Constants (ConstantsTable)
+#define TPM_CC_Unmarshal(target, buffer, size) \
+ UINT32_Unmarshal((UINT32 *)(target), buffer, size)
+#define TPM_CC_Marshal(source, buffer, size) \
+ UINT32_Marshal((UINT32 *)(source), buffer, size)
+
+
+// Table 2:17 - Definition of TPM_RC Constants (ConstantsTable)
+// TPM_RC_Unmarshal not referenced
+#define TPM_RC_Marshal(source, buffer, size) \
+ UINT32_Marshal((UINT32 *)(source), buffer, size)
+
+
+// Table 2:18 - Definition of TPM_CLOCK_ADJUST Constants (ConstantsTable)
+TPM_RC
+TPM_CLOCK_ADJUST_Unmarshal(TPM_CLOCK_ADJUST *target, BYTE **buffer, INT32 *size);
+
+// 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_EO_Marshal not referenced
+
+
+// Table 2:20 - Definition of TPM_ST Constants (ConstantsTable)
+#define TPM_ST_Unmarshal(target, buffer, size) \
+ UINT16_Unmarshal((UINT16 *)(target), buffer, size)
+#define TPM_ST_Marshal(source, buffer, size) \
+ UINT16_Marshal((UINT16 *)(source), buffer, size)
+
+
+// Table 2:21 - Definition of TPM_SU Constants (ConstantsTable)
+TPM_RC
+TPM_SU_Unmarshal(TPM_SU *target, BYTE **buffer, INT32 *size);
+
+// 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_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);
+
+#define TPM_CAP_Marshal(source, buffer, size) \
+ UINT32_Marshal((UINT32 *)(source), buffer, size)
+
+
+// Table 2:24 - Definition of TPM_PT Constants (ConstantsTable)
+// TPM_PT_Unmarshal not referenced
+#define TPM_PT_Marshal(source, buffer, size) \
+ UINT32_Marshal((UINT32 *)(source), buffer, size)
+
+
+// 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
+#define TPM_HANDLE_Unmarshal(target, buffer, size) \
+ UINT32_Unmarshal((UINT32 *)(target), buffer, size)
+#define TPM_HANDLE_Marshal(source, buffer, size) \
+ UINT32_Marshal((UINT32 *)(source), buffer, size)
+
+
+// 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
+#define TPMA_ALGORITHM_Marshal(source, buffer, size) \
+ UINT32_Marshal((UINT32 *)(source), buffer, size)
+
+
+// Table 2:32 - Definition of TPMA_OBJECT Bits (BitsTable)
+TPM_RC
+TPMA_OBJECT_Unmarshal(TPMA_OBJECT *target, BYTE **buffer, INT32 *size);
+
+#define TPMA_OBJECT_Marshal(source, buffer, size) \
+ UINT32_Marshal((UINT32 *)(source), buffer, size)
+
+
+// Table 2:33 - Definition of TPMA_SESSION Bits (BitsTable)
+TPM_RC
+TPMA_SESSION_Unmarshal(TPMA_SESSION *target, BYTE **buffer, INT32 *size);
+
+#define TPMA_SESSION_Marshal(source, buffer, size) \
+ UINT8_Marshal((UINT8 *)(source), buffer, size)
+
+
+// Table 2:34 - Definition of TPMA_LOCALITY Bits (BitsTable)
+#define TPMA_LOCALITY_Unmarshal(target, buffer, size) \
+ UINT8_Unmarshal((UINT8 *)(target), buffer, size)
+#define TPMA_LOCALITY_Marshal(source, buffer, size) \
+ UINT8_Marshal((UINT8 *)(source), buffer, size)
+
+
+// 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
+#define TPMA_CC_Marshal(source, buffer, size) \
+ UINT32_Marshal((UINT32 *)(source), buffer, size)
+
+
+// Table 2:39 - Definition of TPMI_YES_NO Type (TypeTable)
+TPM_RC
+TPMI_YES_NO_Unmarshal(TPMI_YES_NO *target, BYTE **buffer, INT32 *size);
+
+#define TPMI_YES_NO_Marshal(source, buffer, size) \
+ BYTE_Marshal((BYTE *)(source), buffer, size)
+
+
+// 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);
+
+#define TPMI_DH_OBJECT_Marshal(source, buffer, size) \
+ TPM_HANDLE_Marshal((TPM_HANDLE *)(source), buffer, size)
+
+
+// Table 2:41 - Definition of TPMI_DH_PERSISTENT Type (TypeTable)
+TPM_RC
+TPMI_DH_PERSISTENT_Unmarshal(TPMI_DH_PERSISTENT *target, BYTE **buffer, INT32 *size);
+
+// 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);
+
+// 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);
+
+// 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);
+
+#define TPMI_SH_AUTH_SESSION_Marshal(source, buffer, size) \
+ TPM_HANDLE_Marshal((TPM_HANDLE *)(source), buffer, size)
+
+
+// Table 2:45 - Definition of TPMI_SH_HMAC Type (TypeTable)
+TPM_RC
+TPMI_SH_HMAC_Unmarshal(TPMI_SH_HMAC *target, BYTE **buffer, INT32 *size);
+
+// 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);
+
+// 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);
+
+#define TPMI_DH_CONTEXT_Marshal(source, buffer, size) \
+ TPM_HANDLE_Marshal((TPM_HANDLE *)(source), buffer, size)
+
+
+// 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);
+
+#define TPMI_RH_HIERARCHY_Marshal(source, buffer, size) \
+ TPM_HANDLE_Marshal((TPM_HANDLE *)(source), buffer, size)
+
+
+// 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);
+
+// 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);
+
+// 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);
+
+// 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);
+
+// 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);
+
+// 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);
+
+// 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);
+
+// 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);
+
+// 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);
+
+#define TPMI_RH_NV_INDEX_Marshal(source, buffer, size) \
+ TPM_HANDLE_Marshal((TPM_HANDLE *)(source), buffer, size)
+
+
+// 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);
+
+#define TPMI_ALG_HASH_Marshal(source, buffer, size) \
+ TPM_ALG_ID_Marshal((TPM_ALG_ID *)(source), buffer, size)
+
+
+// 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);
+
+// 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);
+
+#define TPMI_ALG_SYM_OBJECT_Marshal(source, buffer, size) \
+ TPM_ALG_ID_Marshal((TPM_ALG_ID *)(source), buffer, size)
+
+
+// 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);
+
+#define TPMI_ALG_SYM_MODE_Marshal(source, buffer, size) \
+ TPM_ALG_ID_Marshal((TPM_ALG_ID *)(source), buffer, size)
+
+
+// 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);
+
+#define TPMI_ALG_KDF_Marshal(source, buffer, size) \
+ TPM_ALG_ID_Marshal((TPM_ALG_ID *)(source), buffer, size)
+
+
+// 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);
+
+#define TPMI_ALG_SIG_SCHEME_Marshal(source, buffer, size) \
+ TPM_ALG_ID_Marshal((TPM_ALG_ID *)(source), buffer, size)
+
+
+// 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);
+
+// 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);
+
+// TPMI_ST_COMMAND_TAG_Marshal not referenced
+TPM_RC
+TPMS_EMPTY_Unmarshal(TPMS_EMPTY *target, BYTE **buffer, INT32 *size);
+UINT16
+TPMS_EMPTY_Marshal(TPMS_EMPTY *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPMU_HA_Marshal(TPMU_HA *source, BYTE **buffer, INT32 *size, UINT32 selector);
+
+
+// Table 2:71 - Definition of TPMT_HA Structure (StructureTable)
+TPM_RC
+TPMT_HA_Unmarshal(TPMT_HA *target, BYTE **buffer, INT32 *size, BOOL flag);
+UINT16
+TPMT_HA_Marshal(TPMT_HA *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:72 - Definition of TPM2B_DIGEST Structure (StructureTable)
+TPM_RC
+TPM2B_DIGEST_Unmarshal(TPM2B_DIGEST *target, BYTE **buffer, INT32 *size);
+UINT16
+TPM2B_DIGEST_Marshal(TPM2B_DIGEST *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:73 - Definition of TPM2B_DATA Structure (StructureTable)
+TPM_RC
+TPM2B_DATA_Unmarshal(TPM2B_DATA *target, BYTE **buffer, INT32 *size);
+UINT16
+TPM2B_DATA_Marshal(TPM2B_DATA *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:74 - Definition of Types for TPM2B_NONCE (TypesTable)
+// TPM2B_DIGEST definition from table 2:74
+#define TPM2B_NONCE_Unmarshal(target, buffer, size) \
+ TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)(target), buffer, size)
+#define TPM2B_NONCE_Marshal(source, buffer, size) \
+ TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)(source), buffer, size)
+
+
+// Table 2:75 - Definition of Types for TPM2B_AUTH (TypesTable)
+// TPM2B_DIGEST definition from table 2:75
+#define TPM2B_AUTH_Unmarshal(target, buffer, size) \
+ TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)(target), buffer, size)
+#define TPM2B_AUTH_Marshal(source, buffer, size) \
+ TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)(source), buffer, size)
+
+
+// Table 2:76 - Definition of Types for TPM2B_OPERAND (TypesTable)
+// TPM2B_DIGEST definition from table 2:76
+#define TPM2B_OPERAND_Unmarshal(target, buffer, size) \
+ TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)(target), buffer, size)
+// 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);
+
+// 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);
+UINT16
+TPM2B_MAX_BUFFER_Marshal(TPM2B_MAX_BUFFER *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPM2B_MAX_NV_BUFFER_Marshal(TPM2B_MAX_NV_BUFFER *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:80 - Definition of TPM2B_TIMEOUT Structure (StructureTable)
+TPM_RC
+TPM2B_TIMEOUT_Unmarshal(TPM2B_TIMEOUT *target, BYTE **buffer, INT32 *size);
+UINT16
+TPM2B_TIMEOUT_Marshal(TPM2B_TIMEOUT *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:81 - Definition of TPM2B_IV Structure (StructureTable)
+TPM_RC
+TPM2B_IV_Unmarshal(TPM2B_IV *target, BYTE **buffer, INT32 *size);
+UINT16
+TPM2B_IV_Marshal(TPM2B_IV *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPM2B_NAME_Marshal(TPM2B_NAME *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPMS_PCR_SELECTION_Marshal(TPMS_PCR_SELECTION *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:88 - Definition of TPMT_TK_CREATION Structure (StructureTable)
+TPM_RC
+TPMT_TK_CREATION_Unmarshal(TPMT_TK_CREATION *target, BYTE **buffer, INT32 *size);
+UINT16
+TPMT_TK_CREATION_Marshal(TPMT_TK_CREATION *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:89 - Definition of TPMT_TK_VERIFIED Structure (StructureTable)
+TPM_RC
+TPMT_TK_VERIFIED_Unmarshal(TPMT_TK_VERIFIED *target, BYTE **buffer, INT32 *size);
+UINT16
+TPMT_TK_VERIFIED_Marshal(TPMT_TK_VERIFIED *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:90 - Definition of TPMT_TK_AUTH Structure (StructureTable)
+TPM_RC
+TPMT_TK_AUTH_Unmarshal(TPMT_TK_AUTH *target, BYTE **buffer, INT32 *size);
+UINT16
+TPMT_TK_AUTH_Marshal(TPMT_TK_AUTH *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:91 - Definition of TPMT_TK_HASHCHECK Structure (StructureTable)
+TPM_RC
+TPMT_TK_HASHCHECK_Unmarshal(TPMT_TK_HASHCHECK *target, BYTE **buffer, INT32 *size);
+UINT16
+TPMT_TK_HASHCHECK_Marshal(TPMT_TK_HASHCHECK *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// Table 2:95 - Definition of TPML_CC Structure (StructureTable)
+TPM_RC
+TPML_CC_Unmarshal(TPML_CC *target, BYTE **buffer, INT32 *size);
+UINT16
+TPML_CC_Marshal(TPML_CC *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+
+
+// Table 2:97 - Definition of TPML_ALG Structure (StructureTable)
+TPM_RC
+TPML_ALG_Unmarshal(TPML_ALG *target, BYTE **buffer, INT32 *size);
+UINT16
+TPML_ALG_Marshal(TPML_ALG *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+
+
+// Table 2:99 - Definition of TPML_DIGEST Structure (StructureTable)
+TPM_RC
+TPML_DIGEST_Unmarshal(TPML_DIGEST *target, BYTE **buffer, INT32 *size);
+UINT16
+TPML_DIGEST_Marshal(TPML_DIGEST *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:100 - Definition of TPML_DIGEST_VALUES Structure (StructureTable)
+TPM_RC
+TPML_DIGEST_VALUES_Unmarshal(TPML_DIGEST_VALUES *target, BYTE **buffer, INT32 *size);
+UINT16
+TPML_DIGEST_VALUES_Marshal(TPML_DIGEST_VALUES *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPML_PCR_SELECTION_Marshal(TPML_PCR_SELECTION *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+#endif // TPM_ALG_ECC
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// Table 2:118 - Definition of TPMI_ST_ATTEST Type (TypeTable)
+// TPMI_ST_ATTEST_Unmarshal not referenced
+#define TPMI_ST_ATTEST_Marshal(source, buffer, size) \
+ TPM_ST_Marshal((TPM_ST *)(source), buffer, size)
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+
+// 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);
+
+#define TPMI_AES_KEY_BITS_Marshal(source, buffer, size) \
+ TPM_KEY_BITS_Marshal((TPM_KEY_BITS *)(source), buffer, size)
+#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);
+
+#define TPMI_SM4_KEY_BITS_Marshal(source, buffer, size) \
+ TPM_KEY_BITS_Marshal((TPM_KEY_BITS *)(source), buffer, size)
+#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);
+
+#define TPMI_CAMELLIA_KEY_BITS_Marshal(source, buffer, size) \
+ TPM_KEY_BITS_Marshal((TPM_KEY_BITS *)(source), buffer, size)
+#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);
+UINT16
+TPMU_SYM_KEY_BITS_Marshal(TPMU_SYM_KEY_BITS *source, BYTE **buffer, INT32 *size, UINT32 selector);
+
+
+// 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);
+UINT16
+TPMU_SYM_MODE_Marshal(TPMU_SYM_MODE *source, BYTE **buffer, INT32 *size, UINT32 selector);
+
+
+// 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);
+
+// 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);
+UINT16
+TPMT_SYM_DEF_OBJECT_Marshal(TPMT_SYM_DEF_OBJECT *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:130 - Definition of TPM2B_SYM_KEY Structure (StructureTable)
+TPM_RC
+TPM2B_SYM_KEY_Unmarshal(TPM2B_SYM_KEY *target, BYTE **buffer, INT32 *size);
+UINT16
+TPM2B_SYM_KEY_Marshal(TPM2B_SYM_KEY *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:131 - Definition of TPMS_SYMCIPHER_PARMS Structure (StructureTable)
+#define TPMS_SYMCIPHER_PARMS_Unmarshal(target, buffer, size) \
+ TPMT_SYM_DEF_OBJECT_Unmarshal((TPMT_SYM_DEF_OBJECT *)&((target)->sym), buffer, size, 0)
+#define TPMS_SYMCIPHER_PARMS_Marshal(source, buffer, size) \
+ TPMT_SYM_DEF_OBJECT_Marshal((TPMT_SYM_DEF_OBJECT *)&((source)->sym), buffer, size)
+
+
+// Table 2:132 - Definition of TPM2B_SENSITIVE_DATA Structure (StructureTable)
+TPM_RC
+TPM2B_SENSITIVE_DATA_Unmarshal(TPM2B_SENSITIVE_DATA *target, BYTE **buffer, INT32 *size);
+UINT16
+TPM2B_SENSITIVE_DATA_Marshal(TPM2B_SENSITIVE_DATA *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:133 - Definition of TPMS_SENSITIVE_CREATE Structure (StructureTable)
+TPM_RC
+TPMS_SENSITIVE_CREATE_Unmarshal(TPMS_SENSITIVE_CREATE *target, BYTE **buffer, INT32 *size);
+
+// 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);
+
+// TPM2B_SENSITIVE_CREATE_Marshal not referenced
+
+
+// Table 2:135 - Definition of TPMS_SCHEME_HASH Structure (StructureTable)
+#define TPMS_SCHEME_HASH_Unmarshal(target, buffer, size) \
+ TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&((target)->hashAlg), buffer, size, 0)
+#define TPMS_SCHEME_HASH_Marshal(source, buffer, size) \
+ TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&((source)->hashAlg), buffer, size)
+
+
+// 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);
+UINT16
+TPMS_SCHEME_ECDAA_Marshal(TPMS_SCHEME_ECDAA *source, BYTE **buffer, INT32 *size);
+
+#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);
+
+#define TPMI_ALG_KEYEDHASH_SCHEME_Marshal(source, buffer, size) \
+ TPM_ALG_ID_Marshal((TPM_ALG_ID *)(source), buffer, size)
+
+
+// Table 2:138 - Definition of Types for HMAC_SIG_SCHEME (TypesTable)
+// TPMS_SCHEME_HASH definition from table 2:138
+#define TPMS_SCHEME_HMAC_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_SCHEME_HMAC_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+
+
+// 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);
+UINT16
+TPMS_SCHEME_XOR_Marshal(TPMS_SCHEME_XOR *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPMU_SCHEME_KEYEDHASH_Marshal(TPMU_SCHEME_KEYEDHASH *source, BYTE **buffer, INT32 *size, UINT32 selector);
+
+
+// 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);
+UINT16
+TPMT_KEYEDHASH_SCHEME_Marshal(TPMT_KEYEDHASH_SCHEME *source, BYTE **buffer, INT32 *size);
+
+
+// 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
+#define TPMS_SIG_SCHEME_RSASSA_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_SIG_SCHEME_RSASSA_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+#endif // TPM_ALG_RSA
+// TPMS_SCHEME_HASH definition from table 2:142
+#ifdef TPM_ALG_RSA
+#define TPMS_SIG_SCHEME_RSAPSS_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_SIG_SCHEME_RSAPSS_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+#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
+#define TPMS_SIG_SCHEME_ECDSA_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_SIG_SCHEME_ECDSA_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+#endif // TPM_ALG_ECC
+// TPMS_SCHEME_HASH definition from table 2:143
+#ifdef TPM_ALG_ECC
+#define TPMS_SIG_SCHEME_SM2_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_SIG_SCHEME_SM2_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+#endif // TPM_ALG_ECC
+// TPMS_SCHEME_HASH definition from table 2:143
+#ifdef TPM_ALG_ECC
+#define TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_SIG_SCHEME_ECSCHNORR_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+#endif // TPM_ALG_ECC
+// TPMS_SCHEME_ECDAA definition from table 2:143
+#ifdef TPM_ALG_ECC
+#define TPMS_SIG_SCHEME_ECDAA_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_ECDAA_Unmarshal((TPMS_SCHEME_ECDAA *)(target), buffer, size)
+#define TPMS_SIG_SCHEME_ECDAA_Marshal(source, buffer, size) \
+ TPMS_SCHEME_ECDAA_Marshal((TPMS_SCHEME_ECDAA *)(source), buffer, size)
+#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);
+
+// 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);
+
+// 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
+#define TPMS_ENC_SCHEME_OAEP_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_ENC_SCHEME_OAEP_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+#endif // TPM_ALG_RSA
+// TPMS_EMPTY definition from table 2:146
+#ifdef TPM_ALG_RSA
+#define TPMS_ENC_SCHEME_RSAES_Unmarshal(target, buffer, size) \
+ TPMS_EMPTY_Unmarshal((TPMS_EMPTY *)(target), buffer, size)
+#define TPMS_ENC_SCHEME_RSAES_Marshal(source, buffer, size) \
+ TPMS_EMPTY_Marshal((TPMS_EMPTY *)(source), buffer, size)
+#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
+#define TPMS_KEY_SCHEME_ECDH_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_KEY_SCHEME_ECDH_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+#endif // TPM_ALG_ECC
+// TPMS_SCHEME_HASH definition from table 2:147
+#ifdef TPM_ALG_ECC
+#define TPMS_KEY_SCHEME_ECMQV_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_KEY_SCHEME_ECMQV_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+#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
+#define TPMS_SCHEME_MGF1_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_SCHEME_MGF1_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+// TPMS_SCHEME_HASH definition from table 2:148
+#define TPMS_SCHEME_KDF1_SP800_56A_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_SCHEME_KDF1_SP800_56A_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+// TPMS_SCHEME_HASH definition from table 2:148
+#define TPMS_SCHEME_KDF2_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_SCHEME_KDF2_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+// TPMS_SCHEME_HASH definition from table 2:148
+#define TPMS_SCHEME_KDF1_SP800_108_Unmarshal(target, buffer, size) \
+ TPMS_SCHEME_HASH_Unmarshal((TPMS_SCHEME_HASH *)(target), buffer, size)
+#define TPMS_SCHEME_KDF1_SP800_108_Marshal(source, buffer, size) \
+ TPMS_SCHEME_HASH_Marshal((TPMS_SCHEME_HASH *)(source), buffer, size)
+
+
+// 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);
+UINT16
+TPMU_KDF_SCHEME_Marshal(TPMU_KDF_SCHEME *source, BYTE **buffer, INT32 *size, UINT32 selector);
+
+
+// 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);
+UINT16
+TPMT_KDF_SCHEME_Marshal(TPMT_KDF_SCHEME *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPMU_ASYM_SCHEME_Marshal(TPMU_ASYM_SCHEME *source, BYTE **buffer, INT32 *size, UINT32 selector);
+
+
+// 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);
+
+#define TPMI_ALG_RSA_SCHEME_Marshal(source, buffer, size) \
+ TPM_ALG_ID_Marshal((TPM_ALG_ID *)(source), buffer, size)
+#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);
+UINT16
+TPMT_RSA_SCHEME_Marshal(TPMT_RSA_SCHEME *source, BYTE **buffer, INT32 *size);
+
+#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);
+
+// 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);
+
+// 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);
+UINT16
+TPM2B_PUBLIC_KEY_RSA_Marshal(TPM2B_PUBLIC_KEY_RSA *source, BYTE **buffer, INT32 *size);
+
+#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);
+
+#define TPMI_RSA_KEY_BITS_Marshal(source, buffer, size) \
+ TPM_KEY_BITS_Marshal((TPM_KEY_BITS *)(source), buffer, size)
+#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);
+UINT16
+TPM2B_PRIVATE_KEY_RSA_Marshal(TPM2B_PRIVATE_KEY_RSA *source, BYTE **buffer, INT32 *size);
+
+#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);
+UINT16
+TPM2B_ECC_PARAMETER_Marshal(TPM2B_ECC_PARAMETER *source, BYTE **buffer, INT32 *size);
+
+#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);
+UINT16
+TPMS_ECC_POINT_Marshal(TPMS_ECC_POINT *source, BYTE **buffer, INT32 *size);
+
+#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);
+UINT16
+TPM2B_ECC_POINT_Marshal(TPM2B_ECC_POINT *source, BYTE **buffer, INT32 *size);
+
+#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);
+
+#define TPMI_ALG_ECC_SCHEME_Marshal(source, buffer, size) \
+ TPM_ALG_ID_Marshal((TPM_ALG_ID *)(source), buffer, size)
+#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);
+
+#define TPMI_ECC_CURVE_Marshal(source, buffer, size) \
+ TPM_ECC_CURVE_Marshal((TPM_ECC_CURVE *)(source), buffer, size)
+#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);
+UINT16
+TPMT_ECC_SCHEME_Marshal(TPMT_ECC_SCHEME *source, BYTE **buffer, INT32 *size);
+
+#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);
+
+#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);
+UINT16
+TPMS_SIGNATURE_RSA_Marshal(TPMS_SIGNATURE_RSA *source, BYTE **buffer, INT32 *size);
+
+#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
+#define TPMS_SIGNATURE_RSASSA_Unmarshal(target, buffer, size) \
+ TPMS_SIGNATURE_RSA_Unmarshal((TPMS_SIGNATURE_RSA *)(target), buffer, size)
+#define TPMS_SIGNATURE_RSASSA_Marshal(source, buffer, size) \
+ TPMS_SIGNATURE_RSA_Marshal((TPMS_SIGNATURE_RSA *)(source), buffer, size)
+#endif // TPM_ALG_RSA
+// TPMS_SIGNATURE_RSA definition from table 2:169
+#ifdef TPM_ALG_RSA
+#define TPMS_SIGNATURE_RSAPSS_Unmarshal(target, buffer, size) \
+ TPMS_SIGNATURE_RSA_Unmarshal((TPMS_SIGNATURE_RSA *)(target), buffer, size)
+#define TPMS_SIGNATURE_RSAPSS_Marshal(source, buffer, size) \
+ TPMS_SIGNATURE_RSA_Marshal((TPMS_SIGNATURE_RSA *)(source), buffer, size)
+#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);
+UINT16
+TPMS_SIGNATURE_ECC_Marshal(TPMS_SIGNATURE_ECC *source, BYTE **buffer, INT32 *size);
+
+#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
+#define TPMS_SIGNATURE_ECDSA_Unmarshal(target, buffer, size) \
+ TPMS_SIGNATURE_ECC_Unmarshal((TPMS_SIGNATURE_ECC *)(target), buffer, size)
+#define TPMS_SIGNATURE_ECDSA_Marshal(source, buffer, size) \
+ TPMS_SIGNATURE_ECC_Marshal((TPMS_SIGNATURE_ECC *)(source), buffer, size)
+#endif // TPM_ALG_ECC
+// TPMS_SIGNATURE_ECC definition from table 2:171
+#ifdef TPM_ALG_ECC
+#define TPMS_SIGNATURE_SM2_Unmarshal(target, buffer, size) \
+ TPMS_SIGNATURE_ECC_Unmarshal((TPMS_SIGNATURE_ECC *)(target), buffer, size)
+#define TPMS_SIGNATURE_SM2_Marshal(source, buffer, size) \
+ TPMS_SIGNATURE_ECC_Marshal((TPMS_SIGNATURE_ECC *)(source), buffer, size)
+#endif // TPM_ALG_ECC
+// TPMS_SIGNATURE_ECC definition from table 2:171
+#ifdef TPM_ALG_ECC
+#define TPMS_SIGNATURE_ECSCHNORR_Unmarshal(target, buffer, size) \
+ TPMS_SIGNATURE_ECC_Unmarshal((TPMS_SIGNATURE_ECC *)(target), buffer, size)
+#define TPMS_SIGNATURE_ECSCHNORR_Marshal(source, buffer, size) \
+ TPMS_SIGNATURE_ECC_Marshal((TPMS_SIGNATURE_ECC *)(source), buffer, size)
+#endif // TPM_ALG_ECC
+// TPMS_SIGNATURE_ECC definition from table 2:171
+#ifdef TPM_ALG_ECC
+#define TPMS_SIGNATURE_ECDAA_Unmarshal(target, buffer, size) \
+ TPMS_SIGNATURE_ECC_Unmarshal((TPMS_SIGNATURE_ECC *)(target), buffer, size)
+#define TPMS_SIGNATURE_ECDAA_Marshal(source, buffer, size) \
+ TPMS_SIGNATURE_ECC_Marshal((TPMS_SIGNATURE_ECC *)(source), buffer, size)
+#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);
+UINT16
+TPMU_SIGNATURE_Marshal(TPMU_SIGNATURE *source, BYTE **buffer, INT32 *size, UINT32 selector);
+
+
+// Table 2:173 - Definition of TPMT_SIGNATURE Structure (StructureTable)
+TPM_RC
+TPMT_SIGNATURE_Unmarshal(TPMT_SIGNATURE *target, BYTE **buffer, INT32 *size, BOOL flag);
+UINT16
+TPMT_SIGNATURE_Marshal(TPMT_SIGNATURE *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPM2B_ENCRYPTED_SECRET_Marshal(TPM2B_ENCRYPTED_SECRET *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:176 - Definition of TPMI_ALG_PUBLIC Type (TypeTable)
+TPM_RC
+TPMI_ALG_PUBLIC_Unmarshal(TPMI_ALG_PUBLIC *target, BYTE **buffer, INT32 *size);
+
+#define TPMI_ALG_PUBLIC_Marshal(source, buffer, size) \
+ TPM_ALG_ID_Marshal((TPM_ALG_ID *)(source), buffer, size)
+
+
+// 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);
+UINT16
+TPMU_PUBLIC_ID_Marshal(TPMU_PUBLIC_ID *source, BYTE **buffer, INT32 *size, UINT32 selector);
+
+
+// Table 2:178 - Definition of TPMS_KEYEDHASH_PARMS Structure (StructureTable)
+#define TPMS_KEYEDHASH_PARMS_Unmarshal(target, buffer, size) \
+ TPMT_KEYEDHASH_SCHEME_Unmarshal((TPMT_KEYEDHASH_SCHEME *)&((target)->scheme), buffer, size, 1)
+#define TPMS_KEYEDHASH_PARMS_Marshal(source, buffer, size) \
+ TPMT_KEYEDHASH_SCHEME_Marshal((TPMT_KEYEDHASH_SCHEME *)&((source)->scheme), buffer, size)
+
+
+// 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);
+UINT16
+TPMS_RSA_PARMS_Marshal(TPMS_RSA_PARMS *source, BYTE **buffer, INT32 *size);
+
+#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);
+UINT16
+TPMS_ECC_PARMS_Marshal(TPMS_ECC_PARMS *source, BYTE **buffer, INT32 *size);
+
+#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);
+UINT16
+TPMU_PUBLIC_PARMS_Marshal(TPMU_PUBLIC_PARMS *source, BYTE **buffer, INT32 *size, UINT32 selector);
+
+
+// Table 2:183 - Definition of TPMT_PUBLIC_PARMS Structure (StructureTable)
+TPM_RC
+TPMT_PUBLIC_PARMS_Unmarshal(TPMT_PUBLIC_PARMS *target, BYTE **buffer, INT32 *size);
+
+// 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);
+UINT16
+TPMT_PUBLIC_Marshal(TPMT_PUBLIC *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:185 - Definition of TPM2B_PUBLIC Structure (StructureTable)
+TPM_RC
+TPM2B_PUBLIC_Unmarshal(TPM2B_PUBLIC *target, BYTE **buffer, INT32 *size, BOOL flag);
+UINT16
+TPM2B_PUBLIC_Marshal(TPM2B_PUBLIC *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPMU_SENSITIVE_COMPOSITE_Marshal(TPMU_SENSITIVE_COMPOSITE *source, BYTE **buffer, INT32 *size, UINT32 selector);
+
+
+// Table 2:188 - Definition of TPMT_SENSITIVE Structure (StructureTable)
+TPM_RC
+TPMT_SENSITIVE_Unmarshal(TPMT_SENSITIVE *target, BYTE **buffer, INT32 *size);
+UINT16
+TPMT_SENSITIVE_Marshal(TPMT_SENSITIVE *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:189 - Definition of TPM2B_SENSITIVE Structure (StructureTable)
+TPM_RC
+TPM2B_SENSITIVE_Unmarshal(TPM2B_SENSITIVE *target, BYTE **buffer, INT32 *size);
+
+// 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);
+UINT16
+TPM2B_PRIVATE_Marshal(TPM2B_PRIVATE *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPM2B_ID_OBJECT_Marshal(TPM2B_ID_OBJECT *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+
+#define TPMA_NV_Marshal(source, buffer, size) \
+ UINT32_Marshal((UINT32 *)(source), buffer, size)
+
+
+// Table 2:196 - Definition of TPMS_NV_PUBLIC Structure (StructureTable)
+TPM_RC
+TPMS_NV_PUBLIC_Unmarshal(TPMS_NV_PUBLIC *target, BYTE **buffer, INT32 *size);
+UINT16
+TPMS_NV_PUBLIC_Marshal(TPMS_NV_PUBLIC *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:197 - Definition of TPM2B_NV_PUBLIC Structure (StructureTable)
+TPM_RC
+TPM2B_NV_PUBLIC_Unmarshal(TPM2B_NV_PUBLIC *target, BYTE **buffer, INT32 *size);
+UINT16
+TPM2B_NV_PUBLIC_Marshal(TPM2B_NV_PUBLIC *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+UINT16
+TPM2B_CONTEXT_DATA_Marshal(TPM2B_CONTEXT_DATA *source, BYTE **buffer, INT32 *size);
+
+
+// Table 2:201 - Definition of TPMS_CONTEXT Structure (StructureTable)
+TPM_RC
+TPMS_CONTEXT_Unmarshal(TPMS_CONTEXT *target, BYTE **buffer, INT32 *size);
+UINT16
+TPMS_CONTEXT_Marshal(TPMS_CONTEXT *source, BYTE **buffer, INT32 *size);
+
+
+// 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);
+
+
+// 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);
+
+// 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);
+
+// 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);
+
+// Array Marshal/Unmarshal for TPMS_PCR_SELECTION
+TPM_RC
+TPMS_PCR_SELECTION_Array_Unmarshal(TPMS_PCR_SELECTION *target, BYTE **buffer, INT32 *size, INT32 count);
+UINT16
+TPMS_PCR_SELECTION_Array_Marshal(TPMS_PCR_SELECTION *source, BYTE **buffer, INT32 *size, INT32 count);
+
+// Array Marshal/Unmarshal for TPMT_HA
+TPM_RC
+TPMT_HA_Array_Unmarshal(TPMT_HA *target, BYTE **buffer, INT32 *size, BOOL flag, INT32 count);
+UINT16
+TPMT_HA_Array_Marshal(TPMT_HA *source, BYTE **buffer, INT32 *size, INT32 count);
+
+// Array Marshal/Unmarshal for BYTE
+TPM_RC
+BYTE_Array_Unmarshal(BYTE *target, BYTE **buffer, INT32 *size, INT32 count);
+UINT16
+BYTE_Array_Marshal(BYTE *source, BYTE **buffer, INT32 *size, INT32 count);
+
+// 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);
+
+// 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);
+
+// 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);
+
+// 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);
+
+#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);
+UINT16
+TPM2B_DIGEST_Array_Marshal(TPM2B_DIGEST *source, BYTE **buffer, INT32 *size, INT32 count);
+
+// Array Marshal/Unmarshal for TPM_CC
+TPM_RC
+TPM_CC_Array_Unmarshal(TPM_CC *target, BYTE **buffer, INT32 *size, INT32 count);
+UINT16
+TPM_CC_Array_Marshal(TPM_CC *source, BYTE **buffer, INT32 *size, INT32 count);
+
+// Array Marshal/Unmarshal for TPM_ALG_ID
+TPM_RC
+TPM_ALG_ID_Array_Unmarshal(TPM_ALG_ID *target, BYTE **buffer, INT32 *size, INT32 count);
+UINT16
+TPM_ALG_ID_Array_Marshal(TPM_ALG_ID *source, BYTE **buffer, INT32 *size, INT32 count);
+
+#endif // _MARSHAL_FP_H
diff --git a/tpm-util/duplicate/include/tpm_duplication_aux.h b/tpm-util/duplicate/include/tpm_duplication_aux.h
new file mode 100644
index 0000000..f32655b
--- /dev/null
+++ b/tpm-util/duplicate/include/tpm_duplication_aux.h
@@ -0,0 +1,81 @@
+/*
+ * 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
+
+#ifndef TPM_DUP_AUX
+#define TPM_DUP_AUX
+
+#include <sapi/tpm20.h>
+#include <openssl/rand.h>
+#include <openssl/hmac.h>
+#include "crypto_aux.h"
+
+#define BYTES_TO_BITS(val) (val * 8)
+
+#define INIT_SIMPLE_TPM2B_SIZE( type ) (type).t.size = sizeof( type ) - 2;
+
+TPM2B_NAME * GetName(TPMI_ALG_HASH hashAlg, TPM2B_PUBLIC *obj, TPM2B_NAME *outName);
+
+TSS2_RC swKeyDuplicate(
+ /* IN */
+ RSA* rsaKey, TPM2B_PUBLIC* parentKeyPublicPortion, UINT8* policyDigest, int digestSize,
+ /* OUT */
+ TPM2B_DATA* encryptionKey, TPM2B_PUBLIC *swKeyPublic, TPM2B_PRIVATE *swKeyPrivate, TPM2B_ENCRYPTED_SECRET *encSymSeed);
+
+void CreateDuplicationBlob(
+ //IN
+ TPM2B_PUBLIC_KEY_RSA *protector,
+ TPMT_PUBLIC * publicPortion,
+ TPMT_SENSITIVE *sens,
+ TPM2B_ENCRYPTED_SECRET *plainSymSeed, TPMI_YES_NO generateInSymSeed,
+ TPM2B_DATA *encryptionKey, TPMI_YES_NO generateEncryptionKey,
+
+ //OUT
+ TPM2B_PRIVATE *outDuplicate,
+ TPM2B_ENCRYPTED_SECRET *encSymSeed);
+
+
+void CreateSwDataObject(
+ BYTE* auth, UINT16 authSize,
+ RSA * rsakey,
+ BYTE * dataToSeal, UINT16 dataSize,
+ BYTE * policyDigest, UINT16 policyDigestSize,
+ TPMT_PUBLIC * outPublic,
+ TPMT_SENSITIVE *outSens);
+
+void CreateDuplicationBlob2B(
+ //IN
+ TPM2B_PUBLIC_KEY_RSA *protector,
+ TPM2B_PUBLIC * publicPortion,
+ TPM2B_SENSITIVE *sens,
+ TPM2B_ENCRYPTED_SECRET *plainSymSeed, TPMI_YES_NO generateInSymSeed,
+ TPM2B_DATA *encryptionKey, TPMI_YES_NO generateEncryptionKey,
+ //OUT
+ TPM2B_PRIVATE *outDuplicate,
+ TPM2B_ENCRYPTED_SECRET *encSymSeed);
+
+void CreateSwDataObject2B(
+ //IN
+ BYTE* auth, UINT16 authSize,
+ RSA * rsaKey,
+ BYTE * policyDigest, UINT16 policyDigestSize,
+ //OUT
+ TPM2B_PUBLIC * outPublic,
+ TPM2B_SENSITIVE *outSens);
+
+
+#endif //TPM_DUP_AUX
+
diff --git a/tpm-util/duplicate/include/util.h b/tpm-util/duplicate/include/util.h
new file mode 100644
index 0000000..1033b5f
--- /dev/null
+++ b/tpm-util/duplicate/include/util.h
@@ -0,0 +1,38 @@
+/*
+ * 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
+
+#ifndef __UTIL_H__
+#define __UTIL_H__
+
+#include <sapi/tpm20.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+#include <ctype.h>
+#include <getopt.h>
+
+
+void hex_log(UINT8 *pData, UINT32 numBytes, const char* caption);
+
+TPM_RC ConcatSizedByteBuffer( TPM2B_MAX_BUFFER *result, TPM2B *addBuffer );
+
+int saveDataToFile(const char *fileName, UINT8 *buf, UINT16 size);
+
+int loadDataFromFile(const char *fileName, UINT8 *buf, UINT16 *size);
+
+#endif
diff --git a/tpm-util/duplicate/main.c b/tpm-util/duplicate/main.c
new file mode 100644
index 0000000..662b984
--- /dev/null
+++ b/tpm-util/duplicate/main.c
@@ -0,0 +1,281 @@
+/*
+ * 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.
+ */
+//
+// main.c : Tool to import Openssl RSA key into TPM. Generates TPM duplication data
+// Author: Arun Kumar Sekar
+//
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <openssl/pem.h>
+
+#include <pthread.h>
+
+#include <sapi/tpm20.h>
+#include <tcti/tcti_socket.h>
+
+#include "tpm_duplication_aux.h"
+#include "util.h"
+
+
+void PrintHelp();
+char version[] = "0.1";
+
+void PrintHelp()
+{
+ printf(
+ "OSSL key to tpm import tool, Version %s\nUsage:"
+ "./ossl_tpm_duplicate [-pemfile InputPemFile] [-pempwd inputPemPwd (optional)] [-parentPub inputParentPubFile]"
+ "[-dupPub out_dupPubFile] [-dupPriv out_dupPrivFile] [-dupSymSeed out_dupSymSeedFile] [-dupEncKey out_dupEncKeyFile] \n"
+ "\n"
+ , version);
+}
+
+static TPM_RC convert_PEM_To_EVP(EVP_PKEY **evpPkey, /* freed by caller */
+ const char *pem_Filename,
+ const char *pem_pwd)
+{
+ TPM_RC rc = 0;
+ FILE *fp_pemfile = NULL;
+
+ if (rc == 0)
+ {
+ fp_pemfile = fopen(pem_Filename, "rb"); /* closed @2 */
+ if(fp_pemfile == NULL) {
+ rc = EXIT_FAILURE;
+ }
+ }
+
+ if (rc == 0)
+ {
+ *evpPkey = PEM_read_PrivateKey(fp_pemfile, NULL, NULL, (void *)pem_pwd);
+ if (*evpPkey == NULL)
+ {
+ printf("convert_PEM_To_EVP: Error reading key file %s\n", pem_Filename);
+ rc = EXIT_FAILURE;
+ }
+ printf("PEM_read_PrivateKey success for file: %s \n", pem_Filename);
+ }
+
+end:
+ if (fp_pemfile != NULL)
+ {
+ fclose(fp_pemfile);
+ }
+
+ return rc;
+}
+
+static TPM_RC convert_EVP_to_RSA(RSA **rsaKey, /* freed by caller */
+ EVP_PKEY *evpPkey)
+{
+ TPM_RC rc = 0;
+
+ if (rc == 0)
+ {
+ *rsaKey = EVP_PKEY_get1_RSA(evpPkey);
+ if (*rsaKey == NULL)
+ {
+ printf("convert_EVP_to_RSA: EVP_PKEY_get1_RSA failed\n");
+ rc = EXIT_FAILURE;
+ }
+ printf("convert_EVP_to_RSA success! \n");
+ }
+
+ return rc;
+}
+
+
+int main(int argc, char* argv[])
+{
+ TPM_RC rval = 0;
+ int count=0;
+
+ char pem_Filename[256];
+ int pemfile_flag = 0;
+ const char *pem_pwd = ""; /* default empty password */
+ int pempwd_flag = 0;
+
+ // SW Key Duplicate I/P variables
+ char parent_pub_Filename[256];
+ int parent_pub_flag = 0;
+
+ // SW Key Duplicate O/P variables
+ char dupPub_Filename[256];
+ int dupPub_flag = 0;
+ char dupPriv_Filename[256];
+ int dupPriv_flag = 0;
+ char dupSymSeed_Filename[256];
+ int dupSymSeed_flag = 0;
+ char dupEncKey_Filename[256];
+ int dupEncKey_flag = 0;
+ TPM2B_DATA encryptionKey;
+ TPM2B_PUBLIC swKeyPublic;
+ TPM2B_PRIVATE swKeyPrivate;
+ TPM2B_ENCRYPTED_SECRET encSymSeed;
+ unsigned short file_size = 0;
+ UINT8 policyDigest[32] = {0};
+ UINT32 digestSize = 0;
+
+ TPM2B_PUBLIC parentKeyPublicPortion;
+ int pubKeysize = 0;
+
+ // RSA key structures
+ EVP_PKEY *evpPkey = NULL;
+ RSA *rsaKey = NULL;
+
+ setbuf(stdout, NULL);
+ setvbuf (stdout, NULL, _IONBF, BUFSIZ);
+ if( (argc < 2) )
+ {
+ printf("Arguments count does not match \n");
+ PrintHelp();
+ return 1;
+ }
+ else
+ {
+ /* Get the argument values and evaluate it */
+ for( count = 1; count < argc; count++ )
+ {
+ if( 0 == strcmp( argv[count], "-pemfile" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", pem_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ pemfile_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-pempwd" ) ) {
+ count++;
+ pem_pwd = argv[count];
+ pempwd_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-parentPub" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", parent_pub_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ parent_pub_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-dupPub" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", dupPub_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ dupPub_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-dupPriv" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", dupPriv_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ dupPriv_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-dupSymSeed" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", dupSymSeed_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ dupSymSeed_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-dupEncKey" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", dupEncKey_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ dupEncKey_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "--help" ) ) {
+ PrintHelp();
+ exit(1);
+ }
+ else {
+ PrintHelp();
+ exit(1);
+ }
+ }
+ }
+
+ // For Duplicate functionality, check all input params are present
+ if( (!pemfile_flag) ||
+ (!parent_pub_flag) ||
+ (!dupPub_flag) ||
+ (!dupPriv_flag) ||
+ (!dupSymSeed_flag) ||
+ (!dupEncKey_flag)
+ )
+ {
+ printf("Error: One or more Inputs for Duplicate are not passed as input \n");
+ return -1;
+ }
+
+ printf("Input PEM file name: %s \n", pem_Filename);
+
+ if (rval == 0) {
+ rval = convert_PEM_To_EVP(&evpPkey, pem_Filename, pem_pwd);
+ }
+ if (rval == 0) {
+ rval = convert_EVP_to_RSA(&rsaKey, evpPkey);
+ }
+
+ if ( rval == 0 ) {
+ file_size = sizeof(TPM2B_PUBLIC);
+ rval = loadDataFromFile(parent_pub_Filename, (UINT8 *) &parentKeyPublicPortion, &file_size);
+ }
+
+ /* SW key duplicate operation started */
+ if ( rval == 0 ) {
+ rval = swKeyDuplicate(rsaKey, &parentKeyPublicPortion, policyDigest, digestSize,
+ &encryptionKey, &swKeyPublic, &swKeyPrivate, &encSymSeed);
+ if(rval != 0) {
+ printf("\nswKeyDuplicate failed: 0x%x ! \n", rval);
+ goto end;
+ }
+ else {
+ printf("\nswKeyDuplicate success: 0x%x ! \n", rval);
+ rval = saveDataToFile(dupPub_Filename, (UINT8 *) &swKeyPublic, sizeof(TPM2B_PUBLIC));
+ rval = saveDataToFile(dupPriv_Filename, (UINT8 *) &swKeyPrivate, sizeof(TPM2B_PRIVATE));
+ rval = saveDataToFile(dupSymSeed_Filename, (UINT8 *) &encSymSeed, sizeof(TPM2B_ENCRYPTED_SECRET));
+ rval = saveDataToFile(dupEncKey_Filename, (UINT8 *) &encryptionKey, sizeof(TPM2B_DATA));
+ printf("\nOutput files are written successfully ! \n");
+ }
+ }
+
+end:
+ if (rsaKey != NULL) {
+ RSA_free(rsaKey);
+ }
+ if (evpPkey != NULL) {
+ EVP_PKEY_free(evpPkey);
+ }
+
+ return rval;
+}
+
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;
+}
+
diff --git a/tpm-util/duplicate/sampleMakefile b/tpm-util/duplicate/sampleMakefile
new file mode 100644
index 0000000..5139954
--- /dev/null
+++ b/tpm-util/duplicate/sampleMakefile
@@ -0,0 +1,42 @@
+
+CC = gcc
+#CC = g++
+LD = ld
+AR = ar
+LDDFLAGS += -fPIC
+ARFLAGS = -rc
+
+TSS_DIR?=/home/pramod/tpm2-tss
+OPENSSL_DIR?=/usr/local/bin/openssl
+
+OUTPUT=ossl_tpm_duplicate
+
+OBJS= util.o \
+ marshal.o \
+ crypto_aux.o \
+ tpm_duplication_aux.o \
+ main.o
+
+
+CFLAGS += -g -fPIC -I./include -I${TSS_DIR}/include/ -I$(TSS_DIR)/sysapi/include #-I${OPENSSL_DIR}/include/
+
+#LDFLAGS += -L${OPENSSL_DIR}/lib -ldl -L/usr/local/lib/ -lsapi -ltcti-device -ltcti-tabrmd
+LDFLAGS += -ldl -L/usr/local/lib/ -lsapi -ltcti-device -ltcti-tabrmd
+
+LIBS = -lpthread -lcrypto -lssl
+
+%.o : %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+
+$(OUTPUT): $(OBJS)
+ $(CC) $(OBJS) $(LDFLAGS) ${LIBS} -o $(OUTPUT)
+
+.PHONY: all
+all: $(OUTPUT)
+
+install:
+ @set -e; for i in $(OUTPUT); do mv $$i ../../bin/$$i ; done
+
+clean:
+ rm -f *.o $(OUTPUT) *.so
diff --git a/tpm-util/duplicate/tpm_duplication_aux.c b/tpm-util/duplicate/tpm_duplication_aux.c
new file mode 100644
index 0000000..2baf3ac
--- /dev/null
+++ b/tpm-util/duplicate/tpm_duplication_aux.c
@@ -0,0 +1,507 @@
+/*
+ * 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 "tpm_duplication_aux.h"
+#include "marshal.h"
+
+#define AES_SIZE 16;
+
+void print2b(char* msg, TPM2B * toprint){
+ print_buff(msg, toprint->size, toprint->buffer);
+}
+
+void TPMT_PUBLIC_TO_TPM2B(TPMT_PUBLIC *source, TPM2B_PUBLIC *target)
+{
+ BYTE buff[1024],
+ *runner = buff+2;
+ int size = 1024;
+
+ UINT16 sizeField = TPMT_PUBLIC_Marshal(source, &runner, &size);
+ runner = buff;
+ UINT16_Marshal(&sizeField, &runner, &size);
+
+
+ runner = buff;
+ size = sizeof(TPM2B_PUBLIC);
+ TPM2B_PUBLIC_Unmarshal(target, &runner, &size, 1);
+}
+
+void TPMT_SENSITIVE_TO_TPM2B(TPMT_SENSITIVE *source, TPM2B_SENSITIVE *target)
+{
+ BYTE buff[1024]={0},
+ *runner = buff+2;
+ INT32 size = 1024;
+
+ UINT16 sizeField = TPMT_SENSITIVE_Marshal(source, &runner, &size);
+ runner = buff;
+ UINT16_Marshal(&sizeField, &runner, &size);
+
+
+ runner = buff;
+ size = sizeof(TPM2B_SENSITIVE);
+ TPM2B_SENSITIVE_Unmarshal(target, &runner, &size);
+
+
+}
+
+void TPM2B_SENSITIVE_TO_TPMT(TPM2B_SENSITIVE *source, TPMT_SENSITIVE *target)
+{
+ BYTE buffer[1024], *runner = buffer;
+ int size = 1024;
+ TPMT_SENSITIVE_Marshal(&(source->t.sensitiveArea), &runner, &size);
+
+ runner = buffer;
+ size = sizeof(*target);
+
+ TPMT_SENSITIVE_Unmarshal(target, &runner, &size);
+
+}
+void TPM2B_PUBLIC_TO_TPMT(TPM2B_PUBLIC *source, TPMT_PUBLIC *target)
+{
+ BYTE buffer[1024], *runner = buffer;
+ int size = 1024;
+ TPMT_PUBLIC_Marshal(&(source->t.publicArea), &runner, &size);
+
+ runner = buffer;
+ size = sizeof(*target);
+
+ TPMT_PUBLIC_Unmarshal(target, &runner, &size, 1);
+}
+
+
+TPM2B_NAME * GetName(TPMI_ALG_HASH hashAlg, TPM2B_PUBLIC *obj, TPM2B_NAME *outName)
+{
+ int size_in =1024;
+ BYTE buff[1024] = {0};
+ BYTE* runner = buff;
+
+ UINT16 toHashSize = TPM2B_PUBLIC_Marshal(obj, &runner, &size_in) ;
+
+ runner = outName->b.buffer;
+ size_in = 2;
+ outName->b.size = TPM_ALG_ID_Marshal(&hashAlg, &runner , &size_in) + 32;
+
+ SHA256(buff+2, toHashSize-2, runner);
+
+ return outName;
+}
+
+
+void CreateDuplicationBlob2B(
+ //IN
+ TPM2B_PUBLIC_KEY_RSA *protector,
+ TPM2B_PUBLIC * public2B,
+ TPM2B_SENSITIVE *sens2B,
+ TPM2B_ENCRYPTED_SECRET *plainSymSeed, TPMI_YES_NO generateInSymSeed,
+ TPM2B_DATA *encryptionKey, TPMI_YES_NO generateEncryptionKey,
+
+ //OUT
+ TPM2B_PRIVATE *outDuplicate,
+ TPM2B_ENCRYPTED_SECRET *encSymSeed)
+{
+ TPMT_PUBLIC publicPortion;
+ TPMT_SENSITIVE sens;
+
+ TPM2B_PUBLIC_TO_TPMT(public2B, &publicPortion);
+ TPM2B_SENSITIVE_TO_TPMT(sens2B, &sens);
+
+ CreateDuplicationBlob(protector, &publicPortion, &sens, plainSymSeed, generateInSymSeed, encryptionKey, generateEncryptionKey, outDuplicate, encSymSeed);
+
+}
+
+void CreateSwDataObject2B(
+ BYTE* auth, UINT16 authSize,
+ RSA * rsaKey,
+ BYTE * policyDigest, UINT16 policyDigestSize,
+ TPM2B_PUBLIC * outPublic2B,
+ TPM2B_SENSITIVE *outSens2B)
+{
+
+ TPMT_PUBLIC publicPortion;
+ TPMT_SENSITIVE sens;
+
+ CreateSwDataObject(auth, authSize, rsaKey, NULL, 0, policyDigest, policyDigestSize, &publicPortion, &sens);
+
+
+ TPMT_PUBLIC_TO_TPM2B(&publicPortion, outPublic2B);
+ TPMT_SENSITIVE_TO_TPM2B(&sens, outSens2B);
+}
+
+void CreateDuplicationBlob(
+ //IN
+ TPM2B_PUBLIC_KEY_RSA *protector,
+ TPMT_PUBLIC * publicPortion,
+ TPMT_SENSITIVE *sens,
+ TPM2B_ENCRYPTED_SECRET *plainSymSeed, TPMI_YES_NO generateInSymSeed,
+ TPM2B_DATA *encryptionKey, TPMI_YES_NO generateEncryptionKey,
+
+ //OUT
+ TPM2B_PRIVATE *outDuplicate,
+ TPM2B_ENCRYPTED_SECRET *encSymSeed)
+{
+ memset((void*)outDuplicate, 0, sizeof(TPM2B_PRIVATE));
+ memset((void*)encSymSeed, 0, sizeof(TPM2B_ENCRYPTED_SECRET));
+ TPM2B_SYM_KEY outerWrapper;
+ TPM2B NULL_2B = {0};
+ TPM2B_NAME swkName = {{0}};
+
+
+ TPM2B_PUBLIC public2B = {{0}};
+ TPM2B_SENSITIVE sens2B = {{0}};
+ INT32 size_in = 0;
+
+ TPM2B_MAX_BUFFER encSensitive = {{0}};
+
+ if(generateInSymSeed)
+ {
+ RAND_bytes(plainSymSeed->b.buffer, 16);
+ plainSymSeed->b.size = 16;
+ }
+ if(generateEncryptionKey)
+ {
+ RAND_bytes(encryptionKey->b.buffer, 16);
+ encryptionKey->b.size = 16;
+ }
+
+ // Preparing marshaled publicPortion:
+ TPMT_PUBLIC_TO_TPM2B(publicPortion, &public2B);
+
+ // calculating name:
+ GetName(TPM_ALG_SHA256, &(public2B), &swkName);
+
+ // preparing marshaled sensitive:
+ TPMT_SENSITIVE_TO_TPM2B(sens, &sens2B);
+
+ //preparing encSensitive
+ {
+ UINT16 tempUint16;
+ TPM2B_SYM_KEY IV = {0};
+ IV.b.size = 16;
+ TPM2B_MAX_BUFFER innerData = {0};
+ BYTE innerIntegrity[34] = {0}, toHash[1024] = {0};
+ size_in = 1024;
+ BYTE* runner = toHash;
+
+
+ UINT16_Marshal(&(sens2B.b.size), &runner, &size_in);
+ TPMT_SENSITIVE_Marshal(sens, &runner, &size_in);
+
+ memcpy(runner, swkName.b.buffer, swkName.b.size );
+ runner += swkName.b.size;
+
+
+ SHA256(toHash, runner - toHash, innerIntegrity+2);
+ runner = innerIntegrity;
+ tempUint16 = 32;
+ UINT16_Marshal(&tempUint16, &runner, &size_in);
+
+ memcpy(innerData.b.buffer, innerIntegrity, 34);
+ runner = innerData.b.buffer + 34;
+ size_in = 1024;
+
+ UINT16_Marshal(&(sens2B.b.size), &runner, &size_in);
+ TPMT_SENSITIVE_Marshal(sens, &runner, &size_in);
+
+ innerData.b.size = sens2B.b.size + 36;
+
+ AES_128_CFB_enc_dec(&(innerData.b), &(encSensitive.b), &(encryptionKey->b), &(IV.b), NULL, 1);
+ }
+
+
+ // outer integrity
+ {
+ TPM2B_SYM_KEY IV = {{0}};
+ TPM2B_DIGEST hmacKey = {{0}};
+ TPM2B_DIGEST outerHmac = {{0}};
+ TPM2B_MAX_BUFFER dupSensitive = {{0}};
+ TPM2B_MAX_BUFFER dataToHmac = {{0}};
+ BYTE * runner = NULL;
+
+ IV.b.size = 16;
+
+ KDFa(TPM_ALG_SHA256, &(plainSymSeed->b), "STORAGE", &(swkName.b), &NULL_2B, 128 , (TPM2B_MAX_BUFFER*) &outerWrapper);
+
+ AES_128_CFB_enc_dec(&(encSensitive.b), &(dupSensitive.b), &(outerWrapper.b), &(IV.b), NULL, 1);
+
+ KDFa(TPM_ALG_SHA256, &(plainSymSeed->b), "INTEGRITY", &NULL_2B, &NULL_2B, 32*8,(TPM2B_MAX_BUFFER*) &(hmacKey.b));
+
+ memcpy(dataToHmac.b.buffer, dupSensitive.b.buffer, dupSensitive.b.size);
+ memcpy(dataToHmac.b.buffer + dupSensitive.b.size, swkName.b.buffer, swkName.b.size);
+ dataToHmac.b.size = dupSensitive.b.size + swkName.b.size;
+
+
+ HMAC(EVP_sha256(), hmacKey.b.buffer, hmacKey.b.size, dataToHmac.b.buffer, dataToHmac.b.size,
+ outerHmac.b.buffer, (UINT32*) &size_in);
+
+ outerHmac.b.size = size_in;
+
+ runner = outDuplicate->b.buffer;
+ size_in = sizeof(*outDuplicate) - 2;
+ outDuplicate->b.size = TPM2B_DIGEST_Marshal(&outerHmac, &runner, &size_in);
+
+ memcpy(runner, dupSensitive.b.buffer, dupSensitive.b.size);
+ outDuplicate->b.size += dupSensitive.b.size;
+
+ }
+
+ // Encrypting seed with RSA pub:
+ TPM2B_DATA encodingParams = {{0}};
+ encodingParams.b.size = 10;
+ memcpy(encodingParams.b.buffer, "DUPLICATE", 10);
+
+ RSA_OAEP_Enc((TPM2B_PUBLIC_KEY_RSA*)plainSymSeed, (TPM2B_PUBLIC_KEY_RSA*)encSymSeed, protector, &encodingParams);
+
+}
+
+void rsaKeyTobn( const RSA* rsaKey,
+ const BIGNUM** n,
+ const BIGNUM** e,
+ const BIGNUM** d,
+ const BIGNUM** p,
+ const BIGNUM** q
+ )
+{
+#if OPENSSL_VERSION_NUMBER < 0x10100000
+ if (n != NULL)
+ {
+ *n = rsaKey->n;
+ *e = rsaKey->e;
+ *d = rsaKey->d;
+ }
+ if (p != NULL)
+ {
+ *p = rsaKey->p;
+ *q = rsaKey->q;
+ }
+
+#else
+ if (n != NULL)
+ {
+ RSA_get0_key(rsaKey, n, e, d);
+ }
+ if (p != NULL)
+ {
+ RSA_get0_factors(rsaKey, p, q);
+ }
+#endif
+}
+
+int rsabnTobin( const BIGNUM** n,
+ const BIGNUM** e,
+ const BIGNUM** p,
+ uint8_t** n_bytes, int* n_size,
+ uint8_t** e_bytes, int* e_size,
+ uint8_t** p_bytes, int* p_size
+ )
+{
+ int rc=-1;
+
+ if(n_size != NULL)
+ {
+ *n_size = BN_num_bytes(*n);
+ }
+
+ if( (n_bytes != NULL) && (*n_size > 0) )
+ {
+ *n_bytes = (uint8_t*) malloc(*n_size);
+ BN_bn2bin(*n, *n_bytes);
+ rc = 0;
+ }
+
+ if(e_size != NULL)
+ {
+ *e_size = BN_num_bytes(*e);
+ }
+
+ if( (e_bytes != NULL) && (*e_size > 0) )
+ {
+ *e_bytes = (uint8_t*) malloc(*e_size);
+ BN_bn2bin(*e, *e_bytes);
+ rc = 0;
+ }
+
+ if(p_size != NULL)
+ {
+ *p_size = BN_num_bytes(*p);
+ }
+
+ if( (p_bytes != NULL) && (*p_size > 0) )
+ {
+ *p_bytes = (uint8_t*) malloc(*p_size);
+ BN_bn2bin(*p, *p_bytes);
+ rc = 0;
+ }
+
+end:
+ return rc;
+}
+
+
+void CreateSwDataObject(
+ BYTE* auth, UINT16 authSize,
+ RSA * rsaKey,
+ BYTE * dataToSeal, UINT16 dataSize,
+ BYTE * policyDigest, UINT16 policyDigestSize,
+ TPMT_PUBLIC * outPublic,
+ TPMT_SENSITIVE *outSens)
+{
+ TPM2B_MAX_BUFFER hash_buffer;
+ BYTE seed[32] = {0};
+
+ if(rsaKey != NULL)
+ {
+ /* Asymmetric key (RSA) creation */
+
+ const BIGNUM *n;
+ const BIGNUM *e;
+ const BIGNUM *d;
+ const BIGNUM *p;
+ const BIGNUM *q;
+
+ uint8_t* n_bytes; int n_size;
+ uint8_t* e_bytes; int e_size;
+ uint8_t* p_bytes; int p_size;
+
+ rsaKeyTobn(rsaKey, &n, &e, &d, &p, &q);
+
+ rsabnTobin( &n, &e, &p,
+ &n_bytes, &n_size,
+ &e_bytes, &e_size,
+ &p_bytes, &p_size
+ );
+
+ /* Fill TPM Sensitive data */
+ outSens->sensitiveType = TPM_ALG_RSA;
+
+ outSens->authValue.b.size = authSize;
+ memcpy(outSens->authValue.b.buffer, auth, authSize);
+
+ outSens->seedValue.b.size = 32;
+ memcpy(outSens->seedValue.b.buffer, seed, 32);
+
+ outSens->sensitive.bits.b.size = p_size;
+ memcpy(outSens->sensitive.bits.b.buffer, p_bytes, p_size);
+
+ /* Fill TPM Public portion */
+ outPublic->type = TPM_ALG_RSA;
+ outPublic->nameAlg = TPM_ALG_SHA256;
+ outPublic->objectAttributes.val = 0;
+ //outPublic->objectAttributes.val |= TPMA_OBJECT_RESTRICTED;
+ outPublic->objectAttributes.val |= TPMA_OBJECT_USERWITHAUTH;
+ outPublic->objectAttributes.val |= TPMA_OBJECT_SIGN;
+ outPublic->authPolicy.t.size = 0;
+
+ /* Table 182 - Definition of TPMU_PUBLIC_PARMS Union <IN/OUT, S> */
+ outPublic->parameters.rsaDetail.symmetric.algorithm = TPM_ALG_NULL;
+ outPublic->parameters.rsaDetail.scheme.scheme = TPM_ALG_NULL;
+ //outPublic->parameters.rsaDetail.scheme.details.rsassa.hashAlg = TPM_ALG_SHA256;
+
+ outPublic->parameters.rsaDetail.keyBits = BYTES_TO_BITS(n_size);;
+ printf("outPublic->parameters.rsaDetail.keyBits: %d \n", outPublic->parameters.rsaDetail.keyBits);
+
+ unsigned long tmp_val = 0; // Need to use this temp variable?
+ memcpy(&tmp_val, e_bytes, e_size);
+ outPublic->parameters.rsaDetail.exponent = tmp_val;
+ printf("outPublic->parameters.rsaDetail.exponent: 0x%x \n", outPublic->parameters.rsaDetail.exponent);
+
+ outPublic->unique.rsa.t.size = n_size;
+ memcpy(outPublic->unique.rsa.t.buffer, n_bytes, n_size);
+ printf("outPublic->unique.rsa.t.size: %d \n", outPublic->unique.rsa.t.size);
+
+ if(( policyDigestSize > 0) && (policyDigest != NULL) )
+ {
+ memcpy(outPublic->authPolicy.b.buffer, policyDigest, policyDigestSize);
+ outPublic->authPolicy.b.size = policyDigestSize;
+ }
+ }
+
+ else if( (dataToSeal != NULL) && (dataSize > 0) )
+ {
+ /* Symmetric Key Creation */
+
+ outSens->authValue.b.size = authSize;
+ memcpy(outSens->authValue.b.buffer, auth, authSize);
+
+ outSens->seedValue.b.size = 32;
+ memcpy(outSens->seedValue.b.buffer, seed, 32);
+
+ outSens->sensitive.bits.b.size = dataSize;
+ memcpy(outSens->sensitive.bits.b.buffer, dataToSeal, dataSize);
+
+ outSens->sensitiveType = TPM_ALG_KEYEDHASH;
+
+ outPublic->objectAttributes.val = 0;
+ outPublic->objectAttributes.adminWithPolicy = 1;
+ outPublic->nameAlg = TPM_ALG_SHA256;
+ memcpy(outPublic->unique.keyedHash.b.buffer, dataToSeal, dataSize);
+ outPublic->unique.keyedHash.b.size = dataSize;
+
+ if(( policyDigestSize > 0) && (policyDigest != NULL) )
+ {
+ memcpy(outPublic->authPolicy.b.buffer, policyDigest, policyDigestSize);
+ outPublic->authPolicy.b.size = policyDigestSize;
+ }
+
+ outPublic->type = TPM_ALG_KEYEDHASH;
+ outPublic->nameAlg = TPM_ALG_SHA256;
+
+ outPublic->parameters.keyedHashDetail.scheme.scheme = TPM_ALG_NULL;
+ outPublic->parameters.keyedHashDetail.scheme.details.hmac.hashAlg = TPM_ALG_NULL;
+
+ memcpy(hash_buffer.b.buffer, seed, 32);
+ memcpy(hash_buffer.b.buffer+32, dataToSeal, dataSize);
+ SHA256(hash_buffer.b.buffer, 32+dataSize, outPublic->unique.keyedHash.b.buffer);
+ outPublic->unique.keyedHash.b.size = 32;
+ }
+
+}
+
+
+TSS2_RC swKeyDuplicate(
+ /* IN */
+ RSA* rsaKey, TPM2B_PUBLIC* parentKeyPublicPortion, UINT8* policyDigest, int digestSize,
+ /* OUT */
+ TPM2B_DATA* encryptionKey, TPM2B_PUBLIC *swKeyPublic, TPM2B_PRIVATE *swKeyPrivate, TPM2B_ENCRYPTED_SECRET *encSymSeed)
+{
+ TPM_RC rval = TPM_RC_SUCCESS;
+ UINT8 auth[0];
+ TPM2B_SENSITIVE swKeySens;
+ TPM2B_ENCRYPTED_SECRET plainSymSeed = {{0}};
+ TPM2B_PUBLIC_KEY_RSA protectorRsaPub = {{0}};
+
+ INIT_SIMPLE_TPM2B_SIZE(swKeySens);
+ INIT_SIMPLE_TPM2B_SIZE(*swKeyPublic);
+
+ // Fill the protector data
+ memcpy(protectorRsaPub.b.buffer, parentKeyPublicPortion->t.publicArea.unique.rsa.t.buffer, parentKeyPublicPortion->t.publicArea.unique.rsa.t.size);
+ protectorRsaPub.b.size = parentKeyPublicPortion->t.publicArea.unique.rsa.t.size;
+
+ // Fill Symmetric seed
+ plainSymSeed.b.size = encryptionKey->b.size = 16;
+ encSymSeed->b.size = 16;
+
+ // Create SW Data Object Public and Sensitive portions
+ CreateSwDataObject2B(auth, 0, rsaKey, policyDigest, digestSize, swKeyPublic, &swKeySens);
+
+ // Create Duplication blob needed for Import
+ CreateDuplicationBlob2B( &protectorRsaPub, swKeyPublic, &swKeySens, &plainSymSeed, 0, encryptionKey, 1, swKeyPrivate, encSymSeed);
+
+ return rval;
+}
+
+
diff --git a/tpm-util/duplicate/util.c b/tpm-util/duplicate/util.c
new file mode 100644
index 0000000..6d5337f
--- /dev/null
+++ b/tpm-util/duplicate/util.c
@@ -0,0 +1,97 @@
+/*
+ * 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 "util.h"
+
+TPM_RC ConcatSizedByteBuffer( TPM2B_MAX_BUFFER *result, TPM2B *addBuffer )
+{
+ int i;
+
+ if( ( result->t.size + addBuffer->size ) > MAX_DIGEST_BUFFER )
+ return TSS2_SYS_RC_BAD_VALUE;
+ else
+ {
+ for( i = 0; i < addBuffer->size; i++ )
+ result->t.buffer[i + result->t.size] = addBuffer->buffer[i];
+
+ result->t.size += addBuffer->size;
+
+ return TPM_RC_SUCCESS;
+ }
+}
+
+int saveDataToFile(const char *fileName, UINT8 *buf, UINT16 size)
+{
+ FILE *f;
+ UINT16 count = 1;
+ if( fileName == NULL || buf == NULL || size == 0 )
+ return -1;
+
+ f = fopen(fileName, "wb+");
+ if( f == NULL ) {
+ printf("File(%s) open error.\n", fileName);
+ return -2;
+ }
+
+ while( size > 0 && count > 0 ) {
+ count = fwrite(buf, 1, size, f);
+ size -= count;
+ buf += count;
+ }
+
+ if( size > 0 ) {
+ printf("File write error\n");
+ fclose(f);
+ return -3;
+ }
+
+ fclose(f);
+ return 0;
+}
+
+int loadDataFromFile(const char *fileName, UINT8 *buf, UINT16 *size)
+{
+ UINT16 count = 1, left;
+ FILE *f;
+ if ( size == NULL || buf == NULL || fileName == NULL )
+ return -1;
+
+ f = fopen(fileName, "rb+");
+ if( f == NULL ) {
+ printf("File(%s) open error.\n", fileName);
+ return -2;
+ }
+
+ left = *size;
+ *size = 0;
+ while( left > 0 && count > 0 ) {
+ count = fread(buf, 1, left, f);
+ *size += count;
+ left -= count;
+ buf += count;
+ }
+
+ if( *size == 0 ) {
+ printf("File read error\n");
+ fclose(f);
+ return -3;
+ }
+ fclose(f);
+ return 0;
+}
+
+
diff --git a/tpm-util/import/include/tpm_wrapper.h b/tpm-util/import/include/tpm_wrapper.h
new file mode 100644
index 0000000..4d1639d
--- /dev/null
+++ b/tpm-util/import/include/tpm_wrapper.h
@@ -0,0 +1,60 @@
+/*
+ * 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
+
+#ifndef __TPM_WRAPPER_H__
+#define __TPM_WRAPPER_H__
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+#include <ctype.h>
+#include <getopt.h>
+
+#include <sapi/tpm20.h>
+
+#include <tcti/tcti-tabrmd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define INIT_SIMPLE_TPM2B_SIZE( type ) (type).t.size = sizeof( type ) - 2;
+
+TSS2_TCTI_CONTEXT* tpm_tcti_tabrmd_init (void);
+
+TSS2_SYS_CONTEXT* sys_ctx_init (TSS2_TCTI_CONTEXT *tcti_ctx);
+
+TSS2_RC TeardownTctiContext( TSS2_TCTI_CONTEXT *tctiContext );
+
+void TeardownSysContext( TSS2_SYS_CONTEXT **sysContext );
+
+TSS2_RC swKeyTpmImport(
+ /* IN */
+ TSS2_SYS_CONTEXT *sysContext,
+ TPM_HANDLE parentKeyHandle,
+ TPM2B_DATA* encryptionKey, TPM2B_PUBLIC* swKeyPublic, TPM2B_PRIVATE* swKeyPrivate, TPM2B_ENCRYPTED_SECRET* encSymSeed,
+ unsigned char* tpm_pwd, int tpm_pwd_len,
+ /* OUT */
+ TPM2B_PRIVATE *importPrivate);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
diff --git a/tpm-util/import/include/util.h b/tpm-util/import/include/util.h
new file mode 100644
index 0000000..5d89376
--- /dev/null
+++ b/tpm-util/import/include/util.h
@@ -0,0 +1,25 @@
+/*
+ * 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
+
+#ifndef __UTIL_H__
+#define __UTIL_H__
+
+int saveDataToFile(const char *fileName, UINT8 *buf, UINT16 size);
+
+int loadDataFromFile(const char *fileName, UINT8 *buf, UINT16 *size);
+
+#endif
diff --git a/tpm-util/import/main.c b/tpm-util/import/main.c
new file mode 100644
index 0000000..c498f6c
--- /dev/null
+++ b/tpm-util/import/main.c
@@ -0,0 +1,244 @@
+/*
+ * 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.
+ */
+//
+// main.c : Tool to import Openssl RSA key into TPM
+// Author: Arun Kumar Sekar
+//
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sapi/tpm20.h>
+
+#include "tpm_wrapper.h"
+#include "util.h"
+
+char* tpm_pwd = "";
+int tpm_pwd_len = 0;
+
+void PrintHelp();
+char version[] = "0.1";
+
+void PrintHelp()
+{
+ printf(
+ "OSSL key to tpm import tool, Version %s\nUsage:"
+ "./ossl_tpm_import "
+ "[-dupPub out_dupPubFile] [-dupPriv out_dupPrivFile] [-dupSymSeed out_dupSymSeedFile] [-dupEncKey out_dupEncKeyFile]"
+ "[-pub out_keyPub] [-priv out_KeyPriv]\n"
+ "\n"
+ , version);
+}
+
+int main(int argc, char* argv[])
+{
+ TPM_RC rval = 0;
+ int count=0;
+ TSS2_TCTI_CONTEXT *tcti_ctx = 0;
+ TSS2_SYS_CONTEXT *sysContext = 0;
+
+ // SW Key Duplicate O/P variables
+ char dupPub_Filename[256];
+ int dupPub_flag = 0;
+ char dupPriv_Filename[256];
+ int dupPriv_flag = 0;
+ char dupSymSeed_Filename[256];
+ int dupSymSeed_flag = 0;
+ char dupEncKey_Filename[256];
+ int dupEncKey_flag = 0;
+ TPM2B_DATA encryptionKey;
+ TPM2B_PUBLIC swKeyPublic;
+ TPM2B_PRIVATE swKeyPrivate;
+ TPM2B_ENCRYPTED_SECRET encSymSeed;
+
+ // SW Key Import O/P variables
+ char pub_Filename[256];
+ int pub_flag = 0;
+ char priv_Filename[256];
+ int priv_flag = 0;
+ unsigned short file_size = 0;
+
+ TPM_HANDLE primaryKeyHandle = 0;
+ int H_flag = 0;
+
+ TPM2B_PUBLIC parentKeyPublicPortion;
+ int pubKeysize = 0;
+
+ setbuf(stdout, NULL);
+ setvbuf (stdout, NULL, _IONBF, BUFSIZ);
+ if( (argc < 2) )
+ {
+ printf("Arguments count does not match \n");
+ PrintHelp();
+ return 1;
+ }
+ else
+ {
+ /* Get the argument values and evaluate it */
+ for( count = 1; count < argc; count++ )
+ {
+ if( 0 == strcmp( argv[count], "-dupPub" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", dupPub_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ dupPub_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-dupPriv" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", dupPriv_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ dupPriv_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-dupSymSeed" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", dupSymSeed_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ dupSymSeed_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-dupEncKey" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", dupEncKey_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ dupEncKey_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-pub" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", pub_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ pub_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-priv" ) ) {
+ count++;
+ if( (1 != sscanf( argv[count], "%s", priv_Filename )) )
+ {
+ PrintHelp();
+ return 1;
+ }
+ priv_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "-H" ) ) {
+ count++;
+ primaryKeyHandle = strtoul(argv[count], NULL, 16);
+ printf("Primary Key handle Given: 0x%x \n", primaryKeyHandle);
+ H_flag = 1;
+ }
+ else if( 0 == strcmp( argv[count], "--help" ) ) {
+ PrintHelp();
+ exit(1);
+ }
+ else {
+ PrintHelp();
+ exit(1);
+ }
+ }
+ }
+
+ if((!H_flag)) {
+ printf("Parent handle should be passed for TPM import operation \n");
+ return -1;
+ }
+
+ // For TPM Import functionality, check all input params are present
+ if( (!dupPub_flag) ||
+ (!dupPriv_flag) ||
+ (!dupSymSeed_flag) ||
+ (!dupEncKey_flag) ||
+ (!pub_flag) ||
+ (!priv_flag)
+ ) {
+ printf("Error: One or more Inputs for TPM import functionality is missing ! \n");
+ return -1;
+ }
+
+ /* SW Key TPM Import operation started */
+ if(rval == 0) {
+ file_size = sizeof(TPM2B_PUBLIC);
+ rval = loadDataFromFile(dupPub_Filename, (UINT8 *) &swKeyPublic, &file_size);
+ if ( rval == 0 ) {
+ file_size = sizeof(TPM2B_PRIVATE);
+ rval = loadDataFromFile(dupPriv_Filename, (UINT8 *) &swKeyPrivate, &file_size);
+ }
+ if ( rval == 0 ) {
+ file_size = sizeof(TPM2B_ENCRYPTED_SECRET);
+ rval = loadDataFromFile(dupSymSeed_Filename, (UINT8 *) &encSymSeed, &file_size);
+ }
+ if ( rval == 0 ) {
+ file_size = sizeof(TPM2B_DATA);
+ rval = loadDataFromFile(dupEncKey_Filename, (UINT8 *) &encryptionKey, &file_size);
+ }
+
+ if ( rval == 0 ) {
+ /* Initialize TCTI and sapi context */
+ tcti_ctx = tpm_tcti_tabrmd_init();
+ if(tcti_ctx == NULL) {
+ printf("Creation of TCTI context with TABRMD failed ! \n");
+ goto end;
+ }
+
+ sysContext = sys_ctx_init(tcti_ctx);
+ if(sysContext == NULL) {
+ printf("Creation of SAPI context with TABRMD failed ! \n");
+ goto end;
+ }
+ printf("\nInitializing TPM context success: 0x%x ! \n", rval);
+ }
+
+ TPM2B_PRIVATE importPrivate;
+ INIT_SIMPLE_TPM2B_SIZE(importPrivate);
+ rval = swKeyTpmImport(sysContext, primaryKeyHandle,
+ &encryptionKey, &swKeyPublic, &swKeyPrivate, &encSymSeed,
+ tpm_pwd, tpm_pwd_len,
+ &importPrivate);
+ if(rval != 0) {
+ printf("\nswKeyTpmImport failed: 0x%x ! \n", rval);
+ goto end;
+ }
+ else {
+ printf("\nswKeyImport success: 0x%x ! \n", rval);
+ saveDataToFile(pub_Filename, (UINT8 *) &swKeyPublic, sizeof(TPM2B_PUBLIC));
+ saveDataToFile(priv_Filename, (UINT8 *) &importPrivate, sizeof(TPM2B_PRIVATE));
+ printf("\nOutput files are written successfully ! \n");
+ }
+ }
+
+end:
+ if(sysContext) {
+ TeardownSysContext(&sysContext);
+ }
+ if(tcti_ctx) {
+ TeardownTctiContext(tcti_ctx);
+ }
+
+ return rval;
+}
+
diff --git a/tpm-util/import/sampleMakefile b/tpm-util/import/sampleMakefile
new file mode 100644
index 0000000..55c180a
--- /dev/null
+++ b/tpm-util/import/sampleMakefile
@@ -0,0 +1,38 @@
+
+CC = gcc
+#CC = g++
+LD = ld
+AR = ar
+LDDFLAGS += -fPIC
+ARFLAGS = -rc
+
+TSS_DIR?=/home/pramod/tpm2-tss
+
+OUTPUT=ossl_tpm_import
+
+OBJS= util.o \
+ tpm_wrapper.o \
+ main.o
+
+
+CFLAGS += -g -fPIC -I./include -I${TSS_DIR}/include/ -I$(TSS_DIR)/sysapi/include
+
+LDFLAGS += -ldl -L/usr/local/lib/ -lsapi -ltcti-device -ltcti-tabrmd
+
+LIBS = -lpthread -lcrypto -lssl
+
+%.o : %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+
+$(OUTPUT): $(OBJS)
+ $(CC) $(OBJS) $(LDFLAGS) ${LIBS} -o $(OUTPUT)
+
+.PHONY: all
+all: $(OUTPUT)
+
+install:
+ @set -e; for i in $(OUTPUT); do mv $$i ../../bin/$$i ; done
+
+clean:
+ rm -f *.o $(OUTPUT) *.so
diff --git a/tpm-util/import/tpm_wrapper.c b/tpm-util/import/tpm_wrapper.c
new file mode 100644
index 0000000..5f4ab2a
--- /dev/null
+++ b/tpm-util/import/tpm_wrapper.c
@@ -0,0 +1,213 @@
+/*
+ * 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 "tpm_wrapper.h"
+#include "util.h"
+
+#include <errno.h>
+
+#include <sapi/tpm20.h>
+#include <sapi/tss2_sys.h>
+#include <tcti/tcti_device.h>
+#include "tcti_util.h"
+
+TSS2_RC swKeyTpmImport(
+ /* IN */
+ TSS2_SYS_CONTEXT *sysContext,
+ TPM_HANDLE parentKeyHandle,
+ TPM2B_DATA* encryptionKey, TPM2B_PUBLIC* swKeyPublic, TPM2B_PRIVATE* swKeyPrivate, TPM2B_ENCRYPTED_SECRET* encSymSeed,
+ unsigned char* tpm_pwd, int tpm_pwd_len,
+ /* OUT */
+ TPM2B_PRIVATE *importPrivate)
+{
+ TPM_RC rval = TPM_RC_SUCCESS;
+ TPM2B_NAME name = { { sizeof( TPM2B_NAME ) - 2, } };
+
+ TPM_HANDLE wrapperKeyHandle;
+
+ TSS2_SYS_CMD_AUTHS npsessionsData;
+ TSS2_SYS_RSP_AUTHS npsessionsDataOut;
+ TPMS_AUTH_COMMAND npsessionData;
+ TPMS_AUTH_RESPONSE npsessionDataOut;
+
+ if(NULL == tpm_pwd) {
+ printf("TPM password pinter is NULL \n");
+ return -1;
+ }
+
+ *((UINT8 *)((void *)&npsessionData.sessionAttributes)) = 0;
+ npsessionData.sessionHandle = TPM_RS_PW;
+ npsessionData.nonce.t.size = 0;
+ npsessionData.hmac.t.size = 0;
+
+ npsessionData.hmac.t.size = tpm_pwd_len;
+ if(tpm_pwd_len > 0)
+ {
+ memcpy(npsessionData.hmac.t.buffer, tpm_pwd, npsessionData.hmac.t.size);
+ }
+
+ TPMS_AUTH_COMMAND *npsessionDataArray[1];
+ TPMS_AUTH_RESPONSE *npsessionDataOutArray[1];
+ TPMT_SYM_DEF_OBJECT symmetricAlg;
+
+ npsessionDataArray[0] = &npsessionData;
+ npsessionDataOutArray[0] = &npsessionDataOut;
+ npsessionsData.cmdAuthsCount = 1;
+ npsessionsData.cmdAuths = &npsessionDataArray[0];
+ npsessionsDataOut.rspAuthsCount = 1;
+ npsessionsDataOut.rspAuths = &npsessionDataOutArray[0];
+
+ symmetricAlg.algorithm = TPM_ALG_AES;
+ symmetricAlg.keyBits.aes = 128;
+ symmetricAlg.mode.aes = TPM_ALG_CFB;
+
+ rval = Tss2_Sys_Import( sysContext,
+ parentKeyHandle,
+ &npsessionsData,
+ encryptionKey,
+ swKeyPublic,
+ swKeyPrivate,
+ encSymSeed,
+ &symmetricAlg,
+ importPrivate,
+ &npsessionsDataOut
+ );
+ printf("The return value of sys import: 0x%x \n", rval);
+
+#if 0
+ if(rval == TSS2_RC_SUCCESS)
+ {
+ rval = Tss2_Sys_Load (sysContext, parentKeyHandle, &npsessionsData, importPrivate, swKeyPublic,
+ &wrapperKeyHandle, &name, &npsessionsDataOut);
+ printf("\n Load Imported Handle: 0x%x | rval 0x%x \n", wrapperKeyHandle, rval);
+ }
+ if(rval == TSS2_RC_SUCCESS)
+ {
+ rval = Tss2_Sys_FlushContext( sysContext, wrapperKeyHandle);
+ printf("\n Flush Loaded key Handle : 0x%8.8x| rval 0x%x \n", wrapperKeyHandle, rval);
+ }
+#endif
+
+ // Nullify TPM password
+ memset(tpm_pwd, 0, tpm_pwd_len);
+
+ return rval;
+}
+
+TSS2_TCTI_CONTEXT* tpm_tcti_tabrmd_init (void)
+{
+ TSS2_TCTI_CONTEXT *tcti_ctx;
+ TSS2_RC rc;
+ size_t size;
+
+ rc = tss2_tcti_tabrmd_init(NULL, &size);
+ if (rc != TSS2_RC_SUCCESS) {
+ printf ("Failed to get size for TABRMD TCTI context: 0x%x", rc);
+ return NULL;
+ }
+
+ tcti_ctx = (TSS2_TCTI_CONTEXT*)calloc (1, size);
+ if (tcti_ctx == NULL) {
+ printf ("Allocation for TABRMD TCTI context failed: %s",
+ strerror (errno));
+ return NULL;
+ }
+ rc = tss2_tcti_tabrmd_init (tcti_ctx, &size);
+ if (rc != TSS2_RC_SUCCESS) {
+ printf ("Failed to initialize TABRMD TCTI context: 0x%x", rc);
+ free (tcti_ctx);
+ return NULL;
+ }
+
+ return tcti_ctx;
+}
+
+TSS2_SYS_CONTEXT* sys_ctx_init (TSS2_TCTI_CONTEXT *tcti_ctx)
+{
+ TSS2_SYS_CONTEXT *sys_ctx;
+ TSS2_RC rc;
+ size_t size;
+ TSS2_ABI_VERSION abi_version = {
+ .tssCreator = TSSWG_INTEROP,
+ .tssFamily = TSS_SAPI_FIRST_FAMILY,
+ .tssLevel = TSS_SAPI_FIRST_LEVEL,
+ .tssVersion = TSS_SAPI_FIRST_VERSION,
+ };
+
+ size = Tss2_Sys_GetContextSize (0);
+ sys_ctx = (TSS2_SYS_CONTEXT*)calloc (1, size);
+ if (sys_ctx == NULL) {
+ fprintf (stderr,
+ "Failed to allocate 0x%zx bytes for the SAPI context\n",
+ size);
+ return NULL;
+ }
+ rc = Tss2_Sys_Initialize (sys_ctx, size, tcti_ctx, &abi_version);
+ if (rc != TSS2_RC_SUCCESS) {
+ fprintf (stderr, "Failed to initialize SAPI context: 0x%x\n", rc);
+ free (sys_ctx);
+ return NULL;
+ }
+
+ return sys_ctx;
+}
+
+TSS2_RC TeardownTctiContext( TSS2_TCTI_CONTEXT *tctiContext )
+{
+ ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->finalize( tctiContext );
+ free (tctiContext);
+ tctiContext = NULL;
+ return TSS2_RC_SUCCESS;
+}
+
+void TeardownSysContext( TSS2_SYS_CONTEXT **sysContext )
+{
+ if( *sysContext != 0 ) {
+ Tss2_Sys_Finalize(*sysContext);
+ free(*sysContext);
+ *sysContext = 0;
+ }
+}
+
+/* helper functions */
+#if 0
+TSS2_RC TPM2ReadPublicPortion(TSS2_SYS_CONTEXT *sysContext, TPM_HANDLE objectHandle, TPM2B_PUBLIC *publicPortion )
+{
+ TPM_RC rval = TPM_RC_SUCCESS;
+ TPM2B_NAME qualifiedName;
+ TPM2B_NAME name;
+ INIT_SIMPLE_TPM2B_SIZE( name );
+ INIT_SIMPLE_TPM2B_SIZE( qualifiedName );
+
+ if(publicPortion == NULL) {
+ printf("Input reference for TPM2B_PUBLIC structure is NULL");
+ return TPM_RC_FAILURE;
+ }
+
+ publicPortion->t.size = 0;
+ rval = Tss2_Sys_ReadPublic( sysContext, objectHandle , 0, publicPortion, &name, &qualifiedName, 0 );
+ if(rval != TPM_RC_SUCCESS)
+ {
+ printf("\n Tss2_Sys_ReadPublic failed: 0x%x ! for TPM handle: 0x%x \n", rval, objectHandle);
+ }
+
+ return rval;
+}
+#endif
+
diff --git a/tpm-util/import/util.c b/tpm-util/import/util.c
new file mode 100644
index 0000000..a0038a5
--- /dev/null
+++ b/tpm-util/import/util.c
@@ -0,0 +1,104 @@
+/*
+ * 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 "tpm_wrapper.h"
+
+int saveDataToFile(const char *fileName, UINT8 *buf, UINT16 size)
+{
+ FILE *f;
+ UINT16 count = 1;
+ if( fileName == NULL || buf == NULL || size == 0 )
+ return -1;
+
+ f = fopen(fileName, "wb+");
+ if( f == NULL ) {
+ printf("File(%s) open error.\n", fileName);
+ return -2;
+ }
+
+ while( size > 0 && count > 0 ) {
+ count = fwrite(buf, 1, size, f);
+ size -= count;
+ buf += count;
+ }
+
+ if( size > 0 ) {
+ printf("File write error\n");
+ fclose(f);
+ return -3;
+ }
+
+ fclose(f);
+ return 0;
+}
+
+int loadDataFromFile(const char *fileName, UINT8 *buf, UINT16 *size)
+{
+ UINT16 count = 1, left;
+ FILE *f;
+ if ( size == NULL || buf == NULL || fileName == NULL )
+ return -1;
+
+ f = fopen(fileName, "rb+");
+ if( f == NULL ) {
+ printf("File(%s) open error.\n", fileName);
+ return -2;
+ }
+
+ left = *size;
+ *size = 0;
+ while( left > 0 && count > 0 ) {
+ count = fread(buf, 1, left, f);
+ *size += count;
+ left -= count;
+ buf += count;
+ }
+
+ if( *size == 0 ) {
+ printf("File read error\n");
+ fclose(f);
+ return -3;
+ }
+ fclose(f);
+ return 0;
+}
+
+void hex_log(UINT8 *pData, UINT32 numBytes, const char* caption)
+{
+ int i = 0;
+
+ if(NULL == pData)
+ {
+ return;
+ }
+ if(caption != NULL)
+ {
+ printf("\n=== %s ===\n", caption);
+ }
+ printf("size: %d \n", numBytes);
+
+ for(i = 0; i < numBytes; i++)
+ {
+ printf("%02X ", pData[i]);
+
+ if (!((i + 1) % 16))
+ printf("\n");
+ }
+ printf("\n");
+}
+