aboutsummaryrefslogtreecommitdiffstats
path: root/tools/vtpm/tpm_emulator-0.2b-x86_64.patch
blob: 0c46598da7d497735142d42157830be9b770d1a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
diff -uprN tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c
--- tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c	2005-09-19 14:10:29.000000000 -0700
@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne
 {
   void *ret  = (void*)kmalloc(size, GFP_KERNEL);
   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 
-    "GMP: cannot allocate memory (size=%u)\n", size);
+    "GMP: cannot allocate memory (size=%Zu)\n", size);
   return ret;
 }
 
@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne
 {
   void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
-    "(old_size=%u new_size=%u)\n", old_size, new_size);
+    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
   memcpy(ret, oldptr, old_size);
   kfree(oldptr);
   return ret;
diff -uprN tpm_emulator-0.2/linux_module.c tpm_emulator-0.2-x86_64/linux_module.c
--- tpm_emulator-0.2/linux_module.c	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/linux_module.c	2005-09-19 14:10:29.000000000 -0700
@@ -66,7 +66,7 @@ static int tpm_release(struct inode *ino
 
 static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)
 {
-  debug("%s(%d)", __FUNCTION__, count);
+  debug("%s(%Zu)", __FUNCTION__, count);
   down(&tpm_mutex);
   if (tpm_response.data != NULL) {
     count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
@@ -81,7 +81,7 @@ static ssize_t tpm_read(struct file *fil
 
 static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
 {
-  debug("%s(%d)", __FUNCTION__, count);
+  debug("%s(%Zu)", __FUNCTION__, count);
   down(&tpm_mutex);
   *ppos = 0;
   if (tpm_response.data != NULL) kfree(tpm_response.data);
diff -uprN tpm_emulator-0.2/linux_module.h tpm_emulator-0.2-x86_64/linux_module.h
--- tpm_emulator-0.2/linux_module.h	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/linux_module.h	2005-09-19 14:10:29.000000000 -0700
@@ -28,8 +28,10 @@
 
 /* module settings */
 
+#ifndef STR
 #define STR(s) __STR__(s)
 #define __STR__(s) #s
+#endif
 #include "tpm_version.h"
 
 #define TPM_DEVICE_MINOR	224
diff -uprN tpm_emulator-0.2/Makefile tpm_emulator-0.2-x86_64/Makefile
--- tpm_emulator-0.2/Makefile	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/Makefile	2005-09-19 14:10:29.000000000 -0700
@@ -7,6 +7,7 @@
 KERNEL_RELEASE := $(shell uname -r)
 KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
 MOD_SUBDIR     := misc
+COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
 
 # module settings
 MODULE_NAME    := tpm_emulator
@@ -17,8 +18,14 @@ VERSION_BUILD  := $(shell date +"%s")
 # enable/disable DEBUG messages
 EXTRA_CFLAGS   += -DDEBUG -g  
 
+ifeq ($(COMPILE_ARCH),x86_64)
+LIBDIR = lib64
+else
+LIBDIR = lib
+endif
+
 # GNU MP configuration
-GMP_LIB        := /usr/lib/libgmp.a
+GMP_LIB        := /usr/$(LIBDIR)/libgmp.a
 GMP_HEADER     := /usr/include/gmp.h
 
 # sources and objects
diff -uprN tpm_emulator-0.2/README tpm_emulator-0.2-x86_64/README
--- tpm_emulator-0.2/README	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/README	2005-09-19 14:21:43.000000000 -0700
@@ -45,6 +45,12 @@ Example:
 GMP_LIB        := /usr/lib/libgmp.a
 GMP_HEADER     := /usr/include/gmp.h
 
+GNU MP Library on 64 bit Systems
+--------------------------------------------------------------------------
+Some 64-bit kernels have problems with importing the user-space gmp 
+library (/usr/lib*/libgmp.a) into kernel space.  These kernels will require
+that the gmp library be recompiled for kernel space with -mcmodel=kernel.
+
 Installation
 --------------------------------------------------------------------------
 The compilation and installation process uses the build environment for 
diff -uprN tpm_emulator-0.2/tpm/tpm_credentials.c tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c
--- tpm_emulator-0.2/tpm/tpm_credentials.c	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c	2005-09-19 14:10:29.000000000 -0700
@@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC
 
 TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey)
 {
-  UINT32 key_length;
+  size_t key_length;
   if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT;
   /* setup TPM_PUBKEY structure */
-  key_length = tpmData.permanent.data.endorsementKey.size;
-  pubEndorsementKey->pubKey.keyLength = key_length >> 3;
+  pubEndorsementKey->pubKey.keyLength = tpmData.permanent.data.endorsementKey.size >> 3;
   pubEndorsementKey->pubKey.key = tpm_malloc(pubEndorsementKey->pubKey.keyLength);
   if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL;
   rsa_export_modulus(&tpmData.permanent.data.endorsementKey,
-    pubEndorsementKey->pubKey.key,
-    &pubEndorsementKey->pubKey.keyLength);
+		     pubEndorsementKey->pubKey.key,
+		     &key_length);
+  pubEndorsementKey->pubKey.keyLength = key_length;
   pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA;
   pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
   pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE;
@@ -169,6 +169,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
 {
   TPM_RESULT res;
   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
+  size_t key_length;
   info("TPM_OwnerReadInternalPub()");
   /* verify authorization */
   res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
@@ -180,7 +181,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
     publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength);
     if (publicPortion->pubKey.key == NULL) return TPM_FAIL;
     rsa_export_modulus(&srk->key, publicPortion->pubKey.key, 
-      &publicPortion->pubKey.keyLength);
+      &key_length);
+    publicPortion->pubKey.keyLength = key_length;
     publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA;
     publicPortion->algorithmParms.encScheme = srk->encScheme;
     publicPortion->algorithmParms.sigScheme = srk->sigScheme;
diff -uprN tpm_emulator-0.2/tpm/tpm_crypto.c tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c
--- tpm_emulator-0.2/tpm/tpm_crypto.c	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c	2005-09-19 14:10:29.000000000 -0700
@@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
   TPM_KEY_DATA *cert, *key;
   sha1_ctx_t sha1_ctx;
   BYTE *buf, *p;
-  UINT32 length;
+  UINT32 length32;
+  size_t length;
   info("TPM_CertifyKey()");
   /* get keys */
   cert = tpm_get_key(certHandle);
@@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
   p = buf = tpm_malloc(length);
+  length32=(UINT32) length;
   if (buf == NULL
-      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
+      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
     return TPM_FAIL;
   }
   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
   sha1_init(&sha1_ctx);
-  sha1_update(&sha1_ctx, buf, length);
+  sha1_update(&sha1_ctx, buf, (size_t) length);
   sha1_final(&sha1_ctx, buf);
   res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSize);
   tpm_free(buf);
@@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
   TPM_KEY_DATA *cert, *key;
   sha1_ctx_t sha1_ctx;
   BYTE *buf, *p;
-  UINT32 length;
+  size_t length;
+  UINT32 length32;
   info("TPM_CertifyKey2()");
   /* get keys */
   cert = tpm_get_key(certHandle);
@@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
   p = buf = tpm_malloc(length);
+  length32 = (UINT32) length;
   if (buf == NULL
-      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
+      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
     return TPM_FAIL;
   }
diff -uprN tpm_emulator-0.2/tpm/tpm_data.c tpm_emulator-0.2-x86_64/tpm/tpm_data.c
--- tpm_emulator-0.2/tpm/tpm_data.c	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/tpm/tpm_data.c	2005-09-19 14:10:29.000000000 -0700
@@ -179,7 +179,7 @@ static int read_from_file(uint8_t **data
 int tpm_store_permanent_data(void)
 {
   uint8_t *buf, *ptr;
-  size_t buf_length, len;
+  UINT32 buf_length, len;
 
   /* marshal data */
   buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
@@ -207,13 +207,14 @@ int tpm_store_permanent_data(void)
 int tpm_restore_permanent_data(void)
 {
   uint8_t *buf, *ptr;
-  size_t buf_length, len;
+  size_t buf_length;
+  UINT32 len;
   TPM_VERSION ver;
 
   /* read data */
   if (read_from_file(&buf, &buf_length)) return -1;
   ptr = buf;
-  len = buf_length;
+  len = (uint32_t) buf_length;
   /* unmarshal data */
   if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
       || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
diff -uprN tpm_emulator-0.2/tpm/tpm_marshalling.c tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c
--- tpm_emulator-0.2/tpm/tpm_marshalling.c	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c	2005-09-19 14:10:29.000000000 -0700
@@ -981,7 +981,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
 
 int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
 {
-  UINT32 m_len, e_len, q_len;
+  size_t m_len, e_len, q_len;
   if (*length < sizeof_RSA((*v))) return -1;
   if (v->size > 0) {
     rsa_export_modulus(v, &(*ptr)[6], &m_len);
diff -uprN tpm_emulator-0.2/tpm/tpm_owner.c tpm_emulator-0.2-x86_64/tpm/tpm_owner.c
--- tpm_emulator-0.2/tpm/tpm_owner.c	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/tpm/tpm_owner.c	2005-09-19 14:10:29.000000000 -0700
@@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
   TPM_RESULT res;
   rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
-  UINT32 buf_size = ek->size >> 3;
+  size_t buf_size = ek->size >> 3, key_length; 
   BYTE buf[buf_size];
 
   info("TPM_TakeOwnership()");
@@ -172,7 +172,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
     return TPM_FAIL;
   }
   rsa_export_modulus(&srk->key, srkPub->pubKey.key,
-    &srkPub->pubKey.keyLength);
+		     &key_length);
+  srkPub->pubKey.keyLength = (UINT32) key_length;
   /* setup tpmProof and set state to owned */
   tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 
     sizeof(tpmData.permanent.data.tpmProof.nonce));
diff -uprN tpm_emulator-0.2/tpm/tpm_storage.c tpm_emulator-0.2-x86_64/tpm/tpm_storage.c
--- tpm_emulator-0.2/tpm/tpm_storage.c	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/tpm/tpm_storage.c	2005-09-19 14:10:29.000000000 -0700
@@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
                         BYTE *enc, UINT32 *enc_size)
 {
   UINT32 len;
+  size_t enc_size32 = *enc_size;
   BYTE *buf, *ptr;
   rsa_public_key_t pub_key;
   int scheme;
@@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
   if (buf == NULL
       || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal)
       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)),
-                     enc, enc_size)) {
+                     enc, &enc_size32)) {
     tpm_free(buf);
     rsa_release_public_key(&pub_key);
     return -1;
@@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
 int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
                         TPM_SEALED_DATA *seal, BYTE **buf) 
 {
-  UINT32 len;
+  size_t len;
+  UINT32 len32;
   BYTE *ptr;
   int scheme;
   switch (key->encScheme) {
@@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke
   len = enc_size;
   *buf = ptr = tpm_malloc(len);
   if (*buf == NULL
-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
-      || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) {
+      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){
+    tpm_free(*buf);
+    return -1;
+  }
+  len32 = len;
+  if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) {
     tpm_free(*buf);
     return -1;
   }
@@ -237,11 +243,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par
 
 TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize,
                       BYTE *inData, TPM_AUTH *auth1, 
-                      UINT32 *outDataSize, BYTE **outData)
+                      UINT32 *outDataSize32, BYTE **outData)
 {
   TPM_RESULT res;
   TPM_KEY_DATA *key;
   int scheme;
+  size_t outDataSize;
   info("TPM_UnBind()");
   /* get key */
   key = tpm_get_key(keyHandle);
@@ -258,8 +265,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
   /* the size of the input data muss be greater than zero */
   if (inDataSize == 0) return TPM_BAD_PARAMETER;
   /* decrypt data */
-  *outDataSize = inDataSize;
-  *outData = tpm_malloc(*outDataSize);
+  outDataSize = inDataSize;
+  *outData = tpm_malloc(outDataSize);
   if (*outData == NULL) return TPM_FAIL;
   switch (key->encScheme) {
     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
@@ -267,20 +274,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
     default: tpm_free(*outData); return TPM_DECRYPT_ERROR;
   }
   if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 
-      *outData, outDataSize)) {
+		  *outData, &outDataSize) ) { 
     tpm_free(*outData);
     return TPM_DECRYPT_ERROR;
   }
   /* verify data if it is of type TPM_BOUND_DATA */
   if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 
       || key->keyUsage != TPM_KEY_LEGACY) {
-    if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
+    if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
       tpm_free(*outData);
       return TPM_DECRYPT_ERROR;
     }
