From d463f70975cccbcbcd740b5bd308ea00c3fcb100 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Wed, 30 Apr 2025 11:22:13 -0700 Subject: [PATCH] Removed options.h not used, added TPM2_GetHierarchyDesc, and fixed indentation error --- examples/u-boot/options.h | 48 --------------------------------------- src/tpm2.c | 18 +++++++++++++++ src/tpm2_wrap.c | 21 ++++------------- wolftpm/tpm2.h | 20 ++++++++++++++++ 4 files changed, 43 insertions(+), 64 deletions(-) delete mode 100644 examples/u-boot/options.h diff --git a/examples/u-boot/options.h b/examples/u-boot/options.h deleted file mode 100644 index b8f6ba4..0000000 --- a/examples/u-boot/options.h +++ /dev/null @@ -1,48 +0,0 @@ -/* examples/u-boot/options.h - * - * Copyright (C) 2006-2021 wolfSSL Inc. - * - * This file is part of wolfTPM. - * - * wolfTPM is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * wolfTPM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA - */ - -/* Example wolfTPM options.h for U-boot compilation */ - -#ifndef WOLFTPM_OPTIONS_H -#define WOLFTPM_OPTIONS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#undef __UBOOT__ -#define __UBOOT__ - -#undef SIZEOF_LONG -#define SIZEOF_LONG 8 - -#undef WOLFTPM2_NO_WOLFCRYPT -#define WOLFTPM2_NO_WOLFCRYPT - -#undef WOLFTPM_AUTODETECT -#define WOLFTPM_AUTODETECT - -#ifdef __cplusplus -} -#endif - -#endif /* WOLFTPM_OPTIONS_H */ - diff --git a/src/tpm2.c b/src/tpm2.c index 3c84bcb..76a4978 100644 --- a/src/tpm2.c +++ b/src/tpm2.c @@ -6197,6 +6197,24 @@ TPM_ALG_ID TPM2_GetAlgId(const char* name) return TPM_ALG_ERROR; } +#ifdef DEBUG_WOLFTPM +const char* TPM2_GetHierarchyDesc(TPMI_RH_HIERARCHY_AUTH authHandle) +{ + switch (authHandle) { + case TPM_RH_LOCKOUT: + return "Lockout"; + case TPM_RH_ENDORSEMENT: + return "Endorsement"; + case TPM_RH_OWNER: + return "Owner"; + case TPM_RH_PLATFORM: + return "Platform"; + default: + return "Unknown"; + } +} +#endif /* DEBUG_WOLFTPM */ + int TPM2_GetCurveSize(TPM_ECC_CURVE curveID) { switch (curveID) { diff --git a/src/tpm2_wrap.c b/src/tpm2_wrap.c index 36db041..4f51697 100644 --- a/src/tpm2_wrap.c +++ b/src/tpm2_wrap.c @@ -5764,10 +5764,10 @@ int wolfTPM2_ChangeHierarchyAuth(WOLFTPM2_DEV* dev, WOLFTPM2_SESSION* session, in.authHandle = authHandle; /* use parameter encryption if session supplied */ - if (session != NULL) { - rc = wolfTPM2_SetAuthSession(dev, 1, session, (TPMA_SESSION_decrypt | - TPMA_SESSION_encrypt | TPMA_SESSION_continueSession)); - } + if (session != NULL) { + rc = wolfTPM2_SetAuthSession(dev, 1, session, (TPMA_SESSION_decrypt | + TPMA_SESSION_encrypt | TPMA_SESSION_continueSession)); + } if (rc == 0) { /* TPM 2.0 PCR's are typically SHA-1 and SHA2-256 */ in.newAuth.size = TPM2_GetHashDigestSize(WOLFTPM2_WRAP_DIGEST); @@ -5782,18 +5782,7 @@ int wolfTPM2_ChangeHierarchyAuth(WOLFTPM2_DEV* dev, WOLFTPM2_SESSION* session, rc = TPM2_HierarchyChangeAuth(&in); } #ifdef DEBUG_WOLFTPM - switch (authHandle) { - case TPM_RH_LOCKOUT: - desc = "Lockout"; break; - case TPM_RH_ENDORSEMENT: - desc = "Endrosement"; break; - case TPM_RH_OWNER: - desc = "Owner"; break; - case TPM_RH_PLATFORM: - desc = "Platform"; break; - default: - break; - } + desc = TPM2_GetHierarchyDesc(authHandle); if (rc == 0) { printf("%s auth set to %d bytes of random\n", desc, in.newAuth.size); diff --git a/wolftpm/tpm2.h b/wolftpm/tpm2.h index 2fe48b1..1e36a9b 100644 --- a/wolftpm/tpm2.h +++ b/wolftpm/tpm2.h @@ -3577,6 +3577,26 @@ WOLFTPM_API const char* TPM2_GetAlgName(TPM_ALG_ID alg); */ WOLFTPM_API TPM_ALG_ID TPM2_GetAlgId(const char* name); +#ifdef DEBUG_WOLFTPM +/*! + \ingroup TPM2_Proprietary + \brief Get readable string for TPM 2.0 hierarchy + + \return pointer to a string constant + + \param authHandle value of type TPMI_RH_HIERARCHY_AUTH specifying a valid + TPM 2.0 hierarchy + + _Example_ + \code + TPMI_RH_HIERARCHY_AUTH authHandle = TPM_RH_OWNER; + + printf("\tHierarchy: %s\n", TPM2_GetHierarchyDesc(authHandle)); + \endcode +*/ +WOLFTPM_API const char* TPM2_GetHierarchyDesc(TPMI_RH_HIERARCHY_AUTH authHandle); +#endif + /*! \ingroup TPM2_Proprietary \brief Determine the size in bytes of any TPM ECC Curve