diff --git a/src/Makefile.am b/src/Makefile.am index c6ba79e7..f6d94712 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -484,7 +484,6 @@ noinst_HEADERS += \ tpm2/LibtpmsCallbacks.h \ tpm2/NVMarshal.h \ tpm2/StateMarshal.h \ - tpm2/Test.h \ tpm2/Volatile.h if LIBTPMS_USE_OPENSSL diff --git a/src/tpm2/LibtpmsCallbacks.c b/src/tpm2/LibtpmsCallbacks.c index 1f450dab..6f411fa7 100644 --- a/src/tpm2/LibtpmsCallbacks.c +++ b/src/tpm2/LibtpmsCallbacks.c @@ -134,11 +134,6 @@ libtpms_plat__NvCommit( { struct libtpms_callbacks *cbs = TPMLIB_GetCallbacks(); -#if 0 - #include "Test.h" - Test_NvChip_UnMarshal(); -#endif - if (cbs->tpm_nvram_storedata) { uint32_t tpm_number = 0; const char *name = TPM_PERMANENT_ALL_NAME; diff --git a/src/tpm2/NVDynamic.c b/src/tpm2/NVDynamic.c index 88c9a2ad..e90b903f 100644 --- a/src/tpm2/NVDynamic.c +++ b/src/tpm2/NVDynamic.c @@ -1642,127 +1642,3 @@ NvGetMaxCount( NvRead(&maxCount, iter + sizeof(UINT32), sizeof(maxCount)); return maxCount; } - -/* libtpms added begin */ -/* - * Test harness for marshalling and unmarshalling and reconstructing the NVChip - */ -#include "Test.h" -#include -int memchk(const uint8_t *s1, const uint8_t *s2, size_t len) -{ - unsigned i; - int rc = 0; - - for (i = 0; i < len; i++) { - uint8_t c1 = s1[i], c2 = s2[i]; - if (c1 != c2) { - printf("diff at %d: x%02x vs x%02x\n", i, c1, c2); - rc = 1; - } - } - return rc; -} - -void Test_NvChip_UnMarshal(void) -{ - BYTE buffer[NV_MEMORY_SIZE]; - BYTE *buffer_p = &buffer[0]; - INT32 size = sizeof(buffer); - TPM_RC rc = TPM_RC_SUCCESS; - unsigned char bak_NV[NV_MEMORY_SIZE]; - size_t used; - NV_REF nvend = NvGetEnd(); - NV_RAM_REF nvramend = NvRamGetEnd(); - - /* make back of NVChip */ - memcpy(bak_NV, s_NV, sizeof(bak_NV)); - - /* marshal */ - printf("Marshalling...\n"); - PERSISTENT_ALL_Marshal(&buffer_p, &size); - used = sizeof(buffer) - size; - printf("size used by marshalling: %zu\n", used); - - /* clean the NVChip */ - memset(s_NV, 0x0, sizeof(s_NV)); - - /* unmarshal */ - buffer_p = &buffer[0]; - size = sizeof(buffer); - printf("Unmarshalling...\n"); - rc = PERSISTENT_ALL_Unmarshal(&buffer_p, &size); - - printf("size used by unmarshalling: %zd\n", sizeof(buffer) - size); - if (rc != TPM_RC_SUCCESS) { - sleep(10); - printf("%s: Unmarshalling failed\n", __func__); - } - if (used != sizeof(buffer) - size) { - sleep(10); - printf("marshalling and unmarshalling consumed different number of bytes\n"); - return; - } - if (nvend != NvGetEnd()) { - printf("NvGetEnd() returned %d but now %d\n", nvend, NvGetEnd()); - sleep(10); - } - if (nvramend != NvRamGetEnd()) { - printf("NvGetEnd() returned %p but now %p\n", nvramend, NvRamGetEnd()); - sleep(10); - } - - if (memchk(&bak_NV[NV_PERSISTENT_DATA], - &s_NV[NV_PERSISTENT_DATA], sizeof(PERSISTENT_DATA))) { - printf("PERSISTENT DATA IS DIFFERENT\n"); - } - if (memchk(&bak_NV[NV_ORDERLY_DATA], - &s_NV[NV_ORDERLY_DATA], sizeof(ORDERLY_DATA))) { - printf("ORDERLY DATA IS DIFFERENT\n"); - } - if (memchk(&bak_NV[NV_STATE_RESET_DATA], - &s_NV[NV_STATE_RESET_DATA], sizeof(STATE_RESET_DATA))) { - printf("STATE RESET DATA IS DIFFERENT\n"); - } - if (memchk(&bak_NV[NV_STATE_CLEAR_DATA], - &s_NV[NV_STATE_CLEAR_DATA], sizeof(STATE_CLEAR_DATA))) { - printf("STATE CLEAR DATA IS DIFFERENT\n"); - } - if (memchk(&bak_NV[NV_INDEX_RAM_DATA], - &s_NV[NV_INDEX_RAM_DATA], NvRamGetEnd() - &s_indexOrderlyRam[0])) { - printf("NV INDEX ORDERLY RAM DATA IS DIFFERENT (size=%ld)\n", - (long int)(NvRamGetEnd() - &s_indexOrderlyRam[0])); - } - if (memchk(&bak_NV[NV_USER_DYNAMIC], - &s_NV[NV_USER_DYNAMIC], - NvGetEnd() - NV_USER_DYNAMIC)) { - printf("NV USER RAM DATA IS DIFFERENT (size=%ld)\n", - (long int)(NvGetEnd() - NV_USER_DYNAMIC)); - } - - /* restore original NVChip */ - //memcpy(s_NV, bak_NV, sizeof(bak_NV)); - printf("VolatileState testing...\n"); - buffer_p = &buffer[0]; - size = sizeof(buffer); - VolatileState_Marshal(&buffer_p, &size); - - used = sizeof(buffer) - size; - printf("size used by VS marshalling: %zu\n", used); - - buffer_p = &buffer[0]; - size = sizeof(buffer); - rc = VolatileState_Unmarshal(&buffer_p, &size); - - printf("size used by unmarshalling: %zd\n", sizeof(buffer) - size); - if (rc != TPM_RC_SUCCESS) { - printf("%s: Unmarshalling failed\n", __func__); - sleep(10); - } - if (used != sizeof(buffer) - size) { - printf("marshalling and unmarshalling consumed different number of bytes\n"); - sleep(10); - return; - } -} -/* libtpms added end */ \ No newline at end of file diff --git a/src/tpm2/Test.h b/src/tpm2/Test.h deleted file mode 100644 index b88f750f..00000000 --- a/src/tpm2/Test.h +++ /dev/null @@ -1,46 +0,0 @@ -/********************************************************************************/ -/* */ -/* Test Prototypes */ -/* Written by Stefan Berger */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* (c) Copyright IBM Corporation 2018. */ -/* */ -/* All rights reserved. */ -/* */ -/* Redistribution and use in source and binary forms, with or without */ -/* modification, are permitted provided that the following conditions are */ -/* met: */ -/* */ -/* Redistributions of source code must retain the above copyright notice, */ -/* this list of conditions and the following disclaimer. */ -/* */ -/* Redistributions in binary form must reproduce the above copyright */ -/* notice, this list of conditions and the following disclaimer in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* Neither the names of the IBM Corporation nor the names of its */ -/* contributors may be used to endorse or promote products derived from */ -/* this software without specific prior written permission. */ -/* */ -/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ -/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ -/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */ -/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */ -/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */ -/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ -/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */ -/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */ -/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ -/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */ -/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/********************************************************************************/ - -#ifndef TEST_FP_H -#define TEST_FP_H - -void -Test_NvChip_UnMarshal( - void - ); -#endif