-    *outDataSize -= 5;
-    memmove(*outData, &(*outData)[5], *outDataSize);   
-  } 
+    outDataSize -= 5;
+    memmove(*outData, &(*outData)[5], outDataSize);   
+  }
+  *outDataSize32 = (UINT32) outDataSize; 
   return TPM_SUCCESS;
 }
 
@@ -311,12 +319,13 @@ static int verify_key_digest(TPM_KEY *ke
 }
 
 int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store,
-                        BYTE *enc, UINT32 *enc_size)
+                        BYTE *enc, UINT32 *enc_size32)
 {
   UINT32 len;
   BYTE *buf, *ptr;
   rsa_public_key_t pub_key;
   int scheme;
+  size_t enc_size;
   switch (key->encScheme) {
     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
     case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break;
@@ -328,11 +337,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke
   if (buf == NULL
       || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store)
       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)),
-                     enc, enc_size)) {
+                     enc, &enc_size)) {
     tpm_free(buf);
     rsa_release_public_key(&pub_key);
     return -1;
   }
+  *enc_size32 = (UINT32) enc_size;
   tpm_free(buf);
   rsa_release_public_key(&pub_key);
   return 0;
@@ -341,7 +351,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke
 int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 
                         TPM_STORE_ASYMKEY *store, BYTE **buf) 
 {
-  UINT32 len;
+  UINT32 len32;
+  size_t len;
   BYTE *ptr;
   int scheme;
   switch (key->encScheme) {
@@ -352,11 +363,16 @@ int decrypt_private_key(TPM_KEY_DATA *ke
   len = enc_size;
   *buf = ptr = tpm_malloc(len);
   if (*buf == NULL
-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
-      || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) {
+      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) {
+    tpm_free(*buf);
+    return -1;
+  }
+  len32 = (UINT32) len;
+  if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) {  
     tpm_free(*buf);
     return -1;
   }
+
   return 0;
 }
 
@@ -371,7 +387,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
   TPM_SESSION_DATA *session;
   TPM_STORE_ASYMKEY store;
   rsa_private_key_t rsa;
-  UINT32 key_length;
+  size_t key_length;
 
   info("TPM_CreateWrapKey()");
   /* get parent key */
@@ -428,11 +444,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
   }
   if (compute_key_digest(wrappedKey, &store.pubDataDigest)) return TPM_FAIL;
   /* generate key and store it */
