mirror of
https://github.com/stefanberger/libtpms
synced 2026-08-10 02:21:14 +00:00
tpm2: Mark all libtpms changes with comments
Mark all libtpms changes with comments for easy identification when diff'ing with the original TPM code. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
parent
2bfed46bbc
commit
3cd5a386f5
@ -296,6 +296,7 @@ BnPointTo2B(
|
||||
}
|
||||
#endif // TPM_ALG_ECC
|
||||
|
||||
/* libtpms added begin */
|
||||
LIB_EXPORT int
|
||||
Bn2bin(bigConst bn,
|
||||
unsigned char *buffer,
|
||||
@ -332,4 +333,4 @@ Bn2bin(bigConst bn,
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/* libtpms added end */
|
||||
@ -76,6 +76,7 @@
|
||||
#include "TpmFail_fp.h"
|
||||
#include <assert.h>
|
||||
|
||||
/* libtpms added begin */
|
||||
/* ClockGetTime -- get time given a specified clock type */
|
||||
uint64_t
|
||||
ClockGetTime(
|
||||
@ -115,6 +116,7 @@ ClockAdjustPostResume(UINT64 backthen, BOOL timesAreRealtime)
|
||||
s_suspendedElapsedTime += timediff;
|
||||
}
|
||||
}
|
||||
/* libtpms added end */
|
||||
|
||||
/* C.3.3. Simulator Functions */
|
||||
/* C.3.3.1. Introduction */
|
||||
@ -134,8 +136,8 @@ _plat__TimerReset(
|
||||
s_adjustRate = CLOCK_NOMINAL;
|
||||
s_timerReset = TRUE;
|
||||
s_timerStopped = TRUE;
|
||||
s_hostMonotonicAdjustTime = 0; /* libtpms */
|
||||
s_suspendedElapsedTime = 0; /* libtpms */
|
||||
s_hostMonotonicAdjustTime = 0; /* libtpms added */
|
||||
s_suspendedElapsedTime = 0; /* libtpms added */
|
||||
return;
|
||||
}
|
||||
/* C.3.3.3. _plat__TimerRestart() */
|
||||
@ -182,6 +184,7 @@ _plat__RealTime(
|
||||
clock_gettime(CLOCK_MONOTONIC, &systime);
|
||||
time = (clock64_t)systime.tv_sec * 1000 + (systime.tv_nsec / 1000000);
|
||||
#endif
|
||||
/* libtpms added begin */
|
||||
/* We have to make sure that this function returns monotonically increasing time
|
||||
also when a vTPM has been suspended and the host has been rebooted.
|
||||
Example:
|
||||
@ -192,6 +195,7 @@ _plat__RealTime(
|
||||
If it was suspended for 10 time units, we need to add '10' here.
|
||||
*/
|
||||
time += s_hostMonotonicAdjustTime + s_suspendedElapsedTime;
|
||||
/* libtpms added end */
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
@ -118,6 +118,7 @@
|
||||
# define WINAPI
|
||||
#endif
|
||||
# define __pragma(x)
|
||||
/* libtpms added begin */
|
||||
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 2)
|
||||
# define REVERSE_ENDIAN_16(_Number) __builtin_bswap16(_Number)
|
||||
# define REVERSE_ENDIAN_32(_Number) __builtin_bswap32(_Number)
|
||||
@ -142,6 +143,7 @@
|
||||
# error Unsupported OS
|
||||
# endif
|
||||
# endif
|
||||
/* libtpms added end */
|
||||
#endif
|
||||
#if defined(__GNUC__)
|
||||
# define NORETURN __attribute__((noreturn))
|
||||
|
||||
@ -65,7 +65,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/rand.h> /* libtpms added */
|
||||
|
||||
#include "PlatformData.h"
|
||||
#include "Platform_fp.h"
|
||||
@ -126,10 +126,11 @@ _plat__GetEntropy(
|
||||
uint32_t rndNum;
|
||||
int32_t ret;
|
||||
//
|
||||
// libtpms added:
|
||||
// libtpms added begin
|
||||
if (amount > 0 && RAND_bytes(entropy, amount) == 1)
|
||||
return amount;
|
||||
// fall back to 'original' method
|
||||
// libtpms added end
|
||||
|
||||
if(amount == 0)
|
||||
{
|
||||
|
||||
@ -115,7 +115,7 @@ TPMA_SESSION s_attributes[MAX_SESSION_NUM];
|
||||
TPM_HANDLE s_associatedHandles[MAX_SESSION_NUM];
|
||||
TPM2B_NONCE s_nonceCaller[MAX_SESSION_NUM];
|
||||
TPM2B_AUTH s_inputAuthValues[MAX_SESSION_NUM];
|
||||
//SESSION *s_usedSessions[MAX_SESSION_NUM];
|
||||
//SESSION *s_usedSessions[MAX_SESSION_NUM]; /* libtpms changed (not needed) */
|
||||
UINT32 s_encryptSessionIndex;
|
||||
UINT32 s_decryptSessionIndex;
|
||||
UINT32 s_auditSessionIndex;
|
||||
|
||||
@ -123,7 +123,7 @@ typedef UINT32 CLOCK_NONCE;
|
||||
OBJECT_ATTRIBUTES is used in the definition of the OBJECT data type. */
|
||||
typedef struct
|
||||
{
|
||||
#if LITTLE_ENDIAN_TPM == YES
|
||||
#if LITTLE_ENDIAN_TPM == YES /* libtpms added */
|
||||
unsigned publicOnly : 1; //0) SET if only the public portion of
|
||||
// an object is loaded
|
||||
unsigned epsHierarchy : 1; //1) SET if the object belongs to EPS
|
||||
@ -161,9 +161,9 @@ typedef struct
|
||||
// parent
|
||||
unsigned external : 1; //17) SET when the object is loaded with
|
||||
// TPM2_LoadExternal();
|
||||
unsigned reserved : 14; //18-31)
|
||||
#endif
|
||||
#if BIG_ENDIAN_TPM == YES
|
||||
unsigned reserved : 14; //18-31) /* libtpms added */
|
||||
#endif /* libtpms added */
|
||||
#if BIG_ENDIAN_TPM == YES /* libtpms added begin */
|
||||
unsigned reserved : 14; //18-31)
|
||||
unsigned external : 1; //17) SET when the object is loaded with
|
||||
unsigned derivation : 1; //16) SET when the key is a derivation
|
||||
@ -184,7 +184,7 @@ typedef struct
|
||||
unsigned ppsHierarchy : 1; //2) SET if the object belongs to PPS
|
||||
unsigned epsHierarchy : 1; //1) SET if the object belongs to EPS
|
||||
unsigned publicOnly : 1; //0) SET if only the public portion of
|
||||
#endif
|
||||
#endif /* libtpms added end */
|
||||
} OBJECT_ATTRIBUTES;
|
||||
/* An OBJECT structure holds the object public, sensitive, and meta-data associated. This structure
|
||||
is implementation dependent. For this implementation, the structure is not optimized for space
|
||||
@ -210,7 +210,7 @@ typedef struct OBJECT
|
||||
TPM2B_NAME name; // Name of the object name. Kept here
|
||||
// to avoid repeatedly computing it.
|
||||
|
||||
// libtpms: OBJECT lies in NVRAM; to avoid that it needs different number
|
||||
// libtpms added: OBJECT lies in NVRAM; to avoid that it needs different number
|
||||
// of bytes on 32 bit and 64 bit architectures, we need to make sure it's the
|
||||
// same size; simple padding at the end works here
|
||||
UINT32 _pad;
|
||||
@ -255,7 +255,7 @@ typedef UINT32 AUTH_ROLE;
|
||||
within the SESSION structure. */
|
||||
typedef struct SESSION_ATTRIBUTES
|
||||
{
|
||||
#if LITTLE_ENDIAN_TPM == YES
|
||||
#if LITTLE_ENDIAN_TPM == YES /* libtpms added */
|
||||
unsigned isPolicy : 1; //1) SET if the session may only be used
|
||||
// for policy
|
||||
unsigned isAudit : 1; //2) SET if the session is used for audit
|
||||
@ -303,9 +303,9 @@ typedef struct SESSION_ATTRIBUTES
|
||||
unsigned isTemplateSet : 1; //14) SET if the templateHash needs to be
|
||||
// checked for Create, CreatePrimary, or
|
||||
// CreateLoaded.
|
||||
unsigned _reserved : 18; //15-32
|
||||
#endif
|
||||
#if BIG_ENDIAN_TPM == YES
|
||||
unsigned _reserved : 18; //15-32 /* libtpms added */
|
||||
#endif /* libtpms added */
|
||||
#if BIG_ENDIAN_TPM == YES /* libtpms added begin */
|
||||
unsigned _reserved : 18; //15-32
|
||||
unsigned isTemplateSet : 1; //14) SET if the templateHash needs to be
|
||||
unsigned nvWrittenState : 1; //13) SET if TPMA_NV_WRITTEN is required to
|
||||
@ -321,7 +321,7 @@ typedef struct SESSION_ATTRIBUTES
|
||||
unsigned isBound : 1; //3) SET if the session is bound to with an
|
||||
unsigned isAudit : 1; //2) SET if the session is used for audit
|
||||
unsigned isPolicy : 1; //1) SET if the session may only be used
|
||||
#endif
|
||||
#endif /* libtpms added end */
|
||||
} SESSION_ATTRIBUTES;
|
||||
/* The SESSION structure contains all the context of a session except for the associated
|
||||
contextID. */
|
||||
@ -882,6 +882,10 @@ extern STATE_RESET_DATA gr;
|
||||
/* c) a STATE_CLEAR_DATA structure */
|
||||
/* d) an ORDERLY_DATA structure */
|
||||
/* e) the user defined NV index space */
|
||||
|
||||
/* libtpms added: to put certain data structure at fixed offsets
|
||||
* to give the ones below some room to expand
|
||||
*/
|
||||
#define NV_ROUNDUP(VAL, SIZE) \
|
||||
( ( (VAL) + (SIZE) - 1 ) / (SIZE) ) * (SIZE)
|
||||
|
||||
@ -890,7 +894,7 @@ extern STATE_RESET_DATA gr;
|
||||
#define NV_STATE_CLEAR_DATA (NV_STATE_RESET_DATA + sizeof(STATE_RESET_DATA))
|
||||
#define NV_ORDERLY_DATA (NV_STATE_CLEAR_DATA + sizeof(STATE_CLEAR_DATA))
|
||||
#define NV_INDEX_RAM_DATA NV_ROUNDUP(NV_ORDERLY_DATA + sizeof(ORDERLY_DATA),\
|
||||
1024)
|
||||
1024) /* libtpms added */
|
||||
#define NV_USER_DYNAMIC (NV_INDEX_RAM_DATA + sizeof(s_indexOrderlyRam))
|
||||
#define NV_USER_DYNAMIC_END NV_MEMORY_SIZE
|
||||
/* 5.10.13 Global Macro Definitions */
|
||||
@ -909,22 +913,22 @@ extern STATE_RESET_DATA gr;
|
||||
GetClosestCommandIndex(). */
|
||||
typedef UINT16 COMMAND_INDEX;
|
||||
#define UNIMPLEMENTED_COMMAND_INDEX ((COMMAND_INDEX)(~0))
|
||||
#if 0
|
||||
#if 0 /* libtpms added */
|
||||
typedef struct _COMMAND_FLAGS_
|
||||
{
|
||||
#if LITTLE_ENDIAN_TPM == YES
|
||||
#if LITTLE_ENDIAN_TPM == YES /* libtpms added */
|
||||
unsigned trialPolicy : 1; //1) If SET, one of the handles references a
|
||||
// trial policy and authorization may be
|
||||
// skipped. This is only allowed for a policy
|
||||
// command.
|
||||
unsigned reserved : 31; //2-31)
|
||||
unsigned reserved : 31; //2-31) /* libtpms added begin */
|
||||
#endif
|
||||
#if BIG_ENDIAN_TPM == YES
|
||||
unsigned reserved : 31; //2-31)
|
||||
unsigned trialPolicy : 1; //1) If SET, one of the handles references a
|
||||
#endif
|
||||
#endif /* libtpms added end */
|
||||
} COMMAND_FLAGS;
|
||||
#endif
|
||||
#endif /* libtpms added */
|
||||
/* This structure is used to avoid having to manage a large number of parameters being passed
|
||||
through various levels of the command input processing. */
|
||||
typedef struct _COMMAND_
|
||||
|
||||
@ -85,16 +85,16 @@
|
||||
#endif // SELF_TEST
|
||||
/* 5.11.3 For Failures */
|
||||
#if defined _POSIX_
|
||||
# define FUNCTION_NAME __func__
|
||||
# define FUNCTION_NAME __func__ /* libtpms changed */
|
||||
#else
|
||||
# define FUNCTION_NAME __FUNCTION__
|
||||
#endif
|
||||
#if !FAIL_TRACE
|
||||
# define FAIL(errorCode) (TpmFail(errorCode))
|
||||
# define FAIL_NOCMD(errorCode) (TpmSetFailureMode(errorCode)
|
||||
# define FAIL_NOCMD(errorCode) (TpmSetFailureMode(errorCode) /* libtpms added */
|
||||
#else
|
||||
# define FAIL(errorCode) (TpmFail(FUNCTION_NAME, __LINE__, errorCode))
|
||||
# define FAIL_NOCMD(errorCode) (TpmSetFailureMode(FUNCTION_NAME, __LINE__, errorCode))
|
||||
# define FAIL_NOCMD(errorCode) (TpmSetFailureMode(FUNCTION_NAME, __LINE__, errorCode)) /* libtpms added */
|
||||
#endif
|
||||
/* If implementation is using longjmp, then the call to TpmFail() does not return and the compiler
|
||||
will complain about unreachable code that comes after. To allow for not having longjmp, TpmFail()
|
||||
|
||||
@ -82,7 +82,7 @@
|
||||
#define SET 1
|
||||
#define CLEAR 0
|
||||
/* From Vendor-Specific: Table 1 - Defines for Processor Values */
|
||||
#if defined __FreeBSD__ || defined __DragonFly__
|
||||
#if defined __FreeBSD__ || defined __DragonFly__ /* libtpms added begin */
|
||||
# include <sys/endian.h>
|
||||
#elif defined __APPLE__
|
||||
# include <libkern/OSByteOrder.h>
|
||||
@ -109,7 +109,7 @@
|
||||
#define LITTLE_ENDIAN_TPM YES
|
||||
#else
|
||||
#error Unsupported OS
|
||||
#endif
|
||||
#endif /* libtpms added end */
|
||||
#ifndef BIG_ENDIAN_TPM
|
||||
#define BIG_ENDIAN_TPM NO
|
||||
#endif
|
||||
@ -154,14 +154,14 @@
|
||||
MAX(CAMELLIA_128_BLOCK_SIZE_BYTES, 0)
|
||||
|
||||
/* From Vendor-Specific: Table 4 - Defines for Implemented Curves */
|
||||
#define ECC_NIST_P192 YES
|
||||
#define ECC_NIST_P224 YES
|
||||
#define ECC_NIST_P192 YES /* libtpms enabled */
|
||||
#define ECC_NIST_P224 YES /* libtpms enabled */
|
||||
#define ECC_NIST_P256 YES
|
||||
#define ECC_NIST_P384 YES
|
||||
#define ECC_NIST_P521 YES
|
||||
#define ECC_NIST_P521 YES /* libtpms enabled */
|
||||
#define ECC_BN_P256 YES
|
||||
#define ECC_BN_P638 YES
|
||||
#define ECC_SM2_P256 YES
|
||||
#define ECC_BN_P638 YES /* libtpms enabled */
|
||||
#define ECC_SM2_P256 YES /* libtpms enabled */
|
||||
#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, TPM_ECC_NIST_P521, TPM_ECC_SM2_P256}
|
||||
@ -185,7 +185,7 @@
|
||||
|
||||
/* From Vendor-Specific: Table 7 - Defines for Implementation Values */
|
||||
#define FIELD_UPGRADE_IMPLEMENTED NO
|
||||
#ifdef TPM_POSIX
|
||||
#ifdef TPM_POSIX /* libtpms added begin */
|
||||
# include <openssl/bn.h>
|
||||
# ifdef THIRTY_TWO_BIT
|
||||
# define RADIX_BITS 32
|
||||
@ -198,8 +198,9 @@
|
||||
# endif
|
||||
#endif
|
||||
#ifdef TPM_WINDOWS
|
||||
#define RADIX_BITS 32 /* kgold */
|
||||
#define RADIX_BITS 32 /* kgold */ /* libtpms added end */
|
||||
#endif
|
||||
|
||||
#define HASH_ALIGNMENT 4
|
||||
#define SYMMETRIC_ALIGNMENT 4
|
||||
#define HASH_LIB OSSL
|
||||
@ -226,7 +227,7 @@
|
||||
#define MAX_NV_INDEX_SIZE 2048
|
||||
#define MAX_NV_BUFFER_SIZE 1024
|
||||
#define MAX_CAP_BUFFER 1024
|
||||
#define NV_MEMORY_SIZE (128 * 1024)
|
||||
#define NV_MEMORY_SIZE (128 * 1024) /* libtpms changed */
|
||||
#define MIN_COUNTER_INDICES 8
|
||||
#define NUM_STATIC_PCR 16
|
||||
#define MAX_ALG_LIST_SIZE 64
|
||||
@ -234,8 +235,8 @@
|
||||
#define CONTEXT_ENCRYPT_ALGORITHM AES
|
||||
#define NV_CLOCK_UPDATE_INTERVAL 12
|
||||
#define NUM_POLICY_PCR 1
|
||||
#define MAX_COMMAND_SIZE TPM2_GetBufferSize()
|
||||
#define MAX_RESPONSE_SIZE TPM2_GetBufferSize()
|
||||
#define MAX_COMMAND_SIZE TPM2_GetBufferSize() /* libtpms changed */
|
||||
#define MAX_RESPONSE_SIZE TPM2_GetBufferSize() /* libtpms changed */
|
||||
#define ORDERLY_BITS 8
|
||||
#define MAX_SYM_DATA 128
|
||||
#define MAX_RNG_ENTROPY_SIZE 64
|
||||
@ -260,12 +261,12 @@
|
||||
#define ALG_ECDAA (ALG_YES && ALG_ECC)
|
||||
#define ALG_ECDH (ALG_YES && ALG_ECC)
|
||||
#define ALG_ECDSA (ALG_YES && ALG_ECC)
|
||||
#define ALG_ECMQV (ALG_YES && ALG_ECC)
|
||||
#define ALG_ECMQV (ALG_YES && ALG_ECC) /* libtpms enabled */
|
||||
#define ALG_ECSCHNORR (ALG_YES && ALG_ECC)
|
||||
#define ALG_HMAC ALG_YES
|
||||
#define ALG_KDF1_SP800_108 ALG_YES
|
||||
#define ALG_KDF1_SP800_56A (ALG_YES && ALG_ECC)
|
||||
#define ALG_KDF2 ALG_YES
|
||||
#define ALG_KDF2 ALG_YES /* libtpms enabled */
|
||||
#define ALG_KEYEDHASH ALG_YES
|
||||
#define ALG_MGF1 ALG_YES
|
||||
#define ALG_OAEP (ALG_YES && ALG_RSA)
|
||||
@ -279,11 +280,11 @@
|
||||
#define ALG_SHA256 ALG_YES
|
||||
#define ALG_SHA384 ALG_YES
|
||||
#define ALG_SHA512 ALG_YES
|
||||
#define ALG_SM2 (ALG_YES && ALG_ECC)
|
||||
#define ALG_SM2 (ALG_YES && ALG_ECC) /* libtpms enabled */
|
||||
#define ALG_SM3_256 ALG_NO
|
||||
#define ALG_SM4 ALG_NO
|
||||
#define ALG_SYMCIPHER ALG_YES
|
||||
#define ALG_TDES ALG_YES
|
||||
#define ALG_TDES ALG_YES /* libtpms enabled */
|
||||
#define ALG_XOR ALG_YES
|
||||
|
||||
/* From TCG Algorithm Registry: Table 2 - Definition of TPM_ALG_ID Constants */
|
||||
|
||||
@ -335,7 +335,7 @@ UINT16
|
||||
TPMA_SESSION_Marshal(TPMA_SESSION *source, BYTE **buffer, INT32 *size)
|
||||
{
|
||||
UINT16 written = 0;
|
||||
written += UINT8_Marshal((UINT8 *)source, buffer, size);
|
||||
written += UINT8_Marshal((UINT8 *)source, buffer, size); /* libtpms changed */
|
||||
return written;
|
||||
}
|
||||
|
||||
@ -345,7 +345,7 @@ UINT16
|
||||
TPMA_LOCALITY_Marshal(TPMA_LOCALITY *source, BYTE **buffer, INT32 *size)
|
||||
{
|
||||
UINT16 written = 0;
|
||||
written += UINT8_Marshal((UINT8 *)source, buffer, size);
|
||||
written += UINT8_Marshal((UINT8 *)source, buffer, size); /* libtpms changed */
|
||||
return written;
|
||||
}
|
||||
|
||||
@ -1369,6 +1369,7 @@ TPMS_SIG_SCHEME_ECDAA_Marshal(TPMS_SIG_SCHEME_ECDAA *source, BYTE **buffer, INT3
|
||||
written += TPMS_SCHEME_ECDAA_Marshal(source, buffer, size);
|
||||
return written;
|
||||
}
|
||||
/* libtpms added begin */
|
||||
UINT16
|
||||
TPMS_SIG_SCHEME_SM2_Marshal(TPMS_SIG_SCHEME_SM2 *source, BYTE **buffer, INT32 *size)
|
||||
{
|
||||
@ -1376,6 +1377,7 @@ TPMS_SIG_SCHEME_SM2_Marshal(TPMS_SIG_SCHEME_SM2 *source, BYTE **buffer, INT32 *s
|
||||
written += TPMS_SCHEME_HASH_Marshal(source, buffer, size);
|
||||
return written;
|
||||
}
|
||||
/* libtpms added end */
|
||||
|
||||
/* Table 2:153 - Definition of Types for Encryption Schemes (TypedefTable()) */
|
||||
|
||||
@ -1795,6 +1797,7 @@ TPMS_SIGNATURE_ECDAA_Marshal(TPMS_SIGNATURE_ECDAA *source, BYTE **buffer, INT32
|
||||
return written;
|
||||
}
|
||||
|
||||
/* libtpms added begin */
|
||||
UINT16
|
||||
TPMS_SIGNATURE_SM2_Marshal(TPMS_SIGNATURE_SM2 *source, BYTE **buffer, INT32 *size)
|
||||
{
|
||||
@ -1802,6 +1805,7 @@ TPMS_SIGNATURE_SM2_Marshal(TPMS_SIGNATURE_SM2 *source, BYTE **buffer, INT32 *siz
|
||||
written += TPMS_SIGNATURE_ECC_Marshal(source, buffer, size);
|
||||
return written;
|
||||
}
|
||||
/* libtpms added end */
|
||||
|
||||
UINT16
|
||||
TPMS_SIGNATURE_ECSCHNORR_Marshal(TPMS_SIGNATURE_ECSCHNORR *source, BYTE **buffer, INT32 *size)
|
||||
@ -2121,7 +2125,7 @@ UINT16
|
||||
TPMA_NV_Marshal(TPMA_NV *source, BYTE **buffer, INT32 *size)
|
||||
{
|
||||
UINT16 written = 0;
|
||||
written += UINT32_Marshal((UINT32 *)source, buffer, size);
|
||||
written += UINT32_Marshal((UINT32 *)source, buffer, size); /* libtpms changed */
|
||||
return written;
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@
|
||||
#define NV_C
|
||||
#include "Tpm.h"
|
||||
#include "PlatformData.h"
|
||||
#include "NVDynamic_fp.h"
|
||||
#include "NVDynamic_fp.h" /* libtpms added */
|
||||
/* 8.4.3 Local Functions */
|
||||
/* 8.4.3.1 NvNext() */
|
||||
/* This function provides a method to traverse every data entry in NV dynamic area. */
|
||||
@ -1643,6 +1643,7 @@ NvGetMaxCount(
|
||||
return maxCount;
|
||||
}
|
||||
|
||||
/* libtpms added begin */
|
||||
/*
|
||||
* Test harness for marshalling and unmarshalling and reconstructing the NVChip
|
||||
*/
|
||||
@ -1764,3 +1765,4 @@ void Test_NvChip_UnMarshal(void)
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* libtpms added end */
|
||||
@ -70,11 +70,12 @@
|
||||
#include <assert.h>
|
||||
#include "PlatformData.h"
|
||||
#include "Platform_fp.h"
|
||||
/* libtpms added begin */
|
||||
#include "NVMarshal.h"
|
||||
|
||||
#include "LibtpmsCallbacks.h"
|
||||
#include <errno.h>
|
||||
#include "tpm_library_intern.h"
|
||||
/* libtpms added end */
|
||||
|
||||
#if FILE_BACKED_NV
|
||||
# include <stdio.h>
|
||||
@ -354,12 +355,12 @@ _plat__NvMemoryMove(
|
||||
assert(sourceOffset + size <= NV_MEMORY_SIZE);
|
||||
assert(destOffset + size <= NV_MEMORY_SIZE);
|
||||
memmove(&s_NV[destOffset], &s_NV[sourceOffset], size); // Move data in RAM
|
||||
#if 1
|
||||
#if 1 /* libtpms added begin */
|
||||
if (destOffset > sourceOffset)
|
||||
memset(&s_NV[sourceOffset], 0, destOffset-sourceOffset);
|
||||
else
|
||||
memset(&s_NV[destOffset+size], 0, sourceOffset-destOffset);
|
||||
#endif
|
||||
#endif /* libtpms added end */
|
||||
return;
|
||||
}
|
||||
/* C.6.3.13. _plat__NvCommit() */
|
||||
|
||||
@ -123,7 +123,7 @@ NvPowerOn(
|
||||
if(g_powerWasLost)
|
||||
{
|
||||
if((nvError = _plat__NVEnable(0)) < 0)
|
||||
FAIL_NOCMD(FATAL_ERROR_NV_UNRECOVERABLE);
|
||||
FAIL_NOCMD(FATAL_ERROR_NV_UNRECOVERABLE); /* libtpms changed */
|
||||
NvInitStatic();
|
||||
}
|
||||
return nvError == 0;
|
||||
|
||||
@ -62,7 +62,7 @@
|
||||
#ifndef NVRESERVED_FP_H
|
||||
#define NVRESERVED_FP_H
|
||||
|
||||
#include "NVMarshal.h"
|
||||
#include "NVMarshal.h" /* libtpms added */
|
||||
|
||||
void
|
||||
NvCheckState(
|
||||
|
||||
@ -66,7 +66,7 @@
|
||||
#include "PlatformData.h"
|
||||
#include "Platform_fp.h"
|
||||
|
||||
#include "LibtpmsCallbacks.h"
|
||||
#include "LibtpmsCallbacks.h" /* libtpms added */
|
||||
|
||||
/* C.10.3. Functions */
|
||||
/* C.10.3.1. _plat__PhysicalPresenceAsserted() */
|
||||
|
||||
@ -78,9 +78,10 @@ clock64_t s_tpmTime;
|
||||
clock64_t s_lastSystemTime;
|
||||
clock64_t s_lastReportedTime;
|
||||
|
||||
/* libtpms added: */
|
||||
/* libtpms added begin */
|
||||
int64_t s_hostMonotonicAdjustTime; /* can be negative */
|
||||
uint64_t s_suspendedElapsedTime;
|
||||
/* libtpms added end */
|
||||
#endif
|
||||
/* From LocalityPlat.c */
|
||||
unsigned char s_locality;
|
||||
|
||||
@ -88,9 +88,10 @@ extern clock64_t s_lastReportedTime;
|
||||
// This is the rate adjusted value that is the equivalent of what would be read from a hardware
|
||||
// register that produced rate adjusted time.
|
||||
extern clock64_t s_tpmTime;
|
||||
/* libtpms added: */
|
||||
/* libtpms added begin */
|
||||
extern int64_t s_hostMonotonicAdjustTime;
|
||||
extern uint64_t s_suspendedElapsedTime;
|
||||
/* libtpms added end */
|
||||
#endif // HARDWARE_CLOCK
|
||||
|
||||
/* This value indicates that the timer was reset */
|
||||
@ -125,7 +126,7 @@ extern unsigned char s_locality;
|
||||
memory. Comment out to use RAM. */
|
||||
#if (!defined VTPM) || ((VTPM != NO) && (VTPM != YES))
|
||||
# undef VTPM
|
||||
# define VTPM NO // Default: Either YES or NO
|
||||
# define VTPM NO // Default: Either YES or NO libtpms: NO
|
||||
#endif
|
||||
|
||||
// For a simulation, use a file to back up the NV
|
||||
|
||||
@ -379,9 +379,10 @@ _plat__GetUnique(
|
||||
unsigned char *b // output buffer
|
||||
);
|
||||
|
||||
/* libtpms: */
|
||||
/* libtpms added begin */
|
||||
#include <time.h>
|
||||
void ClockAdjustPostResume(UINT64 backthen, BOOL timesAreRealtime);
|
||||
uint64_t ClockGetTime(clockid_t clk_id);
|
||||
/* libtpms added end */
|
||||
|
||||
#endif // _PLATFORM_FP_H_
|
||||
|
||||
@ -197,11 +197,12 @@ main(
|
||||
int argc,
|
||||
char *argv[]
|
||||
);
|
||||
// Extensions:
|
||||
/* libtpms added begin */
|
||||
void _rpc__Signal_SetTPMEstablished(void);
|
||||
BOOL _rpc__Signal_GetTPMEstablished(void);
|
||||
void _rpc__Signal_ResetTPMEstablished(void);
|
||||
BOOL _rpc__Signal_IsPowerOn(void);
|
||||
/* libtpms added end */
|
||||
|
||||
#endif // _SIMULATOR_FP_H_
|
||||
|
||||
|
||||
@ -62,17 +62,17 @@
|
||||
/* 9.2 _TPM_Init */
|
||||
#include "Tpm.h"
|
||||
#include "_TPM_Init_fp.h"
|
||||
#include "StateMarshal.h"
|
||||
#include "StateMarshal.h" /* libtpms added */
|
||||
// This function is used to process a _TPM_Init indication.
|
||||
LIB_EXPORT void
|
||||
_TPM_Init(
|
||||
void
|
||||
)
|
||||
{
|
||||
BOOL restored = FALSE;
|
||||
BOOL restored = FALSE; /* libtpms added */
|
||||
|
||||
g_powerWasLost = g_powerWasLost | _plat__WasPowerLost();
|
||||
#if SIMULATION && !defined NDEBUG
|
||||
#if SIMULATION && !defined NDEBUG /* libtpms changed */
|
||||
// If power was lost and this was a simulation, put canary in RAM used by NV
|
||||
// so that uninitialized memory can be detected more easily
|
||||
if(g_powerWasLost)
|
||||
@ -96,7 +96,7 @@ _TPM_Init(
|
||||
// Initialize the NvEnvironment.
|
||||
g_nvOk = NvPowerOn();
|
||||
// Initialize cryptographic functions
|
||||
g_inFailureMode |= (CryptInit() == FALSE); // stefanb
|
||||
g_inFailureMode |= (CryptInit() == FALSE); /* libtpms changed */
|
||||
if(!g_inFailureMode)
|
||||
{
|
||||
// Load the persistent data
|
||||
@ -107,9 +107,11 @@ _TPM_Init(
|
||||
// Start clock. Need to do this after NV has been restored.
|
||||
TimePowerOn();
|
||||
|
||||
/* libtpms added begin */
|
||||
VolatileLoad(&restored);
|
||||
if (restored)
|
||||
NVShadowRestore();
|
||||
/* libtpms added end */
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -251,11 +253,10 @@ TPM2_Startup(
|
||||
// the NV totalResetCount when incrementing would make it 0. When the
|
||||
// TPM starts up again, the old value of totalResetCount will be read
|
||||
// and we will get right back to here with the increment failing.
|
||||
#if 0
|
||||
// libtpms: disable this
|
||||
#if 0 /* libtpms added */
|
||||
if(gp.totalResetCount == 0)
|
||||
FAIL(FATAL_ERROR_INTERNAL);
|
||||
#endif
|
||||
#endif /* libtpms added */
|
||||
// Write total reset counter to NV
|
||||
NV_SYNC_PERSISTENT(totalResetCount);
|
||||
// Reset restartCount
|
||||
|
||||
@ -332,8 +332,7 @@ _rpc__Shutdown(
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Extensions
|
||||
/* libtpms added begin */
|
||||
static BOOL tpmEstablished;
|
||||
|
||||
void
|
||||
@ -360,3 +359,4 @@ _rpc__Signal_IsPowerOn(void)
|
||||
{
|
||||
return s_isPowerOn;
|
||||
}
|
||||
/* libtpms added end */
|
||||
@ -109,7 +109,7 @@
|
||||
SIMULATION == YES */
|
||||
#if !(defined SIMULATION) || ((SIMULATION != NO) && (SIMULATION != YES))
|
||||
# undef SIMULATION
|
||||
# define SIMULATION NO // Default: Either YES or NO
|
||||
# define SIMULATION NO // Default: Either YES or NO libtpms: NO
|
||||
#endif
|
||||
|
||||
// Define this to run the function that checks the compatibility between the chosen big number math
|
||||
@ -121,7 +121,7 @@
|
||||
#endif
|
||||
#if !(defined FIPS_COMPLIANT) || ((FIPS_COMPLIANT != NO) && (FIPS_COMPLIANT != YES))
|
||||
# undef FIPS_COMPLIANT
|
||||
# define FIPS_COMPLIANT NO // Default: Either YES or NO
|
||||
# define FIPS_COMPLIANT NO // Default: Either YES or NO libtpms: NO
|
||||
#endif
|
||||
|
||||
// Definition to allow alternate behavior for non-orderly startup. If there is a chance that the TPM
|
||||
@ -315,7 +315,7 @@
|
||||
#if !(defined USE_BIT_FIELD_STRUCTURES) \
|
||||
|| ((USE_BIT_FIELD_STRUCTURES != NO) && (USE_BIT_FIELD_STRUCTURES != YES))
|
||||
# undef USE_BIT_FIELD_STRUCTURES
|
||||
# define USE_BIT_FIELD_STRUCTURES NO // Default: Either YES or NO
|
||||
# define USE_BIT_FIELD_STRUCTURES NO // Default: Either YES or NO libtpms: NO
|
||||
#endif
|
||||
|
||||
/* Change these definitions to turn all algorithms or commands ON or OFF. That is, to turn all
|
||||
|
||||
@ -194,7 +194,7 @@ TpmFail(
|
||||
int code
|
||||
)
|
||||
{
|
||||
#if 0
|
||||
#if 0 /* libtpms added */
|
||||
// Save the values that indicate where the error occurred.
|
||||
// On a 64-bit machine, this may truncate the address of the string
|
||||
// of the function name where the error occurred.
|
||||
@ -218,7 +218,7 @@ TpmFail(
|
||||
g_forceFailureMode = FALSE;
|
||||
#endif
|
||||
|
||||
#else
|
||||
#else /* libtpms added begin */
|
||||
|
||||
TpmSetFailureMode(
|
||||
#if FAIL_TRACE
|
||||
@ -226,12 +226,13 @@ TpmFail(
|
||||
#endif
|
||||
code);
|
||||
|
||||
#endif
|
||||
#endif /* libtpms added end */
|
||||
// Jump to the failure mode code.
|
||||
// Note: only get here if asserts are off or if we are testing failure mode
|
||||
_plat__Fail();
|
||||
}
|
||||
|
||||
/* libtpms added begin */
|
||||
void
|
||||
TpmSetFailureMode(
|
||||
#if FAIL_TRACE
|
||||
@ -266,6 +267,7 @@ TpmSetFailureMode(
|
||||
// We are in failure mode
|
||||
g_inFailureMode = TRUE;
|
||||
}
|
||||
/* libtpms added end */
|
||||
/* 9.17.5 TpmFailureMode */
|
||||
/* This function is called by the interface code when the platform is in failure mode. */
|
||||
void
|
||||
|
||||
@ -70,7 +70,7 @@ SetForceFailureMode(
|
||||
);
|
||||
NORETURN void
|
||||
TpmFail(
|
||||
#if FAIL_TRACE
|
||||
#if FAIL_TRACE /* libtpms added begin */
|
||||
const char *function,
|
||||
int line,
|
||||
#endif
|
||||
@ -78,7 +78,7 @@ TpmFail(
|
||||
);
|
||||
void
|
||||
TpmSetFailureMode(
|
||||
#if FAIL_TRACE
|
||||
#if FAIL_TRACE /* libtpms added end */
|
||||
const char *function,
|
||||
int line,
|
||||
#endif
|
||||
|
||||
@ -469,7 +469,7 @@ TPMA_ALGORITHM_Unmarshal(TPMA_ALGORITHM *target, BYTE **buffer, INT32 *size)
|
||||
TPM_RC rc = TPM_RC_SUCCESS;
|
||||
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
rc = UINT32_Unmarshal((UINT32 *)target, buffer, size);
|
||||
rc = UINT32_Unmarshal((UINT32 *)target, buffer, size); /* libtpms changed */
|
||||
}
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
if (*target & TPMA_ALGORITHM_reserved) {
|
||||
@ -487,7 +487,7 @@ TPMA_OBJECT_Unmarshal(TPMA_OBJECT *target, BYTE **buffer, INT32 *size)
|
||||
TPM_RC rc = TPM_RC_SUCCESS;
|
||||
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
rc = UINT32_Unmarshal((UINT32 *)target, buffer, size);
|
||||
rc = UINT32_Unmarshal((UINT32 *)target, buffer, size); /* libtpms changed */
|
||||
}
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
if (*target & TPMA_OBJECT_reserved) {
|
||||
@ -505,7 +505,7 @@ TPMA_SESSION_Unmarshal(TPMA_SESSION *target, BYTE **buffer, INT32 *size)
|
||||
TPM_RC rc = TPM_RC_SUCCESS;
|
||||
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
rc = UINT8_Unmarshal((UINT8 *)target, buffer, size);
|
||||
rc = UINT8_Unmarshal((UINT8 *)target, buffer, size); /* libtpms changed */
|
||||
}
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
if (*target & TPMA_SESSION_reserved) {
|
||||
@ -523,7 +523,7 @@ TPMA_LOCALITY_Unmarshal(TPMA_LOCALITY *target, BYTE **buffer, INT32 *size)
|
||||
TPM_RC rc = TPM_RC_SUCCESS;
|
||||
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
rc = UINT8_Unmarshal((UINT8 *)target, buffer, size);
|
||||
rc = UINT8_Unmarshal((UINT8 *)target, buffer, size); /* libtpms changed */
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@ -536,7 +536,7 @@ TPMA_CC_Unmarshal(TPMA_CC *target, BYTE **buffer, INT32 *size)
|
||||
TPM_RC rc = TPM_RC_SUCCESS;
|
||||
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
rc = UINT32_Unmarshal((UINT32 *)target, buffer, size);
|
||||
rc = UINT32_Unmarshal((UINT32 *)target, buffer, size); /* libtpms changed */
|
||||
}
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
if (*target & TPMA_CC_reserved) {
|
||||
@ -4228,7 +4228,7 @@ TPMA_NV_Unmarshal(TPMA_NV *target, BYTE **buffer, INT32 *size)
|
||||
TPM_RC rc = TPM_RC_SUCCESS;
|
||||
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
rc = UINT32_Unmarshal((UINT32 *)target, buffer, size);
|
||||
rc = UINT32_Unmarshal((UINT32 *)target, buffer, size); /* libtpms changed */
|
||||
}
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
if (*target & TPMA_NV_RESERVED) {
|
||||
|
||||
@ -103,10 +103,11 @@ BnPointTo2B(
|
||||
bigPoint ecP, // IN: the values to be converted
|
||||
bigCurve E // IN: curve descriptor for the point
|
||||
);
|
||||
/* libtpms added begin */
|
||||
LIB_EXPORT int
|
||||
Bn2bin(bigConst initializer,
|
||||
unsigned char *buffer,
|
||||
size_t buffer_len);
|
||||
|
||||
/* libtpms added end */
|
||||
|
||||
#endif
|
||||
|
||||
@ -93,7 +93,7 @@ typedef uint64_t crypt_uword_t;
|
||||
typedef int64_t crypt_word_t;
|
||||
# define TO_CRYPT_WORD_64 BIG_ENDIAN_BYTES_TO_UINT64
|
||||
# define TO_CRYPT_WORD_32(a, b, c, d) TO_CRYPT_WORD_64(0, 0, 0, 0, a, b, c, d)
|
||||
#define BN_PAD 0
|
||||
#define BN_PAD 0 /* libtpms added */
|
||||
#elif RADIX_BITS == 32
|
||||
#define SWAP_CRYPT_WORD(x) REVERSE_ENDIAN_32((x))
|
||||
typedef uint32_t crypt_uword_t;
|
||||
@ -102,7 +102,7 @@ typedef int32_t crypt_word_t;
|
||||
BIG_ENDIAN_BYTES_TO_UINT32(e, f, g, h), \
|
||||
BIG_ENDIAN_BYTES_TO_UINT32(a, b, c, d)
|
||||
# define TO_CRYPT_WORD_32 BIG_ENDIAN_BYTES_TO_UINT32
|
||||
#define BN_PAD 1
|
||||
#define BN_PAD 1 /* libtpms added */
|
||||
#endif
|
||||
#define MAX_CRYPT_UWORD (~((crypt_uword_t)0))
|
||||
#define MAX_CRYPT_WORD ((crypt_word_t)(MAX_CRYPT_UWORD >> 1))
|
||||
@ -117,7 +117,7 @@ typedef int32_t crypt_word_t;
|
||||
#define BN_STRUCT_DEF(count) struct { \
|
||||
crypt_uword_t allocated; \
|
||||
crypt_uword_t size; \
|
||||
crypt_uword_t d[count + BN_PAD + BN_PAD + BN_PAD]; \
|
||||
crypt_uword_t d[count + BN_PAD + BN_PAD + BN_PAD]; /* libtpms changed */ \
|
||||
}
|
||||
typedef BN_STRUCT_DEF(1) bignum_t;
|
||||
#ifndef bigNum
|
||||
|
||||
@ -67,7 +67,7 @@
|
||||
#if ALG_TDES
|
||||
#define DES_NUM_WEAK 64
|
||||
const UINT64 DesWeakKeys[DES_NUM_WEAK] = {
|
||||
0x0101010101010101ULL, 0xFEFEFEFEFEFEFEFEULL, 0xE0E0E0E0F1F1F1F1ULL, 0x1F1F1F1F0E0E0E0EULL,
|
||||
0x0101010101010101ULL, 0xFEFEFEFEFEFEFEFEULL, 0xE0E0E0E0F1F1F1F1ULL, 0x1F1F1F1F0E0E0E0EULL, /* libtpms changed begin */
|
||||
0x011F011F010E010EULL, 0x1F011F010E010E01ULL, 0x01E001E001F101F1ULL, 0xE001E001F101F101ULL,
|
||||
0x01FE01FE01FE01FEULL, 0xFE01FE01FE01FE01ULL, 0x1FE01FE00EF10EF1ULL, 0xE01FE01FF10EF10EULL,
|
||||
0x1FFE1FFE0EFE0EFEULL, 0xFE1FFE1FFE0EFE0EULL, 0xE0FEE0FEF1FEF1FEULL, 0xFEE0FEE0FEF1FEF1ULL,
|
||||
@ -82,7 +82,7 @@ const UINT64 DesWeakKeys[DES_NUM_WEAK] = {
|
||||
0xFEE0011FFEF1010EULL, 0x01FEE01F01FEF10EULL, 0xE001FE1FF101FE0EULL, 0xFEE01F01FEF10E01ULL,
|
||||
0x01FEFE0101FEFE01ULL, 0xE01F01FEF10E01FEULL, 0xFEE0E0FEFEF1F1FEULL, 0x1F01011F0E01010EULL,
|
||||
0xE01F1FE0F10E0EF1ULL, 0xFEFE0101FEFE0101ULL, 0x1F01E0FE0E01F1FEULL, 0xE01FFE01F10EFE01ULL,
|
||||
0xFEFE1F1FFEFE0E0EULL, 0x1F01FEE00E01FEF1ULL, 0xE0E00101F1F10101ULL, 0xFEFEE0E0FEFEF1F1ULL};
|
||||
0xFEFE1F1FFEFE0E0EULL, 0x1F01FEE00E01FEF1ULL, 0xE0E00101F1F10101ULL, 0xFEFEE0E0FEFEF1F1ULL};/* libtpms changed end */
|
||||
/* 10.2.9.2.1 CryptSetOddByteParity() */
|
||||
/* This function sets the per byte parity of a 64-bit value. The least-significant bit is of each
|
||||
byte is replaced with the odd parity of the other 7 bits in the byte. With odd parity, no byte
|
||||
|
||||
@ -61,7 +61,7 @@
|
||||
|
||||
/* 10.2.11 CryptEccKeyExchange.c */
|
||||
#include "Tpm.h"
|
||||
/* libtpms added: */
|
||||
/* libtpms added begin */
|
||||
LIB_EXPORT TPM_RC
|
||||
SM2KeyExchange(
|
||||
TPMS_ECC_POINT *outZ, // OUT: the computed point
|
||||
@ -71,6 +71,7 @@ SM2KeyExchange(
|
||||
TPMS_ECC_POINT *QsBIn, // IN: static public party B key
|
||||
TPMS_ECC_POINT *QeBIn // IN: ephemeral public party B key
|
||||
);
|
||||
/* libtpms added end */
|
||||
|
||||
#if CC_ZGen_2Phase == YES
|
||||
#if ALG_ECMQV
|
||||
|
||||
@ -323,7 +323,7 @@ CryptGenerateR(
|
||||
return FALSE;
|
||||
// set the counter to the value that was
|
||||
// present when the commitment was made
|
||||
currentCount = (currentCount & 0xffffffffffff0000ULL) | *c;
|
||||
currentCount = (currentCount & 0xffffffffffff0000ULL) | *c; /* libtpms changed */
|
||||
}
|
||||
// Marshal the count value to a TPM2B buffer for the KDF
|
||||
cntr.t.size = sizeof(currentCount);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user