diff --git a/CMakeLists.txt b/CMakeLists.txt index 5693ea9c..8362a46b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ include(CheckFunctionExists) check_function_exists("gethostbyname" HAVE_GETHOSTBYNAME) check_function_exists("getaddrinfo" HAVE_GETADDRINFO) check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY) +check_function_exists("getpid" HAVE_GETPID) diff --git a/configure.ac b/configure.ac index f1b36fe4..81c18151 100644 --- a/configure.ac +++ b/configure.ac @@ -60,7 +60,7 @@ AC_CHECK_SIZEOF([long], 4) # Check headers/libs AC_CHECK_HEADERS([netdb.h]) -AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday inet_ntoa memset socket]) +AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday inet_ntoa memset socket getpid]) AC_CHECK_LIB([network],[socket]) # Thread local storage diff --git a/src/tpm2_cryptocb.c b/src/tpm2_cryptocb.c index 8753100f..c822efdb 100644 --- a/src/tpm2_cryptocb.c +++ b/src/tpm2_cryptocb.c @@ -120,6 +120,14 @@ int wolfTPM2_CryptoDevCb(int devId, wc_CryptoInfo* info, void* ctx) #endif rc = exit_rc; } + else if (info->pk.type == WC_PK_TYPE_RSA_GET_SIZE) { + if (tlsCtx->rsaKey != NULL) { + *info->pk.rsa_get_size.keySize = + tlsCtx->rsaKey->pub.publicArea.parameters.rsaDetail.keyBits + / 8; + rc = 0; + } + } else if (info->pk.type == WC_PK_TYPE_RSA) { switch (info->pk.rsa.type) { case RSA_PUBLIC_ENCRYPT: @@ -153,6 +161,11 @@ int wolfTPM2_CryptoDevCb(int devId, wc_CryptoInfo* info, void* ctx) case RSA_PRIVATE_DECRYPT: { /* private operations */ + if (tlsCtx->rsaKey == NULL) { + /* TPM key not setup, fallback to software */ + rc = exit_rc; + break; + } rc = wolfTPM2_RsaDecrypt(tlsCtx->dev, tlsCtx->rsaKey, TPM_ALG_NULL, /* no padding */ info->pk.rsa.in, info->pk.rsa.inLen, @@ -237,6 +250,11 @@ int wolfTPM2_CryptoDevCb(int devId, wc_CryptoInfo* info, void* ctx) word32 rsLen = sizeof(sigRS), keySz; word32 inlen = info->pk.eccsign.inlen; + if (tlsCtx->eccKey == NULL) { + /* TPM key not setup, fallback to software */ + return exit_rc; + } + /* get key size from wolf signing key */ keySz = wc_ecc_size(info->pk.eccsign.key); if (keySz == 0) {