Enable vTPM subsystem on TPM 2.0
v4 cover Enable vTPM subsystem on TPM 2.0
This series of patch enable the virtual Trusted Platform Module (vTPM) subsystem for Xen on TPM 2.0.
Noted, functionality for a virtual guest operating system (a DomU) is still TPM 1.2. The main modifcation is on vtpmmgr-stubdom. The challenge is that TPM 2.0 is not backward compatible with TPM 1.2.
------------------------------
DESIGN OVERVIEW
------------------------------
The architecture of vTPM subsystem on TPM 2.0 is described below:
+------------------+
| Linux DomU | ...
| | ^ |
| v | |
| xen-tpmfront |
+------------------+
| ^
v |
+------------------+
| mini-os/tpmback |
| | ^ |
| v | |
| vtpm-stubdom | ...
| | ^ |
| v | |
| mini-os/tpmfront |
+------------------+
| ^
v |
+------------------+
| mini-os/tpmback |
| | ^ |
| v | |
| vtpmmgr-stubdom |
| | ^ |
| v | |
| mini-os/tpm2_tis |
+------------------+
| ^
v |
+------------------+
| Hardware TPM 2.0 |
+------------------+* Linux DomU: The Linux based guest that wants to use a vTPM. There many be more than one of these.
* xen-tpmfront.ko: Linux kernel virtual TPM frontend driver. This driver provides vTPM access to a para-virtualized Linux based DomU.
* mini-os/tpmback: Mini-os TPM backend driver. The Linux frontend driver connects to this backend driver to facilitate communications between the Linux DomU and its vTPM. This driver is also used by vtpmmgr-stubdom to communicate with vtpm-stubdom.
* vtpm-stubdom: A mini-os stub domain that implements a vTPM. There is a one to one mapping between running vtpm-stubdom instances and logical vtpms on the system. The vTPM Platform Configuration Registers (PCRs) are all initialized to zero.
* mini-os/tpmfront: Mini-os TPM frontend driver. The vTPM mini-os domain vtpm-stubdom uses this driver to communicate with vtpmmgr-stubdom. This driver could also be used separately to implement a mini-os domain that wishes to use a vTPM of its own.
* vtpmmgr-stubdom: A mini-os domain that implements the vTPM manager. There is only one vTPM manager and it should be running during the entire lifetime of the machine. This domain regulates access to the physical TPM on the system and secures the persistent state of each vTPM.
* mini-os/tpm2_tis: Mini-os TPM version 2.0 TPM Interface Specification (TIS) driver. This driver used by vtpmmgr-stubdom to talk directly to the hardware TPM 2.0. Communication is facilitated by mapping hardware memory pages into vtpmmgr-stubdom.
* Hardware TPM 2.0: The physical TPM 2.0 that is soldered onto the motherboard.
------------------------------
Key Hierarchy
------------------------------
+------------------+
| vTPM's secrets | ...
+------------------+
| ^
| |(Bind / Unbind)
- - - - - -v |- - - - - - - - TPM 2.0
+------------------+
| SK +
+------------------+
| ^
v |
+------------------+
| SRK |
+------------------+
| ^
v |
+------------------+
| TPM 2.0 Storage |
| Primary Seed |
+------------------+Now the secrets for the vTPMs are only being bound to the presence of thephysical TPM 2.0. Since using PCRs to seal the data can be an important security feature that users of the vtpmmgr rely on. I will replace TPM2_Bind/TPM2_Unbind with TPM2_Seal/TPM2_Unseal to provide as much security as it did for TPM 1.2 in later series of patch.
------------------------------
INSTALLATION
------------------------------
Prerequisites:
--------------
You must have an x86 machine with a TPM on the motherboard. The only extra software requirement for compiling vTPM is cmake. You must use libxl to manage domains with vTPMs; 'xm' is deprecated and does not support vTPMs.
Compiling the Xen tree:
-----------------------
Compile and install the Xen tree as usual; be sure that the vTPM domains are enabled when you run configure.
Compiling the LINUX dom0 kernel:
--------------------------------
Because the TPM manager uses direct access to the physical TPM, it may interfere with access to the TPM by dom0. The simplest solution for this is to prevent dom0 from accessing the physical TPM by compiling the kernel without a driver or blacklisting the module.
Compiling the LINUX domU kernel:
--------------------------------
The domU kernel used by domains with vtpms must include the xen-tpmfront.ko driver. It can be built directly into the kernel or as a module; however, some features such as IMA require the TPM to be built in to the kernel.
CONFIG_TCG_TPM=yCONFIG_TCG_XEN=y
------------------------------
VTPM MANAGER SETUP
------------------------------
Manager disk image setup:
-------------------------
The vTPM Manager requires a disk image to store its encrypted data. The image does not require a filesystem and can live anywhere on the host disk. The image is not large; the Xen 4.5 vtpmmgr is limited to using the first 2MB of the image but can support more than 20,000 vTPMs.
dd if=/dev/zero of=/home/vtpm2/vmgr bs=16M count=1
Manager config file:
--------------------
The vTPM Manager domain (vtpmmgr-stubdom) must be started like any other Xen virtual machine and requires a config file. The manager requires a disk image for storage and permission to access the hardware memory pages for the TPM. The disk must be presented as "hda", and the TPM memory pages are passed using the iomem configuration parameter. The TPM TIS uses 5 pages of IO memory (one per locality) that start at physical address 0xfed40000. By default, the TPM manager uses locality 0 (so only the page at 0xfed40 is needed).
Add:
..
extra="tpm2"
..
extra option to launch vtpmmgr-stubdom domain on TPM 2.0, and ignore it on TPM 1.x. for example:
kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz"
memory=128
disk=["file:/home/vtpm2/vmgr,hda,w"]
name="vtpmmgr"
iomem=["fed40,5"]
extra="tpm2"------------------------------
VTPM AND LINUX PVM SETUP
------------------------------
vTPM disk image setup:
----------------------
The vTPM requires a disk image to store its persistent data (RSA keys, NVRAM, etc). The image does not require a filesystem. The image does not need to be large; 2 Mb should be sufficient.
dd if=/dev/zero of=/home/vtpm2/vtpm0 bs=2M count=1
vTPM config file:
-----------------
The vTPM domain requires a configuration file like any other domain. The vTPM requires a disk image for storage and a TPM frontend driver to communicate with the manager. You are required to generate a uuid for this vtpm, which is specified on the "vtpm=" line that describes its connection to the vTPM Manager. for example:
kernel="/usr/lib/xen/boot/vtpm-stubdom.gz"
memory=8
disk=["file:/home/vtpm2/vtpm0,hda,w"]
name="vtpm0"
vtpm=["backend=vtpmmgr,uuid=914fe389-e2c5-44e6-993f-2189637cf1de"]If you wish to clear the vTPM data you can either recreate the disk image or change the uuid.
Linux Guest config file:
------------------------
The Linux guest config file needs to be modified to include the Linux tpmfront driver. Add the following line:
vtpm=["backend=vtpm0"]
Currently only Linux guests are supported (PV or HVM with PV drivers). My series of patch for HVM virtual mahcine are still being reviewed and modifcated.
Using the vTPM in the guest:
----------------------------
If xen-tpmfront was compiled as a module, it must be loaded it in the guest.
# modprobe xen-tpmfront
After the Linux domain boots and the xen-tpmfront driver is loaded, you should see the following on the vtpm console:
Info: VTPM attached to Frontend X/Y
You can quickly test the vTPM by using the sysfs interface:
# cat /sys/devices/vtpm-0/pubek # cat /sys/devices/vtpm-0/pcrs If you have trousers and tpm_tools installed on the guest, the tpm_version command should return the following:
The version command should return the following:
TPM 1.2 Version Info:
Chip Version: 1.2.0.7 Spec Level: 2 Errata Revision: 1 TPM Vendor ID: ETHZ TPM Version: 01010000 Manufacturer Info: 4554485a
You should also see the command being sent to the vtpm console as well as the vtpm saving its state. You should see the vtpm key being encrypted and stored on the vtpmmgr console.
You may wish to write a script to start your vtpm and guest together and to destroy the vtpm when the guest shuts down.
------------------------------
INTEGRATION WITH PV-GRUB
------------------------------
The vTPM currently starts up with all PCRs set to their default values (all zeros for the lower 16). This means that any decisions about the trustworthiness of the created domain must be made based on the environment that created the vTPM and the domU; for example, a system that only constructs images using a trusted configuration and guest kernel be able to provide guarantees about the guests and any measurements done that kernel (such as the IMA TCB log). Guests wishing to use a custom kernel in such a secure environment are often started using the pv-grub bootloader as the kernel, which then can load the untrusted kernel without needing to parse an untrusted filesystem and kernel in dom0. If the pv-grub stub domain succeeds in connecting to a vTPM, it will extend the hash of the kernel that it boots into PCR #4, and will extend the command line and initrd into PCR #5 before booting so that a domU booted in this way can attest to its early boot state.
------------------------------
REFERENCES
------------------------------
Berlios TPM Emulator:
http://tpm-emulator.berlios.de/
Xen docs/misc/vtpm.txt
Xen docs/misc/vtpm-platforms.txt
Xen docs/misc/vtpmmgr.txt
--Changes in V4:
1. Change extra option from 'tpm2' to 'tpm2=1'
2. Remove test code.
3. Make a note of limitation in the documentation for TPM 2.0 in the 'Key Hierarchy' section of docs/misc/vtpmmgr.txt
--Changes in V3:
1. Add 'olen' parameter in 'stubdom/vtpmmgr/disk_read.c', which is lost in v2.
--Changes in V2:
1. Record some infomation in docs/misc/vtpmmgr.txt.
2. Add TPM 2.0 PCRs read.
3. Bind/Unbind the measurements of the hypervisor and other TCB components.
4. Change extra option from '--tpm2' to 'tpm2'
Quan Xu (14):
vTPM/TPM2: Add TPM 2.0 data structures and commands definition vTPM/TPM2: TPM 2.0 data structures marshal
vTPM/TPM2: Add global data in vtpm_globals{} vTPM/TPM2: Add TPM 2.0 Exposed APIs
vTPM/TPM2: TPM 2.0 takes ownership and create SRK vTPM/TPM2: Create and load SK on TPM 2.0
vTPM/TPM2: TPM2.0 TIS initialization and self test. vTPM/TPM2: Add main entrance vtpmmgr2_init() vTPM/TPM2: Support 'tpm2' extra command line. vTPM/TPM2: TPM 2.0 PCRs read
vTPM/TPM2: Support TPM 2.0 bind and unbind data vTPM/TPM2: Bind group keys and sectors data on disk vTPM/TPM2: Unind group keys and sectors data on disk vTPM/TPM2: Record some infomation in docs/misc/vtpmmgr.txt about
docs/misc/vtpmmgr.txt | 155 ++++++- extras/mini-os/include/tpm_tis.h | 1 + extras/mini-os/tpm_tis.c | 156 +++++++ stubdom/vtpmmgr/Makefile | 2 +- stubdom/vtpmmgr/disk_read.c | 17 +- stubdom/vtpmmgr/disk_tpm.c | 42 +- stubdom/vtpmmgr/disk_tpm.h | 4 + stubdom/vtpmmgr/disk_write.c | 13 +- stubdom/vtpmmgr/init.c | 279 +++++++++++ stubdom/vtpmmgr/tpm2.c | 455 ++++++++++++++++++ stubdom/vtpmmgr/tpm2.h | 104 +++++ stubdom/vtpmmgr/tpm2_marshal.h | 673 +++++++++++++++++++++++++++ stubdom/vtpmmgr/tpm2_types.h | 980 +++++++++++++++++++++++++++++++++++++++ stubdom/vtpmmgr/vtpmmgr.c | 46 +- stubdom/vtpmmgr/vtpmmgr.h | 29 ++ 15 files changed, 2942 insertions(+), 14 deletions(-) create mode 100644 stubdom/vtpmmgr/tpm2.c create mode 100644 stubdom/vtpmmgr/tpm2.h create mode 100644 stubdom/vtpmmgr/tpm2_marshal.h create mode 100644 stubdom/vtpmmgr/tpm2_types.h
Signature · 1 line
1.8.3.2
PATCH v4 1/14 vTPM/TPM2: Add TPM 2.0 data structures and commands definition
Add TPM 2.0 data structures on Trusted Platform Module Library Part 2:
Structures and Trust Platform Module Library Part 3: Commands.
--- stubdom/vtpmmgr/tpm2_types.h | 978 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 978 insertions(+) create mode 100644 stubdom/vtpmmgr/tpm2_types.h
stubdom/vtpmmgr/tpm2_types.h new file +978 -0
@@ -0,0 +1,978 @@ +#ifndef __TPM2_TYPES_H__ +#define __TPM2_TYPES_H__ + +#include <stdlib.h> +#include <stdint.h> + +// "implementation.h" +// Table 212 -- Logic Values +#define YES 1 +#define NO 0 +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef true +#define true 1 +#endif +#ifndef false +#define false 0 +#endif +#define SET 1 +#define CLEAR 0 + + +// Table 214 -- Implemented Algorithms +#define ALG_RSA YES // 1 +#define ALG_DES NO // 0 +#define ALG__3DES NO // 0 +#define ALG_SHA1 YES // 1 +#define ALG_HMAC YES // 1 +#define ALG_AES YES // 1 +#define ALG_MGF1 YES // 1 +#define ALG_XOR YES // 1 +#define ALG_KEYEDHASH YES // 1 +#define ALG_SHA256 YES // 1 +#define ALG_SHA384 YES // 0 +#define ALG_SHA512 YES // 0 +#define ALG_WHIRLPOOL512 YES // 0 +#define ALG_SM3_256 YES // 1 +#define ALG_SM4 YES // 1 +#define ALG_RSASSA YES // 1 +#define ALG_RSAES YES // 1 +#define ALG_RSAPSS YES // 1 +#define ALG_OAEP YES // 1 +#define ALG_ECC YES // 1 +#define ALG_CFB YES // 1 +#define ALG_ECDH YES // 1 +#define ALG_ECDSA YES // 1 +#define ALG_ECDAA YES // 1 +#define ALG_SM2 YES // 1 +#define ALG_ECSCHNORR YES // 1 +#define ALG_SYMCIPHER YES // 1 +#define ALG_KDF1_SP800_56a YES // 1 +#define ALG_KDF2 NO // 0 +#define ALG_KDF1_SP800_108 YES // 1 +#define ALG_CTR YES // 1 +#define ALG_OFB YES // 1 +#define ALG_CBC YES // 1 + +#define HASH_COUNT (ALG_SHA1+ALG_SHA256+ALG_SHA384+ALG_SHA512+ALG_WHIRLPOOL512+ALG_SM3_256) + +// Table 216 -- RSA Algorithm Constants +#define RSA_KEY_SIZES_BITS 2048 // {1024,2048} +#define MAX_RSA_KEY_BITS 2048 +#define MAX_RSA_KEY_BYTES ((MAX_RSA_KEY_BITS + 7) / 8) // 256 + +// Table 218 -- AES Algorithm Constants +#define AES_KEY_SIZES_BITS 128 +#define MAX_AES_KEY_BITS 128 +#define MAX_AES_BLOCK_SIZE_BYTES 16 +#define MAX_AES_KEY_BYTES ((MAX_AES_KEY_BITS + 7) / 8) // 16 + + +// Table 220 -- Symmetric Algorithm Constants +#define MAX_SYM_KEY_BITS MAX_AES_KEY_BITS // 128 +#define MAX_SYM_KEY_BYTES MAX_AES_KEY_BYTES // 16 +#define MAX_SYM_BLOCK_SIZE MAX_AES_BLOCK_SIZE_BYTES // 16 + +#define MAX_SYM_DATA 128 +#define MAX_ECC_KEY_BITS 256 +#define MAX_ECC_KEY_BYTES ((MAX_ECC_KEY_BITS + 7) / 8) + + +typedef unsigned char BYTE ; +typedef unsigned char BOOL ; +typedef uint8_t UINT8 ; +typedef uint16_t UINT16 ; +typedef uint32_t UINT32 ; +typedef uint64_t UINT64 ; + +// TPM2 command code + +typedef UINT32 TPM_CC ; +#define TPM_CC_FIRST (TPM_CC)(0x0000011F) +#define TPM_CC_PP_FIRST (TPM_CC)(0x0000011F) +#define TPM_CC_NV_UndefineSpaceSpecial (TPM_CC)(0x0000011F) +#define TPM_CC_EvictControl (TPM_CC)(0x00000120) +#define TPM_CC_HierarchyControl (TPM_CC)(0x00000121) +#define TPM_CC_NV_UndefineSpace (TPM_CC)(0x00000122) +#define TPM_CC_ChangeEPS (TPM_CC)(0x00000124) +#define TPM_CC_ChangePPS (TPM_CC)(0x00000125) +#define TPM_CC_Clear (TPM_CC)(0x00000126) +#define TPM_CC_ClearControl (TPM_CC)(0x00000127) +#define TPM_CC_ClockSet (TPM_CC)(0x00000128) +#define TPM_CC_HierarchyChangeAuth (TPM_CC)(0x00000129) +#define TPM_CC_NV_DefineSpace (TPM_CC)(0x0000012A) +#define TPM_CC_PCR_Allocate (TPM_CC)(0x0000012B) +#define TPM_CC_PCR_SetAuthPolicy (TPM_CC)(0x0000012C) +#define TPM_CC_PP_Commands (TPM_CC)(0x0000012D) +#define TPM_CC_SetPrimaryPolicy (TPM_CC)(0x0000012E) +#define TPM_CC_FieldUpgradeStart (TPM_CC)(0x0000012F) +#define TPM_CC_ClockRateAdjust (TPM_CC)(0x00000130) +#define TPM_CC_CreatePrimary (TPM_CC)(0x00000131) +#define TPM_CC_NV_GlobalWriteLock (TPM_CC)(0x00000132) +#define TPM_CC_PP_LAST (TPM_CC)(0x00000132) +#define TPM_CC_GetCommandAuditDigest (TPM_CC)(0x00000133) +#define TPM_CC_NV_Increment (TPM_CC)(0x00000134) +#define TPM_CC_NV_SetBits (TPM_CC)(0x00000135) +#define TPM_CC_NV_Extend (TPM_CC)(0x00000136) +#define TPM_CC_NV_Write (TPM_CC)(0x00000137) +#define TPM_CC_NV_WriteLock (TPM_CC)(0x00000138) +#define TPM_CC_DictionaryAttackLockReset (TPM_CC)(0x00000139) +#define TPM_CC_DictionaryAttackParameters (TPM_CC)(0x0000013A) +#define TPM_CC_NV_ChangeAuth (TPM_CC)(0x0000013B) +#define TPM_CC_PCR_Event (TPM_CC)(0x0000013C) +#define TPM_CC_PCR_Reset (TPM_CC)(0x0000013D) +#define TPM_CC_SequenceComplete (TPM_CC)(0x0000013E) +#define TPM_CC_SetAlgorithmSet (TPM_CC)(0x0000013F) +#define TPM_CC_SetCommandCodeAuditStatus (TPM_CC)(0x00000140) +#define TPM_CC_FieldUpgradeData (TPM_CC)(0x00000141) +#define TPM_CC_IncrementalSelfTest (TPM_CC)(0x00000142) +#define TPM_CC_SelfTest (TPM_CC)(0x00000143) +#define TPM_CC_Startup (TPM_CC)(0x00000144) +#define TPM_CC_Shutdown (TPM_CC)(0x00000145) +#define TPM_CC_StirRandom (TPM_CC)(0x00000146) +#define TPM_CC_ActivateCredential (TPM_CC)(0x00000147) +#define TPM_CC_Certify (TPM_CC)(0x00000148) +#define TPM_CC_PolicyNV (TPM_CC)(0x00000149) +#define TPM_CC_CertifyCreation (TPM_CC)(0x0000014A) +#define TPM_CC_Duplicate (TPM_CC)(0x0000014B) +#define TPM_CC_GetTime (TPM_CC)(0x0000014C) +#define TPM_CC_GetSessionAuditDigest (TPM_CC)(0x0000014D) +#define TPM_CC_NV_Read (TPM_CC)(0x0000014E) +#define TPM_CC_NV_ReadLock (TPM_CC)(0x0000014F) +#define TPM_CC_ObjectChangeAuth (TPM_CC)(0x00000150) +#define TPM_CC_PolicySecret (TPM_CC)(0x00000151) +#define TPM_CC_Rewrap (TPM_CC)(0x00000152) +#define TPM_CC_Create (TPM_CC)(0x00000153) +#define TPM_CC_ECDH_ZGen (TPM_CC)(0x00000154) +#define TPM_CC_HMAC (TPM_CC)(0x00000155) +#define TPM_CC_Import (TPM_CC)(0x00000156) +#define TPM_CC_Load (TPM_CC)(0x00000157) +#define TPM_CC_Quote (TPM_CC)(0x00000158) +#define TPM_CC_RSA_Decrypt (TPM_CC)(0x00000159) +#define TPM_CC_HMAC_Start (TPM_CC)(0x0000015B) +#define TPM_CC_SequenceUpdate (TPM_CC)(0x0000015C) +#define TPM_CC_Sign (TPM_CC)(0x0000015D) +#define TPM_CC_Unseal (TPM_CC)(0x0000015E) +#define TPM_CC_PolicySigned (TPM_CC)(0x00000160) +#define TPM_CC_ContextLoad (TPM_CC)(0x00000161) +#define TPM_CC_ContextSave (TPM_CC)(0x00000162) +#define TPM_CC_ECDH_KeyGen (TPM_CC)(0x00000163) +#define TPM_CC_EncryptDecrypt (TPM_CC)(0x00000164) +#define TPM_CC_FlushContext (TPM_CC)(0x00000165) +#define TPM_CC_LoadExternal (TPM_CC)(0x00000167) +#define TPM_CC_MakeCredential (TPM_CC)(0x00000168) +#define TPM_CC_NV_ReadPublic (TPM_CC)(0x00000169) +#define TPM_CC_PolicyAuthorize (TPM_CC)(0x0000016A) +#define TPM_CC_PolicyAuthValue (TPM_CC)(0x0000016B) +#define TPM_CC_PolicyCommandCode (TPM_CC)(0x0000016C) +#define TPM_CC_PolicyCounterTimer (TPM_CC)(0x0000016D) +#define TPM_CC_PolicyCpHash (TPM_CC)(0x0000016E) +#define TPM_CC_PolicyLocality (TPM_CC)(0x0000016F) +#define TPM_CC_PolicyNameHash (TPM_CC)(0x00000170) +#define TPM_CC_PolicyOR (TPM_CC)(0x00000171) +#define TPM_CC_PolicyTicket (TPM_CC)(0x00000172) +#define TPM_CC_ReadPublic (TPM_CC)(0x00000173) +#define TPM_CC_RSA_Encrypt (TPM_CC)(0x00000174) +#define TPM_CC_StartAuthSession (TPM_CC)(0x00000176) +#define TPM_CC_VerifySignature (TPM_CC)(0x00000177) +#define TPM_CC_ECC_Parameters (TPM_CC)(0x00000178) +#define TPM_CC_FirmwareRead (TPM_CC)(0x00000179) +#define TPM_CC_GetCapability (TPM_CC)(0x0000017A) +#define TPM_CC_GetRandom (TPM_CC)(0x0000017B) +#define TPM_CC_GetTestResult (TPM_CC)(0x0000017C) +#define TPM_CC_Hash (TPM_CC)(0x0000017D) +#define TPM_CC_PCR_Read (TPM_CC)(0x0000017E) +#define TPM_CC_PolicyPCR (TPM_CC)(0x0000017F) +#define TPM_CC_PolicyRestart (TPM_CC)(0x00000180) +#define TPM_CC_ReadClock (TPM_CC)(0x00000181) +#define TPM_CC_PCR_Extend (TPM_CC)(0x00000182) +#define TPM_CC_PCR_SetAuthValue (TPM_CC)(0x00000183) +#define TPM_CC_NV_Certify (TPM_CC)(0x00000184) +#define TPM_CC_EventSequenceComplete (TPM_CC)(0x00000185) +#define TPM_CC_HashSequenceStart (TPM_CC)(0x00000186) +#define TPM_CC_PolicyPhysicalPresence (TPM_CC)(0x00000187) +#define TPM_CC_PolicyDuplicationSelect (TPM_CC)(0x00000188) +#define TPM_CC_PolicyGetDigest (TPM_CC)(0x00000189) +#define TPM_CC_TestParms (TPM_CC)(0x0000018A) +#define TPM_CC_Commit (TPM_CC)(0x0000018B) +#define TPM_CC_PolicyPassword (TPM_CC)(0x0000018C) +#define TPM_CC_SM2_ZGen (TPM_CC)(0x0000018D) +#define TPM_CC_LAST (TPM_CC)(0x0000018D) + + +//TPM_RC +typedef UINT32 TPM_RC ; + +// TPM_ST Constants +typedef UINT16 TPM_ST ; +#define TPM_ST_NULL (TPM_ST)(0X8000) +#define TPM_ST_NO_SESSIONS (TPM_ST)(0x8001) +#define TPM_ST_SESSIONS (TPM_ST)(0x8002) + + +// TPM Handle types +typedef UINT32 TPM_HANDLE ; +typedef UINT8 TPM_HT ; + + +// TPM_RH Constants +typedef UINT32 TPM_RH ; + +#define TPM_RH_FIRST (TPM_RH)(0x40000000) +#define TPM_RH_SRK (TPM_RH)(0x40000000) +#define TPM_RH_OWNER (TPM_RH)(0x40000001) +#define TPM_RS_PW (TPM_RH)(0x40000009) +#define TPM_RH_LOCKOUT (TPM_RH)(0x4000000A) +#define TPM_RH_ENDORSEMENT (TPM_RH)(0x4000000B) +#define TPM_RH_PLATFORM (TPM_RH)(0x4000000C) +#define TPM_RH_LAST (TPM_RH)(0x4000000C) + +// Table 4 -- DocumentationClarity Types <I/O> +typedef UINT32 TPM_ALGORITHM_ID ; +typedef UINT32 TPM_MODIFIER_INDICATOR ; +typedef UINT32 TPM_SESSION_OFFSET ; +typedef UINT16 TPM_KEY_SIZE ; +typedef UINT16 TPM_KEY_BITS ; +typedef UINT64 TPM_SYSTEM_ADDRESS ; +typedef UINT32 TPM_SPEC ; + +// Table 29 -- TPMA_ALGORITHM Bits <I/O> +typedef struct { +unsigned int asymmetric:1 ; +unsigned int symmetric:1 ; +unsigned int hash:1 ; +unsigned int object:1 ; +unsigned int reserved5:4 ; +unsigned int signing:1 ; +unsigned int encrypting:1 ; +unsigned int method:1 ; +unsigned int reserved9:21 ; +}TPMA_ALGORITHM ; + +typedef UINT32 TPMA_OBJECT ; +typedef BYTE TPMA_SESSION ; +typedef BYTE TPMA_LOCALITY ; + +// Table 37 -- TPMI_YES_NO Type <I/O> +typedef BYTE TPMI_YES_NO ; + +typedef TPM_HANDLE TPMI_RH_HIERARCHY_AUTH ; + +// Table 38 -- TPMI_DH_OBJECT Type <I/O> +typedef TPM_HANDLE TPMI_DH_OBJECT ; + +// Table 39 -- TPMI_DH_PERSISTENT Type <I/O> +typedef TPM_HANDLE TPMI_DH_PERSISTENT ; + +// Table 42 -- TPMI_SH_AUTH_SESSION Type <I/O> +typedef TPM_HANDLE TPMI_SH_AUTH_SESSION ; + +// Table 40 -- TPMI_DH_ENTITY Type <I> +typedef TPM_HANDLE TPMI_DH_ENTITY ; + +// Table 45 -- TPMI_DH_CONTEXT Type <I/O> +typedef TPM_HANDLE TPMI_DH_CONTEXT ; + +// Table 46 -- TPMI_RH_HIERARCHY Type <I/O> +typedef TPM_HANDLE TPMI_RH_HIERARCHY ; + +// Table 47 -- TPMI_RH_HIERARCHY_AUTH Type <I> +typedef TPM_HANDLE TPMI_RH_HIERARCHY_AUTH ; + +// Table 48 -- TPMI_RH_PLATFORM Type <I> +typedef TPM_HANDLE TPMI_RH_PLATFORM ; + +// Table 49 -- TPMI_RH_OWNER Type <I> +typedef TPM_HANDLE TPMI_RH_OWNER ; + +// Table 50 -- TPMI_RH_ENDORSEMENT Type <I> +typedef TPM_HANDLE TPMI_RH_ENDORSEMENT ; + +// Table 51 -- TPMI_RH_PROVISION Type <I> +typedef TPM_HANDLE TPMI_RH_PROVISION ; + +// Table 52 -- TPMI_RH_CLEAR Type <I> +typedef TPM_HANDLE TPMI_RH_CLEAR ; + +// Table 54 -- TPMI_RH_LOCKOUT Type <I> +typedef TPM_HANDLE TPMI_RH_LOCKOUT ; + +// Table 7 -- TPM_ALG_ID +typedef UINT16 TPM_ALG_ID ; +typedef UINT16 TPM_ALG_ID ; + +#define TPM2_ALG_ERROR (TPM_ALG_ID)(0x0000) // a: ; D: +#define TPM2_ALG_FIRST (TPM_ALG_ID)(0x0001) // a: ; D: +#if ALG_RSA ==YES ||ALG_ALL ==YES +#define TPM2_ALG_RSA (TPM_ALG_ID)(0x0001) // a: A O; D: +#endif +#if ALG_DES ==YES ||ALG_ALL ==YES +#define TPM2_ALG_DES (TPM_ALG_ID)(0x0002) // a: S; D: +#endif +#define TPM2_ALG_SHA1 (TPM_ALG_ID)(0x0004) // a: H; D: +#if ALG_HMAC ==YES ||ALG_ALL ==YES +#define TPM2_ALG_HMAC (TPM_ALG_ID)(0x0005) // a: H X; D: +#endif +#if ALG_AES ==YES ||ALG_ALL ==YES +#define TPM2_ALG_AES (TPM_ALG_ID)(0x0006) // a: S; D: +#endif +#if ALG_XOR ==YES ||ALG_ALL ==YES +#define TPM2_ALG_XOR (TPM_ALG_ID)(0x000A) // a: H S; D: +#endif +#if ALG_MGF1 ==YES ||ALG_ALL ==YES +#define TPM2_ALG_MGF1 (TPM_ALG_ID)(0x0007) // a: H M; D: +#endif +#if ALG_KEYEDHASH ==YES ||ALG_ALL ==YES +#define TPM2_ALG_KEYEDHASH (TPM_ALG_ID)(0x0008) // a: H E X O; D: +#endif +#if ALG_SHA256 ==YES ||ALG_ALL ==YES +#define TPM2_ALG_SHA256 (TPM_ALG_ID)(0x000B) // a: H; D: +#endif +#define TPM2_ALG_NULL (TPM_ALG_ID)(0x0010) // a: ; D: +#if ALG_OAEP ==YES ||ALG_ALL ==YES +#define TPM2_ALG_OAEP (TPM_ALG_ID)(0x0017) // a: A E; D: RSA +#endif +#if ALG_ECC ==YES ||ALG_ALL ==YES +#define TPM2_ALG_ECC (TPM_ALG_ID)(0x0023) // a: A O; D: +#endif +#if ALG_SM4 ==YES ||ALG_ALL ==YES +#define TPM2_ALG_SM4 (TPM_ALG_ID)(0x0013) // a: S; D: +#endif +#if ALG_SYMCIPHER ==YES ||ALG_ALL ==YES +#define TPM2_ALG_SYMCIPHER (TPM_ALG_ID)(0x0025) // a: O; D: +#endif +#if ALG_CFB ==YES ||ALG_ALL ==YES +#define TPM2_ALG_CFB (TPM_ALG_ID)(0x0043) // a: S E; D: +#endif +#define TPM2_ALG_LAST (TPM_ALG_ID)(0x0044) + +#define SHA1_DIGEST_SIZE 20 +#define SHA1_BLOCK_SIZE 64 +#define SHA256_DIGEST_SIZE 32 +#define SHA256_BLOCK_SIZE 64 + +// Table 57 -- TPMI_ALG_ASYM Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_ASYM ; + +// Table 56 -- TPMI_ALG_HASH Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_HASH ; + +// Table 58 -- TPMI_ALG_SYM Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_SYM ; + +// Table 59 -- TPMI_ALG_SYM_OBJECT Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_SYM_OBJECT ; + +// Table 60 -- TPMI_ALG_SYM_MODE Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_SYM_MODE ; + +// Table 61 -- TPMI_ALG_KDF Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_KDF ; + +// Table 62 -- TPMI_ALG_SIG_SCHEME Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_SIG_SCHEME ; + +// Table 65 -- TPMU_HA Union <I/O,S> +typedef union { +#ifdef TPM2_ALG_SHA1 +BYTE sha1[SHA1_DIGEST_SIZE ]; +#endif +#ifdef TPM2_ALG_SHA256 +BYTE sha256[SHA256_DIGEST_SIZE ]; +#endif +#ifdef TPM2_ALG_SM3_256 +BYTE sm3_256[SM3_256_DIGEST_SIZE ]; +#endif +#ifdef TPM2_ALG_SHA384 +BYTE sha384[SHA384_DIGEST_SIZE ]; +#endif +#ifdef TPM2_ALG_SHA512 +BYTE sha512[SHA512_DIGEST_SIZE ]; +#endif +#ifdef TPM2_ALG_WHIRLPOOL512 +BYTE whirlpool[WHIRLPOOL512_DIGEST_SIZE ]; +#endif + +}TPMU_HA ; + +// Table 67 -- TPM2B_DIGEST Structure <I/O> +typedef struct { +UINT16 size; +BYTE buffer[sizeof (TPMU_HA )]; +}TPM2B_DIGEST ; + +// Table 69 -- TPM2B_NONCE Types <I/O> +typedef TPM2B_DIGEST TPM2B_NONCE ; + +typedef TPM2B_DIGEST TPM2B_DATA ; + +// Table 70 -- TPM2B_AUTH Types <I/O> +typedef TPM2B_DIGEST TPM2B_AUTH ; + +// Table 71 -- TPM2B_OPERAND Types <I/O> +typedef TPM2B_DIGEST TPM2B_OPERAND ; + +// Table 66 -- TPMT_HA Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +TPMU_HA digest; +}TPMT_HA ; + +//Table 80 -- TPM2B_NAME Structure +typedef struct { +UINT16 size; +BYTE name[sizeof (TPMT_HA )]; +}TPM2B_NAME ; + +#define IMPLEMENTATION_PCR 24 +#define PLATFORM_PCR 24 +#define PCR_SELECT_MAX ((IMPLEMENTATION_PCR+7)/8) + +//Table 79 -- TPMS_PCR_SELECT Structure <I/O> +typedef struct { +UINT8 sizeofSelect; +BYTE pcrSelect[PCR_SELECT_MAX ]; +}TPMS_PCR_SELECT ; + +// Table 80 -- TPMS_PCR_SELECTION Structure <I/O> +typedef struct { +TPMI_ALG_HASH hash; +UINT8 sizeofSelect; +BYTE pcrSelect[PCR_SELECT_MAX ]; +}TPMS_PCR_SELECTION ; + +// Table 83 -- TPMT_TK_CREATION Structure <I/O> +typedef struct { +TPM_ST tag; +TPMI_RH_HIERARCHY hierarchy; +TPM2B_DIGEST digest; +}TPMT_TK_CREATION ; + +// Table 96 -- Definition of TPML_DIGEST Structure <I/O> +typedef struct { +UINT32 count; +TPM2B_DIGEST digests[8 ]; +}TPML_DIGEST ; + +// Table 97 -- TPML_PCR_SELECTION Structure <I/O> +typedef struct { +UINT32 count; +TPMS_PCR_SELECTION pcrSelections[HASH_COUNT ]; +}TPML_PCR_SELECTION ; + +// Table 119 -- TPMI_AES_KEY_BITS Type <I/O> +typedef TPM_KEY_BITS TPMI_AES_KEY_BITS ; + +// Table 120 -- TPMI_SM4_KEY_BITS Type <I/O> +typedef TPM_KEY_BITS TPMI_SM4_KEY_BITS ; + +// Table 121 -- TPMU_SYM_KEY_BITS Union <I/O> +typedef union { +#ifdef TPM2_ALG_AES +TPMI_AES_KEY_BITS aes; +#endif +#ifdef TPM2_ALG_SM4 +TPMI_SM4_KEY_BITS SM4; +#endif +TPM_KEY_BITS sym; +#ifdef TPM2_ALG_XOR +TPMI_ALG_HASH xor; +#endif + +}TPMU_SYM_KEY_BITS ; + +// Table 122 -- TPMU_SYM_MODE Union <I/O> +typedef union { +#ifdef TPM2_ALG_AES +TPMI_ALG_SYM_MODE aes; +#endif +#ifdef TPM2_ALG_SM4 +TPMI_ALG_SYM_MODE SM4; +#endif +TPMI_ALG_SYM_MODE sym; +}TPMU_SYM_MODE ; + +// Table 124 -- TPMT_SYM_DEF Structure <I/O> +typedef struct { +TPMI_ALG_SYM algorithm; +TPMU_SYM_KEY_BITS keyBits; +TPMU_SYM_MODE mode; +}TPMT_SYM_DEF ; + +// Table 125 -- TPMT_SYM_DEF_OBJECT Structure <I/O> +typedef struct { +TPMI_ALG_SYM_OBJECT algorithm; +TPMU_SYM_KEY_BITS keyBits; +TPMU_SYM_MODE mode; +}TPMT_SYM_DEF_OBJECT ; + +// Table 126 -- TPM2B_SYM_KEY Structure <I/O> +typedef struct { +UINT16 size; +BYTE buffer[MAX_SYM_KEY_BYTES ]; +}TPM2B_SYM_KEY ; + +// Table 127 -- TPMS_SYMCIPHER_PARMS Structure <I/O> +typedef struct { +TPMT_SYM_DEF_OBJECT sym; +}TPMS_SYMCIPHER_PARMS ; + +// Table 128 -- TPM2B_SENSITIVE_DATA Structure <I/O> +typedef struct { +UINT16 size; +BYTE buffer[MAX_SYM_DATA ]; +}TPM2B_SENSITIVE_DATA ; + +// Table 129 -- TPMS_SENSITIVE_CREATE Structure <I> +typedef struct { +TPM2B_AUTH userAuth; +TPM2B_SENSITIVE_DATA data; +}TPMS_SENSITIVE_CREATE ; + +// Table 130 -- TPM2B_SENSITIVE_CREATE Structure <I,S> +typedef struct { +UINT16 size; +TPMS_SENSITIVE_CREATE sensitive; +}TPM2B_SENSITIVE_CREATE ; + +// Table 131 -- TPMS_SCHEME_SIGHASH Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +}TPMS_SCHEME_SIGHASH ; + +// Table 132 -- TPMI_ALG_KEYEDHASH_SCHEME Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_KEYEDHASH_SCHEME ; + +// Table 133 -- HMAC_SIG_SCHEME Types <I/O> +typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_HMAC ; + +// Table 134 -- TPMS_SCHEME_XOR Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +TPMI_ALG_KDF kdf; +}TPMS_SCHEME_XOR ; + +// Table 135 -- TPMU_SCHEME_KEYEDHASH Union <I/O,S> +typedef union { +#ifdef TPM2_ALG_HMAC +TPMS_SCHEME_HMAC hmac; +#endif +#ifdef TPM2_ALG_XOR +TPMS_SCHEME_XOR xor; +#endif + +}TPMU_SCHEME_KEYEDHASH ; + +// Table 136 -- TPMT_KEYEDHASH_SCHEME Structure <I/O> +typedef struct { +TPMI_ALG_KEYEDHASH_SCHEME scheme; +TPMU_SCHEME_KEYEDHASH details; +}TPMT_KEYEDHASH_SCHEME ; + +// Table 137 -- RSA_SIG_SCHEMES Types <I/O> +typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_RSASSA ; +typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_RSAPSS ; + +// Table 138 -- ECC_SIG_SCHEMES Types <I/O> +typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_ECDSA ; +typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_SM2 ; + +// Table 139 -- TPMS_SCHEME_ECDAA Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +UINT16 count; +}TPMS_SCHEME_ECDAA ; + +// Table 140 -- TPMS_SCHEME_ECSCHNORR Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +UINT16 count; +}TPMS_SCHEME_ECSCHNORR ; + +// Table 141 -- TPMU_SIG_SCHEME Union <I/O,S> +typedef union { +#ifdef TPM2_ALG_RSASSA +TPMS_SCHEME_RSASSA rsassa; +#endif +#ifdef TPM2_ALG_RSAPSS +TPMS_SCHEME_RSAPSS rsapss; +#endif +#ifdef TPM2_ALG_ECDSA +TPMS_SCHEME_ECDSA ecdsa; +#endif +#ifdef TPM2_ALG_SM2 +TPMS_SCHEME_SM2 sm2; +#endif +#ifdef TPM2_ALG_ECDAA +TPMS_SCHEME_ECDAA ecdaa; +#endif +#ifdef TPM2_ALG_ECSCHNORR +TPMS_SCHEME_ECSCHNORR ecSchnorr; +#endif +#ifdef TPM2_ALG_HMAC +TPMS_SCHEME_HMAC hmac; +#endif +TPMS_SCHEME_SIGHASH any; +}TPMU_SIG_SCHEME ; + +// Table 142 -- TPMT_SIG_SCHEME Structure <I/O> +typedef struct { +TPMI_ALG_SIG_SCHEME scheme; +TPMU_SIG_SCHEME details; +}TPMT_SIG_SCHEME ; + +// Table 143 -- TPMS_SCHEME_OAEP Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +}TPMS_SCHEME_OAEP ; + +// Table 144 -- TPMS_SCHEME_ECDH Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +}TPMS_SCHEME_ECDH ; + +// Table 145 -- TPMS_SCHEME_MGF1 Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +}TPMS_SCHEME_MGF1 ; + +// Table 146 -- TPMS_SCHEME_KDF1_SP800_56a Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +}TPMS_SCHEME_KDF1_SP800_56a ; + +// Table 147 -- TPMS_SCHEME_KDF2 Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +}TPMS_SCHEME_KDF2 ; + +// Table 148 -- TPMS_SCHEME_KDF1_SP800_108 Structure <I/O> +typedef struct { +TPMI_ALG_HASH hashAlg; +}TPMS_SCHEME_KDF1_SP800_108 ; + +// Table 149 -- TPMU_KDF_SCHEME Union <I/O,S> +typedef union { +#ifdef TPM2_ALG_MGF1 +TPMS_SCHEME_MGF1 mgf1; +#endif +#ifdef TPM2_ALG_KDF1_SP800_56a +TPMS_SCHEME_KDF1_SP800_56a kdf1_SP800_56a; +#endif +#ifdef TPM2_ALG_KDF2 +TPMS_SCHEME_KDF2 kdf2; +#endif +#ifdef TPM2_ALG_KDF1_SP800_108 +TPMS_SCHEME_KDF1_SP800_108 kdf1_sp800_108; +#endif + +}TPMU_KDF_SCHEME ; + +// Table 150 -- TPMT_KDF_SCHEME Structure <I/O> +typedef struct { +TPMI_ALG_KDF scheme; +TPMU_KDF_SCHEME details; +}TPMT_KDF_SCHEME ; +typedef TPM_ALG_ID TPMI_ALG_ASYM_SCHEME ; + +// Table 152 -- TPMU_ASYM_SCHEME Union <I/O> +typedef union { +#ifdef TPM2_ALG_RSASSA +TPMS_SCHEME_RSASSA rsassa; +#endif +#ifdef TPM2_ALG_RSAPSS +TPMS_SCHEME_RSAPSS rsapss; +#endif +#ifdef TPM2_ALG_OAEP +TPMS_SCHEME_OAEP oaep; +#endif +#ifdef TPM2_ALG_ECDSA +TPMS_SCHEME_ECDSA ecdsa; +#endif +#ifdef TPM2_ALG_SM2 +TPMS_SCHEME_SM2 sm2; +#endif +#ifdef TPM2_ALG_ECDAA +TPMS_SCHEME_ECDAA ecdaa; +#endif +#ifdef TPM2_ALG_ECSCHNORR +TPMS_SCHEME_ECSCHNORR ecSchnorr; +#endif +TPMS_SCHEME_SIGHASH anySig; +}TPMU_ASYM_SCHEME ; + +typedef struct { +TPMI_ALG_ASYM_SCHEME scheme; +TPMU_ASYM_SCHEME details; +}TPMT_ASYM_SCHEME ; + +// Table 154 -- TPMI_ALG_RSA_SCHEME Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_RSA_SCHEME ; + +// Table 155 -- TPMT_RSA_SCHEME Structure <I/O> +typedef struct { +TPMI_ALG_RSA_SCHEME scheme; +TPMU_ASYM_SCHEME details; +}TPMT_RSA_SCHEME ; + +// Table 156 -- TPMI_ALG_RSA_DECRYPT Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_RSA_DECRYPT ; + +// Table 157 -- TPMT_RSA_DECRYPT Structure <I/O> +typedef struct { +TPMI_ALG_RSA_DECRYPT scheme; +TPMU_ASYM_SCHEME details; +}TPMT_RSA_DECRYPT ; + +// Table 158 -- TPM2B_PUBLIC_KEY_RSA Structure <I/O> +typedef struct { +UINT16 size; +BYTE buffer[MAX_RSA_KEY_BYTES ]; +}TPM2B_PUBLIC_KEY_RSA ; + +// Table 159 -- TPMI_RSA_KEY_BITS Type <I/O> +typedef TPM_KEY_BITS TPMI_RSA_KEY_BITS ; + +// Table 160 -- TPM2B_PRIVATE_KEY_RSA Structure <I/O> +typedef struct { +UINT16 size; +BYTE buffer[MAX_RSA_KEY_BYTES /2 ]; +}TPM2B_PRIVATE_KEY_RSA ; + +// Table 162 -- TPM2B_ECC_PARAMETER +typedef struct { +UINT16 size; +BYTE buffer[MAX_ECC_KEY_BYTES ]; +}TPM2B_ECC_PARAMETER ; + +// Table 163 -- TPMS_ECC_POINT Structure <I/O> +typedef struct { +TPM2B_ECC_PARAMETER x; +TPM2B_ECC_PARAMETER y; +}TPMS_ECC_POINT ; + +// Table 164 -- TPMI_ALG_ECC_SCHEME Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_ECC_SCHEME ; + +typedef UINT16 TPM_ECC_CURVE ; + +// Table 165 -- TPMI_ECC_CURVE Type <I/O> +typedef TPM_ECC_CURVE TPMI_ECC_CURVE ; + +// Table 166 -- TPMT_ECC_SCHEME Structure <I/O> +typedef struct { +TPMI_ALG_ECC_SCHEME scheme; +TPMU_SIG_SCHEME details; +}TPMT_ECC_SCHEME ; + +// Table 175 -- TPMI_ALG_PUBLIC Type <I/O> +typedef TPM_ALG_ID TPMI_ALG_PUBLIC ; + +// Table 176 -- TPMU_PUBLIC_ID Union <I/O,S> +typedef union { +#ifdef TPM2_ALG_KEYEDHASH +TPM2B_DIGEST keyedHash; +#endif +#ifdef TPM2_ALG_SYMCIPHER +TPM2B_DIGEST sym; +#endif +#ifdef TPM2_ALG_RSA +TPM2B_PUBLIC_KEY_RSA rsa; +#endif +#ifdef TPM2_ALG_ECC +TPMS_ECC_POINT ecc; +#endif +}TPMU_PUBLIC_ID ; + +// Table 177 -- TPMS_KEYEDHASH_PARMS Structure <I/O> +typedef struct { +TPMT_KEYEDHASH_SCHEME scheme; +}TPMS_KEYEDHASH_PARMS ; +typedef struct { +TPMT_SYM_DEF_OBJECT symmetric; +TPMT_ASYM_SCHEME scheme; +}TPMS_ASYM_PARMS ; + +// Table 179 -- TPMS_RSA_PARMS Structure <I/O> +typedef struct { +TPMT_SYM_DEF_OBJECT symmetric; +TPMT_RSA_SCHEME scheme; +TPMI_RSA_KEY_BITS keyBits; +UINT32 exponent; +}TPMS_RSA_PARMS ; + +// Table 180 -- TPMS_ECC_PARMS Structure <I/O> +typedef struct { +TPMT_SYM_DEF_OBJECT symmetric; +TPMT_ECC_SCHEME scheme; +TPMI_ECC_CURVE curveID; +TPMT_KDF_SCHEME kdf; +}TPMS_ECC_PARMS ; + +// Table 181 -- TPMU_PUBLIC_PARMS Union <I/O,S> +typedef union { +#ifdef TPM2_ALG_KEYEDHASH +TPMS_KEYEDHASH_PARMS keyedHashDetail; +#endif +#ifdef TPM2_ALG_SYMCIPHER +TPMT_SYM_DEF_OBJECT symDetail; +#endif +#ifdef TPM2_ALG_RSA +TPMS_RSA_PARMS rsaDetail; +#endif +#ifdef TPM2_ALG_ECC +TPMS_ECC_PARMS eccDetail; +#endif +TPMS_ASYM_PARMS asymDetail; +}TPMU_PUBLIC_PARMS ; + +// Table 182 -- TPMT_PUBLIC_PARMS Structure <I/O> +typedef struct { +TPMI_ALG_PUBLIC type; +TPMU_PUBLIC_PARMS parameters; +}TPMT_PUBLIC_PARMS ; + +// Table 183 -- TPMT_PUBLIC Structure <I/O> +typedef struct { +TPMI_ALG_PUBLIC type; +TPMI_ALG_HASH nameAlg; +TPMA_OBJECT objectAttributes; +TPM2B_DIGEST authPolicy; +TPMU_PUBLIC_PARMS parameters; +TPMU_PUBLIC_ID unique; +}TPMT_PUBLIC ; + +// Table 184 -- TPM2B_PUBLIC +typedef struct { +UINT16 size; +TPMT_PUBLIC publicArea; +}TPM2B_PUBLIC ; + +// Table 185 -- TPMU_SENSITIVE_COMPOSITE Union <I/O,S> +typedef union { +#ifdef TPM2_ALG_RSA +TPM2B_PRIVATE_KEY_RSA rsa; +#endif +#ifdef TPM2_ALG_ECC +TPM2B_ECC_PARAMETER ecc; +#endif +#ifdef TPM2_ALG_KEYEDHASH +TPM2B_SENSITIVE_DATA bits; +#endif +#ifdef TPM2_ALG_SYMCIPHER +TPM2B_SYM_KEY sym; +#endif +TPM2B_SENSITIVE_DATA any; +}TPMU_SENSITIVE_COMPOSITE ; + +// Table 186 -- TPMT_SENSITIVE Structure <I/O> +typedef struct { +TPMI_ALG_PUBLIC sensitiveType; +TPM2B_AUTH authValue; +TPM2B_DIGEST seedValue; +TPMU_SENSITIVE_COMPOSITE sensitive; +}TPMT_SENSITIVE ; + +// Table 187 -- TPM2B_SENSITIVE Structure <I/O> +typedef struct { +UINT16 size; +TPMT_SENSITIVE sensitiveArea; +}TPM2B_SENSITIVE ; + +typedef struct { +TPM2B_DIGEST integrityOuter; +TPM2B_DIGEST integrityInner; +TPMT_SENSITIVE sensitive; +}_PRIVATE ; + +// Table 189 -- TPM2B_PRIVATE Structure <I/O,S> +typedef struct { +UINT16 size; +BYTE buffer[sizeof (_PRIVATE)]; +}TPM2B_PRIVATE ; + +// Table 204 -- TPMS_CREATION_DATA <OUT> +typedef struct { +TPML_PCR_SELECTION pcrSelect; +TPM2B_DIGEST pcrDigest; +TPMA_LOCALITY locality; +TPM_ALG_ID parentNameAlg; +TPM2B_NAME parentName; +TPM2B_NAME parentQualifiedName; +TPM2B_DATA outsideInfo; +}TPMS_CREATION_DATA ; + +// Table 205 -- TPM2B_CREATION_DATA <OUT> +typedef struct { +UINT16 size; +TPMS_CREATION_DATA creationData; +}TPM2B_CREATION_DATA ; + +/* the following structs is not part of standard struct defined in TPM2 spec */ +typedef struct { +UINT32 size; +TPM_RH sessionHandle; +TPM2B_NONCE nonce; +TPMA_SESSION sessionAttributes; +TPM2B_AUTH auth; +}TPM_AuthArea ; + +typedef struct { +TPM2B_SENSITIVE_CREATE inSensitive; +TPM2B_PUBLIC inPublic; +TPM2B_DATA outsideInfo; +TPML_PCR_SELECTION creationPCR; +}TPM2_Create_Params_in ; + +typedef TPM2_Create_Params_in TPM2_CreatePrimary_Params_in ; + +typedef struct { +TPM2B_PUBLIC outPublic; +TPM2B_CREATION_DATA creationData; +TPM2B_DIGEST creationHash; +TPMT_TK_CREATION creationTicket; +TPM2B_NAME name; +}TPM2_CreatePrimary_Params_out ; + +typedef struct { +TPM2B_PRIVATE outPrivate; +TPM2B_PUBLIC outPublic; +TPM2B_CREATION_DATA creationData; +TPM2B_DIGEST creationHash; +TPMT_TK_CREATION creationTicket; +}TPM2_Create_Params_out ; +typedef struct { +TPM2B_PRIVATE Private; +TPM2B_PUBLIC Public; +}TPM2_RSA_KEY ; + +/* +* TPM 2.0 Objects +*/ + +#define TPM_HT_TRANSIENT 0x80 +#define HR_SHIFT 24 +#define HR_PERMANENT (TPM_HT_TRANSIENT << HR_SHIFT) +#define TRANSIENT_FIRST (HR_PERMANENT) +#define MAX_LOADED_OBJECTS 3 +#define TRANSIENT_LAST (TRANSIENT_FIRST+MAX_LOADED_OBJECTS-1) +/* +* TPMA_OBJECT Bits +*/ +#define fixedTPM ((1 << 1)) +#define stClear ((1 << 2)) +#define fixedParent ((1 << 4)) +#define sensitiveDataOrigin ((1 << 5)) +#define userWithAuth ((1 << 6)) +#define adminWithPolicy ((1 << 7)) +#define noDA ((1 << 10)) +#define encryptedDuplication ((1 << 11)) +#define restricted ((1 << 16)) +#define decrypt ((1 << 17)) +#define sign ((1 << 18)) +#endif
Signature · 1 line
1.8.3.2
PATCH v4 2/14 vTPM/TPM2: TPM 2.0 data structures marshal
In reply to Quan XuAdd TPM 2.0 data structure marshal for packing and unpacking TPM 2.0 data structures.
--- stubdom/vtpmmgr/tpm2_marshal.h | 673 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 673 insertions(+) create mode 100644 stubdom/vtpmmgr/tpm2_marshal.h
stubdom/vtpmmgr/tpm2_marshal.h new file +673 -0
@@ -0,0 +1,673 @@ +/* +* Copyright (c) 2014 Intel Corporation. +* +* Authors: +* Quan Xu <[email protected]> +* +* Copyright (c) 2010-2012 United States Government, as represented by +* the Secretary of Defense. All rights reserved. +* +* based off of the original tools/vtpm_manager code base which is: +* Copyright (c) 2005, Intel Corp. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +* OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef TPM2_MARSHAL_H +#define TPM2_MARSHAL_H + +#include <stdlib.h> +#include <mini-os/byteorder.h> +#include <mini-os/endian.h> +#include "tcg.h" +#include "tpm2_types.h" +#include <assert.h> + +#define pack_TPM_BUFFER (ptr, buf, size) pack_BUFFER(ptr, buf, size) +#define unpack_TPM_BUFFER (ptr, buf, size) unpack_BUFFER(ptr, buf, size) + +inline BYTE *pack_BYTE_ARRAY (BYTE * ptr,const BYTE * array,UINT32 size) +{ +int i; +for (i =0 ; i < size; i++) + ptr =pack_BYTE (ptr, array[i]); +return ptr; +} + +inline BYTE *pack_TPMA_SESSION (BYTE * ptr,const TPMA_SESSION *attr) +{ +return pack_BYTE (ptr, (BYTE )(*attr)); +} + +inline BYTE *unpack_TPMA_SESSION (BYTE * ptr,TPMA_SESSION *attr) +{ +return unpack_BYTE (ptr, (BYTE *)attr); +} + +inline BYTE *pack_TPMI_ALG_HASH (BYTE * ptr,const TPMI_ALG_HASH *hash) +{ +return pack_UINT16 (ptr, *hash); +} + +inline BYTE *unpack_TPMI_ALG_HASH (BYTE *ptr,TPMI_ALG_HASH *hash) +{ +return unpack_UINT16 (ptr, hash); +} + +#define pack_TPMA_OBJECT (ptr, t) pack_UINT32(ptr, (UINT32)(*t)) +#define unpack_TPMA_OBJECT (ptr, t) unpack_UINT32(ptr, (UINT32 *)(t)) +#define pack_TPM_RH (ptr, t) pack_UINT32(ptr, (UINT32)(*t)) +#define unpack_TPM_RH (ptr, t) unpack_UINT32(ptr, (UINT32 *)(t)) +#define pack_TPMA_LOCALITY (ptr, locality) pack_BYTE(ptr, (BYTE)*locality) +#define unpack_TPMA_LOCALITY (ptr, locality) unpack_BYTE(ptr, (BYTE *)locality) +#define pack_TPM_ST (ptr, tag) pack_UINT16(ptr, *tag) +#define unpack_TPM_ST (ptr, tag) unpack_UINT16(ptr, tag) +#define pack_TPM_KEY_BITS (ptr, t) pack_UINT16(ptr, *t) +#define unpack_TPM_KEY_BITS (ptr, t) unpack_UINT16(ptr, t) +#define pack_TPMI_AES_KEY_BITS (ptr, t) pack_TPM_KEY_BITS(ptr, t) +#define unpack_TPMI_AES_KEY_BITS (ptr, t) unpack_TPM_KEY_BITS(ptr, t) +#define pack_TPMI_RSA_KEY_BITS (ptr, t) pack_TPM_KEY_BITS(ptr, t) +#define unpack_TPMI_RSA_KEY_BITS (ptr, t) unpack_TPM_KEY_BITS(ptr, t) +#define pack_TPM_ALG_ID (ptr, id) pack_UINT16(ptr, *id) +#define unpack_TPM_ALG_ID (ptr, id) unpack_UINT16(ptr, id) +#define pack_TPM_ALG_SYM (ptr, t) pack_TPM_ALG_ID(ptr, t) +#define unpack_TPM_ALG_SYM (ptr, t) unpack_TPM_ALG_ID(ptr, t) +#define pack_TPMI_ALG_ASYM (ptr, asym) pack_TPM_ALG_ID(ptr, asym) +#define unpack_TPMI_ALG_ASYM (ptr, asym) unpack_TPM_ALG_ID(ptr, asym) +#define pack_TPMI_ALG_SYM_OBJECT (ptr, t) pack_TPM_ALG_ID(ptr, t) +#define unpack_TPMI_ALG_SYM_OBJECT (ptr, t) unpack_TPM_ALG_ID(ptr, t) +#define pack_TPMI_ALG_SYM_MODE (ptr, t) pack_TPM_ALG_ID(ptr, t) +#define unpack_TPMI_ALG_SYM_MODE (ptr, t) unpack_TPM_ALG_ID(ptr, t) +#define pack_TPMI_ALG_KDF (ptr, t) pack_TPM_ALG_ID(ptr, t) +#define unpack_TPMI_ALG_KDF (ptr, t) unpack_TPM_ALG_ID(ptr, t) +#define pack_TPMI_ALG_PUBLIC (ptr, t) pack_TPM_ALG_ID(ptr, t) +#define unpack_TPMI_ALG_PUBLIC (ptr, t) unpack_TPM_ALG_ID(ptr, t) +#define pack_TPM2_HANDLE (ptr, h) pack_UINT32(ptr, *h) +#define unpack_TPM2_HANDLE (ptr, h) unpack_UINT32(ptr, h) +#define pack_TPMI_ALG_RSA_SCHEME (ptr, t) pack_TPM_ALG_ID(ptr, t) +#define unpack_TPMI_ALG_RSA_SCHEME (ptr, t) unpack_TPM_ALG_ID(ptr, t) +#define pack_TPMI_DH_OBJECT (ptr, o) pack_TPM2_HANDLE(ptr, o) +#define unpack_TPMI_DH_OBJECT (PTR ,O ) unpack_TPM2_HANDLE(ptr, o) +#define pack_TPMI_RH_HIERACHY (ptr, h) pack_TPM2_HANDLE(ptr, h) +#define unpack_TPMI_RH_HIERACHY (ptr, h) unpack_TPM2_HANDLE(ptr, h) +#define pack_TPMI_RH_PLATFORM (ptr, p) pack_TPM2_HANDLE(ptr, p) +#define unpack_TPMI_RH_PLATFORM (ptr, p) unpack_TPM2_HANDLE(ptr, p) +#define pack_TPMI_RH_OWNER (ptr, o) pack_TPM2_HANDLE(ptr, o) +#define unpack_TPMI_RH_OWNER (ptr, o) unpack_TPM2_HANDLE(ptr, o) +#define pack_TPMI_RH_ENDORSEMENT (ptr, e) pack_TPM2_HANDLE(ptr, e) +#define unpack_TPMI_RH_ENDORSEMENT (ptr, e) unpack_TPM2_HANDLE(ptr, e) +#define pack_TPMI_RH_LOCKOUT (ptr, l) pack_TPM2_HANDLE(ptr, l) +#define unpack_TPMI_RH_LOCKOUT (ptr, l) unpack_TPM2_HANDLE(ptr, l) + +inline BYTE *pack_TPM2B_DIGEST (BYTE * ptr,const TPM2B_DIGEST *digest) +{ + ptr =pack_UINT16 (ptr, digest->size); + ptr =pack_BUFFER (ptr, digest->buffer, digest->size); +return ptr; +} + +inline BYTE *unpack_TPM2B_DIGEST (BYTE * ptr,TPM2B_DIGEST *digest) +{ + ptr =unpack_UINT16 (ptr, &digest->size); + ptr =unpack_BUFFER (ptr, digest->buffer, digest->size); +return ptr; +} + +inline BYTE *pack_TPMT_TK_CREATION (BYTE * ptr,const TPMT_TK_CREATION *ticket ) +{ + ptr =pack_TPM_ST (ptr , &ticket->tag); + ptr =pack_TPMI_RH_HIERACHY (ptr , &ticket->hierarchy); + ptr =pack_TPM2B_DIGEST (ptr, &ticket->digest); +return ptr; +} + +inline BYTE *unpack_TPMT_TK_CREATION (BYTE * ptr,TPMT_TK_CREATION *ticket ) +{ + ptr =unpack_TPM_ST (ptr, &ticket->tag); + ptr =unpack_TPMI_RH_HIERACHY (ptr, &ticket->hierarchy); + ptr =unpack_TPM2B_DIGEST (ptr, &ticket->digest); +return ptr; +} + +inline BYTE *pack_TPM2B_NAME (BYTE * ptr,const TPM2B_NAME *name ) +{ + ptr =pack_UINT16 (ptr, name->size); + ptr =pack_TPM_BUFFER (ptr, name->name, name->size); +return ptr; +} + +inline BYTE *unpack_TPM2B_NAME (BYTE * ptr,TPM2B_NAME *name) +{ + ptr =unpack_UINT16 (ptr, &name->size); + ptr =unpack_TPM_BUFFER (ptr, name->name, name->size); +return ptr; +} + +inline BYTE *pack_TPM2B_NONCE (BYTE * ptr,const TPM2B_NONCE *nonce) +{ +return pack_TPM2B_DIGEST (ptr, (const TPM2B_DIGEST *)nonce); +} + +#define unpack_TPM2B_NONCE (ptr, nonce) unpack_TPM2B_DIGEST(ptr, (TPM2B_DIGEST*)nonce) + +inline BYTE *pack_TPM2B_AUTH (BYTE * ptr,const TPM2B_AUTH *auth) +{ +return pack_TPM2B_DIGEST (ptr, (const TPM2B_DIGEST *)auth); +} + +#define unpack_TPM2B_AUTH (ptr, auth) unpack_TPM2B_DIGEST(ptr, (TPM2B_DIGEST*)auth) + +inline BYTE *pack_TPM2B_DATA (BYTE * ptr,const TPM2B_DATA *data) +{ +return pack_TPM2B_DIGEST (ptr, (const TPM2B_DIGEST *)data); +} + +#define unpack_TPM2B_DATA (ptr, data) unpack_TPM2B_DIGEST(ptr, (TPM2B_DIGEST*)data) + +inline BYTE *pack_TPM2B_SENSITIVE_DATA (BYTE * ptr,const TPM2B_SENSITIVE_DATA *data) +{ +return pack_TPM2B_DIGEST (ptr, (const TPM2B_DIGEST *)data); +} + +#define unpack_TPM2B_SENSITIVE_DATA (ptr, data) unpack_TPM2B_DIGEST(ptr, (TPM2B_DIGEST*)data) + +inline BYTE *pack_TPM2B_PUBLIC_KEY_RSA (BYTE * ptr,const TPM2B_PUBLIC_KEY_RSA *rsa) +{ +return pack_TPM2B_DIGEST (ptr, (const TPM2B_DIGEST *)rsa); +} + +#define unpack_TPM2B_PUBLIC_KEY_RSA (ptr, rsa) unpack_TPM2B_DIGEST(ptr, (TPM2B_DIGEST*)rsa) + +inline BYTE *pack_TPM2B_PRIVATE (BYTE * ptr,const TPM2B_PRIVATE *Private) +{ + ptr =pack_UINT16 (ptr, Private->size); + ptr =pack_TPM_BUFFER (ptr, Private->buffer, Private->size); +return ptr; +} + +inline BYTE *unpack_TPM2B_PRIVATE (BYTE * ptr,TPM2B_PRIVATE *Private) +{ + ptr =unpack_UINT16 (ptr, &Private->size); + ptr =unpack_BUFFER (ptr, Private->buffer, Private->size); +return ptr; +} + +inline BYTE *pack_TPMS_PCR_SELECTION_ARRAY (BYTE * ptr,const TPMS_PCR_SELECTION *sel,UINT32 count) +{ +int i; +for (i =0 ; i < count; i++) { + ptr =pack_TPMI_ALG_HASH (ptr, &sel[i].hash); + ptr =pack_BYTE (ptr, sel[i].sizeofSelect); + ptr =pack_BUFFER (ptr, sel[i].pcrSelect, sel[i].sizeofSelect); + } +return ptr; +} + +inline BYTE *unpack_TPMS_PCR_SELECTION_ARRAY (BYTE * ptr,TPMS_PCR_SELECTION *sel,UINT32 count) +{ +int i; +for (i =0 ; i < count; i++) { + ptr =unpack_TPMI_ALG_HASH (ptr, &sel[i].hash); + ptr =unpack_BYTE (ptr, &sel[i].sizeofSelect); + ptr =unpack_BUFFER (ptr, sel[i].pcrSelect, sel[i].sizeofSelect); + } +return ptr; +} + +inline BYTE *pack_TPML_PCR_SELECTION (BYTE * ptr,const TPML_PCR_SELECTION *sel) +{ + ptr =pack_UINT32 (ptr, sel->count); + ptr =pack_TPMS_PCR_SELECTION_ARRAY (ptr, sel->pcrSelections, sel->count); +return ptr; +} + +inline BYTE *unpack_TPML_PCR_SELECTION (BYTE * ptr,TPML_PCR_SELECTION *sel) +{ + ptr =unpack_UINT32 (ptr, &sel->count); + ptr =unpack_TPMS_PCR_SELECTION_ARRAY (ptr, sel->pcrSelections, sel->count); +return ptr; +} + +inline BYTE *unpack_TPML_DIGEST (BYTE * ptr,TPML_DIGEST *digest) +{ +int i; + ptr =unpack_UINT32 (ptr, &digest->count); +for (i=0 ;i<digest->count;i++) + { + ptr =unpack_TPM2B_DIGEST (ptr, &digest->digests[i]); + } +return ptr; +} + +inline BYTE *pack_TPMS_CREATION_DATA (BYTE * ptr,const TPMS_CREATION_DATA *data) +{ + ptr =pack_TPML_PCR_SELECTION (ptr, &data->pcrSelect); + ptr =pack_TPM2B_DIGEST (ptr, &data->pcrDigest); + ptr =pack_TPMA_LOCALITY (ptr, &data->locality); + ptr =pack_TPM_ALG_ID (ptr, &data->parentNameAlg); + ptr =pack_TPM2B_NAME (ptr, &data->parentQualifiedName); + ptr =pack_TPM2B_DATA (ptr, &data->outsideInfo); +return ptr; +} + +inline BYTE *unpack_TPMS_CREATION_DATA (BYTE * ptr,TPMS_CREATION_DATA *data) +{ + ptr =unpack_TPML_PCR_SELECTION (ptr, &data->pcrSelect); + ptr =unpack_TPM2B_DIGEST (ptr, &data->pcrDigest); + ptr =unpack_TPMA_LOCALITY (ptr, &data->locality); + ptr =unpack_TPM_ALG_ID (ptr, &data->parentNameAlg); + ptr =unpack_TPM2B_NAME (ptr, &data->parentName); + ptr =unpack_TPM2B_NAME (ptr, &data->parentQualifiedName); + ptr =unpack_TPM2B_DATA (ptr, &data->outsideInfo); +return ptr; +} + +inline BYTE *pack_TPM2B_CREATION_DATA (BYTE * ptr,const TPM2B_CREATION_DATA *data ) +{ + ptr =pack_UINT16 (ptr, data->size); + ptr =pack_TPMS_CREATION_DATA (ptr, &data->creationData); +return ptr; +} + +inline BYTE *unpack_TPM2B_CREATION_DATA (BYTE * ptr,TPM2B_CREATION_DATA * data) +{ + ptr =unpack_UINT16 (ptr, &data->size); + ptr =unpack_TPMS_CREATION_DATA (ptr, &data->creationData); +return ptr; +} + +inline BYTE *pack_TPMS_SENSITIVE_CREATE (BYTE * ptr,const TPMS_SENSITIVE_CREATE *create) +{ + ptr =pack_TPM2B_AUTH (ptr, &create->userAuth); + ptr =pack_TPM2B_SENSITIVE_DATA (ptr, &create->data); +return ptr; +} + +inline BYTE *pack_TPM2B_SENSITIVE_CREATE (BYTE * ptr,const TPM2B_SENSITIVE_CREATE *create) +{ +BYTE * sizePtr = ptr; + ptr +=2 ; + ptr =pack_TPMS_SENSITIVE_CREATE (ptr, &create->sensitive); +pack_UINT16 (sizePtr, (UINT16 )(ptr - sizePtr -2 )); +return ptr; +} + +inline BYTE *pack_TPMU_SYM_MODE (BYTE * ptr,const TPMU_SYM_MODE *p, +const TPMI_ALG_SYM_OBJECT *sel) +{ +switch (*sel) { +case TPM2_ALG_AES : + ptr =pack_TPMI_ALG_SYM_MODE (ptr, &p->aes); +break ; +case TPM2_ALG_SM4 : +assert (false); +break ; +case TPM2_ALG_NULL : +case TPM2_ALG_XOR : +break ; +default : + ptr =pack_TPMI_ALG_SYM_MODE (ptr, &p->sym); + } +return ptr; +} +inline BYTE *unpack_TPMU_SYM_MODE (BYTE * ptr,TPMU_SYM_MODE *p, +const TPMI_ALG_SYM_OBJECT *sel) +{ +switch (*sel) { +case TPM2_ALG_AES : + ptr =unpack_TPMI_ALG_SYM_MODE (ptr, &p->aes); +break ; +case TPM2_ALG_SM4 : +assert (false); +break ; +case TPM2_ALG_NULL : +case TPM2_ALG_XOR : +break ; +default : + ptr =unpack_TPMI_ALG_SYM_MODE (ptr, &p->sym); + } +return ptr; +} + +inline BYTE *pack_TPMU_SYM_KEY_BITS (BYTE * ptr,const TPMU_SYM_KEY_BITS *p, +const TPMI_ALG_SYM_OBJECT *sel) +{ +switch (*sel) { +case TPM2_ALG_AES : + ptr =pack_TPMI_AES_KEY_BITS (ptr, &p->aes); +break ; +case TPM2_ALG_SM4 : +assert (false); +break ; +case TPM2_ALG_XOR : +assert (false); +break ; +case TPM2_ALG_NULL : +break ; +default : + ptr =pack_TPM_KEY_BITS (ptr, &p->sym); + } +return ptr; +} + +inline BYTE *unpack_TPMU_SYM_KEY_BITS (BYTE * ptr,TPMU_SYM_KEY_BITS *p, +const TPMI_ALG_SYM_OBJECT *sel) +{ +switch (*sel) { +case TPM2_ALG_AES : + ptr =unpack_TPMI_AES_KEY_BITS (ptr, &p->aes); +break ; +case TPM2_ALG_SM4 : +assert (false); +break ; +case TPM2_ALG_XOR : +assert (false); +break ; +case TPM2_ALG_NULL : +break ; +default : + ptr =unpack_TPM_KEY_BITS (ptr, &p->sym); + } +return ptr; +} + +inline BYTE *pack_TPMT_SYM_DEF_OBJECT (BYTE * ptr,const TPMT_SYM_DEF_OBJECT *p) +{ + ptr =pack_TPMI_ALG_SYM_OBJECT (ptr, &p->algorithm); + ptr =pack_TPMU_SYM_KEY_BITS (ptr, &p->keyBits, &p->algorithm); + ptr =pack_TPMU_SYM_MODE (ptr, &p->mode, &p->algorithm); +return ptr; +} + +inline BYTE *unpack_TPMT_SYM_DEF_OBJECT (BYTE *ptr,TPMT_SYM_DEF_OBJECT *p) +{ + ptr =unpack_TPMI_ALG_SYM_OBJECT (ptr, &p->algorithm); + ptr =unpack_TPMU_SYM_KEY_BITS (ptr, &p->keyBits, &p->algorithm); + ptr =unpack_TPMU_SYM_MODE (ptr, &p->mode, &p->algorithm); +return ptr; +} + +#define pack_TPMS_SCHEME_OAEP (p, t) pack_TPMI_ALG_HASH(p, &((t)->hashAlg)) +#define unpack_TPMS_SCHEME_OAEP (p, t) unpack_TPMI_ALG_HASH(p, &((t)->hashAlg)) + +inline BYTE *pack_TPMU_ASYM_SCHEME (BYTE *ptr,const TPMU_ASYM_SCHEME *p, +const TPMI_ALG_RSA_SCHEME *s) +{ +switch (*s) { +#ifdef TPM2_ALG_RSASSA +case TPM2_ALG_RSASSA : +assert (false ||"TPM2_ALG_RSASSA" ); +break ; +#endif +#ifdef TPM2_ALG_OAEP +case TPM2_ALG_OAEP : + ptr =pack_TPMS_SCHEME_OAEP (ptr, &p->oaep); +break ; +#endif +case TPM2_ALG_NULL : +break ; +default : +assert (false ||"DEFAULT" ); + } +return ptr; +} + +inline BYTE *unpack_TPMU_ASYM_SCHEME (BYTE *ptr,TPMU_ASYM_SCHEME *p, +const TPMI_ALG_RSA_SCHEME *s) +{ +switch (*s) { +#ifdef TPM2_ALG_RSASSA +case TPM2_ALG_RSASSA : +printf ("not support TPM_ALG_RSASSA\n" ); +assert (false); +break ; +#endif +#ifdef TPM2_ALG_OAEP +case TPM2_ALG_OAEP : + ptr =unpack_TPMS_SCHEME_OAEP (ptr, &p->oaep); +break ; +#endif +case TPM2_ALG_NULL : +break ; +default : +printf ("default TPMI_ALG_RSA_SCHEME 0x%X\n" , (UINT32 )*s); + ptr =unpack_TPMI_ALG_HASH (ptr, &p->anySig.hashAlg); + } +return ptr; +} + +inline BYTE *pack_TPMT_RSA_SCHEME (BYTE * ptr,const TPMT_RSA_SCHEME *p) +{ + ptr =pack_TPMI_ALG_RSA_SCHEME (ptr, &p->scheme); + ptr =pack_TPMU_ASYM_SCHEME (ptr, &p->details, &p->scheme); +return ptr; +} + +inline BYTE *unpack_TPMT_RSA_SCHEME (BYTE * ptr,TPMT_RSA_SCHEME *p) +{ + ptr =unpack_TPMI_ALG_RSA_SCHEME (ptr, &p->scheme); + ptr =unpack_TPMU_ASYM_SCHEME (ptr, &p->details, &p->scheme); +return ptr; +} + +inline BYTE *pack_TPMT_RSA_DECRYPT (BYTE * ptr,const TPMT_RSA_DECRYPT *p) +{ + ptr =pack_TPMI_ALG_RSA_SCHEME (ptr, &p->scheme); + ptr =pack_TPMU_ASYM_SCHEME (ptr, &p->details, &p->scheme); +return ptr; +} + +inline BYTE *pack_TPMS_RSA_PARMS (BYTE * ptr,const TPMS_RSA_PARMS *p) +{ + ptr =pack_TPMT_SYM_DEF_OBJECT (ptr, &p->symmetric); + ptr =pack_TPMT_RSA_SCHEME (ptr, &p->scheme); + ptr =pack_TPMI_RSA_KEY_BITS (ptr, &p->keyBits); + ptr =pack_UINT32 (ptr, p->exponent); +return ptr; +} + +inline BYTE *unpack_TPMS_RSA_PARMS (BYTE *ptr,TPMS_RSA_PARMS *p) +{ + ptr =unpack_TPMT_SYM_DEF_OBJECT (ptr, &p->symmetric); + ptr =unpack_TPMT_RSA_SCHEME (ptr, &p->scheme); + ptr =unpack_TPMI_RSA_KEY_BITS (ptr, &p->keyBits); + ptr =unpack_UINT32 (ptr, &p->exponent); +return ptr; +} + +inline BYTE *pack_TPMU_PUBLIC_PARMS (BYTE * ptr,const TPMU_PUBLIC_PARMS *param, +const TPMI_ALG_PUBLIC *selector) +{ +switch (*selector) { +case TPM2_ALG_KEYEDHASH : +assert (false); +case TPM2_ALG_SYMCIPHER : +assert (false); +case TPM2_ALG_RSA : +return pack_TPMS_RSA_PARMS (ptr, ¶m->rsaDetail); +case TPM2_ALG_ECC : +assert (false); + } +assert (false); +return NULL ; +} + +inline BYTE *unpack_TPMU_PUBLIC_PARMS (BYTE * ptr,TPMU_PUBLIC_PARMS *param, +const TPMI_ALG_PUBLIC *selector) +{ +switch (*selector) { +case TPM2_ALG_KEYEDHASH : +assert (false); +case TPM2_ALG_SYMCIPHER : +assert (false); +case TPM2_ALG_RSA : +return unpack_TPMS_RSA_PARMS (ptr, ¶m->rsaDetail); +case TPM2_ALG_ECC : +assert (false); + } +assert (false); +return NULL ; +} + +inline BYTE *pack_TPMS_ECC_POINT (BYTE * ptr,const TPMS_ECC_POINT *point) +{ +assert (false); +return ptr; +} + +inline BYTE *unpack_TPMS_ECC_POINT (BYTE * ptr,TPMS_ECC_POINT *point) +{ +assert (false); +return ptr; +} + +inline BYTE *pack_TPMU_PUBLIC_ID (BYTE * ptr,const TPMU_PUBLIC_ID *id, +const TPMI_ALG_PUBLIC *selector) +{ +switch (*selector) { +case TPM2_ALG_KEYEDHASH : +return pack_TPM2B_DIGEST (ptr, &id->keyedHash); +case TPM2_ALG_SYMCIPHER : +return pack_TPM2B_DIGEST (ptr, &id->sym); +case TPM2_ALG_RSA : +return pack_TPM2B_PUBLIC_KEY_RSA (ptr, &id->rsa); +case TPM2_ALG_ECC : +return pack_TPMS_ECC_POINT (ptr, &id->ecc); + } +assert (false); +return NULL ; +} + +inline BYTE *unpack_TPMU_PUBLIC_ID (BYTE * ptr,TPMU_PUBLIC_ID *id,TPMI_ALG_PUBLIC *selector) +{ +switch (*selector) { +case TPM2_ALG_KEYEDHASH : +return unpack_TPM2B_DIGEST (ptr, &id->keyedHash); +case TPM2_ALG_SYMCIPHER : +return unpack_TPM2B_DIGEST (ptr, &id->sym); +case TPM2_ALG_RSA : +return unpack_TPM2B_PUBLIC_KEY_RSA (ptr, &id->rsa); +case TPM2_ALG_ECC : +return unpack_TPMS_ECC_POINT (ptr, &id->ecc); + } +assert (false); +return NULL ; +} + +inline BYTE *pack_TPMT_PUBLIC (BYTE * ptr,const TPMT_PUBLIC *public) +{ + ptr =pack_TPMI_ALG_PUBLIC (ptr, &public->type); + ptr =pack_TPMI_ALG_HASH (ptr, &public->nameAlg); + ptr =pack_TPMA_OBJECT (ptr, &public->objectAttributes); + ptr =pack_TPM2B_DIGEST (ptr, &public->authPolicy); + ptr =pack_TPMU_PUBLIC_PARMS (ptr, &public->parameters, &public->type); + ptr =pack_TPMU_PUBLIC_ID (ptr, &public->unique, &public->type); +return ptr; +} + +inline BYTE *unpack_TPMT_PUBLIC (BYTE * ptr,TPMT_PUBLIC *public) +{ + ptr =unpack_TPMI_ALG_PUBLIC (ptr, &public->type); + ptr =unpack_TPMI_ALG_HASH (ptr, &public->nameAlg); + ptr =unpack_TPMA_OBJECT (ptr, &public->objectAttributes); + ptr =unpack_TPM2B_DIGEST (ptr, &public->authPolicy); + ptr =unpack_TPMU_PUBLIC_PARMS (ptr, &public->parameters, &public->type); + ptr =unpack_TPMU_PUBLIC_ID (ptr, &public->unique, &public->type); +return ptr; +} + +inline BYTE *pack_TPM2B_PUBLIC (BYTE * ptr,const TPM2B_PUBLIC *public) +{ +BYTE *sizePtr = ptr; + ptr +=2 ; + ptr =pack_TPMT_PUBLIC (ptr, &public->publicArea); +pack_UINT16 (sizePtr, (UINT16 )(ptr - sizePtr -2 )); +return ptr; +} + +inline BYTE *unpack_TPM2B_PUBLIC (BYTE * ptr,TPM2B_PUBLIC *public) +{ + ptr =unpack_UINT16 (ptr, &public->size); + ptr =unpack_TPMT_PUBLIC (ptr, &public->publicArea); +return ptr; +} + +inline BYTE *pack_TPMS_PCR_SELECTION (BYTE * ptr,const TPMS_PCR_SELECTION *selection) +{ + ptr =pack_TPMI_ALG_HASH (ptr, &selection->hash); + ptr =pack_BYTE (ptr, selection->sizeofSelect); + ptr =pack_BYTE_ARRAY (ptr, selection->pcrSelect, selection->sizeofSelect); +return ptr; +} + +inline BYTE *pack_TPMS_PCR_SELECTION_Array (BYTE * ptr,const TPMS_PCR_SELECTION *selections, +const UINT32 cnt) +{ +int i; +for (i =0 ; i < cnt; i++) + ptr =pack_TPMS_PCR_SELECTION (ptr, selections + i); +return ptr; +} + +inline BYTE *pack_TPM_AuthArea (BYTE * ptr,const TPM_AuthArea *auth) +{ +BYTE * sizePtr = ptr; + ptr +=sizeof (UINT32 ); + ptr =pack_TPM_RH (ptr, &auth->sessionHandle); + ptr =pack_TPM2B_NONCE (ptr, &auth->nonce); + ptr =pack_TPMA_SESSION (ptr, &auth->sessionAttributes); + ptr =pack_TPM2B_AUTH (ptr, &auth->auth); +pack_UINT32 (sizePtr, ptr - sizePtr -sizeof (UINT32 )); +return ptr; +} + +inline BYTE *unpack_TPM_AuthArea (BYTE * ptr,TPM_AuthArea *auth) +{ + ptr =unpack_UINT32 (ptr, &auth->size); + ptr =unpack_TPM_RH (ptr, &auth->sessionHandle); + ptr =unpack_TPM2B_NONCE (ptr, &auth->nonce); + ptr =unpack_TPMA_SESSION (ptr, &auth->sessionAttributes); + ptr =unpack_TPM2B_AUTH (ptr, &auth->auth); +return ptr; +} + +inline BYTE *pack_TPM2_RSA_KEY (BYTE * ptr,const TPM2_RSA_KEY *key) +{ + ptr =pack_TPM2B_PRIVATE (ptr, &key->Private); + ptr =pack_TPM2B_PUBLIC (ptr, &key->Public); +return ptr; +} + +inline BYTE *unpack_TPM2_RSA_KEY (BYTE * ptr,TPM2_RSA_KEY *key) +{ + ptr =unpack_TPM2B_PRIVATE (ptr, &key->Private); + ptr =unpack_TPM2B_PUBLIC (ptr, &key->Public); +return ptr; +} +#endif
Signature · 1 line
1.8.3.2
PATCH v4 3/14 vTPM/TPM2: Add global data in vtpm_globals{}
In reply to Quan XuThese data is for the Mini-os to access TPM 2.0 hardware.
--- stubdom/vtpmmgr/vtpmmgr.h | 9 +++++++++ 1 file changed, 9 insertions(+)
stubdom/vtpmmgr/vtpmmgr.h +9 -0
@@ -44,6 +44,7 @@#include "uuid.h" #include "tcg.h" #include "vtpm_manager.h" +#include "tpm2_types.h" #define RSA_KEY_SIZE 0x0800#define RSA_CIPHER_SIZE (RSA_KEY_SIZE / 8)
@@ -59,6 +60,14 @@ struct vtpm_globals {ctr_drbg_context ctr_drbg;int hw_locality; + +/* TPM 2.0 */ +TPM_AuthArea pw_auth; +TPM_AuthArea srk_auth_area; +TPM_HANDLE srk_handle; +TPM_HANDLE sk_handle; +TPM2B_NAME sk_name; +TPM2_RSA_KEY tpm2_storage_key; };struct tpm_opaque {
Signature · 1 line
1.8.3.2
PATCH v4 4/14 vTPM/TPM2: Add TPM 2.0 Exposed APIs
In reply to Quan XuThese TPM 2.0 Exposed APIs for the Mini-os to access TPM 2.0 hardware.
--- stubdom/vtpmmgr/Makefile | 2 +- stubdom/vtpmmgr/tpm2.c | 455 +++++++++++++++++++++++++++++++++++++++++++++++ stubdom/vtpmmgr/tpm2.h | 104 +++++++++++ 3 files changed, 560 insertions(+), 1 deletion(-) create mode 100644 stubdom/vtpmmgr/tpm2.c create mode 100644 stubdom/vtpmmgr/tpm2.h
stubdom/vtpmmgr/Makefile +1 -1
@@ -12,7 +12,7 @@ XEN_ROOT=../.. TARGET=vtpmmgr.a -OBJS=vtpmmgr.o vtpm_cmd_handler.o init.o tpmrsa.o tpm.o log.o +OBJS=vtpmmgr.o vtpm_cmd_handler.o init.o tpmrsa.o tpm.o tpm2.o log.o OBJS += vtpm_disk.o disk_tpm.o disk_io.o disk_crypto.o disk_read.o disk_write.o OBJS += mgmt_authority.o
stubdom/vtpmmgr/tpm2.c new file +455 -0
455 lines not on this page · raw message
stubdom/vtpmmgr/tpm2.h new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH v4 5/14 vTPM/TPM2: TPM 2.0 takes ownership and create SRK
In reply to Quan XuTPM2_CreatePrimary is used to create a Primary Object under one of the Primary Seeds or a Temporary Object under TPM_RH_NULL. The command uses a TPM2B_PUBLIC as a template for the object to be created. The command will create and load a Primary Object. The sensitive area is not returned. Any type of object and attributes combination that is allowed by TPM2_Create() may be created by this command. The constraints on templates and parameters are the same as TPM2_Create() except that a Primary Storage Key and a Temporary Storage Key are not constrained to use the algorithms of their parents.
--- stubdom/vtpmmgr/init.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ stubdom/vtpmmgr/vtpmmgr.h | 3 ++ 2 files changed, 74 insertions(+)
stubdom/vtpmmgr/init.c +71 -0
@@ -51,6 +51,7 @@#include "vtpm_disk.h" #include "tpm.h" #include "marshal.h" +#include "tpm2.h" struct Opts { enum {
@@ -509,3 +510,73 @@ void vtpmmgr_shutdown(void)vtpmloginfo (VTPM_LOG_VTPM ,"VTPM Manager stopped.\n" ); } + +/* TPM 2.0 */ + +static void tpm2_AuthArea_ctor (const char *authValue,UINT32 authLen, +TPM_AuthArea *auth) +{ + auth->sessionHandle =TPM_RS_PW ; + auth->nonce.size =0 ; + auth->sessionAttributes =1 ; + auth->auth.size = authLen; +memcpy (auth->auth.buffer, authValue, authLen); + auth->size =9 + authLen; +} + +TPM_RC tpm2_take_ownership (void ) +{ +TPM_RC status =TPM_SUCCESS ; + +tpm2_AuthArea_ctor (NULL ,0 , &vtpm_globals.pw_auth); + +/* create SRK */ +TPM2_CreatePrimary_Params_in in = { + .inSensitive = { + .size =4 , + .sensitive = { + .userAuth.size =0 , + .userAuth.buffer = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,\ +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }, + .data.size =0 , + }, + }, + .inPublic = { + .size =60 , + .publicArea = { + .type =TPM2_ALG_RSA , + .nameAlg =TPM2_ALG_SHA256 , +#define SRK_OBJ_ATTR (fixedTPM | fixedParent | userWithAuth | \ + sensitiveDataOrigin | restricted | decrypt) + .objectAttributes =SRK_OBJ_ATTR , + .authPolicy.size =0 , + .parameters.rsaDetail = { + .symmetric = { + .algorithm =TPM2_ALG_AES , + .keyBits.aes =AES_KEY_SIZES_BITS , + .mode.aes =TPM2_ALG_CFB , + }, + .scheme = {TPM2_ALG_NULL }, + .keyBits =RSA_KEY_SIZES_BITS , + .exponent =0 , + }, + .unique.rsa.size =0 , + }, + }, + .outsideInfo.size =0 , + .creationPCR.count =0 , + }; + +TPMTRYRETURN (TPM2_CreatePrimary (TPM_RH_OWNER ,&in, + &vtpm_globals.srk_handle,NULL )); +vtpmloginfo (VTPM_LOG_VTPM ,"SRK handle: 0x%X\n" , vtpm_globals.srk_handle); + { +const char data[20 ] = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,\ +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }; +tpm2_AuthArea_ctor (data,20 , &vtpm_globals.srk_auth_area); + } +/*end create SRK*/ + +abort_egress: +return status; +}
stubdom/vtpmmgr/vtpmmgr.h +3 -0
@@ -93,4 +93,7 @@ inline TPM_RESULT vtpmmgr_rand(unsigned char* bytes, size_t num_bytes) { return ctr_drbg_random(&vtpm_globals.ctr_drbg, bytes, num_bytes) == 0 ? 0 : TPM_FAIL; } +/* TPM 2.0 */ +TPM_RC tpm2_take_ownership (void ); +#endif
Signature · 1 line
1.8.3.2
PATCH v4 6/14 vTPM/TPM2: Create and load SK on TPM 2.0
In reply to Quan XuTPM2_Create is used to create an object that can be loaded into a TPM using TPM2_Load(). If the command completes successfully, the TPM will create the new object and return the object’s creation. data (creationData), its public area (outPublic), and its encrypted sensitive area (outPrivate). Preservation of the returned data is the responsibility of the caller. The object will need to be loaded (TPM2_Load()).TPM2_Load is used to load objects into the TPM. This command is used when both a TPM2B_PUBLIC and TPM2B_PRIVATE are to be loaded. If only a TPM2B_PUBLIC is to be loaded, the TPM2_LoadExternal command is used.
--- stubdom/vtpmmgr/init.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ stubdom/vtpmmgr/vtpmmgr.h | 1 + 2 files changed, 66 insertions(+)
stubdom/vtpmmgr/init.c +65 -0
@@ -580,3 +580,68 @@ TPM_RC tpm2_take_ownership(void) abort_egress:return status; } + +TPM_RESULT vtpmmgr2_create (void ) +{ +TPM_RESULT status =TPM_SUCCESS ; + +TPMTRYRETURN (tpm2_take_ownership ()); + +/* create SK */ +TPM2_Create_Params_out out; +TPM2_Create_Params_in in = { + .inSensitive = { + .size =4 +20 , + .sensitive = { + .userAuth.size =20 , + .userAuth.buffer = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,\ +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }, + .data.size =0 , + }, + }, + .inPublic = { + .size = (60 ), + .publicArea = { + .type =TPM2_ALG_RSA , + .nameAlg =TPM2_ALG_SHA256 , +#define SK_OBJ_ATTR (fixedTPM | fixedParent | userWithAuth |\ + sensitiveDataOrigin |decrypt) + .objectAttributes =SK_OBJ_ATTR , + .authPolicy.size =0 , + .parameters.rsaDetail = { + .symmetric = { + .algorithm =TPM2_ALG_NULL , + }, + .scheme = { +TPM2_ALG_OAEP , + .details.oaep.hashAlg =TPM2_ALG_SHA256 , + }, + .keyBits =RSA_KEY_SIZES_BITS , + .exponent =0 , + }, + .unique.rsa.size =0 , + }, + }, + .outsideInfo.size =0 , + .creationPCR.count =0 , + };/*end in */ + +TPMTRYRETURN (TPM2_Create (vtpm_globals.srk_handle, &in, &out)); +TPMTRYRETURN (TPM2_Load (vtpm_globals.srk_handle, + &vtpm_globals.tpm2_storage_key.Private, + &vtpm_globals.tpm2_storage_key.Public, + &vtpm_globals.sk_handle, + &vtpm_globals.sk_name)); + +vtpmloginfo (VTPM_LOG_VTPM ,"SK HANDLE: 0x%X\n" , vtpm_globals.sk_handle); + +/*Create new disk image*/ +TPMTRYRETURN (vtpm_new_disk ()); + + goto egress; + +abort_egress: +egress: +vtpmloginfo (VTPM_LOG_VTPM ,"Finished initialized new VTPM manager\n" ); +return status; +}
stubdom/vtpmmgr/vtpmmgr.h +1 -0
@@ -95,5 +95,6 @@ inline TPM_RESULT vtpmmgr_rand(unsigned char* bytes, size_t num_bytes) {/* TPM 2.0 */ TPM_RC tpm2_take_ownership (void ); +TPM_RESULT vtpmmgr2_create (void );#endif
Signature · 7 lines
1.8.3.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v4 7/14 vTPM/TPM2: TPM2.0 TIS initialization and self test.
In reply to Quan Xucall the TPM 2.0 various registers that allow communication between the TPM 2.0 and platform hardware and software. TPM2_SelfTest causes the TPM 2.0 to perform a test of its capabilities.
--- extras/mini-os/include/tpm_tis.h | 1 + extras/mini-os/tpm_tis.c | 156 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+)
extras/mini-os/include/tpm_tis.h +1 -0
@@ -36,6 +36,7 @@struct tpm_chip ;struct tpm_chip *init_tpm_tis (unsigned long baseaddr,int localities,unsigned int irq); +struct tpm_chip *init_tpm2_tis (unsigned long baseaddr,int localities,unsigned int irq);void shutdown_tpm_tis (struct tpm_chip * tpm);int tpm_tis_request_locality (struct tpm_chip * tpm,int locality);
extras/mini-os/tpm_tis.c +156 -0
161 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH v4 8/14 vTPM/TPM2: Add main entrance vtpmmgr2_init()
In reply to Quan XuAccept commands from the vtpm-stubdom domains via the mini-os TPM backend driver. The vTPM manager communicates directly with hardware TPM 2.0 using the mini-os tpm2_tis driver.
--- stubdom/vtpmmgr/init.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++ stubdom/vtpmmgr/vtpmmgr.h | 1 + 2 files changed, 110 insertions(+)
stubdom/vtpmmgr/init.c +109 -0
@@ -645,3 +645,112 @@ egress:vtpmloginfo (VTPM_LOG_VTPM ,"Finished initialized new VTPM manager\n" );return status; } + +static int tpm2_entropy_source (void * dummy,unsigned char * data, +size_t len,size_t * olen) +{ +UINT32 sz = len; +TPM_RESULT rc =TPM2_GetRandom (&sz, data); + *olen = sz; +return rc ==TPM_SUCCESS ?0 :POLARSSL_ERR_ENTROPY_SOURCE_FAILED ; +} + +/*TPM 2.0 Objects flush */ +static TPM_RC flush_tpm2 (void ) +{ +int i; + +for (i =TRANSIENT_FIRST ; i <TRANSIENT_LAST ; i++) +TPM2_FlushContext (i); + +return TPM_SUCCESS ; +} + +TPM_RESULT vtpmmgr2_init (int argc,char ** argv) +{ +TPM_RESULT status =TPM_SUCCESS ; + +/* Default commandline options */ +struct Opts opts = { + .tpmdriver =TPMDRV_TPM_TIS , + .tpmiomem =TPM_BASEADDR , + .tpmirq =0 , + .tpmlocality =0 , + .gen_owner_auth =0 , + }; + +if (parse_cmdline_opts (argc, argv, &opts) !=0 ) { +vtpmlogerror (VTPM_LOG_VTPM ,"Command line parsing failed! exiting..\n" ); + status =TPM_BAD_PARAMETER ; + goto abort_egress; + } + +/*Setup storage system*/ +if (vtpm_storage_init () !=0 ) { +vtpmlogerror (VTPM_LOG_VTPM ,"Unable to initialize storage subsystem!\n" ); + status =TPM_IOERROR ; + goto abort_egress; + } + +/*Setup tpmback device*/ +init_tpmback (set_opaque, free_opaque); + +/*Setup tpm access*/ +switch (opts.tpmdriver) { +case TPMDRV_TPM_TIS : + { +struct tpm_chip * tpm; +if ((tpm =init_tpm2_tis (opts.tpmiomem,TPM_TIS_LOCL_INT_TO_FLAG (opts.tpmlocality), + opts.tpmirq)) ==NULL ) { +vtpmlogerror (VTPM_LOG_VTPM ,"Unable to initialize tpmfront device\n" ); + status =TPM_IOERROR ; + goto abort_egress; + } +printk ("init_tpm2_tis() ...ok\n" ); + vtpm_globals.tpm_fd =tpm_tis_open (tpm); +tpm_tis_request_locality (tpm, opts.tpmlocality); + } +break ; +case TPMDRV_TPMFRONT : + { +struct tpmfront_dev * tpmfront_dev; +if ((tpmfront_dev =init_tpmfront (NULL )) ==NULL ) { +vtpmlogerror (VTPM_LOG_VTPM ,"Unable to initialize tpmfront device\n" ); + status =TPM_IOERROR ; + goto abort_egress; + } + vtpm_globals.tpm_fd =tpmfront_open (tpmfront_dev); + } +break ; + } +printk ("TPM 2.0 access ...ok\n" ); +/* Blow away all stale handles left in the tpm*/ +if (flush_tpm2 () !=TPM_SUCCESS ) { +vtpmlogerror (VTPM_LOG_VTPM ,"VTPM_FlushResources failed, continuing anyway..\n" ); + } + +/* Initialize the rng */ +entropy_init (&vtpm_globals.entropy); +entropy_add_source (&vtpm_globals.entropy, tpm2_entropy_source,NULL ,0 ); +entropy_gather (&vtpm_globals.entropy); +ctr_drbg_init (&vtpm_globals.ctr_drbg, entropy_func, &vtpm_globals.entropy,NULL ,0 ); +ctr_drbg_set_prediction_resistance ( &vtpm_globals.ctr_drbg,CTR_DRBG_PR_OFF ); + +/* Generate Auth for Owner*/ +if (opts.gen_owner_auth) { +vtpmmgr_rand (vtpm_globals.owner_auth,sizeof (TPM_AUTHDATA )); + } + +/* Load the Manager data, if it fails create a new manager */ +if (vtpm_load_disk ()) { +vtpmloginfo (VTPM_LOG_VTPM ,"Assuming first time initialization.\n" ); +TPMTRYRETURN (vtpmmgr2_create ()); + } + + goto egress; + +abort_egress: +vtpmmgr_shutdown (); +egress: +return status; +}
stubdom/vtpmmgr/vtpmmgr.h +1 -0
@@ -96,5 +96,6 @@ inline TPM_RESULT vtpmmgr_rand(unsigned char* bytes, size_t num_bytes) {/* TPM 2.0 */ TPM_RC tpm2_take_ownership (void );TPM_RESULT vtpmmgr2_create (void ); +TPM_RESULT vtpmmgr2_init (int argc,char ** argv);#endif
Signature · 1 line
1.8.3.2
PATCH v4 9/14 vTPM/TPM2: Support 'tpm2' extra command line.
In reply to Quan XuMake vtpm-stubdom domain compatible to launch on TPM 1.x / TPM 2.0. Add:
..
extra="tpm2=1"
..
to launch vtpm-stubdom domain on TPM 2.0, ignore it on TPM 1.x. for example,
vtpm-stubdom domain configuration on TPM 2.0:
kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz"
memory=16
disk=["file:/var/scale/vdisk/vmgr,hda,w"]
name="vtpmmgr"
iomem=["fed40,5"]
extra="tpm2=1"
vtpm-stubdom domain configuration on TPM 1.x:
kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz"
memory=16
disk=["file:/var/scale/vdisk/vmgr,hda,w"]
name="vtpmmgr"
iomem=["fed40,5"]
--- stubdom/vtpmmgr/vtpmmgr.c | 46 ++++++++++++++++++++++++++++++++++++++++------ stubdom/vtpmmgr/vtpmmgr.h | 14 ++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-)
stubdom/vtpmmgr/vtpmmgr.c +40 -6
@@ -45,6 +45,27 @@#include "vtpmmgr.h" #include "tcg.h" +struct tpm_hardware_version hardware_version = { + .hw_version =TPM1_HARDWARE , +}; + +int parse_cmdline_hw (int argc,char ** argv) +{ +int i; + +for (i =1 ; i < argc; ++i) { +if (!strcmp (argv[i],TPM2_EXTRA_OPT )) { + hardware_version.hw_version =TPM2_HARDWARE ; +break ; + } + } +return 0 ; +} + +int hw_is_tpm2 (void ) +{ +return (hardware_version.hw_version ==TPM2_HARDWARE ) ?1 :0 ; +}void main_loop (void ) {tpmcmd_t * tpmcmd;
@@ -74,12 +95,25 @@ int main(int argc, char** argv)sleep (2 );vtpmloginfo (VTPM_LOG_VTPM ,"Starting vTPM manager domain\n" ); -/* Initialize the vtpm manager */ -if (vtpmmgr_init (argc, argv) !=TPM_SUCCESS ) { -vtpmlogerror (VTPM_LOG_VTPM ,"Unable to initialize vtpmmgr domain!\n" ); - rc =-1 ; - goto exit; - } +/*Parse TPM hardware in extra command line*/ +parse_cmdline_hw (argc, argv); + +/* Initialize the vtpm manager */ +if (hw_is_tpm2 ()) { +vtpmloginfo (VTPM_LOG_VTPM ,"Hardware : --- TPM 2.0 ---\n" ); +if (vtpmmgr2_init (argc, argv) !=TPM_SUCCESS ) { +vtpmlogerror (VTPM_LOG_VTPM ,"Unable to initialize vtpmmgr domain!\n" ); + rc =-1 ; + goto exit; + } + }else { +vtpmloginfo (VTPM_LOG_VTPM ,"Hardware : --- TPM 1.x ---\n" ); +if (vtpmmgr_init (argc, argv) !=TPM_SUCCESS ) { +vtpmlogerror (VTPM_LOG_VTPM ,"Unable to initialize vtpmmgr domain!\n" ); + rc =-1 ; + goto exit; + } + }main_loop ();
stubdom/vtpmmgr/vtpmmgr.h +14 -0
@@ -46,9 +46,21 @@#include "vtpm_manager.h" #include "tpm2_types.h" +#define TPM2_EXTRA_OPT "tpm2=1"#define RSA_KEY_SIZE 0x0800#define RSA_CIPHER_SIZE (RSA_KEY_SIZE / 8) +enum { +TPM1_HARDWARE =1 , +TPM2_HARDWARE , +} tpm_version; + +struct tpm_hardware_version { +int hw_version; +}; + +extern struct tpm_hardware_version hardware_version; +struct vtpm_globals {int tpm_fd;TPM_AUTH_SESSION oiap;// OIAP session for storageKey
@@ -97,5 +109,7 @@ inline TPM_RESULT vtpmmgr_rand(unsigned char* bytes, size_t num_bytes) {TPM_RC tpm2_take_ownership (void );TPM_RESULT vtpmmgr2_create (void );TPM_RESULT vtpmmgr2_init (int argc,char ** argv); +int parse_cmdline_hw (int argc,char ** argv); +int hw_is_tpm2 (void );#endif
Signature · 1 line
1.8.3.2
PATCH v4 10/14 vTPM/TPM2: TPM 2.0 PCRs read
In reply to Quan Xu--- stubdom/vtpmmgr/init.c | 34 ++++++++++++++++++++++++++++++++++ stubdom/vtpmmgr/tpm2_types.h | 2 ++ stubdom/vtpmmgr/vtpmmgr.h | 1 + 3 files changed, 37 insertions(+)
stubdom/vtpmmgr/init.c +34 -0
@@ -51,6 +51,7 @@#include "vtpm_disk.h" #include "tpm.h" #include "marshal.h" +#include "tpm2_marshal.h" #include "tpm2.h" struct Opts {
@@ -754,3 +755,36 @@ abort_egress: egress:return status; } + +TPM_RC tpm2_pcr_read (int index,uint8_t *buf) +{ +TPM_RESULT status =TPM_SUCCESS ; +TPML_PCR_SELECTION pcrSelectionIn = { + .count =1 ,}; + +TPMS_PCR_SELECTION tpms_pcr_selection = { + .hash =TPM2_ALG_SHA1 , + .sizeofSelect =PCR_SELECT_MAX ,}; + +UINT32 pcrUpdateCounter; +TPML_PCR_SELECTION pcrSelectionOut; +TPML_DIGEST pcrValues; +TPM2B_DIGEST tpm2b_digest; + + tpms_pcr_selection.pcrSelect[PCR_SELECT_NUM (index)] =PCR_SELECT_VALUE (index); +memcpy (&pcrSelectionIn.pcrSelections[0 ], &tpms_pcr_selection, +sizeof (TPMS_PCR_SELECTION )); + +TPMTRYRETURN (TPM2_PCR_Read (pcrSelectionIn, &pcrUpdateCounter, + &pcrSelectionOut, &pcrValues)); + +if (pcrValues.count <1 ) + goto egress; + +unpack_TPM2B_DIGEST ((uint8_t *) &pcrValues, &tpm2b_digest); +memcpy (buf, tpm2b_digest.buffer,SHA1_DIGEST_SIZE ); + +abort_egress: +egress: +return status; +}
stubdom/vtpmmgr/tpm2_types.h +2 -0
@@ -432,6 +432,8 @@ typedef struct {#define IMPLEMENTATION_PCR 24#define PLATFORM_PCR 24#define PCR_SELECT_MAX ((IMPLEMENTATION_PCR+7)/8) +#define PCR_SELECT_NUM (x) (uint8_t)(x/8) +#define PCR_SELECT_VALUE (x) (uint8_t)(0x1)<<(x%8)//Table 79 -- TPMS_PCR_SELECT Structure <I/O> typedef struct {
stubdom/vtpmmgr/vtpmmgr.h +1 -0
@@ -107,6 +107,7 @@ inline TPM_RESULT vtpmmgr_rand(unsigned char* bytes, size_t num_bytes) {/* TPM 2.0 */ TPM_RC tpm2_take_ownership (void ); +TPM_RC tpm2_pcr_read (int index,uint8_t *buf);TPM_RESULT vtpmmgr2_create (void );TPM_RESULT vtpmmgr2_init (int argc,char ** argv);int parse_cmdline_hw (int argc,char ** argv);
Signature · 1 line
1.8.3.2
PATCH v4 11/14 vTPM/TPM2: Support TPM 2.0 bind and unbind data
In reply to Quan XuBind data with TPM2_RSA_Encrypt, which performs RSA encryption using the indicated padding scheme according to PKCS#1v2.1(PKCS#1). If the scheme of keyHandle is TPM_ALG_NULL, then the caller may use inScheme to specify the padding scheme.
Unbind data with TPM2_RSA_Decrypt, which performs RSA decryption using the indicated padding scheme according to PKCS#1v2.1(PKCS#1).
--- stubdom/vtpmmgr/disk_tpm.c | 42 ++++++++++++++++++++++++++++++++++++++++-- stubdom/vtpmmgr/disk_tpm.h | 4 ++++ 2 files changed, 44 insertions(+), 2 deletions(-)
stubdom/vtpmmgr/disk_tpm.c +40 -2
@@ -12,17 +12,20 @@#include <polarssl/sha1.h> #include "tpm.h" +#include "tpm2.h" #include "tcg.h" #include "vtpmmgr.h" #include "vtpm_disk.h" #include "disk_tpm.h" +#include "log.h" // Print out input/output of seal/unseal operations (includes keys) #undef DEBUG_SEAL_OPS#ifdef DEBUG_SEAL_OPS #include "marshal.h" +#include "tpm2_marshal.h" #endif struct pcr_list {
@@ -31,11 +34,16 @@ struct pcr_list {static struct pcr_list hwtpm; +/*Ignore PCR on TPM 2.0, read PCR values for TPM 1.x seal | unseal*/ void TPM_read_pcrs (void ) {int i; -for (i=0 ; i <24 ; i++) -TPM_PCR_Read (i, &hwtpm.pcrs[i]); +for (i=0 ; i <24 ; i++) { +if (hw_is_tpm2 ()) +tpm2_pcr_read (i, (uint8_t *)&hwtpm.pcrs[i]); +else +TPM_PCR_Read (i, &hwtpm.pcrs[i]); + } }struct pcr_composite_3 {
@@ -138,6 +146,36 @@ int TPM_disk_seal(struct disk_seal_entry *dst, const void* src, size_t size)return rc; } +TPM_RC TPM2_disk_bind (struct disk_seal_entry *dst,void * src,unsigned int size) +{ +TPM_RESULT status =TPM_SUCCESS ; + +TPMTRYRETURN (TPM2_Bind (vtpm_globals.sk_handle, + src, + size, + dst->sealed_data)); + +abort_egress: +egress: +return status; +} + +TPM_RC TPM2_disk_unbind (void *dst,unsigned int *size,const struct disk_seal_entry *src) +{ +TPM_RESULT status =TPM_SUCCESS ; +unsigned char buf[RSA_CIPHER_SIZE ]; + +memcpy (buf, src->sealed_data,RSA_CIPHER_SIZE ); +TPMTRYRETURN (TPM2_UnBind (vtpm_globals.sk_handle, +RSA_CIPHER_SIZE , + buf, + size, + dst)); +abort_egress: +egress: +return status; +} +int TPM_disk_unseal (void *dst,size_t size,const struct disk_seal_entry *src) {uint32_t rc;
stubdom/vtpmmgr/disk_tpm.h +4 -0
@@ -10,6 +10,10 @@ void TPM_pcr_digest(struct hash160 *buf, le32_t selection);int TPM_disk_seal (struct disk_seal_entry *dst,const void * src,size_t size);int TPM_disk_unseal (void *dst,size_t size,const struct disk_seal_entry *src); +/*TPM 2.0 Bind and Unbind */ +TPM_RC TPM2_disk_bind (struct disk_seal_entry *dst,void * src,unsigned int size); +TPM_RC TPM2_disk_unbind (void *dst,unsigned int *size,const struct disk_seal_entry *src); +/* NVRAM to allow revocation of TM-KEY */ int TPM_disk_nvalloc (be32_t *nvram_slot,struct tpm_authdata auth);int TPM_disk_nvread (void *buf,size_t bufsiz,be32_t nvram_slot,struct tpm_authdata auth);
Signature · 1 line
1.8.3.2
PATCH v4 12/14 vTPM/TPM2: Bind group keys and sectors data on disk
In reply to Quan Xu--- stubdom/vtpmmgr/disk_write.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
stubdom/vtpmmgr/disk_write.c +11 -2
@@ -88,7 +88,12 @@ static void generate_group_seals(struct mem_group *src, const struct mem_tpm_mgr dst->pcr_selection = src->seals[i].pcr_selection;memcpy (&dst->digest_release, &src->seals[i].digest_release,20 );TPM_pcr_digest (&dst->digest_at_seal, dst->pcr_selection); -TPM_disk_seal (dst, &sblob,sizeof (sblob)); + +/*TPM 2.0 bind | TPM 1.x seal*/ +if (hw_is_tpm2 ()) +TPM2_disk_bind (dst, &sblob,sizeof (sblob)); +else +TPM_disk_seal (dst, &sblob,sizeof (sblob)); } src->seal_bits.nr_cfgs =native_be32 (src->nr_seals);
@@ -250,7 +255,11 @@ static void disk_write_seal_list(struct mem_tpm_mgr *mgr, struct mem_group *groumemcpy (&dst->digest_release, &src->digest_release,20 );TPM_pcr_digest (&dst->digest_at_seal, dst->pcr_selection); -TPM_disk_seal (dst, &sblob,sizeof (sblob)); +/*TPM 2.0 bind / TPM 1.x seal*/ +if (hw_is_tpm2 ()) +TPM2_disk_bind (dst, &sblob,sizeof (sblob)); +else +TPM_disk_seal (dst, &sblob,sizeof (sblob)); }memcpy (seal->hdr.magic,TPM_MGR_MAGIC ,12 );
Signature · 1 line
1.8.3.2
PATCH v4 13/14 vTPM/TPM2: Unind group keys and sectors data on disk
In reply to Quan Xu--- stubdom/vtpmmgr/disk_read.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
stubdom/vtpmmgr/disk_read.c +15 -2
@@ -67,6 +67,7 @@ static int find_group_key(struct mem_group *dst, const struct mem_tpm_mgr *parent) {int i, rc, rv =1 ; +unsigned int olen;struct hash160 buf;struct disk_group_sealed_data sealed;
@@ -88,7 +89,13 @@ static int find_group_key(struct mem_group *dst,TPM_pcr_digest (&buf, cfg->pcr_selection);if (memcmp (&buf, &cfg->digest_release,20 ))continue ; - rc =TPM_disk_unseal (&sealed,sizeof (sealed), cfg); + +/*TPM 2.0 unbind | TPM 1.x unseal*/ +if (hw_is_tpm2 ()) + rc =TPM2_disk_unbind (&sealed, &olen, cfg); +else + rc =TPM_disk_unseal (&sealed,sizeof (sealed), cfg); +if (rc)continue ;if (memcmp (&sealed.magic,DISK_GROUP_BOUND_MAGIC ,4 ))
@@ -112,9 +119,15 @@ static int find_group_key(struct mem_group *dst,static int parse_root_key (struct mem_tpm_mgr *dst,struct disk_seal_entry *src) {int rc; +unsigned int olen;struct disk_root_sealed_data sealed; - rc =TPM_disk_unseal (&sealed,sizeof (sealed), src); +/*TPM 2.0 unbind | TPM 1.x unseal*/ +if (hw_is_tpm2 ()) + rc =TPM2_disk_unbind (&sealed, &olen, src); +else + rc =TPM_disk_unseal (&sealed,sizeof (sealed), src); +if (rc)return rc;
Signature · 1 line
1.8.3.2
PATCH v4 14/14 vTPM/TPM2: Record some infomation in docs/misc/vtpmmgr.txt about
In reply to Quan Xu'vtpmmgr on TPM 2.0'
--- docs/misc/vtpmmgr.txt | 155 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 1 deletion(-)
docs/misc/vtpmmgr.txt +154 -1
@@ -1,4 +1,8 @@ -Author: Daniel De Graaf <[email protected]> +================================================================================ +Authors: + Daniel De Graaf <[email protected]> + Quan Xu <[email protected]> +================================================================================ This document describes the operation and command line interface of vtpmmgr-stubdom. See docs/misc/vtpm.txt for details on the vTPM subsystem as a
@@ -163,3 +167,152 @@ would look like the following: This requires the migration domain to be added to the list of valid vTPM kernel hashes. In the current version of the vtpmmgr domain, this is the hash of the XSM label, not the kernel. + +================================================================================ +Appendix B: vtpmmgr on TPM 2.0 +================================================================================ + +Manager disk image setup: +------------------------- + +The vTPM Manager requires a disk image to store its encrypted data. The image +does not require a filesystem and can live anywhere on the host disk. The image +is not large; the Xen 4.5 vtpmmgr is limited to using the first 2MB of the image +but can support more than 20,000 vTPMs. + + dd if=/dev/zero of=/home/vtpm2/vmgr bs=16M count=1 + +Manager config file: +-------------------- + +The vTPM Manager domain (vtpmmgr-stubdom) must be started like any other Xen +virtual machine and requires a config file. The manager requires a disk image +for storage and permission to access the hardware memory pages for the TPM. The +disk must be presented as "hda", and the TPM memory pages are passed using the +iomem configuration parameter. The TPM TIS uses 5 pages of IO memory (one per +locality) that start at physical address 0xfed40000. By default, the TPM manager +uses locality 0 (so only the page at 0xfed40 is needed). + +Add: +.. + extra="tpm2=1" +.. +extra option to launch vtpmmgr-stubdom domain on TPM 2.0, and ignore it on TPM +1.x. for example: + + kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz" + memory=128 + disk=["file:/home/vtpm2/vmgr,hda,w"] + name="vtpmmgr" + iomem=["fed40,5"] + extra="tpm2=1" + + +Key Hierarchy +------------------------------ + + +------------------+ + | vTPM's secrets | ... + +------------------+ + | ^ + | |(Bind / Unbind) +- - - - - -v |- - - - - - - - TPM 2.0 + +------------------+ + | SK + + +------------------+ + | ^ + v | + +------------------+ + | SRK | + +------------------+ + | ^ + v | + +------------------+ + | TPM 2.0 Storage | + | Primary Seed | + +------------------+ + +Now the secrets for the vTPMs are only being bound to the presence of thephysical +TPM 2.0. Since using PCRs to seal the data can be an important security feature +that users of the vtpmmgr rely on. I will replace TPM2_Bind/TPM2_Unbind with +TPM2_Seal/TPM2_Unseal to provide as much security as it did for TPM 1.2 in later +series of patch. + +DESIGN OVERVIEW +------------------------------ + +The architecture of vTPM subsystem on TPM 2.0 is described below: + ++------------------+ +| Linux DomU | ... +| | ^ | +| v | | +| xen-tpmfront | ++------------------+ + | ^ + v | ++------------------+ +| mini-os/tpmback | +| | ^ | +| v | | +| vtpm-stubdom | ... +| | ^ | +| v | | +| mini-os/tpmfront | ++------------------+ + | ^ + v | ++------------------+ +| mini-os/tpmback | +| | ^ | +| v | | +| vtpmmgr-stubdom | +| | ^ | +| v | | +| mini-os/tpm2_tis | ++------------------+ + | ^ + v | ++------------------+ +| Hardware TPM 2.0 | ++------------------+ + + * Linux DomU: The Linux based guest that wants to use a vTPM. There many be + more than one of these. + + * xen-tpmfront.ko: Linux kernel virtual TPM frontend driver. This driver + provides vTPM access to a para-virtualized Linux based DomU. + + * mini-os/tpmback: Mini-os TPM backend driver. The Linux frontend driver + connects to this backend driver to facilitate + communications between the Linux DomU and its vTPM. This + driver is also used by vtpmmgr-stubdom to communicate with + vtpm-stubdom. + + * vtpm-stubdom: A mini-os stub domain that implements a vTPM. There is a + one to one mapping between running vtpm-stubdom instances and + logical vtpms on the system. The vTPM Platform Configuration + Registers (PCRs) are all initialized to zero. + + * mini-os/tpmfront: Mini-os TPM frontend driver. The vTPM mini-os domain + vtpm-stubdom uses this driver to communicate with + vtpmmgr-stubdom. This driver could also be used separately to + implement a mini-os domain that wishes to use a vTPM of + its own. + + * vtpmmgr-stubdom: A mini-os domain that implements the vTPM manager. + There is only one vTPM manager and it should be running during + the entire lifetime of the machine. This domain regulates + access to the physical TPM on the system and secures the + persistent state of each vTPM. + + * mini-os/tpm2_tis: Mini-os TPM version 2.0 TPM Interface Specification (TIS) + driver. This driver used by vtpmmgr-stubdom to talk directly + to the hardware TPM 2.0. Communication is facilitated by mapping + hardware memory pages into vtpmmgr-stubdom. + + * Hardware TPM 2.0: The physical TPM 2.0 that is soldered onto the motherboard. + +--------------------- +Noted: + functionality for a virtual guest operating system (a DomU) is still TPM 1.2.
Signature · 1 line
1.8.3.2
v4 cover Enable vTPM subsystem on TPM 2.0
In reply to Quan XuWei
Are this series of patch in one thread? Thanks.
-Quan
Quoted 9 lines
-----Original Message-----
From: Xu, Quan
Sent: Thursday, January 15, 2015 5:22 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Xu, Quan
Subject: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0
Quoted 4 lines · Quan
Wei
Are this series of patch in one thread? Thanks.
Yes.
Quoted 12 lines
-Quan
Quoted 9 lines
-----Original Message-----
From: Xu, Quan
Sent: Thursday, January 15, 2015 5:22 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Xu, Quan
Subject: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0
Quoted 9 lines
-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: Thursday, January 15, 2015 10:54 PM
To: Xu, Quan
Cc: [email protected]; [email protected]
Subject: Re: FW: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0
Quoted 8 lines
Quoted 4 lines · Quan
Wei
Are this series of patch in one thread? Thanks.
Yes.
Thanks for your help.:)
-Quan
Quoted 13 lines
Quoted 13 lines
-Quan
Quoted 10 lines
-----Original Message-----
From: Xu, Quan
Sent: Thursday, January 15, 2015 5:22 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Xu, Quan
Subject: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0
Quoted 7 lines · Quan Xu
This series of patch enable the virtual Trusted Platform Module (vTPM) subsystem for Xen on TPM 2.0.
Noted, functionality for a virtual guest operating system (a DomU) is still TPM 1.2. The main modifcation is on vtpmmgr-stubdom. The challenge is that TPM 2.0 is not backward compatible with TPM 1.2.
Updates from v3 all look good, all patches in this series:
PS: If you need to re-post this in the future, you should add that line below the signed-off-by on the unchanged patches, so that it is clear to the other Xen maintainers that only the changed/new patches need my review.
Signature · 2 lines
Daniel De Graaf National Security Agency
Xu, Quan
Acked-by Daniel De GraafQuoted 22 lines
-----Original Message-----
From: Daniel De Graaf [mailto:[email protected]]
Sent: Wednesday, January 21, 2015 6:28 AM
To: Xu, Quan; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 7 lines · Quan Xu
This series of patch enable the virtual Trusted Platform Module (vTPM) subsystem for Xen on TPM 2.0.
Noted, functionality for a virtual guest operating system (a DomU) is still TPM 1.2. The main modifcation is on vtpmmgr-stubdom. The challenge is that TPM 2.0 is not backward compatible with TPM 1.2.
Updates from v3 all look good, all patches in this series:
Quoted 7 lines
Acked-by Daniel De Graaf <[email protected]>PS: If you need to re-post this in the future, you should add that line below the signed-off-by on the unchanged patches, so that it is clear to the other Xen maintainers that only the changed/new patches need my review.
--
Many thanks.
For example:
Right?
Intel
Quan Xu
Quoted 2 lines
Daniel De Graaf
National Security Agency
Quoted 26 lines · Quan
Quoted 26 lines
-----Original Message-----
From: Daniel De Graaf [mailto:[email protected]]
Sent: Wednesday, January 21, 2015 6:28 AM
To: Xu, Quan; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 7 lines · Quan Xu
This series of patch enable the virtual Trusted Platform Module (vTPM) subsystem for Xen on TPM 2.0.
Noted, functionality for a virtual guest operating system (a DomU) is still TPM 1.2. The main modifcation is on vtpmmgr-stubdom. The challenge is that TPM 2.0 is not backward compatible with TPM 1.2.
Updates from v3 all look good, all patches in this series:
Acked-by Daniel De Graaf <[email protected]>PS: If you need to re-post this in the future, you should add that line below the signed-off-by on the unchanged patches, so that it is clear to the other Xen maintainers that only the changed/new patches need my review.
Quoted 7 lines
Quoted 1 line
--
Many thanks.
For example:Signed-off-by Quan Xu <[email protected]>Acked-by Daniel De Graaf <[email protected]>Right?
That is correct.
Quoted 40 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Stefano Stabellini
Sent: Wednesday, January 21, 2015 6:37 PM
To: Xu, Quan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Daniel De Graaf
Subject: Re: [Xen-devel] [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 18 lines · Quan
Quoted 18 lines
-----Original Message-----
From: Daniel De Graaf [mailto:[email protected]]
Sent: Wednesday, January 21, 2015 6:28 AM
To: Xu, Quan; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 7 lines · Quan Xu
This series of patch enable the virtual Trusted Platform Module (vTPM) subsystem for Xen on TPM 2.0.
Noted, functionality for a virtual guest operating system (a DomU) is still TPM 1.2. The main modifcation is on vtpmmgr-stubdom. The challenge is that TPM 2.0 is not backward compatible with TPM 1.2.
Quoted 7 lines
Quoted 7 lines
Updates from v3 all look good, all patches in this series:
Acked-by Daniel De Graaf <[email protected]>PS: If you need to re-post this in the future, you should add that line below the signed-off-by on the unchanged patches, so that it is clear to the other Xen maintainers that only the changed/new patches need
my review.
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
--
Many thanks.
For example:Signed-off-by Quan Xu <[email protected]>That is correct.
Stefano, Thanks.
Now this series of patch were Acked-by Daniel De Graaf <[email protected]>. could you also Review them and give me some comments or feedback? Thanks.
-Quan
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 45 lines · Quan
Quoted 45 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Stefano Stabellini
Sent: Wednesday, January 21, 2015 6:37 PM
To: Xu, Quan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Daniel De Graaf
Subject: Re: [Xen-devel] [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 18 lines · Quan
Quoted 18 lines
-----Original Message-----
From: Daniel De Graaf [mailto:[email protected]]
Sent: Wednesday, January 21, 2015 6:28 AM
To: Xu, Quan; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 7 lines · Quan Xu
This series of patch enable the virtual Trusted Platform Module (vTPM) subsystem for Xen on TPM 2.0.
Noted, functionality for a virtual guest operating system (a DomU) is still TPM 1.2. The main modifcation is on vtpmmgr-stubdom. The challenge is that TPM 2.0 is not backward compatible with TPM 1.2.
Quoted 7 lines
Quoted 7 lines
Updates from v3 all look good, all patches in this series:
Acked-by Daniel De Graaf <[email protected]>PS: If you need to re-post this in the future, you should add that line below the signed-off-by on the unchanged patches, so that it is clear to the other Xen maintainers that only the changed/new patches need
my review.
Quoted 7 lines
Quoted 2 lines
--
Many thanks.
For example:Signed-off-by Quan Xu <[email protected]>
Quoted 5 lines
Quoted 1 line
That is correct.
Stefano, Thanks.
Now this series of patch were Acked-by Daniel De Graaf <[email protected]>. could you also Review them and give me some comments or feedback? Thanks.
I am not sure if I am really the right person to give you feedback on it. But I do trust Daniel's opinion on it.
Xu, Quan
Acked-by Daniel De GraafQuoted 65 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: Tuesday, January 27, 2015 11:48 PM
To: Xu, Quan
Cc: Stefano Stabellini; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Daniel De Graaf
Subject: RE: [Xen-devel] [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 23 lines · Quan
Quoted 23 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Stefano Stabellini
Sent: Wednesday, January 21, 2015 6:37 PM
To: Xu, Quan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Daniel De Graaf
Subject: Re: [Xen-devel] [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 9 lines · Quan
Quoted 9 lines
-----Original Message-----
From: Daniel De Graaf [mailto:[email protected]]
Sent: Wednesday, January 21, 2015 6:28 AM
To: Xu, Quan; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Quan Xu
Quoted 7 lines
This series of patch enable the virtual Trusted Platform Module
(vTPM) subsystem for Xen on TPM 2.0.Noted, functionality for a virtual guest operating system (a DomU) is still TPM 1.2. The main modifcation is on vtpmmgr-stubdom. The challenge is that TPM 2.0 is not backward
compatible with TPM 1.2.
Quoted 21 lines
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Updates from v3 all look good, all patches in this series:
Acked-by Daniel De Graaf <[email protected]>PS: If you need to re-post this in the future, you should add that line below the signed-off-by on the unchanged patches, so that it is clear to the other Xen maintainers that only the changed/new patches need
my review.
Quoted 7 lines
Quoted 2 lines
--
Many thanks.
For example:Signed-off-by Quan Xu <[email protected]>That is correct.
Quoted 7 lines
Quoted 3 lines
Stefano, Thanks.
Now this series of patch were Acked-by Daniel De Graaf <[email protected]>. could you also Review them and give me somecomments or feedback? Thanks.
I am not sure if I am really the right person to give you feedback on it. But I do trust Daniel's opinion on it.
Thanks Stefano.
Now Wei Liu is splitting off mini-os to a separate tree, could I send out v5 with
..
..
Then, Daniel can merge these serious of patch to * staging branch. Or try to send out the patches against the new mini-os tree.
Correct me, If the process is wrong.
Thanks
Quan
On Wed, Jan 28, 2015 at 01:44:03AM +0000, Xu, Quan wrote:
[...]
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
That is correct.
Stefano, Thanks.
Now this series of patch were Acked-by Daniel De Graaf <[email protected]>. could you also Review them and give me somecomments or feedback? Thanks.
I am not sure if I am really the right person to give you feedback on it. But I do trust Daniel's opinion on it.
Quoted 9 lines
Thanks Stefano.
Now Wei Liu is splitting off mini-os to a separate tree, could I send out v5 with
..Signed-off-by Quan Xu <[email protected]>Acked-by Daniel De Graaf <[email protected]>..
Then, Daniel can merge these serious of patch to * staging branch. Or try to send out the patches against the new mini-os tree.
Are you patches all acked? I vaguely remember seeing so but I would like to confirm.
Though I would like splitting off to happen as soon as possible but I can say for sure when it's going to happen.
I think maintainers / committers will tell to rebase / resubmit if necessary.
Wei.
Quoted 7 lines
Correct me, If the process is wrong.
Thanks
Quan
Quoted 74 lines · Quan
Quoted 63 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: Tuesday, January 27, 2015 11:48 PM
To: Xu, Quan
Cc: Stefano Stabellini; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Daniel De Graaf
Subject: RE: [Xen-devel] [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 23 lines · Quan
Quoted 23 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Stefano Stabellini
Sent: Wednesday, January 21, 2015 6:37 PM
To: Xu, Quan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Daniel De Graaf
Subject: Re: [Xen-devel] [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 9 lines · Quan
Quoted 9 lines
-----Original Message-----
From: Daniel De Graaf [mailto:[email protected]]
Sent: Wednesday, January 21, 2015 6:28 AM
To: Xu, Quan; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Quan Xu
Quoted 7 lines
This series of patch enable the virtual Trusted Platform Module
(vTPM) subsystem for Xen on TPM 2.0.Noted, functionality for a virtual guest operating system (a DomU) is still TPM 1.2. The main modifcation is on vtpmmgr-stubdom. The challenge is that TPM 2.0 is not backward
compatible with TPM 1.2.
Quoted 21 lines
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Updates from v3 all look good, all patches in this series:
Acked-by Daniel De Graaf <[email protected]>PS: If you need to re-post this in the future, you should add that line below the signed-off-by on the unchanged patches, so that it is clear to the other Xen maintainers that only the changed/new patches need
my review.
Quoted 7 lines
Quoted 2 lines
--
Many thanks.
For example:Signed-off-by Quan Xu <[email protected]>That is correct.
Quoted 7 lines
Quoted 3 lines
Stefano, Thanks.
Now this series of patch were Acked-by Daniel De Graaf <[email protected]>. could you also Review them and give me somecomments or feedback? Thanks.
I am not sure if I am really the right person to give you feedback on it. But I do trust Daniel's opinion on it.
Thanks Stefano.
Now Wei Liu is splitting off mini-os to a separate tree, could I send out v5 with
..
Quoted 7 lines
Signed-off-by Quan Xu <[email protected]>Acked-by Daniel De Graaf <[email protected]>..
Then, Daniel can merge these serious of patch to * staging branch. Or try to send out the patches against the new mini-os tree.Correct me, If the process is wrong.
I don't think that Daniel has commit access to the tree. Also given that all your patches have been acked, you might not have to wait for Wei to finish off splitting mini-os.
Ian? Wei? How do you want to go about this?
Quoted 5 lines · Stefano Stabellini
I don't think that Daniel has commit access to the tree. Also given that all your patches have been acked, you might not have to wait for Wei to finish off splitting mini-os.
Ian? Wei? How do you want to go about this?
I think at some point we should declare the mini-os split "happening now", at which point no more commits to mini-os in the tree while Wei reruns the conversion/extraction process and we commit the associated patches to xen.git.
But, I think right now we are still sorting out the details of the split so we haven't reached that point yet and should continue to commit to extras/mini-os as usual for the time being (while being mindful of not making Wei's life harder at reconversion time).
Ian.
Quoted 12 lines · Ian Campbell
Quoted 5 lines · Stefano Stabellini
I don't think that Daniel has commit access to the tree. Also given that all your patches have been acked, you might not have to wait for Wei to finish off splitting mini-os.
Ian? Wei? How do you want to go about this?
I think at some point we should declare the mini-os split "happening now", at which point no more commits to mini-os in the tree while Wei reruns the conversion/extraction process and we commit the associated patches to xen.git.
Quoted 5 lines
But, I think right now we are still sorting out the details of the split so we haven't reached that point yet and should continue to commit to extras/mini-os as usual for the time being (while being mindful of not making Wei's life harder at reconversion time).
I agree.
Wei.
Quoted 1 line
Ian.
Quoted 4 lines · Daniel De Graaf
Quoted 3 lines · Quan Xu
This series of patch enable the virtual Trusted Platform Module (vTPM) subsystem for Xen on TPM 2.0.
Quoted 8 lines
Quoted 4 lines
Noted, functionality for a virtual guest operating system (a DomU) is still TPM 1.2. The main modifcation is on vtpmmgr-stubdom. The challenge is that TPM 2.0 is not backward compatible with TPM 1.2.
Updates from v3 all look good, all patches in this series:
Acked-by Daniel De Graaf <[email protected]>
I've now applied the series with your ack.
Quoted 21 lines
-----Original Message-----
From: Ian Campbell [mailto:[email protected]]
Sent: Wednesday, January 28, 2015 9:07 PM
To: Daniel De Graaf
Cc: Xu, Quan; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 00/14] Enable vTPM subsystem on TPM 2.0Quoted 9 lines · Daniel De Graaf
Quoted 7 lines · Quan Xu
This series of patch enable the virtual Trusted Platform Module (vTPM) subsystem for Xen on TPM 2.0.
Noted, functionality for a virtual guest operating system (a DomU) is still TPM 1.2. The main modifcation is on vtpmmgr-stubdom. The challenge is that TPM 2.0 is not backward compatible with TPM 1.2.
Quoted 6 lines
Quoted 3 lines
Updates from v3 all look good, all patches in this series:
Acked-by Daniel De Graaf <[email protected]>I've now applied the series with your ack.
Thank you very much..
Intel
Quan Xu