Skip to content

Commit 091d180

Browse files
authored
Merge pull request coconut-svsm#830 from stefano-garzarella/update-tcgtpm-v184
libtcgtpm: bump TPM reference implementation to v184
2 parents 1aa652a + c7e8586 commit 091d180

18 files changed

Lines changed: 314 additions & 74 deletions

libtcgtpm/deps/TpmConfiguration/CMakeLists.txt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# Microsoft Reference Implementation for TPM 2.0
2-
# Copyright (c) Microsoft Corporation
3-
# This software is being made available under certain license terms, as detailed at
4-
# https://github.com/microsoft/ms-tpm-20-ref/blob/main/LICENSE
5-
#
61
##########################################################
72
# DO NOT MODIFY - TPM Configuration Library
83
##########################################################
@@ -43,8 +38,24 @@ install(FILES
4338
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/TpmProfile_Common.h
4439
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/TpmProfile_ErrorCodes.h
4540
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/TpmProfile_Misc.h
46-
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/VendorInfo.h
4741
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/TpmConfiguration)
4842

43+
install(FILES
44+
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/VendorCommands/VendorCommandList.h
45+
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/VendorCommands/CommandAttributeData_s_ccAttr.inl
46+
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/VendorCommands/CommandAttributeData_s_commandAttributes.inl
47+
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/VendorCommands/CommandDispatchData_CommandStructures.inl
48+
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/VendorCommands/CommandDispatchData_s_CommandDataArray.inl
49+
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/VendorCommands/CommandDispatcher.inl
50+
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/VendorCommands/HandleProcess.inl
51+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/TpmConfiguration/VendorCommands)
52+
53+
install(FILES
54+
${CMAKE_CURRENT_SOURCE_DIR}/TpmConfiguration/VendorCommands/prototypes/Vendor_TCG_Test_fp.h
55+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/TpmConfiguration/VendorCommands/prototypes)
56+
57+
4958
# LAST: create the targets.cmake file for this package
5059
export_targets_cmake_file(${PROJECT_NAME})
60+
61+
add_subdirectory(TpmVendorCommandHandlers)

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmBuildSwitches.h

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,28 @@
5151
// ones in the Simulator project.
5252
#define SIMULATION NO
5353

54+
// ENABLE_TPM_DEBUG_PRINT enables arbitrary string printing.
55+
// enables the TPM_DEBUG_PRINT macro to route debugging strings
56+
// to the _plat_debug_out function
57+
#define ENABLE_TPM_DEBUG_PRINT (YES * SIMULATION)
58+
59+
// ENABLE_TPM_DEBUG_TRACE enables code tracing macros - depends on TPM_DEBUG_PRINT
60+
#define ENABLE_TPM_DEBUG_TRACE (NO * ENABLE_TPM_DEBUG_PRINT)
61+
62+
// ENABLE_CRYPTO_DEBUG enables printing of actual crypto values. This is entirely insecure.
63+
#define ENABLE_CRYPTO_DEBUG (YES * ENABLE_TPM_DEBUG_PRINT)
5464

5565
// The CRYPTO_LIB_REPORTING switch allows the TPM to report its
5666
// crypto library implementation, e.g., at simulation startup.
57-
#define CRYPTO_LIB_REPORTING NO
67+
#define CRYPTO_LIB_REPORTING (YES * SIMULATION)
5868

5969
// If doing debug, can set the DRBG to print out the intermediate test values.
6070
// Before enabling this, make sure that the dbgDumpMemBlock() function
6171
// has been added someplace (preferably, somewhere in CryptRand.c)
6272
#define DRBG_DEBUG_PRINT (NO * DEBUG)
6373

6474
// This define is used to control the debug for the CertifyX509 command.
65-
#define CERTIFYX509_DEBUG (YES * DEBUG)
75+
#define CERTIFYX509_DEBUG (NO * DEBUG)
6676

