Skip to content

Commit 21d8604

Browse files
authored
Merge pull request #421 from dgarske/cryptocb_nokey
Fix for crypto callback with no TPM key and update for WC_RNG getpid
2 parents 8b2e427 + bd1e446 commit 21d8604

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ include(CheckFunctionExists)
6767
check_function_exists("gethostbyname" HAVE_GETHOSTBYNAME)
6868
check_function_exists("getaddrinfo" HAVE_GETADDRINFO)
6969
check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY)
70+
check_function_exists("getpid" HAVE_GETPID)
7071

7172

7273

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ AC_CHECK_SIZEOF([long], 4)
6060

6161
# Check headers/libs
6262
AC_CHECK_HEADERS([netdb.h])
63-
AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday inet_ntoa memset socket])
63+
AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday inet_ntoa memset socket getpid])
6464
AC_CHECK_LIB([network],[socket])
6565

6666
# Thread local storage

src/tpm2_cryptocb.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ int wolfTPM2_CryptoDevCb(int devId, wc_CryptoInfo* info, void* ctx)
120120
#endif
121121
rc = exit_rc;
122122
}
123+
else if (info->pk.type == WC_PK_TYPE_RSA_GET_SIZE) {
124+
if (tlsCtx->rsaKey != NULL) {
125+
*info->pk.rsa_get_size.keySize =
126+
tlsCtx->rsaKey->pub.publicArea.parameters.rsaDetail.keyBits
127+
/ 8;
128+
rc = 0;
129+
}
130+
}
123131
else if (info->pk.type == WC_PK_TYPE_RSA) {
124132
switch (info->pk.rsa.type) {
125133
case RSA_PUBLIC_ENCRYPT:
@@ -153,6 +161,11 @@ int wolfTPM2_CryptoDevCb(int devId, wc_CryptoInfo* info, void* ctx)
153161
case RSA_PRIVATE_DECRYPT:
154162
{
155163
/* private operations */
164+
if (tlsCtx->rsaKey == NULL) {
165+
/* TPM key not setup, fallback to software */
166+
rc = exit_rc;
167+
break;
168+
}
156169
rc = wolfTPM2_RsaDecrypt(tlsCtx->dev, tlsCtx->rsaKey,
157170
TPM_ALG_NULL, /* no padding */
158171
info->pk.rsa.in, info->pk.rsa.inLen,
@@ -237,6 +250,11 @@ int wolfTPM2_CryptoDevCb(int devId, wc_CryptoInfo* info, void* ctx)
237250
word32 rsLen = sizeof(sigRS), keySz;
238251
word32 inlen = info->pk.eccsign.inlen;
239252

253+
if (tlsCtx->eccKey == NULL) {
254+
/* TPM key not setup, fallback to software */
255+
return exit_rc;
256+
}
257+
240258
/* get key size from wolf signing key */
241259
keySz = wc_ecc_size(info->pk.eccsign.key);
242260
if (keySz == 0) {

0 commit comments

Comments
 (0)