Skip to content

Commit 683b1af

Browse files
committed
Fix for HASH_COUNT (make sure its at least 2 by default). Fix for TPM2_GetWolfRng to ensure NULL is set on RNG init error.
1 parent a32b30f commit 683b1af

2 files changed

Lines changed: 41 additions & 27 deletions

File tree

src/tpm2.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6328,6 +6328,9 @@ int TPM2_GetWolfRng(WC_RNG** rng)
63286328
printf("wc_InitRng_ex failed %d: %s\n",
63296329
(int)rc, wc_GetErrorString(rc));
63306330
#endif
6331+
if (rng) {
6332+
*rng = NULL;
6333+
}
63316334
return rc;
63326335
}
63336336
ctx->rngInit = 1;

wolftpm/tpm2_types.h

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -654,39 +654,50 @@ typedef int64_t INT64;
654654
#define MAX_CAP_HANDLES (MAX_CAP_DATA / sizeof(TPM_HANDLE))
655655
#endif
656656
#ifndef HASH_COUNT
657-
/* Calculate hash count based on wolfCrypt enables */
658-
#ifndef NO_SHA
659-
#define HASH_COUNT_SHA1 1
660-
#else
661-
#define HASH_COUNT_SHA1 0
662-
#endif
657+
#ifndef WOLFTPM2_NO_WOLFCRYPT
658+
/* Calculate hash count based on wolfCrypt enables */
659+
#ifndef NO_SHA
660+
#define HASH_COUNT_SHA1 1
661+
#else
662+
#define HASH_COUNT_SHA1 0
663+
#endif
663664

664-
#ifndef NO_SHA256
665-
#define HASH_COUNT_SHA256 1
666-
#else
667-
#define HASH_COUNT_SHA256 0
668-
#endif
665+
#ifndef NO_SHA256
666+
#define HASH_COUNT_SHA256 1
667+
#else
668+
#define HASH_COUNT_SHA256 0
669+
#endif
669670

670-
#ifdef WOLFSSL_SHA384
671-
#define HASH_COUNT_SHA384 1
672-
#else
673-
#define HASH_COUNT_SHA384 0
674-
#endif
671+
#ifdef WOLFSSL_SHA384
672+
#define HASH_COUNT_SHA384 1
673+
#else
674+
#define HASH_COUNT_SHA384 0
675+
#endif
675676

676-
#ifdef WOLFSSL_SHA512
677-
#define HASH_COUNT_SHA512 1
678-
#else
679-
#define HASH_COUNT_SHA512 0
680-
#endif
677+
#ifdef WOLFSSL_SHA512
678+
#define HASH_COUNT_SHA512 1
679+
#else
680+
#define HASH_COUNT_SHA512 0
681+
#endif
681682

682-
#ifdef WOLFSSL_SHA3
683-
#define HASH_COUNT_SHA3 1
683+
#ifdef WOLFSSL_SHA3
684+
#define HASH_COUNT_SHA3 1
685+
#else
686+
#define HASH_COUNT_SHA3 0
687+
#endif
688+
689+
#define HASH_COUNT (HASH_COUNT_SHA1 + HASH_COUNT_SHA256 + \
690+
HASH_COUNT_SHA384 + HASH_COUNT_SHA512 + \
691+
HASH_COUNT_SHA3)
692+
/* make sure hash count is at least 2 */
693+
#if HASH_COUNT < 2
694+
#undef HASH_COUNT
695+
#define HASH_COUNT 2
696+
#endif
684697
#else
685-
#define HASH_COUNT_SHA3 0
698+
/* default to 2 for non-wolfCrypt builds */
699+
#define HASH_COUNT 2
686700
#endif
687-
688-
#define HASH_COUNT (HASH_COUNT_SHA1 + HASH_COUNT_SHA256 + \
689-
HASH_COUNT_SHA384 + HASH_COUNT_SHA512 + HASH_COUNT_SHA3)
690701
#endif
691702
#ifndef MAX_CAP_ALGS
692703
#define MAX_CAP_ALGS (MAX_CAP_DATA / sizeof(TPMS_ALG_PROPERTY))

0 commit comments

Comments
 (0)