rev180: Add TPM2_PolicyCapability and dependencies

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2023-12-25 19:35:29 -05:00 committed by Stefan Berger
parent 269a409dad
commit 07962448cf
31 changed files with 761 additions and 2 deletions

View File

@ -462,6 +462,7 @@ noinst_HEADERS += \
tpm2/PolicyAuthorize_fp.h \
tpm2/PolicyAuthorizeNV_fp.h \
tpm2/PolicyAuthValue_fp.h \
tpm2/PolicyCapability_fp.h \
tpm2/PolicyCommandCode_fp.h \
tpm2/PolicyCounterTimer_fp.h \
tpm2/PolicyCpHash_fp.h \

View File

@ -304,5 +304,30 @@ ActGetCapabilityData(TPM_HANDLE actHandle, // IN: the handle for the starti
return NO;
}
#ifndef __ACT_DISABLED // libtpms: added
//*** ActGetOneCapability()
// This function returns an ACT's capability, if present.
BOOL ActGetOneCapability(TPM_HANDLE actHandle, // IN: the handle for the ACT
TPMS_ACT_DATA* actData // OUT: ACT data
)
{
UINT32 act = actHandle - TPM_RH_ACT_0;
if(ActIsImplemented(actHandle - TPM_RH_ACT_0))
{
memset(&actData->attributes, 0, sizeof(actData->attributes));
actData->handle = actHandle;
actData->timeout = _plat__ACT_GetRemaining(act);
if(_plat__ACT_GetSignaled(act))
SET_ATTRIBUTE(actData->attributes, TPMA_ACT, signaled);
else
CLEAR_ATTRIBUTE(actData->attributes, TPMA_ACT, signaled);
if(go.preservedSignaled & (1 << act))
SET_ATTRIBUTE(actData->attributes, TPMA_ACT, preserveSignaled);
return TRUE;
}
return FALSE;
}
#endif // libtpms: added
#endif // ACT_SUPPORT

View File

@ -103,5 +103,10 @@ ActGetCapabilityData(TPM_HANDLE actHandle, // IN: the handle for the starti
TPML_ACT_DATA* actList // OUT: ACT data list
);
//*** ActGetOneCapability()
// This function returns an ACT's capability, if present.
BOOL ActGetOneCapability(TPM_HANDLE actHandle, // IN: the handle for the ACT
TPMS_ACT_DATA* actData // OUT: ACT data
);
#endif // _ACT_SPT_FP_H_

View File

