From 7aca56fde2db676f03155a938c3e68fc0b65bb02 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Wed, 21 Jan 2026 12:15:45 -0500 Subject: [PATCH] Sync: Sync minor changes in several files with upstream Signed-off-by: Stefan Berger --- .../prototypes/platform_public_interface.h | 7 +++- .../include/prototypes/Simulator_fp.h | 9 +++-- src/tpm2/TPMCmd/Simulator/src/TPMCmdp.c | 2 +- .../TpmConfiguration/TpmProfile_Common.h | 8 +++-- .../VendorCommands/VendorCommandList.h | 4 +++ .../common/include/EccConstantData.inl | 34 ------------------- .../tpm_to_platform_interface.h | 2 +- .../TPMCmd/tpm/include/private/CryptHash.h | 4 +-- .../TPMCmd/tpm/include/private/CryptSym.h | 8 ++--- .../include/private/prototypes/CryptRsa_fp.h | 5 --- .../TPMCmd/tpm/include/tpm_public/GpMacros.h | 2 -- .../TPMCmd/tpm/include/tpm_public/TpmTypes.h | 3 +- .../include/tpm_public/VerifyConfiguration.h | 6 ++++ .../TPMCmd/tpm/include/tpm_public/tpm_debug.h | 1 + .../src/command/NVStorage/NV_ReadPublic2.c | 1 - src/tpm2/TPMCmd/tpm/src/crypt/CryptSym.c | 1 - src/tpm2/TPMCmd/tpm/src/crypt/CryptUtil.c | 1 - .../src/crypt/ecc/TpmEcc_Signature_ECDAA.c | 1 - .../src/crypt/ecc/TpmEcc_Signature_Schnorr.c | 1 - src/tpm2/TPMCmd/tpm/src/subsystem/Session.c | 2 +- src/tpm2/TPMCmd/tpm/src/support/PropertyCap.c | 16 +++------ 21 files changed, 41 insertions(+), 77 deletions(-) diff --git a/src/tpm2/TPMCmd/Platform/include/prototypes/platform_public_interface.h b/src/tpm2/TPMCmd/Platform/include/prototypes/platform_public_interface.h index 94fc5d44..4b532c55 100644 --- a/src/tpm2/TPMCmd/Platform/include/prototypes/platform_public_interface.h +++ b/src/tpm2/TPMCmd/Platform/include/prototypes/platform_public_interface.h @@ -68,8 +68,13 @@ #include -//** From Cancel.c +#if ALLOW_FORCE_FAILURE_MODE +// From Failure.c +// allow simulator to force the TPM into failure mode. +LIB_EXPORT void _plat__SetForceFailureMode(); +#endif +//** From Cancel.c // Set cancel flag. LIB_EXPORT void _plat__SetCancel(void); diff --git a/src/tpm2/TPMCmd/Simulator/include/prototypes/Simulator_fp.h b/src/tpm2/TPMCmd/Simulator/include/prototypes/Simulator_fp.h index f4819158..509fcead 100644 --- a/src/tpm2/TPMCmd/Simulator/include/prototypes/Simulator_fp.h +++ b/src/tpm2/TPMCmd/Simulator/include/prototypes/Simulator_fp.h @@ -80,7 +80,7 @@ bool PlatformServer(SOCKET s); //*** PlatformSvcRoutine() // This function is called to set up the socket interfaces to listen for // commands. -int PlatformSvcRoutine(LPVOID port); +DWORD WINAPI PlatformSvcRoutine(LPVOID port); //*** PlatformSignalService() // This function starts a new thread waiting for platform signals. @@ -88,13 +88,13 @@ int PlatformSvcRoutine(LPVOID port); // received. // If PickPorts is true, the server finds the next available port if the specified // port was unavailable. -int PlatformSignalService(int *PortNumberPlatform); +int PlatformSignalService(int PortNumber, bool PickPorts); //*** RegularCommandService() // This function services regular commands. // If PickPorts is true, the server finds the next available port if the specified // port was unavailable. -int RegularCommandService(int *PortNumber); +int RegularCommandService(int PortNumber, bool PickPorts); //*** StartTcpServer() // This is the main entry-point to the TCP server. The server listens on the port @@ -103,8 +103,7 @@ int RegularCommandService(int *PortNumber); // port was unavailable. // // Note that there is no way to specify the network interface in this implementation. -int StartTcpServer(int *PortNumber, int *PortNumberPlatform); - +int StartTcpServer(int PortNumber, bool PickPorts); //*** ReadBytes() // This function reads the indicated number of bytes ('NumBytes') into buffer diff --git a/src/tpm2/TPMCmd/Simulator/src/TPMCmdp.c b/src/tpm2/TPMCmd/Simulator/src/TPMCmdp.c index 83dc6fcc..67401e0a 100644 --- a/src/tpm2/TPMCmd/Simulator/src/TPMCmdp.c +++ b/src/tpm2/TPMCmd/Simulator/src/TPMCmdp.c @@ -126,7 +126,7 @@ void _rpc__Signal_PowerOff(void) void _rpc__ForceFailureMode(void) { #if SIMULATION - SetForceFailureMode(); + _plat__SetForceFailureMode(); #endif return; } diff --git a/src/tpm2/TPMCmd/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h b/src/tpm2/TPMCmd/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h index 289a65c0..9bf1c129 100644 --- a/src/tpm2/TPMCmd/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h +++ b/src/tpm2/TPMCmd/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h @@ -79,10 +79,10 @@ #define CAMELLIA_192 (YES * ALG_CAMELLIA) /* since libtpms v0.10 stateFormatLevel 4 */ #define CAMELLIA_256 (YES * ALG_CAMELLIA) -#define ALG_TDES ALG_YES /* libtpms enabled */ +#define ALG_TDES ALG_YES /* libtpms added begin; enabled */ #define TDES_128 (ALG_TDES && YES) -#define TDES_192 (ALG_TDES && YES) +#define TDES_192 (ALG_TDES && YES) /* libtpms added end */ // must be yes if any above are yes. #define ALG_SYMCIPHER (ALG_AES || ALG_SM4 || ALG_CAMELLIA) @@ -152,7 +152,7 @@ #define ALG_SHA256 ALG_YES #define ALG_SHA256_192 ALG_NO #define ALG_SHA384 ALG_YES -#define ALG_SHA512 ALG_YES +#define ALG_SHA512 ALG_YES // libtpms: enabled #define ALG_SHA3_256 ALG_NO #define ALG_SHA3_384 ALG_NO @@ -271,6 +271,8 @@ //*********************************************** // Defines controlling secure channel functionality //*********************************************** +// This flag enables support for PolicyTransportSPDM. +// See CC_PolicyTransportSPDM. #define SEC_CHANNEL_SUPPORT NO // libtpms: NO #endif // _TPM_PROFILE_COMMON_H_ diff --git a/src/tpm2/TPMCmd/TpmConfiguration/TpmConfiguration/VendorCommands/VendorCommandList.h b/src/tpm2/TPMCmd/TpmConfiguration/TpmConfiguration/VendorCommands/VendorCommandList.h index b5ccc9a1..15cd8708 100644 --- a/src/tpm2/TPMCmd/TpmConfiguration/TpmConfiguration/VendorCommands/VendorCommandList.h +++ b/src/tpm2/TPMCmd/TpmConfiguration/TpmConfiguration/VendorCommands/VendorCommandList.h @@ -1,5 +1,9 @@ // SPDX-License-Identifier: BSD-2-Clause +// This file defines any Vendor command IDs, and must also define the +// VENDOR_COMMAND_ARRAY_COUNT which is consumed by the CoreLibrary. +// This file is included inside TpmProfile_CommandList.h and therefore +// has access to CC_YES and CC_NO for turning commands on and off. #ifndef _TPM_PROFILE_COMMAND_LIST_H_ # error This file should be included only within TpmProfile_CommandList.h diff --git a/src/tpm2/TPMCmd/tpm/cryptolibs/common/include/EccConstantData.inl b/src/tpm2/TPMCmd/tpm/cryptolibs/common/include/EccConstantData.inl index e444b66b..e5093dd3 100644 --- a/src/tpm2/TPMCmd/tpm/cryptolibs/common/include/EccConstantData.inl +++ b/src/tpm2/TPMCmd/tpm/cryptolibs/common/include/EccConstantData.inl @@ -58,40 +58,6 @@ /* */ /********************************************************************************/ -/* Microsoft Reference Implementation for TPM 2.0 - * - * The copyright in this software is being made available under the BSD License, - * included below. This software may be subject to other third party and - * contributor rights, including patent rights, and no such rights are granted - * under this license. - * - * Copyright (c) Microsoft Corporation - * - * All rights reserved. - * - * BSD License - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this list - * of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ // This file contains the ECC curve data. The data is contained in macros so this // file can be included in other format-specific header files that reformat the diff --git a/src/tpm2/TPMCmd/tpm/include/platform_interface/tpm_to_platform_interface.h b/src/tpm2/TPMCmd/tpm/include/platform_interface/tpm_to_platform_interface.h index 40bcd660..8f44de36 100644 --- a/src/tpm2/TPMCmd/tpm/include/platform_interface/tpm_to_platform_interface.h +++ b/src/tpm2/TPMCmd/tpm/include/platform_interface/tpm_to_platform_interface.h @@ -86,7 +86,7 @@ uint64_t ClockGetTime(clockid_t clk_id); // libtpms: added end //** From DebugHelpers.c - + #if CERTIFYX509_DEBUG #if 0 // libtpms: added diff --git a/src/tpm2/TPMCmd/tpm/include/private/CryptHash.h b/src/tpm2/TPMCmd/tpm/include/private/CryptHash.h index 69a71610..9e20e568 100644 --- a/src/tpm2/TPMCmd/tpm/include/private/CryptHash.h +++ b/src/tpm2/TPMCmd/tpm/include/private/CryptHash.h @@ -117,9 +117,9 @@ typedef union #if HASH_ALIGNMENT == 8 uint64_t align; #else -#if defined(__x86_64__) +#if defined(__x86_64__) // libtpms added begin # error Wrong HASH_ALIGNMENT -#endif +#endif // libtpms added end uint32_t align; #endif } ANY_HASH_STATE; diff --git a/src/tpm2/TPMCmd/tpm/include/private/CryptSym.h b/src/tpm2/TPMCmd/tpm/include/private/CryptSym.h index 31009eab..4cd6bb93 100644 --- a/src/tpm2/TPMCmd/tpm/include/private/CryptSym.h +++ b/src/tpm2/TPMCmd/tpm/include/private/CryptSym.h @@ -83,11 +83,11 @@ #else # define IF_IMPLEMENTED_CAMELLIA(op) #endif -#if ALG_TDES +#if ALG_TDES // libtpms added begin # define IF_IMPLEMENTED_TDES(op) op(TDES, tdes) #else # define IF_IMPLEMENTED_TDES(op) -#endif +#endif // libtpms added end #define FOR_EACH_SYM(op) \ IF_IMPLEMENTED_AES(op) \ @@ -112,9 +112,9 @@ typedef union tpmCryptKeySchedule_t { uint64_t alignment; #else uint32_t alignment; -# if defined(__x86_64__) +# if defined(__x86_64__) // libtpms added begin # error Bad SYMMETRIC_ALIGNMENT -# endif +# endif // libtpms added end #endif } tpmCryptKeySchedule_t; diff --git a/src/tpm2/TPMCmd/tpm/include/private/prototypes/CryptRsa_fp.h b/src/tpm2/TPMCmd/tpm/include/private/prototypes/CryptRsa_fp.h index e9f59c26..e1dd80b1 100644 --- a/src/tpm2/TPMCmd/tpm/include/private/prototypes/CryptRsa_fp.h +++ b/src/tpm2/TPMCmd/tpm/include/private/prototypes/CryptRsa_fp.h @@ -58,11 +58,6 @@ /* */ /********************************************************************************/ -/*(Auto-generated) - * Created by TpmPrototypes; Version 3.0 July 18, 2017 - * Date: Apr 2, 2019 Time: 03:18:00PM - */ - #ifndef _CRYPT_RSA_FP_H_ #define _CRYPT_RSA_FP_H_ diff --git a/src/tpm2/TPMCmd/tpm/include/tpm_public/GpMacros.h b/src/tpm2/TPMCmd/tpm/include/tpm_public/GpMacros.h index 38b361bd..1f316af9 100644 --- a/src/tpm2/TPMCmd/tpm/include/tpm_public/GpMacros.h +++ b/src/tpm2/TPMCmd/tpm/include/tpm_public/GpMacros.h @@ -362,8 +362,6 @@ goto Error; \ } while(0) -#include "MinMax.h" - #ifndef IsOdd # define IsOdd(a) (((a) & 1) != 0) #endif diff --git a/src/tpm2/TPMCmd/tpm/include/tpm_public/TpmTypes.h b/src/tpm2/TPMCmd/tpm/include/tpm_public/TpmTypes.h index c7958395..9decf058 100644 --- a/src/tpm2/TPMCmd/tpm/include/tpm_public/TpmTypes.h +++ b/src/tpm2/TPMCmd/tpm/include/tpm_public/TpmTypes.h @@ -993,6 +993,7 @@ typedef UINT32 TPMA_ALGORITHM; typedef UINT32 TPMA_OBJECT; #define TPMA_OBJECT_fixedTPM (TPMA_OBJECT)(1 << 1) #define TPMA_OBJECT_stClear (TPMA_OBJECT)(1 << 2) +#define TPMA_OBJECT_fixedFirmware (TPMA_OBJECT)(1 << 3) #define TPMA_OBJECT_fixedParent (TPMA_OBJECT)(1 << 4) #define TPMA_OBJECT_sensitiveDataOrigin (TPMA_OBJECT)(1 << 5) #define TPMA_OBJECT_userWithAuth (TPMA_OBJECT)(1 << 6) @@ -1778,7 +1779,7 @@ typedef struct TPM2B_AUTH hmac; } TPMS_AUTH_RESPONSE; -typedef TPM_KEY_BITS TPMI_TDES_KEY_BITS; +typedef TPM_KEY_BITS TPMI_TDES_KEY_BITS; // libtpms added typedef TPM_KEY_BITS TPMI_AES_KEY_BITS; // (Part 2: Structures) typedef TPM_KEY_BITS TPMI_SM4_KEY_BITS; // (Part 2: Structures) typedef TPM_KEY_BITS TPMI_CAMELLIA_KEY_BITS; // (Part 2: Structures) diff --git a/src/tpm2/TPMCmd/tpm/include/tpm_public/VerifyConfiguration.h b/src/tpm2/TPMCmd/tpm/include/tpm_public/VerifyConfiguration.h index e9f324a2..31e37986 100644 --- a/src/tpm2/TPMCmd/tpm/include/tpm_public/VerifyConfiguration.h +++ b/src/tpm2/TPMCmd/tpm/include/tpm_public/VerifyConfiguration.h @@ -95,4 +95,10 @@ MUST_BE_0_OR_1(VENDOR_PERMANENT_AUTH_ENABLED); # endif #endif +MUST_BE_0_OR_1(SEC_CHANNEL_SUPPORT); +MUST_BE_0_OR_1(CC_PolicyTransportSPDM); +#if SEC_CHANNEL_SUPPORT != CC_PolicyTransportSPDM +# error SEC_CHANNEL_SUPPORT and CC_PolicyTransportSPDM must have the same value +#endif + #endif // _VERIFY_CONFIGURATION_H diff --git a/src/tpm2/TPMCmd/tpm/include/tpm_public/tpm_debug.h b/src/tpm2/TPMCmd/tpm/include/tpm_public/tpm_debug.h index 00946389..3337e6d7 100644 --- a/src/tpm2/TPMCmd/tpm/include/tpm_public/tpm_debug.h +++ b/src/tpm2/TPMCmd/tpm/include/tpm_public/tpm_debug.h @@ -1,5 +1,6 @@ // SPDX-License-Identifier: BSD-2-Clause + #ifndef _TPM_DEBUG_H_ #define _TPM_DEBUG_H_ diff --git a/src/tpm2/TPMCmd/tpm/src/command/NVStorage/NV_ReadPublic2.c b/src/tpm2/TPMCmd/tpm/src/command/NVStorage/NV_ReadPublic2.c index b47b2613..1e0560e5 100644 --- a/src/tpm2/TPMCmd/tpm/src/command/NVStorage/NV_ReadPublic2.c +++ b/src/tpm2/TPMCmd/tpm/src/command/NVStorage/NV_ReadPublic2.c @@ -45,4 +45,3 @@ TPM2_NV_ReadPublic2(NV_ReadPublic2_In* in, // IN: input parameter list } #endif // CC_NV_ReadPublic2 - diff --git a/src/tpm2/TPMCmd/tpm/src/crypt/CryptSym.c b/src/tpm2/TPMCmd/tpm/src/crypt/CryptSym.c index 1a1dbf3c..dd3533a5 100644 --- a/src/tpm2/TPMCmd/tpm/src/crypt/CryptSym.c +++ b/src/tpm2/TPMCmd/tpm/src/crypt/CryptSym.c @@ -45,7 +45,6 @@ BOOL CryptSymStartup(void) // Return Type: INT16 // <= 0 cipher not supported // > 0 the cipher block size in bytes - LIB_EXPORT INT16 CryptGetSymmetricBlockSize( TPM_ALG_ID symmetricAlg, // IN: the symmetric algorithm UINT16 keySizeInBits // IN: the key size diff --git a/src/tpm2/TPMCmd/tpm/src/crypt/CryptUtil.c b/src/tpm2/TPMCmd/tpm/src/crypt/CryptUtil.c index a88e9882..ee29082a 100644 --- a/src/tpm2/TPMCmd/tpm/src/crypt/CryptUtil.c +++ b/src/tpm2/TPMCmd/tpm/src/crypt/CryptUtil.c @@ -1369,7 +1369,6 @@ BOOL CryptIsAsymSignScheme(TPMI_ALG_PUBLIC publicType, // IN: Type of the # endif switch(scheme) { - // Support for ECDSA is required for ECC case TPM_ALG_ECDSA: # if ALG_ECDAA // ECDAA is optional case TPM_ALG_ECDAA: diff --git a/src/tpm2/TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_ECDAA.c b/src/tpm2/TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_ECDAA.c index 7e6fadfc..db171ccf 100644 --- a/src/tpm2/TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_ECDAA.c +++ b/src/tpm2/TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_ECDAA.c @@ -136,7 +136,6 @@ TPM_RC TpmEcc_SignEcdaa( CryptDigestUpdate2B(&state, &digest->b); CryptHashEnd2B(&state, &T.b); TpmMath_IntFrom2B(bnT, &T.b); - // libtpms: Note: T is NOT a concern for constant-timeness // Watch out for the name collisions in this call!! retVal = TpmEcc_SchnorrCalculateS( bnS, diff --git a/src/tpm2/TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_Schnorr.c b/src/tpm2/TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_Schnorr.c index 9c673326..ffdca59a 100644 --- a/src/tpm2/TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_Schnorr.c +++ b/src/tpm2/TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_Schnorr.c @@ -148,7 +148,6 @@ TPM_RC TpmEcc_SignEcSchnorr( SchnorrReduce(e, order); // Convert hash to number TpmMath_IntFrom2B(bnR, e); - // libtpms: Note: e is NOT a concern for constant-timeness // Do the Schnorr computation retVal = TpmEcc_SchnorrCalculateS( bnS, bnK, bnR, bnD, ExtEcc_CurveGetOrder(ExtEcc_CurveGetCurveId(E))); diff --git a/src/tpm2/TPMCmd/tpm/src/subsystem/Session.c b/src/tpm2/TPMCmd/tpm/src/subsystem/Session.c index 1b45a364..f1330881 100644 --- a/src/tpm2/TPMCmd/tpm/src/subsystem/Session.c +++ b/src/tpm2/TPMCmd/tpm/src/subsystem/Session.c @@ -643,7 +643,7 @@ SessionContextLoad(SESSION_BUF* session, // IN: session structure from saved co break; // if no spot found, then this is an internal error - pAssert(slotIndex < MAX_LOADED_SESSIONS); + pAssert_RC(slotIndex < MAX_LOADED_SESSIONS); // libtpms: besides the s_freeSessionSlots guard add another array index guard if (slotIndex >= MAX_LOADED_SESSIONS) { // libtpms added begin; cppcheck diff --git a/src/tpm2/TPMCmd/tpm/src/support/PropertyCap.c b/src/tpm2/TPMCmd/tpm/src/support/PropertyCap.c index 2febd5fd..1a36751f 100644 --- a/src/tpm2/TPMCmd/tpm/src/support/PropertyCap.c +++ b/src/tpm2/TPMCmd/tpm/src/support/PropertyCap.c @@ -292,10 +292,7 @@ static BOOL TPMPropertyIsDefined(TPM_PT property, // IN: property case TPM_PT_TOTAL_COMMANDS: // total number of commands implemented in the TPM { -#if COMPRESSED_LISTS // libtpms changed begin - (*value) = RuntimeCommandsCountEnabled(&g_RuntimeProfile.RuntimeCommands); // libtpms changed: was COMMAND_COUNT -#else - COMMAND_INDEX commandIndex; + COMMAND_INDEX commandIndex; // libtpms changed begin *value = 0; // scan all implemented commands @@ -304,17 +301,13 @@ static BOOL TPMPropertyIsDefined(TPM_PT property, // IN: property commandIndex = GetNextCommandIndex(commandIndex)) { (*value)++; // count of all implemented - } -#endif // libtpms changed end + } // libtpms changed end break; } case TPM_PT_LIBRARY_COMMANDS: // number of commands from the TPM library that are implemented { -#if COMPRESSED_LISTS // libtpms changed begin - *value = RuntimeCommandsCountEnabled(&g_RuntimeProfile.RuntimeCommands); // libtpms changed: was LIBRARY_COMMAND_ARRAY_SIZE -#else - COMMAND_INDEX commandIndex; + COMMAND_INDEX commandIndex; // libtpms changed begin *value = 0; // scan all implemented commands @@ -323,8 +316,7 @@ static BOOL TPMPropertyIsDefined(TPM_PT property, // IN: property commandIndex = GetNextCommandIndex(commandIndex)) { (*value)++; - } -#endif // libtpms changed end + } // libtpms changed end break; } case TPM_PT_VENDOR_COMMANDS: