ia64/xen-unstable
changeset 10774:6b08035e10c5
VTPM_TOOLS: Updated vtpm for new release of tpm_emulator 0.4, and set
up easier tracking of the emulator. Also fixed a few minor bugs in the
manager.
Signed-off-by: Vincent Scarlata <vincent.r.scarlata@intel.com>
up easier tracking of the emulator. Also fixed a few minor bugs in the
manager.
Signed-off-by: Vincent Scarlata <vincent.r.scarlata@intel.com>
author | kfraser@localhost.localdomain |
---|---|
date | Tue Jul 25 11:30:30 2006 +0100 (2006-07-25) |
parents | 7d6f0791c650 |
children | f07effe5097b |
files | tools/vtpm/Makefile tools/vtpm/tpm_emulator-0.3-x86_64.patch tools/vtpm/tpm_emulator.patch tools/vtpm/vtpm.patch tools/vtpm_manager/manager/dmictl.c tools/vtpm_manager/manager/vtpm_manager_handler.c tools/vtpm_manager/manager/vtpmd.c tools/vtpm_manager/tcs/tcs.c tools/vtpm_manager/tcs/transmit.c |
line diff
1.1 --- a/tools/vtpm/Makefile Tue Jul 25 11:19:48 2006 +0100 1.2 +++ b/tools/vtpm/Makefile Tue Jul 25 11:30:30 2006 +0100 1.3 @@ -7,9 +7,11 @@ include $(XEN_ROOT)/tools/vtpm/Rules.mk 1.4 TPM_EMULATOR_DIR = tpm_emulator 1.5 # Dir name for vtpm instance 1.6 VTPM_DIR = vtpm 1.7 +ORIG_DIR = orig 1.8 1.9 # Emulator tarball name 1.10 -TPM_EMULATOR_TARFILE = tpm_emulator-0.3.tar.gz 1.11 +TPM_EMULATOR_NAME = tpm_emulator-0.4 1.12 +TPM_EMULATOR_TARFILE = $(TPM_EMULATOR_NAME).tar.gz 1.13 1.14 GMP_HEADER = /usr/include/gmp.h 1.15 1.16 @@ -17,7 +19,7 @@ GMP_HEADER = /usr/include/gmp.h 1.17 all: build 1.18 1.19 .PHONY: build 1.20 -build: $(TPM_EMULATOR_DIR) $(VTPM_DIR) build_sub 1.21 +build: $(VTPM_DIR) $(TPM_EMULATOR_DIR) build_sub 1.22 1.23 .PHONY: install 1.24 install: build 1.25 @@ -37,9 +39,8 @@ clean: 1.26 1.27 .PHONY: mrproper 1.28 mrproper: 1.29 - rm -f $(TPM_EMULATOR_TARFILE) 1.30 - rm -rf $(TPM_EMULATOR_DIR) 1.31 - rm -rf $(VTPM_DIR) 1.32 + rm -f $(TPM_EMULATOR_TARFILE) tpm_emulator.patch.old vtpm.patch.old 1.33 + rm -rf $(TPM_EMULATOR_DIR) $(VTPM_DIR) $(ORIG_DIR) 1.34 1.35 # Download Swiss emulator 1.36 $(TPM_EMULATOR_TARFILE): 1.37 @@ -47,24 +48,38 @@ mrproper: 1.38 1.39 # Create vtpm and TPM emulator dirs 1.40 # apply patches for 1) used as dom0 tpm driver 2) used as vtpm device instance 1.41 -$(TPM_EMULATOR_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator.patch tpm_emulator-0.3-x86_64.patch 1.42 +$(TPM_EMULATOR_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator.patch 1.43 if [ "$(BUILD_EMULATOR)" = "y" ]; then \ 1.44 - tar -xzf $(TPM_EMULATOR_TARFILE); \ 1.45 rm -rf $(TPM_EMULATOR_DIR); \ 1.46 - mv tpm_emulator-0.3 $(TPM_EMULATOR_DIR); \ 1.47 + tar -xzf $(TPM_EMULATOR_TARFILE); \ 1.48 + mv $(TPM_EMULATOR_NAME) $(TPM_EMULATOR_DIR); \ 1.49 cd $(TPM_EMULATOR_DIR); \ 1.50 - patch -p1 < ../tpm_emulator-0.3-x86_64.patch; \ 1.51 patch -p1 <../tpm_emulator.patch; \ 1.52 fi 1.53 1.54 -$(VTPM_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator-0.3-x86_64.patch vtpm.patch 1.55 +$(VTPM_DIR): $(TPM_EMULATOR_TARFILE) vtpm.patch 1.56 + rm -rf $(VTPM_DIR) 1.57 tar -xzf $(TPM_EMULATOR_TARFILE); 1.58 - rm -rf $(VTPM_DIR) 1.59 - mv tpm_emulator-0.3 $(VTPM_DIR); 1.60 + mv $(TPM_EMULATOR_NAME) $(VTPM_DIR); 1.61 1.62 cd $(VTPM_DIR); \ 1.63 - patch -p1 < ../tpm_emulator-0.3-x86_64.patch; \ 1.64 - patch -p1 <../vtpm.patch 1.65 + patch -p1 < ../tpm_emulator.patch; \ 1.66 + patch -p1 < ../vtpm.patch 1.67 + 1.68 +orig: $(TPM_EMULATOR_TARFILE) 1.69 + mkdir $(ORIG_DIR); 1.70 + cd $(ORIG_DIR); \ 1.71 + tar -xzf ../$(TPM_EMULATOR_TARFILE); 1.72 + 1.73 +updatepatches: clean orig 1.74 + if [ "$(BUILD_EMULATOR)" = "y" ]; then \ 1.75 + find $(TPM_EMULATOR_DIR) -name "*.orig" -print | xargs rm -f; \ 1.76 + mv tpm_emulator.patch tpm_emulator.patch.old; \ 1.77 + diff -uprN orig/$(TPM_EMULATOR_NAME) $(TPM_EMULATOR_DIR) > tpm_emulator.patch || true; \ 1.78 + fi; 1.79 + find $(VTPM_DIR) -name "*.orig" -print | xargs rm -f; 1.80 + mv vtpm.patch vtpm.patch.old; 1.81 + diff -uprN $(TPM_EMULATOR_DIR) $(VTPM_DIR) > vtpm.patch || true; 1.82 1.83 .PHONY: build_sub 1.84 build_sub:
2.1 --- a/tools/vtpm/tpm_emulator-0.3-x86_64.patch Tue Jul 25 11:19:48 2006 +0100 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,737 +0,0 @@ 2.4 -diff -uprN orig/tpm_emulator-0.3/Makefile tpm_emulator-0.3-x86_64/Makefile 2.5 ---- orig/tpm_emulator-0.3/Makefile 2006-01-10 04:21:45.000000000 -0800 2.6 -+++ tpm_emulator-0.3-x86_64/Makefile 2006-08-29 15:08:20.532342768 -0700 2.7 -@@ -7,6 +7,7 @@ 2.8 - KERNEL_RELEASE := $(shell uname -r) 2.9 - KERNEL_BUILD := /lib/modules/$(KERNEL_RELEASE)/build 2.10 - MOD_SUBDIR := misc 2.11 -+COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/) 2.12 - 2.13 - # module settings 2.14 - MODULE_NAME := tpm_emulator 2.15 -@@ -17,8 +18,14 @@ VERSION_BUILD := $(shell date +"%s") 2.16 - # enable/disable DEBUG messages 2.17 - EXTRA_CFLAGS += -Wall -DDEBUG -g 2.18 - 2.19 -+ifeq ($(COMPILE_ARCH),x86_64) 2.20 -+LIBDIR = lib64 2.21 -+else 2.22 -+LIBDIR = lib 2.23 -+endif 2.24 -+ 2.25 - # GNU MP configuration 2.26 --GMP_LIB := /usr/lib/libgmp.a 2.27 -+GMP_LIB := /usr/$(LIBDIR)/libgmp.a 2.28 - GMP_HEADER := /usr/include/gmp.h 2.29 - 2.30 - # sources and objects 2.31 -diff -uprN orig/tpm_emulator-0.3/README tpm_emulator-0.3-x86_64/README 2.32 ---- orig/tpm_emulator-0.3/README 2006-01-10 04:21:45.000000000 -0800 2.33 -+++ tpm_emulator-0.3-x86_64/README 2006-08-29 15:07:43.530967832 -0700 2.34 -@@ -43,6 +43,12 @@ Example: 2.35 - GMP_LIB := /usr/lib/libgmp.a 2.36 - GMP_HEADER := /usr/include/gmp.h 2.37 - 2.38 -+GNU MP Library on 64 bit Systems 2.39 -+-------------------------------------------------------------------------- 2.40 -+Some 64-bit kernels have problems with importing the user-space gmp 2.41 -+library (/usr/lib*/libgmp.a) into kernel space. These kernels will require 2.42 -+that the gmp library be recompiled for kernel space with -mcmodel=kernel. 2.43 -+ 2.44 - Installation 2.45 - -------------------------------------------------------------------------- 2.46 - The compilation and installation process uses the build environment for 2.47 -diff -uprN orig/tpm_emulator-0.3/crypto/gmp_kernel_wrapper.c tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c 2.48 ---- orig/tpm_emulator-0.3/crypto/gmp_kernel_wrapper.c 2006-01-10 04:21:45.000000000 -0800 2.49 -+++ tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c 2006-08-29 15:07:43.525968592 -0700 2.50 -@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne 2.51 - { 2.52 - void *ret = (void*)kmalloc(size, GFP_KERNEL); 2.53 - if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 2.54 -- "GMP: cannot allocate memory (size=%u)\n", size); 2.55 -+ "GMP: cannot allocate memory (size=%Zu)\n", size); 2.56 - return ret; 2.57 - } 2.58 - 2.59 -@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne 2.60 - { 2.61 - void *ret = (void*)kmalloc(new_size, GFP_KERNEL); 2.62 - if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory " 2.63 -- "(old_size=%u new_size=%u)\n", old_size, new_size); 2.64 -+ "(old_size=%Zu new_size=%Zu)\n", old_size, new_size); 2.65 - memcpy(ret, oldptr, old_size); 2.66 - kfree(oldptr); 2.67 - return ret; 2.68 -diff -uprN orig/tpm_emulator-0.3/linux_module.c tpm_emulator-0.3-x86_64/linux_module.c 2.69 ---- orig/tpm_emulator-0.3/linux_module.c 2006-01-10 04:21:45.000000000 -0800 2.70 -+++ tpm_emulator-0.3-x86_64/linux_module.c 2006-08-29 15:07:43.526968440 -0700 2.71 -@@ -72,7 +72,7 @@ static int tpm_release(struct inode *ino 2.72 - 2.73 - static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos) 2.74 - { 2.75 -- debug("%s(%d)", __FUNCTION__, count); 2.76 -+ debug("%s(%Zu)", __FUNCTION__, count); 2.77 - down(&tpm_mutex); 2.78 - if (tpm_response.data != NULL) { 2.79 - count = min(count, (size_t)tpm_response.size - (size_t)*ppos); 2.80 -@@ -91,7 +91,7 @@ static ssize_t tpm_read(struct file *fil 2.81 - 2.82 - static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos) 2.83 - { 2.84 -- debug("%s(%d)", __FUNCTION__, count); 2.85 -+ debug("%s(%Zu)", __FUNCTION__, count); 2.86 - down(&tpm_mutex); 2.87 - *ppos = 0; 2.88 - if (tpm_response.data != NULL) kfree(tpm_response.data); 2.89 -diff -uprN orig/tpm_emulator-0.3/linux_module.h tpm_emulator-0.3-x86_64/linux_module.h 2.90 ---- orig/tpm_emulator-0.3/linux_module.h 2006-01-10 04:21:45.000000000 -0800 2.91 -+++ tpm_emulator-0.3-x86_64/linux_module.h 2006-08-29 15:07:43.527968288 -0700 2.92 -@@ -28,8 +28,10 @@ 2.93 - 2.94 - /* module settings */ 2.95 - 2.96 -+#ifndef STR 2.97 - #define STR(s) __STR__(s) 2.98 - #define __STR__(s) #s 2.99 -+#endif 2.100 - #include "tpm_version.h" 2.101 - 2.102 - #define TPM_DEVICE_MINOR 224 2.103 -diff -uprN orig/tpm_emulator-0.3/tpm/tpm_credentials.c tpm_emulator-0.3-x86_64/tpm/tpm_credentials.c 2.104 ---- orig/tpm_emulator-0.3/tpm/tpm_credentials.c 2006-01-10 04:21:45.000000000 -0800 2.105 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_credentials.c 2006-08-29 15:07:43.530967832 -0700 2.106 -@@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC 2.107 - 2.108 - TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey) 2.109 - { 2.110 -- UINT32 key_length; 2.111 -+ size_t key_length; 2.112 - if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT; 2.113 - /* setup TPM_PUBKEY structure */ 2.114 -- key_length = tpmData.permanent.data.endorsementKey.size; 2.115 -- pubEndorsementKey->pubKey.keyLength = key_length >> 3; 2.116 -+ pubEndorsementKey->pubKey.keyLength = tpmData.permanent.data.endorsementKey.size >> 3; 2.117 - pubEndorsementKey->pubKey.key = tpm_malloc(pubEndorsementKey->pubKey.keyLength); 2.118 - if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL; 2.119 - rsa_export_modulus(&tpmData.permanent.data.endorsementKey, 2.120 -- pubEndorsementKey->pubKey.key, 2.121 -- &pubEndorsementKey->pubKey.keyLength); 2.122 -+ pubEndorsementKey->pubKey.key, 2.123 -+ &key_length); 2.124 -+ pubEndorsementKey->pubKey.keyLength = key_length; 2.125 - pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA; 2.126 - pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1; 2.127 - pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE; 2.128 -@@ -175,6 +175,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_ 2.129 - { 2.130 - TPM_RESULT res; 2.131 - TPM_KEY_DATA *srk = &tpmData.permanent.data.srk; 2.132 -+ size_t key_length; 2.133 - info("TPM_OwnerReadInternalPub()"); 2.134 - /* verify authorization */ 2.135 - res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER); 2.136 -@@ -186,7 +187,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_ 2.137 - publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength); 2.138 - if (publicPortion->pubKey.key == NULL) return TPM_FAIL; 2.139 - rsa_export_modulus(&srk->key, publicPortion->pubKey.key, 2.140 -- &publicPortion->pubKey.keyLength); 2.141 -+ &key_length); 2.142 -+ publicPortion->pubKey.keyLength = key_length; 2.143 - publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA; 2.144 - publicPortion->algorithmParms.encScheme = srk->encScheme; 2.145 - publicPortion->algorithmParms.sigScheme = srk->sigScheme; 2.146 -diff -uprN orig/tpm_emulator-0.3/tpm/tpm_crypto.c tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c 2.147 ---- orig/tpm_emulator-0.3/tpm/tpm_crypto.c 2006-01-10 04:21:45.000000000 -0800 2.148 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c 2006-08-29 15:07:43.531967680 -0700 2.149 -@@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE 2.150 - TPM_KEY_DATA *cert, *key; 2.151 - sha1_ctx_t sha1_ctx; 2.152 - BYTE *buf, *p; 2.153 -- UINT32 length; 2.154 -+ UINT32 length32; 2.155 -+ size_t length; 2.156 - info("TPM_CertifyKey()"); 2.157 - /* get keys */ 2.158 - cert = tpm_get_key(certHandle); 2.159 -@@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE 2.160 - /* compute the digest of the CERTIFY_INFO[2] structure and sign it */ 2.161 - length = sizeof_TPM_CERTIFY_INFO((*certifyInfo)); 2.162 - p = buf = tpm_malloc(length); 2.163 -+ length32=(UINT32) length; 2.164 - if (buf == NULL 2.165 -- || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) { 2.166 -+ || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) { 2.167 - free_TPM_KEY_PARMS(certifyInfo->algorithmParms); 2.168 - return TPM_FAIL; 2.169 - } 2.170 - length = sizeof_TPM_CERTIFY_INFO((*certifyInfo)); 2.171 - sha1_init(&sha1_ctx); 2.172 -- sha1_update(&sha1_ctx, buf, length); 2.173 -+ sha1_update(&sha1_ctx, buf, (size_t) length); 2.174 - sha1_final(&sha1_ctx, buf); 2.175 - res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSize); 2.176 - tpm_free(buf); 2.177 -@@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL 2.178 - TPM_KEY_DATA *cert, *key; 2.179 - sha1_ctx_t sha1_ctx; 2.180 - BYTE *buf, *p; 2.181 -- UINT32 length; 2.182 -+ size_t length; 2.183 -+ UINT32 length32; 2.184 - info("TPM_CertifyKey2()"); 2.185 - /* get keys */ 2.186 - cert = tpm_get_key(certHandle); 2.187 -@@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL 2.188 - /* compute the digest of the CERTIFY_INFO[2] structure and sign it */ 2.189 - length = sizeof_TPM_CERTIFY_INFO((*certifyInfo)); 2.190 - p = buf = tpm_malloc(length); 2.191 -+ length32 = (UINT32) length; 2.192 - if (buf == NULL 2.193 -- || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) { 2.194 -+ || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) { 2.195 - free_TPM_KEY_PARMS(certifyInfo->algorithmParms); 2.196 - return TPM_FAIL; 2.197 - } 2.198 -diff -uprN orig/tpm_emulator-0.3/tpm/tpm_data.c tpm_emulator-0.3-x86_64/tpm/tpm_data.c 2.199 ---- orig/tpm_emulator-0.3/tpm/tpm_data.c 2006-01-10 04:21:45.000000000 -0800 2.200 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_data.c 2006-08-29 15:08:20.535342312 -0700 2.201 -@@ -214,23 +214,30 @@ static int read_from_file(uint8_t **data 2.202 - int tpm_store_permanent_data(void) 2.203 - { 2.204 - uint8_t *buf, *ptr; 2.205 -- size_t buf_length, len; 2.206 -+ UINT32 buf_length, len; 2.207 - 2.208 - /* marshal data */ 2.209 -- buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags) 2.210 -- + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) + 2 2.211 -- + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data); 2.212 -+ buf_length = len = 4 + sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags) 2.213 -+ + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) 2.214 -+ + sizeof_TPM_STANY_FLAGS(tpmData.stany.flags) + 2 2.215 -+ + sizeof_TPM_STCLEAR_DATA(tpmData.stclear.data) 2.216 -+ + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data) 2.217 -+ + sizeof_TPM_STANY_DATA(tpmData.stany.data); 2.218 - buf = ptr = tpm_malloc(buf_length); 2.219 - if (buf == NULL 2.220 - || tpm_marshal_TPM_VERSION(&ptr, &len, &tpmData.permanent.data.version) 2.221 - || tpm_marshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags) 2.222 - || tpm_marshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags) 2.223 -+ || tpm_marshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags) 2.224 - || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.selfTestSucceeded) 2.225 - || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.owned) 2.226 -- || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) { 2.227 -+ || tpm_marshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data) 2.228 -+ || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data) 2.229 -+ || tpm_marshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) { 2.230 - tpm_free(buf); 2.231 - return -1; 2.232 - } 2.233 -+ 2.234 - if (write_to_file(buf, buf_length - len)) { 2.235 - tpm_free(buf); 2.236 - return -1; 2.237 -@@ -242,24 +249,29 @@ int tpm_store_permanent_data(void) 2.238 - int tpm_restore_permanent_data(void) 2.239 - { 2.240 - uint8_t *buf, *ptr; 2.241 -- size_t buf_length, len; 2.242 -+ size_t buf_length; 2.243 -+ UINT32 len; 2.244 - TPM_VERSION ver; 2.245 - 2.246 - /* read data */ 2.247 - if (read_from_file(&buf, &buf_length)) return -1; 2.248 - ptr = buf; 2.249 -- len = buf_length; 2.250 -+ len = (uint32_t) buf_length; 2.251 - /* unmarshal data */ 2.252 - if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver) 2.253 - || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION)) 2.254 - || tpm_unmarshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags) 2.255 - || tpm_unmarshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags) 2.256 -+ || tpm_unmarshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags) 2.257 - || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.selfTestSucceeded) 2.258 - || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.owned) 2.259 -- || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) { 2.260 -+ || tpm_unmarshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data) 2.261 -+ || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data) 2.262 -+ || tpm_unmarshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) { 2.263 - tpm_free(buf); 2.264 - return -1; 2.265 - } 2.266 -+ 2.267 - tpm_free(buf); 2.268 - return 0; 2.269 - } 2.270 -diff -uprN orig/tpm_emulator-0.3/tpm/tpm_marshalling.c tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.c 2.271 ---- orig/tpm_emulator-0.3/tpm/tpm_marshalling.c 2006-01-10 04:21:45.000000000 -0800 2.272 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.c 2006-08-29 15:08:20.537342008 -0700 2.273 -@@ -1212,7 +1212,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE * 2.274 - 2.275 - int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v) 2.276 - { 2.277 -- UINT32 m_len, e_len, q_len; 2.278 -+ size_t m_len, e_len, q_len; 2.279 - if (*length < sizeof_RSA((*v))) return -1; 2.280 - if (v->size > 0) { 2.281 - rsa_export_modulus(v, &(*ptr)[6], &m_len); 2.282 -@@ -1356,6 +1356,66 @@ int tpm_unmarshal_TPM_PERMANENT_DATA(BYT 2.283 - return 0; 2.284 - } 2.285 - 2.286 -+int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v) 2.287 -+{ 2.288 -+ if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag) 2.289 -+ || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceKey) 2.290 -+ || tpm_marshal_TPM_COUNT_ID(ptr, length, v->countID) ) return -1; 2.291 -+ 2.292 -+ return 0; 2.293 -+} 2.294 -+ 2.295 -+int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v) 2.296 -+{ 2.297 -+ if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag) 2.298 -+ || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceKey) 2.299 -+ || tpm_unmarshal_TPM_COUNT_ID(ptr, length, &v->countID) ) return -1; 2.300 -+ 2.301 -+ return 0; 2.302 -+} 2.303 -+ 2.304 -+int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v) 2.305 -+{ 2.306 -+ UINT32 i; 2.307 -+ if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag) 2.308 -+ || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceSession) 2.309 -+ || tpm_marshal_TPM_DIGEST(ptr, length, &v->auditDigest) 2.310 -+ || tpm_marshal_BOOL(ptr, length, v->auditSession) 2.311 -+ || tpm_marshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks) 2.312 -+ || tpm_marshal_UINT32(ptr, length, v->contextCount) 2.313 -+ || tpm_marshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1; 2.314 -+ for (i = 0; i < TPM_MAX_SESSIONS; i++) { 2.315 -+ if (tpm_marshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1; 2.316 -+ } 2.317 -+ for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) { 2.318 -+ if (tpm_marshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1; 2.319 -+ } 2.320 -+ if (tpm_marshal_TPM_TRANSHANDLE(ptr, length, v->transExclusive)) return -1; 2.321 -+ 2.322 -+ return 0; 2.323 -+} 2.324 -+ 2.325 -+int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v) 2.326 -+{ 2.327 -+ UINT32 i; 2.328 -+ if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag) 2.329 -+ || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceSession) 2.330 -+ || tpm_unmarshal_TPM_DIGEST(ptr, length, &v->auditDigest) 2.331 -+ || tpm_unmarshal_BOOL(ptr, length, &v->auditSession) 2.332 -+ || tpm_unmarshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks) 2.333 -+ || tpm_unmarshal_UINT32(ptr, length, &v->contextCount) 2.334 -+ || tpm_unmarshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1; 2.335 -+ for (i = 0; i < TPM_MAX_SESSIONS; i++) { 2.336 -+ if (tpm_unmarshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1; 2.337 -+ } 2.338 -+ for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) { 2.339 -+ if (tpm_unmarshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1; 2.340 -+ } 2.341 -+ if (tpm_unmarshal_TPM_TRANSHANDLE(ptr, length, &v->transExclusive)) return -1; 2.342 -+ 2.343 -+ return 0; 2.344 -+} 2.345 -+ 2.346 - int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v) 2.347 - { 2.348 - if (tpm_marshal_BYTE(ptr, length, v->type) 2.349 -diff -uprN orig/tpm_emulator-0.3/tpm/tpm_marshalling.h tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.h 2.350 ---- orig/tpm_emulator-0.3/tpm/tpm_marshalling.h 2006-01-10 04:21:45.000000000 -0800 2.351 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.h 2006-08-29 15:08:20.538341856 -0700 2.352 -@@ -420,6 +420,12 @@ int tpm_unmarshal_TPM_KEY_DATA(BYTE **pt 2.353 - int tpm_marshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *); 2.354 - int tpm_unmarshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *); 2.355 - 2.356 -+int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v); 2.357 -+int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v); 2.358 -+ 2.359 -+int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v); 2.360 -+int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v); 2.361 -+ 2.362 - int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v); 2.363 - int tpm_unmarshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v); 2.364 - 2.365 -diff -uprN orig/tpm_emulator-0.3/tpm/tpm_owner.c tpm_emulator-0.3-x86_64/tpm/tpm_owner.c 2.366 ---- orig/tpm_emulator-0.3/tpm/tpm_owner.c 2006-01-10 04:21:45.000000000 -0800 2.367 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_owner.c 2006-08-29 15:07:43.535967072 -0700 2.368 -@@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO 2.369 - TPM_RESULT res; 2.370 - rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey; 2.371 - TPM_KEY_DATA *srk = &tpmData.permanent.data.srk; 2.372 -- UINT32 buf_size = ek->size >> 3; 2.373 -+ size_t buf_size = ek->size >> 3, key_length; 2.374 - BYTE buf[buf_size]; 2.375 - 2.376 - info("TPM_TakeOwnership()"); 2.377 -@@ -172,7 +172,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO 2.378 - return TPM_FAIL; 2.379 - } 2.380 - rsa_export_modulus(&srk->key, srkPub->pubKey.key, 2.381 -- &srkPub->pubKey.keyLength); 2.382 -+ &key_length); 2.383 -+ srkPub->pubKey.keyLength = (UINT32) key_length; 2.384 - /* setup tpmProof and set state to owned */ 2.385 - tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 2.386 - sizeof(tpmData.permanent.data.tpmProof.nonce)); 2.387 -diff -uprN orig/tpm_emulator-0.3/tpm/tpm_startup.c tpm_emulator-0.3-x86_64/tpm/tpm_startup.c 2.388 ---- orig/tpm_emulator-0.3/tpm/tpm_startup.c 2006-01-10 04:21:45.000000000 -0800 2.389 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_startup.c 2006-08-29 15:08:20.538341856 -0700 2.390 -@@ -41,24 +41,29 @@ void TPM_Init(TPM_STARTUP_TYPE startupTy 2.391 - TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE startupType) 2.392 - { 2.393 - int i; 2.394 -+ int restore_fail; 2.395 - info("TPM_Startup(%d)", startupType); 2.396 - if (tpmData.stany.flags.postInitialise == FALSE) return TPM_INVALID_POSTINIT; 2.397 -- /* reset STANY_FLAGS */ 2.398 -- SET_TO_ZERO(&tpmData.stany.flags); 2.399 -- tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS; 2.400 -- /* reset STANY_DATA (invalidates ALL sessions) */ 2.401 -- SET_TO_ZERO(&tpmData.stany.data); 2.402 -- tpmData.stany.data.tag = TPM_TAG_STANY_DATA; 2.403 -- /* init session-context nonce */ 2.404 -- SET_TO_RAND(&tpmData.stany.data.contextNonceSession); 2.405 -+ 2.406 -+ /* try and restore state to get EK, SRK, etc */ 2.407 -+ restore_fail = tpm_restore_permanent_data(); 2.408 -+ 2.409 - /* set data and flags according to the given startup type */ 2.410 - if (startupType == TPM_ST_CLEAR) { 2.411 -+ /* reset STANY_FLAGS */ 2.412 -+ SET_TO_ZERO(&tpmData.stany.flags); 2.413 -+ tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS; 2.414 -+ /* reset STANY_DATA (invalidates ALL sessions) */ 2.415 -+ SET_TO_ZERO(&tpmData.stany.data); 2.416 -+ tpmData.stany.data.tag = TPM_TAG_STANY_DATA; 2.417 -+ /* init session-context nonce */ 2.418 -+ SET_TO_RAND(&tpmData.stany.data.contextNonceSession); 2.419 - /* reset PCR values */ 2.420 - for (i = 0; i < TPM_NUM_PCR; i++) { 2.421 -- if (tpmData.permanent.data.pcrAttrib[i].pcrReset) 2.422 -- SET_TO_ZERO(tpmData.permanent.data.pcrValue[i].digest); 2.423 -+ if (!tpmData.permanent.data.pcrAttrib[i].pcrReset) 2.424 -+ SET_TO_ZERO(&tpmData.permanent.data.pcrValue[i].digest); 2.425 - else 2.426 -- SET_TO_0xFF(tpmData.permanent.data.pcrValue[i].digest); 2.427 -+ SET_TO_0xFF(&tpmData.permanent.data.pcrValue[i].digest); 2.428 - } 2.429 - /* reset STCLEAR_FLAGS */ 2.430 - SET_TO_ZERO(&tpmData.stclear.flags); 2.431 -@@ -77,7 +82,8 @@ TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE 2.432 - /* init key-context nonce */ 2.433 - SET_TO_RAND(&tpmData.stclear.data.contextNonceKey); 2.434 - } else if (startupType == TPM_ST_STATE) { 2.435 -- if (tpm_restore_permanent_data()) { 2.436 -+ /* restore must have been successful for TPM_ST_STATE */ 2.437 -+ if (restore_fail) { 2.438 - error("restoring permanent data failed"); 2.439 - tpmData.permanent.data.testResult = "tpm_restore_permanent_data() failed"; 2.440 - tpmData.permanent.flags.selfTestSucceeded = FALSE; 2.441 -diff -uprN orig/tpm_emulator-0.3/tpm/tpm_storage.c tpm_emulator-0.3-x86_64/tpm/tpm_storage.c 2.442 ---- orig/tpm_emulator-0.3/tpm/tpm_storage.c 2006-01-10 04:21:45.000000000 -0800 2.443 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_storage.c 2006-08-29 15:07:43.537966768 -0700 2.444 -@@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke 2.445 - BYTE *enc, UINT32 *enc_size) 2.446 - { 2.447 - UINT32 len; 2.448 -+ size_t enc_size32 = *enc_size; 2.449 - BYTE *buf, *ptr; 2.450 - rsa_public_key_t pub_key; 2.451 - int scheme; 2.452 -@@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke 2.453 - if (buf == NULL 2.454 - || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal) 2.455 - || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)), 2.456 -- enc, enc_size)) { 2.457 -+ enc, &enc_size32)) { 2.458 - tpm_free(buf); 2.459 - rsa_release_public_key(&pub_key); 2.460 - return -1; 2.461 -@@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke 2.462 - int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 2.463 - TPM_SEALED_DATA *seal, BYTE **buf) 2.464 - { 2.465 -- UINT32 len; 2.466 -+ size_t len; 2.467 -+ UINT32 len32; 2.468 - BYTE *ptr; 2.469 - int scheme; 2.470 - switch (key->encScheme) { 2.471 -@@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke 2.472 - len = enc_size; 2.473 - *buf = ptr = tpm_malloc(len); 2.474 - if (*buf == NULL 2.475 -- || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) 2.476 -- || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) { 2.477 -+ || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){ 2.478 -+ tpm_free(*buf); 2.479 -+ return -1; 2.480 -+ } 2.481 -+ len32 = len; 2.482 -+ if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) { 2.483 - tpm_free(*buf); 2.484 - return -1; 2.485 - } 2.486 -@@ -237,11 +243,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par 2.487 - 2.488 - TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize, 2.489 - BYTE *inData, TPM_AUTH *auth1, 2.490 -- UINT32 *outDataSize, BYTE **outData) 2.491 -+ UINT32 *outDataSize32, BYTE **outData) 2.492 - { 2.493 - TPM_RESULT res; 2.494 - TPM_KEY_DATA *key; 2.495 - int scheme; 2.496 -+ size_t outDataSize; 2.497 - info("TPM_UnBind()"); 2.498 - /* get key */ 2.499 - key = tpm_get_key(keyHandle); 2.500 -@@ -258,8 +265,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key 2.501 - /* the size of the input data muss be greater than zero */ 2.502 - if (inDataSize == 0) return TPM_BAD_PARAMETER; 2.503 - /* decrypt data */ 2.504 -- *outDataSize = inDataSize; 2.505 -- *outData = tpm_malloc(*outDataSize); 2.506 -+ outDataSize = inDataSize; 2.507 -+ *outData = tpm_malloc(outDataSize); 2.508 - if (*outData == NULL) return TPM_FAIL; 2.509 - switch (key->encScheme) { 2.510 - case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break; 2.511 -@@ -267,20 +274,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key 2.512 - default: tpm_free(*outData); return TPM_DECRYPT_ERROR; 2.513 - } 2.514 - if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 2.515 -- *outData, outDataSize)) { 2.516 -+ *outData, &outDataSize)) { 2.517 - tpm_free(*outData); 2.518 - return TPM_DECRYPT_ERROR; 2.519 - } 2.520 - /* verify data if it is of type TPM_BOUND_DATA */ 2.521 - if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 2.522 - || key->keyUsage != TPM_KEY_LEGACY) { 2.523 -- if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) { 2.524 -+ if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) { 2.525 - tpm_free(*outData); 2.526 - return TPM_DECRYPT_ERROR; 2.527 - } 2.528 -- *outDataSize -= 5; 2.529 -- memmove(*outData, &(*outData)[5], *outDataSize); 2.530 -+ outDataSize -= 5; 2.531 -+ memmove(*outData, &(*outData)[5], outDataSize); 2.532 - } 2.533 -+ *outDataSize32 = (UINT32) outDataSize; 2.534 - return TPM_SUCCESS; 2.535 - } 2.536 - 2.537 -@@ -311,12 +319,13 @@ static int verify_key_digest(TPM_KEY *ke 2.538 - } 2.539 - 2.540 - int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store, 2.541 -- BYTE *enc, UINT32 *enc_size) 2.542 -+ BYTE *enc, UINT32 *enc_size32) 2.543 - { 2.544 - UINT32 len; 2.545 - BYTE *buf, *ptr; 2.546 - rsa_public_key_t pub_key; 2.547 - int scheme; 2.548 -+ size_t enc_size; 2.549 - switch (key->encScheme) { 2.550 - case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break; 2.551 - case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break; 2.552 -@@ -328,11 +337,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke 2.553 - if (buf == NULL 2.554 - || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store) 2.555 - || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)), 2.556 -- enc, enc_size)) { 2.557 -+ enc, &enc_size)) { 2.558 - tpm_free(buf); 2.559 - rsa_release_public_key(&pub_key); 2.560 - return -1; 2.561 - } 2.562 -+ *enc_size32 = (UINT32) enc_size; 2.563 - tpm_free(buf); 2.564 - rsa_release_public_key(&pub_key); 2.565 - return 0; 2.566 -@@ -341,7 +351,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke 2.567 - int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 2.568 - TPM_STORE_ASYMKEY *store, BYTE **buf) 2.569 - { 2.570 -- UINT32 len; 2.571 -+ UINT32 len32; 2.572 -+ size_t len; 2.573 - BYTE *ptr; 2.574 - int scheme; 2.575 - switch (key->encScheme) { 2.576 -@@ -352,8 +363,12 @@ int decrypt_private_key(TPM_KEY_DATA *ke 2.577 - len = enc_size; 2.578 - *buf = ptr = tpm_malloc(len); 2.579 - if (*buf == NULL 2.580 -- || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) 2.581 -- || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) { 2.582 -+ || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) { 2.583 -+ tpm_free(*buf); 2.584 -+ return -1; 2.585 -+ } 2.586 -+ len32 = (UINT32) len; 2.587 -+ if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) { 2.588 - tpm_free(*buf); 2.589 - return -1; 2.590 - } 2.591 -@@ -371,7 +386,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN 2.592 - TPM_SESSION_DATA *session; 2.593 - TPM_STORE_ASYMKEY store; 2.594 - rsa_private_key_t rsa; 2.595 -- UINT32 key_length; 2.596 -+ size_t key_length; 2.597 - 2.598 - info("TPM_CreateWrapKey()"); 2.599 - /* get parent key */ 2.600 -@@ -428,11 +443,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN 2.601 - } 2.602 - if (compute_key_digest(wrappedKey, &store.pubDataDigest)) return TPM_FAIL; 2.603 - /* generate key and store it */ 2.604 -- key_length = keyInfo->algorithmParms.parms.rsa.keyLength; 2.605 -- if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL; 2.606 -- wrappedKey->pubKey.keyLength = key_length >> 3; 2.607 -+ if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 2.608 -+ return TPM_FAIL; 2.609 -+ wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3; 2.610 - wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength); 2.611 -- store.privKey.keyLength = key_length >> 4; 2.612 -+ store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4; 2.613 - store.privKey.key = tpm_malloc(store.privKey.keyLength); 2.614 - wrappedKey->encDataSize = parent->key.size >> 3; 2.615 - wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize); 2.616 -@@ -444,9 +459,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN 2.617 - tpm_free(wrappedKey->encData); 2.618 - return TPM_FAIL; 2.619 - } 2.620 -- rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 2.621 -- &wrappedKey->pubKey.keyLength); 2.622 -- rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength); 2.623 -+ rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 2.624 -+ &key_length); 2.625 -+ wrappedKey->pubKey.keyLength = (UINT32) key_length; 2.626 -+ rsa_export_prime1(&rsa, store.privKey.key, &key_length); 2.627 -+ store.privKey.keyLength = (UINT32) key_length; 2.628 - rsa_release_private_key(&rsa); 2.629 - /* encrypt private key data */ 2.630 - if (encrypt_private_key(parent, &store, wrappedKey->encData, 2.631 -@@ -567,6 +584,7 @@ TPM_RESULT TPM_LoadKey2(TPM_KEY_HANDLE p 2.632 - 2.633 - int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms) 2.634 - { 2.635 -+ size_t key_length; 2.636 - parms->algorithmID = TPM_ALG_RSA; 2.637 - parms->encScheme = key->encScheme; 2.638 - parms->sigScheme = key->sigScheme; 2.639 -@@ -576,7 +594,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke 2.640 - parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize); 2.641 - if (parms->parms.rsa.exponent == NULL) return -1; 2.642 - rsa_export_exponent(&key->key, parms->parms.rsa.exponent, 2.643 -- &parms->parms.rsa.exponentSize); 2.644 -+ &key_length); 2.645 -+ parms->parms.rsa.exponentSize = (UINT32) key_length; 2.646 - parms->parmSize = 12 + parms->parms.rsa.exponentSize; 2.647 - return 0; 2.648 - } 2.649 -@@ -587,6 +606,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 2.650 - TPM_RESULT res; 2.651 - TPM_KEY_DATA *key; 2.652 - TPM_DIGEST digest; 2.653 -+ size_t key_length; 2.654 - info("TPM_GetPubKey()"); 2.655 - /* get key */ 2.656 - if (keyHandle == TPM_KH_SRK) return TPM_BAD_PARAMETER; 2.657 -@@ -614,8 +634,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 2.658 - pubKey->pubKey.keyLength = key->key.size >> 3; 2.659 - pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength); 2.660 - if (pubKey->pubKey.key == NULL) return TPM_FAIL; 2.661 -- rsa_export_modulus(&key->key, pubKey->pubKey.key, 2.662 -- &pubKey->pubKey.keyLength); 2.663 -+ rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 2.664 -+ pubKey->pubKey.keyLength = (UINT32) key_length; 2.665 - if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) { 2.666 - tpm_free(pubKey->pubKey.key); 2.667 - return TPM_FAIL; 2.668 -diff -uprN orig/tpm_emulator-0.3/tpm/tpm_structures.h tpm_emulator-0.3-x86_64/tpm/tpm_structures.h 2.669 ---- orig/tpm_emulator-0.3/tpm/tpm_structures.h 2006-01-10 04:21:45.000000000 -0800 2.670 -+++ tpm_emulator-0.3-x86_64/tpm/tpm_structures.h 2006-08-29 15:08:20.545340792 -0700 2.671 -@@ -1723,6 +1723,7 @@ typedef struct tdTPM_DAA_ISSUER { 2.672 - TPM_DIGEST DAA_digest_gamma; 2.673 - BYTE DAA_generic_q[26]; 2.674 - } TPM_DAA_ISSUER; 2.675 -+#define sizeof_TPM_DAA_ISSUER(s) (2 + (20 * 6) + 26 ) 2.676 - 2.677 - /* 2.678 - * TPM_DAA_TPM ([TPM_Part2], Section 22.8) 2.679 -@@ -1738,6 +1739,7 @@ typedef struct tdTPM_DAA_TPM { 2.680 - TPM_DIGEST DAA_rekey; 2.681 - UINT32 DAA_count; 2.682 - } TPM_DAA_TPM; 2.683 -+#define sizeof_TPM_DAA_TPM(s) (2 + (4 * 20) + 4) 2.684 - 2.685 - /* 2.686 - * TPM_DAA_CONTEXT ([TPM_Part2], Section 22.9) 2.687 -@@ -1752,6 +1754,7 @@ typedef struct tdTPM_DAA_CONTEXT { 2.688 - BYTE DAA_scratch[256]; 2.689 - BYTE DAA_stage; 2.690 - } TPM_DAA_CONTEXT; 2.691 -+#define sizeof_TPM_DAA_CONTEXT(s) (2 + (3 * 20) + 256 + 1) 2.692 - 2.693 - /* 2.694 - * TPM_DAA_JOINDATA ([TPM_Part2], Section 22.10) 2.695 -@@ -1763,6 +1766,7 @@ typedef struct tdTPM_DAA_JOINDATA { 2.696 - BYTE DAA_join_u1[138]; /* WATCH: 138 (v1.2 rev 85) */ 2.697 - TPM_DIGEST DAA_digest_n0; 2.698 - } TPM_DAA_JOINDATA; 2.699 -+#define sizeof_TPM_DAA_JOINDATA(s) (1 + 1 + 20) 2.700 - 2.701 - /* 2.702 - * TPM_DAA_BLOB ([TPM_Part2], Section 22.12) 2.703 -@@ -2033,6 +2037,7 @@ typedef struct tdTPM_STCLEAR_DATA { 2.704 - TPM_COUNT_ID countID; 2.705 - //UINT32 ownerReference; 2.706 - } TPM_STCLEAR_DATA; 2.707 -+#define sizeof_TPM_STCLEAR_DATA(s) (2 + 20 + 4) 2.708 - 2.709 - /* 2.710 - * TPM_SESSION_DATA 2.711 -@@ -2069,6 +2074,11 @@ typedef struct tdTPM_DAA_SESSION_DATA { 2.712 - TPM_DAA_JOINDATA DAA_joinSession; 2.713 - TPM_HANDLE handle; 2.714 - } TPM_DAA_SESSION_DATA; 2.715 -+#define sizeof_TPM_DAA_SESSION_DATA(s) ( 1 \ 2.716 -+ + sizeof_TPM_DAA_ISSUER(s.DAA_issuerSettings) \ 2.717 -+ + sizeof_TPM_DAA_TPM(s.DAA_tpmSpecific) \ 2.718 -+ + sizeof_TPM_DAA_CONTEXT(s.DAA_session) \ 2.719 -+ + sizeof_TPM_DAA_JOINDATA(s.DAA_joinSession) + 4) 2.720 - 2.721 - /* 2.722 - * TPM_STANY_DATA ([TPM_Part2], Section 7.6) 2.723 -@@ -2095,6 +2105,17 @@ typedef struct tdTPM_STANY_DATA { 2.724 - TPM_DAA_SESSION_DATA sessionsDAA[TPM_MAX_SESSIONS_DAA]; 2.725 - TPM_TRANSHANDLE transExclusive; 2.726 - } TPM_STANY_DATA; 2.727 -+#define sizeof_TPM_STANY_DATA(s) (2 + 20 + 20 + 1 \ 2.728 -+ + sizeof_TPM_CURRENT_TICKS(s.currentTicks) \ 2.729 -+ + 4 + (4 * TPM_MAX_SESSION_LIST) \ 2.730 -+ + (sizeof_TPM_SESSION_DATA(s.sessions[0]) * TPM_MAX_SESSION_LIST) \ 2.731 -+ + (sizeof_TPM_DAA_SESSION_DATA(s.sessionsDAA[0]) * TPM_MAX_SESSIONS_DAA) + 4) 2.732 -+ 2.733 -+#define sizeof_TPM_PERMANENT_DATA(s) (2 + 4 + 4*20 \ 2.734 -+ + sizeof_RSA(s.endorsementKey) + TPM_ORD_MAX/8 \ 2.735 -+ + (1+TPM_MAX_KEYS)*sizeof_TPM_KEY_DATA(s.srk) \ 2.736 -+ + TPM_NUM_PCR*(sizeof_TPM_PCR_ATTRIBUTES(x)+20) \ 2.737 -+ + TPM_MAX_COUNTERS*sizeof_TPM_COUNTER_VALUE2(x) + 1 + 4 + 20) 2.738 - 2.739 - /* 2.740 - * TPM_DATA
3.1 --- a/tools/vtpm/tpm_emulator.patch Tue Jul 25 11:19:48 2006 +0100 3.2 +++ b/tools/vtpm/tpm_emulator.patch Tue Jul 25 11:30:30 2006 +0100 3.3 @@ -1,136 +1,23 @@ 3.4 -diff -uprN tpm_emulator-0.3-x86_64/AUTHORS tpm_emulator/AUTHORS 3.5 ---- tpm_emulator-0.3-x86_64/AUTHORS 2006-08-29 15:07:21.618299064 -0700 3.6 -+++ tpm_emulator/AUTHORS 2006-08-29 15:26:17.099679656 -0700 3.7 +diff -uprN orig/tpm_emulator-0.4/AUTHORS tpm_emulator/AUTHORS 3.8 +--- orig/tpm_emulator-0.4/AUTHORS 2006-06-23 03:37:07.000000000 -0700 3.9 ++++ tpm_emulator/AUTHORS 2006-07-24 14:35:35.000000000 -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 tpm_emulator-0.3-x86_64/ChangeLog tpm_emulator/ChangeLog 3.15 ---- tpm_emulator-0.3-x86_64/ChangeLog 2006-08-29 15:07:21.618299064 -0700 3.16 -+++ tpm_emulator/ChangeLog 2006-08-29 15:26:17.100679504 -0700 3.17 +diff -uprN orig/tpm_emulator-0.4/ChangeLog tpm_emulator/ChangeLog 3.18 +--- orig/tpm_emulator-0.4/ChangeLog 2006-06-23 03:37:07.000000000 -0700 3.19 ++++ tpm_emulator/ChangeLog 2006-07-24 14:35:35.000000000 -0700 3.20 @@ -1,3 +1,6 @@ 3.21 -+2005-08-16 Intel Corp 3.22 ++????-??-?? Intel Corp 3.23 + * Moved module out of kernel to run as a ring 3 app 3.24 + 3.25 - 2005-12-24 Mario Strasser <mast@gmx.net> 3.26 - * tpm_transport.c, tpm_marshalling.c, tpm_structures.h: 3.27 - Transport session functionality added 3.28 -diff -uprN tpm_emulator-0.3-x86_64/Makefile tpm_emulator/Makefile 3.29 ---- tpm_emulator-0.3-x86_64/Makefile 2006-08-29 15:08:20.532342768 -0700 3.30 -+++ tpm_emulator/Makefile 2006-08-29 15:27:39.559143912 -0700 3.31 -@@ -1,22 +1,31 @@ 3.32 - # Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.33 - # Copyright (C) 2004 Mario Strasser <mast@gmx.net> 3.34 -+# Copyright (C) 2006 INTEL Corp. 3.35 - # 3.36 - # $Id: Makefile 69 2005-12-13 12:55:52Z mast $ 3.37 - 3.38 --# kernel settings 3.39 --KERNEL_RELEASE := $(shell uname -r) 3.40 --KERNEL_BUILD := /lib/modules/$(KERNEL_RELEASE)/build 3.41 --MOD_SUBDIR := misc 3.42 - COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/) 3.43 - 3.44 - # module settings 3.45 --MODULE_NAME := tpm_emulator 3.46 -+BIN := tpm_emulator 3.47 - VERSION_MAJOR := 0 3.48 - VERSION_MINOR := 3 3.49 - VERSION_BUILD := $(shell date +"%s") 3.50 - 3.51 --# enable/disable DEBUG messages 3.52 --EXTRA_CFLAGS += -Wall -DDEBUG -g 3.53 -+# Installation program and options 3.54 -+INSTALL = install 3.55 -+INSTALL_PROG = $(INSTALL) -m0755 3.56 -+INSTALL_DIR = $(INSTALL) -d -m0755 3.57 -+ 3.58 -+# Xen tools installation directory 3.59 -+TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin 3.60 -+ 3.61 -+CC := gcc 3.62 -+CFLAGS += -g -Wall $(INCLUDE) -DDEBUG 3.63 -+CFLAGS += -I. -Itpm 3.64 -+ 3.65 -+# Is the simulator running in it's own vm? 3.66 -+#CFLAGS += -DVTPM_MULTI_VM 3.67 - 3.68 - ifeq ($(COMPILE_ARCH),x86_64) 3.69 - LIBDIR = lib64 3.70 -@@ -34,38 +43,31 @@ DIRS := . crypto tpm 3.71 - SRCS := $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.c)) 3.72 - OBJS := $(patsubst %.c, %.o, $(SRCS)) 3.73 - SRCS += $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.h)) 3.74 --DISTSRC := ./README ./AUTHORS ./ChangeLog ./Makefile $(SRCS) 3.75 --DISTDIR := tpm_emulator-$(VERSION_MAJOR).$(VERSION_MINOR) 3.76 - 3.77 --obj-m := $(MODULE_NAME).o 3.78 --$(MODULE_NAME)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a 3.79 -+obj-m := $(BIN) 3.80 -+$(BIN)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a 3.81 - 3.82 - EXTRA_CFLAGS += -I$(src) -I$(src)/crypto -I$(src)/tpm 3.83 - 3.84 - # do not print "Entering directory ..." 3.85 - MAKEFLAGS += --no-print-directory 3.86 - 3.87 --all: $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version 3.88 -- @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules 3.89 -+all: $(BIN) 3.90 -+ 3.91 -+$(BIN): $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version $(SRCS) $(OBJS) 3.92 -+ $(CC) $(CFLAGS) $(OBJS) $(src)/crypto/libgmp.a -o $(BIN) 3.93 -+ 3.94 -+%.o: %.c 3.95 -+ $(CC) $(CFLAGS) -c $< -o $@ 3.96 - 3.97 --install: 3.98 -- @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules_install 3.99 -- test -d /var/tpm || mkdir /var/tpm 3.100 -- test -c /dev/tpm || mknod /dev/tpm c 10 224 3.101 -- chmod 666 /dev/tpm 3.102 -- depmod -a 3.103 -+install: $(BIN) 3.104 -+ $(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR) 3.105 - 3.106 - clean: 3.107 -- @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) clean 3.108 -- rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a 3.109 -+ rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS) 3.110 - 3.111 --dist: $(DISTSRC) 3.112 -- rm -rf $(DISTDIR) 3.113 -- mkdir $(DISTDIR) 3.114 -- cp --parents $(DISTSRC) $(DISTDIR)/ 3.115 -- rm -f $(DISTDIR)/crypto/gmp.h 3.116 -- tar -chzf $(DISTDIR).tar.gz $(DISTDIR) 3.117 -- rm -rf $(DISTDIR) 3.118 -+mrproper: clean 3.119 -+ rm -f $(BIN) tpm_version.h 3.120 - 3.121 - $(src)/crypto/libgmp.a: 3.122 - test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a 3.123 -diff -uprN tpm_emulator-0.3-x86_64/README tpm_emulator/README 3.124 ---- tpm_emulator-0.3-x86_64/README 2006-08-29 15:07:43.530967832 -0700 3.125 -+++ tpm_emulator/README 2006-08-29 15:26:17.105678744 -0700 3.126 -@@ -13,7 +13,8 @@ $Id: README 78 2006-01-07 10:45:39Z mast 3.127 - Copyright 3.128 - -------------------------------------------------------------------------- 3.129 - Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal 3.130 --Institute of Technology (ETH) Zurich. 3.131 -+ Institute of Technology (ETH) Zurich. 3.132 -+Copyright (C) 2005 INTEL Corp 3.133 - 3.134 - This program is free software; you can redistribute it and/or modify 3.135 - it under the terms of the GNU General Public License as published by 3.136 -diff -uprN tpm_emulator-0.3-x86_64/README.1st tpm_emulator/README.1st 3.137 ---- tpm_emulator-0.3-x86_64/README.1st 1969-12-31 16:00:00.000000000 -0800 3.138 -+++ tpm_emulator/README.1st 2006-08-29 15:26:17.105678744 -0700 3.139 -@@ -0,0 +1 @@ 3.140 -+Note that you must manually create /tmp/tpm_in.fifo and /tmp/tpm_out.fifo for this emulator to work. 3.141 -diff -uprN tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c tpm_emulator/crypto/gmp_kernel_wrapper.c 3.142 ---- tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c 2006-08-29 15:07:43.525968592 -0700 3.143 -+++ tpm_emulator/crypto/gmp_kernel_wrapper.c 2006-08-29 15:26:17.101679352 -0700 3.144 + 2006-06-23 Mario Strasser <mast@gmx.net> 3.145 + * tpm_startup.c: behaviour of ST_CLEAR and storage of 3.146 + persistent data adapted 3.147 +diff -uprN orig/tpm_emulator-0.4/crypto/gmp_kernel_wrapper.c tpm_emulator/crypto/gmp_kernel_wrapper.c 3.148 +--- orig/tpm_emulator-0.4/crypto/gmp_kernel_wrapper.c 2006-06-23 03:37:07.000000000 -0700 3.149 ++++ tpm_emulator/crypto/gmp_kernel_wrapper.c 2006-07-24 14:35:35.000000000 -0700 3.150 @@ -1,5 +1,6 @@ 3.151 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.152 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.153 @@ -161,7 +48,7 @@ diff -uprN tpm_emulator-0.3-x86_64/crypt 3.154 { 3.155 - void *ret = (void*)kmalloc(size, GFP_KERNEL); 3.156 - if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 3.157 -- "GMP: cannot allocate memory (size=%Zu)\n", size); 3.158 +- "GMP: cannot allocate memory (size=%u)\n", size); 3.159 + void *ret = (void*)malloc(size); 3.160 + if (!ret) error("GMP: cannot allocate memory (size=%Zu)\n", size); 3.161 return ret; 3.162 @@ -172,9 +59,10 @@ diff -uprN tpm_emulator-0.3-x86_64/crypt 3.163 { 3.164 - void *ret = (void*)kmalloc(new_size, GFP_KERNEL); 3.165 - if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory " 3.166 +- "(old_size=%u new_size=%u)\n", old_size, new_size); 3.167 + void *ret = (void*)malloc(new_size); 3.168 + if (!ret) error("GMP: Cannot reallocate memory " 3.169 - "(old_size=%Zu new_size=%Zu)\n", old_size, new_size); 3.170 ++ "(old_size=%Zu new_size=%Zu)\n", old_size, new_size); 3.171 memcpy(ret, oldptr, old_size); 3.172 - kfree(oldptr); 3.173 + free(oldptr); 3.174 @@ -190,9 +78,9 @@ diff -uprN tpm_emulator-0.3-x86_64/crypt 3.175 } 3.176 } 3.177 3.178 -diff -uprN tpm_emulator-0.3-x86_64/crypto/rsa.c tpm_emulator/crypto/rsa.c 3.179 ---- tpm_emulator-0.3-x86_64/crypto/rsa.c 2006-08-29 15:07:21.618299064 -0700 3.180 -+++ tpm_emulator/crypto/rsa.c 2006-08-29 15:26:17.102679200 -0700 3.181 +diff -uprN orig/tpm_emulator-0.4/crypto/rsa.c tpm_emulator/crypto/rsa.c 3.182 +--- orig/tpm_emulator-0.4/crypto/rsa.c 2006-06-23 03:37:07.000000000 -0700 3.183 ++++ tpm_emulator/crypto/rsa.c 2006-07-24 14:35:35.000000000 -0700 3.184 @@ -1,5 +1,6 @@ 3.185 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.186 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.187 @@ -218,10 +106,10 @@ diff -uprN tpm_emulator-0.3-x86_64/crypt 3.188 sha1_final(&ctx, &msg[1]); 3.189 if (memcmp(&msg[1], &msg[1 + SHA1_DIGEST_LENGTH], 3.190 SHA1_DIGEST_LENGTH) != 0) return -1; 3.191 -diff -uprN tpm_emulator-0.3-x86_64/linux_module.c tpm_emulator/linux_module.c 3.192 ---- tpm_emulator-0.3-x86_64/linux_module.c 2006-08-29 15:07:43.526968440 -0700 3.193 +diff -uprN orig/tpm_emulator-0.4/linux_module.c tpm_emulator/linux_module.c 3.194 +--- orig/tpm_emulator-0.4/linux_module.c 2006-06-23 03:37:07.000000000 -0700 3.195 +++ tpm_emulator/linux_module.c 1969-12-31 16:00:00.000000000 -0800 3.196 -@@ -1,194 +0,0 @@ 3.197 +@@ -1,195 +0,0 @@ 3.198 -/* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.199 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.200 - * 3.201 @@ -235,7 +123,7 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 3.202 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3.203 - * GNU General Public License for more details. 3.204 - * 3.205 -- * $Id: linux_module.c 76 2006-01-02 22:17:58Z hstamer $ 3.206 +- * $Id: linux_module.c 91 2006-03-13 13:51:41Z mast $ 3.207 - */ 3.208 - 3.209 -#include <linux/module.h> 3.210 @@ -273,6 +161,7 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 3.211 -/* module state */ 3.212 -#define STATE_IS_OPEN 0 3.213 -static uint32_t module_state; 3.214 +-static struct timespec old_time; 3.215 - 3.216 -static int tpm_open(struct inode *inode, struct file *file) 3.217 -{ 3.218 @@ -296,7 +185,7 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 3.219 - 3.220 -static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos) 3.221 -{ 3.222 -- debug("%s(%Zu)", __FUNCTION__, count); 3.223 +- debug("%s(%d)", __FUNCTION__, count); 3.224 - down(&tpm_mutex); 3.225 - if (tpm_response.data != NULL) { 3.226 - count = min(count, (size_t)tpm_response.size - (size_t)*ppos); 3.227 @@ -315,7 +204,7 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 3.228 - 3.229 -static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos) 3.230 -{ 3.231 -- debug("%s(%Zu)", __FUNCTION__, count); 3.232 +- debug("%s(%d)", __FUNCTION__, count); 3.233 - down(&tpm_mutex); 3.234 - *ppos = 0; 3.235 - if (tpm_response.data != NULL) kfree(tpm_response.data); 3.236 @@ -379,7 +268,8 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 3.237 - /* initialize variables */ 3.238 - sema_init(&tpm_mutex, 1); 3.239 - module_state = 0; 3.240 -- tpm_response.data = NULL; 3.241 +- tpm_response.data = NULL; 3.242 +- old_time = current_kernel_time(); 3.243 - /* initialize TPM emulator */ 3.244 - if (!strcmp(startup, "clear")) { 3.245 - tpm_emulator_init(1); 3.246 @@ -408,17 +298,16 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 3.247 - 3.248 -uint64_t tpm_get_ticks(void) 3.249 -{ 3.250 -- static struct timespec old_time = {0, 0}; 3.251 - struct timespec new_time = current_kernel_time(); 3.252 -- uint64_t ticks = (uint64_t)(old_time.tv_sec - new_time.tv_sec) * 1000000 3.253 -- + (old_time.tv_nsec - new_time.tv_nsec) / 1000; 3.254 +- uint64_t ticks = (uint64_t)(new_time.tv_sec - old_time.tv_sec) * 1000000 3.255 +- + (new_time.tv_nsec - old_time.tv_nsec) / 1000; 3.256 - old_time = new_time; 3.257 - return (ticks > 0) ? ticks : 1; 3.258 -} 3.259 - 3.260 -diff -uprN tpm_emulator-0.3-x86_64/linux_module.h tpm_emulator/linux_module.h 3.261 ---- tpm_emulator-0.3-x86_64/linux_module.h 2006-08-29 15:07:43.527968288 -0700 3.262 -+++ tpm_emulator/linux_module.h 2006-08-29 15:26:17.103679048 -0700 3.263 +diff -uprN orig/tpm_emulator-0.4/linux_module.h tpm_emulator/linux_module.h 3.264 +--- orig/tpm_emulator-0.4/linux_module.h 2006-06-23 03:37:07.000000000 -0700 3.265 ++++ tpm_emulator/linux_module.h 2006-07-24 14:35:35.000000000 -0700 3.266 @@ -1,5 +1,6 @@ 3.267 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.268 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.269 @@ -426,7 +315,7 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 3.270 * 3.271 * This module is free software; you can redistribute it and/or modify 3.272 * it under the terms of the GNU General Public License as published 3.273 -@@ -17,17 +18,22 @@ 3.274 +@@ -17,54 +18,62 @@ 3.275 #ifndef _LINUX_MODULE_H_ 3.276 #define _LINUX_MODULE_H_ 3.277 3.278 @@ -454,12 +343,15 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 3.279 3.280 +/* module settings */ 3.281 +#define min(A,B) ((A)<(B)?(A):(B)) 3.282 - #ifndef STR 3.283 ++#ifndef STR 3.284 #define STR(s) __STR__(s) 3.285 #define __STR__(s) #s 3.286 -@@ -38,35 +44,36 @@ 3.287 - #define TPM_DEVICE_NAME "tpm" 3.288 - #define TPM_MODULE_NAME "tpm_emulator" 3.289 ++#endif 3.290 + #include "tpm_version.h" 3.291 + 3.292 + #define TPM_DEVICE_MINOR 224 3.293 + #define TPM_DEVICE_NAME "tpm" 3.294 + #define TPM_MODULE_NAME "tpm_emulator" 3.295 3.296 -/* debug and log output functions */ 3.297 - 3.298 @@ -506,7 +398,7 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 3.299 static inline void tpm_get_random_bytes(void *buf, int nbytes) 3.300 { 3.301 get_random_bytes(buf, nbytes); 3.302 -@@ -86,9 +93,9 @@ uint64_t tpm_get_ticks(void); 3.303 +@@ -84,9 +93,9 @@ uint64_t tpm_get_ticks(void); 3.304 #define CPU_TO_LE16(x) __cpu_to_le16(x) 3.305 3.306 #define BE64_TO_CPU(x) __be64_to_cpu(x) 3.307 @@ -518,205 +410,242 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 3.308 #define BE16_TO_CPU(x) __be16_to_cpu(x) 3.309 #define LE16_TO_CPU(x) __le16_to_cpu(x) 3.310 3.311 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_audit.c tpm_emulator/tpm/tpm_audit.c 3.312 ---- tpm_emulator-0.3-x86_64/tpm/tpm_audit.c 2006-08-29 15:07:21.620298760 -0700 3.313 -+++ tpm_emulator/tpm/tpm_audit.c 2006-08-29 15:26:17.107678440 -0700 3.314 -@@ -1,6 +1,7 @@ 3.315 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.316 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.317 - * Swiss Federal Institute of Technology (ETH) Zurich 3.318 -+ * Copyright (C) 2005 INTEL Corp 3.319 - * 3.320 - * This module is free software; you can redistribute it and/or modify 3.321 - * it under the terms of the GNU General Public License as published 3.322 -@@ -45,14 +46,14 @@ void tpm_audit_request(TPM_COMMAND_CODE 3.323 - tpmData.permanent.data.auditMonotonicCounter++; 3.324 - } 3.325 - /* update audit digest */ 3.326 -- *((UINT16*)&buf[0]) = cpu_to_be16(TPM_TAG_AUDIT_EVENT_IN); 3.327 -- *((UINT32*)&buf[2]) = cpu_to_be32(ordinal); 3.328 -+ *((UINT16*)&buf[0]) = CPU_TO_BE16(TPM_TAG_AUDIT_EVENT_IN); 3.329 -+ *((UINT32*)&buf[2]) = CPU_TO_BE32(ordinal); 3.330 - sha1_init(&sha1_ctx); 3.331 - sha1_update(&sha1_ctx, req->param, req->paramSize); 3.332 - sha1_final(&sha1_ctx, &buf[6]); 3.333 -- *((UINT16*)&buf[26]) = cpu_to_be16(TPM_TAG_COUNTER_VALUE); 3.334 -+ *((UINT16*)&buf[26]) = CPU_TO_BE16(TPM_TAG_COUNTER_VALUE); 3.335 - memset(&buf[30], 0, 4); 3.336 -- *((UINT32*)&buf[34]) = cpu_to_be32(tpmData.permanent.data.auditMonotonicCounter); 3.337 -+ *((UINT32*)&buf[34]) = CPU_TO_BE32(tpmData.permanent.data.auditMonotonicCounter); 3.338 - sha1_init(&sha1_ctx); 3.339 - sha1_update(&sha1_ctx, tpmData.stany.data.auditDigest.digest, 3.340 - sizeof(TPM_DIGEST)); 3.341 -@@ -70,15 +71,15 @@ void tpm_audit_response(TPM_COMMAND_CODE 3.342 - && (AUDIT_STATUS[ord / 8] & (1 << (ord & 0x07)))) { 3.343 - info("tpm_audit_response()"); 3.344 - /* update audit digest */ 3.345 -- *((UINT16*)&buf[0]) = cpu_to_be16(TPM_TAG_AUDIT_EVENT_OUT); 3.346 -- *((UINT32*)&buf[2]) = cpu_to_be32(ordinal); 3.347 -+ *((UINT16*)&buf[0]) = CPU_TO_BE16(TPM_TAG_AUDIT_EVENT_OUT); 3.348 -+ *((UINT32*)&buf[2]) = CPU_TO_BE32(ordinal); 3.349 - sha1_init(&sha1_ctx); 3.350 - sha1_update(&sha1_ctx, rsp->param, rsp->paramSize); 3.351 - sha1_final(&sha1_ctx, &buf[6]); 3.352 -- *((UINT16*)&buf[26]) = cpu_to_be16(TPM_TAG_COUNTER_VALUE); 3.353 -+ *((UINT16*)&buf[26]) = CPU_TO_BE16(TPM_TAG_COUNTER_VALUE); 3.354 - memset(&buf[30], 0, 4); 3.355 -- *((UINT32*)&buf[34]) = cpu_to_be32(tpmData.permanent.data.auditMonotonicCounter); 3.356 -- *((UINT32*)&buf[34]) = cpu_to_be32(rsp->result); 3.357 -+ *((UINT32*)&buf[34]) = CPU_TO_BE32(tpmData.permanent.data.auditMonotonicCounter); 3.358 -+ *((UINT32*)&buf[34]) = CPU_TO_BE32(rsp->result); 3.359 - sha1_init(&sha1_ctx); 3.360 - sha1_update(&sha1_ctx, tpmData.stany.data.auditDigest.digest, 3.361 - sizeof(TPM_DIGEST)); 3.362 -@@ -158,7 +159,7 @@ TPM_RESULT TPM_GetAuditDigestSigned(TPM_ 3.363 - } 3.364 - memcpy(&buf[0], "\x05\x00ADIG", 6); 3.365 - memcpy(&buf[6], antiReplay->nonce, 20); 3.366 -- *(UINT32*)&buf[26] = cpu_to_be32(buf_size - 30); 3.367 -+ *(UINT32*)&buf[26] = CPU_TO_BE32(buf_size - 30); 3.368 - memcpy(&buf[30], auditDigest->digest, 20); 3.369 - ptr = &buf[50]; 3.370 - len = buf_size - 50; 3.371 -@@ -198,4 +199,3 @@ TPM_RESULT TPM_SetOrdinalAuditStatus(TPM 3.372 - } 3.373 - return TPM_SUCCESS; 3.374 - } 3.375 +diff -uprN orig/tpm_emulator-0.4/Makefile tpm_emulator/Makefile 3.376 +--- orig/tpm_emulator-0.4/Makefile 2006-06-23 03:37:07.000000000 -0700 3.377 ++++ tpm_emulator/Makefile 2006-07-24 14:35:35.000000000 -0700 3.378 +@@ -1,24 +1,40 @@ 3.379 + # Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.380 + # Copyright (C) 2004 Mario Strasser <mast@gmx.net> 3.381 ++# Copyright (C) 2006 INTEL Corp. 3.382 + # 3.383 + # $Id: Makefile 115 2006-06-23 10:36:44Z mast $ 3.384 + 3.385 +-# kernel settings 3.386 +-KERNEL_RELEASE := $(shell uname -r) 3.387 +-KERNEL_BUILD := /lib/modules/$(KERNEL_RELEASE)/build 3.388 +-MOD_SUBDIR := misc 3.389 ++COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/) 3.390 + 3.391 + # module settings 3.392 +-MODULE_NAME := tpm_emulator 3.393 ++BIN := tpm_emulator 3.394 + VERSION_MAJOR := 0 3.395 + VERSION_MINOR := 4 3.396 + VERSION_BUILD := $(shell date +"%s") 3.397 + 3.398 +-# enable/disable DEBUG messages 3.399 +-EXTRA_CFLAGS += -Wall -DDEBUG -g 3.400 ++# Installation program and options 3.401 ++INSTALL = install 3.402 ++INSTALL_PROG = $(INSTALL) -m0755 3.403 ++INSTALL_DIR = $(INSTALL) -d -m0755 3.404 ++ 3.405 ++# Xen tools installation directory 3.406 ++TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin 3.407 ++ 3.408 ++CC := gcc 3.409 ++CFLAGS += -g -Wall $(INCLUDE) -DDEBUG 3.410 ++CFLAGS += -I. -Itpm 3.411 ++ 3.412 ++# Is the simulator running in it's own vm? 3.413 ++#CFLAGS += -DVTPM_MULTI_VM 3.414 ++ 3.415 ++ifeq ($(COMPILE_ARCH),x86_64) 3.416 ++LIBDIR = lib64 3.417 ++else 3.418 ++LIBDIR = lib 3.419 ++endif 3.420 + 3.421 + # GNU MP configuration 3.422 +-GMP_LIB := /usr/lib/libgmp.a 3.423 ++GMP_LIB := /usr/$(LIBDIR)/libgmp.a 3.424 + GMP_HEADER := /usr/include/gmp.h 3.425 + 3.426 + # sources and objects 3.427 +@@ -27,38 +43,32 @@ DIRS := . crypto tpm 3.428 + SRCS := $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.c)) 3.429 + OBJS := $(patsubst %.c, %.o, $(SRCS)) 3.430 + SRCS += $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.h)) 3.431 +-DISTSRC := ./README ./AUTHORS ./ChangeLog ./Makefile $(SRCS) 3.432 +-DISTDIR := tpm_emulator-$(VERSION_MAJOR).$(VERSION_MINOR) 3.433 + 3.434 +-obj-m := $(MODULE_NAME).o 3.435 +-$(MODULE_NAME)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a 3.436 ++obj-m := $(BIN) 3.437 ++$(BIN)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a 3.438 + 3.439 + EXTRA_CFLAGS += -I$(src) -I$(src)/crypto -I$(src)/tpm 3.440 + 3.441 + # do not print "Entering directory ..." 3.442 + MAKEFLAGS += --no-print-directory 3.443 + 3.444 +-all: $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version 3.445 +- @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules 3.446 ++all: $(BIN) 3.447 + 3.448 +-install: 3.449 +- @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules_install 3.450 +- test -d /var/tpm || mkdir /var/tpm 3.451 +- test -c /dev/tpm || mknod /dev/tpm c 10 224 3.452 +- chmod 666 /dev/tpm 3.453 +- depmod -a 3.454 ++$(BIN): $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version $(SRCS) $(OBJS) 3.455 ++ $(CC) $(CFLAGS) $(OBJS) $(src)/crypto/libgmp.a -o $(BIN) 3.456 ++ 3.457 ++%.o: %.c 3.458 ++ $(CC) $(CFLAGS) -c $< -o $@ 3.459 ++ 3.460 ++install: $(BIN) 3.461 ++ $(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR) 3.462 ++ @if [ ! -d "/var/tpm" ]; then mkdir /var/tpm; fi 3.463 + 3.464 + clean: 3.465 +- @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) clean 3.466 +- rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a 3.467 ++ rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS) 3.468 + 3.469 +-dist: $(DISTSRC) 3.470 +- rm -rf $(DISTDIR) 3.471 +- mkdir $(DISTDIR) 3.472 +- cp --parents $(DISTSRC) $(DISTDIR)/ 3.473 +- rm -f $(DISTDIR)/crypto/gmp.h 3.474 +- tar -chzf $(DISTDIR).tar.gz $(DISTDIR) 3.475 +- rm -rf $(DISTDIR) 3.476 ++mrproper: clean 3.477 ++ rm -f $(BIN) tpm_version.h 3.478 + 3.479 + $(src)/crypto/libgmp.a: 3.480 + test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a 3.481 +@@ -88,4 +98,3 @@ version: 3.482 + @echo "#endif /* _TPM_VERSION_H_ */" >> $(src)/tpm_version.h 3.483 + 3.484 + .PHONY: all install clean dist gmp version 3.485 - 3.486 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c tpm_emulator/tpm/tpm_authorization.c 3.487 ---- tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c 2006-08-29 15:07:21.620298760 -0700 3.488 -+++ tpm_emulator/tpm/tpm_authorization.c 2006-08-29 15:26:17.108678288 -0700 3.489 -@@ -1,6 +1,7 @@ 3.490 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.491 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.492 - * Swiss Federal Institute of Technology (ETH) Zurich 3.493 -+ * Copyright (C) 2005 INTEL Corp 3.494 - * 3.495 - * This module is free software; you can redistribute it and/or modify 3.496 - * it under the terms of the GNU General Public License as published 3.497 -@@ -279,7 +280,7 @@ TPM_RESULT tpm_verify_auth(TPM_AUTH *aut 3.498 +diff -uprN orig/tpm_emulator-0.4/README tpm_emulator/README 3.499 +--- orig/tpm_emulator-0.4/README 2006-06-23 03:37:07.000000000 -0700 3.500 ++++ tpm_emulator/README 2006-07-24 14:35:35.000000000 -0700 3.501 +@@ -13,7 +13,8 @@ $Id: README 113 2006-06-18 12:38:13Z hst 3.502 + Copyright 3.503 + -------------------------------------------------------------------------- 3.504 + Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal 3.505 +-Institute of Technology (ETH) Zurich. 3.506 ++ Institute of Technology (ETH) Zurich. 3.507 ++Copyright (C) 2005 INTEL Corp 3.508 + 3.509 + This program is free software; you can redistribute it and/or modify 3.510 + it under the terms of the GNU General Public License as published by 3.511 +@@ -43,6 +44,12 @@ Example: 3.512 + GMP_LIB := /usr/lib/libgmp.a 3.513 + GMP_HEADER := /usr/include/gmp.h 3.514 + 3.515 ++GNU MP Library on 64 bit Systems 3.516 ++-------------------------------------------------------------------------- 3.517 ++Some 64-bit kernels have problems with importing the user-space gmp 3.518 ++library (/usr/lib*/libgmp.a) into kernel space. These kernels will require 3.519 ++that the gmp library be recompiled for kernel space with -mcmodel=kernel. 3.520 ++ 3.521 + Installation 3.522 + -------------------------------------------------------------------------- 3.523 + The compilation and installation process uses the build environment for 3.524 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_credentials.c tpm_emulator/tpm/tpm_credentials.c 3.525 +--- orig/tpm_emulator-0.4/tpm/tpm_credentials.c 2006-06-23 03:37:07.000000000 -0700 3.526 ++++ tpm_emulator/tpm/tpm_credentials.c 2006-07-24 14:35:35.000000000 -0700 3.527 +@@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC 3.528 + 3.529 + TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey) 3.530 { 3.531 - hmac_ctx_t ctx; 3.532 - TPM_SESSION_DATA *session; 3.533 -- UINT32 auth_handle = cpu_to_be32(auth->authHandle); 3.534 -+ UINT32 auth_handle = CPU_TO_BE32(auth->authHandle); 3.535 - 3.536 - info("tpm_verify_auth(%08x)", auth->authHandle); 3.537 - /* get dedicated authorization or transport session */ 3.538 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_capability.c tpm_emulator/tpm/tpm_capability.c 3.539 ---- tpm_emulator-0.3-x86_64/tpm/tpm_capability.c 2006-08-29 15:07:21.620298760 -0700 3.540 -+++ tpm_emulator/tpm/tpm_capability.c 2006-08-29 15:26:17.109678136 -0700 3.541 -@@ -1,6 +1,7 @@ 3.542 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.543 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.544 - * Swiss Federal Institute of Technology (ETH) Zurich 3.545 -+ * Copyright (C) 2005 INTEL Corp 3.546 - * 3.547 - * This module is free software; you can redistribute it and/or modify 3.548 - * it under the terms of the GNU General Public License as published 3.549 -@@ -406,7 +407,7 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL 3.550 - 3.551 - case TPM_CAP_KEY_HANDLE: 3.552 - debug("[TPM_CAP_KEY_HANDLE]"); 3.553 -- subCapSize = cpu_to_be32(TPM_RT_KEY); 3.554 -+ subCapSize = CPU_TO_BE32(TPM_RT_KEY); 3.555 - return cap_handle(4, (BYTE*)&subCapSize, respSize, resp); 3.556 - 3.557 - case TPM_CAP_CHECK_LOADED: 3.558 -@@ -480,4 +481,3 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL 3.559 - return TPM_BAD_MODE; 3.560 - } 3.561 - } 3.562 -- 3.563 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c tpm_emulator/tpm/tpm_cmd_handler.c 3.564 ---- tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c 2006-08-29 15:07:21.621298608 -0700 3.565 -+++ tpm_emulator/tpm/tpm_cmd_handler.c 2006-08-29 15:26:17.113677528 -0700 3.566 -@@ -1,6 +1,7 @@ 3.567 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.568 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.569 - * Swiss Federal Institute of Technology (ETH) Zurich 3.570 -+ * Copyright (C) 2005 INTEL Corp 3.571 - * 3.572 - * This module is free software; you can redistribute it and/or modify 3.573 - * it under the terms of the GNU General Public License as published 3.574 -@@ -73,7 +74,7 @@ void tpm_compute_in_param_digest(TPM_REQ 3.575 - { 3.576 - sha1_ctx_t sha1; 3.577 - UINT32 offset = tpm_get_param_offset(req->ordinal); 3.578 -- UINT32 ord = cpu_to_be32(req->ordinal); 3.579 -+ UINT32 ord = CPU_TO_BE32(req->ordinal); 3.580 - 3.581 - /* compute SHA1 hash */ 3.582 - if (offset <= req->paramSize) { 3.583 -@@ -89,8 +90,8 @@ void tpm_compute_in_param_digest(TPM_REQ 3.584 - void tpm_compute_out_param_digest(TPM_COMMAND_CODE ordinal, TPM_RESPONSE *rsp) 3.585 - { 3.586 - sha1_ctx_t sha1; 3.587 -- UINT32 res = cpu_to_be32(rsp->result); 3.588 -- UINT32 ord = cpu_to_be32(ordinal); 3.589 -+ UINT32 res = CPU_TO_BE32(rsp->result); 3.590 -+ UINT32 ord = CPU_TO_BE32(ordinal); 3.591 - 3.592 - /* compute SHA1 hash */ 3.593 - sha1_init(&sha1); 3.594 -@@ -3123,7 +3124,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA 3.595 - hmac_update(&hmac, rsp->auth2->digest, sizeof(rsp->auth2->digest)); 3.596 - #if 0 3.597 - if (tpm_get_auth(rsp->auth2->authHandle)->type == TPM_ST_OIAP) { 3.598 -- UINT32 handle = cpu_to_be32(rsp->auth2->authHandle); 3.599 -+ UINT32 handle = CPU_TO_BE32(rsp->auth2->authHandle); 3.600 - hmac_update(&hmac, (BYTE*)&handle, 4); 3.601 - } 3.602 - #endif 3.603 -@@ -3138,7 +3139,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA 3.604 - hmac_update(&hmac, rsp->auth1->digest, sizeof(rsp->auth1->digest)); 3.605 - #if 0 3.606 - if (tpm_get_auth(rsp->auth1->authHandle)->type == TPM_ST_OIAP) { 3.607 -- UINT32 handle = cpu_to_be32(rsp->auth1->authHandle); 3.608 -+ UINT32 handle = CPU_TO_BE32(rsp->auth1->authHandle); 3.609 - hmac_update(&hmac, (BYTE*)&handle, 4); 3.610 - } 3.611 - #endif 3.612 -@@ -3221,7 +3222,9 @@ extern const char *tpm_error_to_string(T 3.613 - void tpm_execute_command(TPM_REQUEST *req, TPM_RESPONSE *rsp) 3.614 +- UINT32 key_length; 3.615 ++ size_t key_length; 3.616 + if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT; 3.617 + /* setup TPM_PUBKEY structure */ 3.618 +- key_length = tpmData.permanent.data.endorsementKey.size; 3.619 +- pubEndorsementKey->pubKey.keyLength = key_length >> 3; 3.620 ++ pubEndorsementKey->pubKey.keyLength = tpmData.permanent.data.endorsementKey.size >> 3; 3.621 + pubEndorsementKey->pubKey.key = tpm_malloc(pubEndorsementKey->pubKey.keyLength); 3.622 + if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL; 3.623 + rsa_export_modulus(&tpmData.permanent.data.endorsementKey, 3.624 +- pubEndorsementKey->pubKey.key, 3.625 +- &pubEndorsementKey->pubKey.keyLength); 3.626 ++ pubEndorsementKey->pubKey.key, 3.627 ++ &key_length); 3.628 ++ pubEndorsementKey->pubKey.keyLength = key_length; 3.629 + pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA; 3.630 + pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1; 3.631 + pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE; 3.632 +@@ -175,6 +175,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_ 3.633 { 3.634 TPM_RESULT res; 3.635 -- 3.636 -+ 3.637 -+ req->tag = (BYTE) req->tag; // FIXME: Why is this here 3.638 -+ 3.639 - /* setup authorisation as well as response tag and size */ 3.640 - memset(rsp, 0, sizeof(*rsp)); 3.641 - switch (req->tag) { 3.642 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c tpm_emulator/tpm/tpm_crypto.c 3.643 ---- tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c 2006-08-29 15:07:43.531967680 -0700 3.644 -+++ tpm_emulator/tpm/tpm_crypto.c 2006-08-29 15:26:17.114677376 -0700 3.645 -@@ -1,6 +1,7 @@ 3.646 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.647 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.648 - * Swiss Federal Institute of Technology (ETH) Zurich 3.649 -+ * Copyright (C) 2005 INTEL Corp 3.650 - * 3.651 - * This module is free software; you can redistribute it and/or modify 3.652 - * it under the terms of the GNU General Public License as published 3.653 -@@ -106,7 +107,7 @@ TPM_RESULT tpm_sign(TPM_KEY_DATA *key, T 3.654 - /* setup TPM_SIGN_INFO structure */ 3.655 - memcpy(&buf[0], "\x05\x00SIGN", 6); 3.656 - memcpy(&buf[6], auth->nonceOdd.nonce, 20); 3.657 -- *(UINT32*)&buf[26] = cpu_to_be32(areaToSignSize); 3.658 -+ *(UINT32*)&buf[26] = CPU_TO_BE32(areaToSignSize); 3.659 - memcpy(&buf[30], areaToSign, areaToSignSize); 3.660 - if (rsa_sign(&key->key, RSA_SSA_PKCS1_SHA1, 3.661 - buf, areaToSignSize + 30, *sig)) { 3.662 -@@ -383,4 +384,3 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL 3.663 + TPM_KEY_DATA *srk = &tpmData.permanent.data.srk; 3.664 ++ size_t key_length; 3.665 + info("TPM_OwnerReadInternalPub()"); 3.666 + /* verify authorization */ 3.667 + res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER); 3.668 +@@ -186,7 +187,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_ 3.669 + publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength); 3.670 + if (publicPortion->pubKey.key == NULL) return TPM_FAIL; 3.671 + rsa_export_modulus(&srk->key, publicPortion->pubKey.key, 3.672 +- &publicPortion->pubKey.keyLength); 3.673 ++ &key_length); 3.674 ++ publicPortion->pubKey.keyLength = key_length; 3.675 + publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA; 3.676 + publicPortion->algorithmParms.encScheme = srk->encScheme; 3.677 + publicPortion->algorithmParms.sigScheme = srk->sigScheme; 3.678 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_crypto.c tpm_emulator/tpm/tpm_crypto.c 3.679 +--- orig/tpm_emulator-0.4/tpm/tpm_crypto.c 2006-06-23 03:37:07.000000000 -0700 3.680 ++++ tpm_emulator/tpm/tpm_crypto.c 2006-07-24 14:35:35.000000000 -0700 3.681 +@@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE 3.682 + TPM_KEY_DATA *cert, *key; 3.683 + sha1_ctx_t sha1_ctx; 3.684 + BYTE *buf, *p; 3.685 +- UINT32 length; 3.686 ++ UINT32 length32; 3.687 ++ size_t length; 3.688 + info("TPM_CertifyKey()"); 3.689 + /* get keys */ 3.690 + cert = tpm_get_key(certHandle); 3.691 +@@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE 3.692 + /* compute the digest of the CERTIFY_INFO[2] structure and sign it */ 3.693 + length = sizeof_TPM_CERTIFY_INFO((*certifyInfo)); 3.694 + p = buf = tpm_malloc(length); 3.695 ++ length32=(UINT32) length; 3.696 + if (buf == NULL 3.697 +- || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) { 3.698 ++ || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) { 3.699 + free_TPM_KEY_PARMS(certifyInfo->algorithmParms); 3.700 + return TPM_FAIL; 3.701 } 3.702 - return TPM_SUCCESS; 3.703 - } 3.704 -- 3.705 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_daa.c tpm_emulator/tpm/tpm_daa.c 3.706 ---- tpm_emulator-0.3-x86_64/tpm/tpm_daa.c 2006-08-29 15:07:21.622298456 -0700 3.707 -+++ tpm_emulator/tpm/tpm_daa.c 2006-08-29 15:26:17.119676616 -0700 3.708 -@@ -700,14 +700,14 @@ info("tested until here"); 3.709 + length = sizeof_TPM_CERTIFY_INFO((*certifyInfo)); 3.710 + sha1_init(&sha1_ctx); 3.711 +- sha1_update(&sha1_ctx, buf, length); 3.712 ++ sha1_update(&sha1_ctx, buf, (size_t) length); 3.713 + sha1_final(&sha1_ctx, buf); 3.714 + res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSize); 3.715 + tpm_free(buf); 3.716 +@@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL 3.717 + TPM_KEY_DATA *cert, *key; 3.718 + sha1_ctx_t sha1_ctx; 3.719 + BYTE *buf, *p; 3.720 +- UINT32 length; 3.721 ++ size_t length; 3.722 ++ UINT32 length32; 3.723 + info("TPM_CertifyKey2()"); 3.724 + /* get keys */ 3.725 + cert = tpm_get_key(certHandle); 3.726 +@@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL 3.727 + /* compute the digest of the CERTIFY_INFO[2] structure and sign it */ 3.728 + length = sizeof_TPM_CERTIFY_INFO((*certifyInfo)); 3.729 + p = buf = tpm_malloc(length); 3.730 ++ length32 = (UINT32) length; 3.731 + if (buf == NULL 3.732 +- || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) { 3.733 ++ || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) { 3.734 + free_TPM_KEY_PARMS(certifyInfo->algorithmParms); 3.735 + return TPM_FAIL; 3.736 + } 3.737 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_daa.c tpm_emulator/tpm/tpm_daa.c 3.738 +--- orig/tpm_emulator-0.4/tpm/tpm_daa.c 2006-06-23 03:37:07.000000000 -0700 3.739 ++++ tpm_emulator/tpm/tpm_daa.c 2006-07-24 14:35:35.000000000 -0700 3.740 +@@ -716,14 +716,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl 3.741 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3.742 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3.743 sizeof(session->DAA_tpmSpecific.DAA_count)); 3.744 @@ -733,7 +662,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.745 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 3.746 mpz_init(f), mpz_init(q); 3.747 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 3.748 -@@ -787,14 +787,14 @@ info("tested until here"); 3.749 +@@ -805,14 +805,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl 3.750 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3.751 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3.752 sizeof(session->DAA_tpmSpecific.DAA_count)); 3.753 @@ -750,7 +679,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.754 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 3.755 mpz_init(f), mpz_init(q); 3.756 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 3.757 -@@ -1440,14 +1440,14 @@ info("tested until here"); 3.758 +@@ -1489,14 +1489,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl 3.759 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3.760 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3.761 sizeof(session->DAA_tpmSpecific.DAA_count)); 3.762 @@ -767,7 +696,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.763 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 3.764 mpz_init(f), mpz_init(q); 3.765 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 3.766 -@@ -1660,14 +1660,14 @@ info("tested until here"); 3.767 +@@ -1712,14 +1712,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl 3.768 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3.769 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3.770 sizeof(session->DAA_tpmSpecific.DAA_count)); 3.771 @@ -784,7 +713,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.772 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 3.773 mpz_init(f), mpz_init(q); 3.774 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 3.775 -@@ -1740,14 +1740,14 @@ info("tested until here"); 3.776 +@@ -1793,14 +1793,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl 3.777 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3.778 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3.779 sizeof(session->DAA_tpmSpecific.DAA_count)); 3.780 @@ -801,7 +730,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.781 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 3.782 mpz_init(f), mpz_init(q); 3.783 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 3.784 -@@ -2828,14 +2828,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3.785 +@@ -2918,14 +2918,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3.786 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3.787 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3.788 sizeof(session->DAA_tpmSpecific.DAA_count)); 3.789 @@ -818,7 +747,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.790 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 3.791 mpz_init(f), mpz_init(q); 3.792 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 3.793 -@@ -3050,7 +3050,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3.794 +@@ -3143,7 +3143,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3.795 sha1_init(&sha1); 3.796 sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest, 3.797 sizeof(session->DAA_session.DAA_digest)); 3.798 @@ -827,16 +756,16 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.799 sha1_update(&sha1, inputData1, inputSize1); 3.800 sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest); 3.801 } 3.802 -@@ -3078,7 +3078,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3.803 +@@ -3172,7 +3172,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3.804 sha1_init(&sha1); 3.805 sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest, 3.806 sizeof(session->DAA_session.DAA_digest)); 3.807 -- sha1_update(&sha1, "\x01", 1); 3.808 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 3.809 +- sha1_update(&sha1, "\x00", 1); 3.810 ++ sha1_update(&sha1, (BYTE*) "\x00", 1); 3.811 rsa_export_modulus(&aikData->key, scratch, &size); 3.812 sha1_update(&sha1, scratch, size); 3.813 sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest); 3.814 -@@ -3134,14 +3134,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3.815 +@@ -3229,14 +3229,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3.816 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3.817 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3.818 sizeof(session->DAA_tpmSpecific.DAA_count)); 3.819 @@ -853,7 +782,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.820 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 3.821 mpz_init(f), mpz_init(q); 3.822 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 3.823 -@@ -3213,14 +3213,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3.824 +@@ -3309,14 +3309,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3.825 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3.826 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3.827 sizeof(session->DAA_tpmSpecific.DAA_count)); 3.828 @@ -870,10 +799,27 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.829 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 3.830 mpz_init(f), mpz_init(q); 3.831 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 3.832 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_data.c tpm_emulator/tpm/tpm_data.c 3.833 ---- tpm_emulator-0.3-x86_64/tpm/tpm_data.c 2006-08-29 15:08:20.535342312 -0700 3.834 -+++ tpm_emulator/tpm/tpm_data.c 2006-08-29 15:26:17.121676312 -0700 3.835 -@@ -150,44 +150,43 @@ void tpm_release_data(void) 3.836 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_data.c tpm_emulator/tpm/tpm_data.c 3.837 +--- orig/tpm_emulator-0.4/tpm/tpm_data.c 2006-06-23 03:37:07.000000000 -0700 3.838 ++++ tpm_emulator/tpm/tpm_data.c 2006-07-24 14:35:35.000000000 -0700 3.839 +@@ -40,6 +40,7 @@ static inline void init_pcr_attr(int pcr 3.840 + void tpm_init_data(void) 3.841 + { 3.842 + /* endorsement key */ 3.843 ++#ifndef TPM_GENERATE_EK 3.844 + uint8_t ek_n[] = "\xa8\xdb\xa9\x42\xa8\xf3\xb8\x06\x85\x90\x76\x93\xad\xf7" 3.845 + "\x74\xec\x3f\xd3\x3d\x9d\xe8\x2e\xff\x15\xed\x0e\xce\x5f\x93" 3.846 + "\x92\xeb\xd1\x96\x2b\x72\x18\x81\x79\x12\x9d\x9c\x40\xd7\x1a" 3.847 +@@ -77,6 +78,8 @@ void tpm_init_data(void) 3.848 + "\xd1\xc0\x8b\x5b\xa2\x2e\xa7\x15\xca\x50\x75\x10\x48\x9c\x2b" 3.849 + "\x18\xb9\x67\x8f\x5d\x64\xc3\x28\x9f\x2f\x16\x2f\x08\xda\x47" 3.850 + "\xec\x86\x43\x0c\x80\x99\x07\x34\x0f"; 3.851 ++#endif 3.852 ++ 3.853 + int i; 3.854 + /* reset all data to NULL, FALSE or 0 */ 3.855 + memset(&tpmData, 0, sizeof(tpmData)); 3.856 +@@ -152,44 +155,43 @@ void tpm_release_data(void) 3.857 3.858 #ifdef TPM_STORE_TO_FILE 3.859 3.860 @@ -939,7 +885,75 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.861 if (res != *data_length) { 3.862 tpm_free(*data); 3.863 return -1; 3.864 -@@ -278,7 +277,7 @@ int tpm_restore_permanent_data(void) 3.865 +@@ -216,23 +218,30 @@ static int read_from_file(uint8_t **data 3.866 + int tpm_store_permanent_data(void) 3.867 + { 3.868 + uint8_t *buf, *ptr; 3.869 +- size_t buf_length, len; 3.870 ++ UINT32 buf_length, len; 3.871 + 3.872 + /* marshal data */ 3.873 +- buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags) 3.874 +- + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) + 2 3.875 +- + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data); 3.876 ++ buf_length = len = 4 + sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags) 3.877 ++ + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) 3.878 ++ + sizeof_TPM_STANY_FLAGS(tpmData.stany.flags) + 2 3.879 ++ + sizeof_TPM_STCLEAR_DATA(tpmData.stclear.data) 3.880 ++ + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data) 3.881 ++ + sizeof_TPM_STANY_DATA(tpmData.stany.data); 3.882 + buf = ptr = tpm_malloc(buf_length); 3.883 + if (buf == NULL 3.884 + || tpm_marshal_TPM_VERSION(&ptr, &len, &tpmData.permanent.data.version) 3.885 + || tpm_marshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags) 3.886 + || tpm_marshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags) 3.887 ++ || tpm_marshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags) 3.888 + || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.selfTestSucceeded) 3.889 + || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.owned) 3.890 +- || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) { 3.891 ++ || tpm_marshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data) 3.892 ++ || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data) 3.893 ++ || tpm_marshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) { 3.894 + tpm_free(buf); 3.895 + return -1; 3.896 + } 3.897 ++ 3.898 + if (write_to_file(buf, buf_length - len)) { 3.899 + tpm_free(buf); 3.900 + return -1; 3.901 +@@ -244,31 +253,36 @@ int tpm_store_permanent_data(void) 3.902 + int tpm_restore_permanent_data(void) 3.903 + { 3.904 + uint8_t *buf, *ptr; 3.905 +- size_t buf_length, len; 3.906 ++ size_t buf_length; 3.907 ++ UINT32 len; 3.908 + TPM_VERSION ver; 3.909 + 3.910 + /* read data */ 3.911 + if (read_from_file(&buf, &buf_length)) return -1; 3.912 + ptr = buf; 3.913 +- len = buf_length; 3.914 ++ len = (uint32_t) buf_length; 3.915 + /* unmarshal data */ 3.916 + if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver) 3.917 + || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION)) 3.918 + || tpm_unmarshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags) 3.919 + || tpm_unmarshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags) 3.920 ++ || tpm_unmarshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags) 3.921 + || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.selfTestSucceeded) 3.922 + || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.owned) 3.923 +- || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) { 3.924 ++ || tpm_unmarshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data) 3.925 ++ || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data) 3.926 ++ || tpm_unmarshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) { 3.927 + tpm_free(buf); 3.928 + return -1; 3.929 + } 3.930 ++ 3.931 + tpm_free(buf); 3.932 + return 0; 3.933 + } 3.934 3.935 int tpm_erase_permanent_data(void) 3.936 { 3.937 @@ -948,297 +962,9 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.938 return res; 3.939 } 3.940 3.941 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_data.c.orig tpm_emulator/tpm/tpm_data.c.orig 3.942 ---- tpm_emulator-0.3-x86_64/tpm/tpm_data.c.orig 1969-12-31 16:00:00.000000000 -0800 3.943 -+++ tpm_emulator/tpm/tpm_data.c.orig 2006-08-29 15:26:08.469991568 -0700 3.944 -@@ -0,0 +1,284 @@ 3.945 -+/* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.946 -+ * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.947 -+ * Swiss Federal Institute of Technology (ETH) Zurich 3.948 -+ * 3.949 -+ * This module is free software; you can redistribute it and/or modify 3.950 -+ * it under the terms of the GNU General Public License as published 3.951 -+ * by the Free Software Foundation; either version 2 of the License, 3.952 -+ * or (at your option) any later version. 3.953 -+ * 3.954 -+ * This module is distributed in the hope that it will be useful, 3.955 -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 3.956 -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3.957 -+ * GNU General Public License for more details. 3.958 -+ * 3.959 -+ * $Id: tpm_data.c 36 2005-10-26 20:31:19Z hstamer $ 3.960 -+ */ 3.961 -+ 3.962 -+#include "tpm_emulator.h" 3.963 -+#include "tpm_structures.h" 3.964 -+#include "tpm_marshalling.h" 3.965 -+#include "linux_module.h" 3.966 -+ 3.967 -+TPM_DATA tpmData; 3.968 -+ 3.969 -+BOOL tpm_get_physical_presence(void) 3.970 -+{ 3.971 -+ return (tpmData.stclear.flags.physicalPresence || TRUE); 3.972 -+} 3.973 -+ 3.974 -+static inline void init_pcr_attr(int pcr, BOOL reset, BYTE rl, BYTE el) 3.975 -+{ 3.976 -+ int i; 3.977 -+ tpmData.permanent.data.pcrAttrib[pcr].pcrReset = reset; 3.978 -+ for (i = 0; i < TPM_NUM_LOCALITY; i++) { 3.979 -+ tpmData.permanent.data.pcrAttrib[pcr].pcrResetLocal[i] = (rl & (1 << i)); 3.980 -+ tpmData.permanent.data.pcrAttrib[pcr].pcrExtendLocal[i] = (el & (1 << i)); 3.981 -+ } 3.982 -+} 3.983 -+ 3.984 -+void tpm_init_data(void) 3.985 -+{ 3.986 -+ /* endorsement key */ 3.987 -+ uint8_t ek_n[] = "\xa8\xdb\xa9\x42\xa8\xf3\xb8\x06\x85\x90\x76\x93\xad\xf7" 3.988 -+ "\x74\xec\x3f\xd3\x3d\x9d\xe8\x2e\xff\x15\xed\x0e\xce\x5f\x93" 3.989 -+ "\x92\xeb\xd1\x96\x2b\x72\x18\x81\x79\x12\x9d\x9c\x40\xd7\x1a" 3.990 -+ "\x21\xda\x5f\x56\xe0\xc9\x48\x31\xdd\x96\xdc\xbb\x45\xc6\x8e" 3.991 -+ "\xad\x58\x23\xcb\xbe\xbb\x13\x2d\x6b\x86\xc5\x57\xf5\xdd\x48" 3.992 -+ "\xc1\x3d\xcd\x4d\xda\x81\xc4\x43\x17\xaa\x05\x40\x33\x62\x0a" 3.993 -+ "\x59\xdb\x28\xcd\xb5\x08\x31\xbb\x06\xf5\xf7\x71\xae\x21\xa8" 3.994 -+ "\xf2\x2f\x0e\x17\x80\x5d\x9c\xdf\xaa\xe9\x89\x09\x54\x65\x2b" 3.995 -+ "\x46\xfb\x9d\xb2\x00\x70\x63\x0d\x9a\x6d\x3d\x5e\x11\x78\x65" 3.996 -+ "\x90\xe6\x26\xee\x77\xbe\x08\xff\x07\x60\x5a\xcc\xf1\x0a\xbd" 3.997 -+ "\x44\x92\x6b\xca\xb6\xce\x66\xf9\x93\x40\xae\xf3\x3e\x53\x02" 3.998 -+ "\x3c\xa6\x81\xb3\xbe\xad\x6e\x6c\xa6\xf0\xeb\xdf\xe9\xa2\x83" 3.999 -+ "\x36\x0e\x52\x0d\x64\x17\xd9\xff\xa1\x74\x7c\x2b\xbc\x6a\xcc" 3.1000 -+ "\xe5\x4e\xb4\x52\xd9\xec\x43\xbd\x26\x6a\x2b\x19\x19\x6e\x97" 3.1001 -+ "\xb8\x1d\x9f\x7b\xe7\x32\x2d\xdd\x7c\x51\xc8\xe4\xf3\x02\xd4" 3.1002 -+ "\x7c\x90\x44\xa0\x33\x72\x81\x75\xa9\x16\x27\x5c\x00\x1d\x07" 3.1003 -+ "\x81\xd4\xf7\xac\xcb\xfe\xd6\x60\x03\x6f\x7a\xcc\x00\xd1\xc4" 3.1004 -+ "\x85\x37"; 3.1005 -+ uint8_t ek_e[] = "\x01\x00\x01"; 3.1006 -+ uint8_t ek_p[] = "\xd7\xea\x61\x15\x8b\xa3\x71\xdf\xa8\x74\x77\xca\x88\x95" 3.1007 -+ "\xd0\x76\x17\x43\x2c\xf6\x23\x27\x44\xb9\x0e\x18\x35\x7e\xe4" 3.1008 -+ "\xc3\xcb\x13\x6e\xfc\x38\x02\x1e\x77\x26\x40\x9d\x17\xb2\x39" 3.1009 -+ "\x9c\x7f\x5f\x98\xe6\xf2\x55\x0c\x12\x05\x4c\xb3\x51\xae\x29" 3.1010 -+ "\xe7\xcd\xce\x41\x0b\x28\x4d\x97\x13\x4b\x60\xc8\xd8\x70\x81" 3.1011 -+ "\xf9\x1c\x12\x44\xdf\x53\x0a\x87\x9d\x33\x92\x4a\x34\x69\xf0" 3.1012 -+ "\x70\x5e\x1b\x5d\x65\xc7\x84\x90\xa2\x62\xdf\x83\x14\x10\x69" 3.1013 -+ "\xe2\xa7\x18\x43\xd7\x1f\x60\xc9\x03\x8f\xd6\xa4\xce\xb2\x9d" 3.1014 -+ "\x40\x37\x70\x17\x4c\xe3\x69\xd4\x59"; 3.1015 -+ uint8_t ek_q[] = "\xc8\x34\xd2\xd0\x7c\xfa\xdc\x68\xe2\x72\xd7\x92\xe2\x50" 3.1016 -+ "\x93\xfc\xbb\x72\x55\x4d\x6b\x7a\x0c\x0b\xcf\x87\x66\x1f\x81" 3.1017 -+ "\x71\xf3\x50\xcb\xaa\xe6\x43\x7e\xbe\x11\xc4\xec\x00\x53\xf4" 3.1018 -+ "\x78\x13\x2b\x59\x26\x4a\x9f\x91\x61\x8f\xa7\x07\x64\x11\x5a" 3.1019 -+ "\xf4\xaf\x9c\x9b\x5a\x5d\x69\x20\x17\x55\x74\xba\xd8\xe4\x59" 3.1020 -+ "\x39\x1a\x0a\x7b\x4a\x30\xf0\xc8\x7f\xd9\xaf\x72\xc5\xb6\x71" 3.1021 -+ "\xd1\xc0\x8b\x5b\xa2\x2e\xa7\x15\xca\x50\x75\x10\x48\x9c\x2b" 3.1022 -+ "\x18\xb9\x67\x8f\x5d\x64\xc3\x28\x9f\x2f\x16\x2f\x08\xda\x47" 3.1023 -+ "\xec\x86\x43\x0c\x80\x99\x07\x34\x0f"; 3.1024 -+ int i; 3.1025 -+ /* reset all data to NULL, FALSE or 0 */ 3.1026 -+ memset(&tpmData, 0, sizeof(tpmData)); 3.1027 -+ tpmData.permanent.data.tag = TPM_TAG_PERMANENT_DATA; 3.1028 -+ /* set permanent flags */ 3.1029 -+ tpmData.permanent.flags.tag = TPM_TAG_PERMANENT_FLAGS; 3.1030 -+ tpmData.permanent.flags.disable = FALSE; 3.1031 -+ tpmData.permanent.flags.deactivated = FALSE; 3.1032 -+ tpmData.permanent.flags.ownership = TRUE; 3.1033 -+ tpmData.permanent.flags.readPubek = TRUE; 3.1034 -+ tpmData.permanent.flags.allowMaintenance = TRUE; 3.1035 -+ tpmData.permanent.flags.enableRevokeEK = TRUE; 3.1036 -+ /* set TPM vision */ 3.1037 -+ tpmData.permanent.data.version.major = 1; 3.1038 -+ tpmData.permanent.data.version.minor = 2; 3.1039 -+ tpmData.permanent.data.version.revMajor = VERSION_MAJOR; 3.1040 -+ tpmData.permanent.data.version.revMinor = VERSION_MINOR; 3.1041 -+ /* setup PCR attributes */ 3.1042 -+ for (i = 0; i < min(16, TPM_NUM_PCR); i++) { 3.1043 -+ init_pcr_attr(i, FALSE, 0x00, 0x1f); 3.1044 -+ } 3.1045 -+ if (TPM_NUM_PCR >= 24) { 3.1046 -+ init_pcr_attr(16, TRUE, 0x1f, 0x1f); 3.1047 -+ init_pcr_attr(17, TRUE, 0x10, 0x1c); 3.1048 -+ init_pcr_attr(18, TRUE, 0x10, 0x1c); 3.1049 -+ init_pcr_attr(19, TRUE, 0x10, 0x0c); 3.1050 -+ init_pcr_attr(20, TRUE, 0x14, 0x0e); 3.1051 -+ init_pcr_attr(21, TRUE, 0x04, 0x04); 3.1052 -+ init_pcr_attr(22, TRUE, 0x04, 0x04); 3.1053 -+ init_pcr_attr(23, TRUE, 0x1f, 0x1f); 3.1054 -+ } 3.1055 -+ for (i = 24; i < TPM_NUM_PCR; i++) { 3.1056 -+ init_pcr_attr(i, TRUE, 0x00, 0x00); 3.1057 -+ } 3.1058 -+ /* set tick type */ 3.1059 -+ tpmData.permanent.data.tickType = TICK_INC; 3.1060 -+#ifdef TPM_GENERATE_EK 3.1061 -+ /* generate a new endorsement key */ 3.1062 -+ rsa_generate_key(&tpmData.permanent.data.endorsementKey, 2048); 3.1063 -+#else 3.1064 -+ /* setup endorsement key */ 3.1065 -+ rsa_import_key(&tpmData.permanent.data.endorsementKey, 3.1066 -+ RSA_MSB_FIRST, ek_n, 256, ek_e, 3, ek_p, ek_q); 3.1067 -+#endif 3.1068 -+#ifdef TPM_GENERATE_SEED_DAA 3.1069 -+ /* generate the DAA seed (cf. [TPM_Part2], v1.2 rev 85, Section 7.4) */ 3.1070 -+ tpm_get_random_bytes(tpmData.permanent.data.tpmDAASeed.digest, 3.1071 -+ sizeof(tpmData.permanent.data.tpmDAASeed.digest)); 3.1072 -+#else 3.1073 -+ /* FIXME: setup DAA seed */ 3.1074 -+ memcpy(tpmData.permanent.data.tpmDAASeed.digest, 3.1075 -+ "\x77\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 3.1076 -+ "\x00\x00\x00\x77", 20); 3.1077 -+#endif 3.1078 -+ 3.1079 -+ memcpy(tpmData.permanent.data.ekReset.nonce, "\xde\xad\xbe\xef", 4); 3.1080 -+} 3.1081 -+ 3.1082 -+void tpm_release_data(void) 3.1083 -+{ 3.1084 -+ int i; 3.1085 -+ /* release the EK, SRK as well as all other rsa keys */ 3.1086 -+ if (tpmData.permanent.data.endorsementKey.size > 0) 3.1087 -+ rsa_release_private_key(&tpmData.permanent.data.endorsementKey); 3.1088 -+ if (tpmData.permanent.data.srk.valid) 3.1089 -+ rsa_release_private_key(&tpmData.permanent.data.srk.key); 3.1090 -+ for (i = 0; i < TPM_MAX_KEYS; i++) 3.1091 -+ if (tpmData.permanent.data.keys[i].valid) 3.1092 -+ rsa_release_private_key(&tpmData.permanent.data.keys[i].key); 3.1093 -+} 3.1094 -+ 3.1095 -+#ifdef TPM_STORE_TO_FILE 3.1096 -+ 3.1097 -+#include <linux/fs.h> 3.1098 -+#include <linux/unistd.h> 3.1099 -+#include <asm/uaccess.h> 3.1100 -+ 3.1101 -+#define TPM_STORAGE_FILE "/var/tpm/tpm_emulator-1.2." STR(VERSION_MAJOR) "." STR(VERSION_MINOR) 3.1102 -+ 3.1103 -+static int write_to_file(uint8_t *data, size_t data_length) 3.1104 -+{ 3.1105 -+ int res; 3.1106 -+ struct file *fp; 3.1107 -+ mm_segment_t old_fs = get_fs(); 3.1108 -+ fp = filp_open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR); 3.1109 -+ if (IS_ERR(fp)) return -1; 3.1110 -+ set_fs(get_ds()); 3.1111 -+ res = fp->f_op->write(fp, data, data_length, &fp->f_pos); 3.1112 -+ set_fs(old_fs); 3.1113 -+ filp_close(fp, NULL); 3.1114 -+ return (res == data_length) ? 0 : -1; 3.1115 -+} 3.1116 -+ 3.1117 -+static int read_from_file(uint8_t **data, size_t *data_length) 3.1118 -+{ 3.1119 -+ int res; 3.1120 -+ struct file *fp; 3.1121 -+ mm_segment_t old_fs = get_fs(); 3.1122 -+ fp = filp_open(TPM_STORAGE_FILE, O_RDONLY, 0); 3.1123 -+ if (IS_ERR(fp)) return -1; 3.1124 -+ *data_length = (size_t)fp->f_dentry->d_inode->i_size; 3.1125 -+ /* *data_length = i_size_read(fp->f_dentry->d_inode); */ 3.1126 -+ *data = tpm_malloc(*data_length); 3.1127 -+ if (*data == NULL) { 3.1128 -+ filp_close(fp, NULL); 3.1129 -+ return -1; 3.1130 -+ } 3.1131 -+ set_fs(get_ds()); 3.1132 -+ res = fp->f_op->read(fp, *data, *data_length, &fp->f_pos); 3.1133 -+ set_fs(old_fs); 3.1134 -+ filp_close(fp, NULL); 3.1135 -+ if (res != *data_length) { 3.1136 -+ tpm_free(*data); 3.1137 -+ return -1; 3.1138 -+ } 3.1139 -+ return 0; 3.1140 -+} 3.1141 -+ 3.1142 -+#else 3.1143 -+ 3.1144 -+static int write_to_file(uint8_t *data, size_t data_length) 3.1145 -+{ 3.1146 -+ info("TPM_STORE_TO_FILE disabled, no data written"); 3.1147 -+ return 0; 3.1148 -+} 3.1149 -+ 3.1150 -+static int read_from_file(uint8_t **data, size_t *data_length) 3.1151 -+{ 3.1152 -+ info("TPM_STORE_TO_FILE disabled, no data read"); 3.1153 -+ return 0; 3.1154 -+} 3.1155 -+ 3.1156 -+#endif /* TPM_STORE_TO_FILE */ 3.1157 -+ 3.1158 -+int tpm_store_permanent_data(void) 3.1159 -+{ 3.1160 -+ uint8_t *buf, *ptr; 3.1161 -+ UINT32 buf_length, len; 3.1162 -+ 3.1163 -+ /* marshal data */ 3.1164 -+ buf_length = len = 4 + sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags) 3.1165 -+ + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) 3.1166 -+ + sizeof_TPM_STANY_FLAGS(tpmData.stany.flags) + 2 3.1167 -+ + sizeof_TPM_STCLEAR_DATA(tpmData.stclear.data) 3.1168 -+ + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data) 3.1169 -+ + sizeof_TPM_STANY_DATA(tpmData.stany.data); 3.1170 -+ buf = ptr = tpm_malloc(buf_length); 3.1171 -+ if (buf == NULL 3.1172 -+ || tpm_marshal_TPM_VERSION(&ptr, &len, &tpmData.permanent.data.version) 3.1173 -+ || tpm_marshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags) 3.1174 -+ || tpm_marshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags) 3.1175 -+ || tpm_marshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags) 3.1176 -+ || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.selfTestSucceeded) 3.1177 -+ || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.owned) 3.1178 -+ || tpm_marshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data) 3.1179 -+ || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data) 3.1180 -+ || tpm_marshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) { 3.1181 -+ tpm_free(buf); 3.1182 -+ return -1; 3.1183 -+ } 3.1184 -+ 3.1185 -+ if (write_to_file(buf, buf_length - len)) { 3.1186 -+ tpm_free(buf); 3.1187 -+ return -1; 3.1188 -+ } 3.1189 -+ tpm_free(buf); 3.1190 -+ return 0; 3.1191 -+} 3.1192 -+ 3.1193 -+int tpm_restore_permanent_data(void) 3.1194 -+{ 3.1195 -+ uint8_t *buf, *ptr; 3.1196 -+ size_t buf_length; 3.1197 -+ UINT32 len; 3.1198 -+ TPM_VERSION ver; 3.1199 -+ 3.1200 -+ /* read data */ 3.1201 -+ if (read_from_file(&buf, &buf_length)) return -1; 3.1202 -+ ptr = buf; 3.1203 -+ len = (uint32_t) buf_length; 3.1204 -+ /* unmarshal data */ 3.1205 -+ if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver) 3.1206 -+ || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION)) 3.1207 -+ || tpm_unmarshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags) 3.1208 -+ || tpm_unmarshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags) 3.1209 -+ || tpm_unmarshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags) 3.1210 -+ || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.selfTestSucceeded) 3.1211 -+ || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.owned) 3.1212 -+ || tpm_unmarshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data) 3.1213 -+ || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data) 3.1214 -+ || tpm_unmarshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) { 3.1215 -+ tpm_free(buf); 3.1216 -+ return -1; 3.1217 -+ } 3.1218 -+ 3.1219 -+ tpm_free(buf); 3.1220 -+ return 0; 3.1221 -+} 3.1222 -+ 3.1223 -+int tpm_erase_permanent_data(void) 3.1224 -+{ 3.1225 -+ int res = write_to_file("", 0); 3.1226 -+ return res; 3.1227 -+} 3.1228 -+ 3.1229 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c tpm_emulator/tpm/tpm_deprecated.c 3.1230 ---- tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c 2006-08-29 15:07:21.622298456 -0700 3.1231 -+++ tpm_emulator/tpm/tpm_deprecated.c 2006-08-29 15:26:17.122676160 -0700 3.1232 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_deprecated.c tpm_emulator/tpm/tpm_deprecated.c 3.1233 +--- orig/tpm_emulator-0.4/tpm/tpm_deprecated.c 2006-06-23 03:37:07.000000000 -0700 3.1234 ++++ tpm_emulator/tpm/tpm_deprecated.c 2006-07-24 14:35:35.000000000 -0700 3.1235 @@ -1,6 +1,7 @@ 3.1236 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.1237 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.1238 @@ -1265,9 +991,9 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.1239 authContextSize, &contextBlob); 3.1240 if (res != TPM_SUCCESS) return res; 3.1241 len = *authContextSize; 3.1242 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h tpm_emulator/tpm/tpm_emulator.h 3.1243 ---- tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h 2006-08-29 15:07:21.648294504 -0700 3.1244 -+++ tpm_emulator/tpm/tpm_emulator.h 2006-08-29 15:26:17.122676160 -0700 3.1245 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_emulator.h tpm_emulator/tpm/tpm_emulator.h 3.1246 +--- orig/tpm_emulator-0.4/tpm/tpm_emulator.h 2006-06-23 03:37:07.000000000 -0700 3.1247 ++++ tpm_emulator/tpm/tpm_emulator.h 2006-07-24 14:35:35.000000000 -0700 3.1248 @@ -1,5 +1,6 @@ 3.1249 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.1250 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.1251 @@ -1285,45 +1011,476 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.1252 #undef TPM_GENERATE_SEED_DAA 3.1253 3.1254 #define TPM_MANUFACTURER 0x4554485A /* 'ETHZ' */ 3.1255 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c tpm_emulator/tpm/tpm_integrity.c 3.1256 ---- tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c 2006-08-29 15:07:21.645294960 -0700 3.1257 -+++ tpm_emulator/tpm/tpm_integrity.c 2006-08-29 15:26:17.123676008 -0700 3.1258 -@@ -1,6 +1,7 @@ 3.1259 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.1260 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.1261 - * Swiss Federal Institute of Technology (ETH) Zurich 3.1262 -+ * Copyright (C) 2005 INTEL Corp 3.1263 - * 3.1264 - * This module is free software; you can redistribute it and/or modify 3.1265 - * it under the terms of the GNU General Public License as published 3.1266 -@@ -194,4 +195,3 @@ TPM_RESULT tpm_verify_pcr(TPM_KEY_DATA * 3.1267 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_marshalling.c tpm_emulator/tpm/tpm_marshalling.c 3.1268 +--- orig/tpm_emulator-0.4/tpm/tpm_marshalling.c 2006-06-23 03:37:07.000000000 -0700 3.1269 ++++ tpm_emulator/tpm/tpm_marshalling.c 2006-07-24 14:35:35.000000000 -0700 3.1270 +@@ -1312,7 +1312,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE * 3.1271 + 3.1272 + int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v) 3.1273 + { 3.1274 +- UINT32 m_len, e_len, q_len; 3.1275 ++ size_t m_len, e_len, q_len; 3.1276 + if (*length < sizeof_RSA((*v))) return -1; 3.1277 + if (v->size > 0) { 3.1278 + rsa_export_modulus(v, &(*ptr)[6], &m_len); 3.1279 +@@ -1460,6 +1460,66 @@ int tpm_unmarshal_TPM_PERMANENT_DATA(BYT 3.1280 + return 0; 3.1281 + } 3.1282 + 3.1283 ++int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v) 3.1284 ++{ 3.1285 ++ if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag) 3.1286 ++ || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceKey) 3.1287 ++ || tpm_marshal_TPM_COUNT_ID(ptr, length, v->countID) ) return -1; 3.1288 ++ 3.1289 ++ return 0; 3.1290 ++} 3.1291 ++ 3.1292 ++int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v) 3.1293 ++{ 3.1294 ++ if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag) 3.1295 ++ || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceKey) 3.1296 ++ || tpm_unmarshal_TPM_COUNT_ID(ptr, length, &v->countID) ) return -1; 3.1297 ++ 3.1298 ++ return 0; 3.1299 ++} 3.1300 ++ 3.1301 ++int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v) 3.1302 ++{ 3.1303 ++ UINT32 i; 3.1304 ++ if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag) 3.1305 ++ || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceSession) 3.1306 ++ || tpm_marshal_TPM_DIGEST(ptr, length, &v->auditDigest) 3.1307 ++ || tpm_marshal_BOOL(ptr, length, v->auditSession) 3.1308 ++ || tpm_marshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks) 3.1309 ++ || tpm_marshal_UINT32(ptr, length, v->contextCount) 3.1310 ++ || tpm_marshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1; 3.1311 ++ for (i = 0; i < TPM_MAX_SESSIONS; i++) { 3.1312 ++ if (tpm_marshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1; 3.1313 ++ } 3.1314 ++ for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) { 3.1315 ++ if (tpm_marshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1; 3.1316 ++ } 3.1317 ++ if (tpm_marshal_TPM_TRANSHANDLE(ptr, length, v->transExclusive)) return -1; 3.1318 ++ 3.1319 ++ return 0; 3.1320 ++} 3.1321 ++ 3.1322 ++int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v) 3.1323 ++{ 3.1324 ++ UINT32 i; 3.1325 ++ if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag) 3.1326 ++ || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceSession) 3.1327 ++ || tpm_unmarshal_TPM_DIGEST(ptr, length, &v->auditDigest) 3.1328 ++ || tpm_unmarshal_BOOL(ptr, length, &v->auditSession) 3.1329 ++ || tpm_unmarshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks) 3.1330 ++ || tpm_unmarshal_UINT32(ptr, length, &v->contextCount) 3.1331 ++ || tpm_unmarshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1; 3.1332 ++ for (i = 0; i < TPM_MAX_SESSIONS; i++) { 3.1333 ++ if (tpm_unmarshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1; 3.1334 ++ } 3.1335 ++ for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) { 3.1336 ++ if (tpm_unmarshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1; 3.1337 ++ } 3.1338 ++ if (tpm_unmarshal_TPM_TRANSHANDLE(ptr, length, &v->transExclusive)) return -1; 3.1339 ++ 3.1340 ++ return 0; 3.1341 ++} 3.1342 ++ 3.1343 + int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v) 3.1344 + { 3.1345 + if (tpm_marshal_BYTE(ptr, length, v->type) 3.1346 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_marshalling.h tpm_emulator/tpm/tpm_marshalling.h 3.1347 +--- orig/tpm_emulator-0.4/tpm/tpm_marshalling.h 2006-06-23 03:37:07.000000000 -0700 3.1348 ++++ tpm_emulator/tpm/tpm_marshalling.h 2006-07-24 14:35:35.000000000 -0700 3.1349 +@@ -432,6 +432,12 @@ int tpm_unmarshal_TPM_KEY_DATA(BYTE **pt 3.1350 + int tpm_marshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *); 3.1351 + int tpm_unmarshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *); 3.1352 + 3.1353 ++int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v); 3.1354 ++int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v); 3.1355 ++ 3.1356 ++int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v); 3.1357 ++int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v); 3.1358 ++ 3.1359 + int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v); 3.1360 + int tpm_unmarshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v); 3.1361 + 3.1362 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_owner.c tpm_emulator/tpm/tpm_owner.c 3.1363 +--- orig/tpm_emulator-0.4/tpm/tpm_owner.c 2006-06-23 03:37:07.000000000 -0700 3.1364 ++++ tpm_emulator/tpm/tpm_owner.c 2006-07-24 14:35:35.000000000 -0700 3.1365 +@@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO 3.1366 + TPM_RESULT res; 3.1367 + rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey; 3.1368 + TPM_KEY_DATA *srk = &tpmData.permanent.data.srk; 3.1369 +- UINT32 buf_size = ek->size >> 3; 3.1370 ++ size_t buf_size = ek->size >> 3, key_length; 3.1371 + BYTE buf[buf_size]; 3.1372 + 3.1373 + info("TPM_TakeOwnership()"); 3.1374 +@@ -173,7 +173,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO 3.1375 + return TPM_FAIL; 3.1376 } 3.1377 + rsa_export_modulus(&srk->key, srkPub->pubKey.key, 3.1378 +- &srkPub->pubKey.keyLength); 3.1379 ++ &key_length); 3.1380 ++ srkPub->pubKey.keyLength = (UINT32) key_length; 3.1381 + /* setup tpmProof and set state to owned */ 3.1382 + tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 3.1383 + sizeof(tpmData.permanent.data.tpmProof.nonce)); 3.1384 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_startup.c tpm_emulator/tpm/tpm_startup.c 3.1385 +--- orig/tpm_emulator-0.4/tpm/tpm_startup.c 2006-06-23 03:37:07.000000000 -0700 3.1386 ++++ tpm_emulator/tpm/tpm_startup.c 2006-07-24 14:35:35.000000000 -0700 3.1387 +@@ -41,26 +41,29 @@ void TPM_Init(TPM_STARTUP_TYPE startupTy 3.1388 + TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE startupType) 3.1389 + { 3.1390 + int i; 3.1391 ++ int restore_fail; 3.1392 + info("TPM_Startup(%d)", startupType); 3.1393 + if (tpmData.stany.flags.postInitialise == FALSE) return TPM_INVALID_POSTINIT; 3.1394 +- /* reset STANY_FLAGS */ 3.1395 +- SET_TO_ZERO(&tpmData.stany.flags); 3.1396 +- tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS; 3.1397 +- /* reset STANY_DATA (invalidates ALL sessions) */ 3.1398 +- SET_TO_ZERO(&tpmData.stany.data); 3.1399 +- tpmData.stany.data.tag = TPM_TAG_STANY_DATA; 3.1400 +- /* init session-context nonce */ 3.1401 +- SET_TO_RAND(&tpmData.stany.data.contextNonceSession); 3.1402 ++ 3.1403 ++ /* try and restore state to get EK, SRK, etc */ 3.1404 ++ restore_fail = tpm_restore_permanent_data(); 3.1405 ++ 3.1406 + /* set data and flags according to the given startup type */ 3.1407 + if (startupType == TPM_ST_CLEAR) { 3.1408 +- /* if available, restore permanent data */ 3.1409 +- tpm_restore_permanent_data(); 3.1410 ++ /* reset STANY_FLAGS */ 3.1411 ++ SET_TO_ZERO(&tpmData.stany.flags); 3.1412 ++ tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS; 3.1413 ++ /* reset STANY_DATA (invalidates ALL sessions) */ 3.1414 ++ SET_TO_ZERO(&tpmData.stany.data); 3.1415 ++ tpmData.stany.data.tag = TPM_TAG_STANY_DATA; 3.1416 ++ /* init session-context nonce */ 3.1417 ++ SET_TO_RAND(&tpmData.stany.data.contextNonceSession); 3.1418 + /* reset PCR values */ 3.1419 + for (i = 0; i < TPM_NUM_PCR; i++) { 3.1420 +- if (tpmData.permanent.data.pcrAttrib[i].pcrReset) 3.1421 +- SET_TO_ZERO(tpmData.permanent.data.pcrValue[i].digest); 3.1422 ++ if (!tpmData.permanent.data.pcrAttrib[i].pcrReset) 3.1423 ++ SET_TO_ZERO(&tpmData.permanent.data.pcrValue[i].digest); 3.1424 + else 3.1425 +- SET_TO_0xFF(tpmData.permanent.data.pcrValue[i].digest); 3.1426 ++ SET_TO_0xFF(&tpmData.permanent.data.pcrValue[i].digest); 3.1427 + } 3.1428 + /* reset STCLEAR_FLAGS */ 3.1429 + SET_TO_ZERO(&tpmData.stclear.flags); 3.1430 +@@ -79,7 +82,8 @@ TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE 3.1431 + /* init key-context nonce */ 3.1432 + SET_TO_RAND(&tpmData.stclear.data.contextNonceKey); 3.1433 + } else if (startupType == TPM_ST_STATE) { 3.1434 +- if (tpm_restore_permanent_data()) { 3.1435 ++ /* restore must have been successful for TPM_ST_STATE */ 3.1436 ++ if (restore_fail) { 3.1437 + error("restoring permanent data failed"); 3.1438 + tpmData.permanent.data.testResult = "tpm_restore_permanent_data() failed"; 3.1439 + tpmData.permanent.flags.selfTestSucceeded = FALSE; 3.1440 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_storage.c tpm_emulator/tpm/tpm_storage.c 3.1441 +--- orig/tpm_emulator-0.4/tpm/tpm_storage.c 2006-06-23 03:37:07.000000000 -0700 3.1442 ++++ tpm_emulator/tpm/tpm_storage.c 2006-07-24 14:35:35.000000000 -0700 3.1443 +@@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke 3.1444 + BYTE *enc, UINT32 *enc_size) 3.1445 + { 3.1446 + UINT32 len; 3.1447 ++ size_t enc_size32 = *enc_size; 3.1448 + BYTE *buf, *ptr; 3.1449 + rsa_public_key_t pub_key; 3.1450 + int scheme; 3.1451 +@@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke 3.1452 + if (buf == NULL 3.1453 + || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal) 3.1454 + || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)), 3.1455 +- enc, enc_size)) { 3.1456 ++ enc, &enc_size32)) { 3.1457 + tpm_free(buf); 3.1458 + rsa_release_public_key(&pub_key); 3.1459 + return -1; 3.1460 +@@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke 3.1461 + int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 3.1462 + TPM_SEALED_DATA *seal, BYTE **buf) 3.1463 + { 3.1464 +- UINT32 len; 3.1465 ++ size_t len; 3.1466 ++ UINT32 len32; 3.1467 + BYTE *ptr; 3.1468 + int scheme; 3.1469 + switch (key->encScheme) { 3.1470 +@@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke 3.1471 + len = enc_size; 3.1472 + *buf = ptr = tpm_malloc(len); 3.1473 + if (*buf == NULL 3.1474 +- || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) 3.1475 +- || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) { 3.1476 ++ || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){ 3.1477 ++ tpm_free(*buf); 3.1478 ++ return -1; 3.1479 ++ } 3.1480 ++ len32 = len; 3.1481 ++ if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) { 3.1482 + tpm_free(*buf); 3.1483 + return -1; 3.1484 + } 3.1485 +@@ -240,11 +246,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par 3.1486 + 3.1487 + TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize, 3.1488 + BYTE *inData, TPM_AUTH *auth1, 3.1489 +- UINT32 *outDataSize, BYTE **outData) 3.1490 ++ UINT32 *outDataSize32, BYTE **outData) 3.1491 + { 3.1492 + TPM_RESULT res; 3.1493 + TPM_KEY_DATA *key; 3.1494 + int scheme; 3.1495 ++ size_t outDataSize; 3.1496 + 3.1497 + info("TPM_UnBind()"); 3.1498 + /* get key */ 3.1499 +@@ -262,8 +269,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key 3.1500 + /* the size of the input data muss be greater than zero */ 3.1501 + if (inDataSize == 0) return TPM_BAD_PARAMETER; 3.1502 + /* decrypt data */ 3.1503 +- *outDataSize = inDataSize; 3.1504 +- *outData = tpm_malloc(*outDataSize); 3.1505 ++ outDataSize = inDataSize; 3.1506 ++ *outData = tpm_malloc(outDataSize); 3.1507 + if (*outData == NULL) return TPM_NOSPACE; 3.1508 + switch (key->encScheme) { 3.1509 + case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break; 3.1510 +@@ -271,20 +278,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key 3.1511 + default: tpm_free(*outData); return TPM_DECRYPT_ERROR; 3.1512 + } 3.1513 + if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 3.1514 +- *outData, outDataSize)) { 3.1515 ++ *outData, &outDataSize)) { 3.1516 + tpm_free(*outData); 3.1517 + return TPM_DECRYPT_ERROR; 3.1518 + } 3.1519 + /* verify data if it is of type TPM_BOUND_DATA */ 3.1520 + if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 3.1521 + || key->keyUsage != TPM_KEY_LEGACY) { 3.1522 +- if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) { 3.1523 ++ if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) { 3.1524 + tpm_free(*outData); 3.1525 + return TPM_DECRYPT_ERROR; 3.1526 + } 3.1527 +- *outDataSize -= 5; 3.1528 +- memmove(*outData, &(*outData)[5], *outDataSize); 3.1529 ++ outDataSize -= 5; 3.1530 ++ memmove(*outData, &(*outData)[5], outDataSize); 3.1531 + } 3.1532 ++ *outDataSize32 = (UINT32) outDataSize; 3.1533 return TPM_SUCCESS; 3.1534 } 3.1535 -- 3.1536 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_structures.h tpm_emulator/tpm/tpm_structures.h 3.1537 ---- tpm_emulator-0.3-x86_64/tpm/tpm_structures.h 2006-08-29 15:08:20.545340792 -0700 3.1538 -+++ tpm_emulator/tpm/tpm_structures.h 2006-08-29 15:26:17.125675704 -0700 3.1539 -@@ -1,6 +1,7 @@ 3.1540 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.1541 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.1542 - * Swiss Federal Institute of Technology (ETH) Zurich 3.1543 -+ * Copyright (C) 2005 INTEL Corp 3.1544 - * 3.1545 - * This module is free software; you can redistribute it and/or modify 3.1546 - * it under the terms of the GNU General Public License as published 3.1547 -@@ -18,7 +19,7 @@ 3.1548 - #ifndef _TPM_STRUCTURES_H_ 3.1549 - #define _TPM_STRUCTURES_H_ 3.1550 + 3.1551 +@@ -334,12 +342,13 @@ int compute_pubkey_digest(TPM_PUBKEY *ke 3.1552 + } 3.1553 + 3.1554 + int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store, 3.1555 +- BYTE *enc, UINT32 *enc_size) 3.1556 ++ BYTE *enc, UINT32 *enc_size32) 3.1557 + { 3.1558 + UINT32 len; 3.1559 + BYTE *buf, *ptr; 3.1560 + rsa_public_key_t pub_key; 3.1561 + int scheme; 3.1562 ++ size_t enc_size; 3.1563 + switch (key->encScheme) { 3.1564 + case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break; 3.1565 + case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break; 3.1566 +@@ -351,11 +360,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke 3.1567 + if (buf == NULL 3.1568 + || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store) 3.1569 + || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)), 3.1570 +- enc, enc_size)) { 3.1571 ++ enc, &enc_size)) { 3.1572 + tpm_free(buf); 3.1573 + rsa_release_public_key(&pub_key); 3.1574 + return -1; 3.1575 + } 3.1576 ++ *enc_size32 = (UINT32) enc_size; 3.1577 + tpm_free(buf); 3.1578 + rsa_release_public_key(&pub_key); 3.1579 + return 0; 3.1580 +@@ -364,7 +374,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke 3.1581 + int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 3.1582 + TPM_STORE_ASYMKEY *store, BYTE **buf) 3.1583 + { 3.1584 +- UINT32 len; 3.1585 ++ UINT32 len32; 3.1586 ++ size_t len; 3.1587 + BYTE *ptr; 3.1588 + int scheme; 3.1589 + switch (key->encScheme) { 3.1590 +@@ -375,8 +386,12 @@ int decrypt_private_key(TPM_KEY_DATA *ke 3.1591 + len = enc_size; 3.1592 + *buf = ptr = tpm_malloc(len); 3.1593 + if (*buf == NULL 3.1594 +- || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) 3.1595 +- || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) { 3.1596 ++ || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) { 3.1597 ++ tpm_free(*buf); 3.1598 ++ return -1; 3.1599 ++ } 3.1600 ++ len32 = (UINT32) len; 3.1601 ++ if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) { 3.1602 + tpm_free(*buf); 3.1603 + return -1; 3.1604 + } 3.1605 +@@ -394,7 +409,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN 3.1606 + TPM_SESSION_DATA *session; 3.1607 + TPM_STORE_ASYMKEY store; 3.1608 + rsa_private_key_t rsa; 3.1609 +- UINT32 key_length; 3.1610 ++ size_t key_length; 3.1611 3.1612 --#include <linux/types.h> 3.1613 -+//#include <linux/types.h> 3.1614 - #include "crypto/rsa.h" 3.1615 + info("TPM_CreateWrapKey()"); 3.1616 + /* get parent key */ 3.1617 +@@ -450,11 +465,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN 3.1618 + } 3.1619 + } 3.1620 + /* generate key and store it */ 3.1621 +- key_length = keyInfo->algorithmParms.parms.rsa.keyLength; 3.1622 +- if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL; 3.1623 +- wrappedKey->pubKey.keyLength = key_length >> 3; 3.1624 ++ if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 3.1625 ++ return TPM_FAIL; 3.1626 ++ wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3; 3.1627 + wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength); 3.1628 +- store.privKey.keyLength = key_length >> 4; 3.1629 ++ store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4; 3.1630 + store.privKey.key = tpm_malloc(store.privKey.keyLength); 3.1631 + wrappedKey->encDataSize = parent->key.size >> 3; 3.1632 + wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize); 3.1633 +@@ -466,9 +481,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN 3.1634 + tpm_free(wrappedKey->encData); 3.1635 + return TPM_NOSPACE; 3.1636 + } 3.1637 +- rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 3.1638 +- &wrappedKey->pubKey.keyLength); 3.1639 +- rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength); 3.1640 ++ rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 3.1641 ++ &key_length); 3.1642 ++ wrappedKey->pubKey.keyLength = (UINT32) key_length; 3.1643 ++ rsa_export_prime1(&rsa, store.privKey.key, &key_length); 3.1644 ++ store.privKey.keyLength = (UINT32) key_length; 3.1645 + rsa_release_private_key(&rsa); 3.1646 + /* compute the digest of the wrapped key (without encData) */ 3.1647 + if (compute_key_digest(wrappedKey, &store.pubDataDigest)) { 3.1648 +@@ -602,6 +619,7 @@ TPM_RESULT TPM_LoadKey2(TPM_KEY_HANDLE p 3.1649 + 3.1650 + int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms) 3.1651 + { 3.1652 ++ size_t key_length; 3.1653 + parms->algorithmID = TPM_ALG_RSA; 3.1654 + parms->encScheme = key->encScheme; 3.1655 + parms->sigScheme = key->sigScheme; 3.1656 +@@ -611,7 +629,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke 3.1657 + parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize); 3.1658 + if (parms->parms.rsa.exponent == NULL) return -1; 3.1659 + rsa_export_exponent(&key->key, parms->parms.rsa.exponent, 3.1660 +- &parms->parms.rsa.exponentSize); 3.1661 ++ &key_length); 3.1662 ++ parms->parms.rsa.exponentSize = (UINT32) key_length; 3.1663 + parms->parmSize = 12 + parms->parms.rsa.exponentSize; 3.1664 + return 0; 3.1665 + } 3.1666 +@@ -622,6 +641,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 3.1667 + TPM_RESULT res; 3.1668 + TPM_KEY_DATA *key; 3.1669 + TPM_DIGEST digest; 3.1670 ++ size_t key_length; 3.1671 + info("TPM_GetPubKey()"); 3.1672 + /* get key */ 3.1673 + if (keyHandle == TPM_KH_SRK 3.1674 +@@ -650,8 +670,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 3.1675 + pubKey->pubKey.keyLength = key->key.size >> 3; 3.1676 + pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength); 3.1677 + if (pubKey->pubKey.key == NULL) return TPM_NOSPACE; 3.1678 +- rsa_export_modulus(&key->key, pubKey->pubKey.key, 3.1679 +- &pubKey->pubKey.keyLength); 3.1680 ++ rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 3.1681 ++ pubKey->pubKey.keyLength = (UINT32) key_length; 3.1682 + if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) { 3.1683 + error("TPM_GetPubKey(): tpm_setup_key_parms() failed."); 3.1684 + tpm_free(pubKey->pubKey.key); 3.1685 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_structures.h tpm_emulator/tpm/tpm_structures.h 3.1686 +--- orig/tpm_emulator-0.4/tpm/tpm_structures.h 2006-06-23 03:37:07.000000000 -0700 3.1687 ++++ tpm_emulator/tpm/tpm_structures.h 2006-07-24 14:35:35.000000000 -0700 3.1688 +@@ -1958,6 +1958,7 @@ typedef struct tdTPM_DAA_ISSUER { 3.1689 + TPM_DIGEST DAA_digest_gamma; 3.1690 + BYTE DAA_generic_q[26]; 3.1691 + } TPM_DAA_ISSUER; 3.1692 ++#define sizeof_TPM_DAA_ISSUER(s) (2 + (20 * 6) + 26 ) 3.1693 3.1694 /* 3.1695 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_testing.c tpm_emulator/tpm/tpm_testing.c 3.1696 ---- tpm_emulator-0.3-x86_64/tpm/tpm_testing.c 2006-08-29 15:07:21.646294808 -0700 3.1697 -+++ tpm_emulator/tpm/tpm_testing.c 2006-08-29 15:26:17.127675400 -0700 3.1698 + * TPM_DAA_TPM ([TPM_Part2], Section 22.4) 3.1699 +@@ -1973,6 +1974,7 @@ typedef struct tdTPM_DAA_TPM { 3.1700 + TPM_DIGEST DAA_rekey; 3.1701 + UINT32 DAA_count; 3.1702 + } TPM_DAA_TPM; 3.1703 ++#define sizeof_TPM_DAA_TPM(s) (2 + (4 * 20) + 4) 3.1704 + 3.1705 + /* 3.1706 + * TPM_DAA_CONTEXT ([TPM_Part2], Section 22.5) 3.1707 +@@ -1987,6 +1989,7 @@ typedef struct tdTPM_DAA_CONTEXT { 3.1708 + BYTE DAA_scratch[256]; 3.1709 + BYTE DAA_stage; 3.1710 + } TPM_DAA_CONTEXT; 3.1711 ++#define sizeof_TPM_DAA_CONTEXT(s) (2 + (3 * 20) + 256 + 1) 3.1712 + 3.1713 + /* 3.1714 + * TPM_DAA_JOINDATA ([TPM_Part2], Section 22.6) 3.1715 +@@ -1998,6 +2001,7 @@ typedef struct tdTPM_DAA_JOINDATA { 3.1716 + BYTE DAA_join_u1[138]; 3.1717 + TPM_DIGEST DAA_digest_n0; 3.1718 + } TPM_DAA_JOINDATA; 3.1719 ++#define sizeof_TPM_DAA_JOINDATA(s) (1 + 1 + 20) 3.1720 + 3.1721 + /* 3.1722 + * TPM_DAA_BLOB ([TPM_Part2], Section 22.8) 3.1723 +@@ -2202,6 +2206,7 @@ typedef struct tdTPM_STCLEAR_DATA { 3.1724 + //UINT32 ownerReference; 3.1725 + //BOOL disableResetLock; 3.1726 + } TPM_STCLEAR_DATA; 3.1727 ++#define sizeof_TPM_STCLEAR_DATA(s) (2 + 20 + 4) 3.1728 + 3.1729 + /* 3.1730 + * TPM_SESSION_DATA 3.1731 +@@ -2238,6 +2243,11 @@ typedef struct tdTPM_DAA_SESSION_DATA { 3.1732 + TPM_DAA_JOINDATA DAA_joinSession; 3.1733 + TPM_HANDLE handle; 3.1734 + } TPM_DAA_SESSION_DATA; 3.1735 ++#define sizeof_TPM_DAA_SESSION_DATA(s) ( 1 \ 3.1736 ++ + sizeof_TPM_DAA_ISSUER(s.DAA_issuerSettings) \ 3.1737 ++ + sizeof_TPM_DAA_TPM(s.DAA_tpmSpecific) \ 3.1738 ++ + sizeof_TPM_DAA_CONTEXT(s.DAA_session) \ 3.1739 ++ + sizeof_TPM_DAA_JOINDATA(s.DAA_joinSession) + 4) 3.1740 + 3.1741 + /* 3.1742 + * TPM_STANY_DATA ([TPM_Part2], Section 7.6) 3.1743 +@@ -2262,6 +2272,11 @@ typedef struct tdTPM_STANY_DATA { 3.1744 + TPM_DAAHANDLE currentDAA; 3.1745 + TPM_TRANSHANDLE transExclusive; 3.1746 + } TPM_STANY_DATA; 3.1747 ++#define sizeof_TPM_STANY_DATA(s) (2 + 20 + 20 + 1 \ 3.1748 ++ + sizeof_TPM_CURRENT_TICKS(s.currentTicks) \ 3.1749 ++ + 4 + (4 * TPM_MAX_SESSION_LIST) \ 3.1750 ++ + (sizeof_TPM_SESSION_DATA(s.sessions[0]) * TPM_MAX_SESSION_LIST) \ 3.1751 ++ + (sizeof_TPM_DAA_SESSION_DATA(s.sessionsDAA[0]) * TPM_MAX_SESSIONS_DAA) + 4) 3.1752 + 3.1753 + /* 3.1754 + * TPM_DATA 3.1755 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_testing.c tpm_emulator/tpm/tpm_testing.c 3.1756 +--- orig/tpm_emulator-0.4/tpm/tpm_testing.c 2006-06-23 03:37:07.000000000 -0700 3.1757 ++++ tpm_emulator/tpm/tpm_testing.c 2006-07-24 14:35:35.000000000 -0700 3.1758 @@ -1,6 +1,7 @@ 3.1759 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.1760 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.1761 @@ -1439,9 +1596,9 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.1762 rsa_private_key_t priv_key; 3.1763 rsa_public_key_t pub_key; 3.1764 3.1765 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c tpm_emulator/tpm/tpm_ticks.c 3.1766 ---- tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c 2006-08-29 15:07:21.646294808 -0700 3.1767 -+++ tpm_emulator/tpm/tpm_ticks.c 2006-08-29 15:26:17.128675248 -0700 3.1768 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_ticks.c tpm_emulator/tpm/tpm_ticks.c 3.1769 +--- orig/tpm_emulator-0.4/tpm/tpm_ticks.c 2006-06-23 03:37:07.000000000 -0700 3.1770 ++++ tpm_emulator/tpm/tpm_ticks.c 2006-07-24 14:35:35.000000000 -0700 3.1771 @@ -1,6 +1,7 @@ 3.1772 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.1773 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3.1774 @@ -1450,7 +1607,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.1775 * 3.1776 * This module is free software; you can redistribute it and/or modify 3.1777 * it under the terms of the GNU General Public License as published 3.1778 -@@ -37,9 +38,7 @@ TPM_RESULT TPM_SetTickType(TPM_TICKTYPE 3.1779 +@@ -39,9 +40,7 @@ TPM_RESULT TPM_SetTickType(TPM_TICKTYPE 3.1780 TPM_RESULT TPM_GetTicks(TPM_CURRENT_TICKS *currentTime) 3.1781 { 3.1782 info("TPM_GetTicks()"); 3.1783 @@ -1461,7 +1618,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.1784 } 3.1785 3.1786 TPM_RESULT TPM_TickStampBlob(TPM_KEY_HANDLE keyHandle, TPM_NONCE *antiReplay, 3.1787 -@@ -47,61 +46,12 @@ TPM_RESULT TPM_TickStampBlob(TPM_KEY_HAN 3.1788 +@@ -49,64 +48,11 @@ TPM_RESULT TPM_TickStampBlob(TPM_KEY_HAN 3.1789 TPM_CURRENT_TICKS *currentTicks, 3.1790 UINT32 *sigSize, BYTE **sig) 3.1791 { 3.1792 @@ -1493,7 +1650,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.1793 - } 3.1794 - memcpy(&info[0], "\x05\x00TSTP", 6); 3.1795 - memcpy(&info[6], antiReplay->nonce, 20); 3.1796 -- *(UINT32*)&info[26] = cpu_to_be32(20 3.1797 +- *(UINT32*)&info[26] = CPU_TO_BE32(20 3.1798 - + sizeof_TPM_CURRENT_TICKS(currentTicks)); 3.1799 - memcpy(&info[30], digestToStamp->digest, sizeof(TPM_DIGEST)); 3.1800 - p = &info[30 + sizeof(TPM_DIGEST)]; 3.1801 @@ -1513,91 +1670,45 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 3.1802 - if (tpmData.stany.data.currentTicks.tag == 0) { 3.1803 - tpmData.stany.data.currentTicks.tag = TPM_TAG_CURRENT_TICKS; 3.1804 - tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks(); 3.1805 +-/* removed since v1.2 rev 94 3.1806 - tpmData.stany.data.currentTicks.tickType = tpmData.permanent.data.tickType; 3.1807 +-*/ 3.1808 - tpm_get_random_bytes(tpmData.stany.data.currentTicks.tickNonce.nonce, 3.1809 - sizeof(TPM_NONCE)); 3.1810 - tpmData.stany.data.currentTicks.tickRate = 1; 3.1811 +-/* removed since v1.2 rev 94 3.1812 - tpmData.stany.data.currentTicks.tickSecurity = TICK_SEC_NO_CHECK; 3.1813 +-*/ 3.1814 - } else { 3.1815 - tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks(); 3.1816 - } 3.1817 } 3.1818 - 3.1819 3.1820 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_transport.c tpm_emulator/tpm/tpm_transport.c 3.1821 ---- tpm_emulator-0.3-x86_64/tpm/tpm_transport.c 2006-08-29 15:07:21.647294656 -0700 3.1822 -+++ tpm_emulator/tpm/tpm_transport.c 2006-08-29 15:26:17.129675096 -0700 3.1823 -@@ -59,7 +59,7 @@ static int decrypt_transport_auth(TPM_KE 3.1824 - static void transport_log_in(TPM_COMMAND_CODE ordinal, BYTE parameters[20], 3.1825 - BYTE pubKeyHash[20], TPM_DIGEST *transDigest) 3.1826 - { 3.1827 -- UINT32 tag = cpu_to_be32(TPM_TAG_TRANSPORT_LOG_IN); 3.1828 -+ UINT32 tag = CPU_TO_BE32(TPM_TAG_TRANSPORT_LOG_IN); 3.1829 - BYTE *ptr, buf[sizeof_TPM_TRANSPORT_LOG_IN(x)]; 3.1830 - UINT32 len = sizeof(buf); 3.1831 - sha1_ctx_t sha1; 3.1832 -@@ -76,7 +76,7 @@ static void transport_log_in(TPM_COMMAND 3.1833 - static void transport_log_out(TPM_CURRENT_TICKS *currentTicks, BYTE parameters[20], 3.1834 - TPM_MODIFIER_INDICATOR locality, TPM_DIGEST *transDigest) 3.1835 - { 3.1836 -- UINT32 tag = cpu_to_be32(TPM_TAG_TRANSPORT_LOG_OUT); 3.1837 -+ UINT32 tag = CPU_TO_BE32(TPM_TAG_TRANSPORT_LOG_OUT); 3.1838 - BYTE *ptr, buf[sizeof_TPM_TRANSPORT_LOG_OUT(x)]; 3.1839 - UINT32 len = sizeof(buf); 3.1840 - sha1_ctx_t sha1; 3.1841 -@@ -191,7 +191,7 @@ static void decrypt_wrapped_command(BYTE 3.1842 +diff -uprN orig/tpm_emulator-0.4/tpm/tpm_transport.c tpm_emulator/tpm/tpm_transport.c 3.1843 +--- orig/tpm_emulator-0.4/tpm/tpm_transport.c 2006-06-23 03:37:07.000000000 -0700 3.1844 ++++ tpm_emulator/tpm/tpm_transport.c 2006-07-24 14:35:35.000000000 -0700 3.1845 +@@ -189,7 +189,7 @@ static void decrypt_wrapped_command(BYTE 3.1846 + sha1_init(&sha1); 3.1847 + sha1_update(&sha1, auth->nonceEven.nonce, sizeof(auth->nonceEven.nonce)); 3.1848 sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce)); 3.1849 - sha1_update(&sha1, "in", 2); 3.1850 - sha1_update(&sha1, secret, sizeof(TPM_SECRET)); 3.1851 -- j = cpu_to_be32(i); 3.1852 -+ j = CPU_TO_BE32(i); 3.1853 - sha1_update(&sha1, (BYTE*)&j, 4); 3.1854 - sha1_final(&sha1, mask); 3.1855 - for (j = 0; j < sizeof(mask) && buf_len > 0; j++) { 3.1856 -@@ -213,7 +213,7 @@ static void encrypt_wrapped_command(BYTE 3.1857 - sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce)); 3.1858 - sha1_update(&sha1, "out", 3); 3.1859 +- sha1_update(&sha1, "in", 2); 3.1860 ++ sha1_update(&sha1, (BYTE*)"in", 2); 3.1861 sha1_update(&sha1, secret, sizeof(TPM_SECRET)); 3.1862 -- j = cpu_to_be32(i); 3.1863 -+ j = CPU_TO_BE32(i); 3.1864 + j = CPU_TO_BE32(i); 3.1865 sha1_update(&sha1, (BYTE*)&j, 4); 3.1866 - sha1_final(&sha1, mask); 3.1867 - for (j = 0; j < sizeof(mask) && buf_len > 0; j++) { 3.1868 -@@ -253,9 +253,9 @@ TPM_RESULT TPM_ExecuteTransport(UINT32 i 3.1869 - /* verify authorization */ 3.1870 - tpm_compute_in_param_digest(&req); 3.1871 - sha1_init(&sha1); 3.1872 -- res = cpu_to_be32(TPM_ORD_ExecuteTransport); 3.1873 -+ res = CPU_TO_BE32(TPM_ORD_ExecuteTransport); 3.1874 - sha1_update(&sha1, (BYTE*)&res, 4); 3.1875 -- res = cpu_to_be32(inWrappedCmdSize); 3.1876 -+ res = CPU_TO_BE32(inWrappedCmdSize); 3.1877 - sha1_update(&sha1, (BYTE*)&res, 4); 3.1878 - sha1_update(&sha1, req.auth1.digest, sizeof(req.auth1.digest)); 3.1879 - sha1_final(&sha1, auth1->digest); 3.1880 -@@ -357,7 +357,7 @@ TPM_RESULT TPM_ReleaseTransportSigned(TP 3.1881 - /* setup a TPM_SIGN_INFO structure */ 3.1882 - memcpy(&buf[0], "\x05\x00TRAN", 6); 3.1883 - memcpy(&buf[6], antiReplay->nonce, 20); 3.1884 -- *(UINT32*)&buf[26] = cpu_to_be32(20); 3.1885 -+ *(UINT32*)&buf[26] = CPU_TO_BE32(20); 3.1886 - memcpy(&buf[30], session->transInternal.transDigest.digest, 20); 3.1887 - /* sign info structure */ 3.1888 - res = tpm_sign(key, auth1, TRUE, buf, sizeof(buf), signature, signSize); 3.1889 -diff -uprN tpm_emulator-0.3-x86_64/tpm_version.h tpm_emulator/tpm_version.h 3.1890 ---- tpm_emulator-0.3-x86_64/tpm_version.h 2006-08-29 15:07:21.649294352 -0700 3.1891 -+++ tpm_emulator/tpm_version.h 1969-12-31 16:00:00.000000000 -0800 3.1892 -@@ -1,6 +0,0 @@ 3.1893 --#ifndef _TPM_VERSION_H_ 3.1894 --#define _TPM_VERSION_H_ 3.1895 --#define VERSION_MAJOR 0 3.1896 --#define VERSION_MINOR 3 3.1897 --#define VERSION_BUILD 1136893683 3.1898 --#endif /* _TPM_VERSION_H_ */ 3.1899 -diff -uprN tpm_emulator-0.3-x86_64/tpmd.c tpm_emulator/tpmd.c 3.1900 ---- tpm_emulator-0.3-x86_64/tpmd.c 1969-12-31 16:00:00.000000000 -0800 3.1901 -+++ tpm_emulator/tpmd.c 2006-08-29 15:26:17.130674944 -0700 3.1902 -@@ -0,0 +1,141 @@ 3.1903 +@@ -211,7 +211,7 @@ static void encrypt_wrapped_command(BYTE 3.1904 + sha1_init(&sha1); 3.1905 + sha1_update(&sha1, auth->nonceEven.nonce, sizeof(auth->nonceEven.nonce)); 3.1906 + sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce)); 3.1907 +- sha1_update(&sha1, "out", 3); 3.1908 ++ sha1_update(&sha1, (BYTE*)"out", 3); 3.1909 + sha1_update(&sha1, secret, sizeof(TPM_SECRET)); 3.1910 + j = CPU_TO_BE32(i); 3.1911 + sha1_update(&sha1, (BYTE*)&j, 4); 3.1912 +diff -uprN orig/tpm_emulator-0.4/tpmd.c tpm_emulator/tpmd.c 3.1913 +--- orig/tpm_emulator-0.4/tpmd.c 1969-12-31 16:00:00.000000000 -0800 3.1914 ++++ tpm_emulator/tpmd.c 2006-07-24 14:35:35.000000000 -0700 3.1915 +@@ -0,0 +1,156 @@ 3.1916 +/* Software-Based Trusted Platform Module (TPM) Emulator for Linux 3.1917 + * Copyright (C) 2005 INTEL Corp 3.1918 + * 3.1919 @@ -1624,8 +1735,8 @@ diff -uprN tpm_emulator-0.3-x86_64/tpmd. 3.1920 + 3.1921 +#include "tpm_emulator.h" 3.1922 + 3.1923 -+#define TPM_RX_FNAME "/tmp/tpm_in.fifo" 3.1924 -+#define TPM_TX_FNAME "/tmp/tpm_out.fifo" 3.1925 ++#define TPM_RX_FNAME "/var/tpm/tpm_in.fifo" 3.1926 ++#define TPM_TX_FNAME "/var/tpm/tpm_out.fifo" 3.1927 + 3.1928 +#define BUFFER_SIZE 2048 3.1929 + 3.1930 @@ -1656,7 +1767,8 @@ diff -uprN tpm_emulator-0.3-x86_64/tpmd. 3.1931 + uint32_t out_size; 3.1932 + int in_size, written; 3.1933 + int i; 3.1934 -+ 3.1935 ++ struct stat file_info; 3.1936 ++ 3.1937 + int tpm_tx_fh=-1, tpm_rx_fh=-1; 3.1938 + if (argc < 2) { 3.1939 + printf("Usage: tpmd clear|save|deactivated\n" ); 3.1940 @@ -1679,6 +1791,20 @@ diff -uprN tpm_emulator-0.3-x86_64/tpmd. 3.1941 + return -1; 3.1942 + } 3.1943 + 3.1944 ++ if ( stat(TPM_RX_FNAME, &file_info) == -1) { 3.1945 ++ if ( mkfifo(TPM_RX_FNAME, S_IWUSR | S_IRUSR ) ) { 3.1946 ++ printf("Failed to create fifo %s.\n", TPM_RX_FNAME); 3.1947 ++ return -1; 3.1948 ++ } 3.1949 ++ } 3.1950 ++ 3.1951 ++ if ( stat(TPM_TX_FNAME, &file_info) == -1) { 3.1952 ++ if ( mkfifo(TPM_TX_FNAME, S_IWUSR | S_IRUSR ) ) { 3.1953 ++ printf("Failed to create fifo %s.\n", TPM_TX_FNAME); 3.1954 ++ return -1; 3.1955 ++ } 3.1956 ++ } 3.1957 ++ 3.1958 + while (1) { 3.1959 +abort_command: 3.1960 + if (tpm_rx_fh < 0) { 3.1961 @@ -1739,3 +1865,14 @@ diff -uprN tpm_emulator-0.3-x86_64/tpmd. 3.1962 + close(tpm_rx_fh); 3.1963 + 3.1964 +} 3.1965 +Binary files orig/tpm_emulator-0.4/tpm_emulator and tpm_emulator/tpm_emulator differ 3.1966 +diff -uprN orig/tpm_emulator-0.4/tpm_version.h tpm_emulator/tpm_version.h 3.1967 +--- orig/tpm_emulator-0.4/tpm_version.h 2006-06-23 03:37:07.000000000 -0700 3.1968 ++++ tpm_emulator/tpm_version.h 2006-07-24 14:35:41.000000000 -0700 3.1969 +@@ -2,5 +2,5 @@ 3.1970 + #define _TPM_VERSION_H_ 3.1971 + #define VERSION_MAJOR 0 3.1972 + #define VERSION_MINOR 4 3.1973 +-#define VERSION_BUILD 1151058734 3.1974 ++#define VERSION_BUILD 1153776940 3.1975 + #endif /* _TPM_VERSION_H_ */
4.1 --- a/tools/vtpm/vtpm.patch Tue Jul 25 11:19:48 2006 +0100 4.2 +++ b/tools/vtpm/vtpm.patch Tue Jul 25 11:30:30 2006 +0100 4.3 @@ -1,478 +1,45 @@ 4.4 -diff -uprN tpm_emulator-0.3-x86_64/AUTHORS vtpm/AUTHORS 4.5 ---- tpm_emulator-0.3-x86_64/AUTHORS 2006-08-29 15:07:21.618299064 -0700 4.6 -+++ vtpm/AUTHORS 2006-08-29 15:12:07.184886344 -0700 4.7 -@@ -1,2 +1,3 @@ 4.8 +diff -uprN tpm_emulator/AUTHORS vtpm/AUTHORS 4.9 +--- tpm_emulator/AUTHORS 2006-07-24 14:35:35.000000000 -0700 4.10 ++++ vtpm/AUTHORS 2006-07-24 14:35:35.000000000 -0700 4.11 +@@ -1,3 +1,3 @@ 4.12 Mario Strasser <mast@gmx.net> 4.13 Heiko Stamer <stamer@gaos.org> [DAA] 4.14 +-INTEL Corp <> [Dropped to Ring3] 4.15 +INTEL Corp <> [VTPM Extensions] 4.16 -diff -uprN tpm_emulator-0.3-x86_64/ChangeLog vtpm/ChangeLog 4.17 ---- tpm_emulator-0.3-x86_64/ChangeLog 2006-08-29 15:07:21.618299064 -0700 4.18 -+++ vtpm/ChangeLog 2006-08-29 15:12:07.185886192 -0700 4.19 -@@ -1,3 +1,7 @@ 4.20 -+2005-08-16 Intel Corp 4.21 -+ * Moved module out of kernel to run as a ring 3 app 4.22 -+ * Modified save_to_file and load_from_file to call a xen backend driver to call a VTPM manager 4.23 -+ 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 tpm_emulator-0.3-x86_64/Makefile vtpm/Makefile 4.28 ---- tpm_emulator-0.3-x86_64/Makefile 2006-08-29 15:08:20.532342768 -0700 4.29 -+++ vtpm/Makefile 2006-08-29 15:13:53.023796384 -0700 4.30 -@@ -1,22 +1,31 @@ 4.31 - # Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.32 - # Copyright (C) 2004 Mario Strasser <mast@gmx.net> 4.33 -+# Copyright (C) 2006 INTEL Corp. 4.34 - # 4.35 - # $Id: Makefile 69 2005-12-13 12:55:52Z mast $ 4.36 - 4.37 --# kernel settings 4.38 --KERNEL_RELEASE := $(shell uname -r) 4.39 --KERNEL_BUILD := /lib/modules/$(KERNEL_RELEASE)/build 4.40 --MOD_SUBDIR := misc 4.41 - COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/) 4.42 - 4.43 - # module settings 4.44 --MODULE_NAME := tpm_emulator 4.45 -+BIN := vtpmd 4.46 - VERSION_MAJOR := 0 4.47 - VERSION_MINOR := 3 4.48 - VERSION_BUILD := $(shell date +"%s") 4.49 - 4.50 --# enable/disable DEBUG messages 4.51 --EXTRA_CFLAGS += -Wall -DDEBUG -g 4.52 -+# Installation program and options 4.53 -+INSTALL = install 4.54 -+INSTALL_PROG = $(INSTALL) -m0755 4.55 -+INSTALL_DIR = $(INSTALL) -d -m0755 4.56 -+ 4.57 -+# Xen tools installation directory 4.58 -+TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin 4.59 -+ 4.60 -+CC := gcc 4.61 -+CFLAGS += -g -Wall $(INCLUDE) -DDEBUG 4.62 -+CFLAGS += -I. -Itpm -I../../vtpm_manager/manager 4.63 -+ 4.64 -+# Is the simulator running in it's own vm? 4.65 -+#CFLAGS += -DVTPM_MULTI_VM 4.66 - 4.67 - ifeq ($(COMPILE_ARCH),x86_64) 4.68 - LIBDIR = lib64 4.69 -@@ -34,38 +43,31 @@ DIRS := . crypto tpm 4.70 - SRCS := $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.c)) 4.71 - OBJS := $(patsubst %.c, %.o, $(SRCS)) 4.72 - SRCS += $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.h)) 4.73 --DISTSRC := ./README ./AUTHORS ./ChangeLog ./Makefile $(SRCS) 4.74 --DISTDIR := tpm_emulator-$(VERSION_MAJOR).$(VERSION_MINOR) 4.75 - 4.76 --obj-m := $(MODULE_NAME).o 4.77 --$(MODULE_NAME)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a 4.78 -+obj-m := $(BIN) 4.79 -+$(BIN)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a 4.80 - 4.81 - EXTRA_CFLAGS += -I$(src) -I$(src)/crypto -I$(src)/tpm 4.82 - 4.83 - # do not print "Entering directory ..." 4.84 - MAKEFLAGS += --no-print-directory 4.85 - 4.86 --all: $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version 4.87 -- @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules 4.88 -+all: $(BIN) 4.89 -+ 4.90 -+$(BIN): $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version $(SRCS) $(OBJS) 4.91 -+ $(CC) $(CFLAGS) $(OBJS) $(src)/crypto/libgmp.a -o $(BIN) 4.92 -+ 4.93 -+%.o: %.c 4.94 -+ $(CC) $(CFLAGS) -c $< -o $@ 4.95 - 4.96 --install: 4.97 -- @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules_install 4.98 -- test -d /var/tpm || mkdir /var/tpm 4.99 -- test -c /dev/tpm || mknod /dev/tpm c 10 224 4.100 -- chmod 666 /dev/tpm 4.101 -- depmod -a 4.102 -+install: $(BIN) 4.103 -+ $(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR) 4.104 - 4.105 - clean: 4.106 -- @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) clean 4.107 -- rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a 4.108 -+ rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS) 4.109 - 4.110 --dist: $(DISTSRC) 4.111 -- rm -rf $(DISTDIR) 4.112 -- mkdir $(DISTDIR) 4.113 -- cp --parents $(DISTSRC) $(DISTDIR)/ 4.114 -- rm -f $(DISTDIR)/crypto/gmp.h 4.115 -- tar -chzf $(DISTDIR).tar.gz $(DISTDIR) 4.116 -- rm -rf $(DISTDIR) 4.117 -+mrproper: clean 4.118 -+ rm -f $(BIN) tpm_version.h 4.119 - 4.120 - $(src)/crypto/libgmp.a: 4.121 - test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a 4.122 -diff -uprN tpm_emulator-0.3-x86_64/README vtpm/README 4.123 ---- tpm_emulator-0.3-x86_64/README 2006-08-29 15:07:43.530967832 -0700 4.124 -+++ vtpm/README 2006-08-29 15:12:07.190885432 -0700 4.125 -@@ -13,7 +13,8 @@ $Id: README 78 2006-01-07 10:45:39Z mast 4.126 - Copyright 4.127 - -------------------------------------------------------------------------- 4.128 - Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal 4.129 --Institute of Technology (ETH) Zurich. 4.130 -+ Institute of Technology (ETH) Zurich. 4.131 -+Copyright (C) 2005 INTEL Corp 4.132 - 4.133 - This program is free software; you can redistribute it and/or modify 4.134 - it under the terms of the GNU General Public License as published by 4.135 -diff -uprN tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c vtpm/crypto/gmp_kernel_wrapper.c 4.136 ---- tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c 2006-08-29 15:07:43.525968592 -0700 4.137 -+++ vtpm/crypto/gmp_kernel_wrapper.c 2006-08-29 15:12:07.186886040 -0700 4.138 -@@ -1,5 +1,6 @@ 4.139 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.140 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.141 -+ * Copyright (C) 2005 INTEL Corp 4.142 - * 4.143 - * This module is free software; you can redistribute it and/or modify 4.144 - * it under the terms of the GNU General Public License as published 4.145 -@@ -24,15 +25,10 @@ int __gmp_junk; 4.146 - void __attribute__ ((regparm(0))) __gmp_assert_fail(const char *filename, 4.147 - int linenum, const char *expr) 4.148 - { 4.149 -- panic(KERN_CRIT TPM_MODULE_NAME "%s:%d: GNU MP assertion failed: %s\n", 4.150 -+ error("%s:%d: GNU MP assertion failed: %s\n", 4.151 - filename, linenum, expr); 4.152 - } 4.153 - 4.154 --void __attribute__ ((regparm(0))) abort(void) 4.155 --{ 4.156 -- panic(KERN_CRIT TPM_MODULE_NAME "GNU MP abort() was called\n"); 4.157 --} 4.158 -- 4.159 - /* overwrite GNU MP random functions (used by mpz/millerrabin.c) */ 4.160 - 4.161 - void __attribute__ ((regparm(0))) gmp_randinit(gmp_randstate_t rstate, 4.162 -@@ -77,20 +73,19 @@ void __attribute__ ((regparm(0))) mpz_ur 4.163 - 4.164 - void __attribute__ ((regparm(0))) *kernel_allocate(size_t size) 4.165 - { 4.166 -- void *ret = (void*)kmalloc(size, GFP_KERNEL); 4.167 -- if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 4.168 -- "GMP: cannot allocate memory (size=%Zu)\n", size); 4.169 -+ void *ret = (void*)malloc(size); 4.170 -+ if (!ret) error("GMP: cannot allocate memory (size=%Zu)\n", size); 4.171 - return ret; 4.172 - } 4.173 - 4.174 - void __attribute__ ((regparm(0))) *kernel_reallocate(void *oldptr, 4.175 - size_t old_size, size_t new_size) 4.176 - { 4.177 -- void *ret = (void*)kmalloc(new_size, GFP_KERNEL); 4.178 -- if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory " 4.179 -+ void *ret = (void*)malloc(new_size); 4.180 -+ if (!ret) error("GMP: Cannot reallocate memory " 4.181 - "(old_size=%Zu new_size=%Zu)\n", old_size, new_size); 4.182 - memcpy(ret, oldptr, old_size); 4.183 -- kfree(oldptr); 4.184 -+ free(oldptr); 4.185 - return ret; 4.186 - } 4.187 - 4.188 -@@ -99,7 +94,7 @@ void __attribute__ ((regparm(0))) kernel 4.189 - /* overwrite used memory */ 4.190 - if (blk_ptr != NULL) { 4.191 - memset(blk_ptr, 0, blk_size); 4.192 -- kfree(blk_ptr); 4.193 -+ free(blk_ptr); 4.194 - } 4.195 - } 4.196 - 4.197 -diff -uprN tpm_emulator-0.3-x86_64/crypto/rsa.c vtpm/crypto/rsa.c 4.198 ---- tpm_emulator-0.3-x86_64/crypto/rsa.c 2006-08-29 15:07:21.618299064 -0700 4.199 -+++ vtpm/crypto/rsa.c 2006-08-29 15:12:07.187885888 -0700 4.200 +diff -uprN tpm_emulator/ChangeLog vtpm/ChangeLog 4.201 +--- tpm_emulator/ChangeLog 2006-07-24 14:35:35.000000000 -0700 4.202 ++++ vtpm/ChangeLog 2006-07-24 14:35:35.000000000 -0700 4.203 @@ -1,5 +1,6 @@ 4.204 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.205 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.206 -+ * Copyright (C) 2005 INTEL Corp 4.207 - * 4.208 - * This module is free software; you can redistribute it and/or modify 4.209 - * it under the terms of the GNU General Public License as published 4.210 -@@ -381,7 +382,7 @@ static int encode_message(int type, uint 4.211 - msg[0] = 0x00; 4.212 - get_random_bytes(&msg[1], SHA1_DIGEST_LENGTH); 4.213 - sha1_init(&ctx); 4.214 -- sha1_update(&ctx, "TCPA", 4); 4.215 -+ sha1_update(&ctx, (uint8_t *) "TCPA", 4); 4.216 - sha1_final(&ctx, &msg[1 + SHA1_DIGEST_LENGTH]); 4.217 - memset(&msg[1 + 2 * SHA1_DIGEST_LENGTH], 0x00, 4.218 - msg_len - data_len - 2 * SHA1_DIGEST_LENGTH - 2); 4.219 -@@ -429,7 +430,7 @@ static int decode_message(int type, uint 4.220 - mask_generation(&msg[1], SHA1_DIGEST_LENGTH, 4.221 - &msg[1 + SHA1_DIGEST_LENGTH], msg_len - SHA1_DIGEST_LENGTH - 1); 4.222 - sha1_init(&ctx); 4.223 -- sha1_update(&ctx, "TCPA", 4); 4.224 -+ sha1_update(&ctx, (uint8_t *) "TCPA", 4); 4.225 - sha1_final(&ctx, &msg[1]); 4.226 - if (memcmp(&msg[1], &msg[1 + SHA1_DIGEST_LENGTH], 4.227 - SHA1_DIGEST_LENGTH) != 0) return -1; 4.228 -diff -uprN tpm_emulator-0.3-x86_64/linux_module.c vtpm/linux_module.c 4.229 ---- tpm_emulator-0.3-x86_64/linux_module.c 2006-08-29 15:07:43.526968440 -0700 4.230 -+++ vtpm/linux_module.c 1969-12-31 16:00:00.000000000 -0800 4.231 -@@ -1,194 +0,0 @@ 4.232 --/* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.233 -- * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.234 -- * 4.235 -- * This module is free software; you can redistribute it and/or modify 4.236 -- * it under the terms of the GNU General Public License as published 4.237 -- * by the Free Software Foundation; either version 2 of the License, 4.238 -- * or (at your option) any later version. 4.239 -- * 4.240 -- * This module is distributed in the hope that it will be useful, 4.241 -- * but WITHOUT ANY WARRANTY; without even the implied warranty of 4.242 -- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4.243 -- * GNU General Public License for more details. 4.244 -- * 4.245 -- * $Id: linux_module.c 76 2006-01-02 22:17:58Z hstamer $ 4.246 -- */ 4.247 -- 4.248 --#include <linux/module.h> 4.249 --#include <linux/kernel.h> 4.250 --#include <linux/init.h> 4.251 --#include <linux/miscdevice.h> 4.252 --#include <linux/poll.h> 4.253 --#include "linux_module.h" 4.254 --#include "tpm/tpm_emulator.h" 4.255 -- 4.256 --MODULE_LICENSE("GPL"); 4.257 --MODULE_AUTHOR("Mario Strasser <mast@gmx.net>"); 4.258 --MODULE_DESCRIPTION("Trusted Platform Module (TPM) Emulator"); 4.259 --MODULE_SUPPORTED_DEVICE(TPM_DEVICE_NAME); 4.260 -- 4.261 --/* module startup parameters */ 4.262 --char *startup = "save"; 4.263 --module_param(startup, charp, 0444); 4.264 --MODULE_PARM_DESC(startup, " Sets the startup mode of the TPM. " 4.265 -- "Possible values are 'clear', 'save' (default) and 'deactivated."); 4.266 --char *storage_file = "/var/tpm/tpm_emulator-1.2.0.2"; 4.267 --module_param(storage_file, charp, 0644); 4.268 --MODULE_PARM_DESC(storage_file, " Sets the persistent-data storage " 4.269 -- "file of the TPM."); 4.270 -- 4.271 --/* TPM lock */ 4.272 --static struct semaphore tpm_mutex; 4.273 -- 4.274 --/* TPM command response */ 4.275 --static struct { 4.276 -- uint8_t *data; 4.277 -- uint32_t size; 4.278 --} tpm_response; 4.279 -- 4.280 --/* module state */ 4.281 --#define STATE_IS_OPEN 0 4.282 --static uint32_t module_state; 4.283 -- 4.284 --static int tpm_open(struct inode *inode, struct file *file) 4.285 --{ 4.286 -- debug("%s()", __FUNCTION__); 4.287 -- if (test_and_set_bit(STATE_IS_OPEN, (void*)&module_state)) return -EBUSY; 4.288 -- return 0; 4.289 --} 4.290 -- 4.291 --static int tpm_release(struct inode *inode, struct file *file) 4.292 --{ 4.293 -- debug("%s()", __FUNCTION__); 4.294 -- clear_bit(STATE_IS_OPEN, (void*)&module_state); 4.295 -- down(&tpm_mutex); 4.296 -- if (tpm_response.data != NULL) { 4.297 -- kfree(tpm_response.data); 4.298 -- tpm_response.data = NULL; 4.299 -- } 4.300 -- up(&tpm_mutex); 4.301 -- return 0; 4.302 --} 4.303 -- 4.304 --static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos) 4.305 --{ 4.306 -- debug("%s(%Zu)", __FUNCTION__, count); 4.307 -- down(&tpm_mutex); 4.308 -- if (tpm_response.data != NULL) { 4.309 -- count = min(count, (size_t)tpm_response.size - (size_t)*ppos); 4.310 -- count -= copy_to_user(buf, &tpm_response.data[*ppos], count); 4.311 -- *ppos += count; 4.312 -- if ((size_t)tpm_response.size == (size_t)*ppos) { 4.313 -- kfree(tpm_response.data); 4.314 -- tpm_response.data = NULL; 4.315 -- } 4.316 -- } else { 4.317 -- count = 0; 4.318 -- } 4.319 -- up(&tpm_mutex); 4.320 -- return count; 4.321 --} 4.322 -- 4.323 --static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos) 4.324 --{ 4.325 -- debug("%s(%Zu)", __FUNCTION__, count); 4.326 -- down(&tpm_mutex); 4.327 -- *ppos = 0; 4.328 -- if (tpm_response.data != NULL) kfree(tpm_response.data); 4.329 -- if (tpm_handle_command(buf, count, &tpm_response.data, 4.330 -- &tpm_response.size) != 0) { 4.331 -- count = -EILSEQ; 4.332 -- tpm_response.data = NULL; 4.333 -- } 4.334 -- up(&tpm_mutex); 4.335 -- return count; 4.336 --} 4.337 -- 4.338 --#define TPMIOC_CANCEL _IO('T', 0x00) 4.339 --#define TPMIOC_TRANSMIT _IO('T', 0x01) 4.340 -- 4.341 --static int tpm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 4.342 --{ 4.343 -- debug("%s(%d, %p)", __FUNCTION__, cmd, (char*)arg); 4.344 -- if (cmd == TPMIOC_TRANSMIT) { 4.345 -- uint32_t count = ntohl(*(uint32_t*)(arg + 2)); 4.346 -- down(&tpm_mutex); 4.347 -- if (tpm_response.data != NULL) kfree(tpm_response.data); 4.348 -- if (tpm_handle_command((char*)arg, count, &tpm_response.data, 4.349 -- &tpm_response.size) == 0) { 4.350 -- tpm_response.size -= copy_to_user((char*)arg, tpm_response.data, 4.351 -- tpm_response.size); 4.352 -- kfree(tpm_response.data); 4.353 -- tpm_response.data = NULL; 4.354 -- } else { 4.355 -- tpm_response.size = 0; 4.356 -- tpm_response.data = NULL; 4.357 -- } 4.358 -- up(&tpm_mutex); 4.359 -- return tpm_response.size; 4.360 -- } 4.361 -- return -1; 4.362 --} 4.363 -- 4.364 --struct file_operations fops = { 4.365 -- .owner = THIS_MODULE, 4.366 -- .open = tpm_open, 4.367 -- .release = tpm_release, 4.368 -- .read = tpm_read, 4.369 -- .write = tpm_write, 4.370 -- .ioctl = tpm_ioctl, 4.371 --}; 4.372 -- 4.373 --static struct miscdevice tpm_dev = { 4.374 -- .minor = TPM_DEVICE_MINOR, 4.375 -- .name = TPM_DEVICE_NAME, 4.376 -- .fops = &fops, 4.377 --}; 4.378 -- 4.379 --int __init init_tpm_module(void) 4.380 --{ 4.381 -- int res = misc_register(&tpm_dev); 4.382 -- if (res != 0) { 4.383 -- error("misc_register() failed for minor %d\n", TPM_DEVICE_MINOR); 4.384 -- return res; 4.385 -- } 4.386 -- /* initialize variables */ 4.387 -- sema_init(&tpm_mutex, 1); 4.388 -- module_state = 0; 4.389 -- tpm_response.data = NULL; 4.390 -- /* initialize TPM emulator */ 4.391 -- if (!strcmp(startup, "clear")) { 4.392 -- tpm_emulator_init(1); 4.393 -- } else if (!strcmp(startup, "save")) { 4.394 -- tpm_emulator_init(2); 4.395 -- } else if (!strcmp(startup, "deactivated")) { 4.396 -- tpm_emulator_init(3); 4.397 -- } else { 4.398 -- error("invalid startup mode '%s'; must be 'clear', " 4.399 -- "'save' (default) or 'deactivated", startup); 4.400 -- misc_deregister(&tpm_dev); 4.401 -- return -EINVAL; 4.402 -- } 4.403 -- return 0; 4.404 --} 4.405 -- 4.406 --void __exit cleanup_tpm_module(void) 4.407 --{ 4.408 -- tpm_emulator_shutdown(); 4.409 -- misc_deregister(&tpm_dev); 4.410 -- if (tpm_response.data != NULL) kfree(tpm_response.data); 4.411 --} 4.412 -- 4.413 --module_init(init_tpm_module); 4.414 --module_exit(cleanup_tpm_module); 4.415 -- 4.416 --uint64_t tpm_get_ticks(void) 4.417 --{ 4.418 -- static struct timespec old_time = {0, 0}; 4.419 -- struct timespec new_time = current_kernel_time(); 4.420 -- uint64_t ticks = (uint64_t)(old_time.tv_sec - new_time.tv_sec) * 1000000 4.421 -- + (old_time.tv_nsec - new_time.tv_nsec) / 1000; 4.422 -- old_time = new_time; 4.423 -- return (ticks > 0) ? ticks : 1; 4.424 --} 4.425 -- 4.426 -diff -uprN tpm_emulator-0.3-x86_64/linux_module.h vtpm/linux_module.h 4.427 ---- tpm_emulator-0.3-x86_64/linux_module.h 2006-08-29 15:07:43.527968288 -0700 4.428 -+++ vtpm/linux_module.h 2006-08-29 15:12:07.189885584 -0700 4.429 -@@ -1,5 +1,6 @@ 4.430 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.431 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.432 -+ * Copyright (C) 2005 INTEL Corp 4.433 - * 4.434 - * This module is free software; you can redistribute it and/or modify 4.435 - * it under the terms of the GNU General Public License as published 4.436 -@@ -17,17 +18,22 @@ 4.437 - #ifndef _LINUX_MODULE_H_ 4.438 - #define _LINUX_MODULE_H_ 4.439 + ????-??-?? Intel Corp 4.440 + * Moved module out of kernel to run as a ring 3 app 4.441 ++ * Modified save_to_file and load_from_file to call xen VTPM manager 4.442 4.443 --#include <linux/version.h> 4.444 --#include <linux/kernel.h> 4.445 --#include <linux/slab.h> 4.446 -+#include <malloc.h> 4.447 -+#include <stdint.h> 4.448 -+#include <stdio.h> 4.449 -+#include <string.h> 4.450 - #include <linux/types.h> 4.451 --#include <linux/string.h> 4.452 --#include <linux/random.h> 4.453 --#include <linux/time.h> 4.454 --#include <asm/byteorder.h> 4.455 + 2006-06-23 Mario Strasser <mast@gmx.net> 4.456 + * tpm_startup.c: behaviour of ST_CLEAR and storage of 4.457 +diff -uprN tpm_emulator/linux_module.h vtpm/linux_module.h 4.458 +--- tpm_emulator/linux_module.h 2006-07-24 14:35:35.000000000 -0700 4.459 ++++ vtpm/linux_module.h 2006-07-24 14:35:35.000000000 -0700 4.460 +@@ -44,18 +44,21 @@ 4.461 + #define TPM_DEVICE_NAME "tpm" 4.462 + #define TPM_MODULE_NAME "tpm_emulator" 4.463 4.464 --/* module settings */ 4.465 -+#include <endian.h> 4.466 -+#define __BYTEORDER_HAS_U64__ 4.467 -+#ifdef LITTLE_ENDIAN 4.468 -+ #include <linux/byteorder/little_endian.h> 4.469 -+#else 4.470 -+ #include <linux/byteorder/big_endian.h> 4.471 -+#endif 4.472 - 4.473 -+/* module settings */ 4.474 -+#define min(A,B) ((A)<(B)?(A):(B)) 4.475 - #ifndef STR 4.476 - #define STR(s) __STR__(s) 4.477 - #define __STR__(s) #s 4.478 -@@ -39,34 +45,38 @@ 4.479 - #define TPM_MODULE_NAME "tpm_emulator" 4.480 - 4.481 - /* debug and log output functions */ 4.482 ++/* debug and log output functions */ 4.483 +extern int dmi_id; 4.484 - 4.485 ++ 4.486 #ifdef DEBUG 4.487 --#define debug(fmt, ...) printk(KERN_DEBUG "%s %s:%d: Debug: " fmt "\n", \ 4.488 -- TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) 4.489 +-#define debug(fmt, ...) printf("TPMD: %s:%d: Debug: " fmt "\n", \ 4.490 +- __FILE__, __LINE__, ## __VA_ARGS__) 4.491 +#define debug(fmt, ...) printf("TPMD[%d]: %s:%d: Debug: " fmt "\n", \ 4.492 + dmi_id, __FILE__, __LINE__, ## __VA_ARGS__) 4.493 #else 4.494 #define debug(fmt, ...) 4.495 #endif 4.496 --#define info(fmt, ...) printk(KERN_INFO "%s %s:%d: Info: " fmt "\n", \ 4.497 -- TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) 4.498 --#define error(fmt, ...) printk(KERN_ERR "%s %s:%d: Error: " fmt "\n", \ 4.499 -- TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) 4.500 --#define alert(fmt, ...) printk(KERN_ALERT "%s %s:%d: Alert: " fmt "\n", \ 4.501 -- TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) 4.502 +-#define info(fmt, ...) printf("TPMD: %s:%d: Info: " fmt "\n", \ 4.503 +- __FILE__, __LINE__, ## __VA_ARGS__) 4.504 +-#define error(fmt, ...) printf("TPMD: %s:%d: Error: " fmt "\n", \ 4.505 +- __FILE__, __LINE__, ## __VA_ARGS__) 4.506 +-#define alert(fmt, ...) printf("TPMD: %s:%d: Alert: " fmt "\n", \ 4.507 +- __FILE__, __LINE__, ## __VA_ARGS__) 4.508 +#define info(fmt, ...) printf("TPMD[%d]: %s:%d: Info: " fmt "\n", \ 4.509 + dmi_id, __FILE__, __LINE__, ## __VA_ARGS__) 4.510 +#define error(fmt, ...) printf("TPMD[%d]: %s:%d: Error: " fmt "\n", \ 4.511 @@ -482,393 +49,43 @@ diff -uprN tpm_emulator-0.3-x86_64/linux 4.512 4.513 /* memory allocation */ 4.514 4.515 - static inline void *tpm_malloc(size_t size) 4.516 - { 4.517 -- return kmalloc(size, GFP_KERNEL); 4.518 -+ return malloc(size); 4.519 - } 4.520 - 4.521 - static inline void tpm_free(const void *ptr) 4.522 - { 4.523 -- if (ptr != NULL) kfree(ptr); 4.524 -+ if (ptr != NULL) free( (void *) ptr); 4.525 - } 4.526 - 4.527 - /* random numbers */ 4.528 - 4.529 -+//FIXME; 4.530 -+void get_random_bytes(void *buf, int nbytes); 4.531 -+ 4.532 - static inline void tpm_get_random_bytes(void *buf, int nbytes) 4.533 - { 4.534 - get_random_bytes(buf, nbytes); 4.535 -@@ -86,9 +96,9 @@ uint64_t tpm_get_ticks(void); 4.536 - #define CPU_TO_LE16(x) __cpu_to_le16(x) 4.537 - 4.538 - #define BE64_TO_CPU(x) __be64_to_cpu(x) 4.539 --#define LE64_TO_CPU(x) __be64_to_cpu(x) 4.540 -+#define LE64_TO_CPU(x) __le64_to_cpu(x) 4.541 - #define BE32_TO_CPU(x) __be32_to_cpu(x) 4.542 --#define LE32_TO_CPU(x) __be32_to_cpu(x) 4.543 -+#define LE32_TO_CPU(x) __le32_to_cpu(x) 4.544 - #define BE16_TO_CPU(x) __be16_to_cpu(x) 4.545 - #define LE16_TO_CPU(x) __le16_to_cpu(x) 4.546 +diff -uprN tpm_emulator/Makefile vtpm/Makefile 4.547 +--- tpm_emulator/Makefile 2006-07-24 14:35:35.000000000 -0700 4.548 ++++ vtpm/Makefile 2006-07-24 14:35:35.000000000 -0700 4.549 +@@ -7,7 +7,7 @@ 4.550 + COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/) 4.551 4.552 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_audit.c vtpm/tpm/tpm_audit.c 4.553 ---- tpm_emulator-0.3-x86_64/tpm/tpm_audit.c 2006-08-29 15:07:21.620298760 -0700 4.554 -+++ vtpm/tpm/tpm_audit.c 2006-08-29 15:12:07.191885280 -0700 4.555 -@@ -1,6 +1,7 @@ 4.556 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.557 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.558 - * Swiss Federal Institute of Technology (ETH) Zurich 4.559 -+ * Copyright (C) 2005 INTEL Corp 4.560 - * 4.561 - * This module is free software; you can redistribute it and/or modify 4.562 - * it under the terms of the GNU General Public License as published 4.563 -@@ -45,14 +46,14 @@ void tpm_audit_request(TPM_COMMAND_CODE 4.564 - tpmData.permanent.data.auditMonotonicCounter++; 4.565 - } 4.566 - /* update audit digest */ 4.567 -- *((UINT16*)&buf[0]) = cpu_to_be16(TPM_TAG_AUDIT_EVENT_IN); 4.568 -- *((UINT32*)&buf[2]) = cpu_to_be32(ordinal); 4.569 -+ *((UINT16*)&buf[0]) = CPU_TO_BE16(TPM_TAG_AUDIT_EVENT_IN); 4.570 -+ *((UINT32*)&buf[2]) = CPU_TO_BE32(ordinal); 4.571 - sha1_init(&sha1_ctx); 4.572 - sha1_update(&sha1_ctx, req->param, req->paramSize); 4.573 - sha1_final(&sha1_ctx, &buf[6]); 4.574 -- *((UINT16*)&buf[26]) = cpu_to_be16(TPM_TAG_COUNTER_VALUE); 4.575 -+ *((UINT16*)&buf[26]) = CPU_TO_BE16(TPM_TAG_COUNTER_VALUE); 4.576 - memset(&buf[30], 0, 4); 4.577 -- *((UINT32*)&buf[34]) = cpu_to_be32(tpmData.permanent.data.auditMonotonicCounter); 4.578 -+ *((UINT32*)&buf[34]) = CPU_TO_BE32(tpmData.permanent.data.auditMonotonicCounter); 4.579 - sha1_init(&sha1_ctx); 4.580 - sha1_update(&sha1_ctx, tpmData.stany.data.auditDigest.digest, 4.581 - sizeof(TPM_DIGEST)); 4.582 -@@ -70,15 +71,15 @@ void tpm_audit_response(TPM_COMMAND_CODE 4.583 - && (AUDIT_STATUS[ord / 8] & (1 << (ord & 0x07)))) { 4.584 - info("tpm_audit_response()"); 4.585 - /* update audit digest */ 4.586 -- *((UINT16*)&buf[0]) = cpu_to_be16(TPM_TAG_AUDIT_EVENT_OUT); 4.587 -- *((UINT32*)&buf[2]) = cpu_to_be32(ordinal); 4.588 -+ *((UINT16*)&buf[0]) = CPU_TO_BE16(TPM_TAG_AUDIT_EVENT_OUT); 4.589 -+ *((UINT32*)&buf[2]) = CPU_TO_BE32(ordinal); 4.590 - sha1_init(&sha1_ctx); 4.591 - sha1_update(&sha1_ctx, rsp->param, rsp->paramSize); 4.592 - sha1_final(&sha1_ctx, &buf[6]); 4.593 -- *((UINT16*)&buf[26]) = cpu_to_be16(TPM_TAG_COUNTER_VALUE); 4.594 -+ *((UINT16*)&buf[26]) = CPU_TO_BE16(TPM_TAG_COUNTER_VALUE); 4.595 - memset(&buf[30], 0, 4); 4.596 -- *((UINT32*)&buf[34]) = cpu_to_be32(tpmData.permanent.data.auditMonotonicCounter); 4.597 -- *((UINT32*)&buf[34]) = cpu_to_be32(rsp->result); 4.598 -+ *((UINT32*)&buf[34]) = CPU_TO_BE32(tpmData.permanent.data.auditMonotonicCounter); 4.599 -+ *((UINT32*)&buf[34]) = CPU_TO_BE32(rsp->result); 4.600 - sha1_init(&sha1_ctx); 4.601 - sha1_update(&sha1_ctx, tpmData.stany.data.auditDigest.digest, 4.602 - sizeof(TPM_DIGEST)); 4.603 -@@ -158,7 +159,7 @@ TPM_RESULT TPM_GetAuditDigestSigned(TPM_ 4.604 - } 4.605 - memcpy(&buf[0], "\x05\x00ADIG", 6); 4.606 - memcpy(&buf[6], antiReplay->nonce, 20); 4.607 -- *(UINT32*)&buf[26] = cpu_to_be32(buf_size - 30); 4.608 -+ *(UINT32*)&buf[26] = CPU_TO_BE32(buf_size - 30); 4.609 - memcpy(&buf[30], auditDigest->digest, 20); 4.610 - ptr = &buf[50]; 4.611 - len = buf_size - 50; 4.612 -@@ -198,4 +199,3 @@ TPM_RESULT TPM_SetOrdinalAuditStatus(TPM 4.613 - } 4.614 - return TPM_SUCCESS; 4.615 - } 4.616 -- 4.617 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c vtpm/tpm/tpm_authorization.c 4.618 ---- tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c 2006-08-29 15:07:21.620298760 -0700 4.619 -+++ vtpm/tpm/tpm_authorization.c 2006-08-29 15:12:07.192885128 -0700 4.620 -@@ -1,6 +1,7 @@ 4.621 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.622 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.623 - * Swiss Federal Institute of Technology (ETH) Zurich 4.624 -+ * Copyright (C) 2005 INTEL Corp 4.625 - * 4.626 - * This module is free software; you can redistribute it and/or modify 4.627 - * it under the terms of the GNU General Public License as published 4.628 -@@ -279,7 +280,7 @@ TPM_RESULT tpm_verify_auth(TPM_AUTH *aut 4.629 - { 4.630 - hmac_ctx_t ctx; 4.631 - TPM_SESSION_DATA *session; 4.632 -- UINT32 auth_handle = cpu_to_be32(auth->authHandle); 4.633 -+ UINT32 auth_handle = CPU_TO_BE32(auth->authHandle); 4.634 - 4.635 - info("tpm_verify_auth(%08x)", auth->authHandle); 4.636 - /* get dedicated authorization or transport session */ 4.637 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_capability.c vtpm/tpm/tpm_capability.c 4.638 ---- tpm_emulator-0.3-x86_64/tpm/tpm_capability.c 2006-08-29 15:07:21.620298760 -0700 4.639 -+++ vtpm/tpm/tpm_capability.c 2006-08-29 15:12:07.193884976 -0700 4.640 -@@ -1,6 +1,7 @@ 4.641 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.642 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.643 - * Swiss Federal Institute of Technology (ETH) Zurich 4.644 -+ * Copyright (C) 2005 INTEL Corp 4.645 - * 4.646 - * This module is free software; you can redistribute it and/or modify 4.647 - * it under the terms of the GNU General Public License as published 4.648 -@@ -406,7 +407,7 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL 4.649 + # module settings 4.650 +-BIN := tpm_emulator 4.651 ++BIN := vtpmd 4.652 + VERSION_MAJOR := 0 4.653 + VERSION_MINOR := 4 4.654 + VERSION_BUILD := $(shell date +"%s") 4.655 +@@ -22,7 +22,7 @@ TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin 4.656 4.657 - case TPM_CAP_KEY_HANDLE: 4.658 - debug("[TPM_CAP_KEY_HANDLE]"); 4.659 -- subCapSize = cpu_to_be32(TPM_RT_KEY); 4.660 -+ subCapSize = CPU_TO_BE32(TPM_RT_KEY); 4.661 - return cap_handle(4, (BYTE*)&subCapSize, respSize, resp); 4.662 - 4.663 - case TPM_CAP_CHECK_LOADED: 4.664 -@@ -480,4 +481,3 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL 4.665 - return TPM_BAD_MODE; 4.666 - } 4.667 - } 4.668 -- 4.669 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c vtpm/tpm/tpm_cmd_handler.c 4.670 ---- tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c 2006-08-29 15:07:21.621298608 -0700 4.671 -+++ vtpm/tpm/tpm_cmd_handler.c 2006-08-29 15:12:07.197884368 -0700 4.672 -@@ -1,6 +1,7 @@ 4.673 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.674 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.675 - * Swiss Federal Institute of Technology (ETH) Zurich 4.676 -+ * Copyright (C) 2005 INTEL Corp 4.677 - * 4.678 - * This module is free software; you can redistribute it and/or modify 4.679 - * it under the terms of the GNU General Public License as published 4.680 -@@ -73,7 +74,7 @@ void tpm_compute_in_param_digest(TPM_REQ 4.681 - { 4.682 - sha1_ctx_t sha1; 4.683 - UINT32 offset = tpm_get_param_offset(req->ordinal); 4.684 -- UINT32 ord = cpu_to_be32(req->ordinal); 4.685 -+ UINT32 ord = CPU_TO_BE32(req->ordinal); 4.686 - 4.687 - /* compute SHA1 hash */ 4.688 - if (offset <= req->paramSize) { 4.689 -@@ -89,8 +90,8 @@ void tpm_compute_in_param_digest(TPM_REQ 4.690 - void tpm_compute_out_param_digest(TPM_COMMAND_CODE ordinal, TPM_RESPONSE *rsp) 4.691 - { 4.692 - sha1_ctx_t sha1; 4.693 -- UINT32 res = cpu_to_be32(rsp->result); 4.694 -- UINT32 ord = cpu_to_be32(ordinal); 4.695 -+ UINT32 res = CPU_TO_BE32(rsp->result); 4.696 -+ UINT32 ord = CPU_TO_BE32(ordinal); 4.697 + CC := gcc 4.698 + CFLAGS += -g -Wall $(INCLUDE) -DDEBUG 4.699 +-CFLAGS += -I. -Itpm 4.700 ++CFLAGS += -I. -Itpm -I../../vtpm_manager/manager 4.701 4.702 - /* compute SHA1 hash */ 4.703 - sha1_init(&sha1); 4.704 -@@ -3123,7 +3124,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA 4.705 - hmac_update(&hmac, rsp->auth2->digest, sizeof(rsp->auth2->digest)); 4.706 - #if 0 4.707 - if (tpm_get_auth(rsp->auth2->authHandle)->type == TPM_ST_OIAP) { 4.708 -- UINT32 handle = cpu_to_be32(rsp->auth2->authHandle); 4.709 -+ UINT32 handle = CPU_TO_BE32(rsp->auth2->authHandle); 4.710 - hmac_update(&hmac, (BYTE*)&handle, 4); 4.711 - } 4.712 - #endif 4.713 -@@ -3138,7 +3139,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA 4.714 - hmac_update(&hmac, rsp->auth1->digest, sizeof(rsp->auth1->digest)); 4.715 - #if 0 4.716 - if (tpm_get_auth(rsp->auth1->authHandle)->type == TPM_ST_OIAP) { 4.717 -- UINT32 handle = cpu_to_be32(rsp->auth1->authHandle); 4.718 -+ UINT32 handle = CPU_TO_BE32(rsp->auth1->authHandle); 4.719 - hmac_update(&hmac, (BYTE*)&handle, 4); 4.720 - } 4.721 - #endif 4.722 -@@ -3221,7 +3222,9 @@ extern const char *tpm_error_to_string(T 4.723 - void tpm_execute_command(TPM_REQUEST *req, TPM_RESPONSE *rsp) 4.724 - { 4.725 - TPM_RESULT res; 4.726 -- 4.727 -+ 4.728 -+ req->tag = (BYTE) req->tag; // FIXME: Why is this here 4.729 + # Is the simulator running in it's own vm? 4.730 + #CFLAGS += -DVTPM_MULTI_VM 4.731 +@@ -62,7 +62,6 @@ $(BIN): $(src)/crypto/gmp.h $(src)/crypt 4.732 + 4.733 + install: $(BIN) 4.734 + $(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR) 4.735 +- @if [ ! -d "/var/tpm" ]; then mkdir /var/tpm; fi 4.736 + 4.737 + clean: 4.738 + rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS) 4.739 +@@ -98,3 +97,4 @@ version: 4.740 + @echo "#endif /* _TPM_VERSION_H_ */" >> $(src)/tpm_version.h 4.741 + 4.742 + .PHONY: all install clean dist gmp version 4.743 + 4.744 - /* setup authorisation as well as response tag and size */ 4.745 - memset(rsp, 0, sizeof(*rsp)); 4.746 - switch (req->tag) { 4.747 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c vtpm/tpm/tpm_crypto.c 4.748 ---- tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c 2006-08-29 15:07:43.531967680 -0700 4.749 -+++ vtpm/tpm/tpm_crypto.c 2006-08-29 15:12:07.198884216 -0700 4.750 -@@ -1,6 +1,7 @@ 4.751 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.752 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.753 - * Swiss Federal Institute of Technology (ETH) Zurich 4.754 -+ * Copyright (C) 2005 INTEL Corp 4.755 - * 4.756 - * This module is free software; you can redistribute it and/or modify 4.757 - * it under the terms of the GNU General Public License as published 4.758 -@@ -106,7 +107,7 @@ TPM_RESULT tpm_sign(TPM_KEY_DATA *key, T 4.759 - /* setup TPM_SIGN_INFO structure */ 4.760 - memcpy(&buf[0], "\x05\x00SIGN", 6); 4.761 - memcpy(&buf[6], auth->nonceOdd.nonce, 20); 4.762 -- *(UINT32*)&buf[26] = cpu_to_be32(areaToSignSize); 4.763 -+ *(UINT32*)&buf[26] = CPU_TO_BE32(areaToSignSize); 4.764 - memcpy(&buf[30], areaToSign, areaToSignSize); 4.765 - if (rsa_sign(&key->key, RSA_SSA_PKCS1_SHA1, 4.766 - buf, areaToSignSize + 30, *sig)) { 4.767 -@@ -383,4 +384,3 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL 4.768 - } 4.769 - return TPM_SUCCESS; 4.770 - } 4.771 -- 4.772 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_daa.c vtpm/tpm/tpm_daa.c 4.773 ---- tpm_emulator-0.3-x86_64/tpm/tpm_daa.c 2006-08-29 15:07:21.622298456 -0700 4.774 -+++ vtpm/tpm/tpm_daa.c 2006-08-29 15:12:07.203883456 -0700 4.775 -@@ -700,14 +700,14 @@ info("tested until here"); 4.776 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.777 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.778 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.779 -- sha1_update(&sha1, "\x00", 1); 4.780 -+ sha1_update(&sha1, (BYTE *) "\x00", 1); 4.781 - sha1_final(&sha1, scratch); 4.782 - sha1_init(&sha1); 4.783 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 4.784 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.785 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.786 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.787 -- sha1_update(&sha1, "\x01", 1); 4.788 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 4.789 - sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 4.790 - mpz_init(f), mpz_init(q); 4.791 - mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 4.792 -@@ -787,14 +787,14 @@ info("tested until here"); 4.793 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.794 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.795 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.796 -- sha1_update(&sha1, "\x00", 1); 4.797 -+ sha1_update(&sha1, (BYTE *) "\x00", 1); 4.798 - sha1_final(&sha1, scratch); 4.799 - sha1_init(&sha1); 4.800 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 4.801 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.802 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.803 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.804 -- sha1_update(&sha1, "\x01", 1); 4.805 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 4.806 - sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 4.807 - mpz_init(f), mpz_init(q); 4.808 - mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 4.809 -@@ -1440,14 +1440,14 @@ info("tested until here"); 4.810 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.811 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.812 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.813 -- sha1_update(&sha1, "\x00", 1); 4.814 -+ sha1_update(&sha1, (BYTE *) "\x00", 1); 4.815 - sha1_final(&sha1, scratch); 4.816 - sha1_init(&sha1); 4.817 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 4.818 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.819 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.820 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.821 -- sha1_update(&sha1, "\x01", 1); 4.822 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 4.823 - sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 4.824 - mpz_init(f), mpz_init(q); 4.825 - mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 4.826 -@@ -1660,14 +1660,14 @@ info("tested until here"); 4.827 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.828 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.829 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.830 -- sha1_update(&sha1, "\x00", 1); 4.831 -+ sha1_update(&sha1, (BYTE *) "\x00", 1); 4.832 - sha1_final(&sha1, scratch); 4.833 - sha1_init(&sha1); 4.834 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 4.835 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.836 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.837 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.838 -- sha1_update(&sha1, "\x01", 1); 4.839 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 4.840 - sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 4.841 - mpz_init(f), mpz_init(q); 4.842 - mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 4.843 -@@ -1740,14 +1740,14 @@ info("tested until here"); 4.844 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.845 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.846 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.847 -- sha1_update(&sha1, "\x00", 1); 4.848 -+ sha1_update(&sha1, (BYTE *) "\x00", 1); 4.849 - sha1_final(&sha1, scratch); 4.850 - sha1_init(&sha1); 4.851 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 4.852 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.853 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.854 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.855 -- sha1_update(&sha1, "\x01", 1); 4.856 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 4.857 - sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 4.858 - mpz_init(f), mpz_init(q); 4.859 - mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 4.860 -@@ -2828,14 +2828,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 4.861 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.862 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.863 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.864 -- sha1_update(&sha1, "\x00", 1); 4.865 -+ sha1_update(&sha1, (BYTE *) "\x00", 1); 4.866 - sha1_final(&sha1, scratch); 4.867 - sha1_init(&sha1); 4.868 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 4.869 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.870 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.871 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.872 -- sha1_update(&sha1, "\x01", 1); 4.873 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 4.874 - sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 4.875 - mpz_init(f), mpz_init(q); 4.876 - mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 4.877 -@@ -3050,7 +3050,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 4.878 - sha1_init(&sha1); 4.879 - sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest, 4.880 - sizeof(session->DAA_session.DAA_digest)); 4.881 -- sha1_update(&sha1, "\x01", 1); 4.882 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 4.883 - sha1_update(&sha1, inputData1, inputSize1); 4.884 - sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest); 4.885 - } 4.886 -@@ -3078,7 +3078,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 4.887 - sha1_init(&sha1); 4.888 - sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest, 4.889 - sizeof(session->DAA_session.DAA_digest)); 4.890 -- sha1_update(&sha1, "\x01", 1); 4.891 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 4.892 - rsa_export_modulus(&aikData->key, scratch, &size); 4.893 - sha1_update(&sha1, scratch, size); 4.894 - sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest); 4.895 -@@ -3134,14 +3134,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 4.896 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.897 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.898 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.899 -- sha1_update(&sha1, "\x00", 1); 4.900 -+ sha1_update(&sha1, (BYTE *) "\x00", 1); 4.901 - sha1_final(&sha1, scratch); 4.902 - sha1_init(&sha1); 4.903 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 4.904 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.905 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.906 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.907 -- sha1_update(&sha1, "\x01", 1); 4.908 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 4.909 - sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 4.910 - mpz_init(f), mpz_init(q); 4.911 - mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 4.912 -@@ -3213,14 +3213,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 4.913 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.914 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.915 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.916 -- sha1_update(&sha1, "\x00", 1); 4.917 -+ sha1_update(&sha1, (BYTE *) "\x00", 1); 4.918 - sha1_final(&sha1, scratch); 4.919 - sha1_init(&sha1); 4.920 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 4.921 - sizeof(session->DAA_tpmSpecific.DAA_rekey)); 4.922 - sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 4.923 - sizeof(session->DAA_tpmSpecific.DAA_count)); 4.924 -- sha1_update(&sha1, "\x01", 1); 4.925 -+ sha1_update(&sha1, (BYTE *) "\x01", 1); 4.926 - sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 4.927 - mpz_init(f), mpz_init(q); 4.928 - mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); 4.929 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_data.c vtpm/tpm/tpm_data.c 4.930 ---- tpm_emulator-0.3-x86_64/tpm/tpm_data.c 2006-08-29 15:08:20.535342312 -0700 4.931 -+++ vtpm/tpm/tpm_data.c 2006-08-29 15:12:07.206883000 -0700 4.932 +diff -uprN tpm_emulator/tpm/tpm_data.c vtpm/tpm/tpm_data.c 4.933 +--- tpm_emulator/tpm/tpm_data.c 2006-07-24 14:35:35.000000000 -0700 4.934 ++++ vtpm/tpm/tpm_data.c 2006-07-24 14:35:35.000000000 -0700 4.935 @@ -1,6 +1,7 @@ 4.936 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.937 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.938 @@ -878,7 +95,7 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 4.939 * This module is free software; you can redistribute it and/or modify 4.940 * it under the terms of the GNU General Public License as published 4.941 @@ -15,10 +16,15 @@ 4.942 - * $Id: tpm_data.c 36 2005-10-26 20:31:19Z hstamer $ 4.943 + * $Id: tpm_data.c 98 2006-05-07 14:16:29Z hstamer $ 4.944 */ 4.945 4.946 +#include <sys/types.h> 4.947 @@ -894,37 +111,15 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 4.948 4.949 TPM_DATA tpmData; 4.950 4.951 -@@ -39,6 +45,7 @@ static inline void init_pcr_attr(int pcr 4.952 - 4.953 - void tpm_init_data(void) 4.954 - { 4.955 -+#ifndef TPM_GENERATE_EK 4.956 - /* endorsement key */ 4.957 - uint8_t ek_n[] = "\xa8\xdb\xa9\x42\xa8\xf3\xb8\x06\x85\x90\x76\x93\xad\xf7" 4.958 - "\x74\xec\x3f\xd3\x3d\x9d\xe8\x2e\xff\x15\xed\x0e\xce\x5f\x93" 4.959 -@@ -77,6 +84,8 @@ void tpm_init_data(void) 4.960 - "\xd1\xc0\x8b\x5b\xa2\x2e\xa7\x15\xca\x50\x75\x10\x48\x9c\x2b" 4.961 - "\x18\xb9\x67\x8f\x5d\x64\xc3\x28\x9f\x2f\x16\x2f\x08\xda\x47" 4.962 - "\xec\x86\x43\x0c\x80\x99\x07\x34\x0f"; 4.963 -+#endif 4.964 -+ 4.965 - int i; 4.966 - /* reset all data to NULL, FALSE or 0 */ 4.967 - memset(&tpmData, 0, sizeof(tpmData)); 4.968 -@@ -150,49 +159,235 @@ void tpm_release_data(void) 4.969 - 4.970 - #ifdef TPM_STORE_TO_FILE 4.971 - 4.972 --#include <linux/fs.h> 4.973 --#include <linux/unistd.h> 4.974 --#include <asm/uaccess.h> 4.975 -+#include <sys/types.h> 4.976 -+#include <sys/stat.h> 4.977 -+#include <fcntl.h> 4.978 -+ 4.979 -+ static int vtpm_tx_fh=-1, vtpm_rx_fh=-1; 4.980 +@@ -158,45 +164,232 @@ void tpm_release_data(void) 4.981 + #include <sys/types.h> 4.982 + #include <sys/stat.h> 4.983 + #include <fcntl.h> 4.984 +-#include <unistd.h> 4.985 4.986 -#define TPM_STORAGE_FILE "/var/tpm/tpm_emulator-1.2." STR(VERSION_MAJOR) "." STR(VERSION_MINOR) 4.987 ++ static int vtpm_tx_fh=-1, vtpm_rx_fh=-1; 4.988 ++ 4.989 +#ifdef VTPM_MUTLI_VM 4.990 + #define DEV_FE "/dev/tpm" 4.991 +#else 4.992 @@ -938,14 +133,10 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 4.993 static int write_to_file(uint8_t *data, size_t data_length) 4.994 { 4.995 - int res; 4.996 -- struct file *fp; 4.997 -- mm_segment_t old_fs = get_fs(); 4.998 -- fp = filp_open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR); 4.999 -- if (IS_ERR(fp)) return -1; 4.1000 -- set_fs(get_ds()); 4.1001 -- res = fp->f_op->write(fp, data, data_length, &fp->f_pos); 4.1002 -- set_fs(old_fs); 4.1003 -- filp_close(fp, NULL); 4.1004 +- int fp; 4.1005 +- fp = open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR); 4.1006 +- res = write(fp, data, data_length); 4.1007 +- close(fp); 4.1008 - return (res == data_length) ? 0 : -1; 4.1009 + int res, out_data_size, in_header_size; 4.1010 + BYTE *ptr, *out_data, *in_header; 4.1011 @@ -1049,15 +240,14 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 4.1012 static int read_from_file(uint8_t **data, size_t *data_length) 4.1013 { 4.1014 - int res; 4.1015 -- struct file *fp; 4.1016 -- mm_segment_t old_fs = get_fs(); 4.1017 -- fp = filp_open(TPM_STORAGE_FILE, O_RDONLY, 0); 4.1018 -- if (IS_ERR(fp)) return -1; 4.1019 -- *data_length = (size_t)fp->f_dentry->d_inode->i_size; 4.1020 -- /* *data_length = i_size_read(fp->f_dentry->d_inode); */ 4.1021 -- *data = tpm_malloc(*data_length); 4.1022 -- if (*data == NULL) { 4.1023 -- filp_close(fp, NULL); 4.1024 +- int fp, file_status; 4.1025 +- struct stat file_info; 4.1026 +- fp = open(TPM_STORAGE_FILE, O_RDONLY, 0); 4.1027 +- file_status = fstat(fp, &file_info); 4.1028 +- if (file_status < 0) { 4.1029 +- close(fp); 4.1030 +- return -1; 4.1031 +- } 4.1032 + int res, out_data_size, in_header_size; 4.1033 + uint8_t *ptr, *out_data, *in_header; 4.1034 + UINT16 tag = VTPM_TAG_REQ; 4.1035 @@ -1074,7 +264,11 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 4.1036 + vtpm_tx_fh = open(VTPM_TX_FIFO, O_WRONLY); 4.1037 +#endif 4.1038 + } 4.1039 -+ 4.1040 + 4.1041 +- *data_length = file_info.st_size; 4.1042 +- *data = tpm_malloc(*data_length); 4.1043 +- if (*data == NULL) { 4.1044 +- close(fp); 4.1045 + if (vtpm_tx_fh < 0) { 4.1046 + return -1; 4.1047 + } 4.1048 @@ -1101,10 +295,8 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 4.1049 + free(out_data); 4.1050 return -1; 4.1051 } 4.1052 -- set_fs(get_ds()); 4.1053 -- res = fp->f_op->read(fp, *data, *data_length, &fp->f_pos); 4.1054 -- set_fs(old_fs); 4.1055 -- filp_close(fp, NULL); 4.1056 +- res = read(fp, *data, *data_length); 4.1057 +- close(fp); 4.1058 + 4.1059 + printf("\tSending LoadNVM command\n"); 4.1060 + res = write(vtpm_tx_fh, out_data, out_data_size); 4.1061 @@ -1178,504 +370,138 @@ diff -uprN tpm_emulator-0.3-x86_64/tpm/t 4.1062 } 4.1063 4.1064 #else 4.1065 -@@ -278,7 +473,6 @@ int tpm_restore_permanent_data(void) 4.1066 - 4.1067 - int tpm_erase_permanent_data(void) 4.1068 - { 4.1069 -- int res = write_to_file("", 0); 4.1070 -+ int res = write_to_file((uint8_t*)"", 0); 4.1071 - return res; 4.1072 - } 4.1073 -- 4.1074 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c vtpm/tpm/tpm_deprecated.c 4.1075 ---- tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c 2006-08-29 15:07:21.622298456 -0700 4.1076 -+++ vtpm/tpm/tpm_deprecated.c 2006-08-29 15:12:07.207882848 -0700 4.1077 -@@ -1,6 +1,7 @@ 4.1078 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.1079 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.1080 - * Swiss Federal Institute of Technology (ETH) Zurich 4.1081 -+ * Copyright (C) 2005 INTEL Corp 4.1082 - * 4.1083 - * This module is free software; you can redistribute it and/or modify 4.1084 - * it under the terms of the GNU General Public License as published 4.1085 -@@ -50,7 +51,7 @@ TPM_RESULT TPM_SaveKeyContext(TPM_KEY_HA 4.1086 - BYTE *ptr; 4.1087 - UINT32 len; 4.1088 - info("TPM_SaveKeyContext()"); 4.1089 -- res = TPM_SaveContext(keyHandle, TPM_RT_KEY, "SaveKeyContext..", 4.1090 -+ res = TPM_SaveContext(keyHandle, TPM_RT_KEY, (BYTE*)"SaveKeyContext..", 4.1091 - keyContextSize, &contextBlob); 4.1092 - if (res != TPM_SUCCESS) return res; 4.1093 - len = *keyContextSize; 4.1094 -@@ -82,7 +83,7 @@ TPM_RESULT TPM_SaveAuthContext(TPM_AUTHH 4.1095 - BYTE *ptr; 4.1096 - UINT32 len; 4.1097 - info("TPM_SaveAuthContext()"); 4.1098 -- res = TPM_SaveContext(authHandle, TPM_RT_KEY, "SaveAuthContext.", 4.1099 -+ res = TPM_SaveContext(authHandle, TPM_RT_KEY, (BYTE*)"SaveAuthContext.", 4.1100 - authContextSize, &contextBlob); 4.1101 - if (res != TPM_SUCCESS) return res; 4.1102 - len = *authContextSize; 4.1103 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h vtpm/tpm/tpm_emulator.h 4.1104 ---- tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h 2006-08-29 15:07:21.648294504 -0700 4.1105 -+++ vtpm/tpm/tpm_emulator.h 2006-08-29 15:12:07.208882696 -0700 4.1106 -@@ -1,5 +1,6 @@ 4.1107 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.1108 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.1109 -+ * Copyright (C) 2005 INTEL Corp 4.1110 - * 4.1111 - * This module is free software; you can redistribute it and/or modify 4.1112 - * it under the terms of the GNU General Public License as published 4.1113 -@@ -22,7 +23,8 @@ 4.1114 - /* TPM configuration */ 4.1115 - #define TPM_STORE_TO_FILE 1 4.1116 - #undef TPM_STRONG_PERSISTENCE 4.1117 --#undef TPM_GENERATE_EK 4.1118 -+//#undef TPM_GENERATE_EK 4.1119 -+#define TPM_GENERATE_EK 4.1120 - #undef TPM_GENERATE_SEED_DAA 4.1121 - 4.1122 - #define TPM_MANUFACTURER 0x4554485A /* 'ETHZ' */ 4.1123 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c vtpm/tpm/tpm_integrity.c 4.1124 ---- tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c 2006-08-29 15:07:21.645294960 -0700 4.1125 -+++ vtpm/tpm/tpm_integrity.c 2006-08-29 15:12:07.208882696 -0700 4.1126 -@@ -1,6 +1,7 @@ 4.1127 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.1128 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.1129 - * Swiss Federal Institute of Technology (ETH) Zurich 4.1130 -+ * Copyright (C) 2005 INTEL Corp 4.1131 - * 4.1132 - * This module is free software; you can redistribute it and/or modify 4.1133 - * it under the terms of the GNU General Public License as published 4.1134 -@@ -194,4 +195,3 @@ TPM_RESULT tpm_verify_pcr(TPM_KEY_DATA * 4.1135 - } 4.1136 - return TPM_SUCCESS; 4.1137 - } 4.1138 -- 4.1139 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_structures.h vtpm/tpm/tpm_structures.h 4.1140 ---- tpm_emulator-0.3-x86_64/tpm/tpm_structures.h 2006-08-29 15:08:20.545340792 -0700 4.1141 -+++ vtpm/tpm/tpm_structures.h 2006-08-29 15:12:07.211882240 -0700 4.1142 -@@ -1,6 +1,7 @@ 4.1143 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.1144 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.1145 - * Swiss Federal Institute of Technology (ETH) Zurich 4.1146 -+ * Copyright (C) 2005 INTEL Corp 4.1147 - * 4.1148 - * This module is free software; you can redistribute it and/or modify 4.1149 - * it under the terms of the GNU General Public License as published 4.1150 -@@ -18,7 +19,7 @@ 4.1151 - #ifndef _TPM_STRUCTURES_H_ 4.1152 - #define _TPM_STRUCTURES_H_ 4.1153 - 4.1154 --#include <linux/types.h> 4.1155 -+//#include <linux/types.h> 4.1156 - #include "crypto/rsa.h" 4.1157 - 4.1158 - /* 4.1159 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_testing.c vtpm/tpm/tpm_testing.c 4.1160 ---- tpm_emulator-0.3-x86_64/tpm/tpm_testing.c 2006-08-29 15:07:21.646294808 -0700 4.1161 -+++ vtpm/tpm/tpm_testing.c 2006-08-29 15:12:07.213881936 -0700 4.1162 -@@ -1,6 +1,7 @@ 4.1163 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.1164 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.1165 - * Swiss Federal Institute of Technology (ETH) Zurich 4.1166 -+ * Copyright (C) 2005 INTEL Corp 4.1167 - * 4.1168 - * This module is free software; you can redistribute it and/or modify 4.1169 - * it under the terms of the GNU General Public License as published 4.1170 -@@ -95,24 +96,24 @@ static int tpm_test_sha1(void) 4.1171 - struct { 4.1172 - uint8_t *data; uint32_t repetitions; uint8_t *digest; 4.1173 - } test_cases[] = {{ 4.1174 -- "abc", 1, 4.1175 -- "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D" 4.1176 -+ (uint8_t*)"abc", 1, 4.1177 -+ (uint8_t*)"\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D" 4.1178 - }, { 4.1179 -- "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1, 4.1180 -- "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1" 4.1181 -+ (uint8_t*)"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1, 4.1182 -+ (uint8_t*)"\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1" 4.1183 - }, { 4.1184 -- "a", 1000000, 4.1185 -- "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F" 4.1186 -+ (uint8_t*)"a", 1000000, 4.1187 -+ (uint8_t*)"\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F" 4.1188 - }, { 4.1189 -- "0123456701234567012345670123456701234567012345670123456701234567", 10, 4.1190 -- "\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52" 4.1191 -+ (uint8_t*)"0123456701234567012345670123456701234567012345670123456701234567", 10, 4.1192 -+ (uint8_t*)"\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52" 4.1193 - }}; 4.1194 - 4.1195 - debug("tpm_test_sha1()"); 4.1196 - for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) { 4.1197 - sha1_init(&ctx); 4.1198 - for (j = 0; j < test_cases[i].repetitions; j++) 4.1199 -- sha1_update(&ctx, test_cases[i].data, strlen(test_cases[i].data)); 4.1200 -+ sha1_update(&ctx, test_cases[i].data, strlen((char*)test_cases[i].data)); 4.1201 - sha1_final(&ctx, digest); 4.1202 - if (memcmp(digest, test_cases[i].digest, SHA1_DIGEST_LENGTH) != 0) return -1; 4.1203 - } 4.1204 -@@ -128,41 +129,41 @@ static int tpm_test_hmac(void) 4.1205 - struct { 4.1206 - uint8_t *key, key_len, *data, data_len, *digest; 4.1207 - } test_cases[] = {{ 4.1208 -- "\x0b", 20, "Hi There", 8, 4.1209 -- "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00" 4.1210 -+ (uint8_t*)"\x0b", 20, (uint8_t*)"Hi There", 8, 4.1211 -+ (uint8_t*)"\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00" 4.1212 - }, { 4.1213 -- "Jefe", 4, "what do ya want for nothing?", 28, 4.1214 -- "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79" 4.1215 -+ (uint8_t*)"Jefe", 4, (uint8_t*)"what do ya want for nothing?", 28, 4.1216 -+ (uint8_t*)"\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79" 4.1217 - }, { 4.1218 -- "\xaa", 20, "\xdd", 50, 4.1219 -- "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3" 4.1220 -+ (uint8_t*)"\xaa", 20, (uint8_t*)"\xdd", 50, 4.1221 -+ (uint8_t*)"\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3" 4.1222 - }, { 4.1223 -- "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 4.1224 -- "\x15\x16\x17\x18\x19", 25, "\xcd", 50, 4.1225 -- "\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda" 4.1226 -+ (uint8_t*)"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 4.1227 -+ "\x15\x16\x17\x18\x19", 25, (uint8_t*)"\xcd", 50, 4.1228 -+ (uint8_t*)"\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda" 4.1229 - }, { 4.1230 -- "\x0c", 20, "Test With Truncation", 20, 4.1231 -- "\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04" 4.1232 -+ (uint8_t*)"\x0c", 20, (uint8_t*)"Test With Truncation", 20, 4.1233 -+ (uint8_t*)"\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04" 4.1234 - }, { 4.1235 -- "\xaa", 80, "Test Using Larger Than Block-Size Key - Hash Key First", 54, 4.1236 -- "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12" 4.1237 -+ (uint8_t*)"\xaa", 80, (uint8_t*)"Test Using Larger Than Block-Size Key - Hash Key First", 54, 4.1238 -+ (uint8_t*)"\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12" 4.1239 - }, { 4.1240 -- "\xaa", 80, 4.1241 -- "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73, 4.1242 -- "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91" 4.1243 -+ (uint8_t*)"\xaa", 80, 4.1244 -+ (uint8_t*)"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73, 4.1245 -+ (uint8_t*)"\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91" 4.1246 - }}; 4.1247 +diff -uprN tpm_emulator/tpmd.c vtpm/tpmd.c 4.1248 +--- tpm_emulator/tpmd.c 2006-07-24 14:35:35.000000000 -0700 4.1249 ++++ vtpm/tpmd.c 2006-07-24 14:35:35.000000000 -0700 4.1250 +@@ -23,13 +23,27 @@ 4.1251 + #include <sys/time.h> 4.1252 4.1253 - debug("tpm_test_hmac()"); 4.1254 - for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) { 4.1255 -- if (strlen(test_cases[i].key) < test_cases[i].key_len) { 4.1256 -+ if (strlen((char*)test_cases[i].key) < test_cases[i].key_len) { 4.1257 - uint8_t key[test_cases[i].key_len]; 4.1258 - memset(key, test_cases[i].key[0], test_cases[i].key_len); 4.1259 - hmac_init(&ctx, key, test_cases[i].key_len); 4.1260 - } else { 4.1261 - hmac_init(&ctx, test_cases[i].key, test_cases[i].key_len); 4.1262 - } 4.1263 -- for (j = 0; j < test_cases[i].data_len; j += strlen(test_cases[i].data)) { 4.1264 -- hmac_update(&ctx, test_cases[i].data, strlen(test_cases[i].data)); 4.1265 -+ for (j = 0; j < test_cases[i].data_len; j += strlen((char*)test_cases[i].data)) { 4.1266 -+ hmac_update(&ctx, test_cases[i].data, strlen((char*)test_cases[i].data)); 4.1267 - } 4.1268 - hmac_final(&ctx, digest); 4.1269 - if (memcmp(digest, test_cases[i].digest, SHA1_DIGEST_LENGTH) != 0) return -1; 4.1270 -@@ -173,9 +174,9 @@ static int tpm_test_hmac(void) 4.1271 - static int tpm_test_rsa_EK(void) 4.1272 - { 4.1273 - int res = 0; 4.1274 -- char *data = "RSA PKCS #1 v1.5 Test-String"; 4.1275 -+ uint8_t *data = (uint8_t*)"RSA PKCS #1 v1.5 Test-String"; 4.1276 - uint8_t buf[256]; 4.1277 -- size_t buf_len, data_len = strlen(data); 4.1278 -+ size_t buf_len, data_len = strlen((char*)data); 4.1279 - rsa_private_key_t priv_key; 4.1280 - rsa_public_key_t pub_key; 4.1281 - 4.1282 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c vtpm/tpm/tpm_ticks.c 4.1283 ---- tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c 2006-08-29 15:07:21.646294808 -0700 4.1284 -+++ vtpm/tpm/tpm_ticks.c 2006-08-29 15:12:07.235878592 -0700 4.1285 -@@ -1,6 +1,7 @@ 4.1286 - /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.1287 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 4.1288 - * Swiss Federal Institute of Technology (ETH) Zurich 4.1289 -+ * Copyright (C) 2005 INTEL Corp 4.1290 - * 4.1291 - * This module is free software; you can redistribute it and/or modify 4.1292 - * it under the terms of the GNU General Public License as published 4.1293 -@@ -37,9 +38,7 @@ TPM_RESULT TPM_SetTickType(TPM_TICKTYPE 4.1294 - TPM_RESULT TPM_GetTicks(TPM_CURRENT_TICKS *currentTime) 4.1295 - { 4.1296 - info("TPM_GetTicks()"); 4.1297 -- memcpy(currentTime, &tpmData.stany.data.currentTicks, 4.1298 -- sizeof(TPM_CURRENT_TICKS)); 4.1299 -- return TPM_SUCCESS; 4.1300 -+ return TPM_DISABLED_CMD; 4.1301 - } 4.1302 - 4.1303 - TPM_RESULT TPM_TickStampBlob(TPM_KEY_HANDLE keyHandle, TPM_NONCE *antiReplay, 4.1304 -@@ -47,61 +46,12 @@ TPM_RESULT TPM_TickStampBlob(TPM_KEY_HAN 4.1305 - TPM_CURRENT_TICKS *currentTicks, 4.1306 - UINT32 *sigSize, BYTE **sig) 4.1307 - { 4.1308 -- TPM_RESULT res; 4.1309 -- TPM_KEY_DATA *key; 4.1310 -- BYTE *info, *p; 4.1311 -- UINT32 info_length, length; 4.1312 - info("TPM_TickStampBlob()"); 4.1313 -- /* get key */ 4.1314 -- key = tpm_get_key(keyHandle); 4.1315 -- if (key == NULL) return TPM_INVALID_KEYHANDLE; 4.1316 -- /* verify authorization */ 4.1317 -- res = tpm_verify_auth(auth1, key->usageAuth, keyHandle); 4.1318 -- if (res != TPM_SUCCESS) return res; 4.1319 -- if (key->keyUsage != TPM_KEY_SIGNING && key->keyUsage != TPM_KEY_LEGACY 4.1320 -- && key->keyUsage != TPM_KEY_IDENTITY) return TPM_INVALID_KEYUSAGE; 4.1321 -- /* get current ticks */ 4.1322 -- TPM_GetTicks(currentTicks); 4.1323 -- /* sign data using signature scheme PKCS1_SHA1 and TPM_SIGN_INFO container */ 4.1324 -- *sigSize = key->key.size >> 3; 4.1325 -- *sig = tpm_malloc(*sigSize); 4.1326 -- if (*sig == NULL) return TPM_FAIL; 4.1327 -- /* setup TPM_SIGN_INFO structure */ 4.1328 -- info_length = 30 + sizeof(TPM_DIGEST) + sizeof_TPM_CURRENT_TICKS(currentTicks); 4.1329 -- info = tpm_malloc(info_length); 4.1330 -- if (info == NULL) { 4.1331 -- tpm_free(*sig); 4.1332 -- return TPM_FAIL; 4.1333 -- } 4.1334 -- memcpy(&info[0], "\x05\x00TSTP", 6); 4.1335 -- memcpy(&info[6], antiReplay->nonce, 20); 4.1336 -- *(UINT32*)&info[26] = cpu_to_be32(20 4.1337 -- + sizeof_TPM_CURRENT_TICKS(currentTicks)); 4.1338 -- memcpy(&info[30], digestToStamp->digest, sizeof(TPM_DIGEST)); 4.1339 -- p = &info[30 + sizeof(TPM_DIGEST)]; 4.1340 -- length = sizeof_TPM_CURRENT_TICKS(currentTicks); 4.1341 -- if (tpm_marshal_TPM_CURRENT_TICKS(&p, &length, currentTicks) 4.1342 -- || rsa_sign(&key->key, RSA_SSA_PKCS1_SHA1, info, info_length, *sig)) { 4.1343 -- tpm_free(*sig); 4.1344 -- tpm_free(info); 4.1345 -- return TPM_FAIL; 4.1346 -- } 4.1347 -- return TPM_SUCCESS; 4.1348 -+ return TPM_DISABLED_CMD; 4.1349 - } 4.1350 + #include "tpm_emulator.h" 4.1351 ++#include "vtpm_manager.h" 4.1352 4.1353 - void tpm_update_ticks(void) 4.1354 - { 4.1355 -- if (tpmData.stany.data.currentTicks.tag == 0) { 4.1356 -- tpmData.stany.data.currentTicks.tag = TPM_TAG_CURRENT_TICKS; 4.1357 -- tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks(); 4.1358 -- tpmData.stany.data.currentTicks.tickType = tpmData.permanent.data.tickType; 4.1359 -- tpm_get_random_bytes(tpmData.stany.data.currentTicks.tickNonce.nonce, 4.1360 -- sizeof(TPM_NONCE)); 4.1361 -- tpmData.stany.data.currentTicks.tickRate = 1; 4.1362 -- tpmData.stany.data.currentTicks.tickSecurity = TICK_SEC_NO_CHECK; 4.1363 -- } else { 4.1364 -- tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks(); 4.1365 -- } 4.1366 - } 4.1367 - 4.1368 - 4.1369 -diff -uprN tpm_emulator-0.3-x86_64/tpm/tpm_transport.c vtpm/tpm/tpm_transport.c 4.1370 ---- tpm_emulator-0.3-x86_64/tpm/tpm_transport.c 2006-08-29 15:07:21.647294656 -0700 4.1371 -+++ vtpm/tpm/tpm_transport.c 2006-08-29 15:12:07.239877984 -0700 4.1372 -@@ -59,7 +59,7 @@ static int decrypt_transport_auth(TPM_KE 4.1373 - static void transport_log_in(TPM_COMMAND_CODE ordinal, BYTE parameters[20], 4.1374 - BYTE pubKeyHash[20], TPM_DIGEST *transDigest) 4.1375 - { 4.1376 -- UINT32 tag = cpu_to_be32(TPM_TAG_TRANSPORT_LOG_IN); 4.1377 -+ UINT32 tag = CPU_TO_BE32(TPM_TAG_TRANSPORT_LOG_IN); 4.1378 - BYTE *ptr, buf[sizeof_TPM_TRANSPORT_LOG_IN(x)]; 4.1379 - UINT32 len = sizeof(buf); 4.1380 - sha1_ctx_t sha1; 4.1381 -@@ -76,7 +76,7 @@ static void transport_log_in(TPM_COMMAND 4.1382 - static void transport_log_out(TPM_CURRENT_TICKS *currentTicks, BYTE parameters[20], 4.1383 - TPM_MODIFIER_INDICATOR locality, TPM_DIGEST *transDigest) 4.1384 - { 4.1385 -- UINT32 tag = cpu_to_be32(TPM_TAG_TRANSPORT_LOG_OUT); 4.1386 -+ UINT32 tag = CPU_TO_BE32(TPM_TAG_TRANSPORT_LOG_OUT); 4.1387 - BYTE *ptr, buf[sizeof_TPM_TRANSPORT_LOG_OUT(x)]; 4.1388 - UINT32 len = sizeof(buf); 4.1389 - sha1_ctx_t sha1; 4.1390 -@@ -191,7 +191,7 @@ static void decrypt_wrapped_command(BYTE 4.1391 - sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce)); 4.1392 - sha1_update(&sha1, "in", 2); 4.1393 - sha1_update(&sha1, secret, sizeof(TPM_SECRET)); 4.1394 -- j = cpu_to_be32(i); 4.1395 -+ j = CPU_TO_BE32(i); 4.1396 - sha1_update(&sha1, (BYTE*)&j, 4); 4.1397 - sha1_final(&sha1, mask); 4.1398 - for (j = 0; j < sizeof(mask) && buf_len > 0; j++) { 4.1399 -@@ -213,7 +213,7 @@ static void encrypt_wrapped_command(BYTE 4.1400 - sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce)); 4.1401 - sha1_update(&sha1, "out", 3); 4.1402 - sha1_update(&sha1, secret, sizeof(TPM_SECRET)); 4.1403 -- j = cpu_to_be32(i); 4.1404 -+ j = CPU_TO_BE32(i); 4.1405 - sha1_update(&sha1, (BYTE*)&j, 4); 4.1406 - sha1_final(&sha1, mask); 4.1407 - for (j = 0; j < sizeof(mask) && buf_len > 0; j++) { 4.1408 -@@ -253,9 +253,9 @@ TPM_RESULT TPM_ExecuteTransport(UINT32 i 4.1409 - /* verify authorization */ 4.1410 - tpm_compute_in_param_digest(&req); 4.1411 - sha1_init(&sha1); 4.1412 -- res = cpu_to_be32(TPM_ORD_ExecuteTransport); 4.1413 -+ res = CPU_TO_BE32(TPM_ORD_ExecuteTransport); 4.1414 - sha1_update(&sha1, (BYTE*)&res, 4); 4.1415 -- res = cpu_to_be32(inWrappedCmdSize); 4.1416 -+ res = CPU_TO_BE32(inWrappedCmdSize); 4.1417 - sha1_update(&sha1, (BYTE*)&res, 4); 4.1418 - sha1_update(&sha1, req.auth1.digest, sizeof(req.auth1.digest)); 4.1419 - sha1_final(&sha1, auth1->digest); 4.1420 -@@ -357,7 +357,7 @@ TPM_RESULT TPM_ReleaseTransportSigned(TP 4.1421 - /* setup a TPM_SIGN_INFO structure */ 4.1422 - memcpy(&buf[0], "\x05\x00TRAN", 6); 4.1423 - memcpy(&buf[6], antiReplay->nonce, 20); 4.1424 -- *(UINT32*)&buf[26] = cpu_to_be32(20); 4.1425 -+ *(UINT32*)&buf[26] = CPU_TO_BE32(20); 4.1426 - memcpy(&buf[30], session->transInternal.transDigest.digest, 20); 4.1427 - /* sign info structure */ 4.1428 - res = tpm_sign(key, auth1, TRUE, buf, sizeof(buf), signature, signSize); 4.1429 -diff -uprN tpm_emulator-0.3-x86_64/tpmd.c vtpm/tpmd.c 4.1430 ---- tpm_emulator-0.3-x86_64/tpmd.c 1969-12-31 16:00:00.000000000 -0800 4.1431 -+++ vtpm/tpmd.c 2006-08-29 15:12:07.240877832 -0700 4.1432 -@@ -0,0 +1,207 @@ 4.1433 -+/* Software-Based Trusted Platform Module (TPM) Emulator for Linux 4.1434 -+ * Copyright (C) 2005 INTEL Corp 4.1435 -+ * 4.1436 -+ * This module is free software; you can redistribute it and/or modify 4.1437 -+ * it under the terms of the GNU General Public License as published 4.1438 -+ * by the Free Software Foundation; either version 2 of the License, 4.1439 -+ * or (at your option) any later version. 4.1440 -+ * 4.1441 -+ * This module is distributed in the hope that it will be useful, 4.1442 -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 4.1443 -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4.1444 -+ * GNU General Public License for more details. 4.1445 -+ * 4.1446 -+ */ 4.1447 -+ 4.1448 -+#include <stdio.h> 4.1449 -+#include <stdlib.h> 4.1450 -+#include <unistd.h> 4.1451 -+#include <string.h> 4.1452 -+#include <sys/types.h> 4.1453 -+#include <sys/stat.h> 4.1454 -+#include <fcntl.h> 4.1455 -+#include <sys/time.h> 4.1456 -+ 4.1457 -+#include "tpm_emulator.h" 4.1458 -+#include "vtpm_manager.h" 4.1459 -+ 4.1460 +-#define TPM_RX_FNAME "/var/tpm/tpm_in.fifo" 4.1461 +-#define TPM_TX_FNAME "/var/tpm/tpm_out.fifo" 4.1462 +#ifdef VTPM_MULTI_VM 4.1463 + #define DEV_BE "/dev/vtpm" 4.1464 +#else 4.1465 + #define GUEST_RX_FIFO_D "/var/vtpm/fifos/tpm_cmd_to_%d.fifo" 4.1466 + #define GUEST_TX_FIFO "/var/vtpm/fifos/tpm_rsp_from_all.fifo" 4.1467 +#endif 4.1468 -+ 4.1469 + 4.1470 + int dmi_id; 4.1471 + 4.1472 -+#define BUFFER_SIZE 2048 4.1473 -+ 4.1474 + #define BUFFER_SIZE 2048 4.1475 + 4.1476 +static uint8_t ctrl_msg[] = { 0, 0, 0, 0, // destination 4.1477 + 1, 193, // VTPM_TAG 4.1478 + 0, 0, 0, 10, // Size 4.1479 + 0, 0, 0, 0}; // TPM_SUCCESS 4.1480 + 4.1481 + 4.1482 -+static int devurandom=0; 4.1483 -+ 4.1484 -+ 4.1485 -+void get_random_bytes(void *buf, int nbytes) { 4.1486 -+ 4.1487 -+ if (devurandom == 0) { 4.1488 -+ devurandom = open("/dev/urandom", O_RDONLY); 4.1489 -+ } 4.1490 + static int devurandom=0; 4.1491 + 4.1492 -+ if (read(devurandom, buf, nbytes) != nbytes) { 4.1493 -+ printf("Can't get random number.\n"); 4.1494 -+ exit(-1); 4.1495 -+ } 4.1496 -+} 4.1497 -+ 4.1498 -+uint64_t tpm_get_ticks(void) 4.1499 -+{ 4.1500 -+ //struct timeval tv; 4.1501 -+ //int gettimeofday(&tv, struct timezone *tz); 4.1502 -+ return 0; 4.1503 -+} 4.1504 -+ 4.1505 -+int main(int argc, char **argv) 4.1506 -+{ 4.1507 + 4.1508 + void get_random_bytes(void *buf, int nbytes) { 4.1509 + 4.1510 +@@ -52,18 +66,26 @@ uint64_t tpm_get_ticks(void) 4.1511 + 4.1512 + int main(int argc, char **argv) 4.1513 + { 4.1514 +- uint8_t in[BUFFER_SIZE], *out; 4.1515 + uint8_t in[BUFFER_SIZE], *out, *addressed_out; 4.1516 -+ uint32_t out_size; 4.1517 -+ int in_size, written; 4.1518 + uint32_t out_size; 4.1519 + int in_size, written; 4.1520 +- int i; 4.1521 +- struct stat file_info; 4.1522 +- 4.1523 +- int tpm_tx_fh=-1, tpm_rx_fh=-1; 4.1524 + int i, guest_id=-1; 4.1525 + 4.1526 + int vtpm_tx_fh=-1, vtpm_rx_fh=-1; 4.1527 +#ifdef VTPM_MULTI_VM 4.1528 -+ if (argc < 2) { 4.1529 -+ printf("Usage: tpmd clear|save|deactivated\n" ); 4.1530 + if (argc < 2) { 4.1531 + printf("Usage: tpmd clear|save|deactivated\n" ); 4.1532 +#else 4.1533 + if (argc < 3) { 4.1534 + printf("Usage: tpmd clear|save|deactivated vtpmid\n" ); 4.1535 +#endif 4.1536 -+ return -1; 4.1537 -+ } 4.1538 -+ 4.1539 + return -1; 4.1540 + } 4.1541 + 4.1542 +#ifndef VTPM_MULTI_VM 4.1543 + dmi_id = atoi(argv[2]); 4.1544 +#endif 4.1545 + 4.1546 -+ /* initialize TPM emulator */ 4.1547 -+ if (!strcmp(argv[1], "clear")) { 4.1548 -+ printf("Initializing tpm: %s\n", argv[1]); 4.1549 -+ tpm_emulator_init(1); 4.1550 -+ } else if (!strcmp(argv[1], "save")) { 4.1551 -+ printf("Initializing tpm: %s\n", argv[1]); 4.1552 -+ tpm_emulator_init(2); 4.1553 -+ } else if (!strcmp(argv[1], "deactivated")) { 4.1554 -+ printf("Initializing tpm: %s\n", argv[1]); 4.1555 -+ tpm_emulator_init(3); 4.1556 -+ } else { 4.1557 -+ printf("invalid startup mode '%s'; must be 'clear', " 4.1558 -+ "'save' (default) or 'deactivated", argv[1]); 4.1559 -+ return -1; 4.1560 -+ } 4.1561 -+ 4.1562 + /* initialize TPM emulator */ 4.1563 + if (!strcmp(argv[1], "clear")) { 4.1564 + printf("Initializing tpm: %s\n", argv[1]); 4.1565 +@@ -80,46 +102,30 @@ int main(int argc, char **argv) 4.1566 + return -1; 4.1567 + } 4.1568 + 4.1569 +- if ( stat(TPM_RX_FNAME, &file_info) == -1) { 4.1570 +- if ( mkfifo(TPM_RX_FNAME, S_IWUSR | S_IRUSR ) ) { 4.1571 +- printf("Failed to create fifo %s.\n", TPM_RX_FNAME); 4.1572 +- return -1; 4.1573 +- } 4.1574 +- } 4.1575 +- 4.1576 +- if ( stat(TPM_TX_FNAME, &file_info) == -1) { 4.1577 +- if ( mkfifo(TPM_TX_FNAME, S_IWUSR | S_IRUSR ) ) { 4.1578 +- printf("Failed to create fifo %s.\n", TPM_TX_FNAME); 4.1579 +- return -1; 4.1580 +- } 4.1581 +- } 4.1582 +- 4.1583 + char *guest_rx_file = malloc(10 + strlen(GUEST_RX_FIFO_D)); 4.1584 + sprintf(guest_rx_file, GUEST_RX_FIFO_D, (uint32_t) dmi_id); 4.1585 + 4.1586 -+ while (1) { 4.1587 -+abort_command: 4.1588 + while (1) { 4.1589 + abort_command: 4.1590 +- if (tpm_rx_fh < 0) { 4.1591 +- tpm_rx_fh = open(TPM_RX_FNAME, O_RDONLY); 4.1592 + if (vtpm_rx_fh < 0) { 4.1593 +#ifdef VTPM_MUTLI_VM 4.1594 + vtpm_rx_fh = open(DEV_BE, O_RDWR); 4.1595 +#else 4.1596 + vtpm_rx_fh = open(guest_rx_file, O_RDONLY); 4.1597 +#endif 4.1598 -+ } 4.1599 -+ 4.1600 + } 4.1601 + 4.1602 +- if (tpm_rx_fh < 0) { 4.1603 + if (vtpm_rx_fh < 0) { 4.1604 -+ printf("ERROR: failed to open devices to listen to guest.\n"); 4.1605 -+ return -1; 4.1606 -+ } 4.1607 -+ 4.1608 + printf("ERROR: failed to open devices to listen to guest.\n"); 4.1609 + return -1; 4.1610 + } 4.1611 + 4.1612 +- if (tpm_tx_fh < 0) { 4.1613 +- tpm_tx_fh = open(TPM_TX_FNAME, O_WRONLY); 4.1614 +- } 4.1615 +- 4.1616 +- if (tpm_tx_fh < 0) { 4.1617 +- printf("ERROR: failed to open devices to respond to guest.\n"); 4.1618 +- return -1; 4.1619 +- } 4.1620 +- 4.1621 +- in_size = read(tpm_rx_fh, in, BUFFER_SIZE); 4.1622 + in_size = read(vtpm_rx_fh, in, BUFFER_SIZE); 4.1623 -+ if (in_size < 6) { // Magic size of minium TPM command 4.1624 -+ printf("Recv[%d] to small: 0x", in_size); 4.1625 -+ if (in_size <= 0) { 4.1626 + if (in_size < 6) { // Magic size of minium TPM command 4.1627 + printf("Recv[%d] to small: 0x", in_size); 4.1628 + if (in_size <= 0) { 4.1629 +- close(tpm_rx_fh); 4.1630 +- tpm_rx_fh = -1; 4.1631 + close(vtpm_rx_fh); 4.1632 + vtpm_rx_fh = -1; 4.1633 -+ goto abort_command; 4.1634 -+ } 4.1635 -+ } else { 4.1636 -+ printf("Recv[%d]: 0x", in_size); 4.1637 -+ for (i=0; i< in_size; i++) 4.1638 -+ printf("%x ", in[i]); 4.1639 -+ printf("\n"); 4.1640 -+ } 4.1641 -+ 4.1642 + goto abort_command; 4.1643 + } 4.1644 + } else { 4.1645 +@@ -129,28 +135,73 @@ abort_command: 4.1646 + printf("\n"); 4.1647 + } 4.1648 + 4.1649 +- 4.1650 +- if (tpm_handle_command(in, in_size, &out, &out_size) != 0) { 4.1651 +- printf("ERROR: Handler Failed.\n"); 4.1652 + if (guest_id == -1) { 4.1653 + guest_id = *((uint32_t *) in); 4.1654 + *((uint32_t *) ctrl_msg) = *((uint32_t *) in); 4.1655 @@ -1683,8 +509,9 @@ diff -uprN tpm_emulator-0.3-x86_64/tpmd. 4.1656 + if (guest_id != *((uint32_t *) in) ) { 4.1657 + printf("WARNING: More than one guest attached\n"); 4.1658 + } 4.1659 -+ } 4.1660 -+ 4.1661 + } 4.1662 + 4.1663 +- written = write(tpm_tx_fh, out, out_size); 4.1664 + if (vtpm_tx_fh < 0) { 4.1665 +#ifdef VTPM_MUTLI_VM 4.1666 + vtpm_tx_fh = open(DEV_BE, O_RDWR); 4.1667 @@ -1693,7 +520,11 @@ diff -uprN tpm_emulator-0.3-x86_64/tpmd. 4.1668 + vtpm_tx_fh = open(GUEST_TX_FIFO, O_WRONLY); 4.1669 +#endif 4.1670 + } 4.1671 -+ 4.1672 + 4.1673 +- if (written != out_size ) { 4.1674 +- printf("ERROR: Part of response not written %d/%d.\nAttempt: ", written, out_size); 4.1675 +- } else { 4.1676 +- printf("Sent[%Zu]: ", out_size); 4.1677 + if (vtpm_tx_fh < 0) { 4.1678 + printf("ERROR: failed to open devices to respond to guest.\n"); 4.1679 + return -1; 4.1680 @@ -1733,16 +564,34 @@ diff -uprN tpm_emulator-0.3-x86_64/tpmd. 4.1681 + } 4.1682 + tpm_free(out); 4.1683 + tpm_free(addressed_out); 4.1684 -+ } 4.1685 -+ 4.1686 -+ } // loop 4.1687 -+ 4.1688 -+ tpm_emulator_shutdown(); 4.1689 -+ 4.1690 + } 4.1691 +- for (i=0; i< out_size; i++) 4.1692 +- printf("%x ", out[i]); 4.1693 +- printf("\n"); 4.1694 +- tpm_free(out); 4.1695 + 4.1696 + } // loop 4.1697 + 4.1698 + tpm_emulator_shutdown(); 4.1699 + 4.1700 +- close(tpm_tx_fh); 4.1701 +- close(tpm_rx_fh); 4.1702 + close(vtpm_tx_fh); 4.1703 +#ifndef VTPM_MUTLI_VM 4.1704 + close(vtpm_rx_fh); 4.1705 + free (guest_rx_file); 4.1706 +#endif 4.1707 -+ 4.1708 -+} 4.1709 + 4.1710 + } 4.1711 +Binary files tpm_emulator/tpm_emulator and vtpm/tpm_emulator differ 4.1712 +diff -uprN tpm_emulator/tpm_version.h vtpm/tpm_version.h 4.1713 +--- tpm_emulator/tpm_version.h 2006-07-24 14:35:41.000000000 -0700 4.1714 ++++ vtpm/tpm_version.h 2006-07-24 14:35:35.000000000 -0700 4.1715 +@@ -2,5 +2,5 @@ 4.1716 + #define _TPM_VERSION_H_ 4.1717 + #define VERSION_MAJOR 0 4.1718 + #define VERSION_MINOR 4 4.1719 +-#define VERSION_BUILD 1153776940 4.1720 ++#define VERSION_BUILD 1153776935 4.1721 + #endif /* _TPM_VERSION_H_ */ 4.1722 +Binary files tpm_emulator/vtpmd and vtpm/vtpmd differ
5.1 --- a/tools/vtpm_manager/manager/dmictl.c Tue Jul 25 11:19:48 2006 +0100 5.2 +++ b/tools/vtpm_manager/manager/dmictl.c Tue Jul 25 11:30:30 2006 +0100 5.3 @@ -105,6 +105,9 @@ TPM_RESULT close_dmi(VTPM_DMI_RESOURCE * 5.4 if (dmi_res == NULL) 5.5 return TPM_SUCCESS; 5.6 5.7 + if (dmi_res->dmi_id == VTPM_CTL_DM) 5.8 + return(TPM_BAD_PARAMETER); 5.9 + 5.10 TCS_CloseContext(dmi_res->TCSContext); 5.11 dmi_res->connected = FALSE; 5.12
6.1 --- a/tools/vtpm_manager/manager/vtpm_manager_handler.c Tue Jul 25 11:19:48 2006 +0100 6.2 +++ b/tools/vtpm_manager/manager/vtpm_manager_handler.c Tue Jul 25 11:30:30 2006 +0100 6.3 @@ -166,7 +166,8 @@ TPM_RESULT VTPM_Manager_Handler( vtpm_ip 6.4 (!dmi_res->connected) ) { 6.5 vtpmhandlerlogerror(VTPM_LOG_VTPM, "Attempted access to non-existent or disconnected DMI %d. Aborting...\n", dmi); 6.6 status = TPM_BAD_PARAMETER; 6.7 - goto abort_with_error; 6.8 + // We have no one to reply to, they don't exist. 6.9 + goto abort_command; 6.10 } 6.11 6.12 if (tag == VTPM_TAG_REQ) {
7.1 --- a/tools/vtpm_manager/manager/vtpmd.c Tue Jul 25 11:19:48 2006 +0100 7.2 +++ b/tools/vtpm_manager/manager/vtpmd.c Tue Jul 25 11:30:30 2006 +0100 7.3 @@ -172,7 +172,7 @@ TPM_RESULT VTPM_New_DMI_Extra(VTPM_DMI_R 7.4 } else if (pid == 0) { 7.5 switch (startup_mode) { 7.6 case TPM_ST_CLEAR: 7.7 - execl (TPM_EMULATOR_PATH, "vtmpd", "clear", dmi_id_str, NULL); 7.8 + execl (TPM_EMULATOR_PATH, "vtpmd", "clear", dmi_id_str, NULL); 7.9 break; 7.10 case TPM_ST_STATE: 7.11 execl (TPM_EMULATOR_PATH, "vtpmd", "save", dmi_id_str, NULL);
8.1 --- a/tools/vtpm_manager/tcs/tcs.c Tue Jul 25 11:19:48 2006 +0100 8.2 +++ b/tools/vtpm_manager/tcs/tcs.c Tue Jul 25 11:30:30 2006 +0100 8.3 @@ -162,8 +162,7 @@ TPM_RESULT TCS_OpenContext(TCS_CONTEXT_H 8.4 8.5 vtpmloginfo(VTPM_LOG_TCS, "Calling TCS_OpenContext:\n"); 8.6 8.7 - // hContext must point to a null memory context handle 8.8 - if(*hContext == HANDLE_NULL) { 8.9 + if (hContext) { 8.10 CONTEXT_HANDLE* pContextHandle = (CONTEXT_HANDLE *) malloc(sizeof(CONTEXT_HANDLE)); 8.11 if (pContextHandle == NULL) 8.12 return TPM_SIZE;
9.1 --- a/tools/vtpm_manager/tcs/transmit.c Tue Jul 25 11:19:48 2006 +0100 9.2 +++ b/tools/vtpm_manager/tcs/transmit.c Tue Jul 25 11:30:30 2006 +0100 9.3 @@ -49,8 +49,8 @@ static int g_tx_fd = -1; // 9.4 #define TPM_TX_FNAME "/dev/tpm0" 9.5 static int *g_rx_fdp = &g_tx_fd; 9.6 #else 9.7 - #define TPM_TX_FNAME "/tmp/tpm_in.fifo" 9.8 - #define TPM_RX_FNAME "/tmp/tpm_out.fifo" 9.9 + #define TPM_TX_FNAME "/var/tpm/tpm_in.fifo" 9.10 + #define TPM_RX_FNAME "/var/tpm/tpm_out.fifo" 9.11 static int g_rx_fd = -1; 9.12 static int *g_rx_fdp = &g_rx_fd; // the fd to the TPM 9.13 #endif