rev180: Add FAIL_RC & FAIL_NULL & FAIL_IMMEDIATE and use them

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2023-12-13 20:50:27 -05:00 committed by Stefan Berger
parent 3eee74f6d3
commit be2bb5b00d
4 changed files with 24 additions and 11 deletions

View File

@ -1008,8 +1008,7 @@ CryptParameterDecryption(
// Parameter encryption for a non-2B is not supported.
if(leadingSizeInByte != 2)
{
FAIL(FATAL_ERROR_INTERNAL);
return TPM_RC_FAILURE;
FAIL_RC(FATAL_ERROR_INTERNAL);
}
// Retrieve encrypted data size.

View File

@ -160,16 +160,33 @@
# define FAIL_RETURN(returnCode)
# define TPM_FAIL_RETURN NORETURN void
# define FAIL_IMMEDIATE(failCode, retval) SETFAILED(failCode)
# define FAIL_BOOL(failCode) SETFAILED(failCode)
# define FAIL_RC(failCode) SETFAILED(failCode)
# define FAIL_NULL(failCode) SETFAILED(failCode)
#else // NO_LONGJMP
// no longjmp service is available
# define FAIL_RETURN(returnCode) return(returnCode)
# define TPM_FAIL_RETURN void
// fail and immediately return a value
# define FAIL_IMMEDIATE(failCode, retval) \
do \
{ \
SETFAILED(failCode); \
return retval; \
} while(0)
// fail and return FALSE
# define FAIL_BOOL(failCode) FAIL_IMMEDIATE(failCode, FALSE)
// fail and return TPM_RC_FAILURE
# define FAIL_RC(failCode) FAIL_IMMEDIATE(failCode, TPM_RC_FAILURE)
// fail and return NULL
# define FAIL_NULL(failCode) FAIL_IMMEDIATE(failCode, NULL)
#endif
#if(defined EMPTY_ASSERT) && (EMPTY_ASSERT != NO)

View File

@ -301,7 +301,7 @@ static BYTE* GetSavedPcrPointer(TPM_ALG_ID alg, // IN: algorithm for bank
#undef HASH_CASE
default:
FAIL(FATAL_ERROR_INTERNAL);
FAIL_NULL(FATAL_ERROR_INTERNAL);
}
return retVal;
}

View File

@ -696,8 +696,7 @@ LIB_EXPORT TPM_RC DRBG_InstantiateSeeded(
// DRBG should have been tested, but...
if(!IsDrbgTested() && !DRBG_SelfTest())
{
LOG_FAILURE(FATAL_ERROR_SELF_TEST);
return TPM_RC_FAILURE;
FAIL_RC(FATAL_ERROR_SELF_TEST);
}
// Initialize the DRBG state
memset(drbgState, 0, sizeof(DRBG_STATE));
@ -905,8 +904,7 @@ LIB_EXPORT UINT16 DRBG_Generate(
{
// If this is a PRNG then the only way to get
// here is if the SW has run away.
LOG_FAILURE(FATAL_ERROR_INTERNAL);
return 0;
FAIL_IMMEDIATE(FATAL_ERROR_INTERNAL, 0);
}
}
// if the allowed number of bytes in a request is larger than the
@ -920,8 +918,7 @@ LIB_EXPORT UINT16 DRBG_Generate(
(BYTE*)pDRBG_KEY(seed), DRBG_KEY_SIZE_BITS, &keySchedule)
!= 0)
{
LOG_FAILURE(FATAL_ERROR_INTERNAL);
return 0;
FAIL_IMMEDIATE(FATAL_ERROR_INTERNAL, 0);
}
// Generate the random data
EncryptDRBG(
@ -934,8 +931,8 @@ LIB_EXPORT UINT16 DRBG_Generate(
}
else
{
LOG_FAILURE(FATAL_ERROR_INTERNAL);
return 0; // libtpms changed from FALSE
// invalid DRBG state structure
FAIL_IMMEDIATE(FATAL_ERROR_INTERNAL, 0);
}
return randomSize;
}