@ -221,6 +221,36 @@ AlgorithmCapGetImplemented(
}
return more;
}
//** AlgorithmCapGetOneImplemented()
// This function returns whether a single algorithm was implemented, along
// with its properties (if implemented).
BOOL AlgorithmCapGetOneImplemented(
TPM_ALG_ID algID, // IN: the algorithm ID
TPMS_ALG_PROPERTY* algProperty // OUT: algorithm properties
)
{
UINT32 i;
UINT32 algNum;
// Compute how many algorithms are defined in s_algorithms array.
algNum = sizeof(s_algorithms) / sizeof(s_algorithms[0]);
// Scan the implemented algorithm list to see if there is a match to 'algID'.
for(i = 0; i < algNum; i++)
{
// If algID is less than the starting algorithm ID, skip it
if(s_algorithms[i].algID == algID)
{
algProperty->alg = algID;
algProperty->algProperties = s_algorithms[i].attributes;
return TRUE;
}
}
return FALSE;
}
/* 9.1.4 AlgorithmGetImplementedVector()
This function returns the bit vector of the implemented algorithms.

View File

@ -67,6 +67,14 @@ AlgorithmCapGetImplemented(
UINT32 count, // IN: count of returned algorithms
TPML_ALG_PROPERTY *algList // OUT: algorithm list
);
//** AlgorithmCapGetOneImplemented()
// This function returns whether a single algorithm was implemented, along
// with its properties (if implemented).
BOOL AlgorithmCapGetOneImplemented(
TPM_ALG_ID algID, // IN: the algorithm ID
TPMS_ALG_PROPERTY* algProperty // OUT: algorithm properties
);
LIB_EXPORT
void
AlgorithmGetImplementedVector(

View File

@ -445,6 +445,9 @@ const TPMA_CC s_ccAttr [] = {
#if (PAD_LIST || CC_ECC_Decrypt)
TPMA_CC_INITIALIZER(0x019A, 0, 0, 0, 0, 1, 0, 0, 0),
#endif
#if (PAD_LIST || CC_PolicyCapability)
TPMA_CC_INITIALIZER(0x019B, 0, 0, 0, 0, 1, 0, 0, 0),
#endif
#if (PAD_LIST || CC_Vendor_TCG_Test)
TPMA_CC_INITIALIZER(0x0000, 0, 0, 0, 0, 0, 0, 1, 0),
#endif
@ -946,6 +949,10 @@ const COMMAND_ATTRIBUTES s_commandAttributes [] = {
(COMMAND_ATTRIBUTES)(CC_ECC_Decrypt * // 0x019A
(IS_IMPLEMENTED+DECRYPT_2+HANDLE_1_USER+ENCRYPT_2)),
#endif
#if (PAD_LIST || CC_PolicyCapability)
(COMMAND_ATTRIBUTES)(CC_PolicyCapability * // 0x019B
(IS_IMPLEMENTED+DECRYPT_2+ALLOW_TRIAL)),
#endif
#if (PAD_LIST || CC_Vendor_TCG_Test)
(COMMAND_ATTRIBUTES)(CC_Vendor_TCG_Test * // 0x0000
(IS_IMPLEMENTED+DECRYPT_2+ENCRYPT_2)),

View File

@ -249,6 +249,18 @@ CommandAuditCapGetCCList(TPM_CC commandCode, // IN: start command code
return more;
}
//*** CommandAuditCapGetOneCC()
// This function returns true if a command has its audit bit set.
BOOL CommandAuditCapGetOneCC(TPM_CC commandCode) // IN: command code
{
COMMAND_INDEX commandIndex = CommandCodeToCommandIndex(commandCode);
if(commandIndex != UNIMPLEMENTED_COMMAND_INDEX)
{
return CommandAuditIsRequired(commandIndex);
}
return FALSE;
}
//*** CommandAuditGetDigest
// This command is used to create a digest of the commands being audited. The
// commands are processed in ascending numeric order with a list of TPM_CC being

View File

@ -87,6 +87,8 @@ CommandAuditCapGetCCList(
UINT32 count, // IN: count of returned TPM_CC
TPML_CC *commandList // OUT: list of TPM_CC
);
BOOL CommandAuditCapGetOneCC(TPM_CC commandCode // IN: command code
);
void
CommandAuditGetDigest(
TPM2B_DIGEST *digest // OUT: command digest

View File

@ -540,6 +540,21 @@ CommandCapGetCCList(
}
return more;
}
//*** CommandCapGetOneCC()
// This function checks whether a command is implemented, and returns its
// attributes if so.
BOOL CommandCapGetOneCC(TPM_CC commandCode, // IN: command code
TPMA_CC* commandAttributes // OUT: command attributes
)
{
COMMAND_INDEX commandIndex = CommandCodeToCommandIndex(commandCode);
if(commandIndex != UNIMPLEMENTED_COMMAND_INDEX)
{
*commandAttributes = s_ccAttr[commandIndex];
return TRUE;
}
return FALSE;
}
#if 0 /* libtpms added */
/* 9.3.3.14 IsVendorCommand() */
/* Function indicates if a command index references a vendor command. */

View File

