tpm2: rev162: Trivial whitespace and comment changes

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2020-04-17 17:06:14 -04:00 committed by Stefan Berger
parent ae710d3872
commit 05c032777f
36 changed files with 117 additions and 185 deletions

View File

@ -235,9 +235,10 @@ AlgorithmGetImplementedVector(
int index;
// Nothing implemented until we say it is
MemorySet(implemented, 0, sizeof(ALGORITHM_VECTOR));
// Go through the list of implemented algorithms and SET the corresponding bit in
// in the implemented vector
for(index = (sizeof(s_algorithms) / sizeof(s_algorithms[0])) - 1;
index >= 0;
index--)
index >= 0; index--)
SET_BIT(s_algorithms[index].algID, *implemented);
return;
}

View File

@ -3,7 +3,7 @@
/* Attestation Commands */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: AttestationCommands.c 1529 2019-11-21 23:29:01Z kgoldman $ */
/* $Id: AttestationCommands.c 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/

View File

@ -3,7 +3,7 @@
/* Command Attributes */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CommandAttributes.h 1490 2019-07-26 21:13:22Z kgoldman $ */
/* $Id: CommandAttributes.h 1594 2020-03-26 22:15:48Z 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 - 2020 */
/* */
/********************************************************************************/

View File

@ -3,7 +3,7 @@
/* Functions for testing various command properties */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CommandCodeAttributes.c 1529 2019-11-21 23:29:01Z kgoldman $ */
/* $Id: CommandCodeAttributes.c 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/

View File

@ -3,7 +3,7 @@
/* */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CreateLoaded_fp.h 809 2016-11-16 18:31:54Z kgoldman $ */
/* $Id: CreateLoaded_fp.h 1600 2020-03-30 22:08:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */

View File