-  key_length = keyInfo->algorithmParms.parms.rsa.keyLength;
-  if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL;
-  wrappedKey->pubKey.keyLength = key_length >> 3;
+  if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 
+    return TPM_FAIL;
+  wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3;
   wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength);
-  store.privKey.keyLength = key_length >> 4;
+  store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4;
   store.privKey.key = tpm_malloc(store.privKey.keyLength);
   wrappedKey->encDataSize = parent->key.size >> 3;
   wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize);
@@ -444,9 +460,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
     tpm_free(wrappedKey->encData);
     return TPM_FAIL;
   }
-  rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 
-    &wrappedKey->pubKey.keyLength);
-  rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength);
+  rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
+		     &key_length);
+  wrappedKey->pubKey.keyLength = (UINT32) key_length;
+  rsa_export_prime1(&rsa, store.privKey.key, &key_length);
+  store.privKey.keyLength = (UINT32) key_length;
   rsa_release_private_key(&rsa);
   /* encrypt private key data */
   if (encrypt_private_key(parent, &store, wrappedKey->encData, 
@@ -560,6 +578,7 @@ TPM_RESULT TPM_LoadKey(TPM_KEY_HANDLE pa
 
 int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms)
 {
+  size_t key_length;
   parms->algorithmID = TPM_ALG_RSA;
   parms->encScheme = key->encScheme;
   parms->sigScheme = key->sigScheme;
@@ -569,7 +588,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke
   parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize);
   if (parms->parms.rsa.exponent == NULL) return -1;
   rsa_export_exponent(&key->key, parms->parms.rsa.exponent,
-    &parms->parms.rsa.exponentSize);
+                      &key_length);  
+  parms->parms.rsa.exponentSize = (UINT32) key_length;
   parms->parmSize = 12 + parms->parms.rsa.exponentSize;  
   return 0;
 }
