ia64/xen-unstable

changeset 6986:492fe12a6db4

Fix .hgignore and add missing vtpm patch file.
author kaf24@firebug.cl.cam.ac.uk
date Wed Sep 21 09:56:34 2005 +0000 (2005-09-21)
parents 1bea937e53cc
children 21e7935b2025
files .hgignore tools/vtpm/tpm_emulator-0.2b-x86_64.patch
line diff
     1.1 --- a/.hgignore	Tue Sep 20 16:13:01 2005 +0000
     1.2 +++ b/.hgignore	Wed Sep 21 09:56:34 2005 +0000
     1.3 @@ -139,9 +139,10 @@
     1.4  ^tools/vnet/vnet-module/\..*\.cmd$
     1.5  ^tools/vnet/vnet-module/\.tmp_versions/.*$
     1.6  ^tools/vnet/vnet-module/vnet_module\.mod\..*$
     1.7 -^tools/vtpm/vtpm*
     1.8 -^tools/vtpm/tpm_emulator-*
     1.9 -^tools/vtpm_manager/manager/vtpm_managerd
    1.10 +^tools/vtpm/tpm_emulator/.*$
    1.11 +^tools/vtpm/tpm_emulator-.*\.tar\.gz$
    1.12 +^tools/vtpm/vtpm/.*$
    1.13 +^tools/vtpm_manager/manager/vtpm_managerd$
    1.14  ^tools/xcutils/xc_restore$
    1.15  ^tools/xcutils/xc_save$
    1.16  ^tools/xenstat/xentop/xentop$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/vtpm/tpm_emulator-0.2b-x86_64.patch	Wed Sep 21 09:56:34 2005 +0000
     2.3 @@ -0,0 +1,499 @@
     2.4 +diff -uprN tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c
     2.5 +--- tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c	2005-08-15 00:58:57.000000000 -0700
     2.6 ++++ tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c	2005-09-19 14:10:29.000000000 -0700
     2.7 +@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne
     2.8 + {
     2.9 +   void *ret  = (void*)kmalloc(size, GFP_KERNEL);
    2.10 +   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 
    2.11 +-    "GMP: cannot allocate memory (size=%u)\n", size);
    2.12 ++    "GMP: cannot allocate memory (size=%Zu)\n", size);
    2.13 +   return ret;
    2.14 + }
    2.15 + 
    2.16 +@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne
    2.17 + {
    2.18 +   void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
    2.19 +   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
    2.20 +-    "(old_size=%u new_size=%u)\n", old_size, new_size);
    2.21 ++    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
    2.22 +   memcpy(ret, oldptr, old_size);
    2.23 +   kfree(oldptr);
    2.24 +   return ret;
    2.25 +diff -uprN tpm_emulator-0.2/linux_module.c tpm_emulator-0.2-x86_64/linux_module.c
    2.26 +--- tpm_emulator-0.2/linux_module.c	2005-08-15 00:58:57.000000000 -0700
    2.27 ++++ tpm_emulator-0.2-x86_64/linux_module.c	2005-09-19 14:10:29.000000000 -0700
    2.28 +@@ -66,7 +66,7 @@ static int tpm_release(struct inode *ino
    2.29 + 
    2.30 + static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)
    2.31 + {
    2.32 +-  debug("%s(%d)", __FUNCTION__, count);
    2.33 ++  debug("%s(%Zu)", __FUNCTION__, count);
    2.34 +   down(&tpm_mutex);
    2.35 +   if (tpm_response.data != NULL) {
    2.36 +     count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
    2.37 +@@ -81,7 +81,7 @@ static ssize_t tpm_read(struct file *fil
    2.38 + 
    2.39 + static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
    2.40 + {
    2.41 +-  debug("%s(%d)", __FUNCTION__, count);
    2.42 ++  debug("%s(%Zu)", __FUNCTION__, count);
    2.43 +   down(&tpm_mutex);
    2.44 +   *ppos = 0;
    2.45 +   if (tpm_response.data != NULL) kfree(tpm_response.data);
    2.46 +diff -uprN tpm_emulator-0.2/linux_module.h tpm_emulator-0.2-x86_64/linux_module.h
    2.47 +--- tpm_emulator-0.2/linux_module.h	2005-08-15 00:58:57.000000000 -0700
    2.48 ++++ tpm_emulator-0.2-x86_64/linux_module.h	2005-09-19 14:10:29.000000000 -0700
    2.49 +@@ -28,8 +28,10 @@
    2.50 + 
    2.51 + /* module settings */
    2.52 + 
    2.53 ++#ifndef STR
    2.54 + #define STR(s) __STR__(s)
    2.55 + #define __STR__(s) #s
    2.56 ++#endif
    2.57 + #include "tpm_version.h"
    2.58 + 
    2.59 + #define TPM_DEVICE_MINOR	224
    2.60 +diff -uprN tpm_emulator-0.2/Makefile tpm_emulator-0.2-x86_64/Makefile
    2.61 +--- tpm_emulator-0.2/Makefile	2005-08-15 00:58:57.000000000 -0700
    2.62 ++++ tpm_emulator-0.2-x86_64/Makefile	2005-09-19 14:10:29.000000000 -0700
    2.63 +@@ -7,6 +7,7 @@
    2.64 + KERNEL_RELEASE := $(shell uname -r)
    2.65 + KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
    2.66 + MOD_SUBDIR     := misc
    2.67 ++COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
    2.68 + 
    2.69 + # module settings
    2.70 + MODULE_NAME    := tpm_emulator
    2.71 +@@ -17,8 +18,14 @@ VERSION_BUILD  := $(shell date +"%s")
    2.72 + # enable/disable DEBUG messages
    2.73 + EXTRA_CFLAGS   += -DDEBUG -g  
    2.74 + 
    2.75 ++ifeq ($(COMPILE_ARCH),x86_64)
    2.76 ++LIBDIR = lib64
    2.77 ++else
    2.78 ++LIBDIR = lib
    2.79 ++endif
    2.80 ++
    2.81 + # GNU MP configuration
    2.82 +-GMP_LIB        := /usr/lib/libgmp.a
    2.83 ++GMP_LIB        := /usr/$(LIBDIR)/libgmp.a
    2.84 + GMP_HEADER     := /usr/include/gmp.h
    2.85 + 
    2.86 + # sources and objects
    2.87 +diff -uprN tpm_emulator-0.2/README tpm_emulator-0.2-x86_64/README
    2.88 +--- tpm_emulator-0.2/README	2005-08-15 00:58:57.000000000 -0700
    2.89 ++++ tpm_emulator-0.2-x86_64/README	2005-09-19 14:21:43.000000000 -0700
    2.90 +@@ -45,6 +45,12 @@ Example:
    2.91 + GMP_LIB        := /usr/lib/libgmp.a
    2.92 + GMP_HEADER     := /usr/include/gmp.h
    2.93 + 
    2.94 ++GNU MP Library on 64 bit Systems
    2.95 ++--------------------------------------------------------------------------
    2.96 ++Some 64-bit kernels have problems with importing the user-space gmp 
    2.97 ++library (/usr/lib*/libgmp.a) into kernel space.  These kernels will require
    2.98 ++that the gmp library be recompiled for kernel space with -mcmodel=kernel.
    2.99 ++
   2.100 + Installation
   2.101 + --------------------------------------------------------------------------
   2.102 + The compilation and installation process uses the build environment for 
   2.103 +diff -uprN tpm_emulator-0.2/tpm/tpm_credentials.c tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c
   2.104 +--- tpm_emulator-0.2/tpm/tpm_credentials.c	2005-08-15 00:58:57.000000000 -0700
   2.105 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c	2005-09-19 14:10:29.000000000 -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 +@@ -169,6 +169,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 +@@ -180,7 +181,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 tpm_emulator-0.2/tpm/tpm_crypto.c tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c
   2.147 +--- tpm_emulator-0.2/tpm/tpm_crypto.c	2005-08-15 00:58:57.000000000 -0700
   2.148 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c	2005-09-19 14:10:29.000000000 -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 tpm_emulator-0.2/tpm/tpm_data.c tpm_emulator-0.2-x86_64/tpm/tpm_data.c
   2.199 +--- tpm_emulator-0.2/tpm/tpm_data.c	2005-08-15 00:58:57.000000000 -0700
   2.200 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_data.c	2005-09-19 14:10:29.000000000 -0700
   2.201 +@@ -179,7 +179,7 @@ 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 +@@ -207,13 +207,14 @@ int tpm_store_permanent_data(void)
   2.211 + int tpm_restore_permanent_data(void)
   2.212 + {
   2.213 +   uint8_t *buf, *ptr;
   2.214 +-  size_t buf_length, len;
   2.215 ++  size_t buf_length;
   2.216 ++  UINT32 len;
   2.217 +   TPM_VERSION ver;
   2.218 + 
   2.219 +   /* read data */
   2.220 +   if (read_from_file(&buf, &buf_length)) return -1;
   2.221 +   ptr = buf;
   2.222 +-  len = buf_length;
   2.223 ++  len = (uint32_t) buf_length;
   2.224 +   /* unmarshal data */
   2.225 +   if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
   2.226 +       || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
   2.227 +diff -uprN tpm_emulator-0.2/tpm/tpm_marshalling.c tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c
   2.228 +--- tpm_emulator-0.2/tpm/tpm_marshalling.c	2005-08-15 00:58:57.000000000 -0700
   2.229 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c	2005-09-19 14:10:29.000000000 -0700
   2.230 +@@ -981,7 +981,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
   2.231 + 
   2.232 + int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
   2.233 + {
   2.234 +-  UINT32 m_len, e_len, q_len;
   2.235 ++  size_t m_len, e_len, q_len;
   2.236 +   if (*length < sizeof_RSA((*v))) return -1;
   2.237 +   if (v->size > 0) {
   2.238 +     rsa_export_modulus(v, &(*ptr)[6], &m_len);
   2.239 +diff -uprN tpm_emulator-0.2/tpm/tpm_owner.c tpm_emulator-0.2-x86_64/tpm/tpm_owner.c
   2.240 +--- tpm_emulator-0.2/tpm/tpm_owner.c	2005-08-15 00:58:57.000000000 -0700
   2.241 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_owner.c	2005-09-19 14:10:29.000000000 -0700
   2.242 +@@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
   2.243 +   TPM_RESULT res;
   2.244 +   rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
   2.245 +   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
   2.246 +-  UINT32 buf_size = ek->size >> 3;
   2.247 ++  size_t buf_size = ek->size >> 3, key_length; 
   2.248 +   BYTE buf[buf_size];
   2.249 + 
   2.250 +   info("TPM_TakeOwnership()");
   2.251 +@@ -172,7 +172,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
   2.252 +     return TPM_FAIL;
   2.253 +   }
   2.254 +   rsa_export_modulus(&srk->key, srkPub->pubKey.key,
   2.255 +-    &srkPub->pubKey.keyLength);
   2.256 ++		     &key_length);
   2.257 ++  srkPub->pubKey.keyLength = (UINT32) key_length;
   2.258 +   /* setup tpmProof and set state to owned */
   2.259 +   tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 
   2.260 +     sizeof(tpmData.permanent.data.tpmProof.nonce));
   2.261 +diff -uprN tpm_emulator-0.2/tpm/tpm_storage.c tpm_emulator-0.2-x86_64/tpm/tpm_storage.c
   2.262 +--- tpm_emulator-0.2/tpm/tpm_storage.c	2005-08-15 00:58:57.000000000 -0700
   2.263 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_storage.c	2005-09-19 14:10:29.000000000 -0700
   2.264 +@@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
   2.265 +                         BYTE *enc, UINT32 *enc_size)
   2.266 + {
   2.267 +   UINT32 len;
   2.268 ++  size_t enc_size32 = *enc_size;
   2.269 +   BYTE *buf, *ptr;
   2.270 +   rsa_public_key_t pub_key;
   2.271 +   int scheme;
   2.272 +@@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
   2.273 +   if (buf == NULL
   2.274 +       || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal)
   2.275 +       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)),
   2.276 +-                     enc, enc_size)) {
   2.277 ++                     enc, &enc_size32)) {
   2.278 +     tpm_free(buf);
   2.279 +     rsa_release_public_key(&pub_key);
   2.280 +     return -1;
   2.281 +@@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
   2.282 + int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
   2.283 +                         TPM_SEALED_DATA *seal, BYTE **buf) 
   2.284 + {
   2.285 +-  UINT32 len;
   2.286 ++  size_t len;
   2.287 ++  UINT32 len32;
   2.288 +   BYTE *ptr;
   2.289 +   int scheme;
   2.290 +   switch (key->encScheme) {
   2.291 +@@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke
   2.292 +   len = enc_size;
   2.293 +   *buf = ptr = tpm_malloc(len);
   2.294 +   if (*buf == NULL
   2.295 +-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
   2.296 +-      || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) {
   2.297 ++      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){
   2.298 ++    tpm_free(*buf);
   2.299 ++    return -1;
   2.300 ++  }
   2.301 ++  len32 = len;
   2.302 ++  if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) {
   2.303 +     tpm_free(*buf);
   2.304 +     return -1;
   2.305 +   }
   2.306 +@@ -237,11 +243,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par
   2.307 + 
   2.308 + TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize,
   2.309 +                       BYTE *inData, TPM_AUTH *auth1, 
   2.310 +-                      UINT32 *outDataSize, BYTE **outData)
   2.311 ++                      UINT32 *outDataSize32, BYTE **outData)
   2.312 + {
   2.313 +   TPM_RESULT res;
   2.314 +   TPM_KEY_DATA *key;
   2.315 +   int scheme;
   2.316 ++  size_t outDataSize;
   2.317 +   info("TPM_UnBind()");
   2.318 +   /* get key */
   2.319 +   key = tpm_get_key(keyHandle);
   2.320 +@@ -258,8 +265,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
   2.321 +   /* the size of the input data muss be greater than zero */
   2.322 +   if (inDataSize == 0) return TPM_BAD_PARAMETER;
   2.323 +   /* decrypt data */
   2.324 +-  *outDataSize = inDataSize;
   2.325 +-  *outData = tpm_malloc(*outDataSize);
   2.326 ++  outDataSize = inDataSize;
   2.327 ++  *outData = tpm_malloc(outDataSize);
   2.328 +   if (*outData == NULL) return TPM_FAIL;
   2.329 +   switch (key->encScheme) {
   2.330 +     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
   2.331 +@@ -267,20 +274,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
   2.332 +     default: tpm_free(*outData); return TPM_DECRYPT_ERROR;
   2.333 +   }
   2.334 +   if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 
   2.335 +-      *outData, outDataSize)) {
   2.336 ++		  *outData, &outDataSize) ) { 
   2.337 +     tpm_free(*outData);
   2.338 +     return TPM_DECRYPT_ERROR;
   2.339 +   }
   2.340 +   /* verify data if it is of type TPM_BOUND_DATA */
   2.341 +   if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 
   2.342 +       || key->keyUsage != TPM_KEY_LEGACY) {
   2.343 +-    if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
   2.344 ++    if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
   2.345 +       tpm_free(*outData);
   2.346 +       return TPM_DECRYPT_ERROR;
   2.347 +     }
   2.348 +-    *outDataSize -= 5;
   2.349 +-    memmove(*outData, &(*outData)[5], *outDataSize);   
   2.350 +-  } 
   2.351 ++    outDataSize -= 5;
   2.352 ++    memmove(*outData, &(*outData)[5], outDataSize);   
   2.353 ++  }
   2.354 ++  *outDataSize32 = (UINT32) outDataSize; 
   2.355 +   return TPM_SUCCESS;
   2.356 + }
   2.357 + 
   2.358 +@@ -311,12 +319,13 @@ static int verify_key_digest(TPM_KEY *ke
   2.359 + }
   2.360 + 
   2.361 + int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store,
   2.362 +-                        BYTE *enc, UINT32 *enc_size)
   2.363 ++                        BYTE *enc, UINT32 *enc_size32)
   2.364 + {
   2.365 +   UINT32 len;
   2.366 +   BYTE *buf, *ptr;
   2.367 +   rsa_public_key_t pub_key;
   2.368 +   int scheme;
   2.369 ++  size_t enc_size;
   2.370 +   switch (key->encScheme) {
   2.371 +     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
   2.372 +     case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break;
   2.373 +@@ -328,11 +337,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke
   2.374 +   if (buf == NULL
   2.375 +       || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store)
   2.376 +       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)),
   2.377 +-                     enc, enc_size)) {
   2.378 ++                     enc, &enc_size)) {
   2.379 +     tpm_free(buf);
   2.380 +     rsa_release_public_key(&pub_key);
   2.381 +     return -1;
   2.382 +   }
   2.383 ++  *enc_size32 = (UINT32) enc_size;
   2.384 +   tpm_free(buf);
   2.385 +   rsa_release_public_key(&pub_key);
   2.386 +   return 0;
   2.387 +@@ -341,7 +351,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke
   2.388 + int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 
   2.389 +                         TPM_STORE_ASYMKEY *store, BYTE **buf) 
   2.390 + {
   2.391 +-  UINT32 len;
   2.392 ++  UINT32 len32;
   2.393 ++  size_t len;
   2.394 +   BYTE *ptr;
   2.395 +   int scheme;
   2.396 +   switch (key->encScheme) {
   2.397 +@@ -352,11 +363,16 @@ int decrypt_private_key(TPM_KEY_DATA *ke
   2.398 +   len = enc_size;
   2.399 +   *buf = ptr = tpm_malloc(len);
   2.400 +   if (*buf == NULL
   2.401 +-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
   2.402 +-      || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) {
   2.403 ++      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) {
   2.404 ++    tpm_free(*buf);
   2.405 ++    return -1;
   2.406 ++  }
   2.407 ++  len32 = (UINT32) len;
   2.408 ++  if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) {  
   2.409 +     tpm_free(*buf);
   2.410 +     return -1;
   2.411 +   }
   2.412 ++
   2.413 +   return 0;
   2.414 + }
   2.415 + 
   2.416 +@@ -371,7 +387,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
   2.417 +   TPM_SESSION_DATA *session;
   2.418 +   TPM_STORE_ASYMKEY store;
   2.419 +   rsa_private_key_t rsa;
   2.420 +-  UINT32 key_length;
   2.421 ++  size_t key_length;
   2.422 + 
   2.423 +   info("TPM_CreateWrapKey()");
   2.424 +   /* get parent key */
   2.425 +@@ -428,11 +444,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
   2.426 +   }
   2.427 +   if (compute_key_digest(wrappedKey, &store.pubDataDigest)) return TPM_FAIL;
   2.428 +   /* generate key and store it */
   2.429 +-  key_length = keyInfo->algorithmParms.parms.rsa.keyLength;
   2.430 +-  if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL;
   2.431 +-  wrappedKey->pubKey.keyLength = key_length >> 3;
   2.432 ++  if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 
   2.433 ++    return TPM_FAIL;
   2.434 ++  wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3;
   2.435 +   wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength);
   2.436 +-  store.privKey.keyLength = key_length >> 4;
   2.437 ++  store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4;
   2.438 +   store.privKey.key = tpm_malloc(store.privKey.keyLength);
   2.439 +   wrappedKey->encDataSize = parent->key.size >> 3;
   2.440 +   wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize);
   2.441 +@@ -444,9 +460,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
   2.442 +     tpm_free(wrappedKey->encData);
   2.443 +     return TPM_FAIL;
   2.444 +   }
   2.445 +-  rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 
   2.446 +-    &wrappedKey->pubKey.keyLength);
   2.447 +-  rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength);
   2.448 ++  rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
   2.449 ++		     &key_length);
   2.450 ++  wrappedKey->pubKey.keyLength = (UINT32) key_length;
   2.451 ++  rsa_export_prime1(&rsa, store.privKey.key, &key_length);
   2.452 ++  store.privKey.keyLength = (UINT32) key_length;
   2.453 +   rsa_release_private_key(&rsa);
   2.454 +   /* encrypt private key data */
   2.455 +   if (encrypt_private_key(parent, &store, wrappedKey->encData, 
   2.456 +@@ -560,6 +578,7 @@ TPM_RESULT TPM_LoadKey(TPM_KEY_HANDLE pa
   2.457 + 
   2.458 + int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms)
   2.459 + {
   2.460 ++  size_t key_length;
   2.461 +   parms->algorithmID = TPM_ALG_RSA;
   2.462 +   parms->encScheme = key->encScheme;
   2.463 +   parms->sigScheme = key->sigScheme;
   2.464 +@@ -569,7 +588,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke
   2.465 +   parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize);
   2.466 +   if (parms->parms.rsa.exponent == NULL) return -1;
   2.467 +   rsa_export_exponent(&key->key, parms->parms.rsa.exponent,
   2.468 +-    &parms->parms.rsa.exponentSize);
   2.469 ++                      &key_length);  
   2.470 ++  parms->parms.rsa.exponentSize = (UINT32) key_length;
   2.471 +   parms->parmSize = 12 + parms->parms.rsa.exponentSize;  
   2.472 +   return 0;
   2.473 + }
   2.474 +@@ -580,6 +600,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
   2.475 +   TPM_RESULT res;
   2.476 +   TPM_KEY_DATA *key;
   2.477 +   TPM_DIGEST digest;
   2.478 ++  size_t key_length;
   2.479 +   info("TPM_GetPubKey()");
   2.480 +   /* get key */
   2.481 +   if (keyHandle == TPM_KH_SRK) return TPM_BAD_PARAMETER;
   2.482 +@@ -607,8 +628,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
   2.483 +   pubKey->pubKey.keyLength = key->key.size >> 3;
   2.484 +   pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength);
   2.485 +   if (pubKey->pubKey.key == NULL) return TPM_FAIL;
   2.486 +-  rsa_export_modulus(&key->key, pubKey->pubKey.key, 
   2.487 +-    &pubKey->pubKey.keyLength);
   2.488 ++  rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 
   2.489 ++  pubKey->pubKey.keyLength = (UINT32) key_length;
   2.490 +   if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
   2.491 +     tpm_free(pubKey->pubKey.key);
   2.492 +     return TPM_FAIL;  
   2.493 +diff -uprN tpm_emulator-0.2/tpm_version.h tpm_emulator-0.2-x86_64/tpm_version.h
   2.494 +--- tpm_emulator-0.2/tpm_version.h	2005-08-15 00:58:57.000000000 -0700
   2.495 ++++ tpm_emulator-0.2-x86_64/tpm_version.h	1969-12-31 16:00:00.000000000 -0800
   2.496 +@@ -1,6 +0,0 @@
   2.497 +-#ifndef _TPM_VERSION_H_
   2.498 +-#define _TPM_VERSION_H_
   2.499 +-#define VERSION_MAJOR 0
   2.500 +-#define VERSION_MINOR 2
   2.501 +-#define VERSION_BUILD 1123950310
   2.502 +-#endif /* _TPM_VERSION_H_ */