diff --git a/src/tpm2/AlgorithmTests.c b/src/tpm2/AlgorithmTests.c index d97ffcfc..a5814506 100644 --- a/src/tpm2/AlgorithmTests.c +++ b/src/tpm2/AlgorithmTests.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* Code to perform the various self-test functions. */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2024 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Introduction // This file contains the code to perform the various self-test functions. @@ -123,7 +65,7 @@ static TPM_RC TestHash(TPM_ALG_ID hashAlg, ALGORITHM_VECTOR* toTest) const TPM2B* testDigest = NULL; // TPM2B_TYPE(HMAC_BLOCK, DEFAULT_TEST_HASH_BLOCK_SIZE); - pAssert(hashAlg != TPM_ALG_NULL); + pAssert_RC(hashAlg != TPM_ALG_NULL); # define HASH_CASE_FOR_TEST(HASH, hash) \ case ALG_##HASH##_VALUE: \ testDigest = &c_##HASH##_digest.b; \ @@ -366,7 +308,7 @@ static TPM_RC TestSymmetric(TPM_ALG_ID alg, ALGORITHM_VECTOR* toTest) } } else - pAssert(alg == 0 && alg != 0); + pAssert_RC(alg == 0 && alg != 0); return TPM_RC_SUCCESS; } diff --git a/src/tpm2/Bits.c b/src/tpm2/Bits.c index 47bfeff3..d9561617 100644 --- a/src/tpm2/Bits.c +++ b/src/tpm2/Bits.c @@ -1,73 +1,10 @@ -/********************************************************************************/ -/* */ -/* Bit Manipulation Routines */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* $Id: Bits.c 1490 2019-07-26 21:13:22Z kgoldman $ */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2018 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Introduction // This file contains bit manipulation routines. They operate on bit arrays. // // The 0th bit in the array is the right-most bit in the 0th octet in // the array. -// -// NOTE: If pAssert() is defined, the functions will assert if the indicated bit -// number is outside of the range of 'bArray'. How the assert is handled is -// implementation dependent. //** Includes @@ -85,7 +22,8 @@ BOOL TestBit(unsigned int bitNum, // IN: number of the bit in 'bArray' unsigned int bytesInArray // IN: size in bytes of 'bArray' ) { - pAssert(bytesInArray > (bitNum >> 3)); + NOT_REFERENCED(bytesInArray); // if assertions are disabled. + pAssert_BOOL(bytesInArray > (bitNum >> 3)); return ((bArray[bitNum >> 3] & (1 << (bitNum & 7))) != 0); } @@ -96,7 +34,10 @@ void SetBit(unsigned int bitNum, // IN: number of the bit in 'bArray' unsigned int bytesInArray // IN: size in bytes of 'bArray' ) { - pAssert(bytesInArray > (bitNum >> 3)); + NOT_REFERENCED(bytesInArray); // if assertions are disabled. + // failure will get checked at the end of the command processing, which + // is soon enough for SetBit use cases. + pAssert_VOID_OK(bytesInArray > (bitNum >> 3)); bArray[bitNum >> 3] |= (1 << (bitNum & 7)); } @@ -107,6 +48,9 @@ void ClearBit(unsigned int bitNum, // IN: number of the bit in 'bArray'. unsigned int bytesInArray // IN: size in bytes of 'bArray' ) { - pAssert(bytesInArray > (bitNum >> 3)); + NOT_REFERENCED(bytesInArray); // if assertions are disabled. + // failure will get checked at the end of the command processing, which + // is soon enough for ClearBit use cases. (command auditing, self-test, etc.) + pAssert_VOID_OK(bytesInArray > (bitNum >> 3)); bArray[bitNum >> 3] &= ~(1 << (bitNum & 7)); } diff --git a/src/tpm2/CommandDispatcher.c b/src/tpm2/CommandDispatcher.c index de11158f..8b0ea4c4 100644 --- a/src/tpm2/CommandDispatcher.c +++ b/src/tpm2/CommandDispatcher.c @@ -111,12 +111,12 @@ ParseHandleBuffer(COMMAND* command) BYTE dType; // Make sure that nothing strange has happened - pAssert( + pAssert_RC( command->index < sizeof(s_CommandDataArray) / sizeof(COMMAND_DESCRIPTOR_t*)); // Get the address of the descriptor for this command desc = s_CommandDataArray[command->index]; - pAssert(desc != NULL); + pAssert_RC(desc != NULL); // Get the associated list of unmarshaling data types. types = &((BYTE*)desc)[desc->typesOffset]; @@ -199,12 +199,12 @@ CommandDispatcher(COMMAND* command) TPM_RC result; // // Get the address of the descriptor for this command - pAssert( + pAssert_RC( command->index < sizeof(s_CommandDataArray) / sizeof(COMMAND_DESCRIPTOR_t*)); desc = s_CommandDataArray[command->index]; // Get the list of parameter types for this command - pAssert(desc != NULL); + pAssert_RC(desc != NULL); types = &((BYTE*)desc)[desc->typesOffset]; // Get a pointer to the list of parameter offsets diff --git a/src/tpm2/Context_spt.c b/src/tpm2/Context_spt.c index 963d9f88..9107a25e 100644 --- a/src/tpm2/Context_spt.c +++ b/src/tpm2/Context_spt.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* Context Management Command Support */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2023 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Includes @@ -140,11 +82,11 @@ TPM_RC ComputeContextProtectionKey(TPMS_CONTEXT* contextBlob, // IN: context b MemorySet(proof.b.buffer, 0, proof.b.size); // Copy part of the returned value as the key - pAssert(symKey->t.size <= sizeof(symKey->t.buffer)); + pAssert_RC(symKey->t.size <= sizeof(symKey->t.buffer)); MemoryCopy(symKey->t.buffer, kdfResult, symKey->t.size); // Copy the rest as the IV - pAssert(iv->t.size <= sizeof(iv->t.buffer)); + pAssert_RC(iv->t.size <= sizeof(iv->t.buffer)); MemoryCopy(iv->t.buffer, &kdfResult[symKey->t.size], iv->t.size); return TPM_RC_SUCCESS; diff --git a/src/tpm2/CryptSelfTest.c b/src/tpm2/CryptSelfTest.c index d20831aa..525aadbf 100644 --- a/src/tpm2/CryptSelfTest.c +++ b/src/tpm2/CryptSelfTest.c @@ -151,7 +151,7 @@ CryptIncrementalSelfTest(TPML_ALG* toTest, // IN: list of algorithms to be tes TPM_ALG_ID alg; UINT32 i; - pAssert(toTest != NULL && toDoList != NULL); + pAssert_RC(toTest != NULL && toDoList != NULL); if(toTest->count > 0) { // Transcribe the toTest list into the toTestVector diff --git a/src/tpm2/CryptUtil.c b/src/tpm2/CryptUtil.c index f5f30df9..7f52cdcd 100644 --- a/src/tpm2/CryptUtil.c +++ b/src/tpm2/CryptUtil.c @@ -1222,6 +1222,8 @@ CryptCreateObject(OBJECT* object, // IN: new object structure po DRBG_AdditionalData((DRBG_STATE*)rand, &gp.shProof.b); DRBG_AdditionalData((DRBG_STATE*)rand, &gp.ehProof.b); } + VERIFY_NOT_FAILED(); + // Generate a seedValue that is the size of the digest produced by nameAlg sensitive->seedValue.t.size = DRBG_Generate(rand, diff --git a/src/tpm2/Entity.c b/src/tpm2/Entity.c index 89aa441b..e0660692 100644 --- a/src/tpm2/Entity.c +++ b/src/tpm2/Entity.c @@ -232,7 +232,7 @@ EntityGetAuthValue(TPMI_DH_ENTITY handle, // IN: handle of entity // Authorization is available only when the private portion of // the object is loaded. The check should be made before // this function is called - pAssert(object->attributes.publicOnly == CLEAR); + pAssert_ZERO(object && object->attributes.publicOnly == CLEAR); pAuth = &object->sensitive.authValue; } } diff --git a/src/tpm2/ExecCommand.c b/src/tpm2/ExecCommand.c index bf8c63dd..94342566 100644 --- a/src/tpm2/ExecCommand.c +++ b/src/tpm2/ExecCommand.c @@ -50,11 +50,9 @@ // // 'request' and 'response' may point to the same buffer // -// Note: As of February, 2016, the failure processing has been moved to the +// Note: The failure processing has been moved to the // platform-specific code. When the TPM code encounters an unrecoverable failure, it -// will SET g_inFailureMode and call _plat__Fail(). That function should not return -// but may call ExecuteCommand(). -// +// will call _plat__Fail() and call _plat__InFailureMode() to query failure mode. LIB_EXPORT void ExecuteCommand( uint32_t requestSize, // IN: command buffer size unsigned char* request, // IN: command buffer @@ -306,7 +304,7 @@ Cleanup: FAIL(FATAL_ERROR_INTERNAL); g_updateNV = UT_NONE; } - pAssert((UINT32)command.parameterSize <= maxResponse); + pAssert_NORET((UINT32)command.parameterSize <= maxResponse); // Clear unused bits in response buffer. MemorySet(*response + *responseSize, 0, maxResponse - *responseSize); diff --git a/src/tpm2/Handle.c b/src/tpm2/Handle.c index 46041719..12246c25 100644 --- a/src/tpm2/Handle.c +++ b/src/tpm2/Handle.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* fUnctions that return the type of a handle. */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2023 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Description // This file contains the functions that return the type of a handle. @@ -159,7 +101,7 @@ PermanentCapGetHandles(TPM_HANDLE handle, // IN: start handle TPMI_YES_NO more = NO; UINT32 i; - pAssert(HandleGetType(handle) == TPM_HT_PERMANENT); + VERIFY(HandleGetType(handle) == TPM_HT_PERMANENT, FATAL_ERROR_ASSERT, NO); // Initialize output handle list handleList->count = 0; @@ -195,7 +137,7 @@ BOOL PermanentCapGetOneHandle(TPM_HANDLE handle) // IN: handle { UINT32 i; - pAssert(HandleGetType(handle) == TPM_HT_PERMANENT); + pAssert_BOOL(HandleGetType(handle) == TPM_HT_PERMANENT); // Iterate permanent handle range for(i = NextPermanentHandle(handle); i != 0; i = NextPermanentHandle(i + 1)) @@ -223,7 +165,7 @@ PermanentHandleGetPolicy(TPM_HANDLE handle, // IN: start handle { TPMI_YES_NO more = NO; - pAssert(HandleGetType(handle) == TPM_HT_PERMANENT); + VERIFY(HandleGetType(handle) == TPM_HT_PERMANENT, FATAL_ERROR_ASSERT, NO); // Initialize output handle list policyList->count = 0; @@ -270,7 +212,7 @@ BOOL PermanentHandleGetOnePolicy(TPM_HANDLE handle, // IN: handle TPMS_TAGGED_POLICY* policy // OUT: tagged policy ) { - pAssert(HandleGetType(handle) == TPM_HT_PERMANENT); + pAssert_BOOL(HandleGetType(handle) == TPM_HT_PERMANENT); if(NextPermanentHandle(handle) == handle) { diff --git a/src/tpm2/IoBuffers.c b/src/tpm2/IoBuffers.c index f9de0ef0..17e152dd 100644 --- a/src/tpm2/IoBuffers.c +++ b/src/tpm2/IoBuffers.c @@ -1,63 +1,4 @@ -/********************************************************************************/ -/* */ -/* I/O Buffers */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* $Id: IoBuffers.c 1311 2018-08-23 21:39:29Z kgoldman $ */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2018 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Includes and Data Definitions @@ -99,7 +40,7 @@ BYTE* MemoryGetInBuffer(UINT32 size // Size, in bytes, required for the input // unmarshaling ) { - pAssert(size <= sizeof(s_actionIoBuffer)); + pAssert_NULL(size <= sizeof(s_actionIoBuffer)); // In this implementation, a static buffer is set aside for the command action // buffers. The buffer is shared between input and output. This is because // there is no need to allocate for the worst case input and worst case output @@ -119,7 +60,7 @@ BYTE* MemoryGetOutBuffer(UINT32 size // required size of the buffer ) { BYTE* retVal = (BYTE*)(&s_actionIoBuffer[s_actionIoAllocation / UoM]); - pAssert((size + s_actionIoAllocation) < (sizeof(s_actionIoBuffer))); + pAssert_NULL((size + s_actionIoAllocation) < (sizeof(s_actionIoBuffer))); // In this implementation, a static buffer is set aside for the command action // output buffer. memset(retVal, 0, size); diff --git a/src/tpm2/Locality.c b/src/tpm2/Locality.c index f9cf2354..88ba47ca 100644 --- a/src/tpm2/Locality.c +++ b/src/tpm2/Locality.c @@ -1,63 +1,4 @@ -/********************************************************************************/ -/* */ -/* */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* $Id: Locality.c 1490 2019-07-26 21:13:22Z kgoldman $ */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016, 2017 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Includes #include "Tpm.h" @@ -93,7 +34,7 @@ LocalityGetAttributes(UINT8 locality // IN: locality value SET_ATTRIBUTE(locality_attributes, TPMA_LOCALITY, TPM_LOC_FOUR); break; default: - pAssert(locality > 31); + VERIFY(locality > 31, FATAL_ERROR_ASSERT, 0); *localityAsByte = locality; break; } diff --git a/src/tpm2/Manufacture.c b/src/tpm2/Manufacture.c index c5cab8f9..527e64a5 100644 --- a/src/tpm2/Manufacture.c +++ b/src/tpm2/Manufacture.c @@ -59,7 +59,7 @@ LIB_EXPORT int TPM_Manufacture( // trigger failure mode if called in error. int nvReadyState = _plat__GetNvReadyState(); - pAssert(nvReadyState == NV_READY); // else failure mode + pAssert_NORET(nvReadyState == NV_READY); // else failure mode if(nvReadyState != NV_READY) { return MANUF_NV_NOT_READY; diff --git a/src/tpm2/Memory.c b/src/tpm2/Memory.c index 7b15026a..9ade6c61 100644 --- a/src/tpm2/Memory.c +++ b/src/tpm2/Memory.c @@ -1,63 +1,4 @@ -/********************************************************************************/ -/* */ -/* Miscellaneous Memory Manipulation Routines */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* $Id: Memory.c 1658 2021-01-22 23:14:01Z kgoldman $ */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2021 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Description // This file contains a set of miscellaneous memory manipulation routines. Many @@ -116,12 +57,12 @@ LIB_EXPORT INT16 MemoryCopy2B(TPM2B* dest, // OUT: receiving TPM2B unsigned int dSize // IN: size of the receiving buffer ) { - pAssert(dest != NULL); - if(source == NULL) - dest->size = 0; - else + pAssert_ZERO(dest != NULL); + dest->size = 0; + if(source != NULL) { - pAssert(source->size <= dSize); + NOT_REFERENCED(dSize); // if pAsserts compiled out. + pAssert_ZERO(source->size <= dSize); MemoryCopy(dest->buffer, source->buffer, source->size); dest->size = source->size; } @@ -139,7 +80,9 @@ void MemoryConcat2B( // aInOut.size) ) { - pAssert(bIn->size <= aMaxSize - aInOut->size); + NOT_REFERENCED(aMaxSize); // if pAsserts compiled out. + // if won't fit, enter failure mode and return unchanged. + pAssert_VOID_OK(bIn->size <= aMaxSize - aInOut->size); MemoryCopy(&aInOut->buffer[aInOut->size], &bIn->buffer, bIn->size); aInOut->size = aInOut->size + bIn->size; return; diff --git a/src/tpm2/NVMarshal.c b/src/tpm2/NVMarshal.c index 1356c259..6e195b27 100644 --- a/src/tpm2/NVMarshal.c +++ b/src/tpm2/NVMarshal.c @@ -142,7 +142,7 @@ static void block_skip_write_pop(block_skip_t *bs, INT32 *size) { UINT16 skip; unsigned i = --bs->idx; - pAssert((int)bs->idx >= 0); + pAssert_VOID_OK((int)bs->idx >= 0); skip = bs->pos[i].size - *size - sizeof(UINT16); UINT16_Marshal(&skip, &bs->pos[i].buffer, &bs->pos[i].size); } diff --git a/src/tpm2/NvDynamic.c b/src/tpm2/NvDynamic.c index 117c9ccc..a73513b6 100644 --- a/src/tpm2/NvDynamic.c +++ b/src/tpm2/NvDynamic.c @@ -605,11 +605,11 @@ static void NvObjectFromBuffer(OBJECT* object, BYTE* buf, UINT32 buf_size) */ rc = ANY_OBJECT_Unmarshal(object, &buffer, &size, false); if (!rc) { - pAssert(size == 0); + pAssert_VOID_OK(size == 0); } else { /* It could not be unmarshalled, it must be a plain RSA3072_OBJECT */ rc = RSA3072_OBJECT_Buffer_To_OBJECT(object, buf, buf_size); - pAssert(rc == TPM_RC_SUCCESS); + pAssert_VOID_OK(rc == TPM_RC_SUCCESS); } } // libtpms added end @@ -632,7 +632,7 @@ void NvReadObject(NV_REF ref, // IN: points to NV where index is located entrysize -= sizeof(NV_ENTRY_HEADER); /* read the flat object into a buffer */ - pAssert(entrysize <= sizeof(buffer)); + pAssert_VOID_OK(entrysize <= sizeof(buffer)); NvRead(buffer, ref + sizeof(TPM_HANDLE), entrysize); NvObjectFromBuffer(object, buffer, entrysize); diff --git a/src/tpm2/NvReserved.c b/src/tpm2/NvReserved.c index 2ad65bac..dcda9188 100644 --- a/src/tpm2/NvReserved.c +++ b/src/tpm2/NvReserved.c @@ -155,8 +155,10 @@ void NvRead(void* outBuffer, // OUT: buffer to receive data UINT32 size // IN: size of the value to read ) { - // Input type should be valid - pAssert(nvOffset + size < NV_MEMORY_SIZE); + // Input addresses must be inside the memory buffer. + // void is OK because we simply skip the read, which is the only reasonable + // response. + pAssert_VOID_OK(nvOffset + size < NV_MEMORY_SIZE); _plat__NvMemoryRead(nvOffset, size, outBuffer); return; } @@ -186,7 +188,12 @@ void NvUpdatePersistent( void* buffer // IN: the new data ) { - pAssert(offset + size <= sizeof(gp)); + // Input addresses must be inside the memory buffer. Any callers using the + // expected CLEAR_PERSISTENT macro should encounter a build error before + // tripping this assert so void is reasonable as a defense in depth against + // a manual caller of this function. Skipping the write is the only + // reasonable response. + pAssert_VOID_OK(offset + size <= sizeof(gp)); MemoryCopy(&gp + offset, buffer, size); NvWrite(offset, size, buffer); } @@ -198,7 +205,12 @@ void NvClearPersistent(UINT32 offset, // IN: the offset in the PERMANENT_DATA UINT32 size // IN: number of bytes to clear ) { - pAssert(offset + size <= sizeof(gp)); + // Input addresses must be inside the memory buffer. Any callers using the + // expected CLEAR_PERSISTENT macro should encounter a build error before + // tripping this assert so void is reasonable as a defense in depth against + // a manual caller of this function. Skipping the write is the only + // reasonable response. + pAssert_VOID_OK(offset + size <= sizeof(gp)); MemorySet((&gp) + offset, 0, size); NvWrite(offset, size, (&gp) + offset); } diff --git a/src/tpm2/Object.c b/src/tpm2/Object.c index 7763804d..480df734 100644 --- a/src/tpm2/Object.c +++ b/src/tpm2/Object.c @@ -99,7 +99,7 @@ BOOL IsObjectPresent(TPMI_DH_OBJECT handle // IN: handle to be checked BOOL ObjectIsSequence(OBJECT* object // IN: handle to be checked ) { - pAssert(object != NULL); + pAssert_BOOL(object != NULL); return (object->attributes.hmacSeq == SET || object->attributes.hashSeq == SET || object->attributes.eventSeq == SET); } @@ -120,9 +120,16 @@ OBJECT* HandleToObject(TPMI_DH_OBJECT handle // IN: handle of the object return NULL; // In this implementation, the handle is determined by the slot occupied by the // object. + // this can be an underflow if TPM_Init hasn't happened or the usual handle + // checks are skipped. Enter failure mode on this unexpected condition + if(handle < TRANSIENT_FIRST) + { + FAIL_NULL(FATAL_ERROR_ASSERT); + } + index = handle - TRANSIENT_FIRST; - pAssert(index < MAX_LOADED_OBJECTS); - pAssert(s_objects[index].attributes.occupied); + pAssert_NULL(index < MAX_LOADED_OBJECTS); + pAssert_NULL(s_objects[index].attributes.occupied); return &s_objects[index]; } @@ -324,7 +331,7 @@ ObjectLoad(OBJECT* object, // IN: pointer to object slot TPM_RC result = TPM_RC_SUCCESS; // // Do validations of public area object descriptions - pAssert(publicArea != NULL); + pAssert_RC(publicArea != NULL); // Is this public only or a no-name object? if(sensitive == NULL || publicArea->nameAlg == TPM_ALG_NULL) @@ -637,12 +644,13 @@ ObjectContextLoadLibtpms(BYTE *buffer, // This function frees an object slot. // // This function requires that the object is loaded. +// returns FALSE and enters failure mode if the handle is invalid. BOOL FlushObject(TPMI_DH_OBJECT handle // IN: handle to be freed ) { UINT32 index = handle - TRANSIENT_FIRST; - // - pAssert(index < MAX_LOADED_OBJECTS); + // checks for underflow due to unsigned math + pAssert_BOOL(index < MAX_LOADED_OBJECTS); // Clear all the object attributes MemorySet((BYTE*)&(s_objects[index].attributes), 0, sizeof(OBJECT_ATTRIBUTES)); return TRUE; @@ -859,8 +867,8 @@ ObjectCapGetLoaded(TPMI_DH_OBJECT handle, // IN: start handle { TPMI_YES_NO more = NO; UINT32 i; - // - pAssert(HandleGetType(handle) == TPM_HT_TRANSIENT); + // enter failure mode and stop iterating if we encounter an internal error + VERIFY(HandleGetType(handle) == TPM_HT_TRANSIENT, FATAL_ERROR_INTERNAL, NO); // Initialize output handle list handleList->count = 0; @@ -875,7 +883,7 @@ ObjectCapGetLoaded(TPMI_DH_OBJECT handle, // IN: start handle if(s_objects[i].attributes.occupied == TRUE) { // A valid transient object can not be the copy of a persistent object - pAssert(s_objects[i].attributes.evict == CLEAR); + VERIFY(s_objects[i].attributes.evict == CLEAR, FATAL_ERROR_INTERNAL, NO); if(handleList->count < count) { @@ -903,7 +911,7 @@ BOOL ObjectCapGetOneLoaded(TPMI_DH_OBJECT handle) // IN: handle { UINT32 i; - pAssert(HandleGetType(handle) == TPM_HT_TRANSIENT); + pAssert_BOOL(HandleGetType(handle) == TPM_HT_TRANSIENT); // Iterate object slots to get loaded object handles for(i = handle - TRANSIENT_FIRST; i < MAX_LOADED_OBJECTS; i++) @@ -911,7 +919,7 @@ BOOL ObjectCapGetOneLoaded(TPMI_DH_OBJECT handle) // IN: handle if(s_objects[i].attributes.occupied == TRUE) { // A valid transient object can not be the copy of a persistent object - pAssert(s_objects[i].attributes.evict == CLEAR); + pAssert_BOOL(s_objects[i].attributes.evict == CLEAR); return TRUE; } diff --git a/src/tpm2/Object_spt.c b/src/tpm2/Object_spt.c index 3fc22324..f267758a 100644 --- a/src/tpm2/Object_spt.c +++ b/src/tpm2/Object_spt.c @@ -531,7 +531,7 @@ SchemeChecks(OBJECT* parentObject, // IN: parent (null if primary seed) curveID = publicArea->parameters.eccDetail.curveID; curveScheme = CryptGetCurveSignScheme(curveID); // The curveId must be valid or the unmarshaling is busted. - pAssert(curveScheme != NULL); + pAssert_RC(curveScheme != NULL); // If the curveID requires a specific scheme, then the key must // select the same scheme @@ -1018,7 +1018,7 @@ UnwrapOuter(OBJECT* protector, // IN: The object that provides // This function is used to marshal a sensitive area. Among other things, it // adjusts the size of the authValue to be no smaller than the digest of // 'nameAlg' -// Returns the size of the marshaled area. +// Returns the size of the marshaled area. 0 indicates an error static UINT16 MarshalSensitive( OBJECT* parent LIBTPMS_ATTR_UNUSED, // IN: the object parent (optional) BYTE* buffer, // OUT: receiving buffer @@ -1039,6 +1039,7 @@ static UINT16 MarshalSensitive( // If the sensitive size is the special case for a prime in the type if((sensitive->sensitive.rsa.t.size & RSA_prime_flag) > 0) { + pAssert_ZERO(sensitive->sensitiveType == ALG_RSA_VALUE); UINT16 sizeSave = sensitive->sensitive.rsa.t.size; // // Turn off the flag that indicates that the sensitive->sensitive contains @@ -1057,7 +1058,9 @@ static UINT16 MarshalSensitive( } else #endif + { retVal = TPMT_SENSITIVE_Marshal(sensitive, &buffer, NULL); + } // Marshal the size retVal = (UINT16)(retVal + UINT16_Marshal(&retVal, &sizeField, NULL)); @@ -1118,6 +1121,7 @@ TPM_RC SensitiveToPrivate( // Marshal the sensitive area including authValue size adjustments. dataSize = MarshalSensitive(parent, sensitiveData, sensitive, nameAlg); + pAssert_RC(dataSize != 0); // 0 indicates a failure mode assertion //Produce outer wrap, including encryption and HMAC outPrivate->t.size = ProduceOuterWrap( @@ -1167,7 +1171,7 @@ PrivateToSensitive(TPM2B* inPrivate, // IN: input private structure UINT16 ivSize; // // Make sure that name is provided - pAssert(name != NULL && name->size != 0); + pAssert_RC(name != NULL && name->size != 0); // Find the hash algorithm for integrity computation // For Temporary Object (parent == NULL) use self name algorithm; @@ -1373,10 +1377,10 @@ DuplicateToSensitive( UINT16 dataSizeInput; // // Make sure that name is provided - pAssert(name != NULL && name->size != 0); + pAssert_RC(name != NULL && name->size != 0); // Make sure symDef and innerSymKey are not NULL - pAssert(symDef != NULL && innerSymKey != NULL); + pAssert_RC(symDef != NULL && innerSymKey != NULL); // Starting of sensitive data sensitiveData = inPrivate->buffer; @@ -1400,7 +1404,7 @@ DuplicateToSensitive( if(symDef->algorithm != TPM_ALG_NULL) { // assume the input key size matches the symmetric definition - pAssert(innerSymKey->size == (symDef->keyBits.sym + 7) / 8); + pAssert_RC(innerSymKey->size == (symDef->keyBits.sym + 7) / 8); // Decrypt inner buffer in place CryptSymmetricDecrypt(sensitiveData, diff --git a/src/tpm2/PCR.c b/src/tpm2/PCR.c index 152e748d..9b8f9b55 100644 --- a/src/tpm2/PCR.c +++ b/src/tpm2/PCR.c @@ -914,7 +914,7 @@ PCRAllocate(TPML_PCR_SELECTION* allocate, // IN: required allocation } } // The j loop must exit with a match. - pAssert(j < newAllocate.count); + pAssert_RC(j < newAllocate.count); } // Max PCR in a bank is MIN(implemented PCR, PCR with attributes defined) @@ -1252,7 +1252,7 @@ PCRCapGetHandles(TPMI_DH_PCR handle, // IN: start handle TPMI_YES_NO more = NO; UINT32 i; - pAssert(HandleGetType(handle) == TPM_HT_PCR); + VERIFY(HandleGetType(handle) == TPM_HT_PCR, FATAL_ERROR_INTERNAL, NO); // Initialize output handle list handleList->count = 0; @@ -1286,7 +1286,7 @@ PCRCapGetHandles(TPMI_DH_PCR handle, // IN: start handle // This function is used to check whether a PCR handle exists. BOOL PCRCapGetOneHandle(TPMI_DH_PCR handle) // IN: handle { - pAssert(HandleGetType(handle) == TPM_HT_PCR); + pAssert_BOOL(HandleGetType(handle) == TPM_HT_PCR); if((handle & HR_HANDLE_MASK) <= PCR_LAST) { diff --git a/src/tpm2/PolicyTransportSPDM.c b/src/tpm2/PolicyTransportSPDM.c index c0733b2f..e51aa48d 100644 --- a/src/tpm2/PolicyTransportSPDM.c +++ b/src/tpm2/PolicyTransportSPDM.c @@ -27,7 +27,6 @@ TPM2_PolicyTransportSPDM(PolicyTransportSPDM_In* in // IN: input parameter list // Get pointer to the session structure session = SessionGet(in->policySession); - pAssert_RC(session); // Check that TPM2_PolicyTransportSPDM has not previously been executed if(session->attributes.checkSecureChannel == SET) diff --git a/src/tpm2/Session.c b/src/tpm2/Session.c index b3e7d47c..1b45a364 100644 --- a/src/tpm2/Session.c +++ b/src/tpm2/Session.c @@ -112,8 +112,8 @@ static void ContextIdSetOldest(void) CONTEXT_SLOT entry; CONTEXT_SLOT smallest = CONTEXT_SLOT_MASKED(~0); // libtpms changed UINT32 i; - pAssert(s_ContextSlotMask == 0xff || s_ContextSlotMask == 0xffff); // libtpms added + pAssert_VOID_OK(s_ContextSlotMask == 0xff || s_ContextSlotMask == 0xffff); // libtpms added // Set oldestSaveContext to a value indicating none assigned s_oldestSavedSession = MAX_ACTIVE_SESSIONS + 1; lowBits = CONTEXT_SLOT_MASKED(gr.contextCounter); // libtpms changed @@ -207,8 +207,8 @@ BOOL SessionStartup(STARTUP_TYPE type) BOOL SessionIsLoaded(TPM_HANDLE handle // IN: session handle ) { - pAssert(HandleGetType(handle) == TPM_HT_POLICY_SESSION - || HandleGetType(handle) == TPM_HT_HMAC_SESSION); + pAssert_BOOL(HandleGetType(handle) == TPM_HT_POLICY_SESSION + || HandleGetType(handle) == TPM_HT_HMAC_SESSION); handle = handle & HR_HANDLE_MASK; @@ -236,8 +236,8 @@ BOOL SessionIsLoaded(TPM_HANDLE handle // IN: session handle BOOL SessionIsSaved(TPM_HANDLE handle // IN: session handle ) { - pAssert(HandleGetType(handle) == TPM_HT_POLICY_SESSION - || HandleGetType(handle) == TPM_HT_HMAC_SESSION); + pAssert_BOOL(HandleGetType(handle) == TPM_HT_POLICY_SESSION + || HandleGetType(handle) == TPM_HT_HMAC_SESSION); handle = handle & HR_HANDLE_MASK; // if out of range of possible active session, or not assigned, or @@ -350,7 +350,7 @@ static TPM_RC ContextIdSessionCreate( // be occupied by the created session ) { - pAssert(sessionIndex < MAX_LOADED_SESSIONS); + pAssert_RC(sessionIndex < MAX_LOADED_SESSIONS); // check to see if creating the context is safe // Is this going to be an assignment for the last session context @@ -410,8 +410,8 @@ SessionCreate(TPM_SE sessionType, // IN: the session type CONTEXT_SLOT slotIndex; SESSION* session = NULL; - pAssert(sessionType == TPM_SE_HMAC || sessionType == TPM_SE_POLICY - || sessionType == TPM_SE_TRIAL); + pAssert_RC(sessionType == TPM_SE_HMAC || sessionType == TPM_SE_POLICY + || sessionType == TPM_SE_TRIAL); // If there are no open spots in the session array, then no point in searching if(s_freeSessionSlots == 0) @@ -496,7 +496,7 @@ SessionCreate(TPM_SE sessionType, // IN: the session type // Get authValue of associated entity EntityGetAuthValue(bind, (TPM2B_AUTH*)&key); - pAssert((size_t)key.t.size + seed->t.size <= sizeof(key.t.buffer)); + pAssert_RC((size_t)(key.t.size + seed->t.size) <= sizeof(key.t.buffer)); // Concatenate authValue and seed MemoryConcat2B(&key.b, &seed->b, sizeof(key.t.buffer)); @@ -552,7 +552,7 @@ SessionContextSave(TPM_HANDLE handle, // IN: session handle UINT32 contextIndex; CONTEXT_SLOT slotIndex; - pAssert(SessionIsLoaded(handle)); + pAssert_RC(SessionIsLoaded(handle)); pAssert(s_ContextSlotMask == 0xff || s_ContextSlotMask == 0xffff); // libtpms added // check to see if the gap is already maxed out @@ -568,7 +568,7 @@ SessionContextSave(TPM_HANDLE handle, // IN: session handle *contextID = gr.contextCounter; contextIndex = handle & HR_HANDLE_MASK; - pAssert(contextIndex < MAX_ACTIVE_SESSIONS); + pAssert_RC(contextIndex < MAX_ACTIVE_SESSIONS); // Extract the session slot number referenced by the contextArray // because we are going to overwrite this with the low order @@ -630,8 +630,8 @@ SessionContextLoad(SESSION_BUF* session, // IN: session structure from saved co CONTEXT_SLOT slotIndex; pAssert(s_ContextSlotMask == 0xff || s_ContextSlotMask == 0xffff); // libtpms added - pAssert(HandleGetType(*handle) == TPM_HT_POLICY_SESSION - || HandleGetType(*handle) == TPM_HT_HMAC_SESSION); + pAssert_RC(HandleGetType(*handle) == TPM_HT_POLICY_SESSION + || HandleGetType(*handle) == TPM_HT_HMAC_SESSION); // Don't bother looking if no openings if(s_freeSessionSlots == 0) @@ -660,7 +660,7 @@ SessionContextLoad(SESSION_BUF* session, // IN: session structure from saved co && contextIndex != s_oldestSavedSession) return TPM_RC_CONTEXT_GAP; - pAssert(contextIndex < MAX_ACTIVE_SESSIONS); + pAssert_RC(contextIndex < MAX_ACTIVE_SESSIONS); // set the contextArray value to point to the session slot where // the context is loaded @@ -695,15 +695,16 @@ void SessionFlush(TPM_HANDLE handle // IN: loaded or saved session handle CONTEXT_SLOT slotIndex; UINT32 contextIndex; // Index into contextArray - pAssert((HandleGetType(handle) == TPM_HT_POLICY_SESSION - || HandleGetType(handle) == TPM_HT_HMAC_SESSION) - && (SessionIsLoaded(handle) || SessionIsSaved(handle))); + pAssert_VOID_OK((HandleGetType(handle) == TPM_HT_POLICY_SESSION + || HandleGetType(handle) == TPM_HT_HMAC_SESSION) + && (SessionIsLoaded(handle) || SessionIsSaved(handle))); // Flush context ID of this session // Convert handle to an index into the contextArray contextIndex = handle & HR_HANDLE_MASK; - pAssert(contextIndex < sizeof(gr.contextArray) / sizeof(gr.contextArray[0])); + pAssert_VOID_OK( + contextIndex < sizeof(gr.contextArray) / sizeof(gr.contextArray[0])); // Get the current contents of the array slotIndex = gr.contextArray[contextIndex]; @@ -787,7 +788,7 @@ void SessionResetPolicyData(SESSION* session // IN: the session to reset ) { SESSION_ATTRIBUTES oldAttributes; - pAssert(session != NULL); + pAssert_VOID_OK(session != NULL); // Will need later oldAttributes = session->attributes; @@ -840,7 +841,7 @@ SessionCapGetLoaded(TPMI_SH_POLICY handle, // IN: start handle TPMI_YES_NO more = NO; UINT32 i; - pAssert(HandleGetType(handle) == TPM_HT_LOADED_SESSION); + VERIFY(HandleGetType(handle) == TPM_HT_LOADED_SESSION, FATAL_ERROR_ASSERT, NO); // Initialize output handle list handleList->count = 0; @@ -867,6 +868,7 @@ SessionCapGetLoaded(TPMI_SH_POLICY handle, // IN: start handle // assume that this is going to be an HMAC session handle = i + HMAC_SESSION_FIRST; session = SessionGet(handle); + VERIFY(session != NULL, FATAL_ERROR_ASSERT, NO); if(session->attributes.isPolicy) handle = i + POLICY_SESSION_FIRST; handleList->handle[handleList->count] = handle; @@ -890,7 +892,7 @@ SessionCapGetLoaded(TPMI_SH_POLICY handle, // IN: start handle // This function returns whether a session handle exists and is loaded. BOOL SessionCapGetOneLoaded(TPMI_SH_POLICY handle) // IN: handle { - pAssert(HandleGetType(handle) == TPM_HT_LOADED_SESSION); + pAssert_BOOL(HandleGetType(handle) == TPM_HT_LOADED_SESSION); if((handle & HR_HANDLE_MASK) < MAX_ACTIVE_SESSIONS && gr.contextArray[(handle & HR_HANDLE_MASK)]) @@ -963,7 +965,7 @@ SessionCapGetSaved(TPMI_SH_HMAC handle, // IN: start handle // This function returns whether a session handle exists and is saved. BOOL SessionCapGetOneSaved(TPMI_SH_HMAC handle) // IN: handle { - pAssert(HandleGetType(handle) == TPM_HT_SAVED_SESSION); + pAssert_BOOL(HandleGetType(handle) == TPM_HT_SAVED_SESSION); if((handle & HR_HANDLE_MASK) < MAX_ACTIVE_SESSIONS && gr.contextArray[(handle & HR_HANDLE_MASK)]) diff --git a/src/tpm2/SessionProcess.c b/src/tpm2/SessionProcess.c index 81e6e3ba..bd44a2b1 100644 --- a/src/tpm2/SessionProcess.c +++ b/src/tpm2/SessionProcess.c @@ -298,7 +298,7 @@ static BOOL IsAuthValueAvailable(TPM_HANDLE handle, // IN: handle of e OBJECT* object; TPMA_OBJECT attributes; // - object = HandleToObject(handle); + object = HandleToObject(handle); pAssert_BOOL(object != NULL); attributes = object->publicArea.objectAttributes; @@ -482,7 +482,6 @@ static BOOL IsAuthPolicyAvailable(TPM_HANDLE handle, // IN: handle of default: break; } - return result; } @@ -598,7 +597,7 @@ static TPM2B_DIGEST* GetCpHash(COMMAND* command, TPMI_ALG_HASH hashAlg) { TPM2B_DIGEST* cpHash = GetCpHashPointer(command, hashAlg); // - pAssert(cpHash->t.size != 0); + pAssert_NULL(cpHash && cpHash->t.size != 0); return cpHash; } @@ -1413,7 +1412,7 @@ static TPM_RC CheckAuthSession( TPM_HT sessionHandleType = HandleGetType(sessionHandle); BOOL authUsed; // - pAssert(sessionHandle != TPM_RH_UNASSIGNED); + pAssert_RC(sessionHandle != TPM_RH_UNASSIGNED); // Take care of physical presence if(associatedHandle == TPM_RH_PLATFORM) @@ -1503,7 +1502,7 @@ static TPM_RC CheckAuthSession( NV_PIN pinData; TPMA_NV nvAttributes; // - pAssert(nvIndex != NULL); + pAssert_RC(nvIndex != NULL); nvAttributes = nvIndex->publicArea.attributes; // If this is a PIN FAIL index and the value has been written // then we can update the counter (increment or clear) @@ -1708,7 +1707,8 @@ ParseSessionBuffer(COMMAND* command // IN: the structure that contains { extraKey.b.size = 0; } - size = DecryptSize(command->index); + size = DecryptSize(command->index); + pAssert_RC(command->parameterSize <= INT32_MAX); result = CryptParameterDecryption(s_sessionHandles[s_decryptSessionIndex], &s_nonceCaller[s_decryptSessionIndex].b, command->parameterSize, @@ -1825,7 +1825,7 @@ static void UpdateAuditDigest( TPM2B_DIGEST* cpHash = GetCpHash(command, hashAlg); TPM2B_DIGEST* rpHash = ComputeRpHash(command, hashAlg); // - pAssert(cpHash != NULL); + pAssert_VOID_OK(cpHash != NULL); // digestNew := hash (digestOld || cpHash || rpHash) // Start hash computation. @@ -2082,7 +2082,6 @@ static TPM2B_NONCE* BuildSingleResponseAuth( SESSION* session = SessionGet(s_sessionHandles[sessionIndex]); pAssert_NULL(session != NULL); - // // If the session is a policy session with isPasswordNeeded SET, the // authorization field is empty. if(HandleGetType(s_sessionHandles[sessionIndex]) == TPM_HT_POLICY_SESSION @@ -2133,7 +2132,7 @@ BuildResponseSession(COMMAND* command // IN: structure that has relevant comman { TPM_RC result = TPM_RC_SUCCESS; - pAssert(command->authSize == 0); + pAssert_RC(command->authSize == 0); // Reset the parameter buffer to point to the start of the parameters so that // there is a starting point for any rpHash that might be generated and so there @@ -2144,6 +2143,7 @@ BuildResponseSession(COMMAND* command // IN: structure that has relevant comman if(command->tag == TPM_ST_SESSIONS) { UpdateAllNonceTPM(command); + VERIFY_NOT_FAILED(); // Encrypt first parameter if applicable. Parameter encryption should // happen after nonce update and before any rpHash is computed. @@ -2166,6 +2166,7 @@ BuildResponseSession(COMMAND* command // IN: structure that has relevant comman &extraKey); } size = EncryptSize(command->index); + pAssert_RC(command->parameterSize <= INT32_MAX); // This function operates on internally-generated data that is // expected to be well-formed for parameter encryption. // In the event that there is a bug elsewhere in the code and the @@ -2188,6 +2189,7 @@ BuildResponseSession(COMMAND* command // IN: structure that has relevant comman // Audit sessions should be processed regardless of the tag because // a command with no session may cause a change of the exclusivity state. UpdateAuditSessionStatus(command); + VERIFY_NOT_FAILED(); #if CC_GetCommandAuditDigest // Command Audit if(CommandAuditIsRequired(command->index)) @@ -2198,7 +2200,7 @@ BuildResponseSession(COMMAND* command // IN: structure that has relevant comman { UINT32 i; // - pAssert(command->sessionNum > 0); + pAssert_RC(command->sessionNum > 0); // Iterate over each session in the command session area, and create // corresponding sessions for response. @@ -2229,7 +2231,10 @@ BuildResponseSession(COMMAND* command // IN: structure that has relevant comman command->authSize += TPM2B_DIGEST_Marshal(&responseAuth, &command->responseBuffer, NULL); if(!IS_ATTRIBUTE(s_attributes[i], TPMA_SESSION, continueSession)) + { SessionFlush(s_sessionHandles[i]); + VERIFY_NOT_FAILED(); + } } } diff --git a/src/tpm2/Time.c b/src/tpm2/Time.c index a80a8596..4061bb2d 100644 --- a/src/tpm2/Time.c +++ b/src/tpm2/Time.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* Functions relating to the TPM's time functions */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2023 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Introduction // This file contains the functions relating to the TPM's time functions including @@ -133,7 +75,7 @@ void TimeClockUpdate(UINT64 newTime // IN: New time value in mS. // Check to see if the update will cause a need for an nvClock update if((newTime | CLOCK_UPDATE_MASK) > (go.clock | CLOCK_UPDATE_MASK)) { - pAssert(g_NvStatus == TPM_RC_SUCCESS); + pAssert_VOID_OK(g_NvStatus == TPM_RC_SUCCESS); // Going to update the NV time state so SET the safe flag go.clockSafe = YES; diff --git a/src/tpm2/TpmASN1.c b/src/tpm2/TpmASN1.c index bc150138..aaa6e2da 100644 --- a/src/tpm2/TpmASN1.c +++ b/src/tpm2/TpmASN1.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* TPM ASN.1 */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2019 - 2023 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Includes #include "Tpm.h" @@ -275,7 +217,7 @@ void ASN1InitialializeMarshalContext( // that was previously placed in the structure. void ASN1StartMarshalContext(ASN1MarshalContext* ctx) { - pAssert((ctx->depth + 1) < MAX_DEPTH); + pAssert_VOID_OK((ctx->depth + 1) < MAX_DEPTH); ctx->depth++; ctx->ends[ctx->depth] = ctx->end; ctx->end = ctx->offset; @@ -290,7 +232,7 @@ INT16 ASN1EndMarshalContext(ASN1MarshalContext* ctx) { INT16 length; - pAssert(ctx->depth >= 0); + pAssert_ZERO(ctx->depth >= 0); length = ctx->end - ctx->offset; ctx->end = ctx->ends[ctx->depth--]; return length; diff --git a/src/tpm2/TpmEcc_Signature_SM2.c b/src/tpm2/TpmEcc_Signature_SM2.c index d3ea93d7..1d6ddf1a 100644 --- a/src/tpm2/TpmEcc_Signature_SM2.c +++ b/src/tpm2/TpmEcc_Signature_SM2.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2023 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause #include "Tpm.h" #include "TpmEcc_Signature_SM2_fp.h" @@ -151,9 +93,9 @@ loop: ExtMath_Add(bnR, bnE, ExtEcc_PointX(Q1)); ExtMath_Mod(bnR, order); # ifdef _SM2_SIGN_DEBUG - pAssert(TpmEccDebug_HexEqual(bnR, - "40F1EC59F793D9F49E09DCEF49130D41" - "94F79FB1EED2CAA55BACDB49C4E755D1")); + pAssert_RC(TpmEccDebug_HexEqual(bnR, + "40F1EC59F793D9F49E09DCEF49130D41" + "94F79FB1EED2CAA55BACDB49C4E755D1")); # endif // if r=0 or r+k=n, return to A3; if(ExtMath_IsZero(bnR)) @@ -167,9 +109,9 @@ loop: ExtMath_AddWord(bnT, bnD, 1); ExtMath_ModInverse(bnT, bnT, order); # ifdef _SM2_SIGN_DEBUG - pAssert(TpmEccDebug_HexEqual(bnT, - "79BFCF3052C80DA7B939E0C6914A18CB" - "B2D96D8555256E83122743A7D4F5F956")); + pAssert_RC(TpmEccDebug_HexEqual(bnT, + "79BFCF3052C80DA7B939E0C6914A18CB" + "B2D96D8555256E83122743A7D4F5F956")); # endif // compute s = t * (k - r * dA) mod n ExtMath_ModMult(bnS, bnR, bnD, order); @@ -178,9 +120,9 @@ loop: ExtMath_Add(bnS, bnK, bnS); ExtMath_ModMult(bnS, bnS, bnT, order); # ifdef _SM2_SIGN_DEBUG - pAssert(TpmEccDebug_HexEqual(bnS, - "6FC6DAC32C5D5CF10C77DFB20F7C2EB6" - "67A457872FB09EC56327A67EC7DEEBE7")); + pAssert_RC(TpmEccDebug_HexEqual(bnS, + "6FC6DAC32C5D5CF10C77DFB20F7C2EB6" + "67A457872FB09EC56327A67EC7DEEBE7")); # endif if(ExtMath_IsZero(bnS)) goto loop; @@ -190,12 +132,12 @@ loop: // is (r, s). // This is handled by the common return code # ifdef _SM2_SIGN_DEBUG - pAssert(TpmEccDebug_HexEqual(bnR, - "40F1EC59F793D9F49E09DCEF49130D41" - "94F79FB1EED2CAA55BACDB49C4E755D1")); - pAssert(TpmEccDebug_HexEqual(bnS, - "6FC6DAC32C5D5CF10C77DFB20F7C2EB6" - "67A457872FB09EC56327A67EC7DEEBE7")); + pAssert_RC(TpmEccDebug_HexEqual(bnR, + "40F1EC59F793D9F49E09DCEF49130D41" + "94F79FB1EED2CAA55BACDB49C4E755D1")); + pAssert_RC(TpmEccDebug_HexEqual(bnS, + "6FC6DAC32C5D5CF10C77DFB20F7C2EB6" + "67A457872FB09EC56327A67EC7DEEBE7")); # endif return TPM_RC_SUCCESS; } @@ -227,20 +169,20 @@ TPM_RC TpmEcc_ValidateSignatureEcSm2( # ifdef _SM2_SIGN_DEBUG // Make sure that the input signature is the test signature - pAssert(TpmEccDebug_HexEqual(bnR, - "40F1EC59F793D9F49E09DCEF49130D41" - "94F79FB1EED2CAA55BACDB49C4E755D1")); - pAssert(TpmEccDebug_HexEqual(bnS, - "6FC6DAC32C5D5CF10C77DFB20F7C2EB6" - "67A457872FB09EC56327A67EC7DEEBE7")); + pAssert_RC(TpmEccDebug_HexEqual(bnR, + "40F1EC59F793D9F49E09DCEF49130D41" + "94F79FB1EED2CAA55BACDB49C4E755D1")); + pAssert_RC(TpmEccDebug_HexEqual(bnS, + "6FC6DAC32C5D5CF10C77DFB20F7C2EB6" + "67A457872FB09EC56327A67EC7DEEBE7")); # endif // b) compute t := (r + s) mod n ExtMath_Add(bnT, bnR, bnS); ExtMath_Mod(bnT, order); # ifdef _SM2_SIGN_DEBUG - pAssert(TpmEccDebug_HexEqual(bnT, - "2B75F07ED7ECE7CCC1C8986B991F441A" - "D324D6D619FE06DD63ED32E0C997C801")); + pAssert_RC(TpmEccDebug_HexEqual(bnT, + "2B75F07ED7ECE7CCC1C8986B991F441A" + "D324D6D619FE06DD63ED32E0C997C801")); # endif // c) verify that t > 0 OK = !ExtMath_IsZero(bnT); @@ -251,10 +193,10 @@ TPM_RC TpmEcc_ValidateSignatureEcSm2( // d) compute (x, y) := [s]G + [t]Q OK = ExtEcc_PointMultiplyAndAdd(P, NULL, bnS, ecQ, bnT, E); # ifdef _SM2_SIGN_DEBUG - pAssert(OK - && TpmEccDebug_HexEqual(ExtEcc_PointX(P), - "110FCDA57615705D5E7B9324AC4B856D" - "23E6D9188B2AE47759514657CE25D112")); + pAssert_RC(OK + && TpmEccDebug_HexEqual(ExtEcc_PointX(P), + "110FCDA57615705D5E7B9324AC4B856D" + "23E6D9188B2AE47759514657CE25D112")); # endif // e) compute r' := (e + x) mod n (the x coordinate is in bnT) OK = OK && ExtMath_Add(bnRp, bnE, ExtEcc_PointX(P)); diff --git a/src/tpm2/TpmEcc_Util.c b/src/tpm2/TpmEcc_Util.c index d60f3c7a..6e51eb5d 100644 --- a/src/tpm2/TpmEcc_Util.c +++ b/src/tpm2/TpmEcc_Util.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2023 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Introduction // This file contains utility functions to help using the external Math library @@ -109,7 +51,7 @@ LIB_EXPORT BOOL TpmEcc_PointTo2B( const Crypt_EccCurve* E // IN: curve descriptor for the point ) { - pAssert(p && ecP && E); + pAssert_BOOL(p && ecP && E); TPM_ECC_CURVE curveId = ExtEcc_CurveGetCurveId(E); NUMBYTES size = CryptEccGetKeySizeForCurve(curveId); size = (UINT16)BITS_TO_BYTES(size); diff --git a/src/tpm2/X509_spt.c b/src/tpm2/X509_spt.c index 1db7eddd..fe78af0a 100644 --- a/src/tpm2/X509_spt.c +++ b/src/tpm2/X509_spt.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* X509 Support */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG rants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2019 - 2024 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Includes #include "Tpm.h" @@ -93,7 +35,7 @@ BOOL X509FindExtensionByOID(ASN1UnmarshalContext* ctxIn, // IN: the context to { INT16 length; // - pAssert(ctxIn != NULL); + pAssert_BOOL(ctxIn != NULL); // Make the search non-destructive of the input if ctx provided. Otherwise, use // the provided context. if(ctx == NULL) diff --git a/src/tpm2/crypto/openssl/CryptCmac.c b/src/tpm2/crypto/openssl/CryptCmac.c index f60dbf15..ec87b561 100644 --- a/src/tpm2/crypto/openssl/CryptCmac.c +++ b/src/tpm2/crypto/openssl/CryptCmac.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* Message Authentication Codes Based on a Symmetric Block Cipher */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2018 - 2023 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Introduction // @@ -124,7 +66,7 @@ void CryptCmacData(SMAC_STATES* state, UINT32 size, const BYTE* buffer) { FOR_EACH_SYM(ENCRYPT_CASE) default: - FAIL(FATAL_ERROR_INTERNAL); + FAIL_VOID(FATAL_ERROR_INTERNAL); } while(size > 0) { @@ -175,9 +117,10 @@ CryptCmacEnd(SMAC_STATES* state, UINT32 outSize, BYTE* outBuffer) xorVal = ((subkey.t.buffer[0] & 0x80) == 0) ? 0 : 0x87; ShiftLeft(&subkey.b); subkey.t.buffer[subkey.t.size - 1] ^= xorVal; + // this is a sanity check to make sure that the algorithm is working properly. - // remove this check when debug is done - pAssert(cState->bcount <= cState->iv.t.size); + pAssert_ZERO(cState->bcount <= cState->iv.t.size); + // If the buffer is full then no need to compute subkey 2. if(cState->bcount < cState->iv.t.size) { diff --git a/src/tpm2/crypto/openssl/CryptEccKeyExchange.c b/src/tpm2/crypto/openssl/CryptEccKeyExchange.c index 090e825e..c25cba48 100644 --- a/src/tpm2/crypto/openssl/CryptEccKeyExchange.c +++ b/src/tpm2/crypto/openssl/CryptEccKeyExchange.c @@ -74,7 +74,7 @@ static TPM_RC C_2_2_MQV(TPMS_ECC_POINT* outZ, // OUT: the computed point // Parameter checks if(E == NULL) ERROR_EXIT(TPM_RC_VALUE); - pAssert( + pAssert_RC( outZ != NULL && pQeB != NULL && pQsB != NULL && deA != NULL && dsA != NULL); // Process: // 1. implicitsigA = (de,A + avf(Qe,A)ds,A ) mod n. @@ -159,7 +159,7 @@ static TPM_RC C_2_2_ECDH(TPMS_ECC_POINT* outZs, // OUT: Zs // Parameter checks if(E == NULL) ERROR_EXIT(TPM_RC_CURVE); - pAssert( + pAssert_RC( outZs != NULL && dsA != NULL && deA != NULL && QsB != NULL && QeB != NULL); // Do the point multiply for the Zs value ([dsA]QsB) @@ -194,7 +194,7 @@ LIB_EXPORT TPM_RC CryptEcc2PhaseKeyExchange( TPMS_ECC_POINT* QeB // IN: ephemeral public party B key ) { - pAssert( + pAssert_RC( outZ1 != NULL && dsA != NULL && deA != NULL && QsB != NULL && QeB != NULL); // Initialize the output points so that they are empty until one of the @@ -300,7 +300,8 @@ LIB_EXPORT TPM_RC SM2KeyExchange( // Parameter checks if(E == NULL) ERROR_EXIT(TPM_RC_CURVE); - pAssert(outZ != NULL && dsA != NULL && deA != NULL && QsB != NULL && QeB != NULL); + pAssert_RC( + outZ != NULL && dsA != NULL && deA != NULL && QsB != NULL && QeB != NULL); // Compute the value for w w = ComputeWForSM2(curveId); diff --git a/src/tpm2/crypto/openssl/CryptEccMain.c b/src/tpm2/crypto/openssl/CryptEccMain.c index ef84d935..f73f8afa 100644 --- a/src/tpm2/crypto/openssl/CryptEccMain.c +++ b/src/tpm2/crypto/openssl/CryptEccMain.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* ECC Main */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2024 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Includes and Defines #include "Tpm.h" @@ -64,6 +6,7 @@ #include "TpmEcc_Util_fp.h" #include "TpmEcc_Signature_ECDSA_fp.h" // required for pairwise test in key generation #include "Helpers_fp.h" // libtpms added + #if ALG_ECC //** Functions @@ -588,6 +531,7 @@ BOOL TpmEcc_GenerateKeyPair(Crypt_Int* bnD, // OUT: private scalar // Do a point multiply OK = OK && ExtEcc_PointMultiply(ecQ, NULL, bnD, E); + return OK; } @@ -715,6 +659,7 @@ LIB_EXPORT TPM_RC CryptEccPointMultiply( TpmEcc_PointTo2B(Rout, ecR, E); else ClearPoint2B(Rout); + CRYPT_CURVE_FREE(E); return retVal; } @@ -736,7 +681,7 @@ LIB_EXPORT BOOL CryptEccIsPointOnCurve( CRYPT_POINT_INITIALIZED(ecQ, Qin); BOOL OK; // - pAssert(Qin != NULL); + pAssert_BOOL(Qin != NULL); OK = (E != NULL && (ExtEcc_IsPointOnCurve(ecQ, E))); CRYPT_CURVE_FREE(E); // libtpms added return OK; diff --git a/src/tpm2/crypto/openssl/CryptEccSignature.c b/src/tpm2/crypto/openssl/CryptEccSignature.c index 39509951..4d9da51a 100644 --- a/src/tpm2/crypto/openssl/CryptEccSignature.c +++ b/src/tpm2/crypto/openssl/CryptEccSignature.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* ECC Signatures */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2024 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Includes and Defines #include "Tpm.h" @@ -227,7 +169,7 @@ LIB_EXPORT TPM_RC CryptEccValidateSignature( break; # endif default: - FAIL(FATAL_ERROR_INTERNAL); + FAIL_RC(FATAL_ERROR_INTERNAL); } Exit: CRYPT_CURVE_FREE(E); @@ -270,7 +212,7 @@ LIB_EXPORT TPM_RC CryptEccCommitCompute( // Validate that the required parameters are provided. // Note: E has to be provided if computing E := [r]Q or E := [r]M. Will do // E := [r]Q if both M and B are NULL. - pAssert(r != NULL && E != NULL); + pAssert_RC(r != NULL && E != NULL); // Initialize the output points in case they are not computed ClearPoint2B(K); @@ -278,7 +220,7 @@ LIB_EXPORT TPM_RC CryptEccCommitCompute( ClearPoint2B(E); // Sizes of the r parameter may not be zero - pAssert(r->t.size > 0); + pAssert_RC(r->t.size > 0); // If B is provided, compute K=[d]B and L=[r]B if(B != NULL) @@ -288,7 +230,7 @@ LIB_EXPORT TPM_RC CryptEccCommitCompute( CRYPT_POINT_VAR(pK); CRYPT_POINT_VAR(pL); // - pAssert(d != NULL && K != NULL && L != NULL); + pAssert_RC(d != NULL && K != NULL && L != NULL); if (!curve) // libtpms added ERROR_EXIT(TPM_RC_NO_RESULT); // libtpms added @@ -318,7 +260,7 @@ LIB_EXPORT TPM_RC CryptEccCommitCompute( CRYPT_POINT_VAR(pE); // // Make sure that a place was provided for the result - pAssert(E != NULL); + pAssert_RC(E != NULL); // if this is the third point multiply, check for cancel first if((B != NULL) && _plat__IsCanceled()) diff --git a/src/tpm2/crypto/openssl/CryptHash.c b/src/tpm2/crypto/openssl/CryptHash.c index 20f259cf..952ed3a6 100644 --- a/src/tpm2/crypto/openssl/CryptHash.c +++ b/src/tpm2/crypto/openssl/CryptHash.c @@ -358,7 +358,14 @@ void CryptDigestUpdate(PHASH_STATE hashState, // IN: the hash context informati &hashState->state.smac.state, dataSize, data); #endif // SMAC_IMPLEMENTED else - FAIL(FATAL_ERROR_INTERNAL); + { + // this void assert is OK because these values only indicate the + // intention of the hash, but don't actually affect the hash + // calculation or buffer size calculations. IOW, the failure + // set here can safely percolate out and be checked at a higher + // level. + FAIL_VOID(FATAL_ERROR_INTERNAL); + } } return; } @@ -376,7 +383,7 @@ LIB_EXPORT UINT16 CryptHashEnd(PHASH_STATE hashState, // IN: the state of hash BYTE* dOut // OUT: hash digest ) { - pAssert(hashState->type == HASH_STATE_HASH); + pAssert_ZERO(hashState->type == HASH_STATE_HASH); return HashEnd(hashState, dOutSize, dOut); } @@ -414,7 +421,10 @@ LIB_EXPORT void CryptDigestUpdate2B(PHASH_STATE state, // IN: the digest state // In CryptDigestUpdate(), if size is zero or buffer is NULL, then no change // to the digest occurs. This function should not provide a buffer if bIn is // not provided. - pAssert(bIn != NULL); + // as indicated by the comment above CryptDigestUpdate is tolerant of null, but + // we don't expect a null pointer here, so simply return but trigger failure + // mode because this is an unexpected internal programming error. + pAssert_VOID_OK(bIn != NULL); CryptDigestUpdate(state, bIn->size, bIn->buffer); return; } @@ -537,7 +547,7 @@ LIB_EXPORT UINT16 CryptHmacEnd(PHMAC_STATE state, // IN: the hash state buff return (state->hashState.state.smac.smacMethods.end)( &state->hashState.state.smac.state, dOutSize, dOut); #endif - pAssert(hState->type == HASH_STATE_HMAC); + pAssert_ZERO(hState->type == HASH_STATE_HMAC); hState->def = CryptGetHashDef(hState->hashAlg); // Change the state type for completion processing hState->type = HASH_STATE_HASH; @@ -682,7 +692,7 @@ LIB_EXPORT UINT16 CryptKDFa( HMAC_STATE hState; UINT16 digestSize = CryptHashGetDigestSize(hashAlg); - pAssert(key != NULL && keyStream != NULL); + pAssert_ZERO(key != NULL && keyStream != NULL); TPM_DO_SELF_TEST(TPM_ALG_KDF1_SP800_108); @@ -694,7 +704,7 @@ LIB_EXPORT UINT16 CryptKDFa( // If the size of the request is larger than the numbers will handle, // it is a fatal error. - pAssert(((sizeInBits + 7) / 8) <= INT16_MAX); + pAssert_ZERO(((sizeInBits + 7) / 8) <= INT16_MAX); // The number of bytes to be generated is the smaller of the sizeInBits bytes or // the number of requested blocks. The number of blocks is the smaller of the @@ -776,7 +786,8 @@ LIB_EXPORT UINT16 CryptKDFe(TPM_ALG_ID hashAlg, // IN: hash algorithm used in BYTE* stream = keyStream; INT16 bytes; // number of bytes to generate - pAssert(keyStream != NULL && Z != NULL && ((sizeInBits + 7) / 8) < INT16_MAX); + pAssert_ZERO( + keyStream != NULL && Z != NULL && ((sizeInBits + 7) / 8) < INT16_MAX); // hLen = hashDef->digestSize; bytes = (INT16)((sizeInBits + 7) / 8); diff --git a/src/tpm2/crypto/openssl/CryptPrime.c b/src/tpm2/crypto/openssl/CryptPrime.c index e2087343..1d68f5db 100644 --- a/src/tpm2/crypto/openssl/CryptPrime.c +++ b/src/tpm2/crypto/openssl/CryptPrime.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* Code for prime validation. */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2023 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-Clause //** Introduction // This file contains the code for prime validation. @@ -470,9 +412,9 @@ TPM_RC TpmRsa_GeneratePrimeForRSA( BOOL found = FALSE; // // Make sure that the prime is large enough - pAssert(prime->allocated >= BITS_TO_CRYPT_WORDS(bits)); + pAssert_RC(prime->allocated >= BITS_TO_CRYPT_WORDS(bits)); // Only try to handle specific sizes of keys in order to save overhead - pAssert((bits % 32) == 0); + pAssert_RC((bits % 32) == 0); prime->size = BITS_TO_CRYPT_WORDS(bits); diff --git a/src/tpm2/crypto/openssl/CryptRand.c b/src/tpm2/crypto/openssl/CryptRand.c index 73a722d3..d60460b8 100644 --- a/src/tpm2/crypto/openssl/CryptRand.c +++ b/src/tpm2/crypto/openssl/CryptRand.c @@ -179,7 +179,8 @@ static void DfUpdate(PDF_STATE dfState, int size, const BYTE* data) data += toFill; // increase the buffer contents count by the amount copied dfState->contents += toFill; - pAssert(dfState->contents <= DRBG_IV_SIZE_BYTES); + // error will eventually get handled + pAssert_VOID_OK(dfState->contents <= DRBG_IV_SIZE_BYTES); // If we have a full buffer, do a computation pass. if(dfState->contents == DRBG_IV_SIZE_BYTES) DfCompute(dfState); @@ -253,7 +254,7 @@ BOOL DRBG_GetEntropy(UINT32 requiredEntropy, // IN: requested number of bytes o { // In self-test, the caller should be asking for exactly the seed // size of entropy. - pAssert(requiredEntropy == sizeof(DRBG_NistTestVector_Entropy)); + pAssert_BOOL(requiredEntropy == sizeof(DRBG_NistTestVector_Entropy)); memcpy(entropy, DRBG_NistTestVector_Entropy, sizeof(DRBG_NistTestVector_Entropy)); @@ -388,7 +389,7 @@ static BOOL DRBG_Update( memset(&localKeySchedule, 0, sizeof(localKeySchedule)); /* libtpms added: coverity */ // - pAssert(drbgState->magic == DRBG_MAGIC); + pAssert_BOOL(drbgState->magic == DRBG_MAGIC); // If an key schedule was not provided, make one if(keySchedule == NULL) @@ -428,7 +429,7 @@ BOOL DRBG_Reseed(DRBG_STATE* drbgState, // IN: the state to update { DRBG_SEED seed; - pAssert((drbgState != NULL) && (drbgState->magic == DRBG_MAGIC)); + pAssert_BOOL((drbgState != NULL) && (drbgState->magic == DRBG_MAGIC)); if(providedEntropy == NULL) { @@ -465,7 +466,7 @@ BOOL DRBG_SelfTest(void) BYTE* p; DRBG_STATE testState; // - pAssert(!IsSelfTest()); + pAssert_BOOL(!IsSelfTest()); // no recursion SetSelfTest(); SetDrbgTested(); @@ -546,7 +547,7 @@ LIB_EXPORT TPM_RC CryptRandomStir(UINT16 additionalDataSize, BYTE* additionalDat &tmpBuf, DfBuffer(&dfResult, additionalDataSize, additionalData)); drbgDefault.reseedCounter = 1; - + VERIFY_NOT_FAILED(); return TPM_RC_SUCCESS; #else @@ -671,7 +672,7 @@ LIB_EXPORT TPM_RC DRBG_InstantiateSeeded( // Used the derivation function output as the "entropy" input. This is not // how it is described in SP800-90A but this is the equivalent function DRBG_Reseed(((DRBG_STATE*)drbgState), DfEnd(&dfState), NULL); - + VERIFY_NOT_FAILED(); return TPM_RC_SUCCESS; } @@ -901,7 +902,8 @@ LIB_EXPORT BOOL DRBG_Instantiate( DRBG_SEED seed; DRBG_SEED dfResult; // - pAssert((pSize == 0) || (pSize <= sizeof(seed)) || (personalization != NULL)); + pAssert_BOOL( + (pSize == 0) || (pSize <= sizeof(seed)) || (personalization != NULL)); // If the DRBG has not been tested, test when doing an instantiation. Since // Instantiation is called during self test, make sure we don't get stuck in a // loop. @@ -920,6 +922,7 @@ LIB_EXPORT BOOL DRBG_Instantiate( // and do a reseed. DRBG_Reseed(drbgState, &seed, DfBuffer(&dfResult, pSize, personalization)); + VERIFY(!g_inFailureMode, FATAL_ERROR_ENTROPY, TPM_RC_FAILURE); return TRUE; } diff --git a/src/tpm2/crypto/openssl/CryptSym.c b/src/tpm2/crypto/openssl/CryptSym.c index 70d52f28..9564627e 100644 --- a/src/tpm2/crypto/openssl/CryptSym.c +++ b/src/tpm2/crypto/openssl/CryptSym.c @@ -1,62 +1,4 @@ -/********************************************************************************/ -/* */ -/* Symmetric block cipher modes */ -/* Written by Ken Goldman */ -/* IBM Thomas J. Watson Research Center */ -/* */ -/* Licenses and Notices */ -/* */ -/* 1. Copyright Licenses: */ -/* */ -/* - Trusted Computing Group (TCG) grants to the user of the source code in */ -/* this specification (the "Source Code") a worldwide, irrevocable, */ -/* nonexclusive, royalty free, copyright license to reproduce, create */ -/* derivative works, distribute, display and perform the Source Code and */ -/* derivative works thereof, and to grant others the rights granted herein. */ -/* */ -/* - The TCG grants to the user of the other parts of the specification */ -/* (other than the Source Code) the rights to reproduce, distribute, */ -/* display, and perform the specification solely for the purpose of */ -/* developing products based on such documents. */ -/* */ -/* 2. Source Code Distribution Conditions: */ -/* */ -/* - Redistributions of Source Code must retain the above copyright licenses, */ -/* this list of conditions and the following disclaimers. */ -/* */ -/* - Redistributions in binary form must reproduce the above copyright */ -/* licenses, this list of conditions and the following disclaimers in the */ -/* documentation and/or other materials provided with the distribution. */ -/* */ -/* 3. Disclaimers: */ -/* */ -/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ -/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ -/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ -/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ -/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ -/* information on specification licensing rights available through TCG */ -/* membership agreements. */ -/* */ -/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ -/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ -/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ -/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ -/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ -/* */ -/* - Without limitation, TCG and its members and licensors disclaim all */ -/* liability, including liability for infringement of any proprietary */ -/* rights, relating to use of information in this specification and to the */ -/* implementation of this specification, and TCG disclaims all liability for */ -/* cost of procurement of substitute goods or services, lost profits, loss */ -/* of use, loss of data or any incidental, consequential, direct, indirect, */ -/* or special damages, whether under contract, tort, warranty or otherwise, */ -/* arising in any way out of use or reliance upon this specification or any */ -/* information herein. */ -/* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2024 */ -/* */ -/********************************************************************************/ +// SPDX-License-Identifier: BSD-2-clause //** Introduction // @@ -177,7 +119,7 @@ LIB_EXPORT TPM_RC CryptSymmetricEncrypt( BYTE* iv; BYTE defaultIv[MAX_SYM_BLOCK_SIZE] = {0}; // - pAssert(dOut != NULL && key != NULL && dIn != NULL); + pAssert_RC(dOut != NULL && key != NULL && dIn != NULL); memset((void *)&keySchedule, 0, sizeof(keySchedule)); /* silence false positive; coverity */ memset(tmp, 0, sizeof(tmp)); if(dSize == 0) @@ -342,7 +284,7 @@ LIB_EXPORT TPM_RC CryptSymmetricDecrypt( encrypt = NULL; decrypt = NULL; - pAssert(dOut != NULL && key != NULL && dIn != NULL); + pAssert_RC(dOut != NULL && key != NULL && dIn != NULL); if(dSize == 0) return TPM_RC_SUCCESS; @@ -565,7 +507,7 @@ CryptSymmetricEncrypt( UINT16 keyToUseLen = (UINT16)sizeof(keyToUse); TPM_RC retVal = TPM_RC_SUCCESS; - pAssert(dOut != NULL && key != NULL && dIn != NULL); + pAssert_RC(dOut != NULL && key != NULL && dIn != NULL); if(dSize == 0) return TPM_RC_SUCCESS; TPM_DO_SELF_TEST(algorithm); @@ -623,7 +565,7 @@ CryptSymmetricEncrypt( EVP_EncryptUpdate(ctx, pOut, &outlen1, dIn, dSize) != 1) ERROR_EXIT(TPM_RC_FAILURE); - pAssert(outlen1 <= dSize || dSize >= outlen1 + blockSize); + pAssert_RC(outlen1 <= dSize || dSize >= outlen1 + blockSize); if (EVP_EncryptFinal_ex(ctx, pOut + outlen1, &outlen2) != 1) ERROR_EXIT(TPM_RC_FAILURE); @@ -677,7 +619,7 @@ CryptSymmetricDecrypt( // in case statements and it can't tell if they are always initialized // when needed, so... Comment these out if the compiler can tell or doesn't // care that these are initialized before use. - pAssert(dOut != NULL && key != NULL && dIn != NULL); + pAssert_RC(dOut != NULL && key != NULL && dIn != NULL); if(dSize == 0) return TPM_RC_SUCCESS; TPM_DO_SELF_TEST(algorithm); @@ -736,20 +678,20 @@ CryptSymmetricDecrypt( EVP_DecryptUpdate(ctx, buffer, &outlen1, dIn, dSize) != 1) ERROR_EXIT(TPM_RC_FAILURE); - pAssert((int)buffersize >= outlen1); + pAssert_RC((int)buffersize >= outlen1); if ((int)buffersize <= outlen1 /* coverity */ || EVP_DecryptFinal(ctx, &buffer[outlen1], &outlen2) != 1) ERROR_EXIT(TPM_RC_FAILURE); - pAssert((int)buffersize >= outlen1 + outlen2); + pAssert_RC((int)buffersize >= outlen1 + outlen2); if (ivInOut) retVal = CryptSymmetricGetUpdatedIV(ctx, ivInOut); Exit: if (retVal == TPM_RC_SUCCESS) { - pAssert(dSize >= outlen1 + outlen2); + pAssert_RC(dSize >= outlen1 + outlen2); memcpy(dOut, buffer, outlen1 + outlen2); }