6777
// This provides fixed seeding of the RNG when doing debug on a simulator. This
6878
// should allow consistent results on test runs as long as the input parameters
@@ -89,9 +99,9 @@
8999
////////////////////////////////////////////////////////////////
90100
// The SIMULATION flag can enable test crypto behaviors and caching that
91101
// significantly change the behavior of the code. This flag controls only the
92-
// g_forceFailureMode flag in the TPM library while leaving the rest of the TPM
93-
// behavior alone. Useful for testing when the full set of options controlled by
94-
// SIMULATION may not be desired.
102+
// ability of the platform library to force failure mode while leaving the rest
103+
// of the TPM behavior alone. Useful for testing when the full set of options
104+
// controlled by SIMULATION may not be desired.
95105
#define ALLOW_FORCE_FAILURE_MODE NO
96106

97107
////////////////////////////////////////////////////////////////
@@ -144,37 +154,12 @@
144154
////////////////////////////////////////////////////////////////
145155
// Implementation alternatives - don't change external behavior
146156
////////////////////////////////////////////////////////////////
147-
148-
// Define TABLE_DRIVEN_DISPATCH to use tables rather than case statements
149-
// for command dispatch and handle unmarshaling
150-
#define TABLE_DRIVEN_DISPATCH YES
157+
// does the target system have longjmp support, AND we want to use it?
158+
#define LONGJMP_SUPPORTED NO
151159

152160
// This define is used to enable the new table-driven marshaling code.
153161
#define TABLE_DRIVEN_MARSHAL NO
154162

155-
// This switch allows use of #defines in place of pass-through marshaling or
156-
// unmarshaling code. A pass-through function just calls another function to do
157-
// the required function and does no parameter checking of its own. The
158-
// table-driven dispatcher calls directly to the lowest level
159-
// marshaling/unmarshaling code and by-passes any pass-through functions.
160-
#define USE_MARSHALING_DEFINES YES
161-
162-
// Switch added to support packed lists that leave out space associated with
163-
// unimplemented commands. Comment this out to use linear lists.
164-
// Note: if vendor specific commands are present, the associated list is always
165-
// in compressed form.
166-
#define COMPRESSED_LISTS YES
167-
168-
// This define is used to eliminate the use of bit-fields. It can be enabled for big-
169-
// or little-endian machines. For big-endian architectures that numbers bits in
170-
// registers from left to right (MSb0) this must be enabled. Little-endian machines
171-
// number from right to left with the least significant bit having assigned a bit
172-
// number of 0. These are LSb0 machines (they are also little-endian so they are also
173-
// least-significant byte 0 (LSB0) machines. Big-endian (MSB0) machines may number in
174-
// either direction (MSb0 or LSb0). For an MSB0+MSb0 machine this value is required to
175-
// be 'NO'
176-
#define USE_BIT_FIELD_STRUCTURES NO
177-
178163
// Enable the generation of RSA primes using a sieve.
179164
#define RSA_KEY_SIEVE YES
180165

@@ -207,6 +192,6 @@
207192
#define FAIL_TRACE YES
208193

209194
// TODO_RENAME_INC_FOLDER: public refers to the TPM_CoreLib public headers
210-
#include <public/CompilerDependencies.h>
195+
#include <tpm_public/CompilerDependencies.h>
211196

212197
#endif // _TPM_BUILD_SWITCHES_H_

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88
#include <TpmConfiguration/TpmProfile_CommandList.h>
99
#include <TpmConfiguration/TpmProfile_Misc.h>
1010
#include <TpmConfiguration/TpmProfile_ErrorCodes.h>
11-
#include <TpmConfiguration/VendorInfo.h>
12-
1311
#endif // _TPM_PROFILE_H_

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_CommandList.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,34 @@
1212
# error CC_YES and CC_NO should be defined by the command line file, not before
1313
#endif
1414

15+
// Change these definitions to turn all commands ON or OFF. That is, to turn all
16+
// commands on, set CC_NO to YES. This is intended as a debug feature.
1517
#define CC_YES YES
1618
#define CC_NO NO
1719

18-
//
20+
// do not format automatically - the comments confuse clang-format.
21+
// clang-format off
22+
1923
// Defines for Implemented Commands
20-
//
2124

2225
// Commands that are defined in the spec, but not implemented for various
2326
// reasons:
2427

2528
// The TPM reference implementation does not implement attached-component
2629
// features, and the Compliance test suite has no test cases.
27-
#define CC_AC_GetCapability CC_NO
28-
#define CC_AC_Send CC_NO
30+
#define CC_AC_GetCapability CC_NO
31+
#define CC_AC_Send CC_NO
2932