@ -113,6 +113,9 @@ CommandCapGetCCList(
// 'commandList'
TPML_CCA *commandList // OUT: list of TPMA_CC
);
BOOL CommandCapGetOneCC(TPM_CC commandCode, // IN: command code
TPMA_CC* commandAttributes // OUT: Command attributes
);
#if 0 /* libtpms added */
BOOL
IsVendorCommand(

View File

@ -2938,6 +2938,49 @@ PolicyAuthorizeNV_COMMAND_DESCRIPTOR_t _PolicyAuthorizeNVData = {
#else
#define _PolicyAuthorizeNVDataAddress 0
#endif
#if CC_PolicyCapability
#include "PolicyCapability_fp.h"
typedef TPM_RC (PolicyCapability_Entry)(
PolicyCapability_In* in
);
typedef const struct
{
PolicyCapability_Entry *entry;
UINT16 inSize;
UINT16 outSize;
UINT16 offsetOfTypes;
UINT16 paramOffsets[5];
BYTE types[8];
} PolicyCapability_COMMAND_DESCRIPTOR_t;
PolicyCapability_COMMAND_DESCRIPTOR_t _PolicyCapabilityData = {
/* entry */ &TPM2_PolicyCapability,
/* inSize */ (UINT16)(sizeof(PolicyCapability_In)),
/* outSize */ 0,
/* offsetOfTypes */ offsetof(PolicyCapability_COMMAND_DESCRIPTOR_t, types),
/* offsets */ {(UINT16)(offsetof(PolicyCapability_In, operandB)),
(UINT16)(offsetof(PolicyCapability_In, offset)),
(UINT16)(offsetof(PolicyCapability_In, operation)),
(UINT16)(offsetof(PolicyCapability_In, capability)),
(UINT16)(offsetof(PolicyCapability_In, property))},
/* types */ {TPMI_SH_POLICY_H_UNMARSHAL,
TPM2B_OPERAND_P_UNMARSHAL,
UINT16_P_UNMARSHAL,
TPM_EO_P_UNMARSHAL,
TPM_CAP_P_UNMARSHAL,
UINT32_P_UNMARSHAL,
END_OF_LIST,
END_OF_LIST}
};
#define _PolicyCapabilityDataAddress (&_PolicyCapabilityData)
#else
#define _PolicyCapabilityDataAddress 0
#endif // CC_PolicyCapability
#if CC_CreatePrimary
#include "CreatePrimary_fp.h"
typedef TPM_RC (CreatePrimary_Entry)(
@ -4613,6 +4656,9 @@ COMMAND_DESCRIPTOR_t *s_CommandDataArray[] = {
#if (PAD_LIST || CC_ECC_Decrypt)
(COMMAND_DESCRIPTOR_t *)_ECC_DecryptDataAddress,
#endif // CC_ECC_Decrypt
#if (PAD_LIST || CC_PolicyCapability)
(COMMAND_DESCRIPTOR_t*)_PolicyCapabilityDataAddress,
#endif // CC_PolicyCapability
#if (PAD_LIST || CC_Vendor_TCG_Test)
(COMMAND_DESCRIPTOR_t *)_Vendor_TCG_TestDataAddress,
#endif

View File

@ -1627,3 +1627,275 @@ TPM2_PolicyAuthorizeNV(PolicyAuthorizeNV_In* in)
}
#endif // CC_PolicyAuthorizeNV
#include "Tpm.h"
#include "PolicyCapability_fp.h"
#include "Policy_spt_fp.h"
#include "ACT_spt_fp.h"
#include "AlgorithmCap_fp.h"
#include "CommandAudit_fp.h"
#include "CommandCodeAttributes_fp.h"
#include "CryptEccMain_fp.h"
#include "Handle_fp.h"
#include "NVDynamic_fp.h"
#include "Object_fp.h"
#include "PCR_fp.h"
#include "PP_fp.h"
#include "PropertyCap_fp.h"
#include "Session_fp.h"
#if CC_PolicyCapability // Conditional expansion of this file
/*(See part 3 specification)
// This command performs an immediate policy assertion against the current
// value of a TPM Capability.
*/
// Return Type: TPM_RC
// TPM_RC_HANDLE value of 'property' is in an unsupported handle range
// for the TPM_CAP_HANDLES 'capability' value
// TPM_RC_VALUE invalid 'capability'; or 'property' is not 0 for the
// TPM_CAP_PCRS 'capability' value
// TPM_RC_SIZE 'operandB' is larger than the size of the capability
// data minus 'offset'.
TPM_RC
TPM2_PolicyCapability(PolicyCapability_In* in // IN: input parameter list
)
{
union
{
TPMS_ALG_PROPERTY alg;
TPM_HANDLE handle;
TPMA_CC commandAttributes;
TPM_CC command;
TPMS_TAGGED_PCR_SELECT pcrSelect;
TPMS_TAGGED_PROPERTY tpmProperty;
# if ALG_ECC
TPM_ECC_CURVE curve;
# endif // ALG_ECC
TPMS_TAGGED_POLICY policy;
# if ACT_SUPPORT
TPMS_ACT_DATA act;
# endif // ACT_SUPPORT
} propertyUnion;
SESSION* session;
BYTE propertyData[sizeof(propertyUnion)];
UINT16 propertySize = 0;
BYTE* buffer = propertyData;
INT32 bufferSize = sizeof(propertyData);
TPM_CC commandCode = TPM_CC_PolicyCapability;
HASH_STATE hashState;
TPM2B_DIGEST argHash;
// Get pointer to the session structure
session = SessionGet(in->policySession);
if(session->attributes.isTrialPolicy == CLEAR)
{
switch(in->capability)
{
case TPM_CAP_ALGS:
if(AlgorithmCapGetOneImplemented((TPM_ALG_ID)in->property,
&propertyUnion.alg))
{
propertySize = TPMS_ALG_PROPERTY_Marshal
(&propertyUnion.alg, &buffer, &bufferSize);
}
break;
case TPM_CAP_HANDLES:
BOOL foundHandle = FALSE;
switch(HandleGetType((TPM_HANDLE)in->property))
{
case TPM_HT_TRANSIENT:
foundHandle = ObjectCapGetOneLoaded((TPM_HANDLE)in->property);
break;
case TPM_HT_PERSISTENT:
foundHandle = NvCapGetOnePersistent((TPM_HANDLE)in->property);
break;
case TPM_HT_NV_INDEX:
foundHandle = NvCapGetOneIndex((TPM_HANDLE)in->property);
break;
case TPM_HT_LOADED_SESSION:
foundHandle =
SessionCapGetOneLoaded((TPM_HANDLE)in->property);
break;
case TPM_HT_SAVED_SESSION:
foundHandle = SessionCapGetOneSaved((TPM_HANDLE)in->property);
break;
case TPM_HT_PCR:
foundHandle = PCRCapGetOneHandle((TPM_HANDLE)in->property);
break;
case TPM_HT_PERMANENT:
foundHandle =
PermanentCapGetOneHandle((TPM_HANDLE)in->property);
break;
default:
// Unsupported input handle type
return TPM_RCS_HANDLE + RC_PolicyCapability_property;
break;
}
if(foundHandle)
{
TPM_HANDLE handle = (TPM_HANDLE)in->property;
propertySize = TPM_HANDLE_Marshal(&handle, &buffer, &bufferSize);
}
break;
case TPM_CAP_COMMANDS:
if(CommandCapGetOneCC((TPM_CC)in->property,
&propertyUnion.commandAttributes))
{
propertySize = TPMA_CC_Marshal
(&propertyUnion.commandAttributes, &buffer, &bufferSize);
}
break;
case TPM_CAP_PP_COMMANDS:
if(PhysicalPresenceCapGetOneCC((TPM_CC)in->property))
{
TPM_CC cc = (TPM_CC)in->property;
propertySize = TPM_CC_Marshal(&cc, &buffer, &bufferSize);
}
break;
case TPM_CAP_AUDIT_COMMANDS:
if(CommandAuditCapGetOneCC((TPM_CC)in->property))
{
TPM_CC cc = (TPM_CC)in->property;
propertySize = TPM_CC_Marshal(&cc, &buffer, &bufferSize);
}
break;
// NOTE: TPM_CAP_PCRS can't work for PolicyCapability since CAP_PCRS
// requires property to be 0 and always returns all the PCR banks.
case TPM_CAP_PCR_PROPERTIES:
if(PCRGetProperty((TPM_PT_PCR)in->property, &propertyUnion.pcrSelect))
{
propertySize = TPMS_TAGGED_PCR_SELECT_Marshal
(&propertyUnion.pcrSelect, &buffer, &bufferSize);
}
break;
case TPM_CAP_TPM_PROPERTIES:
if(TPMCapGetOneProperty((TPM_PT)in->property,
&propertyUnion.tpmProperty))
{
propertySize = TPMS_TAGGED_PROPERTY_Marshal
(&propertyUnion.tpmProperty, &buffer, &bufferSize);
}
break;
# if ALG_ECC
case TPM_CAP_ECC_CURVES:
TPM_ECC_CURVE curve = (TPM_ECC_CURVE)in->property;
if(CryptCapGetOneECCCurve(curve))
{
propertySize =
TPM_ECC_CURVE_Marshal(&curve, &buffer, &bufferSize);
}
break;
# endif // ALG_ECC
case TPM_CAP_AUTH_POLICIES:
if(HandleGetType((TPM_HANDLE)in->property) != TPM_HT_PERMANENT)
return TPM_RCS_VALUE + RC_PolicyCapability_property;
if(PermanentHandleGetOnePolicy((TPM_HANDLE)in->property,
&propertyUnion.policy))
{
propertySize = TPMS_TAGGED_POLICY_Marshal
(&propertyUnion.policy, &buffer, &bufferSize);
}
break;
# ifndef __ACT_DISABLED // libtpms: added
# if ACT_SUPPORT
case TPM_CAP_ACT:
if(((TPM_RH)in->property < TPM_RH_ACT_0)
|| ((TPM_RH)in->property > TPM_RH_ACT_F))
return TPM_RCS_VALUE + RC_PolicyCapability_property;
if(ActGetOneCapability((TPM_HANDLE)in->property, &propertyUnion.act))
{
propertySize = TPMS_ACT_DATA_Marshal
(&propertyUnion.act, &buffer, &bufferSize);
}
break;
# endif // ACT_SUPPORT
# endif // __ACT_DISABLED // libtpms: added
case TPM_CAP_VENDOR_PROPERTY:
// vendor property is not implemented
default:
// Unsupported TPM_CAP value
return TPM_RCS_VALUE + RC_PolicyCapability_capability;
break;
}
if(propertySize == 0)
{
// A property that doesn't exist trivially satisfies NEQ, and
// trivially can't satisfy any other operation.
if(in->operation != TPM_EO_NEQ)
{
return TPM_RC_POLICY;
}
}
else
{
// The property was found, so we need to perform the comparison.
// Make sure that offset is within range
if(in->offset > propertySize)
{
return TPM_RCS_VALUE + RC_PolicyCapability_offset;
}
// Property data size should not be smaller than input operandB size
if((propertySize - in->offset) < in->operandB.t.size)
{
return TPM_RCS_SIZE + RC_PolicyCapability_operandB;
}
if(!PolicySptCheckCondition(in->operation,
propertyData + in->offset,
in->operandB.t.buffer,
in->operandB.t.size))
{
return TPM_RC_POLICY;
}
}
}
// Internal Data Update
// Start argument hash
argHash.t.size = CryptHashStart(&hashState, session->authHashAlg);
// add operandB
CryptDigestUpdate2B(&hashState, &in->operandB.b);
// add offset
CryptDigestUpdateInt(&hashState, sizeof(UINT16), in->offset);
// add operation
CryptDigestUpdateInt(&hashState, sizeof(TPM_EO), in->operation);
// add capability
CryptDigestUpdateInt(&hashState, sizeof(TPM_CAP), in->capability);
// add property
CryptDigestUpdateInt(&hashState, sizeof(UINT32), in->property);
// complete argument digest
CryptHashEnd2B(&hashState, &argHash.b);
// Update policyDigest
// Start digest
CryptHashStart(&hashState, session->authHashAlg);
// add old digest
CryptDigestUpdate2B(&hashState, &session->u2.policyDigest.b);
// add commandCode
CryptDigestUpdateInt(&hashState, sizeof(TPM_CC), commandCode);
// add argument digest
CryptDigestUpdate2B(&hashState, &argHash.b);
// complete the digest
CryptHashEnd2B(&hashState, &session->u2.policyDigest.b);
return TPM_RC_SUCCESS;
}
#endif // CC_PolicyCapability

View File

@ -164,6 +164,26 @@ PermanentCapGetHandles(TPM_HANDLE handle, // IN: start handle
}
return more;
}
//*** PermanentCapGetOneHandle()
// This function returns whether a permanent handle exists.
BOOL PermanentCapGetOneHandle(TPM_HANDLE handle) // IN: handle
{
UINT32 i;
pAssert(HandleGetType(handle) == TPM_HT_PERMANENT);
// Iterate permanent handle range
for(i = NextPermanentHandle(handle); i != 0; i = NextPermanentHandle(i + 1))
{
if(i == handle)
{
return TRUE;
}
}
return FALSE;
}
//*** PermanentHandleGetPolicy()
// This function returns a list of the permanent handles of PCR, started from
// 'handle'. If 'handle' is larger than the largest permanent handle, an empty list
@ -219,3 +239,30 @@ PermanentHandleGetPolicy(TPM_HANDLE handle, // IN: start handle
}
return more;
}
//*** PermanentHandleGetOnePolicy()
// This function returns a permanent handle's policy, if present.
BOOL PermanentHandleGetOnePolicy(TPM_HANDLE handle, // IN: handle
TPMS_TAGGED_POLICY* policy // OUT: tagged policy
)
{
pAssert(HandleGetType(handle) == TPM_HT_PERMANENT);
if(NextPermanentHandle(handle) == handle)
{
TPM2B_DIGEST policyDigest;
TPM_ALG_ID policyAlg;
// Check to see if this permanent handle has a policy
policyAlg = EntityGetAuthPolicy(handle, &policyDigest);
if(policyAlg == TPM_ALG_ERROR)
{
return FALSE;
}
policy->handle = handle;
policy->policyHash.hashAlg = policyAlg;
MemoryCopy(
&policy->policyHash.digest, policyDigest.t.buffer, policyDigest.t.size);
return TRUE;
}
return FALSE;
}

View File

@ -75,12 +75,16 @@ PermanentCapGetHandles(
UINT32 count, // IN: count of returned handles
TPML_HANDLE *handleList // OUT: list of handle
);
BOOL PermanentCapGetOneHandle(TPM_HANDLE handle // IN: handle
);
TPMI_YES_NO
PermanentHandleGetPolicy(
TPM_HANDLE handle, // IN: start handle
UINT32 count, // IN: count of returned handles
TPML_TAGGED_POLICY *policyList // OUT: list of handle
);
BOOL PermanentHandleGetOnePolicy(TPM_HANDLE handle, // IN: handle
TPMS_TAGGED_POLICY* policy // OUT: tagged policy
);
#endif

View File

@ -1574,6 +1574,29 @@ NvCapGetPersistent(TPMI_DH_OBJECT handle, // IN: start handle
}
return more;
}
//*** NvCapGetOnePersistent()
// This function returns whether a given persistent handle exists.
//
// 'Handle' must be in valid persistent object handle range.
BOOL NvCapGetOnePersistent(TPMI_DH_OBJECT handle) // IN: handle
{
NV_REF iter = NV_REF_INIT;
NV_REF currentAddr;
TPM_HANDLE entityHandle;
pAssert(HandleGetType(handle) == TPM_HT_PERSISTENT);
while((currentAddr = NvNextEvict(&entityHandle, &iter)) != 0)
{
if(entityHandle == handle)
{
return TRUE;
}
}
return FALSE;
}
//*** NvCapGetIndex()
// This function returns a list of handles of NV indexes, starting from 'handle'.
// 'Handle' must be in the range of NV indexes, but does not have to reference
@ -1621,6 +1644,26 @@ NvCapGetIndex(TPMI_DH_OBJECT handle, // IN: start handle
return more;
}
//*** NvCapGetOneIndex()
// This function whether an NV index exists.
BOOL NvCapGetOneIndex(TPMI_DH_OBJECT handle) // IN: handle
{
NV_REF iter = NV_REF_INIT;
NV_REF currentAddr;
TPM_HANDLE nvHandle;
pAssert(HandleGetType(handle) == TPM_HT_NV_INDEX);
while((currentAddr = NvNextIndex(&nvHandle, &iter)) != 0)
{
if(nvHandle == handle)
{
return TRUE;
}
}
return FALSE;
}
//*** NvCapGetIndexNumber()
// This function returns the count of NV Indexes currently defined.
UINT32

