blob: d7d42469b6186f33980bf4f46f1843336ade624e [file] [log] [blame]
//
// Copyright (C) 2014 The Android Open Source Project
//
// 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.
//
// THIS CODE IS GENERATED - DO NOT MODIFY!
#include "trunks/tpm_generated.h"
#include <string>
#include <base/basictypes.h>
#include <base/bind.h>
#include <base/callback.h>
#include <base/logging.h>
#include <base/stl_util.h>
#include <base/strings/string_number_conversions.h>
#include <base/sys_byteorder.h>
#include <crypto/secure_hash.h>
#include "trunks/authorization_delegate.h"
#include "trunks/command_transceiver.h"
#include "trunks/error_codes.h"
namespace trunks {
size_t GetNumberOfRequestHandles(TPM_CC command_code) {
switch (command_code) {
case TPM_CC_Startup: return 0;
case TPM_CC_Shutdown: return 0;
case TPM_CC_SelfTest: return 0;
case TPM_CC_IncrementalSelfTest: return 0;
case TPM_CC_GetTestResult: return 0;
case TPM_CC_StartAuthSession: return 2;
case TPM_CC_PolicyRestart: return 1;
case TPM_CC_Create: return 1;
case TPM_CC_Load: return 1;
case TPM_CC_LoadExternal: return 1;
case TPM_CC_ReadPublic: return 1;
case TPM_CC_ActivateCredential: return 2;
case TPM_CC_MakeCredential: return 1;
case TPM_CC_Unseal: return 1;
case TPM_CC_ObjectChangeAuth: return 2;
case TPM_CC_Duplicate: return 2;
case TPM_CC_Rewrap: return 2;
case TPM_CC_Import: return 1;
case TPM_CC_RSA_Encrypt: return 1;
case TPM_CC_RSA_Decrypt: return 1;
case TPM_CC_ECDH_KeyGen: return 1;
case TPM_CC_ECDH_ZGen: return 1;
case TPM_CC_ECC_Parameters: return 0;
case TPM_CC_ZGen_2Phase: return 1;
case TPM_CC_EncryptDecrypt: return 1;
case TPM_CC_Hash: return 1;
case TPM_CC_HMAC: return 1;
case TPM_CC_GetRandom: return 0;
case TPM_CC_StirRandom: return 0;
case TPM_CC_HMAC_Start: return 1;
case TPM_CC_HashSequenceStart: return 0;
case TPM_CC_SequenceUpdate: return 1;
case TPM_CC_SequenceComplete: return 2;
case TPM_CC_EventSequenceComplete: return 2;
case TPM_CC_Certify: return 2;
case TPM_CC_CertifyCreation: return 2;
case TPM_CC_Quote: return 1;
case TPM_CC_GetSessionAuditDigest: return 3;
case TPM_CC_GetCommandAuditDigest: return 2;
case TPM_CC_GetTime: return 2;
case TPM_CC_Commit: return 1;
case TPM_CC_EC_Ephemeral: return 0;
case TPM_CC_VerifySignature: return 1;
case TPM_CC_Sign: return 1;
case TPM_CC_SetCommandCodeAuditStatus: return 1;
case TPM_CC_PCR_Extend: return 1;
case TPM_CC_PCR_Event: return 1;
case TPM_CC_PCR_Read: return 0;
case TPM_CC_PCR_Allocate: return 1;
case TPM_CC_PCR_SetAuthPolicy: return 2;
case TPM_CC_PCR_SetAuthValue: return 1;
case TPM_CC_PCR_Reset: return 1;
case TPM_CC_PolicySigned: return 2;
case TPM_CC_PolicySecret: return 2;
case TPM_CC_PolicyTicket: return 1;
case TPM_CC_PolicyOR: return 1;
case TPM_CC_PolicyPCR: return 1;
case TPM_CC_PolicyLocality: return 1;
case TPM_CC_PolicyNV: return 3;
case TPM_CC_PolicyCounterTimer: return 1;
case TPM_CC_PolicyCommandCode: return 1;
case TPM_CC_PolicyPhysicalPresence: return 1;
case TPM_CC_PolicyCpHash: return 1;
case TPM_CC_PolicyNameHash: return 1;
case TPM_CC_PolicyDuplicationSelect: return 1;
case TPM_CC_PolicyAuthorize: return 1;
case TPM_CC_PolicyAuthValue: return 1;
case TPM_CC_PolicyPassword: return 1;
case TPM_CC_PolicyGetDigest: return 1;
case TPM_CC_PolicyNvWritten: return 1;
case TPM_CC_CreatePrimary: return 1;
case TPM_CC_HierarchyControl: return 1;
case TPM_CC_SetPrimaryPolicy: return 1;
case TPM_CC_ChangePPS: return 1;
case TPM_CC_ChangeEPS: return 1;
case TPM_CC_Clear: return 1;
case TPM_CC_ClearControl: return 1;
case TPM_CC_HierarchyChangeAuth: return 1;
case TPM_CC_DictionaryAttackLockReset: return 1;
case TPM_CC_DictionaryAttackParameters: return 1;
case TPM_CC_PP_Commands: return 1;
case TPM_CC_SetAlgorithmSet: return 1;
case TPM_CC_FieldUpgradeStart: return 2;
case TPM_CC_FieldUpgradeData: return 0;
case TPM_CC_FirmwareRead: return 0;
case TPM_CC_ContextSave: return 1;
case TPM_CC_ContextLoad: return 0;
case TPM_CC_FlushContext: return 0;
case TPM_CC_EvictControl: return 2;
case TPM_CC_ReadClock: return 0;
case TPM_CC_ClockSet: return 1;
case TPM_CC_ClockRateAdjust: return 1;
case TPM_CC_GetCapability: return 0;
case TPM_CC_TestParms: return 0;
case TPM_CC_NV_DefineSpace: return 1;
case TPM_CC_NV_UndefineSpace: return 2;
case TPM_CC_NV_UndefineSpaceSpecial: return 2;
case TPM_CC_NV_ReadPublic: return 1;
case TPM_CC_NV_Write: return 2;
case TPM_CC_NV_Increment: return 2;
case TPM_CC_NV_Extend: return 2;
case TPM_CC_NV_SetBits: return 2;
case TPM_CC_NV_WriteLock: return 2;
case TPM_CC_NV_GlobalWriteLock: return 1;
case TPM_CC_NV_Read: return 2;
case TPM_CC_NV_ReadLock: return 2;
case TPM_CC_NV_ChangeAuth: return 1;
case TPM_CC_NV_Certify: return 3;
default: LOG(WARNING) << "Unknown command code: " << command_code;
}
return 0;
}
size_t GetNumberOfResponseHandles(TPM_CC command_code) {
switch (command_code) {
case TPM_CC_Startup: return 0;
case TPM_CC_Shutdown: return 0;
case TPM_CC_SelfTest: return 0;
case TPM_CC_IncrementalSelfTest: return 0;
case TPM_CC_GetTestResult: return 0;
case TPM_CC_StartAuthSession: return 1;
case TPM_CC_PolicyRestart: return 0;
case TPM_CC_Create: return 0;
case TPM_CC_Load: return 1;
case TPM_CC_LoadExternal: return 1;
case TPM_CC_ReadPublic: return 0;
case TPM_CC_ActivateCredential: return 0;
case TPM_CC_MakeCredential: return 0;
case TPM_CC_Unseal: return 0;
case TPM_CC_ObjectChangeAuth: return 0;
case TPM_CC_Duplicate: return 0;
case TPM_CC_Rewrap: return 0;
case TPM_CC_Import: return 0;
case TPM_CC_RSA_Encrypt: return 0;
case TPM_CC_RSA_Decrypt: return 0;
case TPM_CC_ECDH_KeyGen: return 0;
case TPM_CC_ECDH_ZGen: return 0;
case TPM_CC_ECC_Parameters: return 0;
case TPM_CC_ZGen_2Phase: return 0;
case TPM_CC_EncryptDecrypt: return 0;
case TPM_CC_Hash: return 0;
case TPM_CC_HMAC: return 0;
case TPM_CC_GetRandom: return 0;
case TPM_CC_StirRandom: return 0;
case TPM_CC_HMAC_Start: return 1;
case TPM_CC_HashSequenceStart: return 1;
case TPM_CC_SequenceUpdate: return 0;
case TPM_CC_SequenceComplete: return 0;
case TPM_CC_EventSequenceComplete: return 0;
case TPM_CC_Certify: return 0;
case TPM_CC_CertifyCreation: return 0;
case TPM_CC_Quote: return 0;
case TPM_CC_GetSessionAuditDigest: return 0;
case TPM_CC_GetCommandAuditDigest: return 0;
case TPM_CC_GetTime: return 0;
case TPM_CC_Commit: return 0;
case TPM_CC_EC_Ephemeral: return 0;
case TPM_CC_VerifySignature: return 0;
case TPM_CC_Sign: return 0;
case TPM_CC_SetCommandCodeAuditStatus: return 0;
case TPM_CC_PCR_Extend: return 0;
case TPM_CC_PCR_Event: return 0;
case TPM_CC_PCR_Read: return 0;
case TPM_CC_PCR_Allocate: return 0;
case TPM_CC_PCR_SetAuthPolicy: return 0;
case TPM_CC_PCR_SetAuthValue: return 0;
case TPM_CC_PCR_Reset: return 0;
case TPM_CC_PolicySigned: return 0;
case TPM_CC_PolicySecret: return 0;
case TPM_CC_PolicyTicket: return 0;
case TPM_CC_PolicyOR: return 0;
case TPM_CC_PolicyPCR: return 0;
case TPM_CC_PolicyLocality: return 0;
case TPM_CC_PolicyNV: return 0;
case TPM_CC_PolicyCounterTimer: return 0;
case TPM_CC_PolicyCommandCode: return 0;
case TPM_CC_PolicyPhysicalPresence: return 0;
case TPM_CC_PolicyCpHash: return 0;
case TPM_CC_PolicyNameHash: return 0;
case TPM_CC_PolicyDuplicationSelect: return 0;
case TPM_CC_PolicyAuthorize: return 0;
case TPM_CC_PolicyAuthValue: return 0;
case TPM_CC_PolicyPassword: return 0;
case TPM_CC_PolicyGetDigest: return 0;
case TPM_CC_PolicyNvWritten: return 0;
case TPM_CC_CreatePrimary: return 1;
case TPM_CC_HierarchyControl: return 0;
case TPM_CC_SetPrimaryPolicy: return 0;
case TPM_CC_ChangePPS: return 0;
case TPM_CC_ChangeEPS: return 0;
case TPM_CC_Clear: return 0;
case TPM_CC_ClearControl: return 0;
case TPM_CC_HierarchyChangeAuth: return 0;
case TPM_CC_DictionaryAttackLockReset: return 0;
case TPM_CC_DictionaryAttackParameters: return 0;
case TPM_CC_PP_Commands: return 0;
case TPM_CC_SetAlgorithmSet: return 0;
case TPM_CC_FieldUpgradeStart: return 0;
case TPM_CC_FieldUpgradeData: return 0;
case TPM_CC_FirmwareRead: return 0;
case TPM_CC_ContextSave: return 0;
case TPM_CC_ContextLoad: return 1;
case TPM_CC_FlushContext: return 0;
case TPM_CC_EvictControl: return 0;
case TPM_CC_ReadClock: return 0;
case TPM_CC_ClockSet: return 0;
case TPM_CC_ClockRateAdjust: return 0;
case TPM_CC_GetCapability: return 0;
case TPM_CC_TestParms: return 0;
case TPM_CC_NV_DefineSpace: return 0;
case TPM_CC_NV_UndefineSpace: return 0;
case TPM_CC_NV_UndefineSpaceSpecial: return 0;
case TPM_CC_NV_ReadPublic: return 0;
case TPM_CC_NV_Write: return 0;
case TPM_CC_NV_Increment: return 0;
case TPM_CC_NV_Extend: return 0;
case TPM_CC_NV_SetBits: return 0;
case TPM_CC_NV_WriteLock: return 0;
case TPM_CC_NV_GlobalWriteLock: return 0;
case TPM_CC_NV_Read: return 0;
case TPM_CC_NV_ReadLock: return 0;
case TPM_CC_NV_ChangeAuth: return 0;
case TPM_CC_NV_Certify: return 0;
default: LOG(WARNING) << "Unknown command code: " << command_code;
}
return 0;
}
TPM_RC Serialize_uint8_t(const uint8_t& value, std::string* buffer) {
VLOG(3) << __func__;
uint8_t value_net = value;
switch (sizeof(uint8_t)) {
case 2:
value_net = base::HostToNet16(value);
break;
case 4:
value_net = base::HostToNet32(value);
break;
case 8:
value_net = base::HostToNet64(value);
break;
default:
break;
}
const char* value_bytes = reinterpret_cast<const char*>(&value_net);
buffer->append(value_bytes, sizeof(uint8_t));
return TPM_RC_SUCCESS;
}
TPM_RC Parse_uint8_t(
std::string* buffer,
uint8_t* value,
std::string* value_bytes) {
VLOG(3) << __func__;
if (buffer->size() < sizeof(uint8_t))
return TPM_RC_INSUFFICIENT;
uint8_t value_net = 0;
memcpy(&value_net, buffer->data(), sizeof(uint8_t));
switch (sizeof(uint8_t)) {
case 2:
*value = base::NetToHost16(value_net);
break;
case 4:
*value = base::NetToHost32(value_net);
break;
case 8:
*value = base::NetToHost64(value_net);
break;
default:
*value = value_net;
}
if (value_bytes) {
value_bytes->append(buffer->substr(0, sizeof(uint8_t)));
}
buffer->erase(0, sizeof(uint8_t));
return TPM_RC_SUCCESS;
}
TPM_RC Serialize_int8_t(const int8_t& value, std::string* buffer) {
VLOG(3) << __func__;
int8_t value_net = value;
switch (sizeof(int8_t)) {
case 2:
value_net = base::HostToNet16(value);
break;
case 4:
value_net = base::HostToNet32(value);
break;
case 8:
value_net = base::HostToNet64(value);
break;
default:
break;
}
const char* value_bytes = reinterpret_cast<const char*>(&value_net);
buffer->append(value_bytes, sizeof(int8_t));
return TPM_RC_SUCCESS;
}
TPM_RC Parse_int8_t(
std::string* buffer,
int8_t* value,
std::string* value_bytes) {
VLOG(3) << __func__;
if (buffer->size() < sizeof(int8_t))
return TPM_RC_INSUFFICIENT;
int8_t value_net = 0;
memcpy(&value_net, buffer->data(), sizeof(int8_t));
switch (sizeof(int8_t)) {
case 2:
*value = base::NetToHost16(value_net);
break;
case 4:
*value = base::NetToHost32(value_net);
break;
case 8:
*value = base::NetToHost64(value_net);
break;
default:
*value = value_net;
}
if (value_bytes) {
value_bytes->append(buffer->substr(0, sizeof(int8_t)));
}
buffer->erase(0, sizeof(int8_t));
return TPM_RC_SUCCESS;
}
TPM_RC Serialize_int(const int& value, std::string* buffer) {
VLOG(3) << __func__;
int value_net = value;
switch (sizeof(int)) {
case 2:
value_net = base::HostToNet16(value);
break;
case 4:
value_net = base::HostToNet32(value);
break;
case 8:
value_net = base::HostToNet64(value);
break;
default:
break;
}
const char* value_bytes = reinterpret_cast<const char*>(&value_net);
buffer->append(value_bytes, sizeof(int));
return TPM_RC_SUCCESS;
}
TPM_RC Parse_int(
std::string* buffer,
int* value,
std::string* value_bytes) {
VLOG(3) << __func__;
if (buffer->size() < sizeof(int))
return TPM_RC_INSUFFICIENT;
int value_net = 0;
memcpy(&value_net, buffer->data(), sizeof(int));
switch (sizeof(int)) {
case 2:
*value = base::NetToHost16(value_net);
break;
case 4:
*value = base::NetToHost32(value_net);
break;
case 8:
*value = base::NetToHost64(value_net);
break;
default:
*value = value_net;
}
if (value_bytes) {
value_bytes->append(buffer->substr(0, sizeof(int)));
}
buffer->erase(0, sizeof(int));
return TPM_RC_SUCCESS;
}
TPM_RC Serialize_uint16_t(const uint16_t& value, std::string* buffer) {
VLOG(3) << __func__;
uint16_t value_net = value;
switch (sizeof(uint16_t)) {
case 2:
value_net = base::HostToNet16(value);
break;
case 4:
value_net = base::HostToNet32(value);
break;
case 8:
value_net = base::HostToNet64(value);
break;
default:
break;
}
const char* value_bytes = reinterpret_cast<const char*>(&value_net);
buffer->append(value_bytes, sizeof(uint16_t));
return TPM_RC_SUCCESS;
}
TPM_RC Parse_uint16_t(
std::string* buffer,
uint16_t* value,
std::string* value_bytes) {
VLOG(3) << __func__;
if (buffer->size() < sizeof(uint16_t))
return TPM_RC_INSUFFICIENT;
uint16_t value_net = 0;
memcpy(&value_net, buffer->data(), sizeof(uint16_t));
switch (sizeof(uint16_t)) {
case 2:
*value = base::NetToHost16(value_net);
break;
case 4:
*value = base::NetToHost32(value_net);
break;
case 8:
*value = base::NetToHost64(value_net);
break;
default:
*value = value_net;
}
if (value_bytes) {
value_bytes->append(buffer->substr(0, sizeof(uint16_t)));
}
buffer->erase(0, sizeof(uint16_t));
return TPM_RC_SUCCESS;
}
TPM_RC Serialize_int16_t(const int16_t& value, std::string* buffer) {
VLOG(3) << __func__;
int16_t value_net = value;
switch (sizeof(int16_t)) {
case 2:
value_net = base::HostToNet16(value);
break;
case 4:
value_net = base::HostToNet32(value);
break;
case 8:
value_net = base::HostToNet64(value);
break;
default:
break;
}
const char* value_bytes = reinterpret_cast<const char*>(&value_net);
buffer->append(value_bytes, sizeof(int16_t));
return TPM_RC_SUCCESS;
}
TPM_RC Parse_int16_t(
std::string* buffer,
int16_t* value,
std::string* value_bytes) {
VLOG(3) << __func__;
if (buffer->size() < sizeof(int16_t))
return TPM_RC_INSUFFICIENT;
int16_t value_net = 0;
memcpy(&value_net, buffer->data(), sizeof(int16_t));
switch (sizeof(int16_t)) {
case 2:
*value = base::NetToHost16(value_net);
break;
case 4:
*value = base::NetToHost32(value_net);
break;
case 8:
*value = base::NetToHost64(value_net);
break;
default:
*value = value_net;
}
if (value_bytes) {
value_bytes->append(buffer->substr(0, sizeof(int16_t)));
}
buffer->erase(0, sizeof(int16_t));
return TPM_RC_SUCCESS;
}
TPM_RC Serialize_uint32_t(const uint32_t& value, std::string* buffer) {
VLOG(3) << __func__;
uint32_t value_net = value;
switch (sizeof(uint32_t)) {
case 2:
value_net = base::HostToNet16(value);
break;
case 4:
value_net = base::HostToNet32(value);
break;
case 8:
value_net = base::HostToNet64(value);
break;
default:
break;
}
const char* value_bytes = reinterpret_cast<const char*>(&value_net);
buffer->append(value_bytes, sizeof(uint32_t));
return TPM_RC_SUCCESS;
}
TPM_RC Parse_uint32_t(
std::string* buffer,
uint32_t* value,
std::string* value_bytes) {
VLOG(3) << __func__;
if (buffer->size() < sizeof(uint32_t))
return TPM_RC_INSUFFICIENT;
uint32_t value_net = 0;
memcpy(&value_net, buffer->data(), sizeof(uint32_t));
switch (sizeof(uint32_t)) {
case 2:
*value = base::NetToHost16(value_net);
break;
case 4:
*value = base::NetToHost32(value_net);
break;
case 8:
*value = base::NetToHost64(value_net);
break;
default:
*value = value_net;
}
if (value_bytes) {
value_bytes->append(buffer->substr(0, sizeof(uint32_t)));
}
buffer->erase(0, sizeof(uint32_t));
return TPM_RC_SUCCESS;
}
TPM_RC Serialize_int32_t(const int32_t& value, std::string* buffer) {
VLOG(3) << __func__;
int32_t value_net = value;
switch (sizeof(int32_t)) {
case 2:
value_net = base::HostToNet16(value);
break;
case 4:
value_net = base::HostToNet32(value);
break;
case 8:
value_net = base::HostToNet64(value);
break;
default:
break;
}
const char* value_bytes = reinterpret_cast<const char*>(&value_net);
buffer->append(value_bytes, sizeof(int32_t));
return TPM_RC_SUCCESS;
}
TPM_RC Parse_int32_t(
std::string* buffer,
int32_t* value,
std::string* value_bytes) {
VLOG(3) << __func__;
if (buffer->size() < sizeof(int32_t))
return TPM_RC_INSUFFICIENT;
int32_t value_net = 0;
memcpy(&value_net, buffer->data(), sizeof(int32_t));
switch (sizeof(int32_t)) {
case 2:
*value = base::NetToHost16(value_net);
break;
case 4:
*value = base::NetToHost32(value_net);
break;
case 8:
*value = base::NetToHost64(value_net);
break;
default:
*value = value_net;
}
if (value_bytes) {
value_bytes->append(buffer->substr(0, sizeof(int32_t)));
}
buffer->erase(0, sizeof(int32_t));
return TPM_RC_SUCCESS;
}
TPM_RC Serialize_uint64_t(const uint64_t& value, std::string* buffer) {
VLOG(3) << __func__;
uint64_t value_net = value;
switch (sizeof(uint64_t)) {
case 2:
value_net = base::HostToNet16(value);
break;
case 4:
value_net = base::HostToNet32(value);
break;
case 8:
value_net = base::HostToNet64(value);
break;
default:
break;
}
const char* value_bytes = reinterpret_cast<const char*>(&value_net);
buffer->append(value_bytes, sizeof(uint64_t));
return TPM_RC_SUCCESS;
}
TPM_RC Parse_uint64_t(
std::string* buffer,
uint64_t* value,
std::string* value_bytes) {
VLOG(3) << __func__;
if (buffer->size() < sizeof(uint64_t))
return TPM_RC_INSUFFICIENT;
uint64_t value_net = 0;
memcpy(&value_net, buffer->data(), sizeof(uint64_t));
switch (sizeof(uint64_t)) {
case 2:
*value = base::NetToHost16(value_net);
break;
case 4:
*value = base::NetToHost32(value_net);
break;
case 8:
*value = base::NetToHost64(value_net);
break;
default:
*value = value_net;
}
if (value_bytes) {
value_bytes->append(buffer->substr(0, sizeof(uint64_t)));
}
buffer->erase(0, sizeof(uint64_t));
return TPM_RC_SUCCESS;
}
TPM_RC Serialize_int64_t(const int64_t& value, std::string* buffer) {
VLOG(3) << __func__;
int64_t value_net = value;
switch (sizeof(int64_t)) {
case 2:
value_net = base::HostToNet16(value);
break;
case 4:
value_net = base::HostToNet32(value);
break;
case 8:
value_net = base::HostToNet64(value);
break;
default:
break;
}
const char* value_bytes = reinterpret_cast<const char*>(&value_net);
buffer->append(value_bytes, sizeof(int64_t));
return TPM_RC_SUCCESS;
}
TPM_RC Parse_int64_t(
std::string* buffer,
int64_t* value,
std::string* value_bytes) {
VLOG(3) << __func__;
if (buffer->size() < sizeof(int64_t))
return TPM_RC_INSUFFICIENT;
int64_t value_net = 0;
memcpy(&value_net, buffer->data(), sizeof(int64_t));
switch (sizeof(int64_t)) {
case 2:
*value = base::NetToHost16(value_net);
break;
case 4:
*value = base::NetToHost32(value_net);
break;
case 8:
*value = base::NetToHost64(value_net);
break;
default:
*value = value_net;
}
if (value_bytes) {
value_bytes->append(buffer->substr(0, sizeof(int64_t)));
}
buffer->erase(0, sizeof(int64_t));
return TPM_RC_SUCCESS;
}
TPM_RC Serialize_UINT8(
const UINT8& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_uint8_t(value, buffer);
}
TPM_RC Parse_UINT8(
std::string* buffer,
UINT8* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_uint8_t(buffer, value, value_bytes);
}
TPM_RC Serialize_BYTE(
const BYTE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_uint8_t(value, buffer);
}
TPM_RC Parse_BYTE(
std::string* buffer,
BYTE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_uint8_t(buffer, value, value_bytes);
}
TPM_RC Serialize_INT8(
const INT8& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_int8_t(value, buffer);
}
TPM_RC Parse_INT8(
std::string* buffer,
INT8* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_int8_t(buffer, value, value_bytes);
}
TPM_RC Serialize_BOOL(
const BOOL& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_int(value, buffer);
}
TPM_RC Parse_BOOL(
std::string* buffer,
BOOL* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_int(buffer, value, value_bytes);
}
TPM_RC Serialize_UINT16(
const UINT16& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_uint16_t(value, buffer);
}
TPM_RC Parse_UINT16(
std::string* buffer,
UINT16* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_uint16_t(buffer, value, value_bytes);
}
TPM_RC Serialize_INT16(
const INT16& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_int16_t(value, buffer);
}
TPM_RC Parse_INT16(
std::string* buffer,
INT16* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_int16_t(buffer, value, value_bytes);
}
TPM_RC Serialize_UINT32(
const UINT32& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_uint32_t(value, buffer);
}
TPM_RC Parse_UINT32(
std::string* buffer,
UINT32* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_uint32_t(buffer, value, value_bytes);
}
TPM_RC Serialize_INT32(
const INT32& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_int32_t(value, buffer);
}
TPM_RC Parse_INT32(
std::string* buffer,
INT32* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_int32_t(buffer, value, value_bytes);
}
TPM_RC Serialize_UINT64(
const UINT64& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_uint64_t(value, buffer);
}
TPM_RC Parse_UINT64(
std::string* buffer,
UINT64* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_uint64_t(buffer, value, value_bytes);
}
TPM_RC Serialize_INT64(
const INT64& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_int64_t(value, buffer);
}
TPM_RC Parse_INT64(
std::string* buffer,
INT64* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_int64_t(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_ALGORITHM_ID(
const TPM_ALGORITHM_ID& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_ALGORITHM_ID(
std::string* buffer,
TPM_ALGORITHM_ID* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_MODIFIER_INDICATOR(
const TPM_MODIFIER_INDICATOR& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_MODIFIER_INDICATOR(
std::string* buffer,
TPM_MODIFIER_INDICATOR* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_AUTHORIZATION_SIZE(
const TPM_AUTHORIZATION_SIZE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_AUTHORIZATION_SIZE(
std::string* buffer,
TPM_AUTHORIZATION_SIZE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_PARAMETER_SIZE(
const TPM_PARAMETER_SIZE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_PARAMETER_SIZE(
std::string* buffer,
TPM_PARAMETER_SIZE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_KEY_SIZE(
const TPM_KEY_SIZE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT16(value, buffer);
}
TPM_RC Parse_TPM_KEY_SIZE(
std::string* buffer,
TPM_KEY_SIZE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT16(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_KEY_BITS(
const TPM_KEY_BITS& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT16(value, buffer);
}
TPM_RC Parse_TPM_KEY_BITS(
std::string* buffer,
TPM_KEY_BITS* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT16(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_HANDLE(
const TPM_HANDLE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_HANDLE(
std::string* buffer,
TPM_HANDLE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM2B_DIGEST(
const TPM2B_DIGEST& value,
std::string* buffer) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Serialize_UINT16(value.size, buffer);
if (result) {
return result;
}
if (arraysize(value.buffer) < value.size) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < value.size; ++i) {
result = Serialize_BYTE(value.buffer[i], buffer);
if (result) {
return result;
}
}
return result;
}
TPM_RC Parse_TPM2B_DIGEST(
std::string* buffer,
TPM2B_DIGEST* value,
std::string* value_bytes) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Parse_UINT16(
buffer,
&value->size,
value_bytes);
if (result) {
return result;
}
if (arraysize(value->buffer) < value->size) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < value->size; ++i) {
result = Parse_BYTE(
buffer,
&value->buffer[i],
value_bytes);
if (result) {
return result;
}
}
return result;
}
TPM2B_DIGEST Make_TPM2B_DIGEST(
const std::string& bytes) {
TPM2B_DIGEST tpm2b;
CHECK(bytes.size() <= sizeof(tpm2b.buffer));
memset(&tpm2b, 0, sizeof(TPM2B_DIGEST));
tpm2b.size = bytes.size();
memcpy(tpm2b.buffer, bytes.data(), bytes.size());
return tpm2b;
}
std::string StringFrom_TPM2B_DIGEST(
const TPM2B_DIGEST& tpm2b) {
const char* char_buffer = reinterpret_cast<const char*>(
tpm2b.buffer);
return std::string(char_buffer, tpm2b.size);
}
TPM_RC Serialize_TPM2B_NONCE(
const TPM2B_NONCE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM2B_DIGEST(value, buffer);
}
TPM_RC Parse_TPM2B_NONCE(
std::string* buffer,
TPM2B_NONCE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM2B_DIGEST(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM2B_AUTH(
const TPM2B_AUTH& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM2B_DIGEST(value, buffer);
}
TPM_RC Parse_TPM2B_AUTH(
std::string* buffer,
TPM2B_AUTH* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM2B_DIGEST(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM2B_OPERAND(
const TPM2B_OPERAND& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM2B_DIGEST(value, buffer);
}
TPM_RC Parse_TPM2B_OPERAND(
std::string* buffer,
TPM2B_OPERAND* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM2B_DIGEST(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_ALG_ID(
const TPM_ALG_ID& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT16(value, buffer);
}
TPM_RC Parse_TPM_ALG_ID(
std::string* buffer,
TPM_ALG_ID* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT16(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_HASH(
const TPMI_ALG_HASH& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_HASH(
std::string* buffer,
TPMI_ALG_HASH* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMS_SCHEME_SIGHASH(
const TPMS_SCHEME_SIGHASH& value,
std::string* buffer) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Serialize_TPMI_ALG_HASH(value.hash_alg, buffer);
if (result) {
return result;
}
return result;
}
TPM_RC Parse_TPMS_SCHEME_SIGHASH(
std::string* buffer,
TPMS_SCHEME_SIGHASH* value,
std::string* value_bytes) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Parse_TPMI_ALG_HASH(
buffer,
&value->hash_alg,
value_bytes);
if (result) {
return result;
}
return result;
}
TPM_RC Serialize_TPMS_SCHEME_HMAC(
const TPMS_SCHEME_HMAC& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPMS_SCHEME_SIGHASH(value, buffer);
}
TPM_RC Parse_TPMS_SCHEME_HMAC(
std::string* buffer,
TPMS_SCHEME_HMAC* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPMS_SCHEME_SIGHASH(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMS_SCHEME_RSASSA(
const TPMS_SCHEME_RSASSA& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPMS_SCHEME_SIGHASH(value, buffer);
}
TPM_RC Parse_TPMS_SCHEME_RSASSA(
std::string* buffer,
TPMS_SCHEME_RSASSA* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPMS_SCHEME_SIGHASH(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMS_SCHEME_RSAPSS(
const TPMS_SCHEME_RSAPSS& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPMS_SCHEME_SIGHASH(value, buffer);
}
TPM_RC Parse_TPMS_SCHEME_RSAPSS(
std::string* buffer,
TPMS_SCHEME_RSAPSS* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPMS_SCHEME_SIGHASH(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMS_SCHEME_ECDSA(
const TPMS_SCHEME_ECDSA& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPMS_SCHEME_SIGHASH(value, buffer);
}
TPM_RC Parse_TPMS_SCHEME_ECDSA(
std::string* buffer,
TPMS_SCHEME_ECDSA* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPMS_SCHEME_SIGHASH(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMS_SCHEME_SM2(
const TPMS_SCHEME_SM2& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPMS_SCHEME_SIGHASH(value, buffer);
}
TPM_RC Parse_TPMS_SCHEME_SM2(
std::string* buffer,
TPMS_SCHEME_SM2* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPMS_SCHEME_SIGHASH(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMS_SCHEME_ECSCHNORR(
const TPMS_SCHEME_ECSCHNORR& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPMS_SCHEME_SIGHASH(value, buffer);
}
TPM_RC Parse_TPMS_SCHEME_ECSCHNORR(
std::string* buffer,
TPMS_SCHEME_ECSCHNORR* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPMS_SCHEME_SIGHASH(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_YES_NO(
const TPMI_YES_NO& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_BYTE(value, buffer);
}
TPM_RC Parse_TPMI_YES_NO(
std::string* buffer,
TPMI_YES_NO* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_BYTE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_DH_OBJECT(
const TPMI_DH_OBJECT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_DH_OBJECT(
std::string* buffer,
TPMI_DH_OBJECT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_DH_PERSISTENT(
const TPMI_DH_PERSISTENT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_DH_PERSISTENT(
std::string* buffer,
TPMI_DH_PERSISTENT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_DH_ENTITY(
const TPMI_DH_ENTITY& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_DH_ENTITY(
std::string* buffer,
TPMI_DH_ENTITY* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_DH_PCR(
const TPMI_DH_PCR& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_DH_PCR(
std::string* buffer,
TPMI_DH_PCR* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_SH_AUTH_SESSION(
const TPMI_SH_AUTH_SESSION& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_SH_AUTH_SESSION(
std::string* buffer,
TPMI_SH_AUTH_SESSION* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_SH_HMAC(
const TPMI_SH_HMAC& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_SH_HMAC(
std::string* buffer,
TPMI_SH_HMAC* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_SH_POLICY(
const TPMI_SH_POLICY& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_SH_POLICY(
std::string* buffer,
TPMI_SH_POLICY* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_DH_CONTEXT(
const TPMI_DH_CONTEXT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_DH_CONTEXT(
std::string* buffer,
TPMI_DH_CONTEXT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_HIERARCHY(
const TPMI_RH_HIERARCHY& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_HIERARCHY(
std::string* buffer,
TPMI_RH_HIERARCHY* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_ENABLES(
const TPMI_RH_ENABLES& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_ENABLES(
std::string* buffer,
TPMI_RH_ENABLES* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_HIERARCHY_AUTH(
const TPMI_RH_HIERARCHY_AUTH& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_HIERARCHY_AUTH(
std::string* buffer,
TPMI_RH_HIERARCHY_AUTH* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_PLATFORM(
const TPMI_RH_PLATFORM& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_PLATFORM(
std::string* buffer,
TPMI_RH_PLATFORM* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_OWNER(
const TPMI_RH_OWNER& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_OWNER(
std::string* buffer,
TPMI_RH_OWNER* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_ENDORSEMENT(
const TPMI_RH_ENDORSEMENT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_ENDORSEMENT(
std::string* buffer,
TPMI_RH_ENDORSEMENT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_PROVISION(
const TPMI_RH_PROVISION& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_PROVISION(
std::string* buffer,
TPMI_RH_PROVISION* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_CLEAR(
const TPMI_RH_CLEAR& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_CLEAR(
std::string* buffer,
TPMI_RH_CLEAR* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_NV_AUTH(
const TPMI_RH_NV_AUTH& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_NV_AUTH(
std::string* buffer,
TPMI_RH_NV_AUTH* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_LOCKOUT(
const TPMI_RH_LOCKOUT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_LOCKOUT(
std::string* buffer,
TPMI_RH_LOCKOUT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RH_NV_INDEX(
const TPMI_RH_NV_INDEX& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPMI_RH_NV_INDEX(
std::string* buffer,
TPMI_RH_NV_INDEX* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_ASYM(
const TPMI_ALG_ASYM& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_ASYM(
std::string* buffer,
TPMI_ALG_ASYM* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_SYM(
const TPMI_ALG_SYM& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_SYM(
std::string* buffer,
TPMI_ALG_SYM* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_SYM_OBJECT(
const TPMI_ALG_SYM_OBJECT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_SYM_OBJECT(
std::string* buffer,
TPMI_ALG_SYM_OBJECT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_SYM_MODE(
const TPMI_ALG_SYM_MODE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_SYM_MODE(
std::string* buffer,
TPMI_ALG_SYM_MODE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_KDF(
const TPMI_ALG_KDF& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_KDF(
std::string* buffer,
TPMI_ALG_KDF* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_SIG_SCHEME(
const TPMI_ALG_SIG_SCHEME& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_SIG_SCHEME(
std::string* buffer,
TPMI_ALG_SIG_SCHEME* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ECC_KEY_EXCHANGE(
const TPMI_ECC_KEY_EXCHANGE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ECC_KEY_EXCHANGE(
std::string* buffer,
TPMI_ECC_KEY_EXCHANGE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_ST(
const TPM_ST& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT16(value, buffer);
}
TPM_RC Parse_TPM_ST(
std::string* buffer,
TPM_ST* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT16(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ST_COMMAND_TAG(
const TPMI_ST_COMMAND_TAG& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ST(value, buffer);
}
TPM_RC Parse_TPMI_ST_COMMAND_TAG(
std::string* buffer,
TPMI_ST_COMMAND_TAG* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ST(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ST_ATTEST(
const TPMI_ST_ATTEST& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ST(value, buffer);
}
TPM_RC Parse_TPMI_ST_ATTEST(
std::string* buffer,
TPMI_ST_ATTEST* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ST(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_AES_KEY_BITS(
const TPMI_AES_KEY_BITS& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_KEY_BITS(value, buffer);
}
TPM_RC Parse_TPMI_AES_KEY_BITS(
std::string* buffer,
TPMI_AES_KEY_BITS* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_KEY_BITS(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_SM4_KEY_BITS(
const TPMI_SM4_KEY_BITS& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_KEY_BITS(value, buffer);
}
TPM_RC Parse_TPMI_SM4_KEY_BITS(
std::string* buffer,
TPMI_SM4_KEY_BITS* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_KEY_BITS(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_KEYEDHASH_SCHEME(
const TPMI_ALG_KEYEDHASH_SCHEME& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_KEYEDHASH_SCHEME(
std::string* buffer,
TPMI_ALG_KEYEDHASH_SCHEME* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_ASYM_SCHEME(
const TPMI_ALG_ASYM_SCHEME& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_ASYM_SCHEME(
std::string* buffer,
TPMI_ALG_ASYM_SCHEME* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_RSA_SCHEME(
const TPMI_ALG_RSA_SCHEME& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_RSA_SCHEME(
std::string* buffer,
TPMI_ALG_RSA_SCHEME* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_RSA_DECRYPT(
const TPMI_ALG_RSA_DECRYPT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_RSA_DECRYPT(
std::string* buffer,
TPMI_ALG_RSA_DECRYPT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_RSA_KEY_BITS(
const TPMI_RSA_KEY_BITS& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_KEY_BITS(value, buffer);
}
TPM_RC Parse_TPMI_RSA_KEY_BITS(
std::string* buffer,
TPMI_RSA_KEY_BITS* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_KEY_BITS(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_ECC_SCHEME(
const TPMI_ALG_ECC_SCHEME& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_ECC_SCHEME(
std::string* buffer,
TPMI_ALG_ECC_SCHEME* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_ECC_CURVE(
const TPM_ECC_CURVE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT16(value, buffer);
}
TPM_RC Parse_TPM_ECC_CURVE(
std::string* buffer,
TPM_ECC_CURVE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT16(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ECC_CURVE(
const TPMI_ECC_CURVE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ECC_CURVE(value, buffer);
}
TPM_RC Parse_TPMI_ECC_CURVE(
std::string* buffer,
TPMI_ECC_CURVE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ECC_CURVE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMI_ALG_PUBLIC(
const TPMI_ALG_PUBLIC& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_ALG_ID(value, buffer);
}
TPM_RC Parse_TPMI_ALG_PUBLIC(
std::string* buffer,
TPMI_ALG_PUBLIC* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_ALG_ID(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMA_ALGORITHM(
const TPMA_ALGORITHM& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPMA_ALGORITHM(
std::string* buffer,
TPMA_ALGORITHM* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMA_OBJECT(
const TPMA_OBJECT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPMA_OBJECT(
std::string* buffer,
TPMA_OBJECT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMA_SESSION(
const TPMA_SESSION& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT8(value, buffer);
}
TPM_RC Parse_TPMA_SESSION(
std::string* buffer,
TPMA_SESSION* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT8(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMA_LOCALITY(
const TPMA_LOCALITY& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT8(value, buffer);
}
TPM_RC Parse_TPMA_LOCALITY(
std::string* buffer,
TPMA_LOCALITY* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT8(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMA_PERMANENT(
const TPMA_PERMANENT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPMA_PERMANENT(
std::string* buffer,
TPMA_PERMANENT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMA_STARTUP_CLEAR(
const TPMA_STARTUP_CLEAR& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPMA_STARTUP_CLEAR(
std::string* buffer,
TPMA_STARTUP_CLEAR* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMA_MEMORY(
const TPMA_MEMORY& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPMA_MEMORY(
std::string* buffer,
TPMA_MEMORY* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_CC(
const TPM_CC& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_CC(
std::string* buffer,
TPM_CC* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMA_CC(
const TPMA_CC& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_CC(value, buffer);
}
TPM_RC Parse_TPMA_CC(
std::string* buffer,
TPMA_CC* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_CC(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_NV_INDEX(
const TPM_NV_INDEX& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_NV_INDEX(
std::string* buffer,
TPM_NV_INDEX* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMA_NV(
const TPMA_NV& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPMA_NV(
std::string* buffer,
TPMA_NV* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_SPEC(
const TPM_SPEC& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_SPEC(
std::string* buffer,
TPM_SPEC* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_GENERATED(
const TPM_GENERATED& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_GENERATED(
std::string* buffer,
TPM_GENERATED* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_RC(
const TPM_RC& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_RC(
std::string* buffer,
TPM_RC* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_CLOCK_ADJUST(
const TPM_CLOCK_ADJUST& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_INT8(value, buffer);
}
TPM_RC Parse_TPM_CLOCK_ADJUST(
std::string* buffer,
TPM_CLOCK_ADJUST* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_INT8(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_EO(
const TPM_EO& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT16(value, buffer);
}
TPM_RC Parse_TPM_EO(
std::string* buffer,
TPM_EO* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT16(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_SU(
const TPM_SU& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT16(value, buffer);
}
TPM_RC Parse_TPM_SU(
std::string* buffer,
TPM_SU* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT16(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_SE(
const TPM_SE& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT8(value, buffer);
}
TPM_RC Parse_TPM_SE(
std::string* buffer,
TPM_SE* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT8(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_CAP(
const TPM_CAP& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_CAP(
std::string* buffer,
TPM_CAP* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_PT(
const TPM_PT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_PT(
std::string* buffer,
TPM_PT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_PT_PCR(
const TPM_PT_PCR& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_PT_PCR(
std::string* buffer,
TPM_PT_PCR* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_PS(
const TPM_PS& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_PS(
std::string* buffer,
TPM_PS* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_HT(
const TPM_HT& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT8(value, buffer);
}
TPM_RC Parse_TPM_HT(
std::string* buffer,
TPM_HT* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT8(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_RH(
const TPM_RH& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_UINT32(value, buffer);
}
TPM_RC Parse_TPM_RH(
std::string* buffer,
TPM_RH* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_UINT32(buffer, value, value_bytes);
}
TPM_RC Serialize_TPM_HC(
const TPM_HC& value,
std::string* buffer) {
VLOG(3) << __func__;
return Serialize_TPM_HANDLE(value, buffer);
}
TPM_RC Parse_TPM_HC(
std::string* buffer,
TPM_HC* value,
std::string* value_bytes) {
VLOG(3) << __func__;
return Parse_TPM_HANDLE(buffer, value, value_bytes);
}
TPM_RC Serialize_TPMS_ALGORITHM_DESCRIPTION(
const TPMS_ALGORITHM_DESCRIPTION& value,
std::string* buffer) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Serialize_TPM_ALG_ID(value.alg, buffer);
if (result) {
return result;
}
result = Serialize_TPMA_ALGORITHM(value.attributes, buffer);
if (result) {
return result;
}
return result;
}
TPM_RC Parse_TPMS_ALGORITHM_DESCRIPTION(
std::string* buffer,
TPMS_ALGORITHM_DESCRIPTION* value,
std::string* value_bytes) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Parse_TPM_ALG_ID(
buffer,
&value->alg,
value_bytes);
if (result) {
return result;
}
result = Parse_TPMA_ALGORITHM(
buffer,
&value->attributes,
value_bytes);
if (result) {
return result;
}
return result;
}
TPM_RC Serialize_TPMU_HA(
const TPMU_HA& value,
TPMI_ALG_HASH selector,
std::string* buffer) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
if (selector == TPM_ALG_SHA384) {
if (arraysize(value.sha384) < SHA384_DIGEST_SIZE) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < SHA384_DIGEST_SIZE; ++i) {
result = Serialize_BYTE(value.sha384[i], buffer);
if (result) {
return result;
}
}
}
if (selector == TPM_ALG_SHA1) {
if (arraysize(value.sha1) < SHA1_DIGEST_SIZE) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < SHA1_DIGEST_SIZE; ++i) {
result = Serialize_BYTE(value.sha1[i], buffer);
if (result) {
return result;
}
}
}
if (selector == TPM_ALG_SM3_256) {
if (arraysize(value.sm3_256) < SM3_256_DIGEST_SIZE) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < SM3_256_DIGEST_SIZE; ++i) {
result = Serialize_BYTE(value.sm3_256[i], buffer);
if (result) {
return result;
}
}
}
if (selector == TPM_ALG_NULL) {
// Do nothing.
}
if (selector == TPM_ALG_SHA256) {
if (arraysize(value.sha256) < SHA256_DIGEST_SIZE) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < SHA256_DIGEST_SIZE; ++i) {
result = Serialize_BYTE(value.sha256[i], buffer);
if (result) {
return result;
}
}
}
if (selector == TPM_ALG_SHA512) {
if (arraysize(value.sha512) < SHA512_DIGEST_SIZE) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < SHA512_DIGEST_SIZE; ++i) {
result = Serialize_BYTE(value.sha512[i], buffer);
if (result) {
return result;
}
}
}
return result;
}
TPM_RC Parse_TPMU_HA(
std::string* buffer,
TPMI_ALG_HASH selector,
TPMU_HA* value,
std::string* value_bytes) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
if (selector == TPM_ALG_SHA384) {
if (arraysize(value->sha384) < SHA384_DIGEST_SIZE) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < SHA384_DIGEST_SIZE; ++i) {
result = Parse_BYTE(
buffer,
&value->sha384[i],
value_bytes);
if (result) {
return result;
}
}
}
if (selector == TPM_ALG_SHA1) {
if (arraysize(value->sha1) < SHA1_DIGEST_SIZE) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < SHA1_DIGEST_SIZE; ++i) {
result = Parse_BYTE(
buffer,
&value->sha1[i],
value_bytes);
if (result) {
return result;
}
}
}
if (selector == TPM_ALG_SM3_256) {
if (arraysize(value->sm3_256) < SM3_256_DIGEST_SIZE) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < SM3_256_DIGEST_SIZE; ++i) {
result = Parse_BYTE(
buffer,
&value->sm3_256[i],
value_bytes);
if (result) {
return result;
}
}
}
if (selector == TPM_ALG_NULL) {
// Do nothing.
}
if (selector == TPM_ALG_SHA256) {
if (arraysize(value->sha256) < SHA256_DIGEST_SIZE) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < SHA256_DIGEST_SIZE; ++i) {
result = Parse_BYTE(
buffer,
&value->sha256[i],
value_bytes);
if (result) {
return result;
}
}
}
if (selector == TPM_ALG_SHA512) {
if (arraysize(value->sha512) < SHA512_DIGEST_SIZE) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < SHA512_DIGEST_SIZE; ++i) {
result = Parse_BYTE(
buffer,
&value->sha512[i],
value_bytes);
if (result) {
return result;
}
}
}
return result;
}
TPM_RC Serialize_TPMT_HA(
const TPMT_HA& value,
std::string* buffer) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Serialize_TPMI_ALG_HASH(value.hash_alg, buffer);
if (result) {
return result;
}
result = Serialize_TPMU_HA(
value.digest,
value.hash_alg,
buffer);
if (result) {
return result;
}
return result;
}
TPM_RC Parse_TPMT_HA(
std::string* buffer,
TPMT_HA* value,
std::string* value_bytes) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Parse_TPMI_ALG_HASH(
buffer,
&value->hash_alg,
value_bytes);
if (result) {
return result;
}
result = Parse_TPMU_HA(
buffer,
value->hash_alg,
&value->digest,
value_bytes);
if (result) {
return result;
}
return result;
}
TPM_RC Serialize_TPM2B_DATA(
const TPM2B_DATA& value,
std::string* buffer) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Serialize_UINT16(value.size, buffer);
if (result) {
return result;
}
if (arraysize(value.buffer) < value.size) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < value.size; ++i) {
result = Serialize_BYTE(value.buffer[i], buffer);
if (result) {
return result;
}
}
return result;
}
TPM_RC Parse_TPM2B_DATA(
std::string* buffer,
TPM2B_DATA* value,
std::string* value_bytes) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Parse_UINT16(
buffer,
&value->size,
value_bytes);
if (result) {
return result;
}
if (arraysize(value->buffer) < value->size) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < value->size; ++i) {
result = Parse_BYTE(
buffer,
&value->buffer[i],
value_bytes);
if (result) {
return result;
}
}
return result;
}
TPM2B_DATA Make_TPM2B_DATA(
const std::string& bytes) {
TPM2B_DATA tpm2b;
CHECK(bytes.size() <= sizeof(tpm2b.buffer));
memset(&tpm2b, 0, sizeof(TPM2B_DATA));
tpm2b.size = bytes.size();
memcpy(tpm2b.buffer, bytes.data(), bytes.size());
return tpm2b;
}
std::string StringFrom_TPM2B_DATA(
const TPM2B_DATA& tpm2b) {
const char* char_buffer = reinterpret_cast<const char*>(
tpm2b.buffer);
return std::string(char_buffer, tpm2b.size);
}
TPM_RC Serialize_TPM2B_EVENT(
const TPM2B_EVENT& value,
std::string* buffer) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Serialize_UINT16(value.size, buffer);
if (result) {
return result;
}
if (arraysize(value.buffer) < value.size) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < value.size; ++i) {
result = Serialize_BYTE(value.buffer[i], buffer);
if (result) {
return result;
}
}
return result;
}
TPM_RC Parse_TPM2B_EVENT(
std::string* buffer,
TPM2B_EVENT* value,
std::string* value_bytes) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Parse_UINT16(
buffer,
&value->size,
value_bytes);
if (result) {
return result;
}
if (arraysize(value->buffer) < value->size) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < value->size; ++i) {
result = Parse_BYTE(
buffer,
&value->buffer[i],
value_bytes);
if (result) {
return result;
}
}
return result;
}
TPM2B_EVENT Make_TPM2B_EVENT(
const std::string& bytes) {
TPM2B_EVENT tpm2b;
CHECK(bytes.size() <= sizeof(tpm2b.buffer));
memset(&tpm2b, 0, sizeof(TPM2B_EVENT));
tpm2b.size = bytes.size();
memcpy(tpm2b.buffer, bytes.data(), bytes.size());
return tpm2b;
}
std::string StringFrom_TPM2B_EVENT(
const TPM2B_EVENT& tpm2b) {
const char* char_buffer = reinterpret_cast<const char*>(
tpm2b.buffer);
return std::string(char_buffer, tpm2b.size);
}
TPM_RC Serialize_TPM2B_MAX_BUFFER(
const TPM2B_MAX_BUFFER& value,
std::string* buffer) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Serialize_UINT16(value.size, buffer);
if (result) {
return result;
}
if (arraysize(value.buffer) < value.size) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < value.size; ++i) {
result = Serialize_BYTE(value.buffer[i], buffer);
if (result) {
return result;
}
}
return result;
}
TPM_RC Parse_TPM2B_MAX_BUFFER(
std::string* buffer,
TPM2B_MAX_BUFFER* value,
std::string* value_bytes) {
TPM_RC result = TPM_RC_SUCCESS;
VLOG(3) << __func__;
result = Parse_UINT16(
buffer,
&value->size,
value_bytes);
if (result) {
return result;
}
if (arraysize(value->buffer) < value->size) {
return TPM_RC_INSUFFICIENT;
}
for (uint32_t i = 0; i < value->size; ++i) {
result = Parse_BYTE(
buffer,
&value->buffer[i],
value_bytes);
if (result) {
return result;
}
}
return result;
}
TPM2B_MAX_BUFFER Make_TPM2B_MAX_BUFFER(