@@ -580,6 +600,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
   TPM_RESULT res;
   TPM_KEY_DATA *key;
   TPM_DIGEST digest;
+  size_t key_length;
   info("TPM_GetPubKey()");
   /* get key */
   if (keyHandle == TPM_KH_SRK) return TPM_BAD_PARAMETER;
@@ -607,8 +628,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
   pubKey->pubKey.keyLength = key->key.size >> 3;
   pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength);
   if (pubKey->pubKey.key == NULL) return TPM_FAIL;
-  rsa_export_modulus(&key->key, pubKey->pubKey.key, 
-    &pubKey->pubKey.keyLength);
+  rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 
+  pubKey->pubKey.keyLength = (UINT32) key_length;
   if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
     tpm_free(pubKey->pubKey.key);
     return TPM_FAIL;  
diff -uprN tpm_emulator-0.2/tpm_version.h tpm_emulator-0.2-x86_64/tpm_version.h
--- tpm_emulator-0.2/tpm_version.h	2005-08-15 00:58:57.000000000 -0700
+++ tpm_emulator-0.2-x86_64/tpm_version.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _TPM_VERSION_H_
-#define _TPM_VERSION_H_
-#define VERSION_MAJOR 0
-#define VERSION_MINOR 2
-#define VERSION_BUILD 1123950310
-#endif /* _TPM_VERSION_H_ */