View File

@ -193,12 +193,20 @@ NvCapGetPersistent(
UINT32 count, // IN: maximum number of returned handles
TPML_HANDLE *handleList // OUT: list of handle
);
//*** NvCapGetOnePersistent()
// This function returns whether a given persistent handle exists.
//
// 'Handle' must be in valid persistent object handle range.
BOOL NvCapGetOnePersistent(TPMI_DH_OBJECT handle // IN: handle
);
TPMI_YES_NO
NvCapGetIndex(
TPMI_DH_OBJECT handle, // IN: start handle
UINT32 count, // IN: max number of returned handles
TPML_HANDLE *handleList // OUT: list of handle
);
BOOL NvCapGetOneIndex(TPMI_DH_OBJECT handle); // IN: start handle
UINT32
NvCapGetIndexNumber(
void

View File

@ -976,6 +976,30 @@ ObjectCapGetLoaded(TPMI_DH_OBJECT handle, // IN: start handle
return more;
}
//*** ObjectCapGetOneLoaded()
// This function returns whether a handle is loaded.
BOOL ObjectCapGetOneLoaded(TPMI_DH_OBJECT handle) // IN: handle
{
UINT32 i;
pAssert(HandleGetType(handle) == TPM_HT_TRANSIENT);
// Iterate object slots to get loaded object handles
for(i = handle - TRANSIENT_FIRST; i < MAX_LOADED_OBJECTS; i++)
{
if(s_objects[i].attributes.occupied == TRUE)
{
// A valid transient object can not be the copy of a persistent object
pAssert(s_objects[i].attributes.evict == CLEAR);
return TRUE;
}
}
return FALSE;
}
//*** ObjectCapGetTransientAvail()
// This function returns an estimate of the number of additional transient
// objects that could be loaded into the TPM.

View File

@ -316,6 +316,14 @@ ObjectCapGetLoaded(TPMI_DH_OBJECT handle, // IN: start handle
TPML_HANDLE* handleList // OUT: list of handle
);
//*** ObjectCapGetOneLoaded()
// This function returns whether a handle is loaded.
BOOL ObjectCapGetOneLoaded(TPMI_DH_OBJECT handle // IN: handle
);
//*** ObjectCapGetTransientAvail()
// This function returns an estimate of the number of additional transient
// objects that could be loaded into the TPM.
UINT32
ObjectCapGetTransientAvail(void);

View File

@ -1338,3 +1338,16 @@ PCRCapGetHandles(TPMI_DH_PCR handle, // IN: start handle
}
return more;
}
//*** PCRCapGetOneHandle()
// This function is used to check whether a PCR handle exists.
BOOL PCRCapGetOneHandle(TPMI_DH_PCR handle) // IN: handle
{
pAssert(HandleGetType(handle) == TPM_HT_PCR);
if((handle & HR_HANDLE_MASK) <= PCR_LAST)
{
return TRUE;
}
return FALSE;
}