3033
// The TPM reference implementation does not implement firmware upgrade.
31-
#define CC_FieldUpgradeData CC_NO
32-
#define CC_FieldUpgradeStart CC_NO
33-
#define CC_FirmwareRead CC_NO
34+
#define CC_FieldUpgradeData CC_NO
35+
#define CC_FieldUpgradeStart CC_NO
36+
#define CC_FirmwareRead CC_NO
3437

3538
// A prototype of CertifyX509 is provided here for informative purposes only.
3639
// While all of the TPM reference implementation is provided "AS IS" without any
3740
// warranty, the current design and implementation of CertifyX509 are considered
3841
// to be especially unsuitable for product use.
39-
#define CC_CertifyX509 CC_NO
42+
#define CC_CertifyX509 CC_NO
4043

4144
// Normal commands:
4245

@@ -155,11 +158,16 @@
155158
#define CC_StirRandom CC_YES
156159
#define CC_TestParms CC_YES
157160
#define CC_Unseal CC_YES
158-
#define CC_Vendor_TCG_Test CC_YES
159161
#define CC_VerifySignature CC_YES
160162
#define CC_ZGen_2Phase (CC_YES && ALG_ECC)
161163
#define CC_NV_DefineSpace2 CC_YES
162164
#define CC_NV_ReadPublic2 CC_YES
163165
#define CC_SetCapability CC_NO
166+
#define CC_ReadOnlyControl CC_YES
167+
#define CC_PolicyTransportSPDM CC_YES
168+
169+
// clang-format on
170+
171+
#include <TpmConfiguration/VendorCommands/VendorCommandList.h>
164172

165173
#endif // _TPM_PROFILE_COMMAND_LIST_H_

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
// Are building for a BIG_ENDIAN processor?
2626
#define BIG_ENDIAN_TPM NO
2727
#define LITTLE_ENDIAN_TPM !BIG_ENDIAN_TPM
28-
// Does the processor put the most-significant bit at bit position 0?
29-
#define MOST_SIGNIFICANT_BIT_0 NO
30-
#define LEAST_SIGNIFICANT_BIT_0 !MOST_SIGNIFICANT_BIT_0
3128
// Does processor support Auto align?
3229
#define AUTO_ALIGN NO
3330

@@ -175,6 +172,8 @@
175172
#define RH_ACT_E ( NO * ACT_SUPPORT)
176173
#define RH_ACT_F ( NO * ACT_SUPPORT)
177174

175+
// number of vendor properties, must currently be 1.
176+
#define MAX_VENDOR_PROPERTY (1)
178177

179178
//***********************************************
180179
// Enable VENDOR_PERMANENT_AUTH_HANDLE?
@@ -223,4 +222,11 @@
223222
// (external-NV-specific) attributes are supported.
224223
#define EXTERNAL_NV YES
225224

225+
//***********************************************
226+
// Defines controlling secure channel functionality
227+
//***********************************************
228+
// This flag enables support for PolicyTransportSPDM.
229+
// See CC_PolicyTransportSPDM.
230+
#define SEC_CHANNEL_SUPPORT YES
231+
226232
#endif // _TPM_PROFILE_COMMON_H_

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_ErrorCodes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242

