From d7b2ff804ff072f4c92b9c6bde679c9fa30244c4 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Wed, 20 Dec 2023 14:19:59 -0500 Subject: [PATCH] rev180: Add ALLOW_FORCE_FAILURE_MODE with 'NO' and use it Set ALLOW_FORCE_FAILURE_MODE to 'NO' and used it in some places where SIMULATION was used, which is also set to 'NO'. Signed-off-by: Stefan Berger --- src/tpm2/CryptSelfTest.c | 2 +- src/tpm2/Global.h | 2 +- src/tpm2/StartupCommands.c | 3 ++- src/tpm2/TpmBuildSwitches.h | 10 ++++++++++ src/tpm2/TpmFail.c | 7 ++----- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/tpm2/CryptSelfTest.c b/src/tpm2/CryptSelfTest.c index 0af7da49..9d5d10bb 100644 --- a/src/tpm2/CryptSelfTest.c +++ b/src/tpm2/CryptSelfTest.c @@ -116,7 +116,7 @@ TPM_RC CryptSelfTest(TPMI_YES_NO fullTest // IN: if full test is required ) { -#if SIMULATION +#if ALLOW_FORCE_FAILURE_MODE if(g_forceFailureMode) FAIL(FATAL_ERROR_FORCED); #endif diff --git a/src/tpm2/Global.h b/src/tpm2/Global.h index f76e1a88..82935f45 100644 --- a/src/tpm2/Global.h +++ b/src/tpm2/Global.h @@ -1468,7 +1468,7 @@ EXTERN UINT32 s_actionIoAllocation; // number of UIN64 allocated for the // in which the failure occurred. This address value is not useful for anything // other than helping the vendor to know in which file the failure occurred. EXTERN BOOL g_inFailureMode; // Indicates that the TPM is in failure mode -# if SIMULATION +# if ALLOW_FORCE_FAILURE_MODE EXTERN BOOL g_forceFailureMode; // flag to force failure mode during test # endif diff --git a/src/tpm2/StartupCommands.c b/src/tpm2/StartupCommands.c index 21e3734a..1d5be0d5 100644 --- a/src/tpm2/StartupCommands.c +++ b/src/tpm2/StartupCommands.c @@ -82,7 +82,8 @@ LIB_EXPORT void _TPM_Init(void) memset(&go, 0xbb, sizeof(go)); } #endif -#if SIMULATION + +#if ALLOW_FORCE_FAILURE_MODE // Clear the flag that forces failure on self-test g_forceFailureMode = FALSE; #endif diff --git a/src/tpm2/TpmBuildSwitches.h b/src/tpm2/TpmBuildSwitches.h index 6aaa6b27..845b63a9 100644 --- a/src/tpm2/TpmBuildSwitches.h +++ b/src/tpm2/TpmBuildSwitches.h @@ -122,6 +122,16 @@ // Define this to run the function that checks the compatibility between the chosen big number math // library and the TPM code. Not all ports use this. +//////////////////////////////////////////////////////////////// +// TEST OPTIONS +//////////////////////////////////////////////////////////////// +// The SIMULATION flag can enable test crypto behaviors and caching that +// significantly change the behavior of the code. This flag controls only the +// g_forceFailureMode flag in the TPM library while leaving the rest of the TPM +// behavior alone. Useful for testing when the full set of options controlled by +// SIMULATION may not be desired. +#define ALLOW_FORCE_FAILURE_MODE NO // libtpms: NO + #if !(defined LIBRARY_COMPATIBILITY_CHECK) \ || (( LIBRARY_COMPATIBILITY_CHECK != NO) \ && (LIBRARY_COMPATIBILITY_CHECK != YES)) diff --git a/src/tpm2/TpmFail.c b/src/tpm2/TpmFail.c index 405a4f14..392a0794 100644 --- a/src/tpm2/TpmFail.c +++ b/src/tpm2/TpmFail.c @@ -178,19 +178,16 @@ static BOOL Unmarshal16(UINT16* target, BYTE** buffer, INT32* size) } //** Public Functions -#if 0 /* libtpms added */ //*** SetForceFailureMode() // This function is called by the simulator to enable failure mode testing. +#if ALLOW_FORCE_FAILURE_MODE LIB_EXPORT void SetForceFailureMode(void) { -#if SIMULATION g_forceFailureMode = TRUE; -#endif return; } -#endif /* libtpms added */ - +#endif // ALLOW_FORCE_FAILURE_MODE /* libtpms added begin */ static void