View File

@ -297,5 +297,9 @@ PCRCapGetHandles(TPMI_DH_PCR handle, // IN: start handle
TPML_HANDLE* handleList // OUT: list of handle
);
//*** PCRCapGetOneHandle()
// This function is used to check whether a PCR handle exists.
BOOL PCRCapGetOneHandle(TPMI_DH_PCR handle // IN: handle
);
#endif // _PCR_FP_H_

View File

@ -179,3 +179,15 @@ PhysicalPresenceCapGetCCList(
}
return more;
}
//*** PhysicalPresenceCapGetOneCC()
// This function returns true if the command requires Physical Presence.
BOOL PhysicalPresenceCapGetOneCC(TPM_CC commandCode) // IN: command code
{
COMMAND_INDEX commandIndex = CommandCodeToCommandIndex(commandCode);
if(commandIndex != UNIMPLEMENTED_COMMAND_INDEX)
{
return PhysicalPresenceIsRequired(commandIndex);
}
return FALSE;
}

View File

@ -83,6 +83,8 @@ PhysicalPresenceCapGetCCList(
UINT32 count, // IN: count of returned TPM_CC
TPML_CC *commandList // OUT: list of TPM_CC
);
BOOL PhysicalPresenceCapGetOneCC(TPM_CC commandCode // IN: command code
);
#endif