4343
// Additional error codes defined by TPM library:
4444
#define FATAL_ERROR_ASSERT (500)
45+
#define FATAL_ERROR_NV_INIT (501)
46+
#define FATAL_ERROR_CRYPTO_INIT (502)
47+
#define FATAL_ERROR_NO_INIT (503)
48+
4549
// Platform library violated interface contract.
4650
#define FATAL_ERROR_PLATFORM (600)
4751

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file contains an inlined portion of the s_ccAttr array definition
2+
// for vendor commands.
3+
//
4+
// IMPORTANT: This file is included in the middle of an array initializer
5+
// therefore it must not contain anything other than comments and exactly one TPMA_CC
6+
// entry per vendor command. See the private Tpm header CommandAttributeData.h for
7+
// more info.
8+
// (This is why the file has the .INL extension, it's not a normal header.
9+
//
10+
#ifndef _COMMAND_CODE_ATTRIBUTES_
11+
# error This file should be included only within CommandAttributeData.h
12+
#endif
13+
#if (PAD_LIST || CC_Vendor_TCG_Test)
14+
// TPM_CC_Vendor_TCG_Test
15+
TPMA_CC_INITIALIZER(0x0000, 0, 0, 0, 0, 0, 0, 1, 0),
16+
#endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file contains an inlined portion of the s_commandAttributes array
2+
// definition for vendor commands.
3+
//
4+
// IMPORTANT: This file is included in the middle of an array initializer
5+
// therefore it must not contain anything other than comments and exactly one
6+
// COMMAND_ATTRIBUTES entry per vendor command. See the private Tpm header
7+
// CommandAttributeData.h for more info. (This is why the file has the .INL
8+
// extension, it's not a normal header.
9+
//
10+
#ifndef _COMMAND_CODE_ATTRIBUTES_
11+
# error This file should be included only within CommandAttributeData.h
12+
#endif
13+
#if (PAD_LIST || CC_Vendor_TCG_Test)
14+
(COMMAND_ATTRIBUTES)(CC_Vendor_TCG_Test* // 0x0000
15+
(DECRYPT_2 + ENCRYPT_2)),
16+
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file contains an inlined portion of the s_ccAttr array definition
2+
// for vendor commands.
3+
//
4+
// IMPORTANT: This file is included in the middle of an array initializer
5+
// therefore it must not contain anything other than comments and exactly one TPMA_CC
6+
// entry per vendor command. See the private Tpm header CommandAttributeData.h for
7+
// more info.
8+
// (This is why the file has the .INL extension, it's not a normal header.
9+
//
10+
#ifndef _COMMAND_TABLE_DISPATCH_
11+
#error This file should only be included inside CommandDispatchData.h when table dispatching is turned on.
12+
#endif
13+
14+
#if CC_Vendor_TCG_Test
15+
# include "TpmConfiguration/VendorCommands/prototypes/Vendor_TCG_Test_fp.h"
16+
17+
typedef TPM_RC(Vendor_TCG_Test_Entry)(Vendor_TCG_Test_In* in,
18+
Vendor_TCG_Test_Out* out);
19+
20+
typedef const struct
21+
{
22+
Vendor_TCG_Test_Entry* entry;
23+
UINT16 inSize;
24+
UINT16 outSize;
25+
UINT16 offsetOfTypes;
26+
BYTE types[4];
27+
} Vendor_TCG_Test_COMMAND_DESCRIPTOR_t;
28+
29+
Vendor_TCG_Test_COMMAND_DESCRIPTOR_t _Vendor_TCG_TestData = {
30+
/* entry */ &TPM2_Vendor_TCG_Test,
31+
/* inSize */ (UINT16)(sizeof(Vendor_TCG_Test_In)),
32+
/* outSize */ (UINT16)(sizeof(Vendor_TCG_Test_Out)),
33+
/* offsetOfTypes */ offsetof(Vendor_TCG_Test_COMMAND_DESCRIPTOR_t, types),
34+
/* offsets */ // No parameter offsets
35+
/* types */
36+
{TPM2B_DATA_P_UNMARSHAL, END_OF_LIST, TPM2B_DATA_P_MARSHAL, END_OF_LIST}};
37+
38+
# define _Vendor_TCG_TestDataAddress (&_Vendor_TCG_TestData)
39+
#else
40+
# define _Vendor_TCG_TestDataAddress 0
41+
#endif // CC_Vendor_TCG_Test
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file contains an inlined portion of the s_ccAttr array definition
2+
// for vendor commands.
3+
//
4+
// IMPORTANT: This file is included in the middle of an array initializer
5+
// therefore it must not contain anything other than comments and exactly one TPMA_CC
6+
// entry per vendor command. See the private Tpm header CommandAttributeData.h for
7+
// more info.
8+
// (This is why the file has the .INL extension, it's not a normal header.
9+
//
10+
#ifndef _COMMAND_TABLE_DISPATCH_
11+
#error This file should only be included inside CommandDispatchData.h when table dispatching is turned on.
12+
#endif
13+
#if (PAD_LIST || CC_Vendor_TCG_Test)
14+
(COMMAND_DESCRIPTOR_t*)_Vendor_TCG_TestDataAddress,
15+
#endif // CC_Vendor_TCG_Test

0 commit comments

Comments
 (0)