mirror of https://github.com/wolfSSL/wolfTPM.git
cmake: windows fixes and spell fixes
* Examples working on Windows and SWTPM * Check command availability (including for windows blocking it). * update unseal to work without persistent NV storage * cleanup cmake from review * fix a few spelling mistakespull/202/head
parent
f2b7bec392
commit
084ef170b7
|
@ -80,11 +80,8 @@ target_compile_definitions(wolftpm PUBLIC
|
|||
)
|
||||
|
||||
if(WIN32)
|
||||
# TODO: fix benchmark to compile with WIN API TBS
|
||||
target_compile_definitions(wolftpm PRIVATE
|
||||
"_WINDLL"
|
||||
PUBLIC
|
||||
"NO_TPM_BENCH"
|
||||
)
|
||||
endif(WIN32)
|
||||
|
||||
|
@ -101,13 +98,17 @@ elseif("${WOLFTPM_INTERFACE}" STREQUAL "WINAPI")
|
|||
"WOLFTPM_WINAPI"
|
||||
)
|
||||
target_link_libraries(wolftpm tbs)
|
||||
else()
|
||||
get_property(INTERFACE_OPTS CACHE WOLFTPM_INTERFACE
|
||||
PROPERTY STRINGS)
|
||||
message(FATAL_ERROR "\"${WOLFTPM_INTERFACE}\" is not known WOLFTPM_INTERFACE:"
|
||||
" ${INTERFACE_OPTS}")
|
||||
endif("${WOLFTPM_INTERFACE}" STREQUAL "SWTPM")
|
||||
|
||||
target_include_directories(wolftpm
|
||||
PUBLIC
|
||||
$<INSTALL_INTERFACE:wolfssl>
|
||||
$<INSTALL_INTERFACE:wolftpm>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
||||
)
|
||||
|
||||
add_library(tpm_test_lib STATIC
|
||||
|
@ -152,3 +153,12 @@ add_tpm_example(tls_client tls/tls_client.c)
|
|||
add_tpm_example(tls_client_notpm tls/tls_client_notpm.c)
|
||||
add_tpm_example(tls_server tls/tls_server.c)
|
||||
add_tpm_example(wrap_test wrap/wrap_test.c)
|
||||
|
||||
|
||||
install(TARGETS wolftpm
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY)
|
||||
# Install the headers
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wolftpm/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wolftpm
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
|
|
|
@ -172,6 +172,10 @@ static int bench_sym_aes(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* storageKey,
|
|||
do {
|
||||
rc = wolfTPM2_EncryptDecrypt(dev, &aesKey, in, out, inOutSz, NULL, 0,
|
||||
isDecrypt);
|
||||
if (WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) {
|
||||
printf("Encrypt/Decrypt unavailble\n");
|
||||
break;
|
||||
}
|
||||
if (rc != 0) goto exit;
|
||||
} while (bench_stats_check(start, &count, TPM2_BENCH_DURATION_SEC));
|
||||
bench_stats_sym_finish(desc, count, inOutSz, start);
|
||||
|
@ -275,44 +279,44 @@ int TPM2_Wrapper_BenchArgs(void* userCtx, int argc, char *argv[])
|
|||
/* AES CBC */
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-128-CBC-enc", TPM_ALG_CBC, 128,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_ENCRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-128-CBC-dec", TPM_ALG_CBC, 128,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_DECRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-256-CBC-enc", TPM_ALG_CBC, 256,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_ENCRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-256-CBC-dec", TPM_ALG_CBC, 256,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_DECRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
|
||||
/* AES CTR */
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-128-CTR-enc", TPM_ALG_CTR, 128,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_ENCRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-128-CTR-dec", TPM_ALG_CTR, 128,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_DECRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-256-CTR-enc", TPM_ALG_CTR, 256,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_ENCRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-256-CTR-dec", TPM_ALG_CTR, 256,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_DECRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
|
||||
/* AES CFB */
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-128-CFB-enc", TPM_ALG_CFB, 128,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_ENCRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-128-CFB-dec", TPM_ALG_CFB, 128,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_DECRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-256-CFB-enc", TPM_ALG_CFB, 256,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_ENCRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
rc = bench_sym_aes(&dev, &storageKey, "AES-256-CFB-dec", TPM_ALG_CFB, 256,
|
||||
message.buffer, cipher.buffer, sizeof(message.buffer), WOLFTPM2_DECRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
|
||||
/* Hashing Benchmarks */
|
||||
/* SHA1 */
|
||||
|
|
|
@ -303,10 +303,16 @@ int TPM2_Keygen_Example(void* userCtx, int argc, char *argv[])
|
|||
if (rc != 0) goto exit;
|
||||
|
||||
printf("Creating new %s key...\n", TPM2_GetAlgName(alg));
|
||||
rc = wolfTPM2_CreateLoadedKey(&dev, &newKeyBlob, &primary->handle,
|
||||
|
||||
rc = wolfTPM2_CreateKey(&dev, &newKeyBlob, &primary->handle,
|
||||
&publicTemplate, auth.buffer, auth.size);
|
||||
if (rc != TPM_RC_SUCCESS) {
|
||||
printf("wolfTPM2_CreateLoadedKey failed\n");
|
||||
printf("wolfTPM2_CreateKey failed\n");
|
||||
goto exit;
|
||||
}
|
||||
rc = wolfTPM2_LoadKey(&dev, &newKeyBlob, &primary->handle);
|
||||
if (rc != TPM_RC_SUCCESS) {
|
||||
printf("wolfTPM2_LoadKey failed\n");
|
||||
goto exit;
|
||||
}
|
||||
printf("New key created and loaded (pub %d, priv %d bytes)\n",
|
||||
|
|
|
@ -227,6 +227,7 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
session[0].sessionHandle = TPM_RS_PW;
|
||||
TPM2_SetSessionAuth(session);
|
||||
|
||||
#ifndef WOLFTPM_WINAPI
|
||||
XMEMSET(&cmdIn.startup, 0, sizeof(cmdIn.startup));
|
||||
cmdIn.startup.startupType = TPM_SU_CLEAR;
|
||||
rc = TPM2_Startup(&cmdIn.startup);
|
||||
|
@ -237,7 +238,6 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
}
|
||||
printf("TPM2_Startup pass\n");
|
||||
|
||||
|
||||
/* Full self test */
|
||||
XMEMSET(&cmdIn.selfTest, 0, sizeof(cmdIn.selfTest));
|
||||
cmdIn.selfTest.fullTest = YES;
|
||||
|
@ -267,6 +267,7 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
printf("TPM2_IncrementalSelfTest: Rc 0x%x, Alg 0x%x (Todo %d)\n",
|
||||
rc, cmdIn.incSelfTest.toTest.algorithms[0],
|
||||
(int)cmdOut.incSelfTest.toDoList.count);
|
||||
#endif
|
||||
|
||||
|
||||
/* Get Capability for Property */
|
||||
|
@ -420,6 +421,7 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef WOLFTPM_WINAPI
|
||||
/* PCR Extend and Verify */
|
||||
/* Working with PCR16 because of next PCR Reset test */
|
||||
pcrIndex = TPM2_TEST_PCR;
|
||||
|
@ -487,7 +489,7 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
TPM2_PrintBin(cmdOut.pcrRead.pcrValues.digests[0].buffer,
|
||||
cmdOut.pcrRead.pcrValues.digests[0].size);
|
||||
}
|
||||
|
||||
#endif /* !WOLFTPM_WINAPI */
|
||||
|
||||
/* Start Auth Session */
|
||||
XMEMSET(&cmdIn.authSes, 0, sizeof(cmdIn.authSes));
|
||||
|
@ -785,8 +787,8 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
cmdIn.flushCtx.flushHandle = cmdOut.createLoaded.objectHandle;
|
||||
TPM2_FlushContext(&cmdIn.flushCtx);
|
||||
}
|
||||
else if (rc == TPM_RC_COMMAND_CODE) {
|
||||
printf("TPM2_CreatLoaded: Command is not supported on this hardware\n");
|
||||
else if (WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) {
|
||||
printf("TPM2_CreateLoaded: Command is not supported on this hardware\n");
|
||||
}
|
||||
else {
|
||||
printf("TPM2_CreateLoaded failed %d: %s\n", rc,
|
||||
|
@ -1258,6 +1260,8 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
rsaKey.handle = TPM_RH_NULL;
|
||||
TPM2_FlushContext(&cmdIn.flushCtx);
|
||||
|
||||
#ifndef WOLFTPM_WINAPI
|
||||
|
||||
/* NVRAM Access */
|
||||
|
||||
/* Clear auth buffer */
|
||||
|
@ -1312,6 +1316,7 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
TPM2_GetRCString(rc));
|
||||
goto exit;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Example for Encrypt/Decrypt */
|
||||
|
@ -1396,7 +1401,7 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
cmdIn.encDec.decrypt = NO;
|
||||
cmdIn.encDec.mode = TEST_AES_MODE;
|
||||
rc = TPM2_EncryptDecrypt2(&cmdIn.encDec, &cmdOut.encDec);
|
||||
if (rc == TPM_RC_COMMAND_CODE) { /* some TPM's may not support command */
|
||||
if (WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) { /* some TPM's may not support command */
|
||||
printf("TPM2_EncryptDecrypt2: Is not a supported feature without enabling due to export controls\n");
|
||||
perform_EncryptDecrypt2 = 0;
|
||||
rc = 0;
|
||||
|
@ -1434,11 +1439,7 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
cmdOut.encDec.outData.size) == 0) {
|
||||
printf("Encrypt/Decrypt test success\n");
|
||||
}
|
||||
else if (rc == TPM_RC_COMMAND_CODE
|
||||
#ifdef WOLFTPM_WINAPI
|
||||
|| rc == 0x80280400
|
||||
#endif
|
||||
) {
|
||||
else if (WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) {
|
||||
printf("Encrypt/Decrypt test result allowed as pass since hardware doesn't support.\n");
|
||||
rc = TPM_RC_SUCCESS;
|
||||
}
|
||||
|
@ -1487,7 +1488,6 @@ exit:
|
|||
TPM2_FlushContext(&cmdIn.flushCtx);
|
||||
}
|
||||
|
||||
#if 1 //ndef WOLFTPM_WINAPI
|
||||
/* Shutdown */
|
||||
cmdIn.shutdown.shutdownType = TPM_SU_CLEAR;
|
||||
if (TPM2_Shutdown(&cmdIn.shutdown) != TPM_RC_SUCCESS) {
|
||||
|
@ -1495,7 +1495,6 @@ exit:
|
|||
}
|
||||
|
||||
TPM2_Cleanup(&tpm2Ctx);
|
||||
#endif /* WOLFTPM_WINAPI */
|
||||
|
||||
#ifdef TPM2_SPI_DEV
|
||||
/* close handle */
|
||||
|
|
|
@ -132,6 +132,7 @@ int TPM2_Seal_Example(void* userCtx, int argc, char *argv[])
|
|||
}
|
||||
printf("Created new TPM seal key (pub %d, priv %d bytes)\n",
|
||||
newKey.pub.size, newKey.priv.size);
|
||||
printf("0x%x\n", newKey.handle.hndl);
|
||||
|
||||
/* Save key as encrypted blob to the disk */
|
||||
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_FILESYSTEM)
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
static void usage(void)
|
||||
{
|
||||
printf("Expected usage:\n");
|
||||
printf("./examples/seal/unseal [filename]\n");
|
||||
printf("./examples/seal/unseal [filename] [inkey_filename]\n");
|
||||
printf("* filename - File contaning a TPM seal key\n");
|
||||
printf("Demo usage, without arguments, uses keyblob.bin file input.\n");
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ int TPM2_Unseal_Example(void* userCtx, int argc, char *argv[])
|
|||
WOLFTPM2_KEY key;
|
||||
TPM2B_AUTH auth;
|
||||
const char *filename = "unseal.bin";
|
||||
const char *inkeyfilename = "keyblob.bin";
|
||||
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_FILESYSTEM)
|
||||
XFILE fp = NULL;
|
||||
size_t len;
|
||||
|
@ -59,6 +60,10 @@ int TPM2_Unseal_Example(void* userCtx, int argc, char *argv[])
|
|||
Unseal_In cmdIn_unseal;
|
||||
Unseal_Out cmdOut_unseal;
|
||||
|
||||
WOLFTPM2_KEYBLOB newKey;
|
||||
WOLFTPM2_KEY storage; /* SRK */
|
||||
|
||||
|
||||
XMEMSET(&cmdIn_unseal, 0, sizeof(cmdIn_unseal));
|
||||
XMEMSET(&cmdOut_unseal, 0, sizeof(cmdOut_unseal));
|
||||
XMEMSET(&key, 0, sizeof(key));
|
||||
|
@ -75,6 +80,10 @@ int TPM2_Unseal_Example(void* userCtx, int argc, char *argv[])
|
|||
if (argv[1][0] != '-') {
|
||||
filename = argv[1];
|
||||
}
|
||||
|
||||
if (argc >= 3 && argv[2][0] != '-') {
|
||||
inkeyfilename = argv[2];
|
||||
}
|
||||
}
|
||||
|
||||
printf("Example how to unseal data using TPM2.0\n");
|
||||
|
@ -85,12 +94,27 @@ int TPM2_Unseal_Example(void* userCtx, int argc, char *argv[])
|
|||
}
|
||||
printf("wolfTPM2_Init: success\n");
|
||||
|
||||
rc = getPrimaryStoragekey(&dev, &storage, TPM_ALG_RSA);
|
||||
if (rc != 0) goto exit;
|
||||
|
||||
rc = readKeyBlob(inkeyfilename, &newKey);
|
||||
if (rc != 0) goto exit;
|
||||
|
||||
rc = wolfTPM2_LoadKey(&dev, &newKey, &storage.handle);
|
||||
if (rc != TPM_RC_SUCCESS) {
|
||||
printf("wolfTPM2_LoadKey failed\n");
|
||||
goto exit;
|
||||
}
|
||||
printf("Loaded key to 0x%x\n",
|
||||
(word32)newKey.handle.hndl);
|
||||
|
||||
/* Set authorization for using the seal key */
|
||||
auth.size = (int)sizeof(gKeyAuth)-1;
|
||||
auth.size = (int)sizeof(gKeyAuth) - 1;
|
||||
XMEMCPY(auth.buffer, gKeyAuth, auth.size);
|
||||
wolfTPM2_SetAuthPassword(&dev, 0, &auth);
|
||||
|
||||
cmdIn_unseal.itemHandle = TPM2_DEMO_PERSISTENT_KEY_HANDLE;
|
||||
cmdIn_unseal.itemHandle = newKey.handle.hndl;
|
||||
|
||||
rc = TPM2_Unseal(&cmdIn_unseal, &cmdOut_unseal);
|
||||
if (rc != TPM_RC_SUCCESS) {
|
||||
printf("TPM2_Unseal failed 0x%x: %s\n", rc, TPM2_GetRCString(rc));
|
||||
|
@ -124,8 +148,6 @@ int TPM2_Unseal_Example(void* userCtx, int argc, char *argv[])
|
|||
|
||||
/* Remove the loaded TPM seal object */
|
||||
wolfTPM2_SetAuthPassword(&dev, 0, NULL);
|
||||
key.handle.hndl = TPM2_DEMO_PERSISTENT_KEY_HANDLE;
|
||||
wolfTPM2_NVDeleteKey(&dev, TPM_RH_OWNER, &key);
|
||||
|
||||
exit:
|
||||
|
||||
|
|
|
@ -88,16 +88,21 @@ static const char pemFileKey[] = "key.pem";
|
|||
#define TEST_WRAP_DIGEST TPM_ALG_SHA256
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_TPM_BENCH
|
||||
#ifndef WOLFSSL_USER_CURRTIME
|
||||
#ifdef _WIN32
|
||||
#include <time.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#endif
|
||||
static inline double gettime_secs(int reset)
|
||||
{
|
||||
#ifdef WOLFSSL_USER_CURRTIME
|
||||
extern double current_time(int reset);
|
||||
return current_time(reset);
|
||||
#elif defined(_WIN32)
|
||||
return ((double)GetTickCount64())/1000.0;
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, 0);
|
||||
|
|
|
@ -233,7 +233,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
/* Move this key into persistent storage */
|
||||
rc = wolfTPM2_NVStoreKey(&dev, TPM_RH_OWNER, &storageKey,
|
||||
TPM2_DEMO_STORAGE_KEY_HANDLE);
|
||||
if (rc != 0) goto exit;
|
||||
if (!WOLFTPM_IS_COMMAND_UNAVAILABLE(rc) && rc != 0) goto exit;
|
||||
|
||||
printf("Created new RSA Primary Storage Key at 0x%x\n",
|
||||
TPM2_DEMO_STORAGE_KEY_HANDLE);
|
||||
|
@ -270,7 +270,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
printf("Creating a loaded new TPM 2.0 key Test Passed\n");
|
||||
wolfTPM2_UnloadHandle(&dev, &testKey.handle);
|
||||
}
|
||||
else if (rc == TPM_RC_COMMAND_CODE) {
|
||||
else if (WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) {
|
||||
printf("CreateLoadedKey: Feature is not suppored on this hardware\n");
|
||||
}
|
||||
else {
|
||||
|
@ -494,7 +494,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
/* Move this key into persistent storage */
|
||||
rc = wolfTPM2_NVStoreKey(&dev, TPM_RH_OWNER, &storageKey,
|
||||
TPM2_DEMO_STORAGE_EC_KEY_HANDLE);
|
||||
if (rc != 0) goto exit;
|
||||
if (!WOLFTPM_IS_COMMAND_UNAVAILABLE(rc) && rc != 0) goto exit;
|
||||
|
||||
printf("Created new ECC Primary Storage Key at 0x%x\n",
|
||||
TPM2_DEMO_STORAGE_EC_KEY_HANDLE);
|
||||
|
@ -686,6 +686,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
/* NV TESTS */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* NV with Auth (preferred API's) */
|
||||
#ifndef WOLFTPM_WINAPI
|
||||
{
|
||||
WOLFTPM2_HANDLE parent;
|
||||
WOLFTPM2_NV nv;
|
||||
|
@ -756,7 +757,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
|
||||
printf("NV Test on index 0x%x with %d bytes passed\n",
|
||||
TPM2_DEMO_NV_TEST_INDEX, TPM2_DEMO_NV_TEST_SIZE);
|
||||
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* RANDOM TESTS */
|
||||
|
@ -851,7 +852,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
XMEMCPY(aesIv, TEST_AES_IV, (word32)sizeof(TEST_AES_IV));
|
||||
rc = wolfTPM2_EncryptDecrypt(&dev, &aesKey, message.buffer, cipher.buffer,
|
||||
message.size, aesIv, (word32)sizeof(aesIv), WOLFTPM2_ENCRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
|
||||
XMEMSET(plain.buffer, 0, sizeof(plain.buffer));
|
||||
plain.size = message.size;
|
||||
|
@ -868,7 +869,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
XMEMCMP(cipher.buffer, TEST_AES_VERIFY, cipher.size) == 0) {
|
||||
printf("Encrypt/Decrypt (known key) test success\n");
|
||||
}
|
||||
else if (rc == TPM_RC_COMMAND_CODE) {
|
||||
else if (WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) {
|
||||
printf("Encrypt/Decrypt: Is not a supported feature due to export controls\n");
|
||||
rc = TPM_RC_SUCCESS; /* clear error code */
|
||||
}
|
||||
|
@ -896,7 +897,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
cipher.size = message.size;
|
||||
rc = wolfTPM2_EncryptDecrypt(&dev, &aesKey, message.buffer, cipher.buffer,
|
||||
message.size, NULL, 0, WOLFTPM2_ENCRYPT);
|
||||
if (rc != 0 && rc != TPM_RC_COMMAND_CODE) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
|
||||
XMEMSET(plain.buffer, 0, sizeof(plain.buffer));
|
||||
plain.size = message.size;
|
||||
|
@ -910,7 +911,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
XMEMCMP(message.buffer, plain.buffer, message.size) == 0) {
|
||||
printf("Encrypt/Decrypt test success\n");
|
||||
}
|
||||
else if (rc == TPM_RC_COMMAND_CODE) {
|
||||
else if (WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) {
|
||||
printf("Encrypt/Decrypt: Is not a supported feature due to export controls\n");
|
||||
}
|
||||
else {
|
||||
|
@ -932,7 +933,7 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
hashBuf[i] = i;
|
||||
}
|
||||
rc = wolfTPM2_ExtendPCR(&dev, 0, TEST_WRAP_DIGEST, hashBuf, hashSz);
|
||||
if (rc != 0) goto exit;
|
||||
if (rc != 0 && !WOLFTPM_IS_COMMAND_UNAVAILABLE(rc)) goto exit;
|
||||
|
||||
/* Read PCR Index 0 */
|
||||
rc = wolfTPM2_ReadPCR(&dev, 0, TEST_WRAP_DIGEST, hashBuf, &hashSz);
|
||||
|
|
|
@ -1660,10 +1660,14 @@ struct wolfTPM_tcpContext {
|
|||
|
||||
#ifdef WOLFTPM_WINAPI
|
||||
#include <tbs.h>
|
||||
#include <winerror.h>
|
||||
|
||||
struct wolfTPM_winContext {
|
||||
TBS_HCONTEXT tbs_context;
|
||||
};
|
||||
#define WOLFTPM_IS_COMMAND_UNAVAILABLE(code) ((code) == TPM_RC_COMMAND_CODE || (code) == TPM_E_COMMAND_BLOCKED)
|
||||
#else
|
||||
#define WOLFTPM_IS_COMMAND_UNAVAILABLE(code) (code == TPM_RC_COMMAND_CODE)
|
||||
#endif /* WOLFTPM_WINAPI */
|
||||
|
||||
/* make sure advanced IO is enabled for I2C */
|
||||
|
|
|
@ -575,7 +575,7 @@ WOLFTPM_API int wolfTPM2_CreateKey(WOLFTPM2_DEV* dev,
|
|||
/*!
|
||||
\ingroup wolfTPM2_Wrappers
|
||||
\brief Single function to load a TPM 2.0 key
|
||||
\note To load a TPM 2.0 key its parent(Primary Key) should also be loaded prior to this operation. Primary Keys are laoded when they are created.
|
||||
\note To load a TPM 2.0 key its parent(Primary Key) should also be loaded prior to this operation. Primary Keys are loaded when they are created.
|
||||
|
||||
\return TPM_RC_SUCCESS: successful
|
||||
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
|
||||
|
|
Loading…
Reference in New Issue