blob: b471be155270a61926dd9bf449567d1b494d1651 [file] [log] [blame]
// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// THIS CODE IS GENERATED - DO NOT MODIFY!
#include "tpm_generated.h"
UINT16 uint8_t_Marshal(uint8_t* source, BYTE** buffer, INT32* size) {
uint8_t value_net = *source;
if (!size || *size < sizeof(uint8_t)) {
return 0; // Nothing has been marshaled.
}
switch (sizeof(uint8_t)) {
case 2:
value_net = htobe16(*source);
break;
case 4:
value_net = htobe32(*source);
break;
case 8:
value_net = htobe64(*source);
break;
default:
break;
}
memcpy(*buffer, &value_net, sizeof(uint8_t));
*buffer += sizeof(uint8_t);
*size -= sizeof(uint8_t);
return sizeof(uint8_t);
}
TPM_RC uint8_t_Unmarshal(uint8_t* target, BYTE** buffer, INT32* size) {
uint8_t value_net = 0;
if (!size || *size < sizeof(uint8_t)) {
return TPM_RC_INSUFFICIENT;
}
memcpy(&value_net, *buffer, sizeof(uint8_t));
switch (sizeof(uint8_t)) {
case 2:
*target = be16toh(value_net);
break;
case 4:
*target = be32toh(value_net);
break;
case 8:
*target = be64toh(value_net);
break;
default:
*target = value_net;
}
*buffer += sizeof(uint8_t);
*size -= sizeof(uint8_t);
return TPM_RC_SUCCESS;
}
UINT16 int8_t_Marshal(int8_t* source, BYTE** buffer, INT32* size) {
int8_t value_net = *source;
if (!size || *size < sizeof(int8_t)) {
return 0; // Nothing has been marshaled.
}
switch (sizeof(int8_t)) {
case 2:
value_net = htobe16(*source);
break;
case 4:
value_net = htobe32(*source);
break;
case 8:
value_net = htobe64(*source);
break;
default:
break;
}
memcpy(*buffer, &value_net, sizeof(int8_t));
*buffer += sizeof(int8_t);
*size -= sizeof(int8_t);
return sizeof(int8_t);
}
TPM_RC int8_t_Unmarshal(int8_t* target, BYTE** buffer, INT32* size) {
int8_t value_net = 0;
if (!size || *size < sizeof(int8_t)) {
return TPM_RC_INSUFFICIENT;
}
memcpy(&value_net, *buffer, sizeof(int8_t));
switch (sizeof(int8_t)) {
case 2:
*target = be16toh(value_net);
break;
case 4:
*target = be32toh(value_net);
break;
case 8:
*target = be64toh(value_net);
break;
default:
*target = value_net;
}
*buffer += sizeof(int8_t);
*size -= sizeof(int8_t);
return TPM_RC_SUCCESS;
}
UINT16 uint16_t_Marshal(uint16_t* source, BYTE** buffer, INT32* size) {
uint16_t value_net = *source;
if (!size || *size < sizeof(uint16_t)) {
return 0; // Nothing has been marshaled.
}
switch (sizeof(uint16_t)) {
case 2:
value_net = htobe16(*source);
break;
case 4:
value_net = htobe32(*source);
break;
case 8:
value_net = htobe64(*source);
break;
default:
break;
}
memcpy(*buffer, &value_net, sizeof(uint16_t));
*buffer += sizeof(uint16_t);
*size -= sizeof(uint16_t);
return sizeof(uint16_t);
}
TPM_RC uint16_t_Unmarshal(uint16_t* target, BYTE** buffer, INT32* size) {
uint16_t value_net = 0;
if (!size || *size < sizeof(uint16_t)) {
return TPM_RC_INSUFFICIENT;
}
memcpy(&value_net, *buffer, sizeof(uint16_t));
switch (sizeof(uint16_t)) {
case 2:
*target = be16toh(value_net);
break;
case 4:
*target = be32toh(value_net);
break;
case 8:
*target = be64toh(value_net);
break;
default:
*target = value_net;
}
*buffer += sizeof(uint16_t);
*size -= sizeof(uint16_t);
return TPM_RC_SUCCESS;
}
UINT16 int16_t_Marshal(int16_t* source, BYTE** buffer, INT32* size) {
int16_t value_net = *source;
if (!size || *size < sizeof(int16_t)) {
return 0; // Nothing has been marshaled.
}
switch (sizeof(int16_t)) {
case 2:
value_net = htobe16(*source);
break;
case 4:
value_net = htobe32(*source);
break;
case 8:
value_net = htobe64(*source);
break;
default:
break;
}
memcpy(*buffer, &value_net, sizeof(int16_t));
*buffer += sizeof(int16_t);
*size -= sizeof(int16_t);
return sizeof(int16_t);
}
TPM_RC int16_t_Unmarshal(int16_t* target, BYTE** buffer, INT32* size) {
int16_t value_net = 0;
if (!size || *size < sizeof(int16_t)) {
return TPM_RC_INSUFFICIENT;
}
memcpy(&value_net, *buffer, sizeof(int16_t));
switch (sizeof(int16_t)) {
case 2:
*target = be16toh(value_net);
break;
case 4:
*target = be32toh(value_net);
break;
case 8:
*target = be64toh(value_net);
break;
default:
*target = value_net;
}
*buffer += sizeof(int16_t);
*size -= sizeof(int16_t);
return TPM_RC_SUCCESS;
}
UINT16 uint32_t_Marshal(uint32_t* source, BYTE** buffer, INT32* size) {
uint32_t value_net = *source;
if (!size || *size < sizeof(uint32_t)) {
return 0; // Nothing has been marshaled.
}
switch (sizeof(uint32_t)) {
case 2:
value_net = htobe16(*source);
break;
case 4:
value_net = htobe32(*source);
break;
case 8:
value_net = htobe64(*source);
break;
default:
break;
}
memcpy(*buffer, &value_net, sizeof(uint32_t));
*buffer += sizeof(uint32_t);
*size -= sizeof(uint32_t);
return sizeof(uint32_t);
}
TPM_RC uint32_t_Unmarshal(uint32_t* target, BYTE** buffer, INT32* size) {
uint32_t value_net = 0;
if (!size || *size < sizeof(uint32_t)) {
return TPM_RC_INSUFFICIENT;
}
memcpy(&value_net, *buffer, sizeof(uint32_t));
switch (sizeof(uint32_t)) {
case 2:
*target = be16toh(value_net);
break;
case 4:
*target = be32toh(value_net);
break;
case 8:
*target = be64toh(value_net);
break;
default:
*target = value_net;
}
*buffer += sizeof(uint32_t);
*size -= sizeof(uint32_t);
return TPM_RC_SUCCESS;
}
UINT16 int32_t_Marshal(int32_t* source, BYTE** buffer, INT32* size) {
int32_t value_net = *source;
if (!size || *size < sizeof(int32_t)) {
return 0; // Nothing has been marshaled.
}
switch (sizeof(int32_t)) {
case 2:
value_net = htobe16(*source);
break;
case 4:
value_net = htobe32(*source);
break;
case 8:
value_net = htobe64(*source);
break;
default:
break;
}
memcpy(*buffer, &value_net, sizeof(int32_t));
*buffer += sizeof(int32_t);
*size -= sizeof(int32_t);
return sizeof(int32_t);
}
TPM_RC int32_t_Unmarshal(int32_t* target, BYTE** buffer, INT32* size) {
int32_t value_net = 0;
if (!size || *size < sizeof(int32_t)) {
return TPM_RC_INSUFFICIENT;
}
memcpy(&value_net, *buffer, sizeof(int32_t));
switch (sizeof(int32_t)) {
case 2:
*target = be16toh(value_net);
break;
case 4:
*target = be32toh(value_net);
break;
case 8:
*target = be64toh(value_net);
break;
default:
*target = value_net;
}
*buffer += sizeof(int32_t);
*size -= sizeof(int32_t);
return TPM_RC_SUCCESS;
}
UINT16 uint64_t_Marshal(uint64_t* source, BYTE** buffer, INT32* size) {
uint64_t value_net = *source;
if (!size || *size < sizeof(uint64_t)) {
return 0; // Nothing has been marshaled.
}
switch (sizeof(uint64_t)) {
case 2:
value_net = htobe16(*source);
break;
case 4:
value_net = htobe32(*source);
break;
case 8:
value_net = htobe64(*source);
break;
default:
break;
}
memcpy(*buffer, &value_net, sizeof(uint64_t));
*buffer += sizeof(uint64_t);
*size -= sizeof(uint64_t);
return sizeof(uint64_t);
}
TPM_RC uint64_t_Unmarshal(uint64_t* target, BYTE** buffer, INT32* size) {
uint64_t value_net = 0;
if (!size || *size < sizeof(uint64_t)) {
return TPM_RC_INSUFFICIENT;
}
memcpy(&value_net, *buffer, sizeof(uint64_t));
switch (sizeof(uint64_t)) {
case 2:
*target = be16toh(value_net);
break;
case 4:
*target = be32toh(value_net);
break;
case 8:
*target = be64toh(value_net);
break;
default:
*target = value_net;
}
*buffer += sizeof(uint64_t);
*size -= sizeof(uint64_t);
return TPM_RC_SUCCESS;
}
UINT16 int64_t_Marshal(int64_t* source, BYTE** buffer, INT32* size) {
int64_t value_net = *source;
if (!size || *size < sizeof(int64_t)) {
return 0; // Nothing has been marshaled.
}
switch (sizeof(int64_t)) {
case 2:
value_net = htobe16(*source);
break;
case 4:
value_net = htobe32(*source);
break;
case 8:
value_net = htobe64(*source);
break;
default:
break;
}
memcpy(*buffer, &value_net, sizeof(int64_t));
*buffer += sizeof(int64_t);
*size -= sizeof(int64_t);
return sizeof(int64_t);
}
TPM_RC int64_t_Unmarshal(int64_t* target, BYTE** buffer, INT32* size) {
int64_t value_net = 0;
if (!size || *size < sizeof(int64_t)) {
return TPM_RC_INSUFFICIENT;
}
memcpy(&value_net, *buffer, sizeof(int64_t));
switch (sizeof(int64_t)) {
case 2:
*target = be16toh(value_net);
break;
case 4:
*target = be32toh(value_net);
break;
case 8:
*target = be64toh(value_net);
break;
default:
*target = value_net;
}
*buffer += sizeof(int64_t);
*size -= sizeof(int64_t);
return TPM_RC_SUCCESS;
}
UINT16 BYTE_Marshal(BYTE* source, BYTE** buffer, INT32* size) {
return uint8_t_Marshal(source, buffer, size);
}
TPM_RC BYTE_Unmarshal(BYTE* target, BYTE** buffer, INT32* size) {
return uint8_t_Unmarshal(target, buffer, size);
}
UINT16 INT16_Marshal(INT16* source, BYTE** buffer, INT32* size) {
return int16_t_Marshal(source, buffer, size);
}
TPM_RC INT16_Unmarshal(INT16* target, BYTE** buffer, INT32* size) {
return int16_t_Unmarshal(target, buffer, size);
}
UINT16 INT32_Marshal(INT32* source, BYTE** buffer, INT32* size) {
return int32_t_Marshal(source, buffer, size);
}
TPM_RC INT32_Unmarshal(INT32* target, BYTE** buffer, INT32* size) {
return int32_t_Unmarshal(target, buffer, size);
}
UINT16 INT64_Marshal(INT64* source, BYTE** buffer, INT32* size) {
return int64_t_Marshal(source, buffer, size);
}
TPM_RC INT64_Unmarshal(INT64* target, BYTE** buffer, INT32* size) {
return int64_t_Unmarshal(target, buffer, size);
}
UINT16 INT8_Marshal(INT8* source, BYTE** buffer, INT32* size) {
return int8_t_Marshal(source, buffer, size);
}
TPM_RC INT8_Unmarshal(INT8* target, BYTE** buffer, INT32* size) {
return int8_t_Unmarshal(target, buffer, size);
}
UINT16 UINT16_Marshal(UINT16* source, BYTE** buffer, INT32* size) {
return uint16_t_Marshal(source, buffer, size);
}
TPM_RC UINT16_Unmarshal(UINT16* target, BYTE** buffer, INT32* size) {
return uint16_t_Unmarshal(target, buffer, size);
}
UINT16 TPM2B_ATTEST_Marshal(TPM2B_ATTEST* source, BYTE** buffer, INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.attestationData[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_ATTEST_Unmarshal(TPM2B_ATTEST* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > sizeof(TPMS_ATTEST)) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.attestationData[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_DIGEST_Marshal(TPM2B_DIGEST* source, BYTE** buffer, INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_DIGEST_Unmarshal(TPM2B_DIGEST* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > sizeof(TPMU_HA)) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_AUTH_Marshal(TPM2B_AUTH* source, BYTE** buffer, INT32* size) {
return TPM2B_DIGEST_Marshal(source, buffer, size);
}
TPM_RC TPM2B_AUTH_Unmarshal(TPM2B_AUTH* target, BYTE** buffer, INT32* size) {
return TPM2B_DIGEST_Unmarshal(target, buffer, size);
}
UINT16 TPM2B_CONTEXT_DATA_Marshal(TPM2B_CONTEXT_DATA* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_CONTEXT_DATA_Unmarshal(TPM2B_CONTEXT_DATA* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > sizeof(TPMS_CONTEXT_DATA)) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_CONTEXT_SENSITIVE_Marshal(TPM2B_CONTEXT_SENSITIVE* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_CONTEXT_SENSITIVE_Unmarshal(TPM2B_CONTEXT_SENSITIVE* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > MAX_CONTEXT_SIZE) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM_ALG_ID_Marshal(TPM_ALG_ID* source, BYTE** buffer, INT32* size) {
return uint16_t_Marshal(source, buffer, size);
}
TPM_RC TPM_ALG_ID_Unmarshal(TPM_ALG_ID* target, BYTE** buffer, INT32* size) {
TPM_RC result;
result = uint16_t_Unmarshal(target, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
#ifdef TPM_ALG_ERROR
if (*target == TPM_ALG_ERROR) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_RSA
if (*target == TPM_ALG_RSA) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_SHA
if (*target == TPM_ALG_SHA) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_SHA1
if (*target == TPM_ALG_SHA1) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_HMAC
if (*target == TPM_ALG_HMAC) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_AES
if (*target == TPM_ALG_AES) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_MGF1
if (*target == TPM_ALG_MGF1) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_KEYEDHASH
if (*target == TPM_ALG_KEYEDHASH) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_XOR
if (*target == TPM_ALG_XOR) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_SHA256
if (*target == TPM_ALG_SHA256) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_SHA384
if (*target == TPM_ALG_SHA384) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_SHA512
if (*target == TPM_ALG_SHA512) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_NULL
if (*target == TPM_ALG_NULL) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_SM3_256
if (*target == TPM_ALG_SM3_256) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_SM4
if (*target == TPM_ALG_SM4) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_RSASSA
if (*target == TPM_ALG_RSASSA) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_RSAES
if (*target == TPM_ALG_RSAES) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_RSAPSS
if (*target == TPM_ALG_RSAPSS) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_OAEP
if (*target == TPM_ALG_OAEP) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_ECDSA
if (*target == TPM_ALG_ECDSA) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_ECDH
if (*target == TPM_ALG_ECDH) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_ECDAA
if (*target == TPM_ALG_ECDAA) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_SM2
if (*target == TPM_ALG_SM2) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_ECSCHNORR
if (*target == TPM_ALG_ECSCHNORR) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_ECMQV
if (*target == TPM_ALG_ECMQV) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_KDF1_SP800_56A
if (*target == TPM_ALG_KDF1_SP800_56A) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_KDF2
if (*target == TPM_ALG_KDF2) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_KDF1_SP800_108
if (*target == TPM_ALG_KDF1_SP800_108) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_ECC
if (*target == TPM_ALG_ECC) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_SYMCIPHER
if (*target == TPM_ALG_SYMCIPHER) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_CAMELLIA
if (*target == TPM_ALG_CAMELLIA) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_CTR
if (*target == TPM_ALG_CTR) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_OFB
if (*target == TPM_ALG_OFB) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_CBC
if (*target == TPM_ALG_CBC) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_CFB
if (*target == TPM_ALG_CFB) {
return TPM_RC_SUCCESS;
}
#endif
#ifdef TPM_ALG_ECB
if (*target == TPM_ALG_ECB) {
return TPM_RC_SUCCESS;
}
#endif
return TPM_RC_VALUE;
}
UINT16 TPM2B_DATA_Marshal(TPM2B_DATA* source, BYTE** buffer, INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_DATA_Unmarshal(TPM2B_DATA* target, BYTE** buffer, INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > sizeof(TPMT_HA)) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPMA_LOCALITY_Marshal(TPMA_LOCALITY* source,
BYTE** buffer,
INT32* size) {
return uint8_t_Marshal((uint8_t*)source, buffer, size);
}
TPM_RC TPMA_LOCALITY_Unmarshal(TPMA_LOCALITY* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
result = uint8_t_Unmarshal((uint8_t*)target, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_NAME_Marshal(TPM2B_NAME* source, BYTE** buffer, INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.name[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_NAME_Unmarshal(TPM2B_NAME* target, BYTE** buffer, INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > sizeof(TPMU_NAME)) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.name[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPMI_ALG_HASH_Marshal(TPMI_ALG_HASH* source,
BYTE** buffer,
INT32* size) {
return uint16_t_Marshal(source, buffer, size);
}
TPM_RC TPMI_ALG_HASH_Unmarshal(TPMI_ALG_HASH* target,
BYTE** buffer,
INT32* size,
BOOL allow_conditional_value) {
TPM_RC result;
BOOL has_valid_value = FALSE;
result = uint16_t_Unmarshal(target, buffer, size);
if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) {
return result;
}
if (*target == TPM_ALG_NULL) {
return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_HASH;
}
switch (*target) {
#ifdef TPM_ALG_SHA
case TPM_ALG_SHA:
#endif
#ifdef TPM_ALG_SHA1
case TPM_ALG_SHA1:
#endif
#ifdef TPM_ALG_SHA256
case TPM_ALG_SHA256:
#endif
#ifdef TPM_ALG_SHA384
case TPM_ALG_SHA384:
#endif
#ifdef TPM_ALG_SHA512
case TPM_ALG_SHA512:
#endif
#ifdef TPM_ALG_SM3_256
case TPM_ALG_SM3_256:
#endif
has_valid_value = TRUE;
break;
}
if (!has_valid_value) {
return TPM_RC_HASH;
}
return TPM_RC_SUCCESS;
}
UINT16 UINT8_Marshal(UINT8* source, BYTE** buffer, INT32* size) {
return uint8_t_Marshal(source, buffer, size);
}
TPM_RC UINT8_Unmarshal(UINT8* target, BYTE** buffer, INT32* size) {
return uint8_t_Unmarshal(target, buffer, size);
}
UINT16 TPMS_PCR_SELECTION_Marshal(TPMS_PCR_SELECTION* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += TPMI_ALG_HASH_Marshal(&source->hash, buffer, size);
total_size += UINT8_Marshal(&source->sizeofSelect, buffer, size);
for (i = 0; i < source->sizeofSelect; ++i) {
total_size += BYTE_Marshal(&source->pcrSelect[i], buffer, size);
}
return total_size;
}
TPM_RC TPMS_PCR_SELECTION_Unmarshal(TPMS_PCR_SELECTION* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = TPMI_ALG_HASH_Unmarshal(&target->hash, buffer, size, FALSE);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = UINT8_Unmarshal(&target->sizeofSelect, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->sizeofSelect > PCR_SELECT_MAX) {
return TPM_RC_VALUE;
}
if (target->sizeofSelect < PCR_SELECT_MIN) {
return TPM_RC_VALUE;
}
for (i = 0; i < target->sizeofSelect; ++i) {
result = BYTE_Unmarshal(&target->pcrSelect[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 UINT32_Marshal(UINT32* source, BYTE** buffer, INT32* size) {
return uint32_t_Marshal(source, buffer, size);
}
TPM_RC UINT32_Unmarshal(UINT32* target, BYTE** buffer, INT32* size) {
return uint32_t_Unmarshal(target, buffer, size);
}
UINT16 TPML_PCR_SELECTION_Marshal(TPML_PCR_SELECTION* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT32_Marshal(&source->count, buffer, size);
for (i = 0; i < source->count; ++i) {
total_size +=
TPMS_PCR_SELECTION_Marshal(&source->pcrSelections[i], buffer, size);
}
return total_size;
}
TPM_RC TPML_PCR_SELECTION_Unmarshal(TPML_PCR_SELECTION* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT32_Unmarshal(&target->count, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->count > HASH_COUNT) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->count; ++i) {
result =
TPMS_PCR_SELECTION_Unmarshal(&target->pcrSelections[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPMS_CREATION_DATA_Marshal(TPMS_CREATION_DATA* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += TPML_PCR_SELECTION_Marshal(&source->pcrSelect, buffer, size);
total_size += TPM2B_DIGEST_Marshal(&source->pcrDigest, buffer, size);
total_size += TPMA_LOCALITY_Marshal(&source->locality, buffer, size);
total_size += TPM_ALG_ID_Marshal(&source->parentNameAlg, buffer, size);
total_size += TPM2B_NAME_Marshal(&source->parentName, buffer, size);
total_size += TPM2B_NAME_Marshal(&source->parentQualifiedName, buffer, size);
total_size += TPM2B_DATA_Marshal(&source->outsideInfo, buffer, size);
return total_size;
}
TPM_RC TPMS_CREATION_DATA_Unmarshal(TPMS_CREATION_DATA* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
result = TPML_PCR_SELECTION_Unmarshal(&target->pcrSelect, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPM2B_DIGEST_Unmarshal(&target->pcrDigest, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPMA_LOCALITY_Unmarshal(&target->locality, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPM_ALG_ID_Unmarshal(&target->parentNameAlg, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPM2B_NAME_Unmarshal(&target->parentName, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPM2B_NAME_Unmarshal(&target->parentQualifiedName, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPM2B_DATA_Unmarshal(&target->outsideInfo, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_CREATION_DATA_Marshal(TPM2B_CREATION_DATA* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
total_size +=
TPMS_CREATION_DATA_Marshal(&source->t.creationData, buffer, size);
{
BYTE* size_location = *buffer - total_size;
INT32 size_field_size = sizeof(UINT16);
UINT16 payload_size = total_size - (UINT16)size_field_size;
UINT16_Marshal(&payload_size, &size_location, &size_field_size);
}
return total_size;
}
TPM_RC TPM2B_CREATION_DATA_Unmarshal(TPM2B_CREATION_DATA* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
UINT32 start_size = *size;
UINT32 struct_size;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SIZE;
}
result = TPMS_CREATION_DATA_Unmarshal(&target->t.creationData, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
struct_size = start_size - *size - sizeof(target->t.size);
if (struct_size != target->t.size) {
return TPM_RC_SIZE;
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_DIGEST_VALUES_Marshal(TPM2B_DIGEST_VALUES* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_DIGEST_VALUES_Unmarshal(TPM2B_DIGEST_VALUES* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > sizeof(TPML_DIGEST_VALUES)) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_ECC_PARAMETER_Marshal(TPM2B_ECC_PARAMETER* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_ECC_PARAMETER_Unmarshal(TPM2B_ECC_PARAMETER* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > MAX_ECC_KEY_BYTES) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPMS_ECC_POINT_Marshal(TPMS_ECC_POINT* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += TPM2B_ECC_PARAMETER_Marshal(&source->x, buffer, size);
total_size += TPM2B_ECC_PARAMETER_Marshal(&source->y, buffer, size);
return total_size;
}
TPM_RC TPMS_ECC_POINT_Unmarshal(TPMS_ECC_POINT* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
result = TPM2B_ECC_PARAMETER_Unmarshal(&target->x, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPM2B_ECC_PARAMETER_Unmarshal(&target->y, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_ECC_POINT_Marshal(TPM2B_ECC_POINT* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
total_size += TPMS_ECC_POINT_Marshal(&source->t.point, buffer, size);
{
BYTE* size_location = *buffer - total_size;
INT32 size_field_size = sizeof(UINT16);
UINT16 payload_size = total_size - (UINT16)size_field_size;
UINT16_Marshal(&payload_size, &size_location, &size_field_size);
}
return total_size;
}
TPM_RC TPM2B_ECC_POINT_Unmarshal(TPM2B_ECC_POINT* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
UINT32 start_size = *size;
UINT32 struct_size;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SIZE;
}
result = TPMS_ECC_POINT_Unmarshal(&target->t.point, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
struct_size = start_size - *size - sizeof(target->t.size);
if (struct_size != target->t.size) {
return TPM_RC_SIZE;
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_ENCRYPTED_SECRET_Marshal(TPM2B_ENCRYPTED_SECRET* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.secret[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_ENCRYPTED_SECRET_Unmarshal(TPM2B_ENCRYPTED_SECRET* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > sizeof(TPMU_ENCRYPTED_SECRET)) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.secret[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_EVENT_Marshal(TPM2B_EVENT* source, BYTE** buffer, INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_EVENT_Unmarshal(TPM2B_EVENT* target, BYTE** buffer, INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > 1024) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_ID_OBJECT_Marshal(TPM2B_ID_OBJECT* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.credential[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_ID_OBJECT_Unmarshal(TPM2B_ID_OBJECT* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > sizeof(_ID_OBJECT)) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.credential[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_IV_Marshal(TPM2B_IV* source, BYTE** buffer, INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_IV_Unmarshal(TPM2B_IV* target, BYTE** buffer, INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > MAX_SYM_BLOCK_SIZE) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_MAX_BUFFER_Marshal(TPM2B_MAX_BUFFER* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_MAX_BUFFER_Unmarshal(TPM2B_MAX_BUFFER* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > MAX_DIGEST_BUFFER) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_MAX_NV_BUFFER_Marshal(TPM2B_MAX_NV_BUFFER* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_MAX_NV_BUFFER_Unmarshal(TPM2B_MAX_NV_BUFFER* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > MAX_NV_BUFFER_SIZE) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_NONCE_Marshal(TPM2B_NONCE* source, BYTE** buffer, INT32* size) {
return TPM2B_DIGEST_Marshal(source, buffer, size);
}
TPM_RC TPM2B_NONCE_Unmarshal(TPM2B_NONCE* target, BYTE** buffer, INT32* size) {
return TPM2B_DIGEST_Unmarshal(target, buffer, size);
}
UINT16 TPMI_RH_NV_INDEX_Marshal(TPMI_RH_NV_INDEX* source,
BYTE** buffer,
INT32* size) {
return uint32_t_Marshal(source, buffer, size);
}
TPM_RC TPMI_RH_NV_INDEX_Unmarshal(TPMI_RH_NV_INDEX* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
BOOL has_valid_value = FALSE;
result = uint32_t_Unmarshal(target, buffer, size);
if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) {
return result;
}
if ((*target >= NV_INDEX_FIRST) && (*target <= NV_INDEX_LAST)) {
has_valid_value = TRUE;
}
if (!has_valid_value) {
return TPM_RC_VALUE;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMA_NV_Marshal(TPMA_NV* source, BYTE** buffer, INT32* size) {
return uint32_t_Marshal((uint32_t*)source, buffer, size);
}
TPM_RC TPMA_NV_Unmarshal(TPMA_NV* target, BYTE** buffer, INT32* size) {
TPM_RC result;
result = uint32_t_Unmarshal((uint32_t*)target, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->reserved7_9 != 0) {
return TPM_RC_RESERVED_BITS;
}
if (target->reserved20_24 != 0) {
return TPM_RC_RESERVED_BITS;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMS_NV_PUBLIC_Marshal(TPMS_NV_PUBLIC* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += TPMI_RH_NV_INDEX_Marshal(&source->nvIndex, buffer, size);
total_size += TPMI_ALG_HASH_Marshal(&source->nameAlg, buffer, size);
total_size += TPMA_NV_Marshal(&source->attributes, buffer, size);
total_size += TPM2B_DIGEST_Marshal(&source->authPolicy, buffer, size);
total_size += UINT16_Marshal(&source->dataSize, buffer, size);
return total_size;
}
TPM_RC TPMS_NV_PUBLIC_Unmarshal(TPMS_NV_PUBLIC* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
result = TPMI_RH_NV_INDEX_Unmarshal(&target->nvIndex, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPMI_ALG_HASH_Unmarshal(&target->nameAlg, buffer, size, FALSE);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPMA_NV_Unmarshal(&target->attributes, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPM2B_DIGEST_Unmarshal(&target->authPolicy, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = UINT16_Unmarshal(&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 TPM2B_NV_PUBLIC_Marshal(TPM2B_NV_PUBLIC* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
total_size += TPMS_NV_PUBLIC_Marshal(&source->t.nvPublic, buffer, size);
{
BYTE* size_location = *buffer - total_size;
INT32 size_field_size = sizeof(UINT16);
UINT16 payload_size = total_size - (UINT16)size_field_size;
UINT16_Marshal(&payload_size, &size_location, &size_field_size);
}
return total_size;
}
TPM_RC TPM2B_NV_PUBLIC_Unmarshal(TPM2B_NV_PUBLIC* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
UINT32 start_size = *size;
UINT32 struct_size;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SIZE;
}
result = TPMS_NV_PUBLIC_Unmarshal(&target->t.nvPublic, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
struct_size = start_size - *size - sizeof(target->t.size);
if (struct_size != target->t.size) {
return TPM_RC_SIZE;
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_OPERAND_Marshal(TPM2B_OPERAND* source,
BYTE** buffer,
INT32* size) {
return TPM2B_DIGEST_Marshal(source, buffer, size);
}
TPM_RC TPM2B_OPERAND_Unmarshal(TPM2B_OPERAND* target,
BYTE** buffer,
INT32* size) {
return TPM2B_DIGEST_Unmarshal(target, buffer, size);
}
UINT16 TPM2B_PRIVATE_Marshal(TPM2B_PRIVATE* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_PRIVATE_Unmarshal(TPM2B_PRIVATE* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > sizeof(_PRIVATE)) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_PRIVATE_KEY_RSA_Marshal(TPM2B_PRIVATE_KEY_RSA* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_PRIVATE_KEY_RSA_Unmarshal(TPM2B_PRIVATE_KEY_RSA* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > MAX_RSA_KEY_BYTES / 2) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_PRIVATE_VENDOR_SPECIFIC_Marshal(
TPM2B_PRIVATE_VENDOR_SPECIFIC* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_PRIVATE_VENDOR_SPECIFIC_Unmarshal(
TPM2B_PRIVATE_VENDOR_SPECIFIC* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > PRIVATE_VENDOR_SPECIFIC_BYTES) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
UINT16 TPMA_OBJECT_Marshal(TPMA_OBJECT* source, BYTE** buffer, INT32* size) {
return uint32_t_Marshal((uint32_t*)source, buffer, size);
}
TPM_RC TPMA_OBJECT_Unmarshal(TPMA_OBJECT* target, BYTE** buffer, INT32* size) {
TPM_RC result;
result = uint32_t_Unmarshal((uint32_t*)target, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->reserved0 != 0) {
return TPM_RC_RESERVED_BITS;
}
if (target->reserved3 != 0) {
return TPM_RC_RESERVED_BITS;
}
if (target->reserved8_9 != 0) {
return TPM_RC_RESERVED_BITS;
}
if (target->reserved12_15 != 0) {
return TPM_RC_RESERVED_BITS;
}
if (target->reserved19_31 != 0) {
return TPM_RC_RESERVED_BITS;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMI_ALG_PUBLIC_Marshal(TPMI_ALG_PUBLIC* source,
BYTE** buffer,
INT32* size) {
return uint16_t_Marshal(source, buffer, size);
}
TPM_RC TPMI_ALG_PUBLIC_Unmarshal(TPMI_ALG_PUBLIC* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
BOOL has_valid_value = FALSE;
result = uint16_t_Unmarshal(target, buffer, size);
if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) {
return result;
}
switch (*target) {
#ifdef TPM_ALG_RSA
case TPM_ALG_RSA:
#endif
#ifdef TPM_ALG_KEYEDHASH
case TPM_ALG_KEYEDHASH:
#endif
#ifdef TPM_ALG_ECC
case TPM_ALG_ECC:
#endif
#ifdef TPM_ALG_SYMCIPHER
case TPM_ALG_SYMCIPHER:
#endif
has_valid_value = TRUE;
break;
}
if (!has_valid_value) {
return TPM_RC_TYPE;
}
return TPM_RC_SUCCESS;
}
UINT16 TPM2B_PUBLIC_KEY_RSA_Marshal(TPM2B_PUBLIC_KEY_RSA* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
INT32 i;
total_size += UINT16_Marshal(&source->t.size, buffer, size);
for (i = 0; i < source->t.size; ++i) {
total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size);
}
return total_size;
}
TPM_RC TPM2B_PUBLIC_KEY_RSA_Unmarshal(TPM2B_PUBLIC_KEY_RSA* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
INT32 i;
result = UINT16_Unmarshal(&target->t.size, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
if (target->t.size == 0) {
return TPM_RC_SUCCESS;
}
if (target->t.size > MAX_RSA_KEY_BYTES) {
return TPM_RC_SIZE;
}
for (i = 0; i < target->t.size; ++i) {
result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
}
return TPM_RC_SUCCESS;
}
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
#ifdef TPM_ALG_SYMCIPHER
case TPM_ALG_SYMCIPHER:
return TPM2B_DIGEST_Marshal((TPM2B_DIGEST*)&source->sym, buffer, size);
#endif
#ifdef TPM_ALG_RSA
case TPM_ALG_RSA:
return TPM2B_PUBLIC_KEY_RSA_Marshal((TPM2B_PUBLIC_KEY_RSA*)&source->rsa,
buffer, size);
#endif
#ifdef TPM_ALG_ECC
case TPM_ALG_ECC:
return TPMS_ECC_POINT_Marshal((TPMS_ECC_POINT*)&source->ecc, buffer,
size);
#endif
}
return 0;
}
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
#ifdef TPM_ALG_SYMCIPHER
case TPM_ALG_SYMCIPHER:
return TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST*)&target->sym, buffer, size);
#endif
#ifdef TPM_ALG_RSA
case TPM_ALG_RSA:
return TPM2B_PUBLIC_KEY_RSA_Unmarshal((TPM2B_PUBLIC_KEY_RSA*)&target->rsa,
buffer, size);
#endif
#ifdef TPM_ALG_ECC
case TPM_ALG_ECC:
return TPMS_ECC_POINT_Unmarshal((TPMS_ECC_POINT*)&target->ecc, buffer,
size);
#endif
}
return TPM_RC_SELECTOR;
}
UINT16 TPM_KEY_BITS_Marshal(TPM_KEY_BITS* source, BYTE** buffer, INT32* size) {
return uint16_t_Marshal(source, buffer, size);
}
TPM_RC TPM_KEY_BITS_Unmarshal(TPM_KEY_BITS* target,
BYTE** buffer,
INT32* size) {
return uint16_t_Unmarshal(target, buffer, size);
}
UINT16 TPMI_AES_KEY_BITS_Marshal(TPMI_AES_KEY_BITS* source,
BYTE** buffer,
INT32* size) {
return TPM_KEY_BITS_Marshal(source, buffer, size);
}
TPM_RC TPMI_AES_KEY_BITS_Unmarshal(TPMI_AES_KEY_BITS* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
uint16_t supported_values[] = AES_KEY_SIZES_BITS;
size_t length = sizeof(supported_values) / sizeof(supported_values[0]);
size_t i;
BOOL is_supported_value = FALSE;
result = TPM_KEY_BITS_Unmarshal(target, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
for (i = 0; i < length; ++i) {
if (*target == supported_values[i]) {
is_supported_value = TRUE;
break;
}
}
if (!is_supported_value) {
return TPM_RC_VALUE;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMI_SM4_KEY_BITS_Marshal(TPMI_SM4_KEY_BITS* source,
BYTE** buffer,
INT32* size) {
return TPM_KEY_BITS_Marshal(source, buffer, size);
}
TPM_RC TPMI_SM4_KEY_BITS_Unmarshal(TPMI_SM4_KEY_BITS* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
uint16_t supported_values[] = SM4_KEY_SIZES_BITS;
size_t length = sizeof(supported_values) / sizeof(supported_values[0]);
size_t i;
BOOL is_supported_value = FALSE;
result = TPM_KEY_BITS_Unmarshal(target, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
for (i = 0; i < length; ++i) {
if (*target == supported_values[i]) {
is_supported_value = TRUE;
break;
}
}
if (!is_supported_value) {
return TPM_RC_VALUE;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMI_CAMELLIA_KEY_BITS_Marshal(TPMI_CAMELLIA_KEY_BITS* source,
BYTE** buffer,
INT32* size) {
return TPM_KEY_BITS_Marshal(source, buffer, size);
}
TPM_RC TPMI_CAMELLIA_KEY_BITS_Unmarshal(TPMI_CAMELLIA_KEY_BITS* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
uint16_t supported_values[] = CAMELLIA_KEY_SIZES_BITS;
size_t length = sizeof(supported_values) / sizeof(supported_values[0]);
size_t i;
BOOL is_supported_value = FALSE;
result = TPM_KEY_BITS_Unmarshal(target, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
for (i = 0; i < length; ++i) {
if (*target == supported_values[i]) {
is_supported_value = TRUE;
break;
}
}
if (!is_supported_value) {
return TPM_RC_VALUE;
}
return TPM_RC_SUCCESS;
}
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
#ifdef TPM_ALG_SM4
case TPM_ALG_SM4:
return TPMI_SM4_KEY_BITS_Marshal((TPMI_SM4_KEY_BITS*)&source->sm4, buffer,
size);
#endif
#ifdef TPM_ALG_CAMELLIA
case TPM_ALG_CAMELLIA:
return TPMI_CAMELLIA_KEY_BITS_Marshal(
(TPMI_CAMELLIA_KEY_BITS*)&source->camellia, buffer, size);
#endif
#ifdef TPM_ALG_XOR
case TPM_ALG_XOR:
return TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH*)&source->xor_, buffer, size);
#endif
#ifdef TPM_ALG_NULL
case TPM_ALG_NULL:
return 0;
#endif
}
return 0;
}
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
#ifdef TPM_ALG_SM4
case TPM_ALG_SM4:
return TPMI_SM4_KEY_BITS_Unmarshal((TPMI_SM4_KEY_BITS*)&target->sm4,
buffer, size);
#endif
#ifdef TPM_ALG_CAMELLIA
case TPM_ALG_CAMELLIA:
return TPMI_CAMELLIA_KEY_BITS_Unmarshal(
(TPMI_CAMELLIA_KEY_BITS*)&target->camellia, buffer, size);
#endif
#ifdef TPM_ALG_XOR
case TPM_ALG_XOR:
return TPMI_ALG_HASH_Unmarshal(&target->xor_, buffer, size, FALSE);
#endif
#ifdef TPM_ALG_NULL
case TPM_ALG_NULL:
return TPM_RC_SUCCESS;
#endif
}
return TPM_RC_SELECTOR;
}
UINT16 TPMI_ALG_SYM_MODE_Marshal(TPMI_ALG_SYM_MODE* source,
BYTE** buffer,
INT32* size) {
return uint16_t_Marshal(source, buffer, size);
}
TPM_RC TPMI_ALG_SYM_MODE_Unmarshal(TPMI_ALG_SYM_MODE* target,
BYTE** buffer,
INT32* size,
BOOL allow_conditional_value) {
TPM_RC result;
BOOL has_valid_value = FALSE;
result = uint16_t_Unmarshal(target, buffer, size);
if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) {
return result;
}
if (*target == TPM_ALG_NULL) {
return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_MODE;
}
switch (*target) {
#ifdef TPM_ALG_CTR
case TPM_ALG_CTR:
#endif
#ifdef TPM_ALG_OFB
case TPM_ALG_OFB:
#endif
#ifdef TPM_ALG_CBC
case TPM_ALG_CBC:
#endif
#ifdef TPM_ALG_CFB
case TPM_ALG_CFB:
#endif
#ifdef TPM_ALG_ECB
case TPM_ALG_ECB:
#endif
has_valid_value = TRUE;
break;
}
if (!has_valid_value) {
return TPM_RC_MODE;
}
return TPM_RC_SUCCESS;
}
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
#ifdef TPM_ALG_SM4
case TPM_ALG_SM4:
return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE*)&source->sm4, buffer,
size);
#endif
#ifdef TPM_ALG_CAMELLIA
case TPM_ALG_CAMELLIA:
return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE*)&source->camellia,
buffer, size);
#endif
#ifdef TPM_ALG_XOR
case TPM_ALG_XOR:
return 0;
#endif
#ifdef TPM_ALG_NULL
case TPM_ALG_NULL:
return 0;
#endif
}
return 0;
}
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(&target->aes, buffer, size, FALSE);
#endif
#ifdef TPM_ALG_SM4
case TPM_ALG_SM4:
return TPMI_ALG_SYM_MODE_Unmarshal(&target->sm4, buffer, size, FALSE);
#endif
#ifdef TPM_ALG_CAMELLIA
case TPM_ALG_CAMELLIA:
return TPMI_ALG_SYM_MODE_Unmarshal(&target->camellia, buffer, size,
FALSE);
#endif
#ifdef TPM_ALG_XOR
case TPM_ALG_XOR:
return TPM_RC_SUCCESS;
#endif
#ifdef TPM_ALG_NULL
case TPM_ALG_NULL:
return TPM_RC_SUCCESS;
#endif
}
return TPM_RC_SELECTOR;
}
UINT16 TPMI_ALG_SYM_OBJECT_Marshal(TPMI_ALG_SYM_OBJECT* source,
BYTE** buffer,
INT32* size) {
return uint16_t_Marshal(source, buffer, size);
}
TPM_RC TPMI_ALG_SYM_OBJECT_Unmarshal(TPMI_ALG_SYM_OBJECT* target,
BYTE** buffer,
INT32* size,
BOOL allow_conditional_value) {
TPM_RC result;
BOOL has_valid_value = FALSE;
result = uint16_t_Unmarshal(target, buffer, size);
if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) {
return result;
}
if (*target == TPM_ALG_NULL) {
return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_SYMMETRIC;
}
switch (*target) {
#ifdef TPM_ALG_AES
case TPM_ALG_AES:
#endif
#ifdef TPM_ALG_SM4
case TPM_ALG_SM4:
#endif
#ifdef TPM_ALG_CAMELLIA
case TPM_ALG_CAMELLIA:
#endif
has_valid_value = TRUE;
break;
}
if (!has_valid_value) {
return TPM_RC_SYMMETRIC;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMT_SYM_DEF_OBJECT_Marshal(TPMT_SYM_DEF_OBJECT* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += TPMI_ALG_SYM_OBJECT_Marshal(&source->algorithm, buffer, size);
total_size += TPMU_SYM_KEY_BITS_Marshal(&source->keyBits, buffer, size,
source->algorithm);
total_size +=
TPMU_SYM_MODE_Marshal(&source->mode, buffer, size, source->algorithm);
return total_size;
}
TPM_RC TPMT_SYM_DEF_OBJECT_Unmarshal(TPMT_SYM_DEF_OBJECT* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
result =
TPMI_ALG_SYM_OBJECT_Unmarshal(&target->algorithm, buffer, size, TRUE);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPMU_SYM_KEY_BITS_Unmarshal(&target->keyBits, buffer, size,
target->algorithm);
if (result != TPM_RC_SUCCESS) {
return result;
}
result =
TPMU_SYM_MODE_Unmarshal(&target->mode, buffer, size, target->algorithm);
if (result != TPM_RC_SUCCESS) {
return result;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMI_ALG_RSA_SCHEME_Marshal(TPMI_ALG_RSA_SCHEME* source,
BYTE** buffer,
INT32* size) {
return uint16_t_Marshal(source, buffer, size);
}
TPM_RC TPMI_ALG_RSA_SCHEME_Unmarshal(TPMI_ALG_RSA_SCHEME* target,
BYTE** buffer,
INT32* size,
BOOL allow_conditional_value) {
TPM_RC result;
BOOL has_valid_value = FALSE;
result = uint16_t_Unmarshal(target, buffer, size);
if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) {
return result;
}
if (*target == TPM_ALG_NULL) {
return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE;
}
switch (*target) {
#ifdef TPM_ALG_RSAES
case TPM_ALG_RSAES:
#endif
#ifdef TPM_ALG_OAEP
case TPM_ALG_OAEP:
#endif
#ifdef TPM_ALG_RSASSA
case TPM_ALG_RSASSA:
#endif
#ifdef TPM_ALG_RSAPSS
case TPM_ALG_RSAPSS:
#endif
has_valid_value = TRUE;
break;
}
if (!has_valid_value) {
return TPM_RC_VALUE;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMS_SCHEME_HASH_Marshal(TPMS_SCHEME_HASH* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += TPMI_ALG_HASH_Marshal(&source->hashAlg, buffer, size);
return total_size;
}
TPM_RC TPMS_SCHEME_HASH_Unmarshal(TPMS_SCHEME_HASH* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
result = TPMI_ALG_HASH_Unmarshal(&target->hashAlg, buffer, size, FALSE);
if (result != TPM_RC_SUCCESS) {
return result;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMS_SIG_SCHEME_RSAPSS_Marshal(TPMS_SIG_SCHEME_RSAPSS* source,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Marshal(source, buffer, size);
}
TPM_RC TPMS_SIG_SCHEME_RSAPSS_Unmarshal(TPMS_SIG_SCHEME_RSAPSS* target,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size);
}
UINT16 TPMS_SIG_SCHEME_SM2_Marshal(TPMS_SIG_SCHEME_SM2* source,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Marshal(source, buffer, size);
}
TPM_RC TPMS_SIG_SCHEME_SM2_Unmarshal(TPMS_SIG_SCHEME_SM2* target,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size);
}
UINT16 TPMS_SIG_SCHEME_ECSCHNORR_Marshal(TPMS_SIG_SCHEME_ECSCHNORR* source,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Marshal(source, buffer, size);
}
TPM_RC TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal(TPMS_SIG_SCHEME_ECSCHNORR* target,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size);
}
UINT16 TPMS_SCHEME_ECDAA_Marshal(TPMS_SCHEME_ECDAA* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += TPMI_ALG_HASH_Marshal(&source->hashAlg, buffer, size);
total_size += UINT16_Marshal(&source->count, buffer, size);
return total_size;
}
TPM_RC TPMS_SCHEME_ECDAA_Unmarshal(TPMS_SCHEME_ECDAA* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
result = TPMI_ALG_HASH_Unmarshal(&target->hashAlg, buffer, size, FALSE);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = UINT16_Unmarshal(&target->count, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMS_SIG_SCHEME_ECDAA_Marshal(TPMS_SIG_SCHEME_ECDAA* source,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_ECDAA_Marshal(source, buffer, size);
}
TPM_RC TPMS_SIG_SCHEME_ECDAA_Unmarshal(TPMS_SIG_SCHEME_ECDAA* target,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_ECDAA_Unmarshal(target, buffer, size);
}
UINT16 TPMS_KEY_SCHEME_ECDH_Marshal(TPMS_KEY_SCHEME_ECDH* source,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Marshal(source, buffer, size);
}
TPM_RC TPMS_KEY_SCHEME_ECDH_Unmarshal(TPMS_KEY_SCHEME_ECDH* target,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size);
}
UINT16 TPMS_KEY_SCHEME_ECMQV_Marshal(TPMS_KEY_SCHEME_ECMQV* source,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Marshal(source, buffer, size);
}
TPM_RC TPMS_KEY_SCHEME_ECMQV_Unmarshal(TPMS_KEY_SCHEME_ECMQV* target,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size);
}
UINT16 TPMS_SIG_SCHEME_RSASSA_Marshal(TPMS_SIG_SCHEME_RSASSA* source,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Marshal(source, buffer, size);
}
TPM_RC TPMS_SIG_SCHEME_RSASSA_Unmarshal(TPMS_SIG_SCHEME_RSASSA* target,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size);
}
UINT16 TPMS_ENC_SCHEME_OAEP_Marshal(TPMS_ENC_SCHEME_OAEP* source,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Marshal(source, buffer, size);
}
TPM_RC TPMS_ENC_SCHEME_OAEP_Unmarshal(TPMS_ENC_SCHEME_OAEP* target,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size);
}
UINT16 TPMS_EMPTY_Marshal(TPMS_EMPTY* source, BYTE** buffer, INT32* size) {
UINT16 total_size = 0;
return total_size;
}
TPM_RC TPMS_EMPTY_Unmarshal(TPMS_EMPTY* target, BYTE** buffer, INT32* size) {
TPM_RC result;
(void)result;
return TPM_RC_SUCCESS;
}
UINT16 TPMS_ENC_SCHEME_RSAES_Marshal(TPMS_ENC_SCHEME_RSAES* source,
BYTE** buffer,
INT32* size) {
return TPMS_EMPTY_Marshal(source, buffer, size);
}
TPM_RC TPMS_ENC_SCHEME_RSAES_Unmarshal(TPMS_ENC_SCHEME_RSAES* target,
BYTE** buffer,
INT32* size) {
return TPMS_EMPTY_Unmarshal(target, buffer, size);
}
UINT16 TPMS_SIG_SCHEME_ECDSA_Marshal(TPMS_SIG_SCHEME_ECDSA* source,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Marshal(source, buffer, size);
}
TPM_RC TPMS_SIG_SCHEME_ECDSA_Unmarshal(TPMS_SIG_SCHEME_ECDSA* target,
BYTE** buffer,
INT32* size) {
return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size);
}
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
#ifdef TPM_ALG_ECMQV
case TPM_ALG_ECMQV:
return TPMS_KEY_SCHEME_ECMQV_Marshal(
(TPMS_KEY_SCHEME_ECMQV*)&source->ecmqv, buffer, size);
#endif
#ifdef TPM_ALG_RSASSA
case TPM_ALG_RSASSA:
return TPMS_SIG_SCHEME_RSASSA_Marshal(
(TPMS_SIG_SCHEME_RSASSA*)&source->rsassa, buffer, size);
#endif
#ifdef TPM_ALG_RSAPSS
case TPM_ALG_RSAPSS:
return TPMS_SIG_SCHEME_RSAPSS_Marshal(
(TPMS_SIG_SCHEME_RSAPSS*)&source->rsapss, buffer, size);
#endif
#ifdef TPM_ALG_ECDSA
case TPM_ALG_ECDSA:
return TPMS_SIG_SCHEME_ECDSA_Marshal(
(TPMS_SIG_SCHEME_ECDSA*)&source->ecdsa, buffer, size);
#endif
#ifdef TPM_ALG_ECDAA
case TPM_ALG_ECDAA:
return TPMS_SIG_SCHEME_ECDAA_Marshal(
(TPMS_SIG_SCHEME_ECDAA*)&source->ecdaa, buffer, size);
#endif
#ifdef TPM_ALG_SM2
case TPM_ALG_SM2:
return TPMS_SIG_SCHEME_SM2_Marshal((TPMS_SIG_SCHEME_SM2*)&source->sm2,
buffer, size);
#endif
#ifdef TPM_ALG_ECSCHNORR
case TPM_ALG_ECSCHNORR:
return TPMS_SIG_SCHEME_ECSCHNORR_Marshal(
(TPMS_SIG_SCHEME_ECSCHNORR*)&source->ecschnorr, buffer, size);
#endif
#ifdef TPM_ALG_RSAES
case TPM_ALG_RSAES:
return TPMS_ENC_SCHEME_RSAES_Marshal(
(TPMS_ENC_SCHEME_RSAES*)&source->rsaes, buffer, size);
#endif
#ifdef TPM_ALG_OAEP
case TPM_ALG_OAEP:
return TPMS_ENC_SCHEME_OAEP_Marshal((TPMS_ENC_SCHEME_OAEP*)&source->oaep,
buffer, size);
#endif
#ifdef TPM_ALG_NULL
case TPM_ALG_NULL:
return 0;
#endif
}
return 0;
}
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
#ifdef TPM_ALG_ECMQV
case TPM_ALG_ECMQV:
return TPMS_KEY_SCHEME_ECMQV_Unmarshal(
(TPMS_KEY_SCHEME_ECMQV*)&target->ecmqv, buffer, size);
#endif
#ifdef TPM_ALG_RSASSA
case TPM_ALG_RSASSA:
return TPMS_SIG_SCHEME_RSASSA_Unmarshal(
(TPMS_SIG_SCHEME_RSASSA*)&target->rsassa, buffer, size);
#endif
#ifdef TPM_ALG_RSAPSS
case TPM_ALG_RSAPSS:
return TPMS_SIG_SCHEME_RSAPSS_Unmarshal(
(TPMS_SIG_SCHEME_RSAPSS*)&target->rsapss, buffer, size);
#endif
#ifdef TPM_ALG_ECDSA
case TPM_ALG_ECDSA:
return TPMS_SIG_SCHEME_ECDSA_Unmarshal(
(TPMS_SIG_SCHEME_ECDSA*)&target->ecdsa, buffer, size);
#endif
#ifdef TPM_ALG_ECDAA
case TPM_ALG_ECDAA:
return TPMS_SIG_SCHEME_ECDAA_Unmarshal(
(TPMS_SIG_SCHEME_ECDAA*)&target->ecdaa, buffer, size);
#endif
#ifdef TPM_ALG_SM2
case TPM_ALG_SM2:
return TPMS_SIG_SCHEME_SM2_Unmarshal((TPMS_SIG_SCHEME_SM2*)&target->sm2,
buffer, size);
#endif
#ifdef TPM_ALG_ECSCHNORR
case TPM_ALG_ECSCHNORR:
return TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal(
(TPMS_SIG_SCHEME_ECSCHNORR*)&target->ecschnorr, buffer, size);
#endif
#ifdef TPM_ALG_RSAES
case TPM_ALG_RSAES:
return TPMS_ENC_SCHEME_RSAES_Unmarshal(
(TPMS_ENC_SCHEME_RSAES*)&target->rsaes, buffer, size);
#endif
#ifdef TPM_ALG_OAEP
case TPM_ALG_OAEP:
return TPMS_ENC_SCHEME_OAEP_Unmarshal(
(TPMS_ENC_SCHEME_OAEP*)&target->oaep, buffer, size);
#endif
#ifdef TPM_ALG_NULL
case TPM_ALG_NULL:
return TPM_RC_SUCCESS;
#endif
}
return TPM_RC_SELECTOR;
}
UINT16 TPMT_RSA_SCHEME_Marshal(TPMT_RSA_SCHEME* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += TPMI_ALG_RSA_SCHEME_Marshal(&source->scheme, buffer, size);
total_size +=
TPMU_ASYM_SCHEME_Marshal(&source->details, buffer, size, source->scheme);
return total_size;
}
TPM_RC TPMT_RSA_SCHEME_Unmarshal(TPMT_RSA_SCHEME* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
result = TPMI_ALG_RSA_SCHEME_Unmarshal(&target->scheme, buffer, size, TRUE);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPMU_ASYM_SCHEME_Unmarshal(&target->details, buffer, size,
target->scheme);
if (result != TPM_RC_SUCCESS) {
return result;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMI_RSA_KEY_BITS_Marshal(TPMI_RSA_KEY_BITS* source,
BYTE** buffer,
INT32* size) {
return uint16_t_Marshal(source, buffer, size);
}
TPM_RC TPMI_RSA_KEY_BITS_Unmarshal(TPMI_RSA_KEY_BITS* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
uint16_t supported_values[] = RSA_KEY_SIZES_BITS;
size_t length = sizeof(supported_values) / sizeof(supported_values[0]);
size_t i;
BOOL is_supported_value = FALSE;
result = uint16_t_Unmarshal(target, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
for (i = 0; i < length; ++i) {
if (*target == supported_values[i]) {
is_supported_value = TRUE;
break;
}
}
if (!is_supported_value) {
return TPM_RC_VALUE;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMS_RSA_PARMS_Marshal(TPMS_RSA_PARMS* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += TPMT_SYM_DEF_OBJECT_Marshal(&source->symmetric, buffer, size);
total_size += TPMT_RSA_SCHEME_Marshal(&source->scheme, buffer, size);
total_size += TPMI_RSA_KEY_BITS_Marshal(&source->keyBits, buffer, size);
total_size += UINT32_Marshal(&source->exponent, buffer, size);
return total_size;
}
TPM_RC TPMS_RSA_PARMS_Unmarshal(TPMS_RSA_PARMS* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
result = TPMT_SYM_DEF_OBJECT_Unmarshal(&target->symmetric, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPMT_RSA_SCHEME_Unmarshal(&target->scheme, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = TPMI_RSA_KEY_BITS_Unmarshal(&target->keyBits, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
result = UINT32_Unmarshal(&target->exponent, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMS_SYMCIPHER_PARMS_Marshal(TPMS_SYMCIPHER_PARMS* source,
BYTE** buffer,
INT32* size) {
UINT16 total_size = 0;
total_size += TPMT_SYM_DEF_OBJECT_Marshal(&source->sym, buffer, size);
return total_size;
}
TPM_RC TPMS_SYMCIPHER_PARMS_Unmarshal(TPMS_SYMCIPHER_PARMS* target,
BYTE** buffer,
INT32* size) {
TPM_RC result;
result = TPMT_SYM_DEF_OBJECT_Unmarshal(&target->sym, buffer, size);
if (result != TPM_RC_SUCCESS) {
return result;
}
return TPM_RC_SUCCESS;
}
UINT16 TPMI_ALG_ASYM_SCHEME_Marshal(TPMI_ALG_ASYM_SCHEME* source,
BYTE** buffer,
INT32* size) {
return uint16_t_Marshal(source, buffer, size);
}
TPM_RC TPMI_ALG_ASYM_SCHEME_Unmarshal(TPMI_ALG_ASYM_SCHEME* target,
BYTE** buffer,
INT32* size,
BOOL allow_conditional_value) {
TPM_RC result;
BOOL has_valid_value = FALSE;
result = uint16_t_Unmarshal(target, buffer, size);