direct-io.hg

changeset 10492:18587d3e94c8

[VTPM_TOOLS] Updated vtpmd to save complete state in preperateion to
support suspend/resume and migration. Fixed startup bug.

Signed-off-by: Vincent Scarlata <vincent.r.scarlata@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Jun 27 11:14:19 2006 +0100 (2006-06-27)
parents 533b0709a68f
children 8589cdd09636
files tools/vtpm/Rules.mk tools/vtpm/tpm_emulator-0.3-x86_64.patch tools/vtpm/tpm_emulator.patch tools/vtpm/vtpm.patch
line diff
     1.1 --- a/tools/vtpm/Rules.mk	Tue Jun 27 11:13:24 2006 +0100
     1.2 +++ b/tools/vtpm/Rules.mk	Tue Jun 27 11:14:19 2006 +0100
     1.3 @@ -33,7 +33,7 @@ OBJS	= $(patsubst %.c,%.o,$(SRCS))
     1.4  
     1.5  -include $(DEP_FILES)
     1.6  
     1.7 -BUILD_EMULATOR = n
     1.8 +BUILD_EMULATOR = y
     1.9  
    1.10  # Make sure these are just rules
    1.11  .PHONY : all build install clean
     2.1 --- a/tools/vtpm/tpm_emulator-0.3-x86_64.patch	Tue Jun 27 11:13:24 2006 +0100
     2.2 +++ b/tools/vtpm/tpm_emulator-0.3-x86_64.patch	Tue Jun 27 11:14:19 2006 +0100
     2.3 @@ -1,62 +1,6 @@
     2.4 -diff -uprN tpm_emulator-0.3/crypto/gmp_kernel_wrapper.c tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c
     2.5 ---- tpm_emulator-0.3/crypto/gmp_kernel_wrapper.c	2006-01-10 04:21:45.000000000 -0800
     2.6 -+++ tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c	2006-05-26 11:26:02.000000000 -0700
     2.7 -@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne
     2.8 - {
     2.9 -   void *ret  = (void*)kmalloc(size, GFP_KERNEL);
    2.10 -   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 
    2.11 --    "GMP: cannot allocate memory (size=%u)\n", size);
    2.12 -+    "GMP: cannot allocate memory (size=%Zu)\n", size);
    2.13 -   return ret;
    2.14 - }
    2.15 - 
    2.16 -@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne
    2.17 - {
    2.18 -   void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
    2.19 -   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
    2.20 --    "(old_size=%u new_size=%u)\n", old_size, new_size);
    2.21 -+    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
    2.22 -   memcpy(ret, oldptr, old_size);
    2.23 -   kfree(oldptr);
    2.24 -   return ret;
    2.25 -diff -uprN tpm_emulator-0.3/linux_module.c tpm_emulator-0.3-x86_64/linux_module.c
    2.26 ---- tpm_emulator-0.3/linux_module.c	2006-01-10 04:21:45.000000000 -0800
    2.27 -+++ tpm_emulator-0.3-x86_64/linux_module.c	2006-05-26 11:26:02.000000000 -0700
    2.28 -@@ -72,7 +72,7 @@ static int tpm_release(struct inode *ino
    2.29 - 
    2.30 - static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)
    2.31 - {
    2.32 --  debug("%s(%d)", __FUNCTION__, count);
    2.33 -+  debug("%s(%Zu)", __FUNCTION__, count);
    2.34 -   down(&tpm_mutex);
    2.35 -   if (tpm_response.data != NULL) {
    2.36 -     count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
    2.37 -@@ -91,7 +91,7 @@ static ssize_t tpm_read(struct file *fil
    2.38 - 
    2.39 - static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
    2.40 - {
    2.41 --  debug("%s(%d)", __FUNCTION__, count);
    2.42 -+  debug("%s(%Zu)", __FUNCTION__, count);
    2.43 -   down(&tpm_mutex);
    2.44 -   *ppos = 0;
    2.45 -   if (tpm_response.data != NULL) kfree(tpm_response.data);
    2.46 -diff -uprN tpm_emulator-0.3/linux_module.h tpm_emulator-0.3-x86_64/linux_module.h
    2.47 ---- tpm_emulator-0.3/linux_module.h	2006-01-10 04:21:45.000000000 -0800
    2.48 -+++ tpm_emulator-0.3-x86_64/linux_module.h	2006-05-26 11:26:02.000000000 -0700
    2.49 -@@ -28,8 +28,10 @@
    2.50 - 
    2.51 - /* module settings */
    2.52 - 
    2.53 -+#ifndef STR
    2.54 - #define STR(s) __STR__(s)
    2.55 - #define __STR__(s) #s
    2.56 -+#endif
    2.57 - #include "tpm_version.h"
    2.58 - 
    2.59 - #define TPM_DEVICE_MINOR	224
    2.60 -diff -uprN tpm_emulator-0.3/Makefile tpm_emulator-0.3-x86_64/Makefile
    2.61 ---- tpm_emulator-0.3/Makefile	2006-01-10 04:21:45.000000000 -0800
    2.62 -+++ tpm_emulator-0.3-x86_64/Makefile	2006-05-26 11:26:02.000000000 -0700
    2.63 +diff -uprN orig/tpm_emulator-0.3/Makefile tpm_emulator-0.3-x86_64/Makefile
    2.64 +--- orig/tpm_emulator-0.3/Makefile	2006-01-10 04:21:45.000000000 -0800
    2.65 ++++ tpm_emulator-0.3-x86_64/Makefile	2006-08-29 15:08:20.532342768 -0700
    2.66  @@ -7,6 +7,7 @@
    2.67   KERNEL_RELEASE := $(shell uname -r)
    2.68   KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
    2.69 @@ -81,9 +25,9 @@ diff -uprN tpm_emulator-0.3/Makefile tpm
    2.70   GMP_HEADER     := /usr/include/gmp.h
    2.71   
    2.72   # sources and objects
    2.73 -diff -uprN tpm_emulator-0.3/README tpm_emulator-0.3-x86_64/README
    2.74 ---- tpm_emulator-0.3/README	2006-01-10 04:21:45.000000000 -0800
    2.75 -+++ tpm_emulator-0.3-x86_64/README	2006-05-26 11:26:02.000000000 -0700
    2.76 +diff -uprN orig/tpm_emulator-0.3/README tpm_emulator-0.3-x86_64/README
    2.77 +--- orig/tpm_emulator-0.3/README	2006-01-10 04:21:45.000000000 -0800
    2.78 ++++ tpm_emulator-0.3-x86_64/README	2006-08-29 15:07:43.530967832 -0700
    2.79  @@ -43,6 +43,12 @@ Example:
    2.80   GMP_LIB        := /usr/lib/libgmp.a
    2.81   GMP_HEADER     := /usr/include/gmp.h
    2.82 @@ -97,9 +41,65 @@ diff -uprN tpm_emulator-0.3/README tpm_e
    2.83   Installation
    2.84   --------------------------------------------------------------------------
    2.85   The compilation and installation process uses the build environment for 
    2.86 -diff -uprN tpm_emulator-0.3/tpm/tpm_credentials.c tpm_emulator-0.3-x86_64/tpm/tpm_credentials.c
    2.87 ---- tpm_emulator-0.3/tpm/tpm_credentials.c	2006-01-10 04:21:45.000000000 -0800
    2.88 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_credentials.c	2006-05-26 11:26:02.000000000 -0700
    2.89 +diff -uprN orig/tpm_emulator-0.3/crypto/gmp_kernel_wrapper.c tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c
    2.90 +--- orig/tpm_emulator-0.3/crypto/gmp_kernel_wrapper.c	2006-01-10 04:21:45.000000000 -0800
    2.91 ++++ tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c	2006-08-29 15:07:43.525968592 -0700
    2.92 +@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne
    2.93 + {
    2.94 +   void *ret  = (void*)kmalloc(size, GFP_KERNEL);
    2.95 +   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 
    2.96 +-    "GMP: cannot allocate memory (size=%u)\n", size);
    2.97 ++    "GMP: cannot allocate memory (size=%Zu)\n", size);
    2.98 +   return ret;
    2.99 + }
   2.100 + 
   2.101 +@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne
   2.102 + {
   2.103 +   void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
   2.104 +   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
   2.105 +-    "(old_size=%u new_size=%u)\n", old_size, new_size);
   2.106 ++    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
   2.107 +   memcpy(ret, oldptr, old_size);
   2.108 +   kfree(oldptr);
   2.109 +   return ret;
   2.110 +diff -uprN orig/tpm_emulator-0.3/linux_module.c tpm_emulator-0.3-x86_64/linux_module.c
   2.111 +--- orig/tpm_emulator-0.3/linux_module.c	2006-01-10 04:21:45.000000000 -0800
   2.112 ++++ tpm_emulator-0.3-x86_64/linux_module.c	2006-08-29 15:07:43.526968440 -0700
   2.113 +@@ -72,7 +72,7 @@ static int tpm_release(struct inode *ino
   2.114 + 
   2.115 + static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)
   2.116 + {
   2.117 +-  debug("%s(%d)", __FUNCTION__, count);
   2.118 ++  debug("%s(%Zu)", __FUNCTION__, count);
   2.119 +   down(&tpm_mutex);
   2.120 +   if (tpm_response.data != NULL) {
   2.121 +     count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
   2.122 +@@ -91,7 +91,7 @@ static ssize_t tpm_read(struct file *fil
   2.123 + 
   2.124 + static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
   2.125 + {
   2.126 +-  debug("%s(%d)", __FUNCTION__, count);
   2.127 ++  debug("%s(%Zu)", __FUNCTION__, count);
   2.128 +   down(&tpm_mutex);
   2.129 +   *ppos = 0;
   2.130 +   if (tpm_response.data != NULL) kfree(tpm_response.data);
   2.131 +diff -uprN orig/tpm_emulator-0.3/linux_module.h tpm_emulator-0.3-x86_64/linux_module.h
   2.132 +--- orig/tpm_emulator-0.3/linux_module.h	2006-01-10 04:21:45.000000000 -0800
   2.133 ++++ tpm_emulator-0.3-x86_64/linux_module.h	2006-08-29 15:07:43.527968288 -0700
   2.134 +@@ -28,8 +28,10 @@
   2.135 + 
   2.136 + /* module settings */
   2.137 + 
   2.138 ++#ifndef STR
   2.139 + #define STR(s) __STR__(s)
   2.140 + #define __STR__(s) #s
   2.141 ++#endif
   2.142 + #include "tpm_version.h"
   2.143 + 
   2.144 + #define TPM_DEVICE_MINOR	224
   2.145 +diff -uprN orig/tpm_emulator-0.3/tpm/tpm_credentials.c tpm_emulator-0.3-x86_64/tpm/tpm_credentials.c
   2.146 +--- orig/tpm_emulator-0.3/tpm/tpm_credentials.c	2006-01-10 04:21:45.000000000 -0800
   2.147 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_credentials.c	2006-08-29 15:07:43.530967832 -0700
   2.148  @@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC
   2.149   
   2.150   TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey)
   2.151 @@ -140,9 +140,9 @@ diff -uprN tpm_emulator-0.3/tpm/tpm_cred
   2.152       publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA;
   2.153       publicPortion->algorithmParms.encScheme = srk->encScheme;
   2.154       publicPortion->algorithmParms.sigScheme = srk->sigScheme;
   2.155 -diff -uprN tpm_emulator-0.3/tpm/tpm_crypto.c tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c
   2.156 ---- tpm_emulator-0.3/tpm/tpm_crypto.c	2006-01-10 04:21:45.000000000 -0800
   2.157 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c	2006-05-26 11:26:02.000000000 -0700
   2.158 +diff -uprN orig/tpm_emulator-0.3/tpm/tpm_crypto.c tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c
   2.159 +--- orig/tpm_emulator-0.3/tpm/tpm_crypto.c	2006-01-10 04:21:45.000000000 -0800
   2.160 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c	2006-08-29 15:07:43.531967680 -0700
   2.161  @@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
   2.162     TPM_KEY_DATA *cert, *key;
   2.163     sha1_ctx_t sha1_ctx;
   2.164 @@ -192,10 +192,10 @@ diff -uprN tpm_emulator-0.3/tpm/tpm_cryp
   2.165       free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
   2.166       return TPM_FAIL;
   2.167     }
   2.168 -diff -uprN tpm_emulator-0.3/tpm/tpm_data.c tpm_emulator-0.3-x86_64/tpm/tpm_data.c
   2.169 ---- tpm_emulator-0.3/tpm/tpm_data.c	2006-01-10 04:21:45.000000000 -0800
   2.170 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_data.c	2006-05-26 11:26:02.000000000 -0700
   2.171 -@@ -214,7 +214,7 @@ static int read_from_file(uint8_t **data
   2.172 +diff -uprN orig/tpm_emulator-0.3/tpm/tpm_data.c tpm_emulator-0.3-x86_64/tpm/tpm_data.c
   2.173 +--- orig/tpm_emulator-0.3/tpm/tpm_data.c	2006-01-10 04:21:45.000000000 -0800
   2.174 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_data.c	2006-08-29 15:08:20.535342312 -0700
   2.175 +@@ -214,23 +214,30 @@ static int read_from_file(uint8_t **data
   2.176   int tpm_store_permanent_data(void)
   2.177   {
   2.178     uint8_t *buf, *ptr;
   2.179 @@ -203,8 +203,35 @@ diff -uprN tpm_emulator-0.3/tpm/tpm_data
   2.180  +  UINT32 buf_length, len;
   2.181   
   2.182     /* marshal data */
   2.183 -   buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
   2.184 -@@ -242,13 +242,14 @@ int tpm_store_permanent_data(void)
   2.185 +-  buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
   2.186 +-    + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) + 2
   2.187 +-    + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data);
   2.188 ++  buf_length = len = 4 + sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
   2.189 ++    + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) 
   2.190 ++    + sizeof_TPM_STANY_FLAGS(tpmData.stany.flags) + 2
   2.191 ++    + sizeof_TPM_STCLEAR_DATA(tpmData.stclear.data) 
   2.192 ++    + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data)
   2.193 ++    + sizeof_TPM_STANY_DATA(tpmData.stany.data);
   2.194 +   buf = ptr = tpm_malloc(buf_length);
   2.195 +   if (buf == NULL
   2.196 +       || tpm_marshal_TPM_VERSION(&ptr, &len, &tpmData.permanent.data.version)
   2.197 +       || tpm_marshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags)
   2.198 +       || tpm_marshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags)
   2.199 ++      || tpm_marshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags)
   2.200 +       || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.selfTestSucceeded)
   2.201 +       || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.owned)
   2.202 +-      || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) {
   2.203 ++      || tpm_marshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data)
   2.204 ++      || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)
   2.205 ++      || tpm_marshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) {
   2.206 +     tpm_free(buf);
   2.207 +     return -1;
   2.208 +   }
   2.209 ++
   2.210 +   if (write_to_file(buf, buf_length - len)) {
   2.211 +     tpm_free(buf);
   2.212 +     return -1; 
   2.213 +@@ -242,24 +249,29 @@ int tpm_store_permanent_data(void)
   2.214   int tpm_restore_permanent_data(void)
   2.215   {
   2.216     uint8_t *buf, *ptr;
   2.217 @@ -221,9 +248,25 @@ diff -uprN tpm_emulator-0.3/tpm/tpm_data
   2.218     /* unmarshal data */
   2.219     if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
   2.220         || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
   2.221 -diff -uprN tpm_emulator-0.3/tpm/tpm_marshalling.c tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.c
   2.222 ---- tpm_emulator-0.3/tpm/tpm_marshalling.c	2006-01-10 04:21:45.000000000 -0800
   2.223 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.c	2006-05-26 11:26:02.000000000 -0700
   2.224 +       || tpm_unmarshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags)
   2.225 +       || tpm_unmarshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags)
   2.226 ++      || tpm_unmarshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags)
   2.227 +       || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.selfTestSucceeded)
   2.228 +       || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.owned)
   2.229 +-      || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) {
   2.230 ++      || tpm_unmarshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data)
   2.231 ++      || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)
   2.232 ++      || tpm_unmarshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) {
   2.233 +     tpm_free(buf);
   2.234 +     return -1;
   2.235 +   }
   2.236 ++
   2.237 +   tpm_free(buf);
   2.238 +   return 0;
   2.239 + }
   2.240 +diff -uprN orig/tpm_emulator-0.3/tpm/tpm_marshalling.c tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.c
   2.241 +--- orig/tpm_emulator-0.3/tpm/tpm_marshalling.c	2006-01-10 04:21:45.000000000 -0800
   2.242 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.c	2006-08-29 15:08:20.537342008 -0700
   2.243  @@ -1212,7 +1212,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
   2.244   
   2.245   int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
   2.246 @@ -233,9 +276,92 @@ diff -uprN tpm_emulator-0.3/tpm/tpm_mars
   2.247     if (*length < sizeof_RSA((*v))) return -1;
   2.248     if (v->size > 0) {
   2.249       rsa_export_modulus(v, &(*ptr)[6], &m_len);
   2.250 -diff -uprN tpm_emulator-0.3/tpm/tpm_owner.c tpm_emulator-0.3-x86_64/tpm/tpm_owner.c
   2.251 ---- tpm_emulator-0.3/tpm/tpm_owner.c	2006-01-10 04:21:45.000000000 -0800
   2.252 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_owner.c	2006-05-26 11:26:02.000000000 -0700
   2.253 +@@ -1356,6 +1356,66 @@ int tpm_unmarshal_TPM_PERMANENT_DATA(BYT
   2.254 +   return 0;
   2.255 + }
   2.256 + 
   2.257 ++int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v)
   2.258 ++{
   2.259 ++  if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag)
   2.260 ++    || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceKey)
   2.261 ++    || tpm_marshal_TPM_COUNT_ID(ptr, length, v->countID) ) return -1;
   2.262 ++
   2.263 ++  return 0;
   2.264 ++}
   2.265 ++
   2.266 ++int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v)
   2.267 ++{
   2.268 ++  if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag)
   2.269 ++    || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceKey)
   2.270 ++    || tpm_unmarshal_TPM_COUNT_ID(ptr, length, &v->countID) ) return -1;
   2.271 ++
   2.272 ++  return 0;
   2.273 ++}
   2.274 ++
   2.275 ++int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v)
   2.276 ++{
   2.277 ++  UINT32 i;
   2.278 ++  if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag)
   2.279 ++    || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceSession)
   2.280 ++    || tpm_marshal_TPM_DIGEST(ptr, length, &v->auditDigest)
   2.281 ++    || tpm_marshal_BOOL(ptr, length, v->auditSession)
   2.282 ++    || tpm_marshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks)
   2.283 ++    || tpm_marshal_UINT32(ptr, length, v->contextCount)
   2.284 ++    || tpm_marshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1;
   2.285 ++  for (i = 0; i < TPM_MAX_SESSIONS; i++) {
   2.286 ++    if (tpm_marshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1;
   2.287 ++  }
   2.288 ++  for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) {
   2.289 ++    if (tpm_marshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1;
   2.290 ++  }
   2.291 ++  if (tpm_marshal_TPM_TRANSHANDLE(ptr, length, v->transExclusive)) return -1;
   2.292 ++
   2.293 ++  return 0;
   2.294 ++}
   2.295 ++
   2.296 ++int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v)
   2.297 ++{
   2.298 ++  UINT32 i;
   2.299 ++  if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag)
   2.300 ++    || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceSession)
   2.301 ++    || tpm_unmarshal_TPM_DIGEST(ptr, length, &v->auditDigest)
   2.302 ++    || tpm_unmarshal_BOOL(ptr, length, &v->auditSession)
   2.303 ++    || tpm_unmarshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks)
   2.304 ++    || tpm_unmarshal_UINT32(ptr, length, &v->contextCount)
   2.305 ++    || tpm_unmarshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1;
   2.306 ++  for (i = 0; i < TPM_MAX_SESSIONS; i++) {
   2.307 ++    if (tpm_unmarshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1;
   2.308 ++  }
   2.309 ++  for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) {
   2.310 ++    if (tpm_unmarshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1;
   2.311 ++  }
   2.312 ++  if (tpm_unmarshal_TPM_TRANSHANDLE(ptr, length, &v->transExclusive)) return -1;
   2.313 ++
   2.314 ++  return 0;
   2.315 ++}
   2.316 ++
   2.317 + int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v)
   2.318 + {
   2.319 +   if (tpm_marshal_BYTE(ptr, length, v->type)
   2.320 +diff -uprN orig/tpm_emulator-0.3/tpm/tpm_marshalling.h tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.h
   2.321 +--- orig/tpm_emulator-0.3/tpm/tpm_marshalling.h	2006-01-10 04:21:45.000000000 -0800
   2.322 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.h	2006-08-29 15:08:20.538341856 -0700
   2.323 +@@ -420,6 +420,12 @@ int tpm_unmarshal_TPM_KEY_DATA(BYTE **pt
   2.324 + int tpm_marshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *);
   2.325 + int tpm_unmarshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *);
   2.326 + 
   2.327 ++int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v);
   2.328 ++int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v);
   2.329 ++
   2.330 ++int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v);
   2.331 ++int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v);
   2.332 ++
   2.333 + int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v);
   2.334 + int tpm_unmarshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v);
   2.335 + 
   2.336 +diff -uprN orig/tpm_emulator-0.3/tpm/tpm_owner.c tpm_emulator-0.3-x86_64/tpm/tpm_owner.c
   2.337 +--- orig/tpm_emulator-0.3/tpm/tpm_owner.c	2006-01-10 04:21:45.000000000 -0800
   2.338 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_owner.c	2006-08-29 15:07:43.535967072 -0700
   2.339  @@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
   2.340     TPM_RESULT res;
   2.341     rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
   2.342 @@ -255,9 +381,63 @@ diff -uprN tpm_emulator-0.3/tpm/tpm_owne
   2.343     /* setup tpmProof and set state to owned */
   2.344     tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 
   2.345       sizeof(tpmData.permanent.data.tpmProof.nonce));
   2.346 -diff -uprN tpm_emulator-0.3/tpm/tpm_storage.c tpm_emulator-0.3-x86_64/tpm/tpm_storage.c
   2.347 ---- tpm_emulator-0.3/tpm/tpm_storage.c	2006-01-10 04:21:45.000000000 -0800
   2.348 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_storage.c	2006-05-26 14:33:18.000000000 -0700
   2.349 +diff -uprN orig/tpm_emulator-0.3/tpm/tpm_startup.c tpm_emulator-0.3-x86_64/tpm/tpm_startup.c
   2.350 +--- orig/tpm_emulator-0.3/tpm/tpm_startup.c	2006-01-10 04:21:45.000000000 -0800
   2.351 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_startup.c	2006-08-29 15:08:20.538341856 -0700
   2.352 +@@ -41,24 +41,29 @@ void TPM_Init(TPM_STARTUP_TYPE startupTy
   2.353 + TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE startupType)
   2.354 + {
   2.355 +   int i;
   2.356 ++  int restore_fail;
   2.357 +   info("TPM_Startup(%d)", startupType);
   2.358 +   if (tpmData.stany.flags.postInitialise == FALSE) return TPM_INVALID_POSTINIT;
   2.359 +-  /* reset STANY_FLAGS */
   2.360 +-  SET_TO_ZERO(&tpmData.stany.flags);
   2.361 +-  tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS;
   2.362 +-  /* reset STANY_DATA (invalidates ALL sessions) */
   2.363 +-  SET_TO_ZERO(&tpmData.stany.data);
   2.364 +-  tpmData.stany.data.tag = TPM_TAG_STANY_DATA;
   2.365 +-  /* init session-context nonce */
   2.366 +-  SET_TO_RAND(&tpmData.stany.data.contextNonceSession);
   2.367 ++
   2.368 ++  /* try and restore state to get EK, SRK, etc */
   2.369 ++  restore_fail = tpm_restore_permanent_data();
   2.370 ++
   2.371 +   /* set data and flags according to the given startup type */
   2.372 +   if (startupType == TPM_ST_CLEAR) {
   2.373 ++    /* reset STANY_FLAGS */
   2.374 ++    SET_TO_ZERO(&tpmData.stany.flags);
   2.375 ++    tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS;
   2.376 ++    /* reset STANY_DATA (invalidates ALL sessions) */
   2.377 ++    SET_TO_ZERO(&tpmData.stany.data);
   2.378 ++    tpmData.stany.data.tag = TPM_TAG_STANY_DATA;
   2.379 ++    /* init session-context nonce */
   2.380 ++    SET_TO_RAND(&tpmData.stany.data.contextNonceSession);
   2.381 +     /* reset PCR values */
   2.382 +     for (i = 0; i < TPM_NUM_PCR; i++) {
   2.383 +-      if (tpmData.permanent.data.pcrAttrib[i].pcrReset)
   2.384 +-        SET_TO_ZERO(tpmData.permanent.data.pcrValue[i].digest);
   2.385 ++      if (!tpmData.permanent.data.pcrAttrib[i].pcrReset)
   2.386 ++        SET_TO_ZERO(&tpmData.permanent.data.pcrValue[i].digest);
   2.387 +       else
   2.388 +-        SET_TO_0xFF(tpmData.permanent.data.pcrValue[i].digest);
   2.389 ++        SET_TO_0xFF(&tpmData.permanent.data.pcrValue[i].digest);
   2.390 +     }
   2.391 +     /* reset STCLEAR_FLAGS */
   2.392 +     SET_TO_ZERO(&tpmData.stclear.flags);
   2.393 +@@ -77,7 +82,8 @@ TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE 
   2.394 +     /* init key-context nonce */
   2.395 +     SET_TO_RAND(&tpmData.stclear.data.contextNonceKey);
   2.396 +   } else if (startupType == TPM_ST_STATE) {
   2.397 +-    if (tpm_restore_permanent_data()) {
   2.398 ++    /* restore must have been successful for TPM_ST_STATE */
   2.399 ++    if (restore_fail) {
   2.400 +       error("restoring permanent data failed");
   2.401 +       tpmData.permanent.data.testResult = "tpm_restore_permanent_data() failed";
   2.402 +       tpmData.permanent.flags.selfTestSucceeded = FALSE;
   2.403 +diff -uprN orig/tpm_emulator-0.3/tpm/tpm_storage.c tpm_emulator-0.3-x86_64/tpm/tpm_storage.c
   2.404 +--- orig/tpm_emulator-0.3/tpm/tpm_storage.c	2006-01-10 04:21:45.000000000 -0800
   2.405 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_storage.c	2006-08-29 15:07:43.537966768 -0700
   2.406  @@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
   2.407                           BYTE *enc, UINT32 *enc_size)
   2.408   {
   2.409 @@ -482,3 +662,76 @@ diff -uprN tpm_emulator-0.3/tpm/tpm_stor
   2.410     if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
   2.411       tpm_free(pubKey->pubKey.key);
   2.412       return TPM_FAIL;
   2.413 +diff -uprN orig/tpm_emulator-0.3/tpm/tpm_structures.h tpm_emulator-0.3-x86_64/tpm/tpm_structures.h
   2.414 +--- orig/tpm_emulator-0.3/tpm/tpm_structures.h	2006-01-10 04:21:45.000000000 -0800
   2.415 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_structures.h	2006-08-29 15:08:20.545340792 -0700
   2.416 +@@ -1723,6 +1723,7 @@ typedef struct tdTPM_DAA_ISSUER {
   2.417 +   TPM_DIGEST DAA_digest_gamma;
   2.418 +   BYTE DAA_generic_q[26];
   2.419 + } TPM_DAA_ISSUER;
   2.420 ++#define sizeof_TPM_DAA_ISSUER(s) (2 + (20 * 6) + 26 )
   2.421 + 
   2.422 + /*
   2.423 +  * TPM_DAA_TPM ([TPM_Part2], Section 22.8)
   2.424 +@@ -1738,6 +1739,7 @@ typedef struct tdTPM_DAA_TPM {
   2.425 +   TPM_DIGEST DAA_rekey;
   2.426 +   UINT32 DAA_count;
   2.427 + } TPM_DAA_TPM;
   2.428 ++#define sizeof_TPM_DAA_TPM(s) (2 + (4 * 20) + 4)
   2.429 + 
   2.430 + /*
   2.431 +  * TPM_DAA_CONTEXT ([TPM_Part2], Section 22.9)
   2.432 +@@ -1752,6 +1754,7 @@ typedef struct tdTPM_DAA_CONTEXT {
   2.433 +   BYTE DAA_scratch[256];
   2.434 +   BYTE DAA_stage;
   2.435 + } TPM_DAA_CONTEXT;
   2.436 ++#define sizeof_TPM_DAA_CONTEXT(s) (2 + (3 * 20) + 256 + 1)
   2.437 + 
   2.438 + /*
   2.439 +  * TPM_DAA_JOINDATA ([TPM_Part2], Section 22.10)
   2.440 +@@ -1763,6 +1766,7 @@ typedef struct tdTPM_DAA_JOINDATA {
   2.441 +   BYTE DAA_join_u1[138]; /* WATCH: 138 (v1.2 rev 85) */
   2.442 +   TPM_DIGEST DAA_digest_n0;
   2.443 + } TPM_DAA_JOINDATA;
   2.444 ++#define sizeof_TPM_DAA_JOINDATA(s) (1 + 1 + 20)
   2.445 + 
   2.446 + /*
   2.447 +  * TPM_DAA_BLOB ([TPM_Part2], Section 22.12)
   2.448 +@@ -2033,6 +2037,7 @@ typedef struct tdTPM_STCLEAR_DATA {
   2.449 +   TPM_COUNT_ID countID;
   2.450 +   //UINT32 ownerReference;
   2.451 + } TPM_STCLEAR_DATA;
   2.452 ++#define sizeof_TPM_STCLEAR_DATA(s) (2 + 20 + 4)
   2.453 + 
   2.454 + /*
   2.455 +  * TPM_SESSION_DATA
   2.456 +@@ -2069,6 +2074,11 @@ typedef struct tdTPM_DAA_SESSION_DATA {
   2.457 +   TPM_DAA_JOINDATA DAA_joinSession;
   2.458 +   TPM_HANDLE handle;
   2.459 + } TPM_DAA_SESSION_DATA;
   2.460 ++#define sizeof_TPM_DAA_SESSION_DATA(s) ( 1 \
   2.461 ++  + sizeof_TPM_DAA_ISSUER(s.DAA_issuerSettings) \
   2.462 ++  + sizeof_TPM_DAA_TPM(s.DAA_tpmSpecific) \
   2.463 ++  + sizeof_TPM_DAA_CONTEXT(s.DAA_session) \
   2.464 ++  + sizeof_TPM_DAA_JOINDATA(s.DAA_joinSession) + 4)
   2.465 + 
   2.466 + /*
   2.467 +  * TPM_STANY_DATA ([TPM_Part2], Section 7.6)
   2.468 +@@ -2095,6 +2105,17 @@ typedef struct tdTPM_STANY_DATA {
   2.469 +   TPM_DAA_SESSION_DATA sessionsDAA[TPM_MAX_SESSIONS_DAA];
   2.470 +   TPM_TRANSHANDLE transExclusive;
   2.471 + } TPM_STANY_DATA;
   2.472 ++#define sizeof_TPM_STANY_DATA(s) (2 + 20 + 20 + 1 \
   2.473 ++  + sizeof_TPM_CURRENT_TICKS(s.currentTicks) \
   2.474 ++  + 4 + (4 * TPM_MAX_SESSION_LIST) \
   2.475 ++  + (sizeof_TPM_SESSION_DATA(s.sessions[0]) * TPM_MAX_SESSION_LIST) \
   2.476 ++  + (sizeof_TPM_DAA_SESSION_DATA(s.sessionsDAA[0]) * TPM_MAX_SESSIONS_DAA) + 4)
   2.477 ++
   2.478 ++#define sizeof_TPM_PERMANENT_DATA(s) (2 + 4 + 4*20 \
   2.479 ++  + sizeof_RSA(s.endorsementKey) + TPM_ORD_MAX/8 \
   2.480 ++  + (1+TPM_MAX_KEYS)*sizeof_TPM_KEY_DATA(s.srk) \
   2.481 ++  + TPM_NUM_PCR*(sizeof_TPM_PCR_ATTRIBUTES(x)+20) \
   2.482 ++  + TPM_MAX_COUNTERS*sizeof_TPM_COUNTER_VALUE2(x) + 1 + 4 + 20)
   2.483 + 
   2.484 + /*
   2.485 +  * TPM_DATA
     3.1 --- a/tools/vtpm/tpm_emulator.patch	Tue Jun 27 11:13:24 2006 +0100
     3.2 +++ b/tools/vtpm/tpm_emulator.patch	Tue Jun 27 11:14:19 2006 +0100
     3.3 @@ -1,13 +1,13 @@
     3.4 -diff -uprN orig/tpm_emulator-0.3-x86_64/AUTHORS tpm_emulator/AUTHORS
     3.5 ---- orig/tpm_emulator-0.3-x86_64/AUTHORS	2006-01-10 04:21:45.000000000 -0800
     3.6 -+++ tpm_emulator/AUTHORS	2006-06-02 13:36:03.000000000 -0700
     3.7 +diff -uprN tpm_emulator-0.3-x86_64/AUTHORS tpm_emulator/AUTHORS
     3.8 +--- tpm_emulator-0.3-x86_64/AUTHORS	2006-08-29 15:07:21.618299064 -0700
     3.9 ++++ tpm_emulator/AUTHORS	2006-08-29 15:26:17.099679656 -0700
    3.10  @@ -1,2 +1,3 @@
    3.11   Mario Strasser <mast@gmx.net>
    3.12   Heiko Stamer <stamer@gaos.org> [DAA]
    3.13  +INTEL Corp <> [Dropped to Ring3]
    3.14 -diff -uprN orig/tpm_emulator-0.3-x86_64/ChangeLog tpm_emulator/ChangeLog
    3.15 ---- orig/tpm_emulator-0.3-x86_64/ChangeLog	2006-01-10 04:21:45.000000000 -0800
    3.16 -+++ tpm_emulator/ChangeLog	2006-06-02 13:36:03.000000000 -0700
    3.17 +diff -uprN tpm_emulator-0.3-x86_64/ChangeLog tpm_emulator/ChangeLog
    3.18 +--- tpm_emulator-0.3-x86_64/ChangeLog	2006-08-29 15:07:21.618299064 -0700
    3.19 ++++ tpm_emulator/ChangeLog	2006-08-29 15:26:17.100679504 -0700
    3.20  @@ -1,3 +1,6 @@
    3.21  +2005-08-16 Intel Corp
    3.22  +	* Moved module out of kernel to run as a ring 3 app
    3.23 @@ -15,9 +15,122 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
    3.24   2005-12-24  Mario Strasser <mast@gmx.net>
    3.25   	* tpm_transport.c, tpm_marshalling.c, tpm_structures.h:
    3.26   		Transport session functionality added
    3.27 -diff -uprN orig/tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c tpm_emulator/crypto/gmp_kernel_wrapper.c
    3.28 ---- orig/tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c	2006-06-05 09:54:21.000000000 -0700
    3.29 -+++ tpm_emulator/crypto/gmp_kernel_wrapper.c	2006-06-02 13:36:03.000000000 -0700
    3.30 +diff -uprN tpm_emulator-0.3-x86_64/Makefile tpm_emulator/Makefile
    3.31 +--- tpm_emulator-0.3-x86_64/Makefile	2006-08-29 15:08:20.532342768 -0700
    3.32 ++++ tpm_emulator/Makefile	2006-08-29 15:27:39.559143912 -0700
    3.33 +@@ -1,22 +1,31 @@
    3.34 + # Software-Based Trusted Platform Module (TPM) Emulator for Linux
    3.35 + # Copyright (C) 2004 Mario Strasser <mast@gmx.net>
    3.36 ++# Copyright (C) 2006 INTEL Corp.
    3.37 + #
    3.38 + # $Id: Makefile 69 2005-12-13 12:55:52Z mast $
    3.39 + 
    3.40 +-# kernel settings
    3.41 +-KERNEL_RELEASE := $(shell uname -r)
    3.42 +-KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
    3.43 +-MOD_SUBDIR     := misc
    3.44 + COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
    3.45 + 
    3.46 + # module settings
    3.47 +-MODULE_NAME    := tpm_emulator
    3.48 ++BIN            := tpm_emulator
    3.49 + VERSION_MAJOR  := 0
    3.50 + VERSION_MINOR  := 3
    3.51 + VERSION_BUILD  := $(shell date +"%s")
    3.52 + 
    3.53 +-# enable/disable DEBUG messages
    3.54 +-EXTRA_CFLAGS   += -Wall -DDEBUG -g  
    3.55 ++# Installation program and options
    3.56 ++INSTALL         = install
    3.57 ++INSTALL_PROG    = $(INSTALL) -m0755
    3.58 ++INSTALL_DIR     = $(INSTALL) -d -m0755
    3.59 ++
    3.60 ++# Xen tools installation directory
    3.61 ++TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
    3.62 ++
    3.63 ++CC      := gcc
    3.64 ++CFLAGS  += -g -Wall $(INCLUDE) -DDEBUG
    3.65 ++CFLAGS  += -I. -Itpm
    3.66 ++
    3.67 ++# Is the simulator running in it's own vm?
    3.68 ++#CFLAGS += -DVTPM_MULTI_VM
    3.69 + 
    3.70 + ifeq ($(COMPILE_ARCH),x86_64)
    3.71 + LIBDIR = lib64
    3.72 +@@ -34,38 +43,31 @@ DIRS           := . crypto tpm 
    3.73 + SRCS           := $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.c))
    3.74 + OBJS           := $(patsubst %.c, %.o, $(SRCS))
    3.75 + SRCS           += $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.h))
    3.76 +-DISTSRC        := ./README ./AUTHORS ./ChangeLog ./Makefile $(SRCS)
    3.77 +-DISTDIR        := tpm_emulator-$(VERSION_MAJOR).$(VERSION_MINOR)
    3.78 + 
    3.79 +-obj-m               := $(MODULE_NAME).o
    3.80 +-$(MODULE_NAME)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
    3.81 ++obj-m               := $(BIN)
    3.82 ++$(BIN)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
    3.83 + 
    3.84 + EXTRA_CFLAGS   += -I$(src) -I$(src)/crypto -I$(src)/tpm 
    3.85 + 
    3.86 + # do not print "Entering directory ..."
    3.87 + MAKEFLAGS      += --no-print-directory
    3.88 + 
    3.89 +-all:	$(src)/crypto/gmp.h $(src)/crypto/libgmp.a version
    3.90 +-	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules
    3.91 ++all: $(BIN)
    3.92 ++
    3.93 ++$(BIN):	$(src)/crypto/gmp.h $(src)/crypto/libgmp.a version $(SRCS) $(OBJS)
    3.94 ++	$(CC) $(CFLAGS) $(OBJS) $(src)/crypto/libgmp.a -o $(BIN)
    3.95 ++
    3.96 ++%.o: %.c
    3.97 ++	$(CC) $(CFLAGS) -c $< -o $@
    3.98 + 
    3.99 +-install:
   3.100 +-	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules_install
   3.101 +-	test -d /var/tpm || mkdir /var/tpm
   3.102 +-	test -c /dev/tpm || mknod /dev/tpm c 10 224
   3.103 +-	chmod 666 /dev/tpm
   3.104 +-	depmod -a
   3.105 ++install: $(BIN)
   3.106 ++	$(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
   3.107 + 
   3.108 + clean:
   3.109 +-	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) clean
   3.110 +-	rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a
   3.111 ++	rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS)
   3.112 + 
   3.113 +-dist:	$(DISTSRC)
   3.114 +-	rm -rf $(DISTDIR)
   3.115 +-	mkdir $(DISTDIR)
   3.116 +-	cp --parents $(DISTSRC) $(DISTDIR)/
   3.117 +-	rm -f $(DISTDIR)/crypto/gmp.h 
   3.118 +-	tar -chzf $(DISTDIR).tar.gz $(DISTDIR)
   3.119 +-	rm -rf $(DISTDIR)
   3.120 ++mrproper: clean
   3.121 ++	rm -f $(BIN) tpm_version.h
   3.122 + 
   3.123 + $(src)/crypto/libgmp.a:
   3.124 + 	test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a
   3.125 +diff -uprN tpm_emulator-0.3-x86_64/README tpm_emulator/README
   3.126 +--- tpm_emulator-0.3-x86_64/README	2006-08-29 15:07:43.530967832 -0700
   3.127 ++++ tpm_emulator/README	2006-08-29 15:26:17.105678744 -0700
   3.128 +@@ -13,7 +13,8 @@ $Id: README 78 2006-01-07 10:45:39Z mast
   3.129 + Copyright
   3.130 + --------------------------------------------------------------------------
   3.131 + Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal 
   3.132 +-Institute of Technology (ETH) Zurich.
   3.133 ++                   Institute of Technology (ETH) Zurich.
   3.134 ++Copyright (C) 2005 INTEL Corp 
   3.135 +               
   3.136 + This program is free software; you can redistribute it and/or modify
   3.137 + it under the terms of the GNU General Public License as published by
   3.138 +diff -uprN tpm_emulator-0.3-x86_64/README.1st tpm_emulator/README.1st
   3.139 +--- tpm_emulator-0.3-x86_64/README.1st	1969-12-31 16:00:00.000000000 -0800
   3.140 ++++ tpm_emulator/README.1st	2006-08-29 15:26:17.105678744 -0700
   3.141 +@@ -0,0 +1 @@
   3.142 ++Note that you must manually create /tmp/tpm_in.fifo and /tmp/tpm_out.fifo for this emulator to work.
   3.143 +diff -uprN tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c tpm_emulator/crypto/gmp_kernel_wrapper.c
   3.144 +--- tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c	2006-08-29 15:07:43.525968592 -0700
   3.145 ++++ tpm_emulator/crypto/gmp_kernel_wrapper.c	2006-08-29 15:26:17.101679352 -0700
   3.146  @@ -1,5 +1,6 @@
   3.147   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.148    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.149 @@ -77,9 +190,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.150     }
   3.151   }
   3.152   
   3.153 -diff -uprN orig/tpm_emulator-0.3-x86_64/crypto/rsa.c tpm_emulator/crypto/rsa.c
   3.154 ---- orig/tpm_emulator-0.3-x86_64/crypto/rsa.c	2006-01-10 04:21:45.000000000 -0800
   3.155 -+++ tpm_emulator/crypto/rsa.c	2006-06-02 13:36:03.000000000 -0700
   3.156 +diff -uprN tpm_emulator-0.3-x86_64/crypto/rsa.c tpm_emulator/crypto/rsa.c
   3.157 +--- tpm_emulator-0.3-x86_64/crypto/rsa.c	2006-08-29 15:07:21.618299064 -0700
   3.158 ++++ tpm_emulator/crypto/rsa.c	2006-08-29 15:26:17.102679200 -0700
   3.159  @@ -1,5 +1,6 @@
   3.160   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.161    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.162 @@ -105,8 +218,8 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.163         sha1_final(&ctx, &msg[1]);
   3.164         if (memcmp(&msg[1], &msg[1 + SHA1_DIGEST_LENGTH], 
   3.165             SHA1_DIGEST_LENGTH) != 0) return -1;
   3.166 -diff -uprN orig/tpm_emulator-0.3-x86_64/linux_module.c tpm_emulator/linux_module.c
   3.167 ---- orig/tpm_emulator-0.3-x86_64/linux_module.c	2006-06-05 09:54:21.000000000 -0700
   3.168 +diff -uprN tpm_emulator-0.3-x86_64/linux_module.c tpm_emulator/linux_module.c
   3.169 +--- tpm_emulator-0.3-x86_64/linux_module.c	2006-08-29 15:07:43.526968440 -0700
   3.170  +++ tpm_emulator/linux_module.c	1969-12-31 16:00:00.000000000 -0800
   3.171  @@ -1,194 +0,0 @@
   3.172  -/* Software-Based Trusted Platform Module (TPM) Emulator for Linux 
   3.173 @@ -303,9 +416,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.174  -  return (ticks > 0) ? ticks : 1;
   3.175  -}
   3.176  -
   3.177 -diff -uprN orig/tpm_emulator-0.3-x86_64/linux_module.h tpm_emulator/linux_module.h
   3.178 ---- orig/tpm_emulator-0.3-x86_64/linux_module.h	2006-06-05 09:54:21.000000000 -0700
   3.179 -+++ tpm_emulator/linux_module.h	2006-06-02 13:36:03.000000000 -0700
   3.180 +diff -uprN tpm_emulator-0.3-x86_64/linux_module.h tpm_emulator/linux_module.h
   3.181 +--- tpm_emulator-0.3-x86_64/linux_module.h	2006-08-29 15:07:43.527968288 -0700
   3.182 ++++ tpm_emulator/linux_module.h	2006-08-29 15:26:17.103679048 -0700
   3.183  @@ -1,5 +1,6 @@
   3.184   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.185    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.186 @@ -405,121 +518,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.187   #define BE16_TO_CPU(x) __be16_to_cpu(x)
   3.188   #define LE16_TO_CPU(x) __le16_to_cpu(x)
   3.189   
   3.190 -diff -uprN orig/tpm_emulator-0.3-x86_64/Makefile tpm_emulator/Makefile
   3.191 ---- orig/tpm_emulator-0.3-x86_64/Makefile	2006-06-05 09:54:21.000000000 -0700
   3.192 -+++ tpm_emulator/Makefile	2006-06-02 13:36:03.000000000 -0700
   3.193 -@@ -1,22 +1,31 @@
   3.194 - # Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.195 - # Copyright (C) 2004 Mario Strasser <mast@gmx.net>
   3.196 -+# Copyright (C) 2006 INTEL Corp.
   3.197 - #
   3.198 - # $Id: Makefile 69 2005-12-13 12:55:52Z mast $
   3.199 - 
   3.200 --# kernel settings
   3.201 --KERNEL_RELEASE := $(shell uname -r)
   3.202 --KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
   3.203 --MOD_SUBDIR     := misc
   3.204 - COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
   3.205 - 
   3.206 - # module settings
   3.207 --MODULE_NAME    := tpm_emulator
   3.208 -+BIN            := tpm_emulator
   3.209 - VERSION_MAJOR  := 0
   3.210 - VERSION_MINOR  := 3
   3.211 - VERSION_BUILD  := $(shell date +"%s")
   3.212 - 
   3.213 --# enable/disable DEBUG messages
   3.214 --EXTRA_CFLAGS   += -Wall -DDEBUG -g  
   3.215 -+# Installation program and options
   3.216 -+INSTALL         = install
   3.217 -+INSTALL_PROG    = $(INSTALL) -m0755
   3.218 -+INSTALL_DIR     = $(INSTALL) -d -m0755
   3.219 -+
   3.220 -+# Xen tools installation directory
   3.221 -+TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
   3.222 -+
   3.223 -+CC      := gcc
   3.224 -+CFLAGS  += -g -Wall $(INCLUDE) -DDEBUG
   3.225 -+CFLAGS  += -I. -Itpm
   3.226 -+
   3.227 -+# Is the simulator running in it's own vm?
   3.228 -+#CFLAGS += -DVTPM_MULTI_VM
   3.229 - 
   3.230 - ifeq ($(COMPILE_ARCH),x86_64)
   3.231 - LIBDIR = lib64
   3.232 -@@ -34,38 +43,31 @@ DIRS           := . crypto tpm 
   3.233 - SRCS           := $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.c))
   3.234 - OBJS           := $(patsubst %.c, %.o, $(SRCS))
   3.235 - SRCS           += $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.h))
   3.236 --DISTSRC        := ./README ./AUTHORS ./ChangeLog ./Makefile $(SRCS)
   3.237 --DISTDIR        := tpm_emulator-$(VERSION_MAJOR).$(VERSION_MINOR)
   3.238 - 
   3.239 --obj-m               := $(MODULE_NAME).o
   3.240 --$(MODULE_NAME)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
   3.241 -+obj-m               := $(BIN)
   3.242 -+$(BIN)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
   3.243 - 
   3.244 - EXTRA_CFLAGS   += -I$(src) -I$(src)/crypto -I$(src)/tpm 
   3.245 - 
   3.246 - # do not print "Entering directory ..."
   3.247 - MAKEFLAGS      += --no-print-directory
   3.248 - 
   3.249 --all:	$(src)/crypto/gmp.h $(src)/crypto/libgmp.a version
   3.250 --	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules
   3.251 -+all: $(BIN)
   3.252 -+
   3.253 -+$(BIN):	$(src)/crypto/gmp.h $(src)/crypto/libgmp.a version $(SRCS) $(OBJS)
   3.254 -+	$(CC) $(CFLAGS) $(OBJS) $(src)/crypto/libgmp.a -o $(BIN)
   3.255 -+
   3.256 -+%.o: %.c
   3.257 -+	$(CC) $(CFLAGS) -c $< -o $@
   3.258 - 
   3.259 - install:
   3.260 --	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules_install
   3.261 --	test -d /var/tpm || mkdir /var/tpm
   3.262 --	test -c /dev/tpm || mknod /dev/tpm c 10 224
   3.263 --	chmod 666 /dev/tpm
   3.264 --	depmod -a
   3.265 -+	$(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
   3.266 - 
   3.267 - clean:
   3.268 --	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) clean
   3.269 --	rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a
   3.270 -+	rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS)
   3.271 - 
   3.272 --dist:	$(DISTSRC)
   3.273 --	rm -rf $(DISTDIR)
   3.274 --	mkdir $(DISTDIR)
   3.275 --	cp --parents $(DISTSRC) $(DISTDIR)/
   3.276 --	rm -f $(DISTDIR)/crypto/gmp.h 
   3.277 --	tar -chzf $(DISTDIR).tar.gz $(DISTDIR)
   3.278 --	rm -rf $(DISTDIR)
   3.279 -+mrproper: clean
   3.280 -+	rm -f $(BIN) tpm_version.h
   3.281 - 
   3.282 - $(src)/crypto/libgmp.a:
   3.283 - 	test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a
   3.284 -diff -uprN orig/tpm_emulator-0.3-x86_64/README tpm_emulator/README
   3.285 ---- orig/tpm_emulator-0.3-x86_64/README	2006-06-05 09:54:21.000000000 -0700
   3.286 -+++ tpm_emulator/README	2006-06-02 13:36:03.000000000 -0700
   3.287 -@@ -13,7 +13,8 @@ $Id: README 78 2006-01-07 10:45:39Z mast
   3.288 - Copyright
   3.289 - --------------------------------------------------------------------------
   3.290 - Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal 
   3.291 --Institute of Technology (ETH) Zurich.
   3.292 -+                   Institute of Technology (ETH) Zurich.
   3.293 -+Copyright (C) 2005 INTEL Corp 
   3.294 -               
   3.295 - This program is free software; you can redistribute it and/or modify
   3.296 - it under the terms of the GNU General Public License as published by
   3.297 -diff -uprN orig/tpm_emulator-0.3-x86_64/README.1st tpm_emulator/README.1st
   3.298 ---- orig/tpm_emulator-0.3-x86_64/README.1st	1969-12-31 16:00:00.000000000 -0800
   3.299 -+++ tpm_emulator/README.1st	2006-06-02 13:37:48.000000000 -0700
   3.300 -@@ -0,0 +1 @@
   3.301 -+Note that you must manually create /tmp/tpm_in.fifo and /tmp/tpm_out.fifo for this emulator to work.
   3.302 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_audit.c tpm_emulator/tpm/tpm_audit.c
   3.303 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_audit.c	2006-01-10 04:21:45.000000000 -0800
   3.304 -+++ tpm_emulator/tpm/tpm_audit.c	2006-06-02 13:36:03.000000000 -0700
   3.305 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_audit.c tpm_emulator/tpm/tpm_audit.c
   3.306 +--- tpm_emulator-0.3-x86_64/tpm/tpm_audit.c	2006-08-29 15:07:21.620298760 -0700
   3.307 ++++ tpm_emulator/tpm/tpm_audit.c	2006-08-29 15:26:17.107678440 -0700
   3.308  @@ -1,6 +1,7 @@
   3.309   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.310    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.311 @@ -582,9 +583,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.312     return TPM_SUCCESS;
   3.313   }
   3.314  -
   3.315 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c tpm_emulator/tpm/tpm_authorization.c
   3.316 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c	2006-01-10 04:21:45.000000000 -0800
   3.317 -+++ tpm_emulator/tpm/tpm_authorization.c	2006-06-02 13:36:03.000000000 -0700
   3.318 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c tpm_emulator/tpm/tpm_authorization.c
   3.319 +--- tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c	2006-08-29 15:07:21.620298760 -0700
   3.320 ++++ tpm_emulator/tpm/tpm_authorization.c	2006-08-29 15:26:17.108678288 -0700
   3.321  @@ -1,6 +1,7 @@
   3.322   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.323    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.324 @@ -602,9 +603,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.325     
   3.326     info("tpm_verify_auth(%08x)", auth->authHandle);
   3.327     /* get dedicated authorization or transport session */
   3.328 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_capability.c tpm_emulator/tpm/tpm_capability.c
   3.329 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_capability.c	2006-01-10 04:21:45.000000000 -0800
   3.330 -+++ tpm_emulator/tpm/tpm_capability.c	2006-06-02 13:36:03.000000000 -0700
   3.331 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_capability.c tpm_emulator/tpm/tpm_capability.c
   3.332 +--- tpm_emulator-0.3-x86_64/tpm/tpm_capability.c	2006-08-29 15:07:21.620298760 -0700
   3.333 ++++ tpm_emulator/tpm/tpm_capability.c	2006-08-29 15:26:17.109678136 -0700
   3.334  @@ -1,6 +1,7 @@
   3.335   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.336    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.337 @@ -627,9 +628,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.338     }
   3.339   }
   3.340  -
   3.341 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c tpm_emulator/tpm/tpm_cmd_handler.c
   3.342 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c	2006-01-10 04:21:45.000000000 -0800
   3.343 -+++ tpm_emulator/tpm/tpm_cmd_handler.c	2006-06-02 13:36:03.000000000 -0700
   3.344 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c tpm_emulator/tpm/tpm_cmd_handler.c
   3.345 +--- tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c	2006-08-29 15:07:21.621298608 -0700
   3.346 ++++ tpm_emulator/tpm/tpm_cmd_handler.c	2006-08-29 15:26:17.113677528 -0700
   3.347  @@ -1,6 +1,7 @@
   3.348   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.349    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.350 @@ -687,9 +688,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.351     /* setup authorisation as well as response tag and size */
   3.352     memset(rsp, 0, sizeof(*rsp));
   3.353     switch (req->tag) {
   3.354 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c tpm_emulator/tpm/tpm_crypto.c
   3.355 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c	2006-06-05 09:54:21.000000000 -0700
   3.356 -+++ tpm_emulator/tpm/tpm_crypto.c	2006-06-02 13:36:03.000000000 -0700
   3.357 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c tpm_emulator/tpm/tpm_crypto.c
   3.358 +--- tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c	2006-08-29 15:07:43.531967680 -0700
   3.359 ++++ tpm_emulator/tpm/tpm_crypto.c	2006-08-29 15:26:17.114677376 -0700
   3.360  @@ -1,6 +1,7 @@
   3.361   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.362    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.363 @@ -712,9 +713,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.364     return TPM_SUCCESS;
   3.365   }
   3.366  -
   3.367 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_daa.c tpm_emulator/tpm/tpm_daa.c
   3.368 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_daa.c	2006-01-10 04:21:45.000000000 -0800
   3.369 -+++ tpm_emulator/tpm/tpm_daa.c	2006-06-02 13:36:03.000000000 -0700
   3.370 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_daa.c tpm_emulator/tpm/tpm_daa.c
   3.371 +--- tpm_emulator-0.3-x86_64/tpm/tpm_daa.c	2006-08-29 15:07:21.622298456 -0700
   3.372 ++++ tpm_emulator/tpm/tpm_daa.c	2006-08-29 15:26:17.119676616 -0700
   3.373  @@ -700,14 +700,14 @@ info("tested until here");
   3.374             sizeof(session->DAA_tpmSpecific.DAA_rekey));
   3.375         sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
   3.376 @@ -869,9 +870,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.377         sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
   3.378         mpz_init(f), mpz_init(q);
   3.379         mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
   3.380 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_data.c tpm_emulator/tpm/tpm_data.c
   3.381 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_data.c	2006-06-05 09:54:21.000000000 -0700
   3.382 -+++ tpm_emulator/tpm/tpm_data.c	2006-06-02 13:36:03.000000000 -0700
   3.383 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_data.c tpm_emulator/tpm/tpm_data.c
   3.384 +--- tpm_emulator-0.3-x86_64/tpm/tpm_data.c	2006-08-29 15:08:20.535342312 -0700
   3.385 ++++ tpm_emulator/tpm/tpm_data.c	2006-08-29 15:26:17.121676312 -0700
   3.386  @@ -150,44 +150,43 @@ void tpm_release_data(void)
   3.387   
   3.388   #ifdef TPM_STORE_TO_FILE
   3.389 @@ -938,7 +939,7 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.390     if (res != *data_length) {
   3.391       tpm_free(*data);
   3.392       return -1;
   3.393 -@@ -267,7 +266,7 @@ int tpm_restore_permanent_data(void)
   3.394 +@@ -278,7 +277,7 @@ int tpm_restore_permanent_data(void)
   3.395   
   3.396   int tpm_erase_permanent_data(void)
   3.397   {
   3.398 @@ -947,9 +948,297 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.399     return res;
   3.400   }
   3.401   
   3.402 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c tpm_emulator/tpm/tpm_deprecated.c
   3.403 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c	2006-01-10 04:21:45.000000000 -0800
   3.404 -+++ tpm_emulator/tpm/tpm_deprecated.c	2006-06-02 13:36:03.000000000 -0700
   3.405 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_data.c.orig tpm_emulator/tpm/tpm_data.c.orig
   3.406 +--- tpm_emulator-0.3-x86_64/tpm/tpm_data.c.orig	1969-12-31 16:00:00.000000000 -0800
   3.407 ++++ tpm_emulator/tpm/tpm_data.c.orig	2006-08-29 15:26:08.469991568 -0700
   3.408 +@@ -0,0 +1,284 @@
   3.409 ++/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.410 ++ * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.411 ++ *                    Swiss Federal Institute of Technology (ETH) Zurich
   3.412 ++ *
   3.413 ++ * This module is free software; you can redistribute it and/or modify
   3.414 ++ * it under the terms of the GNU General Public License as published
   3.415 ++ * by the Free Software Foundation; either version 2 of the License,
   3.416 ++ * or (at your option) any later version.
   3.417 ++ *
   3.418 ++ * This module is distributed in the hope that it will be useful,
   3.419 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
   3.420 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   3.421 ++ * GNU General Public License for more details.
   3.422 ++ *
   3.423 ++ * $Id: tpm_data.c 36 2005-10-26 20:31:19Z hstamer $
   3.424 ++ */
   3.425 ++
   3.426 ++#include "tpm_emulator.h"
   3.427 ++#include "tpm_structures.h"
   3.428 ++#include "tpm_marshalling.h"
   3.429 ++#include "linux_module.h"
   3.430 ++
   3.431 ++TPM_DATA tpmData;
   3.432 ++
   3.433 ++BOOL tpm_get_physical_presence(void)
   3.434 ++{
   3.435 ++  return (tpmData.stclear.flags.physicalPresence || TRUE);
   3.436 ++}
   3.437 ++
   3.438 ++static inline void init_pcr_attr(int pcr, BOOL reset, BYTE rl, BYTE el)
   3.439 ++{
   3.440 ++  int i;
   3.441 ++  tpmData.permanent.data.pcrAttrib[pcr].pcrReset = reset;
   3.442 ++  for (i = 0; i < TPM_NUM_LOCALITY; i++) {
   3.443 ++    tpmData.permanent.data.pcrAttrib[pcr].pcrResetLocal[i] = (rl & (1 << i));
   3.444 ++    tpmData.permanent.data.pcrAttrib[pcr].pcrExtendLocal[i] = (el & (1 << i));
   3.445 ++  }
   3.446 ++}
   3.447 ++
   3.448 ++void tpm_init_data(void)
   3.449 ++{
   3.450 ++  /* endorsement key */
   3.451 ++  uint8_t ek_n[] =  "\xa8\xdb\xa9\x42\xa8\xf3\xb8\x06\x85\x90\x76\x93\xad\xf7"
   3.452 ++    "\x74\xec\x3f\xd3\x3d\x9d\xe8\x2e\xff\x15\xed\x0e\xce\x5f\x93"
   3.453 ++    "\x92\xeb\xd1\x96\x2b\x72\x18\x81\x79\x12\x9d\x9c\x40\xd7\x1a"
   3.454 ++    "\x21\xda\x5f\x56\xe0\xc9\x48\x31\xdd\x96\xdc\xbb\x45\xc6\x8e"
   3.455 ++    "\xad\x58\x23\xcb\xbe\xbb\x13\x2d\x6b\x86\xc5\x57\xf5\xdd\x48"
   3.456 ++    "\xc1\x3d\xcd\x4d\xda\x81\xc4\x43\x17\xaa\x05\x40\x33\x62\x0a"
   3.457 ++    "\x59\xdb\x28\xcd\xb5\x08\x31\xbb\x06\xf5\xf7\x71\xae\x21\xa8"
   3.458 ++    "\xf2\x2f\x0e\x17\x80\x5d\x9c\xdf\xaa\xe9\x89\x09\x54\x65\x2b"
   3.459 ++    "\x46\xfb\x9d\xb2\x00\x70\x63\x0d\x9a\x6d\x3d\x5e\x11\x78\x65"
   3.460 ++    "\x90\xe6\x26\xee\x77\xbe\x08\xff\x07\x60\x5a\xcc\xf1\x0a\xbd"
   3.461 ++    "\x44\x92\x6b\xca\xb6\xce\x66\xf9\x93\x40\xae\xf3\x3e\x53\x02"
   3.462 ++    "\x3c\xa6\x81\xb3\xbe\xad\x6e\x6c\xa6\xf0\xeb\xdf\xe9\xa2\x83"
   3.463 ++    "\x36\x0e\x52\x0d\x64\x17\xd9\xff\xa1\x74\x7c\x2b\xbc\x6a\xcc"
   3.464 ++    "\xe5\x4e\xb4\x52\xd9\xec\x43\xbd\x26\x6a\x2b\x19\x19\x6e\x97"
   3.465 ++    "\xb8\x1d\x9f\x7b\xe7\x32\x2d\xdd\x7c\x51\xc8\xe4\xf3\x02\xd4"
   3.466 ++    "\x7c\x90\x44\xa0\x33\x72\x81\x75\xa9\x16\x27\x5c\x00\x1d\x07"
   3.467 ++    "\x81\xd4\xf7\xac\xcb\xfe\xd6\x60\x03\x6f\x7a\xcc\x00\xd1\xc4"
   3.468 ++    "\x85\x37";
   3.469 ++  uint8_t ek_e[] = "\x01\x00\x01";
   3.470 ++  uint8_t ek_p[] = "\xd7\xea\x61\x15\x8b\xa3\x71\xdf\xa8\x74\x77\xca\x88\x95"
   3.471 ++    "\xd0\x76\x17\x43\x2c\xf6\x23\x27\x44\xb9\x0e\x18\x35\x7e\xe4"
   3.472 ++    "\xc3\xcb\x13\x6e\xfc\x38\x02\x1e\x77\x26\x40\x9d\x17\xb2\x39"
   3.473 ++    "\x9c\x7f\x5f\x98\xe6\xf2\x55\x0c\x12\x05\x4c\xb3\x51\xae\x29"
   3.474 ++    "\xe7\xcd\xce\x41\x0b\x28\x4d\x97\x13\x4b\x60\xc8\xd8\x70\x81"
   3.475 ++    "\xf9\x1c\x12\x44\xdf\x53\x0a\x87\x9d\x33\x92\x4a\x34\x69\xf0"
   3.476 ++    "\x70\x5e\x1b\x5d\x65\xc7\x84\x90\xa2\x62\xdf\x83\x14\x10\x69"
   3.477 ++    "\xe2\xa7\x18\x43\xd7\x1f\x60\xc9\x03\x8f\xd6\xa4\xce\xb2\x9d"
   3.478 ++    "\x40\x37\x70\x17\x4c\xe3\x69\xd4\x59";
   3.479 ++  uint8_t ek_q[] = "\xc8\x34\xd2\xd0\x7c\xfa\xdc\x68\xe2\x72\xd7\x92\xe2\x50"
   3.480 ++    "\x93\xfc\xbb\x72\x55\x4d\x6b\x7a\x0c\x0b\xcf\x87\x66\x1f\x81"
   3.481 ++    "\x71\xf3\x50\xcb\xaa\xe6\x43\x7e\xbe\x11\xc4\xec\x00\x53\xf4"
   3.482 ++    "\x78\x13\x2b\x59\x26\x4a\x9f\x91\x61\x8f\xa7\x07\x64\x11\x5a"
   3.483 ++    "\xf4\xaf\x9c\x9b\x5a\x5d\x69\x20\x17\x55\x74\xba\xd8\xe4\x59"
   3.484 ++    "\x39\x1a\x0a\x7b\x4a\x30\xf0\xc8\x7f\xd9\xaf\x72\xc5\xb6\x71"
   3.485 ++    "\xd1\xc0\x8b\x5b\xa2\x2e\xa7\x15\xca\x50\x75\x10\x48\x9c\x2b"
   3.486 ++    "\x18\xb9\x67\x8f\x5d\x64\xc3\x28\x9f\x2f\x16\x2f\x08\xda\x47"
   3.487 ++    "\xec\x86\x43\x0c\x80\x99\x07\x34\x0f";
   3.488 ++  int i;
   3.489 ++  /* reset all data to NULL, FALSE or 0 */
   3.490 ++  memset(&tpmData, 0, sizeof(tpmData));
   3.491 ++  tpmData.permanent.data.tag = TPM_TAG_PERMANENT_DATA;
   3.492 ++  /* set permanent flags */
   3.493 ++  tpmData.permanent.flags.tag = TPM_TAG_PERMANENT_FLAGS;
   3.494 ++  tpmData.permanent.flags.disable = FALSE;
   3.495 ++  tpmData.permanent.flags.deactivated = FALSE;
   3.496 ++  tpmData.permanent.flags.ownership = TRUE;
   3.497 ++  tpmData.permanent.flags.readPubek = TRUE;
   3.498 ++  tpmData.permanent.flags.allowMaintenance = TRUE;
   3.499 ++  tpmData.permanent.flags.enableRevokeEK = TRUE;
   3.500 ++  /* set TPM vision */
   3.501 ++  tpmData.permanent.data.version.major = 1;
   3.502 ++  tpmData.permanent.data.version.minor = 2;
   3.503 ++  tpmData.permanent.data.version.revMajor = VERSION_MAJOR;
   3.504 ++  tpmData.permanent.data.version.revMinor = VERSION_MINOR;
   3.505 ++  /* setup PCR attributes */
   3.506 ++  for (i = 0; i < min(16, TPM_NUM_PCR); i++) {
   3.507 ++    init_pcr_attr(i, FALSE, 0x00, 0x1f);
   3.508 ++  }
   3.509 ++  if (TPM_NUM_PCR >= 24) {
   3.510 ++    init_pcr_attr(16, TRUE, 0x1f, 0x1f);
   3.511 ++    init_pcr_attr(17, TRUE, 0x10, 0x1c);
   3.512 ++    init_pcr_attr(18, TRUE, 0x10, 0x1c);
   3.513 ++    init_pcr_attr(19, TRUE, 0x10, 0x0c);
   3.514 ++    init_pcr_attr(20, TRUE, 0x14, 0x0e);
   3.515 ++    init_pcr_attr(21, TRUE, 0x04, 0x04);
   3.516 ++    init_pcr_attr(22, TRUE, 0x04, 0x04);
   3.517 ++    init_pcr_attr(23, TRUE, 0x1f, 0x1f);
   3.518 ++  }
   3.519 ++  for (i = 24; i < TPM_NUM_PCR; i++) {
   3.520 ++    init_pcr_attr(i, TRUE, 0x00, 0x00);
   3.521 ++  }
   3.522 ++  /* set tick type */
   3.523 ++  tpmData.permanent.data.tickType = TICK_INC;
   3.524 ++#ifdef TPM_GENERATE_EK
   3.525 ++  /* generate a new endorsement key */
   3.526 ++  rsa_generate_key(&tpmData.permanent.data.endorsementKey, 2048);
   3.527 ++#else
   3.528 ++  /* setup endorsement key */
   3.529 ++  rsa_import_key(&tpmData.permanent.data.endorsementKey, 
   3.530 ++    RSA_MSB_FIRST, ek_n, 256, ek_e, 3, ek_p, ek_q);
   3.531 ++#endif
   3.532 ++#ifdef TPM_GENERATE_SEED_DAA
   3.533 ++  /* generate the DAA seed (cf. [TPM_Part2], v1.2 rev 85, Section 7.4) */
   3.534 ++  tpm_get_random_bytes(tpmData.permanent.data.tpmDAASeed.digest, 
   3.535 ++    sizeof(tpmData.permanent.data.tpmDAASeed.digest));
   3.536 ++#else
   3.537 ++  /* FIXME: setup DAA seed */
   3.538 ++  memcpy(tpmData.permanent.data.tpmDAASeed.digest, 
   3.539 ++    "\x77\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
   3.540 ++    "\x00\x00\x00\x77", 20);
   3.541 ++#endif
   3.542 ++
   3.543 ++  memcpy(tpmData.permanent.data.ekReset.nonce, "\xde\xad\xbe\xef", 4);
   3.544 ++}
   3.545 ++
   3.546 ++void tpm_release_data(void)
   3.547 ++{
   3.548 ++  int i;
   3.549 ++  /* release the EK, SRK as well as all other rsa keys */
   3.550 ++  if (tpmData.permanent.data.endorsementKey.size > 0)
   3.551 ++    rsa_release_private_key(&tpmData.permanent.data.endorsementKey);
   3.552 ++  if (tpmData.permanent.data.srk.valid)
   3.553 ++    rsa_release_private_key(&tpmData.permanent.data.srk.key);
   3.554 ++  for (i = 0; i < TPM_MAX_KEYS; i++)
   3.555 ++    if (tpmData.permanent.data.keys[i].valid)
   3.556 ++      rsa_release_private_key(&tpmData.permanent.data.keys[i].key);
   3.557 ++}
   3.558 ++
   3.559 ++#ifdef TPM_STORE_TO_FILE
   3.560 ++
   3.561 ++#include <linux/fs.h>
   3.562 ++#include <linux/unistd.h>
   3.563 ++#include <asm/uaccess.h>
   3.564 ++
   3.565 ++#define TPM_STORAGE_FILE "/var/tpm/tpm_emulator-1.2." STR(VERSION_MAJOR) "." STR(VERSION_MINOR) 
   3.566 ++
   3.567 ++static int write_to_file(uint8_t *data, size_t data_length)
   3.568 ++{
   3.569 ++  int res;
   3.570 ++  struct file *fp;
   3.571 ++  mm_segment_t old_fs = get_fs();
   3.572 ++  fp = filp_open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
   3.573 ++  if (IS_ERR(fp)) return -1;
   3.574 ++  set_fs(get_ds());
   3.575 ++  res = fp->f_op->write(fp, data, data_length, &fp->f_pos);
   3.576 ++  set_fs(old_fs);
   3.577 ++  filp_close(fp, NULL);
   3.578 ++  return (res == data_length) ? 0 : -1;
   3.579 ++}
   3.580 ++
   3.581 ++static int read_from_file(uint8_t **data, size_t *data_length)
   3.582 ++{
   3.583 ++  int res;
   3.584 ++  struct file *fp;
   3.585 ++  mm_segment_t old_fs = get_fs();
   3.586 ++  fp = filp_open(TPM_STORAGE_FILE, O_RDONLY, 0);
   3.587 ++  if (IS_ERR(fp)) return -1;
   3.588 ++  *data_length = (size_t)fp->f_dentry->d_inode->i_size;
   3.589 ++  /* *data_length = i_size_read(fp->f_dentry->d_inode); */
   3.590 ++  *data = tpm_malloc(*data_length);
   3.591 ++  if (*data == NULL) {
   3.592 ++    filp_close(fp, NULL);
   3.593 ++    return -1;
   3.594 ++  }
   3.595 ++  set_fs(get_ds());
   3.596 ++  res = fp->f_op->read(fp, *data, *data_length, &fp->f_pos);
   3.597 ++  set_fs(old_fs);
   3.598 ++  filp_close(fp, NULL);
   3.599 ++  if (res != *data_length) {
   3.600 ++    tpm_free(*data);
   3.601 ++    return -1;
   3.602 ++  }
   3.603 ++  return 0;
   3.604 ++}
   3.605 ++
   3.606 ++#else
   3.607 ++
   3.608 ++static int write_to_file(uint8_t *data, size_t data_length)
   3.609 ++{
   3.610 ++  info("TPM_STORE_TO_FILE disabled, no data written");
   3.611 ++  return 0;
   3.612 ++}
   3.613 ++
   3.614 ++static int read_from_file(uint8_t **data, size_t *data_length)
   3.615 ++{
   3.616 ++  info("TPM_STORE_TO_FILE disabled, no data read");
   3.617 ++  return 0;
   3.618 ++}
   3.619 ++
   3.620 ++#endif /* TPM_STORE_TO_FILE */
   3.621 ++
   3.622 ++int tpm_store_permanent_data(void)
   3.623 ++{
   3.624 ++  uint8_t *buf, *ptr;
   3.625 ++  UINT32 buf_length, len;
   3.626 ++
   3.627 ++  /* marshal data */
   3.628 ++  buf_length = len = 4 + sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
   3.629 ++    + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) 
   3.630 ++    + sizeof_TPM_STANY_FLAGS(tpmData.stany.flags) + 2
   3.631 ++    + sizeof_TPM_STCLEAR_DATA(tpmData.stclear.data) 
   3.632 ++    + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data)
   3.633 ++    + sizeof_TPM_STANY_DATA(tpmData.stany.data);
   3.634 ++  buf = ptr = tpm_malloc(buf_length);
   3.635 ++  if (buf == NULL
   3.636 ++      || tpm_marshal_TPM_VERSION(&ptr, &len, &tpmData.permanent.data.version)
   3.637 ++      || tpm_marshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags)
   3.638 ++      || tpm_marshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags)
   3.639 ++      || tpm_marshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags)
   3.640 ++      || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.selfTestSucceeded)
   3.641 ++      || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.owned)
   3.642 ++      || tpm_marshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data)
   3.643 ++      || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)
   3.644 ++      || tpm_marshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) {
   3.645 ++    tpm_free(buf);
   3.646 ++    return -1;
   3.647 ++  }
   3.648 ++
   3.649 ++  if (write_to_file(buf, buf_length - len)) {
   3.650 ++    tpm_free(buf);
   3.651 ++    return -1; 
   3.652 ++  }
   3.653 ++  tpm_free(buf);
   3.654 ++  return 0;
   3.655 ++}
   3.656 ++
   3.657 ++int tpm_restore_permanent_data(void)
   3.658 ++{
   3.659 ++  uint8_t *buf, *ptr;
   3.660 ++  size_t buf_length;
   3.661 ++  UINT32 len;
   3.662 ++  TPM_VERSION ver;
   3.663 ++
   3.664 ++  /* read data */
   3.665 ++  if (read_from_file(&buf, &buf_length)) return -1;
   3.666 ++  ptr = buf;
   3.667 ++  len = (uint32_t) buf_length;
   3.668 ++  /* unmarshal data */
   3.669 ++  if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
   3.670 ++      || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
   3.671 ++      || tpm_unmarshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags)
   3.672 ++      || tpm_unmarshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags)
   3.673 ++      || tpm_unmarshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags)
   3.674 ++      || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.selfTestSucceeded)
   3.675 ++      || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.owned)
   3.676 ++      || tpm_unmarshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data)
   3.677 ++      || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)
   3.678 ++      || tpm_unmarshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) {
   3.679 ++    tpm_free(buf);
   3.680 ++    return -1;
   3.681 ++  }
   3.682 ++
   3.683 ++  tpm_free(buf);
   3.684 ++  return 0;
   3.685 ++}
   3.686 ++
   3.687 ++int tpm_erase_permanent_data(void)
   3.688 ++{
   3.689 ++  int res = write_to_file("", 0);
   3.690 ++  return res;
   3.691 ++}
   3.692 ++
   3.693 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c tpm_emulator/tpm/tpm_deprecated.c
   3.694 +--- tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c	2006-08-29 15:07:21.622298456 -0700
   3.695 ++++ tpm_emulator/tpm/tpm_deprecated.c	2006-08-29 15:26:17.122676160 -0700
   3.696  @@ -1,6 +1,7 @@
   3.697   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.698    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.699 @@ -976,9 +1265,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.700                           authContextSize, &contextBlob);
   3.701     if (res != TPM_SUCCESS) return res;
   3.702     len = *authContextSize;
   3.703 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h tpm_emulator/tpm/tpm_emulator.h
   3.704 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h	2006-01-10 04:21:45.000000000 -0800
   3.705 -+++ tpm_emulator/tpm/tpm_emulator.h	2006-06-02 13:36:03.000000000 -0700
   3.706 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h tpm_emulator/tpm/tpm_emulator.h
   3.707 +--- tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h	2006-08-29 15:07:21.648294504 -0700
   3.708 ++++ tpm_emulator/tpm/tpm_emulator.h	2006-08-29 15:26:17.122676160 -0700
   3.709  @@ -1,5 +1,6 @@
   3.710   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.711    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.712 @@ -996,9 +1285,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.713   #undef  TPM_GENERATE_SEED_DAA
   3.714   
   3.715   #define TPM_MANUFACTURER 0x4554485A /* 'ETHZ' */        
   3.716 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c tpm_emulator/tpm/tpm_integrity.c
   3.717 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c	2006-01-10 04:21:45.000000000 -0800
   3.718 -+++ tpm_emulator/tpm/tpm_integrity.c	2006-06-02 13:36:03.000000000 -0700
   3.719 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c tpm_emulator/tpm/tpm_integrity.c
   3.720 +--- tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c	2006-08-29 15:07:21.645294960 -0700
   3.721 ++++ tpm_emulator/tpm/tpm_integrity.c	2006-08-29 15:26:17.123676008 -0700
   3.722  @@ -1,6 +1,7 @@
   3.723   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.724    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.725 @@ -1012,9 +1301,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.726     return TPM_SUCCESS;
   3.727   }
   3.728  -
   3.729 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_structures.h tpm_emulator/tpm/tpm_structures.h
   3.730 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_structures.h	2006-01-10 04:21:45.000000000 -0800
   3.731 -+++ tpm_emulator/tpm/tpm_structures.h	2006-06-02 13:36:03.000000000 -0700
   3.732 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_structures.h tpm_emulator/tpm/tpm_structures.h
   3.733 +--- tpm_emulator-0.3-x86_64/tpm/tpm_structures.h	2006-08-29 15:08:20.545340792 -0700
   3.734 ++++ tpm_emulator/tpm/tpm_structures.h	2006-08-29 15:26:17.125675704 -0700
   3.735  @@ -1,6 +1,7 @@
   3.736   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.737    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.738 @@ -1032,9 +1321,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.739   #include "crypto/rsa.h"
   3.740   
   3.741   /*
   3.742 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_testing.c tpm_emulator/tpm/tpm_testing.c
   3.743 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_testing.c	2006-01-10 04:21:45.000000000 -0800
   3.744 -+++ tpm_emulator/tpm/tpm_testing.c	2006-06-02 13:36:03.000000000 -0700
   3.745 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_testing.c tpm_emulator/tpm/tpm_testing.c
   3.746 +--- tpm_emulator-0.3-x86_64/tpm/tpm_testing.c	2006-08-29 15:07:21.646294808 -0700
   3.747 ++++ tpm_emulator/tpm/tpm_testing.c	2006-08-29 15:26:17.127675400 -0700
   3.748  @@ -1,6 +1,7 @@
   3.749   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.750    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.751 @@ -1150,9 +1439,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.752     rsa_private_key_t priv_key;
   3.753     rsa_public_key_t pub_key;
   3.754   
   3.755 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c tpm_emulator/tpm/tpm_ticks.c
   3.756 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c	2006-01-10 04:21:45.000000000 -0800
   3.757 -+++ tpm_emulator/tpm/tpm_ticks.c	2006-06-02 13:36:03.000000000 -0700
   3.758 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c tpm_emulator/tpm/tpm_ticks.c
   3.759 +--- tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c	2006-08-29 15:07:21.646294808 -0700
   3.760 ++++ tpm_emulator/tpm/tpm_ticks.c	2006-08-29 15:26:17.128675248 -0700
   3.761  @@ -1,6 +1,7 @@
   3.762   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.763    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   3.764 @@ -1235,9 +1524,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.765   }
   3.766     
   3.767   
   3.768 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_transport.c tpm_emulator/tpm/tpm_transport.c
   3.769 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_transport.c	2006-01-10 04:21:45.000000000 -0800
   3.770 -+++ tpm_emulator/tpm/tpm_transport.c	2006-06-02 13:36:03.000000000 -0700
   3.771 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_transport.c tpm_emulator/tpm/tpm_transport.c
   3.772 +--- tpm_emulator-0.3-x86_64/tpm/tpm_transport.c	2006-08-29 15:07:21.647294656 -0700
   3.773 ++++ tpm_emulator/tpm/tpm_transport.c	2006-08-29 15:26:17.129675096 -0700
   3.774  @@ -59,7 +59,7 @@ static int decrypt_transport_auth(TPM_KE
   3.775   static void transport_log_in(TPM_COMMAND_CODE ordinal, BYTE parameters[20],
   3.776                                BYTE pubKeyHash[20], TPM_DIGEST *transDigest)
   3.777 @@ -1295,9 +1584,19 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.778     memcpy(&buf[30], session->transInternal.transDigest.digest, 20);
   3.779     /* sign info structure */ 
   3.780     res = tpm_sign(key, auth1, TRUE, buf, sizeof(buf), signature, signSize);
   3.781 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpmd.c tpm_emulator/tpmd.c
   3.782 ---- orig/tpm_emulator-0.3-x86_64/tpmd.c	1969-12-31 16:00:00.000000000 -0800
   3.783 -+++ tpm_emulator/tpmd.c	2006-06-02 13:36:03.000000000 -0700
   3.784 +diff -uprN tpm_emulator-0.3-x86_64/tpm_version.h tpm_emulator/tpm_version.h
   3.785 +--- tpm_emulator-0.3-x86_64/tpm_version.h	2006-08-29 15:07:21.649294352 -0700
   3.786 ++++ tpm_emulator/tpm_version.h	1969-12-31 16:00:00.000000000 -0800
   3.787 +@@ -1,6 +0,0 @@
   3.788 +-#ifndef _TPM_VERSION_H_
   3.789 +-#define _TPM_VERSION_H_
   3.790 +-#define VERSION_MAJOR 0
   3.791 +-#define VERSION_MINOR 3
   3.792 +-#define VERSION_BUILD 1136893683
   3.793 +-#endif /* _TPM_VERSION_H_ */
   3.794 +diff -uprN tpm_emulator-0.3-x86_64/tpmd.c tpm_emulator/tpmd.c
   3.795 +--- tpm_emulator-0.3-x86_64/tpmd.c	1969-12-31 16:00:00.000000000 -0800
   3.796 ++++ tpm_emulator/tpmd.c	2006-08-29 15:26:17.130674944 -0700
   3.797  @@ -0,0 +1,141 @@
   3.798  +/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   3.799  + * Copyright (C) 2005 INTEL Corp
   3.800 @@ -1440,13 +1739,3 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   3.801  +  close(tpm_rx_fh);
   3.802  +
   3.803  +}
   3.804 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm_version.h tpm_emulator/tpm_version.h
   3.805 ---- orig/tpm_emulator-0.3-x86_64/tpm_version.h	2006-01-10 04:21:45.000000000 -0800
   3.806 -+++ tpm_emulator/tpm_version.h	1969-12-31 16:00:00.000000000 -0800
   3.807 -@@ -1,6 +0,0 @@
   3.808 --#ifndef _TPM_VERSION_H_
   3.809 --#define _TPM_VERSION_H_
   3.810 --#define VERSION_MAJOR 0
   3.811 --#define VERSION_MINOR 3
   3.812 --#define VERSION_BUILD 1136893683
   3.813 --#endif /* _TPM_VERSION_H_ */
     4.1 --- a/tools/vtpm/vtpm.patch	Tue Jun 27 11:13:24 2006 +0100
     4.2 +++ b/tools/vtpm/vtpm.patch	Tue Jun 27 11:14:19 2006 +0100
     4.3 @@ -1,13 +1,13 @@
     4.4 -diff -uprN orig/tpm_emulator-0.3-x86_64/AUTHORS vtpm/AUTHORS
     4.5 ---- orig/tpm_emulator-0.3-x86_64/AUTHORS	2006-01-10 04:21:45.000000000 -0800
     4.6 -+++ vtpm/AUTHORS	2006-05-30 12:23:26.000000000 -0700
     4.7 +diff -uprN tpm_emulator-0.3-x86_64/AUTHORS vtpm/AUTHORS
     4.8 +--- tpm_emulator-0.3-x86_64/AUTHORS	2006-08-29 15:07:21.618299064 -0700
     4.9 ++++ vtpm/AUTHORS	2006-08-29 15:12:07.184886344 -0700
    4.10  @@ -1,2 +1,3 @@
    4.11   Mario Strasser <mast@gmx.net>
    4.12   Heiko Stamer <stamer@gaos.org> [DAA]
    4.13  +INTEL Corp <> [VTPM Extensions]
    4.14 -diff -uprN orig/tpm_emulator-0.3-x86_64/ChangeLog vtpm/ChangeLog
    4.15 ---- orig/tpm_emulator-0.3-x86_64/ChangeLog	2006-01-10 04:21:45.000000000 -0800
    4.16 -+++ vtpm/ChangeLog	2006-05-30 12:23:26.000000000 -0700
    4.17 +diff -uprN tpm_emulator-0.3-x86_64/ChangeLog vtpm/ChangeLog
    4.18 +--- tpm_emulator-0.3-x86_64/ChangeLog	2006-08-29 15:07:21.618299064 -0700
    4.19 ++++ vtpm/ChangeLog	2006-08-29 15:12:07.185886192 -0700
    4.20  @@ -1,3 +1,7 @@
    4.21  +2005-08-16 Intel Corp
    4.22  +	* Moved module out of kernel to run as a ring 3 app
    4.23 @@ -16,9 +16,117 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
    4.24   2005-12-24  Mario Strasser <mast@gmx.net>
    4.25   	* tpm_transport.c, tpm_marshalling.c, tpm_structures.h:
    4.26   		Transport session functionality added
    4.27 -diff -uprN orig/tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c vtpm/crypto/gmp_kernel_wrapper.c
    4.28 ---- orig/tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c	2006-05-30 12:28:02.000000000 -0700
    4.29 -+++ vtpm/crypto/gmp_kernel_wrapper.c	2006-05-30 12:23:26.000000000 -0700
    4.30 +diff -uprN tpm_emulator-0.3-x86_64/Makefile vtpm/Makefile
    4.31 +--- tpm_emulator-0.3-x86_64/Makefile	2006-08-29 15:08:20.532342768 -0700
    4.32 ++++ vtpm/Makefile	2006-08-29 15:13:53.023796384 -0700
    4.33 +@@ -1,22 +1,31 @@
    4.34 + # Software-Based Trusted Platform Module (TPM) Emulator for Linux
    4.35 + # Copyright (C) 2004 Mario Strasser <mast@gmx.net>
    4.36 ++# Copyright (C) 2006 INTEL Corp.
    4.37 + #
    4.38 + # $Id: Makefile 69 2005-12-13 12:55:52Z mast $
    4.39 + 
    4.40 +-# kernel settings
    4.41 +-KERNEL_RELEASE := $(shell uname -r)
    4.42 +-KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
    4.43 +-MOD_SUBDIR     := misc
    4.44 + COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
    4.45 + 
    4.46 + # module settings
    4.47 +-MODULE_NAME    := tpm_emulator
    4.48 ++BIN            := vtpmd
    4.49 + VERSION_MAJOR  := 0
    4.50 + VERSION_MINOR  := 3
    4.51 + VERSION_BUILD  := $(shell date +"%s")
    4.52 + 
    4.53 +-# enable/disable DEBUG messages
    4.54 +-EXTRA_CFLAGS   += -Wall -DDEBUG -g  
    4.55 ++# Installation program and options
    4.56 ++INSTALL         = install
    4.57 ++INSTALL_PROG    = $(INSTALL) -m0755
    4.58 ++INSTALL_DIR     = $(INSTALL) -d -m0755
    4.59 ++
    4.60 ++# Xen tools installation directory
    4.61 ++TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
    4.62 ++
    4.63 ++CC      := gcc
    4.64 ++CFLAGS  += -g -Wall $(INCLUDE) -DDEBUG
    4.65 ++CFLAGS  += -I. -Itpm -I../../vtpm_manager/manager
    4.66 ++
    4.67 ++# Is the simulator running in it's own vm?
    4.68 ++#CFLAGS += -DVTPM_MULTI_VM
    4.69 + 
    4.70 + ifeq ($(COMPILE_ARCH),x86_64)
    4.71 + LIBDIR = lib64
    4.72 +@@ -34,38 +43,31 @@ DIRS           := . crypto tpm 
    4.73 + SRCS           := $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.c))
    4.74 + OBJS           := $(patsubst %.c, %.o, $(SRCS))
    4.75 + SRCS           += $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.h))
    4.76 +-DISTSRC        := ./README ./AUTHORS ./ChangeLog ./Makefile $(SRCS)
    4.77 +-DISTDIR        := tpm_emulator-$(VERSION_MAJOR).$(VERSION_MINOR)
    4.78 + 
    4.79 +-obj-m               := $(MODULE_NAME).o
    4.80 +-$(MODULE_NAME)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
    4.81 ++obj-m               := $(BIN)
    4.82 ++$(BIN)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
    4.83 + 
    4.84 + EXTRA_CFLAGS   += -I$(src) -I$(src)/crypto -I$(src)/tpm 
    4.85 + 
    4.86 + # do not print "Entering directory ..."
    4.87 + MAKEFLAGS      += --no-print-directory
    4.88 + 
    4.89 +-all:	$(src)/crypto/gmp.h $(src)/crypto/libgmp.a version
    4.90 +-	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules
    4.91 ++all: $(BIN)
    4.92 ++
    4.93 ++$(BIN):	$(src)/crypto/gmp.h $(src)/crypto/libgmp.a version $(SRCS) $(OBJS)
    4.94 ++	$(CC) $(CFLAGS) $(OBJS) $(src)/crypto/libgmp.a -o $(BIN)
    4.95 ++
    4.96 ++%.o: %.c
    4.97 ++	$(CC) $(CFLAGS) -c $< -o $@
    4.98 + 
    4.99 +-install:
   4.100 +-	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules_install
   4.101 +-	test -d /var/tpm || mkdir /var/tpm
   4.102 +-	test -c /dev/tpm || mknod /dev/tpm c 10 224
   4.103 +-	chmod 666 /dev/tpm
   4.104 +-	depmod -a
   4.105 ++install: $(BIN)
   4.106 ++	$(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
   4.107 + 
   4.108 + clean:
   4.109 +-	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) clean
   4.110 +-	rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a
   4.111 ++	rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS)
   4.112 + 
   4.113 +-dist:	$(DISTSRC)
   4.114 +-	rm -rf $(DISTDIR)
   4.115 +-	mkdir $(DISTDIR)
   4.116 +-	cp --parents $(DISTSRC) $(DISTDIR)/
   4.117 +-	rm -f $(DISTDIR)/crypto/gmp.h 
   4.118 +-	tar -chzf $(DISTDIR).tar.gz $(DISTDIR)
   4.119 +-	rm -rf $(DISTDIR)
   4.120 ++mrproper: clean
   4.121 ++	rm -f $(BIN) tpm_version.h
   4.122 + 
   4.123 + $(src)/crypto/libgmp.a:
   4.124 + 	test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a
   4.125 +diff -uprN tpm_emulator-0.3-x86_64/README vtpm/README
   4.126 +--- tpm_emulator-0.3-x86_64/README	2006-08-29 15:07:43.530967832 -0700
   4.127 ++++ vtpm/README	2006-08-29 15:12:07.190885432 -0700
   4.128 +@@ -13,7 +13,8 @@ $Id: README 78 2006-01-07 10:45:39Z mast
   4.129 + Copyright
   4.130 + --------------------------------------------------------------------------
   4.131 + Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal 
   4.132 +-Institute of Technology (ETH) Zurich.
   4.133 ++                   Institute of Technology (ETH) Zurich.
   4.134 ++Copyright (C) 2005 INTEL Corp 
   4.135 +               
   4.136 + This program is free software; you can redistribute it and/or modify
   4.137 + it under the terms of the GNU General Public License as published by
   4.138 +diff -uprN tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c vtpm/crypto/gmp_kernel_wrapper.c
   4.139 +--- tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c	2006-08-29 15:07:43.525968592 -0700
   4.140 ++++ vtpm/crypto/gmp_kernel_wrapper.c	2006-08-29 15:12:07.186886040 -0700
   4.141  @@ -1,5 +1,6 @@
   4.142   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.143    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.144 @@ -78,9 +186,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.145     }
   4.146   }
   4.147   
   4.148 -diff -uprN orig/tpm_emulator-0.3-x86_64/crypto/rsa.c vtpm/crypto/rsa.c
   4.149 ---- orig/tpm_emulator-0.3-x86_64/crypto/rsa.c	2006-01-10 04:21:45.000000000 -0800
   4.150 -+++ vtpm/crypto/rsa.c	2006-05-30 12:23:26.000000000 -0700
   4.151 +diff -uprN tpm_emulator-0.3-x86_64/crypto/rsa.c vtpm/crypto/rsa.c
   4.152 +--- tpm_emulator-0.3-x86_64/crypto/rsa.c	2006-08-29 15:07:21.618299064 -0700
   4.153 ++++ vtpm/crypto/rsa.c	2006-08-29 15:12:07.187885888 -0700
   4.154  @@ -1,5 +1,6 @@
   4.155   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.156    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.157 @@ -106,8 +214,8 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.158         sha1_final(&ctx, &msg[1]);
   4.159         if (memcmp(&msg[1], &msg[1 + SHA1_DIGEST_LENGTH], 
   4.160             SHA1_DIGEST_LENGTH) != 0) return -1;
   4.161 -diff -uprN orig/tpm_emulator-0.3-x86_64/linux_module.c vtpm/linux_module.c
   4.162 ---- orig/tpm_emulator-0.3-x86_64/linux_module.c	2006-05-30 12:28:02.000000000 -0700
   4.163 +diff -uprN tpm_emulator-0.3-x86_64/linux_module.c vtpm/linux_module.c
   4.164 +--- tpm_emulator-0.3-x86_64/linux_module.c	2006-08-29 15:07:43.526968440 -0700
   4.165  +++ vtpm/linux_module.c	1969-12-31 16:00:00.000000000 -0800
   4.166  @@ -1,194 +0,0 @@
   4.167  -/* Software-Based Trusted Platform Module (TPM) Emulator for Linux 
   4.168 @@ -304,9 +412,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.169  -  return (ticks > 0) ? ticks : 1;
   4.170  -}
   4.171  -
   4.172 -diff -uprN orig/tpm_emulator-0.3-x86_64/linux_module.h vtpm/linux_module.h
   4.173 ---- orig/tpm_emulator-0.3-x86_64/linux_module.h	2006-05-30 12:28:02.000000000 -0700
   4.174 -+++ vtpm/linux_module.h	2006-05-30 12:23:26.000000000 -0700
   4.175 +diff -uprN tpm_emulator-0.3-x86_64/linux_module.h vtpm/linux_module.h
   4.176 +--- tpm_emulator-0.3-x86_64/linux_module.h	2006-08-29 15:07:43.527968288 -0700
   4.177 ++++ vtpm/linux_module.h	2006-08-29 15:12:07.189885584 -0700
   4.178  @@ -1,5 +1,6 @@
   4.179   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.180    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.181 @@ -406,116 +514,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.182   #define BE16_TO_CPU(x) __be16_to_cpu(x)
   4.183   #define LE16_TO_CPU(x) __le16_to_cpu(x)
   4.184   
   4.185 -diff -uprN orig/tpm_emulator-0.3-x86_64/Makefile vtpm/Makefile
   4.186 ---- orig/tpm_emulator-0.3-x86_64/Makefile	2006-05-30 12:28:02.000000000 -0700
   4.187 -+++ vtpm/Makefile	2006-05-30 12:23:26.000000000 -0700
   4.188 -@@ -1,22 +1,31 @@
   4.189 - # Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.190 - # Copyright (C) 2004 Mario Strasser <mast@gmx.net>
   4.191 -+# Copyright (C) 2006 INTEL Corp.
   4.192 - #
   4.193 - # $Id: Makefile 69 2005-12-13 12:55:52Z mast $
   4.194 - 
   4.195 --# kernel settings
   4.196 --KERNEL_RELEASE := $(shell uname -r)
   4.197 --KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
   4.198 --MOD_SUBDIR     := misc
   4.199 - COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
   4.200 - 
   4.201 - # module settings
   4.202 --MODULE_NAME    := tpm_emulator
   4.203 -+BIN            := vtpmd
   4.204 - VERSION_MAJOR  := 0
   4.205 - VERSION_MINOR  := 3
   4.206 - VERSION_BUILD  := $(shell date +"%s")
   4.207 - 
   4.208 --# enable/disable DEBUG messages
   4.209 --EXTRA_CFLAGS   += -Wall -DDEBUG -g  
   4.210 -+# Installation program and options
   4.211 -+INSTALL         = install
   4.212 -+INSTALL_PROG    = $(INSTALL) -m0755
   4.213 -+INSTALL_DIR     = $(INSTALL) -d -m0755
   4.214 -+
   4.215 -+# Xen tools installation directory
   4.216 -+TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
   4.217 -+
   4.218 -+CC      := gcc
   4.219 -+CFLAGS  += -g -Wall $(INCLUDE) -DDEBUG
   4.220 -+CFLAGS  += -I. -Itpm -I../../vtpm_manager/manager
   4.221 -+
   4.222 -+# Is the simulator running in it's own vm?
   4.223 -+#CFLAGS += -DVTPM_MULTI_VM
   4.224 - 
   4.225 - ifeq ($(COMPILE_ARCH),x86_64)
   4.226 - LIBDIR = lib64
   4.227 -@@ -34,38 +43,31 @@ DIRS           := . crypto tpm 
   4.228 - SRCS           := $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.c))
   4.229 - OBJS           := $(patsubst %.c, %.o, $(SRCS))
   4.230 - SRCS           += $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.h))
   4.231 --DISTSRC        := ./README ./AUTHORS ./ChangeLog ./Makefile $(SRCS)
   4.232 --DISTDIR        := tpm_emulator-$(VERSION_MAJOR).$(VERSION_MINOR)
   4.233 - 
   4.234 --obj-m               := $(MODULE_NAME).o
   4.235 --$(MODULE_NAME)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
   4.236 -+obj-m               := $(BIN)
   4.237 -+$(BIN)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
   4.238 - 
   4.239 - EXTRA_CFLAGS   += -I$(src) -I$(src)/crypto -I$(src)/tpm 
   4.240 - 
   4.241 - # do not print "Entering directory ..."
   4.242 - MAKEFLAGS      += --no-print-directory
   4.243 - 
   4.244 --all:	$(src)/crypto/gmp.h $(src)/crypto/libgmp.a version
   4.245 --	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules
   4.246 -+all: $(BIN)
   4.247 -+
   4.248 -+$(BIN):	$(src)/crypto/gmp.h $(src)/crypto/libgmp.a version $(SRCS) $(OBJS)
   4.249 -+	$(CC) $(CFLAGS) $(OBJS) $(src)/crypto/libgmp.a -o $(BIN)
   4.250 -+
   4.251 -+%.o: %.c
   4.252 -+	$(CC) $(CFLAGS) -c $< -o $@
   4.253 - 
   4.254 - install:
   4.255 --	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules_install
   4.256 --	test -d /var/tpm || mkdir /var/tpm
   4.257 --	test -c /dev/tpm || mknod /dev/tpm c 10 224
   4.258 --	chmod 666 /dev/tpm
   4.259 --	depmod -a
   4.260 -+	$(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
   4.261 - 
   4.262 - clean:
   4.263 --	@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) clean
   4.264 --	rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a
   4.265 -+	rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS)
   4.266 - 
   4.267 --dist:	$(DISTSRC)
   4.268 --	rm -rf $(DISTDIR)
   4.269 --	mkdir $(DISTDIR)
   4.270 --	cp --parents $(DISTSRC) $(DISTDIR)/
   4.271 --	rm -f $(DISTDIR)/crypto/gmp.h 
   4.272 --	tar -chzf $(DISTDIR).tar.gz $(DISTDIR)
   4.273 --	rm -rf $(DISTDIR)
   4.274 -+mrproper: clean
   4.275 -+	rm -f $(BIN) tpm_version.h
   4.276 - 
   4.277 - $(src)/crypto/libgmp.a:
   4.278 - 	test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a
   4.279 -diff -uprN orig/tpm_emulator-0.3-x86_64/README vtpm/README
   4.280 ---- orig/tpm_emulator-0.3-x86_64/README	2006-05-30 12:28:02.000000000 -0700
   4.281 -+++ vtpm/README	2006-05-30 12:23:26.000000000 -0700
   4.282 -@@ -13,7 +13,8 @@ $Id: README 78 2006-01-07 10:45:39Z mast
   4.283 - Copyright
   4.284 - --------------------------------------------------------------------------
   4.285 - Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal 
   4.286 --Institute of Technology (ETH) Zurich.
   4.287 -+                   Institute of Technology (ETH) Zurich.
   4.288 -+Copyright (C) 2005 INTEL Corp 
   4.289 -               
   4.290 - This program is free software; you can redistribute it and/or modify
   4.291 - it under the terms of the GNU General Public License as published by
   4.292 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_audit.c vtpm/tpm/tpm_audit.c
   4.293 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_audit.c	2006-01-10 04:21:45.000000000 -0800
   4.294 -+++ vtpm/tpm/tpm_audit.c	2006-05-30 12:23:26.000000000 -0700
   4.295 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_audit.c vtpm/tpm/tpm_audit.c
   4.296 +--- tpm_emulator-0.3-x86_64/tpm/tpm_audit.c	2006-08-29 15:07:21.620298760 -0700
   4.297 ++++ vtpm/tpm/tpm_audit.c	2006-08-29 15:12:07.191885280 -0700
   4.298  @@ -1,6 +1,7 @@
   4.299   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.300    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.301 @@ -578,9 +579,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.302     return TPM_SUCCESS;
   4.303   }
   4.304  -
   4.305 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c vtpm/tpm/tpm_authorization.c
   4.306 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c	2006-01-10 04:21:45.000000000 -0800
   4.307 -+++ vtpm/tpm/tpm_authorization.c	2006-05-30 12:23:26.000000000 -0700
   4.308 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c vtpm/tpm/tpm_authorization.c
   4.309 +--- tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c	2006-08-29 15:07:21.620298760 -0700
   4.310 ++++ vtpm/tpm/tpm_authorization.c	2006-08-29 15:12:07.192885128 -0700
   4.311  @@ -1,6 +1,7 @@
   4.312   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.313    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.314 @@ -598,9 +599,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.315     
   4.316     info("tpm_verify_auth(%08x)", auth->authHandle);
   4.317     /* get dedicated authorization or transport session */
   4.318 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_capability.c vtpm/tpm/tpm_capability.c
   4.319 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_capability.c	2006-01-10 04:21:45.000000000 -0800
   4.320 -+++ vtpm/tpm/tpm_capability.c	2006-05-30 12:23:26.000000000 -0700
   4.321 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_capability.c vtpm/tpm/tpm_capability.c
   4.322 +--- tpm_emulator-0.3-x86_64/tpm/tpm_capability.c	2006-08-29 15:07:21.620298760 -0700
   4.323 ++++ vtpm/tpm/tpm_capability.c	2006-08-29 15:12:07.193884976 -0700
   4.324  @@ -1,6 +1,7 @@
   4.325   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.326    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.327 @@ -623,9 +624,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.328     }
   4.329   }
   4.330  -
   4.331 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c vtpm/tpm/tpm_cmd_handler.c
   4.332 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c	2006-01-10 04:21:45.000000000 -0800
   4.333 -+++ vtpm/tpm/tpm_cmd_handler.c	2006-05-30 12:23:26.000000000 -0700
   4.334 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c vtpm/tpm/tpm_cmd_handler.c
   4.335 +--- tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c	2006-08-29 15:07:21.621298608 -0700
   4.336 ++++ vtpm/tpm/tpm_cmd_handler.c	2006-08-29 15:12:07.197884368 -0700
   4.337  @@ -1,6 +1,7 @@
   4.338   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.339    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.340 @@ -683,9 +684,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.341     /* setup authorisation as well as response tag and size */
   4.342     memset(rsp, 0, sizeof(*rsp));
   4.343     switch (req->tag) {
   4.344 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c vtpm/tpm/tpm_crypto.c
   4.345 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c	2006-05-30 12:28:02.000000000 -0700
   4.346 -+++ vtpm/tpm/tpm_crypto.c	2006-05-30 12:23:26.000000000 -0700
   4.347 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c vtpm/tpm/tpm_crypto.c
   4.348 +--- tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c	2006-08-29 15:07:43.531967680 -0700
   4.349 ++++ vtpm/tpm/tpm_crypto.c	2006-08-29 15:12:07.198884216 -0700
   4.350  @@ -1,6 +1,7 @@
   4.351   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.352    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.353 @@ -708,9 +709,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.354     return TPM_SUCCESS;
   4.355   }
   4.356  -
   4.357 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_daa.c vtpm/tpm/tpm_daa.c
   4.358 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_daa.c	2006-01-10 04:21:45.000000000 -0800
   4.359 -+++ vtpm/tpm/tpm_daa.c	2006-05-30 12:23:26.000000000 -0700
   4.360 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_daa.c vtpm/tpm/tpm_daa.c
   4.361 +--- tpm_emulator-0.3-x86_64/tpm/tpm_daa.c	2006-08-29 15:07:21.622298456 -0700
   4.362 ++++ vtpm/tpm/tpm_daa.c	2006-08-29 15:12:07.203883456 -0700
   4.363  @@ -700,14 +700,14 @@ info("tested until here");
   4.364             sizeof(session->DAA_tpmSpecific.DAA_rekey));
   4.365         sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
   4.366 @@ -865,9 +866,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.367         sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
   4.368         mpz_init(f), mpz_init(q);
   4.369         mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
   4.370 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_data.c vtpm/tpm/tpm_data.c
   4.371 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_data.c	2006-05-30 12:28:02.000000000 -0700
   4.372 -+++ vtpm/tpm/tpm_data.c	2006-05-30 12:23:26.000000000 -0700
   4.373 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_data.c vtpm/tpm/tpm_data.c
   4.374 +--- tpm_emulator-0.3-x86_64/tpm/tpm_data.c	2006-08-29 15:08:20.535342312 -0700
   4.375 ++++ vtpm/tpm/tpm_data.c	2006-08-29 15:12:07.206883000 -0700
   4.376  @@ -1,6 +1,7 @@
   4.377   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.378    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.379 @@ -1177,7 +1178,7 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.380   }
   4.381   
   4.382   #else
   4.383 -@@ -267,7 +462,6 @@ int tpm_restore_permanent_data(void)
   4.384 +@@ -278,7 +473,6 @@ int tpm_restore_permanent_data(void)
   4.385   
   4.386   int tpm_erase_permanent_data(void)
   4.387   {
   4.388 @@ -1186,9 +1187,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.389     return res;
   4.390   }
   4.391  -
   4.392 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c vtpm/tpm/tpm_deprecated.c
   4.393 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c	2006-01-10 04:21:45.000000000 -0800
   4.394 -+++ vtpm/tpm/tpm_deprecated.c	2006-05-30 12:23:26.000000000 -0700
   4.395 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c vtpm/tpm/tpm_deprecated.c
   4.396 +--- tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c	2006-08-29 15:07:21.622298456 -0700
   4.397 ++++ vtpm/tpm/tpm_deprecated.c	2006-08-29 15:12:07.207882848 -0700
   4.398  @@ -1,6 +1,7 @@
   4.399   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.400    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.401 @@ -1215,9 +1216,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.402                           authContextSize, &contextBlob);
   4.403     if (res != TPM_SUCCESS) return res;
   4.404     len = *authContextSize;
   4.405 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h vtpm/tpm/tpm_emulator.h
   4.406 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h	2006-01-10 04:21:45.000000000 -0800
   4.407 -+++ vtpm/tpm/tpm_emulator.h	2006-05-30 12:23:26.000000000 -0700
   4.408 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h vtpm/tpm/tpm_emulator.h
   4.409 +--- tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h	2006-08-29 15:07:21.648294504 -0700
   4.410 ++++ vtpm/tpm/tpm_emulator.h	2006-08-29 15:12:07.208882696 -0700
   4.411  @@ -1,5 +1,6 @@
   4.412   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.413    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.414 @@ -1235,9 +1236,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.415   #undef  TPM_GENERATE_SEED_DAA
   4.416   
   4.417   #define TPM_MANUFACTURER 0x4554485A /* 'ETHZ' */        
   4.418 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c vtpm/tpm/tpm_integrity.c
   4.419 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c	2006-01-10 04:21:45.000000000 -0800
   4.420 -+++ vtpm/tpm/tpm_integrity.c	2006-05-30 12:23:26.000000000 -0700
   4.421 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c vtpm/tpm/tpm_integrity.c
   4.422 +--- tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c	2006-08-29 15:07:21.645294960 -0700
   4.423 ++++ vtpm/tpm/tpm_integrity.c	2006-08-29 15:12:07.208882696 -0700
   4.424  @@ -1,6 +1,7 @@
   4.425   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.426    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.427 @@ -1251,9 +1252,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.428     return TPM_SUCCESS;
   4.429   }
   4.430  -
   4.431 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_structures.h vtpm/tpm/tpm_structures.h
   4.432 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_structures.h	2006-01-10 04:21:45.000000000 -0800
   4.433 -+++ vtpm/tpm/tpm_structures.h	2006-05-30 12:23:26.000000000 -0700
   4.434 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_structures.h vtpm/tpm/tpm_structures.h
   4.435 +--- tpm_emulator-0.3-x86_64/tpm/tpm_structures.h	2006-08-29 15:08:20.545340792 -0700
   4.436 ++++ vtpm/tpm/tpm_structures.h	2006-08-29 15:12:07.211882240 -0700
   4.437  @@ -1,6 +1,7 @@
   4.438   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.439    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.440 @@ -1271,9 +1272,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.441   #include "crypto/rsa.h"
   4.442   
   4.443   /*
   4.444 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_testing.c vtpm/tpm/tpm_testing.c
   4.445 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_testing.c	2006-01-10 04:21:45.000000000 -0800
   4.446 -+++ vtpm/tpm/tpm_testing.c	2006-05-30 12:23:26.000000000 -0700
   4.447 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_testing.c vtpm/tpm/tpm_testing.c
   4.448 +--- tpm_emulator-0.3-x86_64/tpm/tpm_testing.c	2006-08-29 15:07:21.646294808 -0700
   4.449 ++++ vtpm/tpm/tpm_testing.c	2006-08-29 15:12:07.213881936 -0700
   4.450  @@ -1,6 +1,7 @@
   4.451   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.452    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.453 @@ -1389,9 +1390,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.454     rsa_private_key_t priv_key;
   4.455     rsa_public_key_t pub_key;
   4.456   
   4.457 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c vtpm/tpm/tpm_ticks.c
   4.458 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c	2006-01-10 04:21:45.000000000 -0800
   4.459 -+++ vtpm/tpm/tpm_ticks.c	2006-05-30 12:23:26.000000000 -0700
   4.460 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c vtpm/tpm/tpm_ticks.c
   4.461 +--- tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c	2006-08-29 15:07:21.646294808 -0700
   4.462 ++++ vtpm/tpm/tpm_ticks.c	2006-08-29 15:12:07.235878592 -0700
   4.463  @@ -1,6 +1,7 @@
   4.464   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.465    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   4.466 @@ -1474,9 +1475,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.467   }
   4.468     
   4.469   
   4.470 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_transport.c vtpm/tpm/tpm_transport.c
   4.471 ---- orig/tpm_emulator-0.3-x86_64/tpm/tpm_transport.c	2006-01-10 04:21:45.000000000 -0800
   4.472 -+++ vtpm/tpm/tpm_transport.c	2006-05-30 12:23:26.000000000 -0700
   4.473 +diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_transport.c vtpm/tpm/tpm_transport.c
   4.474 +--- tpm_emulator-0.3-x86_64/tpm/tpm_transport.c	2006-08-29 15:07:21.647294656 -0700
   4.475 ++++ vtpm/tpm/tpm_transport.c	2006-08-29 15:12:07.239877984 -0700
   4.476  @@ -59,7 +59,7 @@ static int decrypt_transport_auth(TPM_KE
   4.477   static void transport_log_in(TPM_COMMAND_CODE ordinal, BYTE parameters[20],
   4.478                                BYTE pubKeyHash[20], TPM_DIGEST *transDigest)
   4.479 @@ -1534,9 +1535,9 @@ diff -uprN orig/tpm_emulator-0.3-x86_64/
   4.480     memcpy(&buf[30], session->transInternal.transDigest.digest, 20);
   4.481     /* sign info structure */ 
   4.482     res = tpm_sign(key, auth1, TRUE, buf, sizeof(buf), signature, signSize);
   4.483 -diff -uprN orig/tpm_emulator-0.3-x86_64/tpmd.c vtpm/tpmd.c
   4.484 ---- orig/tpm_emulator-0.3-x86_64/tpmd.c	1969-12-31 16:00:00.000000000 -0800
   4.485 -+++ vtpm/tpmd.c	2006-05-30 12:23:26.000000000 -0700
   4.486 +diff -uprN tpm_emulator-0.3-x86_64/tpmd.c vtpm/tpmd.c
   4.487 +--- tpm_emulator-0.3-x86_64/tpmd.c	1969-12-31 16:00:00.000000000 -0800
   4.488 ++++ vtpm/tpmd.c	2006-08-29 15:12:07.240877832 -0700
   4.489  @@ -0,0 +1,207 @@
   4.490  +/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   4.491  + * Copyright (C) 2005 INTEL Corp