@ -3,7 +3,7 @@
/* Self-Test of Cryptographic Functions */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CryptSelfTest.c 1529 2019-11-21 23:29:01Z kgoldman $ */
/* $Id: CryptSelfTest.c 1594 2020-03-26 22:15:48Z 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 - 2020 */
/* */
/********************************************************************************/
@ -171,7 +171,8 @@ CryptIncrementalSelfTest(
return TPM_RC_SUCCESS;
}
/* 10.2.7.2.4 CryptInitializeToTest() */
/* This function will initialize the data structures for testing all the algorithms. */
/* This function will initialize the data structures for testing all the algorithms. This should not
be called unless CryptAlgsSetImplemented() has been called */
void
CryptInitializeToTest(
void

View File

@ -3,7 +3,7 @@
/* Accessing properties for handles of various types */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: Entity.c 1519 2019-11-15 20:43:51Z kgoldman $ */
/* $Id: Entity.c 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/
@ -260,7 +260,7 @@ EntityGetAuthValue(
#ifdef VENDOR_PERMANENT
case VENDOR_PERMANENT:
// vendor authorization value
pAauth = &g_platformUniqueDetails;
pAuth = &g_platformUniqueDetails;
#endif
default:
// If any other permanent handle is present it is

View File

@ -3,7 +3,7 @@
/* ExecCommand */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: ExecCommand.c 1490 2019-07-26 21:13:22Z kgoldman $ */
/* $Id: ExecCommand.c 1600 2020-03-30 22:08: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 - 2020 */
/* */
/********************************************************************************/
@ -83,7 +83,7 @@
// 2) call the routine that performs the command actions; and
// 3) marshal the responses into the response buffer.
// f) If any error occurs in any of the steps above create the error response and return.
// g) Calls BuildResponseSessions() to:
// g) Calls BuildResponseSession() to:
// 1) when necessary, encrypt a parameter
// 2) build the response authorization sessions
// 3) update the audit sessions and nonces

View File

@ -3,7 +3,7 @@
/* Internal Global Type Definitions */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: Global.h 1529 2019-11-21 23:29:01Z kgoldman $ */
/* $Id: Global.h 1600 2020-03-30 22:08: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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/
@ -298,7 +298,7 @@ typedef struct SESSION_ATTRIBUTES
unsigned isBound : 1; //3) SET if the session is bound to with an
// entity. This attribute will be CLEAR
// if either isPolicy or isAudit is SET.
unsigned isCpHashDefined : 1; //3) SET if the cpHash has been defined
unsigned isCpHashDefined : 1; //4) SET if the cpHash has been defined
// This attribute is not SET unless
// 'isPolicy' is SET.
unsigned isAuthValueNeeded : 1; //5) SET if the authValue is required for
@ -620,7 +620,7 @@ EXTERN BOOL g_StartupLocality3;
/* 5.9.10.15 g_daUsed */
/* This location indicates if a DA-protected value is accessed during a boot cycle. If none has,
then there is no need to increment failedTries on the next non-orderly startup. This bit is
merged with gp.orderlyState when that gp.orderly is set to SU_NONE_VALUE */
merged with gp.orderlyState when gp.orderly is set to SU_NONE_VALUE */
/* This global is set to FALSE on startup (after a decision has been made on whether to increment
the failedTries or not). On a first attempt to access a DA protected object: this global is set
@ -873,6 +873,7 @@ typedef struct orderly_data
// that they can be manipulated by ACT number rather than having to access a
// structure.
UINT32 signaledACT;
UINT16 preservedSignaled;
#endif // libtpms added
} ORDERLY_DATA;
#if ACCUMULATE_SELF_HEAL_TIMER

View File

@ -348,10 +348,6 @@ extern "C" {
TPMS_ECC_PARMS_Marshal(TPMS_ECC_PARMS *source, BYTE **buffer, INT32 *size);
UINT16
TPMU_PUBLIC_PARMS_Marshal(TPMU_PUBLIC_PARMS *source, BYTE **buffer, INT32 *size, UINT32 selector);
#if 0 /* libtpms added */
UINT16
TPMT_PUBLIC_PARMS_Marshal(TPMT_PUBLIC_PARMS *source, BYTE **buffer, INT32 *size);
#endif /* libtpms added */
UINT16
TPMT_PUBLIC_Marshal(TPMT_PUBLIC *source, BYTE **buffer, INT32 *size);
UINT16

View File

@ -3,7 +3,7 @@
/* Dynamic space for user defined NV */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: NVDynamic.c 1525 2019-11-18 20:04:03Z kgoldman $ */
/* $Id: NVDynamic.c 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/

View File

@ -146,15 +146,18 @@
// These hash OIDs used in a lot of places.
#define OID_SHA1_VALUE 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A
SHA1_OID(_); // Expands to
// MAKE_OID(_SHA1)
SHA1_OID(_); // Expands to:
// MAKE_OID(_SHA1)
// which expands to:
// extern BYTE OID_SHA1[]
// EXTERN const BYTE OID_SHA1[] INITIALIZER({OID_SHA1_VALUE})
// which, depending on the setting of EXTERN and
// INITIALIZER, expands to either:
// extern const BYTE OID_SHA1[]
// or
// const BYTE OID_SHA1[] = {OID_SHA1_VALUE}
// const BYTE OID_SHA1[] = {OID_SHA1_VALUE}
// which is:
// const BYTE OID_SHA1[] = {0x06, 0x05, 0x2B, 0x0E,
// 0x03, 0x02, 0x1A}
// const BYTE OID_SHA1[] = {0x06, 0x05, 0x2B, 0x0E,
// 0x03, 0x02, 0x1A}
#define OID_SHA256_VALUE NIST_HASH, 1
SHA256_OID(_);
#define OID_SHA384_VALUE NIST_HASH, 2

View File

@ -3,7 +3,7 @@
/* PCR access and manipulation */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: PCR.c 1529 2019-11-21 23:29:01Z kgoldman $ */
/* $Id: PCR.c 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/

View File

@ -3,7 +3,7 @@
/* Platform Authenticated Countdown Timer */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: PlatformACT.c 1529 2019-11-21 23:29:01Z kgoldman $ */
/* $Id: PlatformACT.c 1594 2020-03-26 22:15:48Z 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, 2019 */
/* (c) Copyright IBM Corp. and others, 2019 - 2020 */
/* */
/********************************************************************************/
/* C.16 PlatformACT.c */
@ -170,7 +170,7 @@ ActGetDataPointer(
}
/* C.16.2.3. _plat__ACT_GetImplemented() */
/* This function tests to see if an ACT is implemented. It is a belt and suspenders function because
the TPM should not be calling to to manipulate an ACT that is not implemented. However, this
the TPM should not be calling to manipulate an ACT that is not implemented. However, this
could help the simulator code which doesn't necessarily know if an ACT is implemented or not. */
LIB_EXPORT int
_plat__ACT_GetImplemented(

View File

@ -3,7 +3,7 @@
/* Platform Clock . */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id$ */
/* $Id: PlatformClock.h 1594 2020-03-26 22:15:48Z 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, 2019 */
/* (c) Copyright IBM Corp. and others, 2019 - 2020 */
/* */
/********************************************************************************/
@ -73,7 +73,7 @@
// CLOCK_NOMINAL is the number of hardware ticks per mS. A value of 300000 means that the nominal
// clock rate used to drive the hardware clock is 30 MHz. The adjustment rates are used to determine
// the conversion of the hardware ticks to internal hardware clock value. In practice, we would
// expect that there woudl be a hardware register will accumulated mS. It would be incremented by
// expect that there would be a hardware register will accumulated mS. It would be incremented by
// the output of a pre-scaler. The pre-scaler would divide the ticks from the clock by some value
// that would compensate for the difference between clock time and real time. The code in Clock does
// the emulation of this function.

View File

@ -3,7 +3,7 @@
/* NV read and write access methods */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: Platform_fp.h 1529 2019-11-21 23:29:01Z kgoldman $ */
/* $Id: Platform_fp.h 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/

View File

@ -1,9 +1,9 @@
/********************************************************************************/
/* */
/* */
/* Policy Command Support */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: Policy_spt.c 1490 2019-07-26 21:13:22Z kgoldman $ */
/* $Id: Policy_spt.c 1594 2020-03-26 22:15:48Z 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 - 2020 */
/* */
/********************************************************************************/
@ -216,6 +216,10 @@ PolicyDigestClear(
MemorySet(session->u2.policyDigest.t.buffer, 0,
session->u2.policyDigest.t.size);
}
/* 7.4.2.5 PolicySptCheckCondition() */
/* Checks to see if the condition in the policy is satisfied. */
BOOL
PolicySptCheckCondition(
TPM_EO operation,

View File

@ -3,7 +3,7 @@
/* Manage the session context counter */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: Session.c 1529 2019-11-21 23:29:01Z kgoldman $ */
/* $Id: Session.c 1594 2020-03-26 22:15:48Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,77 +55,16 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/
/* The code in this file is used to manage the session context counter. The scheme implemented here
is a "truncated counter". This scheme allows the TPM to not need TPM_SU_CLEAR for a very long
period of time and still not have the context count for a session repeated. */
/* The counter (contextCounter)in this implementation is a UINT64 but can be smaller. The "tracking
array" (contextArray) only has 16-bits per context. The tracking array is the data that needs to
be saved and restored across TPM_SU_STATE so that sessions are not lost when the system enters
the sleep state. Also, when the TPM is active, the tracking array is kept in RAM making it
important that the number of bytes for each entry be kept as small as possible. */
/* The TPM prevents collisions of these truncated values by not allowing a contextID to be assigned
if it would be the same as an existing value. Since the array holds 16 bits, after a context has
been saved, an additional 2^16-1 contexts may be saved before the count would again match. The
normal expectation is that the context will be flushed before its count value is needed again but
it is always possible to have long-lived sessions. */
/* The contextID is assigned when the context is saved (TPM2_ContextSave()). At that time, the TPM
will compare the low-order 16 bits of contextCounter to the existing values in contextArray and
if one matches, the TPM will return TPM_RC_CONTEXT_GAP (by construction, the entry that contains
the matching value is the oldest context). */
/* The expected remediation by the TRM is to load the oldest saved session context (the one found by
the TPM), and save it. Since loading the oldest session also eliminates its contextID value from
contextArray, there TPM will always be able to load and save the oldest existing context. */
/* In the worst case, software may have to load and save several contexts in order to save an
additional one. This should happen very infrequently. */
/* When the TPM searches contextArray and finds that none of the contextIDs match the low-order
16-bits of contextCount, the TPM can copy the low bits to the contextArray associated with the
session, and increment contextCount. */
/* There is one entry in contextArray for each of the active sessions allowed by the TPM
implementation. This array contains either a context count, an index, or a value indicating the
slot is available (0). */
/* e index into the contextArray is the handle for the session with the region selector byte of the
session set to zero. If an entry in contextArray contains 0, then the corresponding handle may
be assigned to a session. If the entry contains a value that is less than or equal to the number
of loaded sessions for the TPM, then the array entry is the slot in which the context is
loaded. */
/* EXAMPLE: If the TPM allows 8 loaded sessions, then the slot numbers would be 1-8 and a
contextArrary value in that range would represent the loaded session. */
/* NOTE: When the TPM firmware determines that the array entry is for a loaded session, it will
subtract 1 to create the zero-based slot number. */
/* There is one significant corner case in this scheme. When the contextCount is equal to a value
in the contextArray, the oldest session needs to be recycled or flushed. In order to recycle the
session, it must be loaded. To be loaded, there must be an available slot. Rather than require
that a spare slot be available all the time, the TPM will check to see if the contextCount is
equal to some value in the contextArray when a session is created. This prevents the last
session slot from being used when it is likely that a session will need to be recycled. */
/* If a TPM with both 1.2 and 2.0 functionality uses this scheme for both 1.2 and 2.0 sessions, and
the list of active contexts is read with TPM_GetCapabiltiy(), the TPM will create 32-bit
representations of the list that contains 16-bit values (the TPM2_GetCapability() returns a list
of handles for active sessions rather than a list of contextID). The full contextID has
high-order bits that are either the same as the current contextCount or one less. It is one less
if the 16-bits of the contextArray has a value that is larger than the low-order 16 bits of
contextCount. */
/* 8.9.2 Includes, Defines, and Local Variables */
#define SESSION_C
#include "Tpm.h"
/* 8.9.3 File Scope Function -- ContextIdSetOldest() */
/* This function is called when the oldest contextID is being loaded or deleted. Once a saved
context becomes the oldest, it stays the oldest until it is deleted. */
/* Finding the oldest is a bit tricky. It is not just the numeric comparison of values but is
dependent on the value of contextCounter. */
/* 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 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 because it has the lowest value. */
static void
ContextIdSetOldest(
@ -134,7 +73,7 @@ ContextIdSetOldest(
{
CONTEXT_SLOT lowBits;
CONTEXT_SLOT entry;
CONTEXT_SLOT smallest = ((CONTEXT_SLOT)~0); /* Set to the maximum possible */
CONTEXT_SLOT smallest = ((CONTEXT_SLOT)~0);
UINT32 i;
// Set oldestSaveContext to a value indicating none assigned
s_oldestSavedSession = MAX_ACTIVE_SESSIONS + 1;

View File

@ -3,7 +3,7 @@
/* Process the Authorization Sessions */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: SessionProcess.c 1532 2019-11-26 14:28:36Z kgoldman $ */
/* $Id: SessionProcess.c 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/

View File

@ -3,7 +3,7 @@
/* Startup Commands */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: StartupCommands.c 1559 2019-12-19 15:41:01Z kgoldman $ */
/* $Id: StartupCommands.c 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/
@ -149,7 +149,7 @@ TPM2_Startup(
locality = 0;
g_StartupLocality3 = (locality == 3);
#if USE_DA_USED
// If there was no orderly shutdown, then their might have been a write to
// If there was no orderly shutdown, then there might have been a write to
// failedTries that didn't get recorded but only if g_daUsed was SET in the
// shutdown state
g_daUsed = (gp.orderlyState == SU_DA_USED_VALUE);

View File

@ -93,7 +93,7 @@ const SYMMETRIC_TEST_VECTOR c_symTestValues[NUM_SYMS + 1] = {
{dataOut_AES256_CTR, dataOut_AES256_OFB, dataOut_AES256_CBC,
dataOut_AES256_CFB, dataOut_AES256_ECB}},
#endif
#if ALG_SM4 && SM4_128
#if ALG_SM4 && SM4_128 // libtpms activated
{ALG_SM4_VALUE, 128, key_SM4128, 16, sizeof(dataIn_SM4128), dataIn_SM4128,
{dataOut_SM4128_CTR, dataOut_SM4128_OFB, dataOut_SM4128_CBC,
dataOut_SM4128_CFB, dataOut_AES128_ECB}},

View File

@ -3,7 +3,7 @@
/* Process the commands */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: TPMCmdp.c 1519 2019-11-15 20:43:51Z kgoldman $ */
/* $Id: TPMCmdp.c 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/

View File

@ -3,7 +3,7 @@
/* Root header file for building any TPM.lib code */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: Tpm.h 1490 2019-07-26 21:13:22Z kgoldman $ */
/* $Id: Tpm.h 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/

View File

@ -63,7 +63,7 @@
// This file contains the algorithm values from the TCG Algorithm Registry.
#ifndef _TPM_ALGORITHM_DEFINES_H_
#define _TPM_ALGORITHM_DEFINES_H_
// Table 2:3 - Definition of Base Types Base Types are in BaseTypes.h
// Table 2:3 - Definition of Base Types
#define ECC_CURVES \
{TPM_ECC_BN_P256, TPM_ECC_BN_P638, TPM_ECC_NIST_P192, \
TPM_ECC_NIST_P224, TPM_ECC_NIST_P256, TPM_ECC_NIST_P384, \

View File

@ -3,7 +3,7 @@
/* Build Switches */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: TpmBuildSwitches.h 1529 2019-11-21 23:29:01Z kgoldman $ */
/* $Id: TpmBuildSwitches.h 1594 2020-03-26 22:15:48Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/

View File

@ -64,7 +64,7 @@
#ifndef TPMTYPES_H
#define TPMTYPES_H
/* Table 1:2 - Definition of TPM_ALG_ID Constants */
/* TCG Algorithm Registry: Table 1:2 - Definition of TPM_ALG_ID Constants */
typedef UINT16 TPM_ALG_ID;
#define TYPE_OF_TPM_ALG_ID UINT16
@ -157,7 +157,7 @@ typedef UINT16 TPM_ALG_ID;
#define ALG_LAST_VALUE 0x0044
#define TPM_ALG_LAST (TPM_ALG_ID)(ALG_LAST_VALUE)
/* Table 1:3 - Definition of TPM_ECC_CURVE Constants */
/* TCG Algorithm Registry: Table 1:3 - Definition of TPM_ECC_CURVE Constants */
typedef UINT16 TPM_ECC_CURVE;
#define TYPE_OF_TPM_ECC_CURVE UINT16
#define TPM_ECC_NONE (TPM_ECC_CURVE)(0x0000)
@ -170,7 +170,7 @@ typedef UINT16 TPM_ECC_CURVE;
#define TPM_ECC_BN_P638 (TPM_ECC_CURVE)(0x0011)
#define TPM_ECC_SM2_P256 (TPM_ECC_CURVE)(0x0020)
/* Table 2:12 - Definition of TPM_CC Constants */
/* TPM 2.0 Part 2: Table 2:12 - Definition of TPM_CC Constants */
typedef UINT32 TPM_CC;
#define TYPE_OF_TPM_CC UINT32
#define TPM_CC_NV_UndefineSpaceSpecial (TPM_CC)(0x0000011F)
@ -805,6 +805,7 @@ typedef UINT32 TPMA_ALGORITHM;
#define TPMA_ALGORITHM_method ((TPMA_ALGORITHM)1 << 10)
#define TPMA_ALGORITHM_reserved 0xfffff8f0
// This is the initializer for a TPMA_ALGORITHM bit array.
#define TPMA_ALGORITHM_INITIALIZER( \
asymmetric, symmetric, hash, object, bits_at_4, \
signing, encrypting, method, bits_at_11) \

View File

@ -158,7 +158,8 @@ TPM_KEY_BITS_Unmarshal(TPM_KEY_BITS *target, BYTE **buffer, INT32 *size)
}
/* Table 7 - Definition of (UINT32) TPM_GENERATED Constants <O> */
#if 0 // libtpms added
#if 0
TPM_RC
TPM_GENERATED_Unmarshal(TPM_GENERATED *target, BYTE **buffer, INT32 *size)
{
@ -174,7 +175,7 @@ TPM_GENERATED_Unmarshal(TPM_GENERATED *target, BYTE **buffer, INT32 *size)
}
return rc;
}
#endif // libtpms added
#endif
/* Table 9 - Definition of (UINT16) TPM_ALG_ID Constants <IN/OUT, S> */

View File

@ -3,7 +3,7 @@
/* TPM X509 ECC */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: X509_ECC.c 1519 2019-11-15 20:43:51Z kgoldman $ */
/* $Id: X509_ECC.c 1594 2020-03-26 22:15:48Z 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, 2019 */
/* (c) Copyright IBM Corp. and others, 2019 - 2020 */
/* */
/********************************************************************************/
@ -65,9 +65,9 @@
#include "X509.h"
#include "OIDs.h"
#include "TpmAsn1_fp.h"
#include "X509_ECC_fp.h"
#include "X509_spt_fp.h"
#include "CryptHash_fp.h"
#include "X509_ECC_fp.h" /* kgold */
/* 10.2.24.2 Functions */
/* 10.2.24.2.1 X509PushPoint() */

View File

@ -3,7 +3,7 @@
/* TPM X509 RSA */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: X509_RSA.c 1519 2019-11-15 20:43:51Z kgoldman $ */
/* $Id: X509_RSA.c 1594 2020-03-26 22:15:48Z 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, 2019 */
/* (c) Copyright IBM Corp. and others, 2019 - 2020 */
/* */
/********************************************************************************/
@ -64,10 +64,10 @@
#include "Tpm.h"
#include "X509.h"
#include "TpmAsn1_fp.h"
#include "X509_RSA_fp.h"
#include "X509_spt_fp.h"
#include "CryptHash_fp.h"
#include "CryptRsa_fp.h"
#include "X509_RSA_fp.h" /* kgold */
/* 10.2.25.2 Functions */
#if ALG_RSA
@ -216,16 +216,6 @@ X509AddPublicRSA(
{
UINT32 exp = object->publicArea.parameters.rsaDetail.exponent;
//
/*
SEQUENCE (2 elem) 1st
SEQUENCE (2 elem) 2nd
OBJECT IDENTIFIER 1.2.840.113549.1.1.1 rsaEncryption (PKCS #1)
NULL
BIT STRING (1 elem)
SEQUENCE (2 elem) 3rd
INTEGER (2048 bit) 2197304513741227955725834199357401
INTEGER 65537
*/
// If this is a check to see if the key can be encoded, it can.
// Need to mark the end sequence
if(ctx == NULL)

View File

@ -306,10 +306,6 @@ X509PushAlgorithmIdentifierSequence(
const BYTE *OID
)
{
// An algorithm ID sequence is:
// SEQUENCE
// OID
// NULL
ASN1StartMarshalContext(ctx); // hash algorithm
ASN1PushNull(ctx);
ASN1PushOID(ctx, OID);

View File

@ -65,6 +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.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

View File

@ -3,7 +3,7 @@
/* Functions that are used for the two-phase, ECC, key-exchange protocols */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CryptEccKeyExchange.c 1370 2018-11-02 19:39:07Z kgoldman $ */
/* $Id: CryptEccKeyExchange.c 1594 2020-03-26 22:15:48Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -61,17 +61,16 @@
/* 10.2.11 CryptEccKeyExchange.c */
#include "Tpm.h"
/* libtpms added begin */
LIB_EXPORT TPM_RC
SM2KeyExchange(
TPMS_ECC_POINT *outZ, // OUT: the computed point
TPM_ECC_CURVE curveId, // IN: the curve for the computations
TPM2B_ECC_PARAMETER *dsAIn, // IN: static private TPM key
TPM2B_ECC_PARAMETER *deAIn, // IN: ephemeral private TPM key
TPMS_ECC_POINT *QsBIn, // IN: static public party B key
TPMS_ECC_POINT *QeBIn // IN: ephemeral public party B key
);
/* libtpms added end */
TPMS_ECC_POINT *outZ, // OUT: the computed point
TPM_ECC_CURVE curveId, // IN: the curve for the computations
TPM2B_ECC_PARAMETER *dsAIn, // IN: static private TPM key
TPM2B_ECC_PARAMETER *deAIn, // IN: ephemeral private TPM key
TPMS_ECC_POINT *QsBIn, // IN: static public party B key
TPMS_ECC_POINT *QeBIn // IN: ephemeral public party B key
);
#if CC_ZGen_2Phase == YES
#if ALG_ECMQV

View File

@ -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 1532 2019-11-26 14:28:36Z kgoldman $ */
/* $Id: CryptRand.c 1603 2020-04-03 17:48:43Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -638,7 +638,9 @@ DRBG_InstantiateSeeded(
return TPM_RC_SUCCESS;
}
/* 10.2.16.3.7 CryptRandStartup() */
/* This function is called when TPM_Startup() is executed. This function always returns TRUE. */
/* This function is called when TPM_Startup() is executed. */
/* TRUE instantiation succeeded */ /* kgold */
/* FALSE instantiation failed */
LIB_EXPORT BOOL
CryptRandStartup(
void
@ -646,18 +648,16 @@ CryptRandStartup(
{
#if ! _DRBG_STATE_SAVE
// If not saved in NV, re-instantiate on each startup
return DRBG_Instantiate(&drbgDefault, 0, NULL); // libtpms changed; return BOOL
return DRBG_Instantiate(&drbgDefault, 0, NULL); /* kgold; libtpms return BOOL */
#else
// If the running state is saved in NV, NV has to be loaded before it can
// be updated
if(go.drbgState.magic == DRBG_MAGIC)
return DRBG_Reseed(&go.drbgState, NULL, NULL); // libtpms changed; return BOOL
return DRBG_Reseed(&go.drbgState, NULL, NULL); /* kgold; libtpms return BOOL */
else
return DRBG_Instantiate(&go.drbgState, 0, NULL); // libtpms changed; return BOOL
return DRBG_Instantiate(&go.drbgState, 0, NULL); /* kgold; libtpms return BOOL */
#endif
#if 0
return TRUE;
#endif
}
/* 10.2.16.3.8 CryptRandInit() */
/* This function is called when _TPM_Init() is being processed */

View File

@ -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 1519 2019-11-15 20:43:51Z kgoldman $ */
/* $Id: LibSupport.h 1603 2020-04-03 17:48:43Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/
@ -65,11 +65,14 @@
#define _LIB_SUPPORT_H_
#if 0 // libtpms added
/* kgold added power and s390 */
#ifndef RADIX_BITS
# if defined(__x86_64__) || defined(__x86_64) \
|| defined(__amd64__) || defined(__amd64) || defined(_WIN64) || defined(_M_X64) \
|| defined(_M_ARM64) || defined(__aarch64__) \
|| defined(__powerpc64__) || defined(__ppc64__)
|| defined(__amd64__) || defined(__amd64) \
|| defined(_WIN64) || defined(_M_X64) \
|| defined(_M_ARM64) || defined(__aarch64__) \
|| defined(__powerpc64__) || defined(__ppc64__) \
|| defined(__s390x__)
# define RADIX_BITS 64
# elif defined(__i386__) || defined(__i386) || defined(i386) \
|| defined(_WIN32) || defined(_M_IX86) \
@ -85,7 +88,7 @@
#define LIB_QUOTE(_STRING_) #_STRING_
#define LIB_INCLUDE2(_LIB_, _TYPE_) LIB_QUOTE(TpmTo##_LIB_##_TYPE_.h)
#define LIB_INCLUDE(_LIB_, _TYPE_) LIB_INCLUDE2(_LIB_, _TYPE_)
// Include the options for hashing and symmetric. Defer the load of the math package Until the
// Include the options for hashing and symmetric. Defer the load of the math package until the
// bignum parameters are defined.
#include LIB_INCLUDE(SYM_LIB, Sym)
#include LIB_INCLUDE(HASH_LIB, Hash)

View File

@ -3,7 +3,7 @@
/* TPM to OpenSSL BigNum Shim Layer */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: TpmToOsslMath.c 1519 2019-11-15 20:43:51Z kgoldman $ */
/* $Id: TpmToOsslMath.c 1598 2020-03-27 21:59:49Z 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 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* */
/********************************************************************************/
@ -82,13 +82,6 @@
#ifdef MATH_LIB_OSSL
#include "TpmToOsslMath_fp.h"
#if 0 // libtpms added
#if OPENSSL_VERSION_NUMBER < 0x10101000 /* kgold */
#define EC_POINT_set_affine_coordinates(a,b,c,d,e) EC_POINT_set_affine_coordinates_GFp(a,b,c,d,e)
#define EC_POINT_get_affine_coordinates(a,b,c,d,e) EC_POINT_get_affine_coordinates_GFp(a,b,c,d,e)
#endif
#endif // libtpms added
/* B.2.3.2.3.1. OsslToTpmBn() */
/* This function converts an OpenSSL BIGNUM to a TPM bignum. In this implementation it is assumed
that OpenSSL uses a different control structure but the same data layout -- an array of
@ -533,9 +526,9 @@ EcPointInitialized(
{
BIG_INITIALIZED(bnX, initializer->x);
BIG_INITIALIZED(bnY, initializer->y);
if(E == NULL) // libtpms changed begin (check E before accessing)
if(E == NULL)
FAIL(FATAL_ERROR_ALLOCATION);
P = EC_POINT_new(E->G); // libtpms changed end
P = EC_POINT_new(E->G);
#if defined(OPENSSL_API_COMPAT) && OPENSSL_API_COMPAT >= 0x10200000L // libtpms added begin
if(!EC_POINT_set_affine_coordinates(E->G, P, bnX, bnY, E->CTX))
#else // libtpms added end

View File

@ -78,14 +78,17 @@
#elif OPENSSL_VERSION_NUMBER >= 0x10100000L
// from crypto/bn/bn_lcl.h
struct bignum_st {
BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit
* chunks. */
BN_ULONG *d;
int top; /* Index of last used d +1. */
/* The next are internal book keeping for bn_expand. */
int dmax; /* Size of the d array. */
int neg; /* one if the number is negative */
int flags;
};
#if 0 // libtpms added
# define EC_POINT_get_affine_coordinates EC_POINT_get_affine_coordinates_GFp
# define EC_POINT_set_affine_coordinates EC_POINT_set_affine_coordinates_GFp
#endif // libtpms added
#endif // OPENSSL_VERSION_NUMBER
#endif // libtpms added
#include <openssl/bn.h>