Fix tests and wrapper example with no wolfcrypt

pull/207/head
Elms 2022-05-06 21:43:15 -07:00
parent 6324ed6253
commit a787dab931
2 changed files with 14 additions and 6 deletions

View File

@ -442,7 +442,6 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
wc_FreeRsaKey(&wolfRsaPrivKey);
rc = wolfTPM2_UnloadHandle(&dev, &rsaKey.handle);
if (rc != 0) goto exit;
#endif /* !WOLFTPM2_NO_WOLFCRYPT && !NO_RSA */
/* Load raw RSA private key into TPM */
rc = wolfTPM2_LoadRsaPrivateKey(&dev, &storageKey, &rsaKey,
@ -455,12 +454,12 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
(word32)rsaKey.handle.hndl);
rc = wolfTPM2_UnloadHandle(&dev, &rsaKey.handle);
if (rc != 0) goto exit;
#endif /* !WOLFTPM2_NO_WOLFCRYPT && !NO_RSA */
/* Close TPM session based on RSA storage key */
wolfTPM2_UnloadHandle(&dev, &tpmSession.handle);
wolfTPM2_SetAuthSession(&dev, 1, NULL, 0); /* clear auth session */
/*------------------------------------------------------------------------*/
/* ECC TESTS */
/*------------------------------------------------------------------------*/
@ -662,7 +661,6 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
wc_ecc_free(&wolfEccPrivKey);
rc = wolfTPM2_UnloadHandle(&dev, &eccKey.handle);
if (rc != 0) goto exit;
#endif /* !WOLFTPM2_NO_WOLFCRYPT && HAVE_ECC */
/* Load raw ECC private key into TPM */
rc = wolfTPM2_LoadEccPrivateKey(&dev, &storageKey, &eccKey, TPM_ECC_NIST_P256,
@ -675,6 +673,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
(word32)eccKey.handle.hndl);
rc = wolfTPM2_UnloadHandle(&dev, &eccKey.handle);
if (rc != 0) goto exit;
#endif /* !WOLFTPM2_NO_WOLFCRYPT && HAVE_ECC */
#if 0 /* disabled until ECC Encrypted salt is added */
/* Close TPM session based on ECC storage key */
@ -841,6 +840,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
/*------------------------------------------------------------------------*/
/* ENCRYPT/DECRYPT TESTS */
/*------------------------------------------------------------------------*/
#ifndef WOLFTPM2_NO_WOLFCRYPT
rc = wolfTPM2_LoadSymmetricKey(&dev, &aesKey, TEST_AES_MODE,
TEST_AES_KEY, (word32)sizeof(TEST_AES_KEY));
if (rc != 0) goto exit;
@ -878,7 +878,9 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
goto exit;
}
if (rc != 0) goto exit;
#else
(void)aesIv;
#endif /* !WOLFTPM2_NO_WOLFCRYPT */
rc = wolfTPM2_GetKeyTemplate_Symmetric(&publicTemplate, 128, TEST_AES_MODE,
YES, YES);

View File

@ -274,15 +274,21 @@ static void test_TPM2_KDFa(void)
.size = 8,
.buffer = {0xDA, 0x50, 0x40, 0x31, 0xDD, 0xF1, 0x2E, 0x83}
};
byte key[TEST_KDFA_KEYSZ];
#ifndef WOLFTPM2_NO_WOLFCRYPT
const byte keyExp[TEST_KDFA_KEYSZ] = {
0xbb, 0x02, 0x59, 0xe1, 0xc8, 0xba, 0x60, 0x7e, 0x6a, 0x2c,
0xd7, 0x04, 0xb6, 0x9a, 0x90, 0x2e, 0x9a, 0xde, 0x84, 0xc4};
byte key[TEST_KDFA_KEYSZ];
#endif
rc = TPM2_KDFa(TPM_ALG_SHA256, &keyIn, label, &contextU, &contextV, key, keyIn.size);
#ifdef WOLFTPM2_NO_WOLFCRYPT
AssertIntEQ(NOT_COMPILED_IN, rc);
#else
AssertIntEQ(sizeof(keyExp), rc);
AssertIntEQ(XMEMCMP(key, keyExp, sizeof(keyExp)), 0);
#endif
}
#endif /* !WOLFTPM2_NO_WRAPPER */