From 2296a4dd2aadcf3569d1fbabe5e64813f193a5f9 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Tue, 26 Nov 2019 13:16:46 -0500 Subject: [PATCH] tpm2: Comments and whitespace changes only Signed-off-by: Stefan Berger --- src/tpm2/BaseTypes.h | 6 +- src/tpm2/CommandCodeAttributes.c | 7 +- src/tpm2/CryptSelfTest.c | 5 +- src/tpm2/MinMax.h | 5 +- src/tpm2/NVMem.c | 2 +- src/tpm2/NVReserved.c | 1 + src/tpm2/OIDs.h | 4 +- src/tpm2/Object.c | 6 +- src/tpm2/ObjectCommands.c | 2 +- src/tpm2/PCR.c | 76 +++++++++---------- src/tpm2/PRNG_TestVectors.h | 17 ++--- src/tpm2/PlatformData.h | 8 +- src/tpm2/SelfTest.h | 11 ++- src/tpm2/Session.c | 12 +-- src/tpm2/SessionProcess.c | 2 +- src/tpm2/SigningCommands.c | 4 +- .../SupportLibraryFunctionPrototypes_fp.h | 59 +++++++++----- src/tpm2/SymmetricTest.h | 2 +- src/tpm2/TpmFail.c | 1 - src/tpm2/X509_spt.c | 4 +- src/tpm2/crypto/CryptEcc.h | 4 +- src/tpm2/crypto/openssl/CryptPrime.c | 4 +- src/tpm2/crypto/openssl/CryptRand.c | 2 +- src/tpm2/crypto/openssl/CryptRsa.c | 2 + src/tpm2/crypto/openssl/LibSupport.h | 2 +- src/tpm2/crypto/openssl/TpmToOsslMath.c | 16 ++-- src/tpm2/crypto/openssl/TpmToOsslSym.h | 2 +- 27 files changed, 149 insertions(+), 117 deletions(-) diff --git a/src/tpm2/BaseTypes.h b/src/tpm2/BaseTypes.h index 7687715e..b134b22c 100644 --- a/src/tpm2/BaseTypes.h +++ b/src/tpm2/BaseTypes.h @@ -1,9 +1,9 @@ /********************************************************************************/ /* */ -/* */ +/* Basic Typedefs */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: BaseTypes.h 1521 2019-11-15 21:00:47Z kgoldman $ */ +/* $Id: BaseTypes.h 1531 2019-11-21 23:54:38Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -55,7 +55,7 @@ /* arising in any way out of use or reliance upon this specification or any */ /* information herein. */ /* */ -/* (c) Copyright IBM Corp. and others, 2016 */ +/* (c) Copyright IBM Corp. and others, 2016 - 2019 */ /* */ /********************************************************************************/ diff --git a/src/tpm2/CommandCodeAttributes.c b/src/tpm2/CommandCodeAttributes.c index 9ad9f2ef..23d13fb5 100644 --- a/src/tpm2/CommandCodeAttributes.c +++ b/src/tpm2/CommandCodeAttributes.c @@ -3,7 +3,7 @@ /* Functions for testing various command properties */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: CommandCodeAttributes.c 1490 2019-07-26 21:13:22Z kgoldman $ */ +/* $Id: CommandCodeAttributes.c 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -55,7 +55,7 @@ /* arising in any way out of use or reliance upon this specification or any */ /* information herein. */ /* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2018 */ +/* (c) Copyright IBM Corp. and others, 2016 - 2019 */ /* */ /********************************************************************************/ @@ -73,7 +73,7 @@ typedef UINT16 ATTRIBUTE_TYPE; /* The following file is produced from the command tables in part 3 of the specification. It defines the attributes for each of the commands. */ /* NOTE: This file is currently produced by an automated process. Files produced from Part 2 or Part - 3 tables through automated processes are not included in the specification so that their is no + 3 tables through automated processes are not included in the specification so that there is no ambiguity about the table containing the information being the normative definition. */ #define _COMMAND_CODE_ATTRIBUTES_ #include "CommandAttributeData.h" @@ -556,3 +556,4 @@ IsVendorCommand( return (IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V)); } #endif /* libtpms added */ + diff --git a/src/tpm2/CryptSelfTest.c b/src/tpm2/CryptSelfTest.c index 324c92f1..712497cb 100644 --- a/src/tpm2/CryptSelfTest.c +++ b/src/tpm2/CryptSelfTest.c @@ -3,7 +3,7 @@ /* Self-Test of Cryptographic Functions */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: CryptSelfTest.c 1490 2019-07-26 21:13:22Z kgoldman $ */ +/* $Id: CryptSelfTest.c 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -171,8 +171,7 @@ CryptIncrementalSelfTest( return TPM_RC_SUCCESS; } /* 10.2.7.2.4 CryptInitializeToTest() */ -/* This function will initialize the data structures for testing all the algorithms. This should not - be called unless CryptAlgsSetImplemented() has been called */ +/* This function will initialize the data structures for testing all the algorithms. */ void CryptInitializeToTest( void diff --git a/src/tpm2/MinMax.h b/src/tpm2/MinMax.h index d1b2a4a2..db008a8d 100644 --- a/src/tpm2/MinMax.h +++ b/src/tpm2/MinMax.h @@ -3,7 +3,7 @@ /* Min Max Macros */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: MinMax.h 1490 2019-07-26 21:13:22Z kgoldman $ */ +/* $Id: MinMax.h 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -59,7 +59,8 @@ /* */ /********************************************************************************/ -// 10.1.17 MinMax.h +// 5.13 MinMax.h + #ifndef _MIN_MAX_H_ #define _MIN_MAX_H_ #ifndef MAX diff --git a/src/tpm2/NVMem.c b/src/tpm2/NVMem.c index c684a293..ff82a765 100644 --- a/src/tpm2/NVMem.c +++ b/src/tpm2/NVMem.c @@ -3,7 +3,7 @@ /* NV read and write access methods */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: NVMem.c 1519 2019-11-15 20:43:51Z kgoldman $ */ +/* $Id: NVMem.c 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ diff --git a/src/tpm2/NVReserved.c b/src/tpm2/NVReserved.c index 77637508..fa1053cb 100644 --- a/src/tpm2/NVReserved.c +++ b/src/tpm2/NVReserved.c @@ -188,6 +188,7 @@ NvWrite( } return FALSE; } + #if 0 // libtpms added being (for Coverity) /* 8.5.3.8 NvUpdatePersistent() */ /* This function is used to update a value in the PERSISTENT_DATA structure and commits the value to diff --git a/src/tpm2/OIDs.h b/src/tpm2/OIDs.h index 3531ddb7..210afc36 100644 --- a/src/tpm2/OIDs.h +++ b/src/tpm2/OIDs.h @@ -3,7 +3,7 @@ /* OID values */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: OIDs.h 1519 2019-11-15 20:43:51Z kgoldman $ */ +/* $Id: OIDs.h 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -59,7 +59,7 @@ /* */ /********************************************************************************/ -// 10.1.14 OIDS.h +// 10.1.16 OIDs.h #include "Tpm.h" diff --git a/src/tpm2/Object.c b/src/tpm2/Object.c index 5aab1967..c5b2e942 100644 --- a/src/tpm2/Object.c +++ b/src/tpm2/Object.c @@ -3,7 +3,7 @@ /* Manage the object store of the TPM. */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: Object.c 1490 2019-07-26 21:13:22Z kgoldman $ */ +/* $Id: Object.c 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -241,8 +241,8 @@ ObjectGetHierarchy( } /* 8.6.3.11 GetHeriarchy() */ /* This function returns the handle of the hierarchy to which a handle belongs. This function is - similar to ObjectGetHierarchy() but this routine takes a handle but ObjectGetHierarchy() takes an - pointer to an object. */ + similar to ObjectGetHierarchy() but this routine takes a handle while ObjectGetHierarchy() takes + an pointer to an object. */ /* This function requires that handle references a loaded object. */ TPMI_RH_HIERARCHY GetHeriarchy( diff --git a/src/tpm2/ObjectCommands.c b/src/tpm2/ObjectCommands.c index 5eefa004..f524132e 100644 --- a/src/tpm2/ObjectCommands.c +++ b/src/tpm2/ObjectCommands.c @@ -3,7 +3,7 @@ /* Object Commands */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: ObjectCommands.c 1490 2019-07-26 21:13:22Z kgoldman $ */ +/* $Id: ObjectCommands.c 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ diff --git a/src/tpm2/PCR.c b/src/tpm2/PCR.c index 87338525..590efc92 100644 --- a/src/tpm2/PCR.c +++ b/src/tpm2/PCR.c @@ -3,7 +3,7 @@ /* PCR access and manipulation */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: PCR.c 1519 2019-11-15 20:43:51Z kgoldman $ */ +/* $Id: PCR.c 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -91,8 +91,8 @@ static const PCR_Attributes s_initAttributes[] = {0, 0x0F, 0x1F}, // PCR 23, Application specific {0, 0x0F, 0x1F} // PCR 24, testing policy }; -/* 8.7.3 Functions */ -/* 8.7.3.1 PCRBelongsAuthGroup() */ +/* 8.7.2 Functions */ +/* 8.7.2.1 PCRBelongsAuthGroup() */ /* This function indicates if a PCR belongs to a group that requires an authValue in order to modify the PCR. If it does, groupIndex is set to value of the group index. This feature of PCR is decided by the platform specification. */ @@ -123,13 +123,13 @@ PCRBelongsAuthGroup( #endif return FALSE; } -/* 8.7.3.2 PCRBelongsPolicyGroup() */ +/* 8.7.2.2 PCRBelongsPolicyGroup() */ /* This function indicates if a PCR belongs to a group that requires a policy authorization in order to modify the PCR. If it does, groupIndex is set to value of the group index. This feature of PCR is decided by the platform specification. */ /* Return Values Meaning */ -/* TRUE: PCR belongs a policy group */ -/* FALSE: PCR does not belong a policy group */ +/* TRUE: PCR belongs to a policy group */ +/* FALSE: PCR does not belong to a policy group */ BOOL PCRBelongsPolicyGroup( TPMI_DH_PCR handle, // IN: handle of PCR @@ -152,11 +152,11 @@ PCRBelongsPolicyGroup( #endif return FALSE; } -/* 8.7.3.3 PCRBelongsTCBGroup() */ +/* 8.7.2.3 PCRBelongsTCBGroup() */ /* This function indicates if a PCR belongs to the TCB group. */ /* Return Values Meaning */ -/* TRUE: PCR belongs to TCB group */ -/* FALSE: PCR does not belong to TCB group */ +/* TRUE: PCR belongs to a TCB group */ +/* FALSE: PCR does not belong to a TCB group */ static BOOL PCRBelongsTCBGroup( TPMI_DH_PCR handle // IN: handle of PCR @@ -172,10 +172,10 @@ PCRBelongsTCBGroup( #endif return FALSE; } -/* 8.7.3.4 PCRPolicyIsAvailable() */ +/* 8.7.2.4 PCRPolicyIsAvailable() */ /* This function indicates if a policy is available for a PCR. */ /* Return Values Meaning */ -/* TRUE the PCR should be authorized by policy */ +/* TRUE the PCR may be authorized by policy */ /* FALSE the PCR does not allow policy */ BOOL PCRPolicyIsAvailable( @@ -185,7 +185,7 @@ PCRPolicyIsAvailable( UINT32 groupIndex; return PCRBelongsPolicyGroup(handle, &groupIndex); } -/* 8.7.3.5 PCRGetAuthValue() */ +/* 8.7.2.5 PCRGetAuthValue() */ /* This function is used to access the authValue of a PCR. If PCR does not belong to an authValue group, an EmptyAuth() will be returned. */ TPM2B_AUTH * @@ -203,7 +203,7 @@ PCRGetAuthValue( return NULL; } } -/* 8.7.3.6 PCRGetAuthPolicy() */ +/* 8.7.2.6 PCRGetAuthPolicy() */ /* This function is used to access the authorization policy of a PCR. It sets policy to the authorization policy and returns the hash algorithm for policy If the PCR does not allow a policy, TPM_ALG_NULL is returned. */ @@ -225,7 +225,7 @@ PCRGetAuthPolicy( return TPM_ALG_NULL; } } -/* 8.7.3.7 PCRSimStart() */ +/* 8.7.2.7 PCRSimStart() */ /* This function is used to initialize the policies when a TPM is manufactured. This function would only be called in a manufacturing environment or in a TPM simulator. */ void @@ -266,7 +266,7 @@ PCRSimStart( NV_SYNC_PERSISTENT(pcrAllocated); return; } -/* 8.7.3.8 GetSavedPcrPointer() */ +/* 8.7.2.8 GetSavedPcrPointer() */ /* This function returns the address of an array of state saved PCR based on the hash algorithm. */ /* Return Values Meaning */ /* NULL no such algorithm */ @@ -310,7 +310,7 @@ GetSavedPcrPointer( } return retVal; } -/* 8.7.3.9 PcrIsAllocated() */ +/* 8.7.2.9 PcrIsAllocated() */ /* This function indicates if a PCR number for the particular hash algorithm is allocated. */ /* Return Values Meaning */ /* FALSE PCR is not allocated */ @@ -340,7 +340,7 @@ PcrIsAllocated( } return allocated; } -/* 8.7.3.10 GetPcrPointer() */ +/* 8.7.2.10 GetPcrPointer() */ /* This function returns the address of an array of PCR based on the hash algorithm. */ /* Return Values Meaning */ /* NULL no such algorithm */ @@ -387,7 +387,7 @@ GetPcrPointer( } return pcr; } -/* 8.7.3.11 IsPcrSelected() */ +/* 8.7.2.11 IsPcrSelected() */ /* This function indicates if an indicated PCR number is selected by the bit map in selection. */ /* Return Values Meaning */ /* FALSE PCR is not selected */ @@ -403,7 +403,7 @@ IsPcrSelected( && ((selection->pcrSelect[pcr / 8]) & (1 << (pcr % 8))) != 0); return selected; } -/* 8.7.3.12 FilterPcr() */ +/* 8.7.2.12 FilterPcr() */ /* This function modifies a PCR selection array based on the implemented PCR. */ static void FilterPcr( @@ -436,7 +436,7 @@ FilterPcr( } return; } -/* 8.7.3.13 PcrDrtm() */ +/* 8.7.2.13 PcrDrtm() */ /* This function does the DRTM and H-CRTM processing it is called from _TPM_Hash_End(). */ void PcrDrtm( @@ -460,7 +460,7 @@ PcrDrtm( PCRExtend(pcrHandle, hash, digest->t.size, (BYTE *)digest->t.buffer); } } -/* 8.7.3.14 PCR_ClearAuth() */ +/* 8.7.2.14 PCR_ClearAuth() */ /* This function is used to reset the PCR authorization values. It is called on TPM2_Startup(CLEAR) and TPM2_Clear(). */ void @@ -476,7 +476,7 @@ PCR_ClearAuth( } #endif } -/* 8.7.3.15 PCRStartup() */ +/* 8.7.2.15 PCRStartup() */ /* This function initializes the PCR subsystem at TPM2_Startup(). */ BOOL PCRStartup( @@ -557,7 +557,7 @@ PCRStartup( PCR_ClearAuth(); return TRUE; } -/* 8.7.3.16 PCRStateSave() */ +/* 8.7.2.16 PCRStateSave() */ /* This function is used to save the PCR values that will be restored on TPM Resume. */ void PCRStateSave( @@ -598,7 +598,7 @@ PCRStateSave( } return; } -/* 8.7.3.17 PCRIsStateSaved() */ +/* 8.7.2.17 PCRIsStateSaved() */ /* This function indicates if the selected PCR is a PCR that is state saved on TPM2_Shutdown(STATE). The return value is based on PCR attributes. */ /* Return Values Meaning */ @@ -615,7 +615,7 @@ PCRIsStateSaved( else return FALSE; } -/* 8.7.3.18 PCRIsResetAllowed() */ +/* 8.7.2.18 PCRIsResetAllowed() */ /* This function indicates if a PCR may be reset by the current command locality. The return value is based on PCR attributes, and not the PCR allocation. */ /* Return Values Meaning */ @@ -642,7 +642,7 @@ PCRIsResetAllowed( else return TRUE; } -/* 8.7.3.19 PCRChanged() */ +/* 8.7.2.19 PCRChanged() */ /* This function checks a PCR handle to see if the attributes for the PCR are set so that any change to the PCR causes an increment of the pcrCounter. If it does, then the function increments the counter. Will also bump the counter if the handle is zero which means that PCR 0 can not be in @@ -661,7 +661,7 @@ PCRChanged( FAIL(FATAL_ERROR_COUNTER_OVERFLOW); } } -/* 8.7.3.20 PCRIsExtendAllowed() */ +/* 8.7.2.20 PCRIsExtendAllowed() */ /* This function indicates a PCR may be extended at the current command locality. The return value is based on PCR attributes, and not the PCR allocation. */ /* Return Values Meaning */ @@ -683,7 +683,7 @@ PCRIsExtendAllowed( else return TRUE; } -/* 8.7.3.21 PCRExtend() */ +/* 8.7.2.21 PCRExtend() */ /* This function is used to extend a PCR in a specific bank. */ void PCRExtend( @@ -710,7 +710,7 @@ PCRExtend( } return; } -/* 8.7.3.22 PCRComputeCurrentDigest() */ +/* 8.7.2.22 PCRComputeCurrentDigest() */ /* This function computes the digest of the selected PCR. */ /* As a side-effect, selection is modified so that only the implemented PCR will have their bits still set. */ @@ -755,7 +755,7 @@ PCRComputeCurrentDigest( CryptHashEnd2B(&hashState, &digest->b); return; } -/* 8.7.3.23 PCRRead() */ +/* 8.7.2.23 PCRRead() */ /* This function is used to read a list of selected PCR. If the requested PCR number exceeds the maximum number that can be output, the selection is adjusted to reflect the actual output PCR. */ void @@ -828,7 +828,7 @@ PCRRead( *pcrCounter = gr.pcrCounter; return; } -/* 8.7.3.25 PCRAllocate() */ +/* 8.7.2.25 PCRAllocate() */ /* This function is used to change the PCR allocation. */ /* Error Returns Meaning */ /* TPM_RC_NO_RESULT allocate failed */ @@ -923,7 +923,7 @@ PCRAllocate( NV_WRITE_PERSISTENT(pcrAllocated, newAllocate); return TPM_RC_SUCCESS; } -/* 8.7.3.26 PCRSetValue() */ +/* 8.7.2.26 PCRSetValue() */ /* This function is used to set the designated PCR in all banks to an initial value. The initial value is signed and will be sign extended into the entire PCR. */ void @@ -961,7 +961,7 @@ PCRSetValue( } } } -/* 8.7.3.27 PCRResetDynamics */ +/* 8.7.2.27 PCRResetDynamics */ /* This function is used to reset a dynamic PCR to 0. This function is used in DRTM sequence. */ void PCRResetDynamics( @@ -991,7 +991,7 @@ PCRResetDynamics( } return; } -/* 8.7.3.28 PCRCapGetAllocation() */ +/* 8.7.2.28 PCRCapGetAllocation() */ /* This function is used to get the current allocation of PCR banks. */ /* Return Values Meaning */ /* YES: if the return count is 0 */ @@ -1013,7 +1013,7 @@ PCRCapGetAllocation( return NO; } } -/* 8.7.3.29 PCRSetSelectBit() */ +/* 8.7.2.29 PCRSetSelectBit() */ /* This function sets a bit in a bitmap array. */ static void PCRSetSelectBit( @@ -1024,7 +1024,7 @@ PCRSetSelectBit( bitmap[pcr / 8] |= (1 << (pcr % 8)); return; } -/* 8.7.3.30 PCRGetProperty() */ +/* 8.7.2.30 PCRGetProperty() */ /* This function returns the selected PCR property. */ /* Return Values Meaning */ /* TRUE the property type is implemented */ @@ -1123,7 +1123,7 @@ PCRGetProperty( } return TRUE; } -/* 8.7.3.31 PCRCapGetProperties() */ +/* 8.7.2.31 PCRCapGetProperties() */ /* This function returns a list of PCR properties starting at property. */ /* Return Values Meaning */ /* YES: if no more property is available */ @@ -1165,7 +1165,7 @@ PCRCapGetProperties( } return more; } -/* 8.7.3.32 PCRCapGetHandles() */ +/* 8.7.2.32 PCRCapGetHandles() */ /* This function is used to get a list of handles of PCR, started from handle. If handle exceeds the maximum PCR handle range, an empty list will be returned and the return value will be NO. */ /* Return Values Meaning */ diff --git a/src/tpm2/PRNG_TestVectors.h b/src/tpm2/PRNG_TestVectors.h index 713e5cb5..eca09b1b 100644 --- a/src/tpm2/PRNG_TestVectors.h +++ b/src/tpm2/PRNG_TestVectors.h @@ -1,9 +1,9 @@ /********************************************************************************/ /* */ -/* PRNG Test Vectors */ +/* PRNG Test Vectors */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: PRNG_TestVectors.h 1311 2018-08-23 21:39:29Z kgoldman $ */ +/* $Id: PRNG_TestVectors.h 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -55,17 +55,20 @@ /* arising in any way out of use or reliance upon this specification or any */ /* information herein. */ /* */ -/* (c) Copyright IBM Corp. and others, 2016 - 2018 */ +/* (c) Copyright IBM Corp. and others, 2016 - 2019 */ /* */ /********************************************************************************/ -#ifndef PRNG_TESTVECTORS_H -#define PRNG_TESTVECTORS_H +/* 10.1.17 PRNG_TestVectors.h */ #ifndef _MSBN_DRBG_TEST_VECTORS_H #define _MSBN_DRBG_TEST_VECTORS_H //#if DRBG_ALGORITHM == TPM_ALG_AES && DRBG_KEY_BITS == 256 #if DRBG_KEY_SIZE_BITS == 256 + +/* Entropy is the size of the state. The state is the size of the key plus the IV. The IV is a + block. If Key = 256 and Block = 128 then State = 384 */ + #define DRBG_TEST_INITIATE_ENTROPY \ 0x0d, 0x15, 0xaa, 0x80, 0xb1, 0x6c, 0x3a, 0x10, \ 0x90, 0x6c, 0xfe, 0xdb, 0x79, 0x5d, 0xae, 0x0b, \ @@ -86,7 +89,6 @@ #define DRBG_TEST_GENERATED \ 0x94, 0x6f, 0x51, 0x82, 0xd5, 0x45, 0x10, 0xb9, \ 0x46, 0x12, 0x48, 0xf5, 0x71, 0xca, 0x06, 0xc9 -//#elif DRBG_ALGORITHM == TPM_ALG_AES && DRBG_KEY_BITS == 128 #elif DRBG_KEY_SIZE_BITS == 128 #define DRBG_TEST_INITIATE_ENTROPY \ 0x8f, 0xc1, 0x1b, 0xdb, 0x5a, 0xab, 0xb7, 0xe0, \ @@ -106,6 +108,3 @@ 0x44, 0x76, 0x9a, 0x8e, 0x6e, 0x8c, 0x1a, 0xd4 #endif #endif // _MSBN_DRBG_TEST_VECTORS_H - - -#endif diff --git a/src/tpm2/PlatformData.h b/src/tpm2/PlatformData.h index 49c99e95..f378dece 100644 --- a/src/tpm2/PlatformData.h +++ b/src/tpm2/PlatformData.h @@ -79,7 +79,7 @@ EXTERN int s_isCanceled; typedef uint64_t clock64_t; // This is the value returned the last time that the system clock was read. This is only relevant // for a simulator or virtual TPM. -EXTERN clock64_t s_realTimePrevious; +EXTERN clock64_t s_realTimePrevious; // These values are used to try to synthesize a long lived version of clock(). EXTERN clock64_t s_lastSystemTime; EXTERN clock64_t s_lastReportedTime; @@ -98,9 +98,9 @@ EXTERN BOOL s_timerReset; EXTERN BOOL s_timerStopped; /* This variable records the time when _plat__TimerReset() is called. This mechanism allow us to subtract the time when TPM is power off from the total time reported by clock() function */ -EXTERN uint64_t s_initClock; +EXTERN uint64_t s_initClock; /* This variable records the timer adjustment factor. */ -EXTERN unsigned int s_adjustRate; +EXTERN unsigned int s_adjustRate; /* From LocalityPlat.c Locality of current command */ EXTERN unsigned char s_locality; /* From NVMem.c Choose if the NV memory should be backed by RAM or by file. If this macro is @@ -124,7 +124,7 @@ EXTERN unsigned char s_locality; #error Do not define SIMULATION for libtpms! #endif // SIMULATION -EXTERN unsigned char s_NV[NV_MEMORY_SIZE]; +EXTERN unsigned char s_NV[NV_MEMORY_SIZE]; EXTERN BOOL s_NvIsAvailable; EXTERN BOOL s_NV_unrecoverable; EXTERN BOOL s_NV_recoverable; diff --git a/src/tpm2/SelfTest.h b/src/tpm2/SelfTest.h index 506e97ff..1605914f 100644 --- a/src/tpm2/SelfTest.h +++ b/src/tpm2/SelfTest.h @@ -3,7 +3,7 @@ /* Structure definitions for the self-test */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: SelfTest.h 1476 2019-06-10 19:32:03Z kgoldman $ */ +/* $Id: SelfTest.h 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -62,11 +62,12 @@ #ifndef SELFTEST_H #define SELFTEST_H -/* 5.16.1 Introduction */ +/* 10.1.10 SelfTest.h */ +/* 10.1.10.1 Introduction */ + /* This file contains the structure definitions for the self-test. It also contains macros for use when the self-test is implemented. */ -/* 5.16.2 Defines */ -/* Was typing this a lot */ + #define SELF_TEST_FAILURE FAIL(FATAL_ERROR_SELF_TEST) // Use the definition of key sizes to set algorithm values for key size. @@ -80,9 +81,11 @@ typedef UINT32 SYM_INDEX; /* These two defines deal with the fact that the TPM_ALG_ID table does not delimit the symmetric mode values with a TPM_SYM_MODE_FIRST and TPM_SYM_MODE_LAST */ + #define TPM_SYM_MODE_FIRST ALG_CTR_VALUE #define TPM_SYM_MODE_LAST ALG_ECB_VALUE #define NUM_SYM_MODES (TPM_SYM_MODE_LAST - TPM_SYM_MODE_FIRST + 1) + /* Define a type to hold a bit vector for the modes. */ #if NUM_SYM_MODES <= 0 #error "No symmetric modes implemented" diff --git a/src/tpm2/Session.c b/src/tpm2/Session.c index f45fec01..b2a62c32 100644 --- a/src/tpm2/Session.c +++ b/src/tpm2/Session.c @@ -3,7 +3,7 @@ /* Manage the session context counter */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: Session.c 1490 2019-07-26 21:13:22Z kgoldman $ */ +/* $Id: Session.c 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -122,10 +122,10 @@ /* Assume we have a small contextArray with 8, 4-bit values with values 1 and 2 used to indicate the loaded context slot number. Also assume that the array contains hex values of (0 0 1 0 3 0 9 F) and that the contextCounter is an 8-bit counter with a value of 0x37. Since the low nibble is 7, - that means that values above 7 are older than values below it and, in this example, 9 is the - oldest value. */ + that means that values closest to but above 7 are older than values below it and, in this + example, 9 is the oldest value. */ /* Note if we subtract the counter value, from each slot that contains a saved contextID we get (- - - - - B - 2 - 8) and the oldest entry is now easy to find. */ + - - B - 2 - 8) and the oldest entry is now easy to find because it has the lowest value. */ static void ContextIdSetOldest( @@ -134,7 +134,7 @@ ContextIdSetOldest( { CONTEXT_SLOT lowBits; CONTEXT_SLOT entry; - CONTEXT_SLOT smallest = ((CONTEXT_SLOT)~0); + CONTEXT_SLOT smallest = ((CONTEXT_SLOT)~0); /* Set to the maximum possible */ UINT32 i; // Set oldestSaveContext to a value indicating none assigned s_oldestSavedSession = MAX_ACTIVE_SESSIONS + 1; @@ -231,7 +231,7 @@ SessionIsLoaded( /* 8.9.5.2 SessionIsSaved() */ /* This function test a session handle references a saved session. The handle must have previously been checked to make sure that it is a valid handle for an authorization session. */ -/* NOTE: An password authorization does not have a session. */ +/* NOTE: A password authorization does not have a session. */ /* This function requires that the handle be a valid session handle. */ /* Return Values Meaning */ /* TRUE if session is saved */ diff --git a/src/tpm2/SessionProcess.c b/src/tpm2/SessionProcess.c index c09ad462..0fa74c12 100644 --- a/src/tpm2/SessionProcess.c +++ b/src/tpm2/SessionProcess.c @@ -1566,7 +1566,7 @@ CheckAuthNoSession( } /* 6.4.5 Response Session Processing */ /* 6.4.5.1 Introduction */ -/* The following functions build the session area in a response, and handle the audit sessions (if +/* The following functions build the session area in a response and handle the audit sessions (if present). */ /* 6.4.5.2 ComputeRpHash() */ /* Function to compute rpHash (Response Parameter Hash). The rpHash is only computed if there is an diff --git a/src/tpm2/SigningCommands.c b/src/tpm2/SigningCommands.c index 4d0ba157..53c30867 100644 --- a/src/tpm2/SigningCommands.c +++ b/src/tpm2/SigningCommands.c @@ -3,7 +3,7 @@ /* Signing and Signature Verification */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: SigningCommands.c 1490 2019-07-26 21:13:22Z kgoldman $ */ +/* $Id: SigningCommands.c 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -86,7 +86,7 @@ TPM2_VerifySignature( || signObject->publicArea.nameAlg == TPM_ALG_NULL) { // produce empty ticket if hierarchy is TPM_RH_NULL or nameAlg is - // TPM_ALG_NULL + // ALG_NULL out->validation.tag = TPM_ST_VERIFIED; out->validation.hierarchy = TPM_RH_NULL; out->validation.digest.t.size = 0; diff --git a/src/tpm2/SupportLibraryFunctionPrototypes_fp.h b/src/tpm2/SupportLibraryFunctionPrototypes_fp.h index 69c9e0bd..3b1e1a9a 100644 --- a/src/tpm2/SupportLibraryFunctionPrototypes_fp.h +++ b/src/tpm2/SupportLibraryFunctionPrototypes_fp.h @@ -3,7 +3,7 @@ /* For Selected Math Library */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: SupportLibraryFunctionPrototypes_fp.h 1519 2019-11-15 20:43:51Z kgoldman $ */ +/* $Id: SupportLibraryFunctionPrototypes_fp.h 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -59,71 +59,96 @@ /* */ /********************************************************************************/ -/* 5.16 SupportLibraryFunctionPrototypes_fp.h */ - #ifndef SUPPORT_LIBRARY_FUNCTION_PROTOTYPES_H #define SUPPORT_LIBRARY_FUNCTION_PROTOTYPES_H +/* 10.1.11 SupportLibraryFunctionPrototypes_fp.h */ +/* 10.1.11.1 Introduction */ + /* This file contains the function prototypes for the functions that need to be present in the selected math library. For each function listed, there should be a small stub function. That stub provides the interface between the TPM code and the support library. In most cases, the stub function will only need to do a format conversion between the TPM big number and the support library big number. The TPM big number format was chosen to make this relatively simple and fast. */ + + +/* 10.1.11.2 SupportLibInit() */ +/* This function is called by CryptInit() so that necessary initializations can be performed on the + cryptographic library. */ + + LIB_EXPORT int SupportLibInit(void); -/* MathLibraryCompatibililtyCheck() This function is only used during development to make sure that - the library that is being referenced is using the same size of data structures as the TPM. */ + + +/* 10.1.11.3 MathLibraryCompatibililtyCheck() */ +/* This function is only used during development to make sure that the library that is being + referenced is using the same size of data structures as the TPM. */ + BOOL MathLibraryCompatibilityCheck( void ); -/* 5.19.2 BnModMult() */ +/* 10.1.1114 BnModMult() */ /* Does multiply op1 * op2 and divide by modulus returning the remainder of the divide. */ + LIB_EXPORT BOOL BnModMult(bigNum result, bigConst op1, bigConst op2, bigConst modulus); -/* 5.19.3 BnMult() */ + +/* 10.1.11.5 BnMult() */ /* Multiplies two numbers and returns the result */ + LIB_EXPORT BOOL BnMult(bigNum result, bigConst multiplicand, bigConst multiplier); -/* 5.19.4 BnDiv() */ + +/* 10.1.11.6 BnDiv() */ /* This function divides two bigNum values. The function returns FALSE if there is an error in the operation. */ LIB_EXPORT BOOL BnDiv(bigNum quotient, bigNum remainder, bigConst dividend, bigConst divisor); -/* 5.19.5 BnMod() */ + +/* 10.1.11.7 BnMod() */ #define BnMod(a, b) BnDiv(NULL, (a), (a), (b)) -/* 5.19.6 BnGcd() */ + +/* 10.1.11.8 BnGcd() */ /* Get the greatest common divisor of two numbers. This function is only needed when the TPM implements RSA. */ LIB_EXPORT BOOL BnGcd(bigNum gcd, bigConst number1, bigConst number2); -/* 5.19.7 BnModExp() */ + +/* 10.1.11.9 BnModExp() */ /* Do modular exponentiation using bigNum values. This function is only needed when the TPM implements RSA. */ LIB_EXPORT BOOL BnModExp(bigNum result, bigConst number, bigConst exponent, bigConst modulus); -/* 5.19.8 BnModInverse() */ + +/* 10.1.11.10 BnModInverse() */ /* Modular multiplicative inverse. This function is only needed when the TPM implements RSA. */ LIB_EXPORT BOOL BnModInverse(bigNum result, bigConst number, bigConst modulus); -/* 5.19.9 BnEccModMult() */ + +/* 10.1.11.11 BnEccModMult() */ /* This function does a point multiply of the form R = [d]S. A return of FALSE indicates that the result was the point at infinity. This function is only needed if the TPM supports ECC. */ LIB_EXPORT BOOL BnEccModMult(bigPoint R, pointConst S, bigConst d, bigCurve E); -/* 5.19.10 BnEccModMult2() */ + +/* 10.1.11.13 BnEccModMult2() */ /* This function does a point multiply of the form R = [d]S + [u]Q. A return of FALSE indicates that the result was the point at infinity. This function is only needed if the TPM supports ECC */ LIB_EXPORT BOOL BnEccModMult2(bigPoint R, pointConst S, bigConst d, pointConst Q, bigConst u, bigCurve E); -/* 5.19.11 BnEccAdd() */ + +/* 10.1.11.14 BnEccAdd() */ /* This function does a point add R = S + Q. A return of FALSE indicates that the result was the point at infinity. This function is only needed if the TPM supports ECC. */ LIB_EXPORT BOOL BnEccAdd(bigPoint R, pointConst S, pointConst Q, bigCurve E); -/* 5.19.12 BnCurveInitialize() */ + +/* 10.1.11.15 BnCurveInitialize() */ /* This function is used to initialize the pointers of a bnCurve_t structure. The structure is a set of pointers to bigNum values. The curve-dependent values are set by a different function. This function is only needed if the TPM supports ECC.*/ LIB_EXPORT bigCurve BnCurveInitialize(bigCurve E, TPM_ECC_CURVE curveId); -/* 5.16.14.1 BnCurveFree() */ + +/* 10.1.11.16 BnCurveFree() */ /* This function will free the allocated components of the curve and end the frame in which the curve data exists */ LIB_EXPORT void BnCurveFree(bigCurve E); diff --git a/src/tpm2/SymmetricTest.h b/src/tpm2/SymmetricTest.h index 205def63..c20f4fa9 100644 --- a/src/tpm2/SymmetricTest.h +++ b/src/tpm2/SymmetricTest.h @@ -3,7 +3,7 @@ /* Structures and data definitions for the symmetric tests */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: SymmetricTest.h 1476 2019-06-10 19:32:03Z kgoldman $ */ +/* $Id: SymmetricTest.h 1519 2019-11-15 20:43:51Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ diff --git a/src/tpm2/TpmFail.c b/src/tpm2/TpmFail.c index 454c692f..25391c07 100644 --- a/src/tpm2/TpmFail.c +++ b/src/tpm2/TpmFail.c @@ -189,7 +189,6 @@ static BOOL Unmarshal16( /* 9.17.4Public Functions */ #if 0 /* libtpms added */ -/* 9.17.4Public Functions */ /* 9.17.4.1 SetForceFailureMode() */ /* This function is called by the simulator to enable failure mode testing. */ LIB_EXPORT void diff --git a/src/tpm2/X509_spt.c b/src/tpm2/X509_spt.c index 8e32fe8f..195a4f7f 100644 --- a/src/tpm2/X509_spt.c +++ b/src/tpm2/X509_spt.c @@ -3,7 +3,7 @@ /* X509 Support */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: X509_spt.c 1511 2019-10-07 20:40:15Z kgoldman $ */ +/* $Id: X509_spt.c 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -78,7 +78,7 @@ //# include "X509_SM2_fp.h" #endif // ALG_RSA /* 10.2.26.2 Unmarshaling Functions */ -/* 10.2.26.2.1 X509FindExtensionOID() */ +/* 10.2.26.2.1 X509FindExtensionByOID() */ /* This will search a list of X509 extensions to find an extension with the requested OID. If the extension is found, the output context (ctx) is set up to point to the OID in the extension. */ /* Return Value Meaning */ diff --git a/src/tpm2/crypto/CryptEcc.h b/src/tpm2/crypto/CryptEcc.h index 1e99b2ea..ac88d267 100644 --- a/src/tpm2/crypto/CryptEcc.h +++ b/src/tpm2/crypto/CryptEcc.h @@ -3,7 +3,7 @@ /* Structure definitions used for ECC */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: CryptEcc.h 1519 2019-11-15 20:43:51Z kgoldman $ */ +/* $Id: CryptEcc.h 1532 2019-11-26 14:28:36Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -65,7 +65,7 @@ internally. The ECC-related structures that cross the TPM interface are defined in TpmTypes.h */ #ifndef _CRYPT_ECC_H #define _CRYPT_ECC_H -/* 10.1.2.1.1 ECC-related Structures */ +/* 10.1.2.2 Structures */ /* This is used to define the macro that may or may not be in the data set for the curve (CryptEccData.c). If there is a mismatch, the compiler will warn that there is to much/not enough initialization data in the curve. The macro is used because not all versions of the diff --git a/src/tpm2/crypto/openssl/CryptPrime.c b/src/tpm2/crypto/openssl/CryptPrime.c index b42a4096..de34e8c6 100644 --- a/src/tpm2/crypto/openssl/CryptPrime.c +++ b/src/tpm2/crypto/openssl/CryptPrime.c @@ -325,7 +325,7 @@ RsaAdjustPrimeCandidate_PreRev155( the left of the most significant bit. This approach helps make it clear what is happening with the MSb of the values. The two RSA primes have to be large enough so that their product will be a number with the necessary number of significant bits. For example, we want to be able to multiply - two 1024-bit numbers to produce a number with 2028 significant bits. If we accept any 1024-bit + two 1024-bit numbers to produce a number with 2048 significant bits. If we accept any 1024-bit prime that has its MSb set, then it is possible to produce a product that does not have the MSb SET. For example, if we use tiny keys of 16 bits and have two 8-bit primes of 0x80, then the public key would be 0x4000 which is only 15-bits. So, what we need to do is made sure that each @@ -366,6 +366,8 @@ RsaAdjustPrimeCandidate_New( // make sure the number is odd prime->d[0] |= 1; } + + LIB_EXPORT void RsaAdjustPrimeCandidate( bigNum prime, diff --git a/src/tpm2/crypto/openssl/CryptRand.c b/src/tpm2/crypto/openssl/CryptRand.c index c539c143..87522819 100644 --- a/src/tpm2/crypto/openssl/CryptRand.c +++ b/src/tpm2/crypto/openssl/CryptRand.c @@ -3,7 +3,7 @@ /* DRBG with a behavior according to SP800-90A */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: CryptRand.c 1519 2019-11-15 20:43:51Z kgoldman $ */ +/* $Id: CryptRand.c 1532 2019-11-26 14:28:36Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ diff --git a/src/tpm2/crypto/openssl/CryptRsa.c b/src/tpm2/crypto/openssl/CryptRsa.c index 7e2b103d..4ce3a832 100644 --- a/src/tpm2/crypto/openssl/CryptRsa.c +++ b/src/tpm2/crypto/openssl/CryptRsa.c @@ -511,6 +511,7 @@ CryptRsaPssSaltSize( saltSize = 0; return saltSize; } + #if !USE_OPENSSL_FUNCTIONS_RSA // libtpms added /* 10.2.17.4.9 PssEncode() */ /* This function creates an encoded block of data that is the size of modulus. The function uses the @@ -814,6 +815,7 @@ RSASSA_Decode( return retVal; } #endif // libtpms added + /* 10.2.17.4.13 CryptRsaSelectScheme() */ /* This function is used by TPM2_RSA_Decrypt() and TPM2_RSA_Encrypt(). It sets up the rules to select a scheme between input and object default. This function assume the RSA object is diff --git a/src/tpm2/crypto/openssl/LibSupport.h b/src/tpm2/crypto/openssl/LibSupport.h index 741fad78..07d7e6a7 100644 --- a/src/tpm2/crypto/openssl/LibSupport.h +++ b/src/tpm2/crypto/openssl/LibSupport.h @@ -3,7 +3,7 @@ /* select the library code that gets included in the TPM build */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: LibSupport.h 1476 2019-06-10 19:32:03Z kgoldman $ */ +/* $Id: LibSupport.h 1519 2019-11-15 20:43:51Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ diff --git a/src/tpm2/crypto/openssl/TpmToOsslMath.c b/src/tpm2/crypto/openssl/TpmToOsslMath.c index 3b6dfff4..82b2969a 100644 --- a/src/tpm2/crypto/openssl/TpmToOsslMath.c +++ b/src/tpm2/crypto/openssl/TpmToOsslMath.c @@ -649,8 +649,8 @@ BnEccModMult( else EC_POINT_mul(E->G, pR, NULL, pS, bnD, E->CTX); PointFromOssl(R, pR, E); - EC_POINT_clear_free(pR); - EC_POINT_clear_free(pS); + EC_POINT_clear_free(pR); // libtpms changed + EC_POINT_clear_free(pS); // libtpms changed BN_clear_free(bnD); // libtpms added return !BnEqualZero(R->z); } @@ -688,9 +688,9 @@ BnEccModMult2( EC_POINTs_mul(E->G, pR, NULL, 2, points, scalars, E->CTX); } PointFromOssl(R, pR, E); - EC_POINT_clear_free(pR); - EC_POINT_clear_free(pS); - EC_POINT_clear_free(pQ); + EC_POINT_clear_free(pR); // libtpms changed + EC_POINT_clear_free(pS); // libtpms changed + EC_POINT_clear_free(pQ); // libtpms changed BN_clear_free(bnD); // libtpms added BN_clear_free(bnU); // libtpms added @@ -715,9 +715,9 @@ BnEccAdd( // EC_POINT_add(E->G, pR, pS, pQ, E->CTX); PointFromOssl(R, pR, E); - EC_POINT_clear_free(pR); - EC_POINT_clear_free(pS); - EC_POINT_clear_free(pQ); + EC_POINT_clear_free(pR); // libtpms changed + EC_POINT_clear_free(pS); // libtpms changed + EC_POINT_clear_free(pQ); // libtpms changed return !BnEqualZero(R->z); } diff --git a/src/tpm2/crypto/openssl/TpmToOsslSym.h b/src/tpm2/crypto/openssl/TpmToOsslSym.h index 05c0d312..72a4fd78 100644 --- a/src/tpm2/crypto/openssl/TpmToOsslSym.h +++ b/src/tpm2/crypto/openssl/TpmToOsslSym.h @@ -3,7 +3,7 @@ /* Splice the OpenSSL() library into the TPM code. */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: TpmToOsslSym.h 1519 2019-11-15 20:43:51Z kgoldman $ */ +/* $Id: TpmToOsslSym.h 1529 2019-11-21 23:29:01Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */