From e41d4d453a02cdfdfdd4d845053b7228dfc2ef51 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Wed, 11 Jul 2018 12:37:47 -0400 Subject: [PATCH] rev148: Rework DRBG_DEBUG_PRINT Signed-off-by: Stefan Berger --- src/tpm2/TpmBuildSwitches.h | 14 ++++++++------ src/tpm2/crypto/openssl/CryptRand.c | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/tpm2/TpmBuildSwitches.h b/src/tpm2/TpmBuildSwitches.h index 7272f7f1..ddb63eea 100644 --- a/src/tpm2/TpmBuildSwitches.h +++ b/src/tpm2/TpmBuildSwitches.h @@ -183,13 +183,15 @@ # define RUNTIME_SIZE_CHECKS NO // Default: Either YES or NO # endif +// If doing debug, can set the DRBG to print out the intermediate test values. Before enabling this, +// make sure that the dbgDumpMemBlock() function has been added someplace (preferably, somewhere in +// CryptRand.c) +# if !(defined DRBG_DEBUG_PRINT) \ + || ((DRBG_DEBUG_PRINT != NO) && (DRBG_DEBUG_PRINT != YES)) +# undef DRBG_DEBUG_PRINT +# define DRBG_DEBUG_PRINT NO // Default: Either YES or NO +# endif -/* If doing debug, can set the DRBG to print out the intermediate test values. Before enabling this, - make sure that the dbgDumpMemBlock() function has been added someplace (preferably, somewhere in - CryptRand.c) */ -#ifndef DRBG_DEBUG_PRINT -//# define DRBG_DEBUG_PRINT -#endif /* If an assertion event it not going to produce any trace information (function and line number) then define NO_FAIL_TRACE */ #ifndef NO_FAIL_TRACE diff --git a/src/tpm2/crypto/openssl/CryptRand.c b/src/tpm2/crypto/openssl/CryptRand.c index fe22c34a..1aa8b630 100644 --- a/src/tpm2/crypto/openssl/CryptRand.c +++ b/src/tpm2/crypto/openssl/CryptRand.c @@ -435,7 +435,7 @@ DRBG_SelfTest( // Do an instantiate if(!DRBG_Instantiate(&testState, 0, NULL)) return FALSE; -#if defined DRBG_DEBUG_PRINT && defined DEBUG +#if DRBG_DEBUG_PRINT dbgDumpMemBlock(pDRBG_KEY(&testState), DRBG_KEY_SIZE_BYTES, "Key after Instantiate"); dbgDumpMemBlock(pDRBG_IV(&testState), DRBG_IV_SIZE_BYTES, @@ -443,7 +443,7 @@ DRBG_SelfTest( #endif if(DRBG_Generate((RAND_STATE *)&testState, buf, sizeof(buf)) == 0) return FALSE; -#if defined DRBG_DEBUG_PRINT && defined DEBUG +#if DRBG_DEBUG_PRINT dbgDumpMemBlock(pDRBG_KEY(&testState.seed), DRBG_KEY_SIZE_BYTES, "Key after 1st Generate"); dbgDumpMemBlock(pDRBG_IV(&testState.seed), DRBG_IV_SIZE_BYTES, @@ -453,7 +453,7 @@ DRBG_SelfTest( return FALSE; memcpy(seed.bytes, DRBG_NistTestVector_EntropyReseed, sizeof(seed)); DRBG_Reseed(&testState, &seed, NULL); -#if defined DRBG_DEBUG_PRINT && defined DEBUG +#if DRBG_DEBUG_PRINT dbgDumpMemBlock((BYTE *)pDRBG_KEY(&testState.seed), DRBG_KEY_SIZE_BYTES, "Key after 2nd Generate"); dbgDumpMemBlock((BYTE *)pDRBG_IV(&testState.seed), DRBG_IV_SIZE_BYTES,