View File

@ -0,0 +1,87 @@
/********************************************************************************/
/* */
/* */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* */
/* Licenses and Notices */
/* */
/* 1. Copyright Licenses: */
/* */
/* - Trusted Computing Group (TCG) grants to the user of the source code in */
/* this specification (the "Source Code") a worldwide, irrevocable, */
/* nonexclusive, royalty free, copyright license to reproduce, create */
/* derivative works, distribute, display and perform the Source Code and */
/* derivative works thereof, and to grant others the rights granted herein. */
/* */
/* - The TCG grants to the user of the other parts of the specification */
/* (other than the Source Code) the rights to reproduce, distribute, */
/* display, and perform the specification solely for the purpose of */
/* developing products based on such documents. */
/* */
/* 2. Source Code Distribution Conditions: */
/* */
/* - Redistributions of Source Code must retain the above copyright licenses, */
/* this list of conditions and the following disclaimers. */
/* */
/* - Redistributions in binary form must reproduce the above copyright */
/* licenses, this list of conditions and the following disclaimers in the */
/* documentation and/or other materials provided with the distribution. */
/* */
/* 3. Disclaimers: */
/* */
/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */
/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */
/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */
/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */
/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */
/* information on specification licensing rights available through TCG */
/* membership agreements. */
/* */
/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */
/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */
/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */
/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */
/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */
/* */
/* - Without limitation, TCG and its members and licensors disclaim all */
/* liability, including liability for infringement of any proprietary */
/* rights, relating to use of information in this specification and to the */
/* implementation of this specification, and TCG disclaims all liability for */
/* cost of procurement of substitute goods or services, lost profits, loss */
/* of use, loss of data or any incidental, consequential, direct, indirect, */
/* or special damages, whether under contract, tort, warranty or otherwise, */
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2023 */
/* */
/********************************************************************************/
#if CC_PolicyCapability // Command must be enabled
#ifndef POLICYCAPABILITY_FP_H
#define POLICYCAPABILITY_FP_H
typedef struct
{
TPMI_SH_POLICY policySession;
TPM2B_OPERAND operandB;
UINT16 offset;
TPM_EO operation;
TPM_CAP capability;
UINT32 property;
} PolicyCapability_In;
#define RC_PolicyCapability_policySession (TPM_RC_H + TPM_RC_1)
#define RC_PolicyCapability_operandB (TPM_RC_P + TPM_RC_1)
#define RC_PolicyCapability_offset (TPM_RC_P + TPM_RC_2)
#define RC_PolicyCapability_operation (TPM_RC_P + TPM_RC_3)
#define RC_PolicyCapability_capability (TPM_RC_P + TPM_RC_4)
#define RC_PolicyCapability_property (TPM_RC_P + TPM_RC_5)
TPM_RC
TPM2_PolicyCapability(PolicyCapability_In* in);
#endif // POLICYCAPABILITY_FP_H
#endif // CC_PolicyCapability

