mirror of
https://github.com/stefanberger/libtpms
synced 2026-01-09 05:50:48 +00:00
rev180: Define MUST_BE and replace cAssert with it
Introduce MUST_BE #define and replace cAssert with it. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
fd2e55e3a5
commit
2c63bf6c81
@ -99,8 +99,16 @@
|
||||
#ifdef _POSIX_
|
||||
typedef int SOCKET;
|
||||
#endif
|
||||
// #ifdef TPM_POSIX
|
||||
// typedef int SOCKET;
|
||||
// #endif
|
||||
|
||||
#if !defined(TPM_STATIC_ASSERT) || !defined(COMPILER_CHECKS)
|
||||
# error Expect definitions of COMPILER_CHECKS and TPM_STATIC_ASSERT
|
||||
#elif COMPILER_CHECKS
|
||||
// pre static_assert static_assert
|
||||
# define MUST_BE(e) TPM_STATIC_ASSERT(e)
|
||||
|
||||
#else
|
||||
// intentionally disabled, fine.
|
||||
# define MUST_BE(e)
|
||||
#endif
|
||||
|
||||
#endif // _COMPILER_DEPENDENCIES_H_
|
||||
|
||||
@ -109,12 +109,12 @@ ComputeContextProtectionKey(TPMS_CONTEXT* contextBlob, // IN: context blob
|
||||
|
||||
// Get sequence value in 2B format
|
||||
sequence2B.t.size = sizeof(contextBlob->sequence);
|
||||
cAssert(sequence2B.t.size <= sizeof(sequence2B.t.buffer));
|
||||
MUST_BE(sizeof(contextBlob->sequence) <= sizeof(sequence2B.t.buffer));
|
||||
MemoryCopy(sequence2B.t.buffer, &contextBlob->sequence, sequence2B.t.size);
|
||||
|
||||
// Get handle value in 2B format
|
||||
handle2B.t.size = sizeof(contextBlob->savedHandle);
|
||||
cAssert(handle2B.t.size <= sizeof(handle2B.t.buffer));
|
||||
MUST_BE(sizeof(contextBlob->savedHandle) <= sizeof(handle2B.t.buffer));
|
||||
MemoryCopy(handle2B.t.buffer, &contextBlob->savedHandle, handle2B.t.size);
|
||||
|
||||
// Get the symmetric encryption key size
|
||||
|
||||
@ -135,20 +135,6 @@
|
||||
#define RSA_MAX_PRIME (MAX_RSA_KEY_BYTES / 2)
|
||||
#define RSA_PRIVATE_SIZE (RSA_MAX_PRIME * 5)
|
||||
|
||||
/* 5.10.5 Compile-time Checks */
|
||||
/* In some cases, the relationship between two values may be dependent on things that change based
|
||||
on various selections like the chosen cryptographic libraries. It is possible that these
|
||||
selections will result in incompatible settings. These are often detectable by the compiler but
|
||||
it isn't always possible to do the check in the preprocessor code. For example, when the check
|
||||
requires use of sizeof then the preprocessor can't do the comparison. For these cases, we include
|
||||
a special macro that, depending on the compiler will generate a warning to indicate if the check
|
||||
always passes or always fails because it involves fixed constants. To run these checks, define
|
||||
COMPILER_CHECKS in TpmBuildSwitches.h */
|
||||
#if COMPILER_CHECKS
|
||||
# define cAssert pAssert
|
||||
#else
|
||||
# define cAssert(value)
|
||||
#endif
|
||||
/* This is used commonly in the Crypt code as a way to keep listings from getting too long. This is
|
||||
not to save paper but to allow one to see more useful stuff on the screen at any given time. */
|
||||
#define ERROR_RETURN(returnCode) \
|
||||
|
||||
@ -270,7 +270,7 @@ NvWriteNvListEnd(NV_REF end)
|
||||
UINT64 maxCount = NvReadMaxCount();
|
||||
//
|
||||
// This is a constant check that can be resolved at compile time.
|
||||
cAssert(sizeof(UINT64) <= sizeof(NV_LIST_TERMINATOR) - sizeof(UINT32));
|
||||
MUST_BE(sizeof(UINT64) <= sizeof(NV_LIST_TERMINATOR) - sizeof(UINT32));
|
||||
|
||||
// Copy the maxCount value to the marker buffer
|
||||
MemoryCopy(&listEndMarker[sizeof(UINT32)], &maxCount, sizeof(UINT64));
|
||||
|
||||
@ -497,7 +497,7 @@ static HASH_OBJECT* AllocateSequenceSlot(
|
||||
// Validate that the proper location of the hash state data relative to the
|
||||
// object state data. It would be good if this could have been done at compile
|
||||
// time but it can't so do it in something that can be removed after debug.
|
||||
cAssert(offsetof(HASH_OBJECT, auth) == offsetof(OBJECT, publicArea.authPolicy));
|
||||
MUST_BE(offsetof(HASH_OBJECT, auth) == offsetof(OBJECT, publicArea.authPolicy));
|
||||
|
||||
if(object != NULL)
|
||||
{
|
||||
|
||||
@ -1179,7 +1179,8 @@ PCRCapGetProperties(TPM_PT_PCR property, // IN: the starting PCR property
|
||||
|
||||
// TPM_PT_PCR_FIRST is defined as 0 in spec. It ensures that property
|
||||
// value would never be less than TPM_PT_PCR_FIRST
|
||||
cAssert(TPM_PT_PCR_FIRST == 0);
|
||||
MUST_BE(TPM_PT_PCR_FIRST == 0);
|
||||
|
||||
// Iterate PCR properties. TPM_PT_PCR_LAST is the index of the last property
|
||||
// implemented on the TPM.
|
||||
for(i = property; i <= TPM_PT_PCR_LAST; i++)
|
||||
|
||||
@ -90,7 +90,6 @@
|
||||
# undef DEBUG
|
||||
# define DEBUG YES // Default: Either YES or NO
|
||||
#endif
|
||||
#include "CompilerDependencies.h"
|
||||
|
||||
// This definition is required for the re-factored code
|
||||
#if (!defined USE_BN_ECC_DATA) || ((USE_BN_ECC_DATA != NO) && (USE_BN_ECC_DATA != YES))
|
||||
@ -352,4 +351,7 @@
|
||||
#define CC_YES YES
|
||||
#define CC_NO NO
|
||||
|
||||
// TODO_RENAME_INC_FOLDER: public refers to the TPM_CoreLib public headers
|
||||
#include "CompilerDependencies.h"
|
||||
|
||||
#endif // _TPM_BUILD_SWITCHES_H_
|
||||
|
||||
@ -249,7 +249,7 @@ void CryptHashExportState(
|
||||
{
|
||||
BYTE* outBuf = (BYTE*)externalFmt;
|
||||
//
|
||||
cAssert(sizeof(HASH_STATE) <= sizeof(EXPORT_HASH_STATE));
|
||||
MUST_BE(sizeof(HASH_STATE) <= sizeof(EXPORT_HASH_STATE));
|
||||
// the following #define is used to move data from an aligned internal data
|
||||
// structure to a byte buffer (external format data.
|
||||
#define CopyToOffset(value) \
|
||||
|
||||
Loading…
Reference in New Issue
Block a user