summaryrefslogtreecommitdiffstats
path: root/src/usr/secureboot/trusted/trustedTypes.C
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr/secureboot/trusted/trustedTypes.C')
-rw-r--r--src/usr/secureboot/trusted/trustedTypes.C149
1 files changed, 91 insertions, 58 deletions
diff --git a/src/usr/secureboot/trusted/trustedTypes.C b/src/usr/secureboot/trusted/trustedTypes.C
index 404a56860..4467b4c54 100644
--- a/src/usr/secureboot/trusted/trustedTypes.C
+++ b/src/usr/secureboot/trusted/trustedTypes.C
@@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
-/* Contributors Listed Below - COPYRIGHT 2015 */
+/* Contributors Listed Below - COPYRIGHT 2015,2016 */
/* [+] International Business Machines Corp. */
/* */
/* */
@@ -28,26 +28,32 @@
* @brief Trusted boot type inline functions
*/
+/////////////////////////////////////////////////////////////////
+// NOTE: This file is exportable as TSS-Lite for skiboot/PHYP //
+/////////////////////////////////////////////////////////////////
+
// ----------------------------------------------
// Includes
// ----------------------------------------------
#include <string.h>
-#include <sys/time.h>
-#include <trace/interface.H>
-#include <errl/errlentry.H>
-#include <errl/errlmanager.H>
-#include <errl/errludtarget.H>
-#include <errl/errludstring.H>
+#include "trustedboot.H"
#include "trustedTypes.H"
-extern trace_desc_t* g_trac_trustedboot;
-
-// Easy macro replace for unit testing
-//#define TRACUCOMP(args...) TRACFCOMP(args)
-#define TRACUCOMP(args...)
-
+#ifdef __cplusplus
namespace TRUSTEDBOOT
{
+#endif
+
+ uint8_t* unmarshalChunk(uint8_t* i_tpmBuf,
+ size_t * io_tpmBufSize,
+ void* o_chunkPtr,
+ size_t i_chunkSize);
+
+ uint8_t* marshalChunk(uint8_t* o_tpmBuf,
+ size_t i_tpmBufSize,
+ size_t * io_cmdSize,
+ void* i_chunkPtr,
+ size_t i_chunkSize);
uint32_t getDigestSize(TPM_Alg_Id i_algId)
{
@@ -68,71 +74,73 @@ namespace TRUSTEDBOOT
}
uint8_t* unmarshalChunk(uint8_t* i_tpmBuf,
- size_t & io_tpmBufSize,
+ size_t * io_tpmBufSize,
void* o_chunkPtr,
size_t i_chunkSize)
{
if (NULL != i_tpmBuf)
{
- if (i_chunkSize > io_tpmBufSize)
+ if (i_chunkSize > *io_tpmBufSize)
{
return NULL;
}
memcpy(o_chunkPtr, i_tpmBuf, i_chunkSize);
i_tpmBuf += i_chunkSize;
- io_tpmBufSize -= i_chunkSize;
+ *io_tpmBufSize -= i_chunkSize;
}
return i_tpmBuf;
}
uint8_t* marshalChunk(uint8_t* o_tpmBuf,
size_t i_tpmBufSize,
- size_t & io_cmdSize,
+ size_t * io_cmdSize,
void* i_chunkPtr,
size_t i_chunkSize)
{
if (NULL != o_tpmBuf)
{
- if ((io_cmdSize + i_chunkSize) > i_tpmBufSize)
+ if ((*io_cmdSize + i_chunkSize) > i_tpmBufSize)
{
return NULL;
}
memcpy(o_tpmBuf, i_chunkPtr, i_chunkSize);
o_tpmBuf += i_chunkSize;
- io_cmdSize += i_chunkSize;
+ *io_cmdSize += i_chunkSize;
}
return o_tpmBuf;
}
- uint8_t* TPML_TAGGED_TPM_PROPERTY::unmarshal(uint8_t* i_tpmBuf,
- size_t & io_tpmBufSize,
- size_t i_outBufSize)
+ uint8_t* TPML_TAGGED_TPM_PROPERTY_unmarshal(TPML_TAGGED_TPM_PROPERTY* val,
+ uint8_t* i_tpmBuf,
+ size_t* io_tpmBufSize)
{
i_tpmBuf = unmarshalChunk(i_tpmBuf, io_tpmBufSize,
- &count, sizeof(count));
+ &(val->count), sizeof(val->count));
// Now we know the count as well
i_tpmBuf = unmarshalChunk(i_tpmBuf, io_tpmBufSize,
- &(tpmProperty[0]),
- sizeof(TPMS_TAGGED_PROPERTY) * count);
+ &(val->tpmProperty[0]),
+ sizeof(TPMS_TAGGED_PROPERTY) * val->count);
return i_tpmBuf;
}
- uint8_t* TPMS_CAPABILITY_DATA::unmarshal(uint8_t* i_tpmBuf,
- size_t & io_tpmBufSize,
- size_t i_outBufSize)
+ uint8_t* TPMS_CAPABILITY_DATA_unmarshal(TPMS_CAPABILITY_DATA* val,
+ uint8_t* i_tpmBuf,
+ size_t * io_tpmBufSize)
{
i_tpmBuf = unmarshalChunk(i_tpmBuf, io_tpmBufSize,
- &capability, sizeof(capability));
+ &(val->capability),
+ sizeof(val->capability));
- switch (capability)
+ switch (val->capability)
{
- case TRUSTEDBOOT::TPM_CAP_TPM_PROPERTIES:
+ case TPM_CAP_TPM_PROPERTIES:
{
- return data.tpmProperties.unmarshal(i_tpmBuf, io_tpmBufSize,
- i_outBufSize);
+ return TPML_TAGGED_TPM_PROPERTY_unmarshal(
+ &(val->data.tpmProperties), i_tpmBuf,
+ io_tpmBufSize);
}
break;
default:
@@ -146,61 +154,83 @@ namespace TRUSTEDBOOT
return NULL;
}
- size_t TPML_DIGEST_VALUES::marshalSize() const
+ size_t TCG_PCR_EVENT_marshalSize(TCG_PCR_EVENT* val)
{
- size_t ret = sizeof(count);
- for (size_t idx = 0; (idx < count && idx < HASH_COUNT); idx++)
+ return (sizeof(TCG_PCR_EVENT) + val->eventSize - MAX_TPM_LOG_MSG);
+ }
+
+ size_t TPMT_HA_marshalSize(TPMT_HA* val)
+ {
+ return (sizeof(TPMT_HA) - sizeof(TPMU_HA) +
+ getDigestSize((TPM_Alg_Id)(val->algorithmId)));
+ }
+
+ size_t TPML_DIGEST_VALUES_marshalSize(TPML_DIGEST_VALUES* val)
+ {
+ size_t ret = sizeof(val->count);
+ for (size_t idx = 0; (idx < val->count && idx < HASH_COUNT); idx++)
{
- ret += digests[idx].marshalSize();
+ ret += TPMT_HA_marshalSize(&(val->digests[idx]));
}
return ret;
}
- uint8_t* TPM2_BaseIn::marshal(uint8_t* o_tpmBuf, size_t i_tpmBufSize,
- size_t & io_cmdSize)
+ size_t TPM_EVENT_FIELD_marshalSize(TPM_EVENT_FIELD* val)
+ {
+ return (sizeof(val->eventSize) + val->eventSize);
+ }
+
+ uint8_t* TPM2_BaseIn_marshal(TPM2_BaseIn* val, uint8_t* o_tpmBuf,
+ size_t i_tpmBufSize, size_t* io_cmdSize)
{
return marshalChunk(o_tpmBuf, i_tpmBufSize, io_cmdSize,
- this, sizeof(TPM2_BaseIn));
+ val, sizeof(TPM2_BaseIn));
}
- uint8_t* TPM2_BaseOut::unmarshal(uint8_t* i_tpmBuf, size_t & io_tpmBufSize,
- size_t i_outBufSize)
+ uint8_t* TPM2_BaseOut_unmarshal(TPM2_BaseOut* val, uint8_t* i_tpmBuf,
+ size_t* io_tpmBufSize, size_t i_outBufSize)
{
if (sizeof(TPM2_BaseOut) > i_outBufSize)
{
return NULL;
}
return unmarshalChunk(i_tpmBuf, io_tpmBufSize,
- this, sizeof(TPM2_BaseOut));
+ val, sizeof(TPM2_BaseOut));
}
- uint8_t* TPM2_2ByteIn::marshal(uint8_t* o_tpmBuf,
- size_t i_tpmBufSize,
- size_t & io_cmdSize)
+ uint8_t* TPM2_2ByteIn_marshal(TPM2_2ByteIn* val,
+ uint8_t* o_tpmBuf,
+ size_t i_tpmBufSize,
+ size_t* io_cmdSize)
{
// Base has already been marshaled
return marshalChunk(o_tpmBuf, i_tpmBufSize, io_cmdSize,
- &param, sizeof(param));
+ &(val->param), sizeof(val->param));
}
- uint8_t* TPM2_GetCapabilityIn::marshal(uint8_t* o_tpmBuf,
- size_t i_tpmBufSize,
- size_t& io_cmdSize)
+ uint8_t* TPM2_GetCapabilityIn_marshal(TPM2_GetCapabilityIn* val,
+ uint8_t* o_tpmBuf,
+ size_t i_tpmBufSize,
+ size_t* io_cmdSize)
{
// Base has already been marshaled
o_tpmBuf = marshalChunk(o_tpmBuf, i_tpmBufSize, io_cmdSize,
- &capability, sizeof(capability));
+ &(val->capability),
+ sizeof(val->capability));
o_tpmBuf = marshalChunk(o_tpmBuf, i_tpmBufSize, io_cmdSize,
- &property, sizeof(property));
+ &(val->property),
+ sizeof(val->property));
o_tpmBuf = marshalChunk(o_tpmBuf, i_tpmBufSize, io_cmdSize,
- &propertyCount, sizeof(propertyCount));
+ &(val->propertyCount),
+ sizeof(val->propertyCount));
return o_tpmBuf;
}
- uint8_t* TPM2_GetCapabilityOut::unmarshal(uint8_t* i_tpmBuf,
- size_t & io_tpmBufSize,
- size_t i_outBufSize)
+ uint8_t* TPM2_GetCapabilityOut_unmarshal(TPM2_GetCapabilityOut* val,
+ uint8_t* i_tpmBuf,
+ size_t* io_tpmBufSize,
+ size_t i_outBufSize)
{
// Base has already been unmarshaled
if (sizeof(TPM2_GetCapabilityOut) > i_outBufSize)
@@ -208,12 +238,15 @@ namespace TRUSTEDBOOT
return NULL;
}
i_tpmBuf = unmarshalChunk(i_tpmBuf, io_tpmBufSize,
- &moreData, sizeof(moreData));
+ &(val->moreData), sizeof(val->moreData));
// Capability data block
- return capData.unmarshal(i_tpmBuf, io_tpmBufSize, i_outBufSize);
+ return TPMS_CAPABILITY_DATA_unmarshal(&(val->capData), i_tpmBuf,
+ io_tpmBufSize);
}
+#ifdef __cplusplus
} // end TRUSTEDBOOT
+#endif
OpenPOWER on IntegriCloud