ia64/xen-unstable

view tools/vtpm/tpm_emulator-0.2b-x86_64.patch @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

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