View File

@ -593,3 +593,21 @@ TPMCapGetProperties(
}
return more;
}
//*** TPMCapGetOneProperty()
// This function returns a single TPM property, if present.
BOOL TPMCapGetOneProperty(TPM_PT pt, // IN: the TPM property
TPMS_TAGGED_PROPERTY* property // OUT: tagged property
)
{
UINT32 value;
if(TPMPropertyIsDefined((TPM_PT)pt, &value))
{
property->property = (TPM_PT)pt;
property->value = value;
return TRUE;
}
return FALSE;
}

View File

@ -68,6 +68,9 @@ TPMCapGetProperties(
// properties
TPML_TAGGED_TPM_PROPERTY *propertyList // OUT: property list
);
BOOL TPMCapGetOneProperty(TPM_PT pt, // IN: the TPM property
TPMS_TAGGED_PROPERTY* property // OUT: tagged property
);
#endif

View File

@ -941,6 +941,21 @@ SessionCapGetLoaded(TPMI_SH_POLICY handle, // IN: start handle
return more;
}
//*** SessionCapGetOneLoaded()
// This function returns whether a session handle exists and is loaded.
BOOL SessionCapGetOneLoaded(TPMI_SH_POLICY handle) // IN: handle
{
pAssert(HandleGetType(handle) == TPM_HT_LOADED_SESSION);
if((handle & HR_HANDLE_MASK) < MAX_ACTIVE_SESSIONS
&& gr.contextArray[(handle & HR_HANDLE_MASK)])
{
return TRUE;
}
return FALSE;
}
//*** SessionCapGetSaved()
// This function returns a list of handles for saved session, starting at
// 'handle'.
@ -999,6 +1014,21 @@ SessionCapGetSaved(TPMI_SH_HMAC handle, // IN: start handle
return more;
}
//*** SessionCapGetOneSaved()
// This function returns whether a session handle exists and is saved.
BOOL SessionCapGetOneSaved(TPMI_SH_HMAC handle) // IN: handle
{
pAssert(HandleGetType(handle) == TPM_HT_SAVED_SESSION);
if((handle & HR_HANDLE_MASK) < MAX_ACTIVE_SESSIONS
&& gr.contextArray[(handle & HR_HANDLE_MASK)])
{
return TRUE;
}
return FALSE;
}
//*** SessionCapGetLoadedNumber()
// This function return the number of authorization sessions currently
// loaded into TPM RAM.

