Skip to content

Commit

Permalink
Fixes for compiler type warnings. Add WOLFTPM_NO_LOCK. Improve STM …
Browse files Browse the repository at this point in the history
…IO options/logging.
  • Loading branch information
dgarske committed Dec 20, 2023
1 parent 17fcfb6 commit 32ddfdc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
7 changes: 7 additions & 0 deletions hal/tpm_io_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@
}

#else /* STM32 CubeMX Hal SPI */
#ifndef STM32_CUBEMX_SPI_TIMEOUT
#define STM32_CUBEMX_SPI_TIMEOUT 250
#endif
#ifndef USE_SPI_CS_PORT
#define USE_SPI_CS_PORT GPIOA
#endif
Expand Down Expand Up @@ -218,6 +220,11 @@

if (status == HAL_OK)
ret = TPM_RC_SUCCESS;
#ifdef WOLFTPM_DEBUG_VERBOSE
else {
printf("SPI Failed: Xfer %d, Status=0x%x\n", xferSz, status);
}
#endif

(void)ctx;

Expand Down
10 changes: 5 additions & 5 deletions src/tpm2.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static volatile int gWolfCryptRefCount = 0;
/******************************************************************************/
static TPM_RC TPM2_AcquireLock(TPM2_CTX* ctx)
{
#if defined(WOLFTPM2_NO_WOLFCRYPT) || defined(SINGLE_THREADED)
#if defined(WOLFTPM2_NO_WOLFCRYPT) || defined(WOLFTPM_NO_LOCK)
(void)ctx;
#else
int ret;
Expand Down Expand Up @@ -86,7 +86,7 @@ static TPM_RC TPM2_AcquireLock(TPM2_CTX* ctx)

static void TPM2_ReleaseLock(TPM2_CTX* ctx)
{
#if defined(WOLFTPM2_NO_WOLFCRYPT) || defined(SINGLE_THREADED)
#if defined(WOLFTPM2_NO_WOLFCRYPT) || defined(WOLFTPM_NO_LOCK)
(void)ctx;
#else
ctx->lockCount--;
Expand Down Expand Up @@ -143,7 +143,7 @@ static int TPM2_CommandProcess(TPM2_CTX* ctx, TPM2_Packet* packet,

#ifdef WOLFTPM_DEBUG_VERBOSE
printf("CommandProcess: Handles (Auth %d, In %d), CmdSz %d, AuthSz %d, ParamSz %d, EncSz %d\n",
info->authCnt, info->inHandleCnt, cmdSz, authSz, paramSz, encParamSz);
info->authCnt, info->inHandleCnt, (int)cmdSz, (int)authSz, paramSz, encParamSz);
#else
(void)paramSz;
#endif
Expand Down Expand Up @@ -282,7 +282,7 @@ static int TPM2_ResponseProcess(TPM2_CTX* ctx, TPM2_Packet* packet,

#ifdef WOLFTPM_DEBUG_VERBOSE
printf("ResponseProcess: Handles (Out %d), RespSz %d, ParamSz %d, DecSz %d, AuthSz %d\n",
info->outHandleCnt, respSz, paramSz, decParamSz, respSz - authPos);
info->outHandleCnt, (int)respSz, (int)paramSz, (int)decParamSz, (int)(respSz - authPos));
#endif

for (i=0; i<info->authCnt; i++) {
Expand Down Expand Up @@ -662,7 +662,7 @@ TPM_RC TPM2_Cleanup(TPM2_CTX* ctx)
wc_FreeRng(&ctx->rng);
}
#endif
#ifndef SINGLE_THREADED
#ifndef WOLFTPM_NO_LOCK
if (ctx->hwLockInit) {
ctx->hwLockInit = 0;
wc_FreeMutex(&ctx->hwLock);
Expand Down
4 changes: 2 additions & 2 deletions src/tpm2_param_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ int TPM2_CalcCpHash(TPMI_ALG_HASH authHash, TPM_CC cmdCode,
}

#ifdef WOLFTPM_DEBUG_VERBOSE
printf("cpHash: cmd %x, size %d\n", cmdCode, hash->size);
printf("cpHash: cmd %x, size %d\n", (unsigned int)cmdCode, hash->size);
TPM2_PrintBin(hash->buffer, hash->size);
#endif

Expand Down Expand Up @@ -448,7 +448,7 @@ int TPM2_CalcRpHash(TPMI_ALG_HASH authHash,
}

#ifdef WOLFTPM_DEBUG_VERBOSE
printf("rpHash: cmd %x, size %d\n", cmdCode, hash->size);
printf("rpHash: cmd %x, size %d\n", (unsigned int)cmdCode, hash->size);
TPM2_PrintBin(hash->buffer, hash->size);
#endif

Expand Down
4 changes: 2 additions & 2 deletions wolftpm/tpm2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ typedef struct TPM2_CTX {
struct wolfTPM_winContext winCtx;
#endif
#ifndef WOLFTPM2_NO_WOLFCRYPT
#ifndef SINGLE_THREADED
#ifndef WOLFTPM_NO_LOCK
wolfSSL_Mutex hwLock;
int lockCount;
#endif
Expand All @@ -1733,7 +1733,7 @@ typedef struct TPM2_CTX {
byte rid;
/* Informational Bits - use unsigned int for best compiler compatibility */
#ifndef WOLFTPM2_NO_WOLFCRYPT
#ifndef SINGLE_THREADED
#ifndef WOLFTPM_NO_LOCK
unsigned int hwLockInit:1;
#endif
#ifndef WC_NO_RNG
Expand Down
5 changes: 5 additions & 0 deletions wolftpm/tpm2_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ typedef int64_t INT64;
#define printf XPRINTF
#endif

/* check if locking / mutex should be enabled */
#if defined(SINGLE_THREADED)
#undef WOLFTPM_NO_LOCK
#define WOLFTPM_NO_LOCK
#endif


/* ---------------------------------------------------------------------------*/
Expand Down

0 comments on commit 32ddfdc

Please sign in to comment.