ia64/xen-unstable

view tools/vtpm/tpm_emulator.patch @ 14445:cb1693873a7e

libxc: Explicitly reserve space for special pages in HVM memmap.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Mar 16 18:59:28 2007 +0000 (2007-03-16)
parents 6b08035e10c5
children 3ce70f7312d9
line source
1 diff -uprN orig/tpm_emulator-0.4/AUTHORS tpm_emulator/AUTHORS
2 --- orig/tpm_emulator-0.4/AUTHORS 2006-06-23 03:37:07.000000000 -0700
3 +++ tpm_emulator/AUTHORS 2006-07-24 14:35:35.000000000 -0700
4 @@ -1,2 +1,3 @@
5 Mario Strasser <mast@gmx.net>
6 Heiko Stamer <stamer@gaos.org> [DAA]
7 +INTEL Corp <> [Dropped to Ring3]
8 diff -uprN orig/tpm_emulator-0.4/ChangeLog tpm_emulator/ChangeLog
9 --- orig/tpm_emulator-0.4/ChangeLog 2006-06-23 03:37:07.000000000 -0700
10 +++ tpm_emulator/ChangeLog 2006-07-24 14:35:35.000000000 -0700
11 @@ -1,3 +1,6 @@
12 +????-??-?? Intel Corp
13 + * Moved module out of kernel to run as a ring 3 app
14 +
15 2006-06-23 Mario Strasser <mast@gmx.net>
16 * tpm_startup.c: behaviour of ST_CLEAR and storage of
17 persistent data adapted
18 diff -uprN orig/tpm_emulator-0.4/crypto/gmp_kernel_wrapper.c tpm_emulator/crypto/gmp_kernel_wrapper.c
19 --- orig/tpm_emulator-0.4/crypto/gmp_kernel_wrapper.c 2006-06-23 03:37:07.000000000 -0700
20 +++ tpm_emulator/crypto/gmp_kernel_wrapper.c 2006-07-24 14:35:35.000000000 -0700
21 @@ -1,5 +1,6 @@
22 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
23 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
24 + * Copyright (C) 2005 INTEL Corp
25 *
26 * This module is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published
28 @@ -24,15 +25,10 @@ int __gmp_junk;
29 void __attribute__ ((regparm(0))) __gmp_assert_fail(const char *filename,
30 int linenum, const char *expr)
31 {
32 - panic(KERN_CRIT TPM_MODULE_NAME "%s:%d: GNU MP assertion failed: %s\n",
33 + error("%s:%d: GNU MP assertion failed: %s\n",
34 filename, linenum, expr);
35 }
37 -void __attribute__ ((regparm(0))) abort(void)
38 -{
39 - panic(KERN_CRIT TPM_MODULE_NAME "GNU MP abort() was called\n");
40 -}
41 -
42 /* overwrite GNU MP random functions (used by mpz/millerrabin.c) */
44 void __attribute__ ((regparm(0))) gmp_randinit(gmp_randstate_t rstate,
45 @@ -77,20 +73,19 @@ void __attribute__ ((regparm(0))) mpz_ur
47 void __attribute__ ((regparm(0))) *kernel_allocate(size_t size)
48 {
49 - void *ret = (void*)kmalloc(size, GFP_KERNEL);
50 - if (!ret) panic(KERN_CRIT TPM_MODULE_NAME
51 - "GMP: cannot allocate memory (size=%u)\n", size);
52 + void *ret = (void*)malloc(size);
53 + if (!ret) error("GMP: cannot allocate memory (size=%Zu)\n", size);
54 return ret;
55 }
57 void __attribute__ ((regparm(0))) *kernel_reallocate(void *oldptr,
58 size_t old_size, size_t new_size)
59 {
60 - void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
61 - if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
62 - "(old_size=%u new_size=%u)\n", old_size, new_size);
63 + void *ret = (void*)malloc(new_size);
64 + if (!ret) error("GMP: Cannot reallocate memory "
65 + "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
66 memcpy(ret, oldptr, old_size);
67 - kfree(oldptr);
68 + free(oldptr);
69 return ret;
70 }
72 @@ -99,7 +94,7 @@ void __attribute__ ((regparm(0))) kernel
73 /* overwrite used memory */
74 if (blk_ptr != NULL) {
75 memset(blk_ptr, 0, blk_size);
76 - kfree(blk_ptr);
77 + free(blk_ptr);
78 }
79 }
81 diff -uprN orig/tpm_emulator-0.4/crypto/rsa.c tpm_emulator/crypto/rsa.c
82 --- orig/tpm_emulator-0.4/crypto/rsa.c 2006-06-23 03:37:07.000000000 -0700
83 +++ tpm_emulator/crypto/rsa.c 2006-07-24 14:35:35.000000000 -0700
84 @@ -1,5 +1,6 @@
85 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
86 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
87 + * Copyright (C) 2005 INTEL Corp
88 *
89 * This module is free software; you can redistribute it and/or modify
90 * it under the terms of the GNU General Public License as published
91 @@ -381,7 +382,7 @@ static int encode_message(int type, uint
92 msg[0] = 0x00;
93 get_random_bytes(&msg[1], SHA1_DIGEST_LENGTH);
94 sha1_init(&ctx);
95 - sha1_update(&ctx, "TCPA", 4);
96 + sha1_update(&ctx, (uint8_t *) "TCPA", 4);
97 sha1_final(&ctx, &msg[1 + SHA1_DIGEST_LENGTH]);
98 memset(&msg[1 + 2 * SHA1_DIGEST_LENGTH], 0x00,
99 msg_len - data_len - 2 * SHA1_DIGEST_LENGTH - 2);
100 @@ -429,7 +430,7 @@ static int decode_message(int type, uint
101 mask_generation(&msg[1], SHA1_DIGEST_LENGTH,
102 &msg[1 + SHA1_DIGEST_LENGTH], msg_len - SHA1_DIGEST_LENGTH - 1);
103 sha1_init(&ctx);
104 - sha1_update(&ctx, "TCPA", 4);
105 + sha1_update(&ctx, (uint8_t *) "TCPA", 4);
106 sha1_final(&ctx, &msg[1]);
107 if (memcmp(&msg[1], &msg[1 + SHA1_DIGEST_LENGTH],
108 SHA1_DIGEST_LENGTH) != 0) return -1;
109 diff -uprN orig/tpm_emulator-0.4/linux_module.c tpm_emulator/linux_module.c
110 --- orig/tpm_emulator-0.4/linux_module.c 2006-06-23 03:37:07.000000000 -0700
111 +++ tpm_emulator/linux_module.c 1969-12-31 16:00:00.000000000 -0800
112 @@ -1,195 +0,0 @@
113 -/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
114 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
115 - *
116 - * This module is free software; you can redistribute it and/or modify
117 - * it under the terms of the GNU General Public License as published
118 - * by the Free Software Foundation; either version 2 of the License,
119 - * or (at your option) any later version.
120 - *
121 - * This module is distributed in the hope that it will be useful,
122 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
123 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124 - * GNU General Public License for more details.
125 - *
126 - * $Id: linux_module.c 91 2006-03-13 13:51:41Z mast $
127 - */
128 -
129 -#include <linux/module.h>
130 -#include <linux/kernel.h>
131 -#include <linux/init.h>
132 -#include <linux/miscdevice.h>
133 -#include <linux/poll.h>
134 -#include "linux_module.h"
135 -#include "tpm/tpm_emulator.h"
136 -
137 -MODULE_LICENSE("GPL");
138 -MODULE_AUTHOR("Mario Strasser <mast@gmx.net>");
139 -MODULE_DESCRIPTION("Trusted Platform Module (TPM) Emulator");
140 -MODULE_SUPPORTED_DEVICE(TPM_DEVICE_NAME);
141 -
142 -/* module startup parameters */
143 -char *startup = "save";
144 -module_param(startup, charp, 0444);
145 -MODULE_PARM_DESC(startup, " Sets the startup mode of the TPM. "
146 - "Possible values are 'clear', 'save' (default) and 'deactivated.");
147 -char *storage_file = "/var/tpm/tpm_emulator-1.2.0.2";
148 -module_param(storage_file, charp, 0644);
149 -MODULE_PARM_DESC(storage_file, " Sets the persistent-data storage "
150 - "file of the TPM.");
151 -
152 -/* TPM lock */
153 -static struct semaphore tpm_mutex;
154 -
155 -/* TPM command response */
156 -static struct {
157 - uint8_t *data;
158 - uint32_t size;
159 -} tpm_response;
160 -
161 -/* module state */
162 -#define STATE_IS_OPEN 0
163 -static uint32_t module_state;
164 -static struct timespec old_time;
165 -
166 -static int tpm_open(struct inode *inode, struct file *file)
167 -{
168 - debug("%s()", __FUNCTION__);
169 - if (test_and_set_bit(STATE_IS_OPEN, (void*)&module_state)) return -EBUSY;
170 - return 0;
171 -}
172 -
173 -static int tpm_release(struct inode *inode, struct file *file)
174 -{
175 - debug("%s()", __FUNCTION__);
176 - clear_bit(STATE_IS_OPEN, (void*)&module_state);
177 - down(&tpm_mutex);
178 - if (tpm_response.data != NULL) {
179 - kfree(tpm_response.data);
180 - tpm_response.data = NULL;
181 - }
182 - up(&tpm_mutex);
183 - return 0;
184 -}
185 -
186 -static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)
187 -{
188 - debug("%s(%d)", __FUNCTION__, count);
189 - down(&tpm_mutex);
190 - if (tpm_response.data != NULL) {
191 - count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
192 - count -= copy_to_user(buf, &tpm_response.data[*ppos], count);
193 - *ppos += count;
194 - if ((size_t)tpm_response.size == (size_t)*ppos) {
195 - kfree(tpm_response.data);
196 - tpm_response.data = NULL;
197 - }
198 - } else {
199 - count = 0;
200 - }
201 - up(&tpm_mutex);
202 - return count;
203 -}
204 -
205 -static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
206 -{
207 - debug("%s(%d)", __FUNCTION__, count);
208 - down(&tpm_mutex);
209 - *ppos = 0;
210 - if (tpm_response.data != NULL) kfree(tpm_response.data);
211 - if (tpm_handle_command(buf, count, &tpm_response.data,
212 - &tpm_response.size) != 0) {
213 - count = -EILSEQ;
214 - tpm_response.data = NULL;
215 - }
216 - up(&tpm_mutex);
217 - return count;
218 -}
219 -
220 -#define TPMIOC_CANCEL _IO('T', 0x00)
221 -#define TPMIOC_TRANSMIT _IO('T', 0x01)
222 -
223 -static int tpm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
224 -{
225 - debug("%s(%d, %p)", __FUNCTION__, cmd, (char*)arg);
226 - if (cmd == TPMIOC_TRANSMIT) {
227 - uint32_t count = ntohl(*(uint32_t*)(arg + 2));
228 - down(&tpm_mutex);
229 - if (tpm_response.data != NULL) kfree(tpm_response.data);
230 - if (tpm_handle_command((char*)arg, count, &tpm_response.data,
231 - &tpm_response.size) == 0) {
232 - tpm_response.size -= copy_to_user((char*)arg, tpm_response.data,
233 - tpm_response.size);
234 - kfree(tpm_response.data);
235 - tpm_response.data = NULL;
236 - } else {
237 - tpm_response.size = 0;
238 - tpm_response.data = NULL;
239 - }
240 - up(&tpm_mutex);
241 - return tpm_response.size;
242 - }
243 - return -1;
244 -}
245 -
246 -struct file_operations fops = {
247 - .owner = THIS_MODULE,
248 - .open = tpm_open,
249 - .release = tpm_release,
250 - .read = tpm_read,
251 - .write = tpm_write,
252 - .ioctl = tpm_ioctl,
253 -};
254 -
255 -static struct miscdevice tpm_dev = {
256 - .minor = TPM_DEVICE_MINOR,
257 - .name = TPM_DEVICE_NAME,
258 - .fops = &fops,
259 -};
260 -
261 -int __init init_tpm_module(void)
262 -{
263 - int res = misc_register(&tpm_dev);
264 - if (res != 0) {
265 - error("misc_register() failed for minor %d\n", TPM_DEVICE_MINOR);
266 - return res;
267 - }
268 - /* initialize variables */
269 - sema_init(&tpm_mutex, 1);
270 - module_state = 0;
271 - tpm_response.data = NULL;
272 - old_time = current_kernel_time();
273 - /* initialize TPM emulator */
274 - if (!strcmp(startup, "clear")) {
275 - tpm_emulator_init(1);
276 - } else if (!strcmp(startup, "save")) {
277 - tpm_emulator_init(2);
278 - } else if (!strcmp(startup, "deactivated")) {
279 - tpm_emulator_init(3);
280 - } else {
281 - error("invalid startup mode '%s'; must be 'clear', "
282 - "'save' (default) or 'deactivated", startup);
283 - misc_deregister(&tpm_dev);
284 - return -EINVAL;
285 - }
286 - return 0;
287 -}
288 -
289 -void __exit cleanup_tpm_module(void)
290 -{
291 - tpm_emulator_shutdown();
292 - misc_deregister(&tpm_dev);
293 - if (tpm_response.data != NULL) kfree(tpm_response.data);
294 -}
295 -
296 -module_init(init_tpm_module);
297 -module_exit(cleanup_tpm_module);
298 -
299 -uint64_t tpm_get_ticks(void)
300 -{
301 - struct timespec new_time = current_kernel_time();
302 - uint64_t ticks = (uint64_t)(new_time.tv_sec - old_time.tv_sec) * 1000000
303 - + (new_time.tv_nsec - old_time.tv_nsec) / 1000;
304 - old_time = new_time;
305 - return (ticks > 0) ? ticks : 1;
306 -}
307 -
308 diff -uprN orig/tpm_emulator-0.4/linux_module.h tpm_emulator/linux_module.h
309 --- orig/tpm_emulator-0.4/linux_module.h 2006-06-23 03:37:07.000000000 -0700
310 +++ tpm_emulator/linux_module.h 2006-07-24 14:35:35.000000000 -0700
311 @@ -1,5 +1,6 @@
312 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
313 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
314 + * Copyright (C) 2005 INTEL Corp
315 *
316 * This module is free software; you can redistribute it and/or modify
317 * it under the terms of the GNU General Public License as published
318 @@ -17,54 +18,62 @@
319 #ifndef _LINUX_MODULE_H_
320 #define _LINUX_MODULE_H_
322 -#include <linux/version.h>
323 -#include <linux/kernel.h>
324 -#include <linux/slab.h>
325 +#include <malloc.h>
326 +#include <stdint.h>
327 +#include <stdio.h>
328 +#include <string.h>
329 #include <linux/types.h>
330 -#include <linux/string.h>
331 -#include <linux/random.h>
332 -#include <linux/time.h>
333 -#include <asm/byteorder.h>
335 -/* module settings */
336 +#include <endian.h>
337 +#define __BYTEORDER_HAS_U64__
338 +#ifdef LITTLE_ENDIAN
339 + #include <linux/byteorder/little_endian.h>
340 +#else
341 + #include <linux/byteorder/big_endian.h>
342 +#endif
344 +/* module settings */
345 +#define min(A,B) ((A)<(B)?(A):(B))
346 +#ifndef STR
347 #define STR(s) __STR__(s)
348 #define __STR__(s) #s
349 +#endif
350 #include "tpm_version.h"
352 #define TPM_DEVICE_MINOR 224
353 #define TPM_DEVICE_NAME "tpm"
354 #define TPM_MODULE_NAME "tpm_emulator"
356 -/* debug and log output functions */
357 -
358 #ifdef DEBUG
359 -#define debug(fmt, ...) printk(KERN_DEBUG "%s %s:%d: Debug: " fmt "\n", \
360 - TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__)
361 +#define debug(fmt, ...) printf("TPMD: %s:%d: Debug: " fmt "\n", \
362 + __FILE__, __LINE__, ## __VA_ARGS__)
363 #else
364 #define debug(fmt, ...)
365 #endif
366 -#define info(fmt, ...) printk(KERN_INFO "%s %s:%d: Info: " fmt "\n", \
367 - TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__)
368 -#define error(fmt, ...) printk(KERN_ERR "%s %s:%d: Error: " fmt "\n", \
369 - TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__)
370 -#define alert(fmt, ...) printk(KERN_ALERT "%s %s:%d: Alert: " fmt "\n", \
371 - TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__)
372 +#define info(fmt, ...) printf("TPMD: %s:%d: Info: " fmt "\n", \
373 + __FILE__, __LINE__, ## __VA_ARGS__)
374 +#define error(fmt, ...) printf("TPMD: %s:%d: Error: " fmt "\n", \
375 + __FILE__, __LINE__, ## __VA_ARGS__)
376 +#define alert(fmt, ...) printf("TPMD: %s:%d: Alert: " fmt "\n", \
377 + __FILE__, __LINE__, ## __VA_ARGS__)
379 /* memory allocation */
381 static inline void *tpm_malloc(size_t size)
382 {
383 - return kmalloc(size, GFP_KERNEL);
384 + return malloc(size);
385 }
387 static inline void tpm_free(const void *ptr)
388 {
389 - if (ptr != NULL) kfree(ptr);
390 + if (ptr != NULL) free( (void *) ptr);
391 }
393 /* random numbers */
395 +//FIXME;
396 +void get_random_bytes(void *buf, int nbytes);
397 +
398 static inline void tpm_get_random_bytes(void *buf, int nbytes)
399 {
400 get_random_bytes(buf, nbytes);
401 @@ -84,9 +93,9 @@ uint64_t tpm_get_ticks(void);
402 #define CPU_TO_LE16(x) __cpu_to_le16(x)
404 #define BE64_TO_CPU(x) __be64_to_cpu(x)
405 -#define LE64_TO_CPU(x) __be64_to_cpu(x)
406 +#define LE64_TO_CPU(x) __le64_to_cpu(x)
407 #define BE32_TO_CPU(x) __be32_to_cpu(x)
408 -#define LE32_TO_CPU(x) __be32_to_cpu(x)
409 +#define LE32_TO_CPU(x) __le32_to_cpu(x)
410 #define BE16_TO_CPU(x) __be16_to_cpu(x)
411 #define LE16_TO_CPU(x) __le16_to_cpu(x)
413 diff -uprN orig/tpm_emulator-0.4/Makefile tpm_emulator/Makefile
414 --- orig/tpm_emulator-0.4/Makefile 2006-06-23 03:37:07.000000000 -0700
415 +++ tpm_emulator/Makefile 2006-07-24 14:35:35.000000000 -0700
416 @@ -1,24 +1,40 @@
417 # Software-Based Trusted Platform Module (TPM) Emulator for Linux
418 # Copyright (C) 2004 Mario Strasser <mast@gmx.net>
419 +# Copyright (C) 2006 INTEL Corp.
420 #
421 # $Id: Makefile 115 2006-06-23 10:36:44Z mast $
423 -# kernel settings
424 -KERNEL_RELEASE := $(shell uname -r)
425 -KERNEL_BUILD := /lib/modules/$(KERNEL_RELEASE)/build
426 -MOD_SUBDIR := misc
427 +COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/)
429 # module settings
430 -MODULE_NAME := tpm_emulator
431 +BIN := tpm_emulator
432 VERSION_MAJOR := 0
433 VERSION_MINOR := 4
434 VERSION_BUILD := $(shell date +"%s")
436 -# enable/disable DEBUG messages
437 -EXTRA_CFLAGS += -Wall -DDEBUG -g
438 +# Installation program and options
439 +INSTALL = install
440 +INSTALL_PROG = $(INSTALL) -m0755
441 +INSTALL_DIR = $(INSTALL) -d -m0755
442 +
443 +# Xen tools installation directory
444 +TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
445 +
446 +CC := gcc
447 +CFLAGS += -g -Wall $(INCLUDE) -DDEBUG
448 +CFLAGS += -I. -Itpm
449 +
450 +# Is the simulator running in it's own vm?
451 +#CFLAGS += -DVTPM_MULTI_VM
452 +
453 +ifeq ($(COMPILE_ARCH),x86_64)
454 +LIBDIR = lib64
455 +else
456 +LIBDIR = lib
457 +endif
459 # GNU MP configuration
460 -GMP_LIB := /usr/lib/libgmp.a
461 +GMP_LIB := /usr/$(LIBDIR)/libgmp.a
462 GMP_HEADER := /usr/include/gmp.h
464 # sources and objects
465 @@ -27,38 +43,32 @@ DIRS := . crypto tpm
466 SRCS := $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.c))
467 OBJS := $(patsubst %.c, %.o, $(SRCS))
468 SRCS += $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.h))
469 -DISTSRC := ./README ./AUTHORS ./ChangeLog ./Makefile $(SRCS)
470 -DISTDIR := tpm_emulator-$(VERSION_MAJOR).$(VERSION_MINOR)
472 -obj-m := $(MODULE_NAME).o
473 -$(MODULE_NAME)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
474 +obj-m := $(BIN)
475 +$(BIN)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
477 EXTRA_CFLAGS += -I$(src) -I$(src)/crypto -I$(src)/tpm
479 # do not print "Entering directory ..."
480 MAKEFLAGS += --no-print-directory
482 -all: $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version
483 - @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules
484 +all: $(BIN)
486 -install:
487 - @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules_install
488 - test -d /var/tpm || mkdir /var/tpm
489 - test -c /dev/tpm || mknod /dev/tpm c 10 224
490 - chmod 666 /dev/tpm
491 - depmod -a
492 +$(BIN): $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version $(SRCS) $(OBJS)
493 + $(CC) $(CFLAGS) $(OBJS) $(src)/crypto/libgmp.a -o $(BIN)
494 +
495 +%.o: %.c
496 + $(CC) $(CFLAGS) -c $< -o $@
497 +
498 +install: $(BIN)
499 + $(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
500 + @if [ ! -d "/var/tpm" ]; then mkdir /var/tpm; fi
502 clean:
503 - @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) clean
504 - rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a
505 + rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS)
507 -dist: $(DISTSRC)
508 - rm -rf $(DISTDIR)
509 - mkdir $(DISTDIR)
510 - cp --parents $(DISTSRC) $(DISTDIR)/
511 - rm -f $(DISTDIR)/crypto/gmp.h
512 - tar -chzf $(DISTDIR).tar.gz $(DISTDIR)
513 - rm -rf $(DISTDIR)
514 +mrproper: clean
515 + rm -f $(BIN) tpm_version.h
517 $(src)/crypto/libgmp.a:
518 test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a
519 @@ -88,4 +98,3 @@ version:
520 @echo "#endif /* _TPM_VERSION_H_ */" >> $(src)/tpm_version.h
522 .PHONY: all install clean dist gmp version
523 -
524 diff -uprN orig/tpm_emulator-0.4/README tpm_emulator/README
525 --- orig/tpm_emulator-0.4/README 2006-06-23 03:37:07.000000000 -0700
526 +++ tpm_emulator/README 2006-07-24 14:35:35.000000000 -0700
527 @@ -13,7 +13,8 @@ $Id: README 113 2006-06-18 12:38:13Z hst
528 Copyright
529 --------------------------------------------------------------------------
530 Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal
531 -Institute of Technology (ETH) Zurich.
532 + Institute of Technology (ETH) Zurich.
533 +Copyright (C) 2005 INTEL Corp
535 This program is free software; you can redistribute it and/or modify
536 it under the terms of the GNU General Public License as published by
537 @@ -43,6 +44,12 @@ Example:
538 GMP_LIB := /usr/lib/libgmp.a
539 GMP_HEADER := /usr/include/gmp.h
541 +GNU MP Library on 64 bit Systems
542 +--------------------------------------------------------------------------
543 +Some 64-bit kernels have problems with importing the user-space gmp
544 +library (/usr/lib*/libgmp.a) into kernel space. These kernels will require
545 +that the gmp library be recompiled for kernel space with -mcmodel=kernel.
546 +
547 Installation
548 --------------------------------------------------------------------------
549 The compilation and installation process uses the build environment for
550 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_credentials.c tpm_emulator/tpm/tpm_credentials.c
551 --- orig/tpm_emulator-0.4/tpm/tpm_credentials.c 2006-06-23 03:37:07.000000000 -0700
552 +++ tpm_emulator/tpm/tpm_credentials.c 2006-07-24 14:35:35.000000000 -0700
553 @@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC
555 TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey)
556 {
557 - UINT32 key_length;
558 + size_t key_length;
559 if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT;
560 /* setup TPM_PUBKEY structure */
561 - key_length = tpmData.permanent.data.endorsementKey.size;
562 - pubEndorsementKey->pubKey.keyLength = key_length >> 3;
563 + pubEndorsementKey->pubKey.keyLength = tpmData.permanent.data.endorsementKey.size >> 3;
564 pubEndorsementKey->pubKey.key = tpm_malloc(pubEndorsementKey->pubKey.keyLength);
565 if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL;
566 rsa_export_modulus(&tpmData.permanent.data.endorsementKey,
567 - pubEndorsementKey->pubKey.key,
568 - &pubEndorsementKey->pubKey.keyLength);
569 + pubEndorsementKey->pubKey.key,
570 + &key_length);
571 + pubEndorsementKey->pubKey.keyLength = key_length;
572 pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA;
573 pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
574 pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE;
575 @@ -175,6 +175,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
576 {
577 TPM_RESULT res;
578 TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
579 + size_t key_length;
580 info("TPM_OwnerReadInternalPub()");
581 /* verify authorization */
582 res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
583 @@ -186,7 +187,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
584 publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength);
585 if (publicPortion->pubKey.key == NULL) return TPM_FAIL;
586 rsa_export_modulus(&srk->key, publicPortion->pubKey.key,
587 - &publicPortion->pubKey.keyLength);
588 + &key_length);
589 + publicPortion->pubKey.keyLength = key_length;
590 publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA;
591 publicPortion->algorithmParms.encScheme = srk->encScheme;
592 publicPortion->algorithmParms.sigScheme = srk->sigScheme;
593 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_crypto.c tpm_emulator/tpm/tpm_crypto.c
594 --- orig/tpm_emulator-0.4/tpm/tpm_crypto.c 2006-06-23 03:37:07.000000000 -0700
595 +++ tpm_emulator/tpm/tpm_crypto.c 2006-07-24 14:35:35.000000000 -0700
596 @@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
597 TPM_KEY_DATA *cert, *key;
598 sha1_ctx_t sha1_ctx;
599 BYTE *buf, *p;
600 - UINT32 length;
601 + UINT32 length32;
602 + size_t length;
603 info("TPM_CertifyKey()");
604 /* get keys */
605 cert = tpm_get_key(certHandle);
606 @@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
607 /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
608 length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
609 p = buf = tpm_malloc(length);
610 + length32=(UINT32) length;
611 if (buf == NULL
612 - || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
613 + || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
614 free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
615 return TPM_FAIL;
616 }
617 length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
618 sha1_init(&sha1_ctx);
619 - sha1_update(&sha1_ctx, buf, length);
620 + sha1_update(&sha1_ctx, buf, (size_t) length);
621 sha1_final(&sha1_ctx, buf);
622 res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSize);
623 tpm_free(buf);
624 @@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
625 TPM_KEY_DATA *cert, *key;
626 sha1_ctx_t sha1_ctx;
627 BYTE *buf, *p;
628 - UINT32 length;
629 + size_t length;
630 + UINT32 length32;
631 info("TPM_CertifyKey2()");
632 /* get keys */
633 cert = tpm_get_key(certHandle);
634 @@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
635 /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
636 length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
637 p = buf = tpm_malloc(length);
638 + length32 = (UINT32) length;
639 if (buf == NULL
640 - || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
641 + || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
642 free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
643 return TPM_FAIL;
644 }
645 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_daa.c tpm_emulator/tpm/tpm_daa.c
646 --- orig/tpm_emulator-0.4/tpm/tpm_daa.c 2006-06-23 03:37:07.000000000 -0700
647 +++ tpm_emulator/tpm/tpm_daa.c 2006-07-24 14:35:35.000000000 -0700
648 @@ -716,14 +716,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl
649 sizeof(session->DAA_tpmSpecific.DAA_rekey));
650 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
651 sizeof(session->DAA_tpmSpecific.DAA_count));
652 - sha1_update(&sha1, "\x00", 1);
653 + sha1_update(&sha1, (BYTE *) "\x00", 1);
654 sha1_final(&sha1, scratch);
655 sha1_init(&sha1);
656 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
657 sizeof(session->DAA_tpmSpecific.DAA_rekey));
658 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
659 sizeof(session->DAA_tpmSpecific.DAA_count));
660 - sha1_update(&sha1, "\x01", 1);
661 + sha1_update(&sha1, (BYTE *) "\x01", 1);
662 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
663 mpz_init(f), mpz_init(q);
664 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
665 @@ -805,14 +805,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl
666 sizeof(session->DAA_tpmSpecific.DAA_rekey));
667 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
668 sizeof(session->DAA_tpmSpecific.DAA_count));
669 - sha1_update(&sha1, "\x00", 1);
670 + sha1_update(&sha1, (BYTE *) "\x00", 1);
671 sha1_final(&sha1, scratch);
672 sha1_init(&sha1);
673 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
674 sizeof(session->DAA_tpmSpecific.DAA_rekey));
675 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
676 sizeof(session->DAA_tpmSpecific.DAA_count));
677 - sha1_update(&sha1, "\x01", 1);
678 + sha1_update(&sha1, (BYTE *) "\x01", 1);
679 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
680 mpz_init(f), mpz_init(q);
681 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
682 @@ -1489,14 +1489,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl
683 sizeof(session->DAA_tpmSpecific.DAA_rekey));
684 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
685 sizeof(session->DAA_tpmSpecific.DAA_count));
686 - sha1_update(&sha1, "\x00", 1);
687 + sha1_update(&sha1, (BYTE *) "\x00", 1);
688 sha1_final(&sha1, scratch);
689 sha1_init(&sha1);
690 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
691 sizeof(session->DAA_tpmSpecific.DAA_rekey));
692 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
693 sizeof(session->DAA_tpmSpecific.DAA_count));
694 - sha1_update(&sha1, "\x01", 1);
695 + sha1_update(&sha1, (BYTE *) "\x01", 1);
696 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
697 mpz_init(f), mpz_init(q);
698 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
699 @@ -1712,14 +1712,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl
700 sizeof(session->DAA_tpmSpecific.DAA_rekey));
701 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
702 sizeof(session->DAA_tpmSpecific.DAA_count));
703 - sha1_update(&sha1, "\x00", 1);
704 + sha1_update(&sha1, (BYTE *) "\x00", 1);
705 sha1_final(&sha1, scratch);
706 sha1_init(&sha1);
707 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
708 sizeof(session->DAA_tpmSpecific.DAA_rekey));
709 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
710 sizeof(session->DAA_tpmSpecific.DAA_count));
711 - sha1_update(&sha1, "\x01", 1);
712 + sha1_update(&sha1, (BYTE *) "\x01", 1);
713 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
714 mpz_init(f), mpz_init(q);
715 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
716 @@ -1793,14 +1793,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl
717 sizeof(session->DAA_tpmSpecific.DAA_rekey));
718 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
719 sizeof(session->DAA_tpmSpecific.DAA_count));
720 - sha1_update(&sha1, "\x00", 1);
721 + sha1_update(&sha1, (BYTE *) "\x00", 1);
722 sha1_final(&sha1, scratch);
723 sha1_init(&sha1);
724 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
725 sizeof(session->DAA_tpmSpecific.DAA_rekey));
726 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
727 sizeof(session->DAA_tpmSpecific.DAA_count));
728 - sha1_update(&sha1, "\x01", 1);
729 + sha1_update(&sha1, (BYTE *) "\x01", 1);
730 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
731 mpz_init(f), mpz_init(q);
732 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
733 @@ -2918,14 +2918,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
734 sizeof(session->DAA_tpmSpecific.DAA_rekey));
735 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
736 sizeof(session->DAA_tpmSpecific.DAA_count));
737 - sha1_update(&sha1, "\x00", 1);
738 + sha1_update(&sha1, (BYTE *) "\x00", 1);
739 sha1_final(&sha1, scratch);
740 sha1_init(&sha1);
741 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
742 sizeof(session->DAA_tpmSpecific.DAA_rekey));
743 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
744 sizeof(session->DAA_tpmSpecific.DAA_count));
745 - sha1_update(&sha1, "\x01", 1);
746 + sha1_update(&sha1, (BYTE *) "\x01", 1);
747 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
748 mpz_init(f), mpz_init(q);
749 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
750 @@ -3143,7 +3143,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
751 sha1_init(&sha1);
752 sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest,
753 sizeof(session->DAA_session.DAA_digest));
754 - sha1_update(&sha1, "\x01", 1);
755 + sha1_update(&sha1, (BYTE *) "\x01", 1);
756 sha1_update(&sha1, inputData1, inputSize1);
757 sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest);
758 }
759 @@ -3172,7 +3172,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
760 sha1_init(&sha1);
761 sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest,
762 sizeof(session->DAA_session.DAA_digest));
763 - sha1_update(&sha1, "\x00", 1);
764 + sha1_update(&sha1, (BYTE*) "\x00", 1);
765 rsa_export_modulus(&aikData->key, scratch, &size);
766 sha1_update(&sha1, scratch, size);
767 sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest);
768 @@ -3229,14 +3229,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
769 sizeof(session->DAA_tpmSpecific.DAA_rekey));
770 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
771 sizeof(session->DAA_tpmSpecific.DAA_count));
772 - sha1_update(&sha1, "\x00", 1);
773 + sha1_update(&sha1, (BYTE *) "\x00", 1);
774 sha1_final(&sha1, scratch);
775 sha1_init(&sha1);
776 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
777 sizeof(session->DAA_tpmSpecific.DAA_rekey));
778 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
779 sizeof(session->DAA_tpmSpecific.DAA_count));
780 - sha1_update(&sha1, "\x01", 1);
781 + sha1_update(&sha1, (BYTE *) "\x01", 1);
782 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
783 mpz_init(f), mpz_init(q);
784 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
785 @@ -3309,14 +3309,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
786 sizeof(session->DAA_tpmSpecific.DAA_rekey));
787 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
788 sizeof(session->DAA_tpmSpecific.DAA_count));
789 - sha1_update(&sha1, "\x00", 1);
790 + sha1_update(&sha1, (BYTE *) "\x00", 1);
791 sha1_final(&sha1, scratch);
792 sha1_init(&sha1);
793 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
794 sizeof(session->DAA_tpmSpecific.DAA_rekey));
795 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
796 sizeof(session->DAA_tpmSpecific.DAA_count));
797 - sha1_update(&sha1, "\x01", 1);
798 + sha1_update(&sha1, (BYTE *) "\x01", 1);
799 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
800 mpz_init(f), mpz_init(q);
801 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
802 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_data.c tpm_emulator/tpm/tpm_data.c
803 --- orig/tpm_emulator-0.4/tpm/tpm_data.c 2006-06-23 03:37:07.000000000 -0700
804 +++ tpm_emulator/tpm/tpm_data.c 2006-07-24 14:35:35.000000000 -0700
805 @@ -40,6 +40,7 @@ static inline void init_pcr_attr(int pcr
806 void tpm_init_data(void)
807 {
808 /* endorsement key */
809 +#ifndef TPM_GENERATE_EK
810 uint8_t ek_n[] = "\xa8\xdb\xa9\x42\xa8\xf3\xb8\x06\x85\x90\x76\x93\xad\xf7"
811 "\x74\xec\x3f\xd3\x3d\x9d\xe8\x2e\xff\x15\xed\x0e\xce\x5f\x93"
812 "\x92\xeb\xd1\x96\x2b\x72\x18\x81\x79\x12\x9d\x9c\x40\xd7\x1a"
813 @@ -77,6 +78,8 @@ void tpm_init_data(void)
814 "\xd1\xc0\x8b\x5b\xa2\x2e\xa7\x15\xca\x50\x75\x10\x48\x9c\x2b"
815 "\x18\xb9\x67\x8f\x5d\x64\xc3\x28\x9f\x2f\x16\x2f\x08\xda\x47"
816 "\xec\x86\x43\x0c\x80\x99\x07\x34\x0f";
817 +#endif
818 +
819 int i;
820 /* reset all data to NULL, FALSE or 0 */
821 memset(&tpmData, 0, sizeof(tpmData));
822 @@ -152,44 +155,43 @@ void tpm_release_data(void)
824 #ifdef TPM_STORE_TO_FILE
826 -#include <linux/fs.h>
827 -#include <linux/unistd.h>
828 -#include <asm/uaccess.h>
829 +#include <sys/types.h>
830 +#include <sys/stat.h>
831 +#include <fcntl.h>
832 +#include <unistd.h>
834 #define TPM_STORAGE_FILE "/var/tpm/tpm_emulator-1.2." STR(VERSION_MAJOR) "." STR(VERSION_MINOR)
836 static int write_to_file(uint8_t *data, size_t data_length)
837 {
838 int res;
839 - struct file *fp;
840 - mm_segment_t old_fs = get_fs();
841 - fp = filp_open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
842 - if (IS_ERR(fp)) return -1;
843 - set_fs(get_ds());
844 - res = fp->f_op->write(fp, data, data_length, &fp->f_pos);
845 - set_fs(old_fs);
846 - filp_close(fp, NULL);
847 + int fp;
848 + fp = open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
849 + res = write(fp, data, data_length);
850 + close(fp);
851 return (res == data_length) ? 0 : -1;
852 }
854 static int read_from_file(uint8_t **data, size_t *data_length)
855 {
856 int res;
857 - struct file *fp;
858 - mm_segment_t old_fs = get_fs();
859 - fp = filp_open(TPM_STORAGE_FILE, O_RDONLY, 0);
860 - if (IS_ERR(fp)) return -1;
861 - *data_length = (size_t)fp->f_dentry->d_inode->i_size;
862 - /* *data_length = i_size_read(fp->f_dentry->d_inode); */
863 + int fp, file_status;
864 + struct stat file_info;
865 + fp = open(TPM_STORAGE_FILE, O_RDONLY, 0);
866 + file_status = fstat(fp, &file_info);
867 + if (file_status < 0) {
868 + close(fp);
869 + return -1;
870 + }
871 +
872 + *data_length = file_info.st_size;
873 *data = tpm_malloc(*data_length);
874 if (*data == NULL) {
875 - filp_close(fp, NULL);
876 + close(fp);
877 return -1;
878 }
879 - set_fs(get_ds());
880 - res = fp->f_op->read(fp, *data, *data_length, &fp->f_pos);
881 - set_fs(old_fs);
882 - filp_close(fp, NULL);
883 + res = read(fp, *data, *data_length);
884 + close(fp);
885 if (res != *data_length) {
886 tpm_free(*data);
887 return -1;
888 @@ -216,23 +218,30 @@ static int read_from_file(uint8_t **data
889 int tpm_store_permanent_data(void)
890 {
891 uint8_t *buf, *ptr;
892 - size_t buf_length, len;
893 + UINT32 buf_length, len;
895 /* marshal data */
896 - buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
897 - + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) + 2
898 - + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data);
899 + buf_length = len = 4 + sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
900 + + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags)
901 + + sizeof_TPM_STANY_FLAGS(tpmData.stany.flags) + 2
902 + + sizeof_TPM_STCLEAR_DATA(tpmData.stclear.data)
903 + + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data)
904 + + sizeof_TPM_STANY_DATA(tpmData.stany.data);
905 buf = ptr = tpm_malloc(buf_length);
906 if (buf == NULL
907 || tpm_marshal_TPM_VERSION(&ptr, &len, &tpmData.permanent.data.version)
908 || tpm_marshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags)
909 || tpm_marshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags)
910 + || tpm_marshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags)
911 || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.selfTestSucceeded)
912 || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.owned)
913 - || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) {
914 + || tpm_marshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data)
915 + || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)
916 + || tpm_marshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) {
917 tpm_free(buf);
918 return -1;
919 }
920 +
921 if (write_to_file(buf, buf_length - len)) {
922 tpm_free(buf);
923 return -1;
924 @@ -244,31 +253,36 @@ int tpm_store_permanent_data(void)
925 int tpm_restore_permanent_data(void)
926 {
927 uint8_t *buf, *ptr;
928 - size_t buf_length, len;
929 + size_t buf_length;
930 + UINT32 len;
931 TPM_VERSION ver;
933 /* read data */
934 if (read_from_file(&buf, &buf_length)) return -1;
935 ptr = buf;
936 - len = buf_length;
937 + len = (uint32_t) buf_length;
938 /* unmarshal data */
939 if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
940 || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
941 || tpm_unmarshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags)
942 || tpm_unmarshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags)
943 + || tpm_unmarshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags)
944 || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.selfTestSucceeded)
945 || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.owned)
946 - || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) {
947 + || tpm_unmarshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data)
948 + || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)
949 + || tpm_unmarshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) {
950 tpm_free(buf);
951 return -1;
952 }
953 +
954 tpm_free(buf);
955 return 0;
956 }
958 int tpm_erase_permanent_data(void)
959 {
960 - int res = write_to_file("", 0);
961 + int res = write_to_file((uint8_t *) "", 0);
962 return res;
963 }
965 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_deprecated.c tpm_emulator/tpm/tpm_deprecated.c
966 --- orig/tpm_emulator-0.4/tpm/tpm_deprecated.c 2006-06-23 03:37:07.000000000 -0700
967 +++ tpm_emulator/tpm/tpm_deprecated.c 2006-07-24 14:35:35.000000000 -0700
968 @@ -1,6 +1,7 @@
969 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
970 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
971 * Swiss Federal Institute of Technology (ETH) Zurich
972 + * Copyright (C) 2005 INTEL Corp
973 *
974 * This module is free software; you can redistribute it and/or modify
975 * it under the terms of the GNU General Public License as published
976 @@ -50,7 +51,7 @@ TPM_RESULT TPM_SaveKeyContext(TPM_KEY_HA
977 BYTE *ptr;
978 UINT32 len;
979 info("TPM_SaveKeyContext()");
980 - res = TPM_SaveContext(keyHandle, TPM_RT_KEY, "SaveKeyContext..",
981 + res = TPM_SaveContext(keyHandle, TPM_RT_KEY, (BYTE*)"SaveKeyContext..",
982 keyContextSize, &contextBlob);
983 if (res != TPM_SUCCESS) return res;
984 len = *keyContextSize;
985 @@ -82,7 +83,7 @@ TPM_RESULT TPM_SaveAuthContext(TPM_AUTHH
986 BYTE *ptr;
987 UINT32 len;
988 info("TPM_SaveAuthContext()");
989 - res = TPM_SaveContext(authHandle, TPM_RT_KEY, "SaveAuthContext.",
990 + res = TPM_SaveContext(authHandle, TPM_RT_KEY, (BYTE*)"SaveAuthContext.",
991 authContextSize, &contextBlob);
992 if (res != TPM_SUCCESS) return res;
993 len = *authContextSize;
994 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_emulator.h tpm_emulator/tpm/tpm_emulator.h
995 --- orig/tpm_emulator-0.4/tpm/tpm_emulator.h 2006-06-23 03:37:07.000000000 -0700
996 +++ tpm_emulator/tpm/tpm_emulator.h 2006-07-24 14:35:35.000000000 -0700
997 @@ -1,5 +1,6 @@
998 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
999 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1000 + * Copyright (C) 2005 INTEL Corp
1002 * This module is free software; you can redistribute it and/or modify
1003 * it under the terms of the GNU General Public License as published
1004 @@ -22,7 +23,8 @@
1005 /* TPM configuration */
1006 #define TPM_STORE_TO_FILE 1
1007 #undef TPM_STRONG_PERSISTENCE
1008 -#undef TPM_GENERATE_EK
1009 +//#undef TPM_GENERATE_EK
1010 +#define TPM_GENERATE_EK
1011 #undef TPM_GENERATE_SEED_DAA
1013 #define TPM_MANUFACTURER 0x4554485A /* 'ETHZ' */
1014 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_marshalling.c tpm_emulator/tpm/tpm_marshalling.c
1015 --- orig/tpm_emulator-0.4/tpm/tpm_marshalling.c 2006-06-23 03:37:07.000000000 -0700
1016 +++ tpm_emulator/tpm/tpm_marshalling.c 2006-07-24 14:35:35.000000000 -0700
1017 @@ -1312,7 +1312,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
1019 int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
1021 - UINT32 m_len, e_len, q_len;
1022 + size_t m_len, e_len, q_len;
1023 if (*length < sizeof_RSA((*v))) return -1;
1024 if (v->size > 0) {
1025 rsa_export_modulus(v, &(*ptr)[6], &m_len);
1026 @@ -1460,6 +1460,66 @@ int tpm_unmarshal_TPM_PERMANENT_DATA(BYT
1027 return 0;
1030 +int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v)
1031 +{
1032 + if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag)
1033 + || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceKey)
1034 + || tpm_marshal_TPM_COUNT_ID(ptr, length, v->countID) ) return -1;
1036 + return 0;
1037 +}
1039 +int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v)
1040 +{
1041 + if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag)
1042 + || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceKey)
1043 + || tpm_unmarshal_TPM_COUNT_ID(ptr, length, &v->countID) ) return -1;
1045 + return 0;
1046 +}
1048 +int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v)
1049 +{
1050 + UINT32 i;
1051 + if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag)
1052 + || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceSession)
1053 + || tpm_marshal_TPM_DIGEST(ptr, length, &v->auditDigest)
1054 + || tpm_marshal_BOOL(ptr, length, v->auditSession)
1055 + || tpm_marshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks)
1056 + || tpm_marshal_UINT32(ptr, length, v->contextCount)
1057 + || tpm_marshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1;
1058 + for (i = 0; i < TPM_MAX_SESSIONS; i++) {
1059 + if (tpm_marshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1;
1060 + }
1061 + for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) {
1062 + if (tpm_marshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1;
1063 + }
1064 + if (tpm_marshal_TPM_TRANSHANDLE(ptr, length, v->transExclusive)) return -1;
1066 + return 0;
1067 +}
1069 +int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v)
1070 +{
1071 + UINT32 i;
1072 + if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag)
1073 + || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceSession)
1074 + || tpm_unmarshal_TPM_DIGEST(ptr, length, &v->auditDigest)
1075 + || tpm_unmarshal_BOOL(ptr, length, &v->auditSession)
1076 + || tpm_unmarshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks)
1077 + || tpm_unmarshal_UINT32(ptr, length, &v->contextCount)
1078 + || tpm_unmarshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1;
1079 + for (i = 0; i < TPM_MAX_SESSIONS; i++) {
1080 + if (tpm_unmarshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1;
1081 + }
1082 + for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) {
1083 + if (tpm_unmarshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1;
1084 + }
1085 + if (tpm_unmarshal_TPM_TRANSHANDLE(ptr, length, &v->transExclusive)) return -1;
1087 + return 0;
1088 +}
1090 int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v)
1092 if (tpm_marshal_BYTE(ptr, length, v->type)
1093 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_marshalling.h tpm_emulator/tpm/tpm_marshalling.h
1094 --- orig/tpm_emulator-0.4/tpm/tpm_marshalling.h 2006-06-23 03:37:07.000000000 -0700
1095 +++ tpm_emulator/tpm/tpm_marshalling.h 2006-07-24 14:35:35.000000000 -0700
1096 @@ -432,6 +432,12 @@ int tpm_unmarshal_TPM_KEY_DATA(BYTE **pt
1097 int tpm_marshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *);
1098 int tpm_unmarshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *);
1100 +int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v);
1101 +int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v);
1103 +int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v);
1104 +int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v);
1106 int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v);
1107 int tpm_unmarshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v);
1109 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_owner.c tpm_emulator/tpm/tpm_owner.c
1110 --- orig/tpm_emulator-0.4/tpm/tpm_owner.c 2006-06-23 03:37:07.000000000 -0700
1111 +++ tpm_emulator/tpm/tpm_owner.c 2006-07-24 14:35:35.000000000 -0700
1112 @@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
1113 TPM_RESULT res;
1114 rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
1115 TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
1116 - UINT32 buf_size = ek->size >> 3;
1117 + size_t buf_size = ek->size >> 3, key_length;
1118 BYTE buf[buf_size];
1120 info("TPM_TakeOwnership()");
1121 @@ -173,7 +173,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
1122 return TPM_FAIL;
1124 rsa_export_modulus(&srk->key, srkPub->pubKey.key,
1125 - &srkPub->pubKey.keyLength);
1126 + &key_length);
1127 + srkPub->pubKey.keyLength = (UINT32) key_length;
1128 /* setup tpmProof and set state to owned */
1129 tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce,
1130 sizeof(tpmData.permanent.data.tpmProof.nonce));
1131 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_startup.c tpm_emulator/tpm/tpm_startup.c
1132 --- orig/tpm_emulator-0.4/tpm/tpm_startup.c 2006-06-23 03:37:07.000000000 -0700
1133 +++ tpm_emulator/tpm/tpm_startup.c 2006-07-24 14:35:35.000000000 -0700
1134 @@ -41,26 +41,29 @@ void TPM_Init(TPM_STARTUP_TYPE startupTy
1135 TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE startupType)
1137 int i;
1138 + int restore_fail;
1139 info("TPM_Startup(%d)", startupType);
1140 if (tpmData.stany.flags.postInitialise == FALSE) return TPM_INVALID_POSTINIT;
1141 - /* reset STANY_FLAGS */
1142 - SET_TO_ZERO(&tpmData.stany.flags);
1143 - tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS;
1144 - /* reset STANY_DATA (invalidates ALL sessions) */
1145 - SET_TO_ZERO(&tpmData.stany.data);
1146 - tpmData.stany.data.tag = TPM_TAG_STANY_DATA;
1147 - /* init session-context nonce */
1148 - SET_TO_RAND(&tpmData.stany.data.contextNonceSession);
1150 + /* try and restore state to get EK, SRK, etc */
1151 + restore_fail = tpm_restore_permanent_data();
1153 /* set data and flags according to the given startup type */
1154 if (startupType == TPM_ST_CLEAR) {
1155 - /* if available, restore permanent data */
1156 - tpm_restore_permanent_data();
1157 + /* reset STANY_FLAGS */
1158 + SET_TO_ZERO(&tpmData.stany.flags);
1159 + tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS;
1160 + /* reset STANY_DATA (invalidates ALL sessions) */
1161 + SET_TO_ZERO(&tpmData.stany.data);
1162 + tpmData.stany.data.tag = TPM_TAG_STANY_DATA;
1163 + /* init session-context nonce */
1164 + SET_TO_RAND(&tpmData.stany.data.contextNonceSession);
1165 /* reset PCR values */
1166 for (i = 0; i < TPM_NUM_PCR; i++) {
1167 - if (tpmData.permanent.data.pcrAttrib[i].pcrReset)
1168 - SET_TO_ZERO(tpmData.permanent.data.pcrValue[i].digest);
1169 + if (!tpmData.permanent.data.pcrAttrib[i].pcrReset)
1170 + SET_TO_ZERO(&tpmData.permanent.data.pcrValue[i].digest);
1171 else
1172 - SET_TO_0xFF(tpmData.permanent.data.pcrValue[i].digest);
1173 + SET_TO_0xFF(&tpmData.permanent.data.pcrValue[i].digest);
1175 /* reset STCLEAR_FLAGS */
1176 SET_TO_ZERO(&tpmData.stclear.flags);
1177 @@ -79,7 +82,8 @@ TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE
1178 /* init key-context nonce */
1179 SET_TO_RAND(&tpmData.stclear.data.contextNonceKey);
1180 } else if (startupType == TPM_ST_STATE) {
1181 - if (tpm_restore_permanent_data()) {
1182 + /* restore must have been successful for TPM_ST_STATE */
1183 + if (restore_fail) {
1184 error("restoring permanent data failed");
1185 tpmData.permanent.data.testResult = "tpm_restore_permanent_data() failed";
1186 tpmData.permanent.flags.selfTestSucceeded = FALSE;
1187 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_storage.c tpm_emulator/tpm/tpm_storage.c
1188 --- orig/tpm_emulator-0.4/tpm/tpm_storage.c 2006-06-23 03:37:07.000000000 -0700
1189 +++ tpm_emulator/tpm/tpm_storage.c 2006-07-24 14:35:35.000000000 -0700
1190 @@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
1191 BYTE *enc, UINT32 *enc_size)
1193 UINT32 len;
1194 + size_t enc_size32 = *enc_size;
1195 BYTE *buf, *ptr;
1196 rsa_public_key_t pub_key;
1197 int scheme;
1198 @@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
1199 if (buf == NULL
1200 || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal)
1201 || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)),
1202 - enc, enc_size)) {
1203 + enc, &enc_size32)) {
1204 tpm_free(buf);
1205 rsa_release_public_key(&pub_key);
1206 return -1;
1207 @@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
1208 int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
1209 TPM_SEALED_DATA *seal, BYTE **buf)
1211 - UINT32 len;
1212 + size_t len;
1213 + UINT32 len32;
1214 BYTE *ptr;
1215 int scheme;
1216 switch (key->encScheme) {
1217 @@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke
1218 len = enc_size;
1219 *buf = ptr = tpm_malloc(len);
1220 if (*buf == NULL
1221 - || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
1222 - || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) {
1223 + || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){
1224 + tpm_free(*buf);
1225 + return -1;
1226 + }
1227 + len32 = len;
1228 + if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) {
1229 tpm_free(*buf);
1230 return -1;
1232 @@ -240,11 +246,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par
1234 TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize,
1235 BYTE *inData, TPM_AUTH *auth1,
1236 - UINT32 *outDataSize, BYTE **outData)
1237 + UINT32 *outDataSize32, BYTE **outData)
1239 TPM_RESULT res;
1240 TPM_KEY_DATA *key;
1241 int scheme;
1242 + size_t outDataSize;
1244 info("TPM_UnBind()");
1245 /* get key */
1246 @@ -262,8 +269,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
1247 /* the size of the input data muss be greater than zero */
1248 if (inDataSize == 0) return TPM_BAD_PARAMETER;
1249 /* decrypt data */
1250 - *outDataSize = inDataSize;
1251 - *outData = tpm_malloc(*outDataSize);
1252 + outDataSize = inDataSize;
1253 + *outData = tpm_malloc(outDataSize);
1254 if (*outData == NULL) return TPM_NOSPACE;
1255 switch (key->encScheme) {
1256 case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
1257 @@ -271,20 +278,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
1258 default: tpm_free(*outData); return TPM_DECRYPT_ERROR;
1260 if (rsa_decrypt(&key->key, scheme, inData, inDataSize,
1261 - *outData, outDataSize)) {
1262 + *outData, &outDataSize)) {
1263 tpm_free(*outData);
1264 return TPM_DECRYPT_ERROR;
1266 /* verify data if it is of type TPM_BOUND_DATA */
1267 if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1
1268 || key->keyUsage != TPM_KEY_LEGACY) {
1269 - if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
1270 + if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
1271 tpm_free(*outData);
1272 return TPM_DECRYPT_ERROR;
1274 - *outDataSize -= 5;
1275 - memmove(*outData, &(*outData)[5], *outDataSize);
1276 + outDataSize -= 5;
1277 + memmove(*outData, &(*outData)[5], outDataSize);
1279 + *outDataSize32 = (UINT32) outDataSize;
1280 return TPM_SUCCESS;
1283 @@ -334,12 +342,13 @@ int compute_pubkey_digest(TPM_PUBKEY *ke
1286 int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store,
1287 - BYTE *enc, UINT32 *enc_size)
1288 + BYTE *enc, UINT32 *enc_size32)
1290 UINT32 len;
1291 BYTE *buf, *ptr;
1292 rsa_public_key_t pub_key;
1293 int scheme;
1294 + size_t enc_size;
1295 switch (key->encScheme) {
1296 case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
1297 case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break;
1298 @@ -351,11 +360,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke
1299 if (buf == NULL
1300 || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store)
1301 || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)),
1302 - enc, enc_size)) {
1303 + enc, &enc_size)) {
1304 tpm_free(buf);
1305 rsa_release_public_key(&pub_key);
1306 return -1;
1308 + *enc_size32 = (UINT32) enc_size;
1309 tpm_free(buf);
1310 rsa_release_public_key(&pub_key);
1311 return 0;
1312 @@ -364,7 +374,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke
1313 int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
1314 TPM_STORE_ASYMKEY *store, BYTE **buf)
1316 - UINT32 len;
1317 + UINT32 len32;
1318 + size_t len;
1319 BYTE *ptr;
1320 int scheme;
1321 switch (key->encScheme) {
1322 @@ -375,8 +386,12 @@ int decrypt_private_key(TPM_KEY_DATA *ke
1323 len = enc_size;
1324 *buf = ptr = tpm_malloc(len);
1325 if (*buf == NULL
1326 - || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
1327 - || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) {
1328 + || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) {
1329 + tpm_free(*buf);
1330 + return -1;
1331 + }
1332 + len32 = (UINT32) len;
1333 + if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) {
1334 tpm_free(*buf);
1335 return -1;
1337 @@ -394,7 +409,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
1338 TPM_SESSION_DATA *session;
1339 TPM_STORE_ASYMKEY store;
1340 rsa_private_key_t rsa;
1341 - UINT32 key_length;
1342 + size_t key_length;
1344 info("TPM_CreateWrapKey()");
1345 /* get parent key */
1346 @@ -450,11 +465,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
1349 /* generate key and store it */
1350 - key_length = keyInfo->algorithmParms.parms.rsa.keyLength;
1351 - if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL;
1352 - wrappedKey->pubKey.keyLength = key_length >> 3;
1353 + if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength))
1354 + return TPM_FAIL;
1355 + wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3;
1356 wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength);
1357 - store.privKey.keyLength = key_length >> 4;
1358 + store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4;
1359 store.privKey.key = tpm_malloc(store.privKey.keyLength);
1360 wrappedKey->encDataSize = parent->key.size >> 3;
1361 wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize);
1362 @@ -466,9 +481,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
1363 tpm_free(wrappedKey->encData);
1364 return TPM_NOSPACE;
1366 - rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
1367 - &wrappedKey->pubKey.keyLength);
1368 - rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength);
1369 + rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
1370 + &key_length);
1371 + wrappedKey->pubKey.keyLength = (UINT32) key_length;
1372 + rsa_export_prime1(&rsa, store.privKey.key, &key_length);
1373 + store.privKey.keyLength = (UINT32) key_length;
1374 rsa_release_private_key(&rsa);
1375 /* compute the digest of the wrapped key (without encData) */
1376 if (compute_key_digest(wrappedKey, &store.pubDataDigest)) {
1377 @@ -602,6 +619,7 @@ TPM_RESULT TPM_LoadKey2(TPM_KEY_HANDLE p
1379 int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms)
1381 + size_t key_length;
1382 parms->algorithmID = TPM_ALG_RSA;
1383 parms->encScheme = key->encScheme;
1384 parms->sigScheme = key->sigScheme;
1385 @@ -611,7 +629,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke
1386 parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize);
1387 if (parms->parms.rsa.exponent == NULL) return -1;
1388 rsa_export_exponent(&key->key, parms->parms.rsa.exponent,
1389 - &parms->parms.rsa.exponentSize);
1390 + &key_length);
1391 + parms->parms.rsa.exponentSize = (UINT32) key_length;
1392 parms->parmSize = 12 + parms->parms.rsa.exponentSize;
1393 return 0;
1395 @@ -622,6 +641,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE
1396 TPM_RESULT res;
1397 TPM_KEY_DATA *key;
1398 TPM_DIGEST digest;
1399 + size_t key_length;
1400 info("TPM_GetPubKey()");
1401 /* get key */
1402 if (keyHandle == TPM_KH_SRK
1403 @@ -650,8 +670,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE
1404 pubKey->pubKey.keyLength = key->key.size >> 3;
1405 pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength);
1406 if (pubKey->pubKey.key == NULL) return TPM_NOSPACE;
1407 - rsa_export_modulus(&key->key, pubKey->pubKey.key,
1408 - &pubKey->pubKey.keyLength);
1409 + rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length);
1410 + pubKey->pubKey.keyLength = (UINT32) key_length;
1411 if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
1412 error("TPM_GetPubKey(): tpm_setup_key_parms() failed.");
1413 tpm_free(pubKey->pubKey.key);
1414 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_structures.h tpm_emulator/tpm/tpm_structures.h
1415 --- orig/tpm_emulator-0.4/tpm/tpm_structures.h 2006-06-23 03:37:07.000000000 -0700
1416 +++ tpm_emulator/tpm/tpm_structures.h 2006-07-24 14:35:35.000000000 -0700
1417 @@ -1958,6 +1958,7 @@ typedef struct tdTPM_DAA_ISSUER {
1418 TPM_DIGEST DAA_digest_gamma;
1419 BYTE DAA_generic_q[26];
1420 } TPM_DAA_ISSUER;
1421 +#define sizeof_TPM_DAA_ISSUER(s) (2 + (20 * 6) + 26 )
1423 /*
1424 * TPM_DAA_TPM ([TPM_Part2], Section 22.4)
1425 @@ -1973,6 +1974,7 @@ typedef struct tdTPM_DAA_TPM {
1426 TPM_DIGEST DAA_rekey;
1427 UINT32 DAA_count;
1428 } TPM_DAA_TPM;
1429 +#define sizeof_TPM_DAA_TPM(s) (2 + (4 * 20) + 4)
1431 /*
1432 * TPM_DAA_CONTEXT ([TPM_Part2], Section 22.5)
1433 @@ -1987,6 +1989,7 @@ typedef struct tdTPM_DAA_CONTEXT {
1434 BYTE DAA_scratch[256];
1435 BYTE DAA_stage;
1436 } TPM_DAA_CONTEXT;
1437 +#define sizeof_TPM_DAA_CONTEXT(s) (2 + (3 * 20) + 256 + 1)
1439 /*
1440 * TPM_DAA_JOINDATA ([TPM_Part2], Section 22.6)
1441 @@ -1998,6 +2001,7 @@ typedef struct tdTPM_DAA_JOINDATA {
1442 BYTE DAA_join_u1[138];
1443 TPM_DIGEST DAA_digest_n0;
1444 } TPM_DAA_JOINDATA;
1445 +#define sizeof_TPM_DAA_JOINDATA(s) (1 + 1 + 20)
1447 /*
1448 * TPM_DAA_BLOB ([TPM_Part2], Section 22.8)
1449 @@ -2202,6 +2206,7 @@ typedef struct tdTPM_STCLEAR_DATA {
1450 //UINT32 ownerReference;
1451 //BOOL disableResetLock;
1452 } TPM_STCLEAR_DATA;
1453 +#define sizeof_TPM_STCLEAR_DATA(s) (2 + 20 + 4)
1455 /*
1456 * TPM_SESSION_DATA
1457 @@ -2238,6 +2243,11 @@ typedef struct tdTPM_DAA_SESSION_DATA {
1458 TPM_DAA_JOINDATA DAA_joinSession;
1459 TPM_HANDLE handle;
1460 } TPM_DAA_SESSION_DATA;
1461 +#define sizeof_TPM_DAA_SESSION_DATA(s) ( 1 \
1462 + + sizeof_TPM_DAA_ISSUER(s.DAA_issuerSettings) \
1463 + + sizeof_TPM_DAA_TPM(s.DAA_tpmSpecific) \
1464 + + sizeof_TPM_DAA_CONTEXT(s.DAA_session) \
1465 + + sizeof_TPM_DAA_JOINDATA(s.DAA_joinSession) + 4)
1467 /*
1468 * TPM_STANY_DATA ([TPM_Part2], Section 7.6)
1469 @@ -2262,6 +2272,11 @@ typedef struct tdTPM_STANY_DATA {
1470 TPM_DAAHANDLE currentDAA;
1471 TPM_TRANSHANDLE transExclusive;
1472 } TPM_STANY_DATA;
1473 +#define sizeof_TPM_STANY_DATA(s) (2 + 20 + 20 + 1 \
1474 + + sizeof_TPM_CURRENT_TICKS(s.currentTicks) \
1475 + + 4 + (4 * TPM_MAX_SESSION_LIST) \
1476 + + (sizeof_TPM_SESSION_DATA(s.sessions[0]) * TPM_MAX_SESSION_LIST) \
1477 + + (sizeof_TPM_DAA_SESSION_DATA(s.sessionsDAA[0]) * TPM_MAX_SESSIONS_DAA) + 4)
1479 /*
1480 * TPM_DATA
1481 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_testing.c tpm_emulator/tpm/tpm_testing.c
1482 --- orig/tpm_emulator-0.4/tpm/tpm_testing.c 2006-06-23 03:37:07.000000000 -0700
1483 +++ tpm_emulator/tpm/tpm_testing.c 2006-07-24 14:35:35.000000000 -0700
1484 @@ -1,6 +1,7 @@
1485 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1486 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1487 * Swiss Federal Institute of Technology (ETH) Zurich
1488 + * Copyright (C) 2005 INTEL Corp
1490 * This module is free software; you can redistribute it and/or modify
1491 * it under the terms of the GNU General Public License as published
1492 @@ -95,24 +96,24 @@ static int tpm_test_sha1(void)
1493 struct {
1494 uint8_t *data; uint32_t repetitions; uint8_t *digest;
1495 } test_cases[] = {{
1496 - "abc", 1,
1497 - "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D"
1498 + (uint8_t*)"abc", 1,
1499 + (uint8_t*)"\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D"
1500 }, {
1501 - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
1502 - "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1"
1503 + (uint8_t*)"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
1504 + (uint8_t*)"\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1"
1505 }, {
1506 - "a", 1000000,
1507 - "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F"
1508 + (uint8_t*)"a", 1000000,
1509 + (uint8_t*)"\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F"
1510 }, {
1511 - "0123456701234567012345670123456701234567012345670123456701234567", 10,
1512 - "\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52"
1513 + (uint8_t*)"0123456701234567012345670123456701234567012345670123456701234567", 10,
1514 + (uint8_t*)"\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52"
1515 }};
1517 debug("tpm_test_sha1()");
1518 for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
1519 sha1_init(&ctx);
1520 for (j = 0; j < test_cases[i].repetitions; j++)
1521 - sha1_update(&ctx, test_cases[i].data, strlen(test_cases[i].data));
1522 + sha1_update(&ctx, test_cases[i].data, strlen((char*)test_cases[i].data));
1523 sha1_final(&ctx, digest);
1524 if (memcmp(digest, test_cases[i].digest, SHA1_DIGEST_LENGTH) != 0) return -1;
1526 @@ -128,41 +129,41 @@ static int tpm_test_hmac(void)
1527 struct {
1528 uint8_t *key, key_len, *data, data_len, *digest;
1529 } test_cases[] = {{
1530 - "\x0b", 20, "Hi There", 8,
1531 - "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00"
1532 + (uint8_t*)"\x0b", 20, (uint8_t*)"Hi There", 8,
1533 + (uint8_t*)"\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00"
1534 }, {
1535 - "Jefe", 4, "what do ya want for nothing?", 28,
1536 - "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79"
1537 + (uint8_t*)"Jefe", 4, (uint8_t*)"what do ya want for nothing?", 28,
1538 + (uint8_t*)"\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79"
1539 }, {
1540 - "\xaa", 20, "\xdd", 50,
1541 - "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3"
1542 + (uint8_t*)"\xaa", 20, (uint8_t*)"\xdd", 50,
1543 + (uint8_t*)"\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3"
1544 }, {
1545 - "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1546 - "\x15\x16\x17\x18\x19", 25, "\xcd", 50,
1547 - "\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda"
1548 + (uint8_t*)"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1549 + "\x15\x16\x17\x18\x19", 25, (uint8_t*)"\xcd", 50,
1550 + (uint8_t*)"\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda"
1551 }, {
1552 - "\x0c", 20, "Test With Truncation", 20,
1553 - "\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04"
1554 + (uint8_t*)"\x0c", 20, (uint8_t*)"Test With Truncation", 20,
1555 + (uint8_t*)"\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04"
1556 }, {
1557 - "\xaa", 80, "Test Using Larger Than Block-Size Key - Hash Key First", 54,
1558 - "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12"
1559 + (uint8_t*)"\xaa", 80, (uint8_t*)"Test Using Larger Than Block-Size Key - Hash Key First", 54,
1560 + (uint8_t*)"\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12"
1561 }, {
1562 - "\xaa", 80,
1563 - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73,
1564 - "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91"
1565 + (uint8_t*)"\xaa", 80,
1566 + (uint8_t*)"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73,
1567 + (uint8_t*)"\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91"
1568 }};
1570 debug("tpm_test_hmac()");
1571 for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
1572 - if (strlen(test_cases[i].key) < test_cases[i].key_len) {
1573 + if (strlen((char*)test_cases[i].key) < test_cases[i].key_len) {
1574 uint8_t key[test_cases[i].key_len];
1575 memset(key, test_cases[i].key[0], test_cases[i].key_len);
1576 hmac_init(&ctx, key, test_cases[i].key_len);
1577 } else {
1578 hmac_init(&ctx, test_cases[i].key, test_cases[i].key_len);
1580 - for (j = 0; j < test_cases[i].data_len; j += strlen(test_cases[i].data)) {
1581 - hmac_update(&ctx, test_cases[i].data, strlen(test_cases[i].data));
1582 + for (j = 0; j < test_cases[i].data_len; j += strlen((char*)test_cases[i].data)) {
1583 + hmac_update(&ctx, test_cases[i].data, strlen((char*)test_cases[i].data));
1585 hmac_final(&ctx, digest);
1586 if (memcmp(digest, test_cases[i].digest, SHA1_DIGEST_LENGTH) != 0) return -1;
1587 @@ -173,9 +174,9 @@ static int tpm_test_hmac(void)
1588 static int tpm_test_rsa_EK(void)
1590 int res = 0;
1591 - char *data = "RSA PKCS #1 v1.5 Test-String";
1592 + uint8_t *data = (uint8_t*)"RSA PKCS #1 v1.5 Test-String";
1593 uint8_t buf[256];
1594 - size_t buf_len, data_len = strlen(data);
1595 + size_t buf_len, data_len = strlen((char*)data);
1596 rsa_private_key_t priv_key;
1597 rsa_public_key_t pub_key;
1599 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_ticks.c tpm_emulator/tpm/tpm_ticks.c
1600 --- orig/tpm_emulator-0.4/tpm/tpm_ticks.c 2006-06-23 03:37:07.000000000 -0700
1601 +++ tpm_emulator/tpm/tpm_ticks.c 2006-07-24 14:35:35.000000000 -0700
1602 @@ -1,6 +1,7 @@
1603 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1604 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1605 * Swiss Federal Institute of Technology (ETH) Zurich
1606 + * Copyright (C) 2005 INTEL Corp
1608 * This module is free software; you can redistribute it and/or modify
1609 * it under the terms of the GNU General Public License as published
1610 @@ -39,9 +40,7 @@ TPM_RESULT TPM_SetTickType(TPM_TICKTYPE
1611 TPM_RESULT TPM_GetTicks(TPM_CURRENT_TICKS *currentTime)
1613 info("TPM_GetTicks()");
1614 - memcpy(currentTime, &tpmData.stany.data.currentTicks,
1615 - sizeof(TPM_CURRENT_TICKS));
1616 - return TPM_SUCCESS;
1617 + return TPM_DISABLED_CMD;
1620 TPM_RESULT TPM_TickStampBlob(TPM_KEY_HANDLE keyHandle, TPM_NONCE *antiReplay,
1621 @@ -49,64 +48,11 @@ TPM_RESULT TPM_TickStampBlob(TPM_KEY_HAN
1622 TPM_CURRENT_TICKS *currentTicks,
1623 UINT32 *sigSize, BYTE **sig)
1625 - TPM_RESULT res;
1626 - TPM_KEY_DATA *key;
1627 - BYTE *info, *p;
1628 - UINT32 info_length, length;
1629 info("TPM_TickStampBlob()");
1630 - /* get key */
1631 - key = tpm_get_key(keyHandle);
1632 - if (key == NULL) return TPM_INVALID_KEYHANDLE;
1633 - /* verify authorization */
1634 - res = tpm_verify_auth(auth1, key->usageAuth, keyHandle);
1635 - if (res != TPM_SUCCESS) return res;
1636 - if (key->keyUsage != TPM_KEY_SIGNING && key->keyUsage != TPM_KEY_LEGACY
1637 - && key->keyUsage != TPM_KEY_IDENTITY) return TPM_INVALID_KEYUSAGE;
1638 - /* get current ticks */
1639 - TPM_GetTicks(currentTicks);
1640 - /* sign data using signature scheme PKCS1_SHA1 and TPM_SIGN_INFO container */
1641 - *sigSize = key->key.size >> 3;
1642 - *sig = tpm_malloc(*sigSize);
1643 - if (*sig == NULL) return TPM_FAIL;
1644 - /* setup TPM_SIGN_INFO structure */
1645 - info_length = 30 + sizeof(TPM_DIGEST) + sizeof_TPM_CURRENT_TICKS(currentTicks);
1646 - info = tpm_malloc(info_length);
1647 - if (info == NULL) {
1648 - tpm_free(*sig);
1649 - return TPM_FAIL;
1650 - }
1651 - memcpy(&info[0], "\x05\x00TSTP", 6);
1652 - memcpy(&info[6], antiReplay->nonce, 20);
1653 - *(UINT32*)&info[26] = CPU_TO_BE32(20
1654 - + sizeof_TPM_CURRENT_TICKS(currentTicks));
1655 - memcpy(&info[30], digestToStamp->digest, sizeof(TPM_DIGEST));
1656 - p = &info[30 + sizeof(TPM_DIGEST)];
1657 - length = sizeof_TPM_CURRENT_TICKS(currentTicks);
1658 - if (tpm_marshal_TPM_CURRENT_TICKS(&p, &length, currentTicks)
1659 - || rsa_sign(&key->key, RSA_SSA_PKCS1_SHA1, info, info_length, *sig)) {
1660 - tpm_free(*sig);
1661 - tpm_free(info);
1662 - return TPM_FAIL;
1663 - }
1664 - return TPM_SUCCESS;
1665 + return TPM_DISABLED_CMD;
1668 void tpm_update_ticks(void)
1670 - if (tpmData.stany.data.currentTicks.tag == 0) {
1671 - tpmData.stany.data.currentTicks.tag = TPM_TAG_CURRENT_TICKS;
1672 - tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks();
1673 -/* removed since v1.2 rev 94
1674 - tpmData.stany.data.currentTicks.tickType = tpmData.permanent.data.tickType;
1675 -*/
1676 - tpm_get_random_bytes(tpmData.stany.data.currentTicks.tickNonce.nonce,
1677 - sizeof(TPM_NONCE));
1678 - tpmData.stany.data.currentTicks.tickRate = 1;
1679 -/* removed since v1.2 rev 94
1680 - tpmData.stany.data.currentTicks.tickSecurity = TICK_SEC_NO_CHECK;
1681 -*/
1682 - } else {
1683 - tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks();
1684 - }
1687 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_transport.c tpm_emulator/tpm/tpm_transport.c
1688 --- orig/tpm_emulator-0.4/tpm/tpm_transport.c 2006-06-23 03:37:07.000000000 -0700
1689 +++ tpm_emulator/tpm/tpm_transport.c 2006-07-24 14:35:35.000000000 -0700
1690 @@ -189,7 +189,7 @@ static void decrypt_wrapped_command(BYTE
1691 sha1_init(&sha1);
1692 sha1_update(&sha1, auth->nonceEven.nonce, sizeof(auth->nonceEven.nonce));
1693 sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce));
1694 - sha1_update(&sha1, "in", 2);
1695 + sha1_update(&sha1, (BYTE*)"in", 2);
1696 sha1_update(&sha1, secret, sizeof(TPM_SECRET));
1697 j = CPU_TO_BE32(i);
1698 sha1_update(&sha1, (BYTE*)&j, 4);
1699 @@ -211,7 +211,7 @@ static void encrypt_wrapped_command(BYTE
1700 sha1_init(&sha1);
1701 sha1_update(&sha1, auth->nonceEven.nonce, sizeof(auth->nonceEven.nonce));
1702 sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce));
1703 - sha1_update(&sha1, "out", 3);
1704 + sha1_update(&sha1, (BYTE*)"out", 3);
1705 sha1_update(&sha1, secret, sizeof(TPM_SECRET));
1706 j = CPU_TO_BE32(i);
1707 sha1_update(&sha1, (BYTE*)&j, 4);
1708 diff -uprN orig/tpm_emulator-0.4/tpmd.c tpm_emulator/tpmd.c
1709 --- orig/tpm_emulator-0.4/tpmd.c 1969-12-31 16:00:00.000000000 -0800
1710 +++ tpm_emulator/tpmd.c 2006-07-24 14:35:35.000000000 -0700
1711 @@ -0,0 +1,156 @@
1712 +/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1713 + * Copyright (C) 2005 INTEL Corp
1714 + *
1715 + * This module is free software; you can redistribute it and/or modify
1716 + * it under the terms of the GNU General Public License as published
1717 + * by the Free Software Foundation; either version 2 of the License,
1718 + * or (at your option) any later version.
1719 + *
1720 + * This module is distributed in the hope that it will be useful,
1721 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1722 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1723 + * GNU General Public License for more details.
1724 + *
1725 + */
1727 +#include <stdio.h>
1728 +#include <stdlib.h>
1729 +#include <unistd.h>
1730 +#include <string.h>
1731 +#include <sys/types.h>
1732 +#include <sys/stat.h>
1733 +#include <fcntl.h>
1734 +#include <sys/time.h>
1736 +#include "tpm_emulator.h"
1738 +#define TPM_RX_FNAME "/var/tpm/tpm_in.fifo"
1739 +#define TPM_TX_FNAME "/var/tpm/tpm_out.fifo"
1741 +#define BUFFER_SIZE 2048
1743 +static int devurandom=0;
1745 +void get_random_bytes(void *buf, int nbytes) {
1747 + if (devurandom == 0) {
1748 + devurandom = open("/dev/urandom", O_RDONLY);
1749 + }
1751 + if (read(devurandom, buf, nbytes) != nbytes) {
1752 + printf("Can't get random number.\n");
1753 + exit(-1);
1754 + }
1755 +}
1757 +uint64_t tpm_get_ticks(void)
1758 +{
1759 + //struct timeval tv;
1760 + //int gettimeofday(&tv, struct timezone *tz);
1761 + return 0;
1762 +}
1764 +int main(int argc, char **argv)
1765 +{
1766 + uint8_t in[BUFFER_SIZE], *out;
1767 + uint32_t out_size;
1768 + int in_size, written;
1769 + int i;
1770 + struct stat file_info;
1772 + int tpm_tx_fh=-1, tpm_rx_fh=-1;
1773 + if (argc < 2) {
1774 + printf("Usage: tpmd clear|save|deactivated\n" );
1775 + return -1;
1776 + }
1778 + /* initialize TPM emulator */
1779 + if (!strcmp(argv[1], "clear")) {
1780 + printf("Initializing tpm: %s\n", argv[1]);
1781 + tpm_emulator_init(1);
1782 + } else if (!strcmp(argv[1], "save")) {
1783 + printf("Initializing tpm: %s\n", argv[1]);
1784 + tpm_emulator_init(2);
1785 + } else if (!strcmp(argv[1], "deactivated")) {
1786 + printf("Initializing tpm: %s\n", argv[1]);
1787 + tpm_emulator_init(3);
1788 + } else {
1789 + printf("invalid startup mode '%s'; must be 'clear', "
1790 + "'save' (default) or 'deactivated", argv[1]);
1791 + return -1;
1792 + }
1794 + if ( stat(TPM_RX_FNAME, &file_info) == -1) {
1795 + if ( mkfifo(TPM_RX_FNAME, S_IWUSR | S_IRUSR ) ) {
1796 + printf("Failed to create fifo %s.\n", TPM_RX_FNAME);
1797 + return -1;
1798 + }
1799 + }
1801 + if ( stat(TPM_TX_FNAME, &file_info) == -1) {
1802 + if ( mkfifo(TPM_TX_FNAME, S_IWUSR | S_IRUSR ) ) {
1803 + printf("Failed to create fifo %s.\n", TPM_TX_FNAME);
1804 + return -1;
1805 + }
1806 + }
1808 + while (1) {
1809 +abort_command:
1810 + if (tpm_rx_fh < 0) {
1811 + tpm_rx_fh = open(TPM_RX_FNAME, O_RDONLY);
1812 + }
1814 + if (tpm_rx_fh < 0) {
1815 + printf("ERROR: failed to open devices to listen to guest.\n");
1816 + return -1;
1817 + }
1819 + if (tpm_tx_fh < 0) {
1820 + tpm_tx_fh = open(TPM_TX_FNAME, O_WRONLY);
1821 + }
1823 + if (tpm_tx_fh < 0) {
1824 + printf("ERROR: failed to open devices to respond to guest.\n");
1825 + return -1;
1826 + }
1828 + in_size = read(tpm_rx_fh, in, BUFFER_SIZE);
1829 + if (in_size < 6) { // Magic size of minium TPM command
1830 + printf("Recv[%d] to small: 0x", in_size);
1831 + if (in_size <= 0) {
1832 + close(tpm_rx_fh);
1833 + tpm_rx_fh = -1;
1834 + goto abort_command;
1835 + }
1836 + } else {
1837 + printf("Recv[%d]: 0x", in_size);
1838 + for (i=0; i< in_size; i++)
1839 + printf("%x ", in[i]);
1840 + printf("\n");
1841 + }
1844 + if (tpm_handle_command(in, in_size, &out, &out_size) != 0) {
1845 + printf("ERROR: Handler Failed.\n");
1846 + }
1848 + written = write(tpm_tx_fh, out, out_size);
1850 + if (written != out_size ) {
1851 + printf("ERROR: Part of response not written %d/%d.\nAttempt: ", written, out_size);
1852 + } else {
1853 + printf("Sent[%Zu]: ", out_size);
1854 + }
1855 + for (i=0; i< out_size; i++)
1856 + printf("%x ", out[i]);
1857 + printf("\n");
1858 + tpm_free(out);
1860 + } // loop
1862 + tpm_emulator_shutdown();
1864 + close(tpm_tx_fh);
1865 + close(tpm_rx_fh);
1867 +}
1868 Binary files orig/tpm_emulator-0.4/tpm_emulator and tpm_emulator/tpm_emulator differ
1869 diff -uprN orig/tpm_emulator-0.4/tpm_version.h tpm_emulator/tpm_version.h
1870 --- orig/tpm_emulator-0.4/tpm_version.h 2006-06-23 03:37:07.000000000 -0700
1871 +++ tpm_emulator/tpm_version.h 2006-07-24 14:35:41.000000000 -0700
1872 @@ -2,5 +2,5 @@
1873 #define _TPM_VERSION_H_
1874 #define VERSION_MAJOR 0
1875 #define VERSION_MINOR 4
1876 -#define VERSION_BUILD 1151058734
1877 +#define VERSION_BUILD 1153776940
1878 #endif /* _TPM_VERSION_H_ */