View File

@ -130,12 +130,17 @@ SessionCapGetLoaded(
UINT32 count, // IN: count of returned handles
TPML_HANDLE *handleList // OUT: list of handle
);
BOOL SessionCapGetOneLoaded(TPMI_SH_POLICY handle // IN: handle
);
TPMI_YES_NO
SessionCapGetSaved(
TPMI_SH_HMAC handle, // IN: start handle
UINT32 count, // IN: count of returned handles
TPML_HANDLE *handleList // OUT: list of handle
);
BOOL SessionCapGetOneSaved(TPMI_SH_HMAC handle // IN: handle
);
UINT32
SessionCapGetLoadedNumber(
void

View File

@ -344,6 +344,7 @@
+ (ADD_FILL || CC_ACT_SetTimeout) /* 0x00000198 */ \
+ (ADD_FILL || CC_ECC_Encrypt) /* 0x00000199 */ \
+ (ADD_FILL || CC_ECC_Decrypt) /* 0x0000019A */ \
+ (ADD_FILL || CC_PolicyCapability) /* 0x0000019B */ \
)
#define VENDOR_COMMAND_ARRAY_SIZE (0 + CC_Vendor_TCG_Test)

View File

@ -302,7 +302,8 @@ typedef UINT32 TPM_CC;
#define TPM_CC_ACT_SetTimeout (TPM_CC)(0x00000198)
#define TPM_CC_ECC_Encrypt (TPM_CC)(0x00000199)
#define TPM_CC_ECC_Decrypt (TPM_CC)(0x0000019A)
#define TPM_CC_LAST (TPM_CC)(0x0000019A)
#define TPM_CC_PolicyCapability (TPM_CC)(0x0000019B)
#define TPM_CC_LAST (TPM_CC)(0x0000019B)
#define CC_VEND 0x20000000
#define TPM_CC_Vendor_TCG_Test (TPM_CC)(0x20000000)

View File

@ -123,6 +123,11 @@ CryptCapGetECCCurve(TPM_ECC_CURVE curveID, // IN: the starting ECC curve
TPML_ECC_CURVE* curveList // OUT: ECC curve list
);
//*** CryptCapGetOneECCCurve()
// This function returns whether the ECC curve is implemented.
BOOL CryptCapGetOneECCCurve(TPM_ECC_CURVE curveID // IN: the ECC curve
);
//*** CryptGetCurveSignScheme()
// This function will return a pointer to the scheme of the curve.
const TPMT_ECC_SCHEME* CryptGetCurveSignScheme(

View File

@ -203,6 +203,24 @@ CryptCapGetECCCurve(TPM_ECC_CURVE curveID, // IN: the starting ECC curve
return more;
}
//*** CryptCapGetOneECCCurve()
// This function returns whether the ECC curve is implemented.
BOOL CryptCapGetOneECCCurve(TPM_ECC_CURVE curveID // IN: the ECC curve
)
{
UINT16 i;
// Scan the eccCurveValues array
for(i = 0; i < ECC_CURVE_COUNT; i++)
{
if(CryptEccGetCurveByIndex(i) == curveID)
{
return TRUE;
}
}
return FALSE;
}
//*** CryptGetCurveSignScheme()
// This function will return a pointer to the scheme of the curve.
const TPMT_ECC_SCHEME* CryptGetCurveSignScheme(