ia64/xen-unstable

view tools/vtpm/tpm_emulator.patch @ 19731:01748ccc4da3

Intel VT-d: fix Stoakley boot issue with iommu=1

Signed-off-by: Weidong Han <Weidong.han@intel.com>
Signed-off-by: Allen Kay <allen.m.kay@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 05 09:25:50 2009 +0100 (2009-06-05)
parents 688e9186eed4
children
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_capability.c tpm_emulator/tpm/tpm_capability.c
551 --- orig/tpm_emulator-0.4/tpm/tpm_capability.c 2006-06-23 19:37:07.000000000 +0900
552 +++ tpm_emulator/tpm/tpm_capability.c 2007-12-28 22:50:19.000000000 +0900
553 @@ -701,7 +701,10 @@ TPM_RESULT TPM_GetCapabilityOwner(TPM_VE
554 TPM_RESULT res;
556 info("TPM_GetCapabilityOwner()");
557 -
558 +
559 + if (!tpmData.permanent.flags.owned) {
560 + return TPM_NOSRK;
561 + }
562 /* Verify owner authorization */
563 res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
564 if (res != TPM_SUCCESS) return res;
565 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_cmd_handler.c tpm_emulator/tpm/tpm_cmd_handler.c
566 --- orig/tpm_emulator-0.4/tpm/tpm_cmd_handler.c 2006-06-23 19:37:07.000000000 +0900
567 +++ tpm_emulator/tpm/tpm_cmd_handler.c 2007-09-12 20:23:00.000000000 +0900
568 @@ -565,7 +565,7 @@ static TPM_RESULT execute_TPM_Seal(TPM_R
569 if (tpm_unmarshal_TPM_KEY_HANDLE(&ptr, &len, &keyHandle)
570 || tpm_unmarshal_TPM_ENCAUTH(&ptr, &len, &encAuth)
571 || tpm_unmarshal_UINT32(&ptr, &len, &pcrInfoSize)
572 - || tpm_unmarshal_TPM_PCR_INFO(&ptr, &len, &pcrInfo)
573 + || (pcrInfoSize >0 && tpm_unmarshal_TPM_PCR_INFO(&ptr, &len, &pcrInfo))
574 || tpm_unmarshal_UINT32(&ptr, &len, &inDataSize)
575 || tpm_unmarshal_BLOB(&ptr, &len, &inData, inDataSize)
576 || len != 0) return TPM_BAD_PARAMETER;
577 @@ -798,7 +798,7 @@ static TPM_RESULT execute_TPM_Sealx(TPM_
578 if (tpm_unmarshal_TPM_KEY_HANDLE(&ptr, &len, &keyHandle)
579 || tpm_unmarshal_TPM_ENCAUTH(&ptr, &len, &encAuth)
580 || tpm_unmarshal_UINT32(&ptr, &len, &pcrInfoSize)
581 - || tpm_unmarshal_TPM_PCR_INFO(&ptr, &len, &pcrInfo)
582 + || (pcrInfoSize > 0 && tpm_unmarshal_TPM_PCR_INFO(&ptr, &len, &pcrInfo))
583 || tpm_unmarshal_UINT32(&ptr, &len, &inDataSize)
584 || tpm_unmarshal_BLOB(&ptr, &len, &inData, inDataSize)
585 || len != 0) return TPM_BAD_PARAMETER;
586 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_credentials.c tpm_emulator/tpm/tpm_credentials.c
587 --- orig/tpm_emulator-0.4/tpm/tpm_credentials.c 2006-06-23 19:37:07.000000000 +0900
588 +++ tpm_emulator/tpm/tpm_credentials.c 2007-09-12 20:23:30.000000000 +0900
589 @@ -47,20 +47,20 @@ int tpm_compute_pubkey_checksum(TPM_NONC
591 TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey)
592 {
593 - UINT32 key_length;
594 + size_t key_length;
595 if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT;
596 /* setup TPM_PUBKEY structure */
597 - key_length = tpmData.permanent.data.endorsementKey.size;
598 - pubEndorsementKey->pubKey.keyLength = key_length >> 3;
599 + pubEndorsementKey->pubKey.keyLength = tpmData.permanent.data.endorsementKey.size >> 3;
600 pubEndorsementKey->pubKey.key = tpm_malloc(pubEndorsementKey->pubKey.keyLength);
601 if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL;
602 rsa_export_modulus(&tpmData.permanent.data.endorsementKey,
603 - pubEndorsementKey->pubKey.key,
604 - &pubEndorsementKey->pubKey.keyLength);
605 + pubEndorsementKey->pubKey.key,
606 + &key_length);
607 + pubEndorsementKey->pubKey.keyLength = key_length;
608 pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA;
609 pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
610 pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE;
611 - pubEndorsementKey->algorithmParms.parms.rsa.keyLength = key_length;
612 + pubEndorsementKey->algorithmParms.parms.rsa.keyLength = key_length << 3;
613 pubEndorsementKey->algorithmParms.parms.rsa.numPrimes = 2;
614 pubEndorsementKey->algorithmParms.parms.rsa.exponentSize = 0;
615 pubEndorsementKey->algorithmParms.parms.rsa.exponent = NULL;
616 @@ -175,6 +175,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
617 {
618 TPM_RESULT res;
619 TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
620 + size_t key_length;
621 info("TPM_OwnerReadInternalPub()");
622 /* verify authorization */
623 res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
624 @@ -186,7 +187,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
625 publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength);
626 if (publicPortion->pubKey.key == NULL) return TPM_FAIL;
627 rsa_export_modulus(&srk->key, publicPortion->pubKey.key,
628 - &publicPortion->pubKey.keyLength);
629 + &key_length);
630 + publicPortion->pubKey.keyLength = key_length;
631 publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA;
632 publicPortion->algorithmParms.encScheme = srk->encScheme;
633 publicPortion->algorithmParms.sigScheme = srk->sigScheme;
634 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_crypto.c tpm_emulator/tpm/tpm_crypto.c
635 --- orig/tpm_emulator-0.4/tpm/tpm_crypto.c 2006-06-23 03:37:07.000000000 -0700
636 +++ tpm_emulator/tpm/tpm_crypto.c 2006-07-24 14:35:35.000000000 -0700
637 @@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
638 TPM_KEY_DATA *cert, *key;
639 sha1_ctx_t sha1_ctx;
640 BYTE *buf, *p;
641 - UINT32 length;
642 + UINT32 length32;
643 + size_t length;
644 info("TPM_CertifyKey()");
645 /* get keys */
646 cert = tpm_get_key(certHandle);
647 @@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
648 /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
649 length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
650 p = buf = tpm_malloc(length);
651 + length32=(UINT32) length;
652 if (buf == NULL
653 - || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
654 + || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
655 free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
656 return TPM_FAIL;
657 }
658 length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
659 sha1_init(&sha1_ctx);
660 - sha1_update(&sha1_ctx, buf, length);
661 + sha1_update(&sha1_ctx, buf, (size_t) length);
662 sha1_final(&sha1_ctx, buf);
663 res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSize);
664 tpm_free(buf);
665 @@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
666 TPM_KEY_DATA *cert, *key;
667 sha1_ctx_t sha1_ctx;
668 BYTE *buf, *p;
669 - UINT32 length;
670 + size_t length;
671 + UINT32 length32;
672 info("TPM_CertifyKey2()");
673 /* get keys */
674 cert = tpm_get_key(certHandle);
675 @@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
676 /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
677 length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
678 p = buf = tpm_malloc(length);
679 + length32 = (UINT32) length;
680 if (buf == NULL
681 - || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
682 + || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
683 free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
684 return TPM_FAIL;
685 }
686 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_daa.c tpm_emulator/tpm/tpm_daa.c
687 --- orig/tpm_emulator-0.4/tpm/tpm_daa.c 2006-06-23 03:37:07.000000000 -0700
688 +++ tpm_emulator/tpm/tpm_daa.c 2006-07-24 14:35:35.000000000 -0700
689 @@ -716,14 +716,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl
690 sizeof(session->DAA_tpmSpecific.DAA_rekey));
691 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
692 sizeof(session->DAA_tpmSpecific.DAA_count));
693 - sha1_update(&sha1, "\x00", 1);
694 + sha1_update(&sha1, (BYTE *) "\x00", 1);
695 sha1_final(&sha1, scratch);
696 sha1_init(&sha1);
697 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
698 sizeof(session->DAA_tpmSpecific.DAA_rekey));
699 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
700 sizeof(session->DAA_tpmSpecific.DAA_count));
701 - sha1_update(&sha1, "\x01", 1);
702 + sha1_update(&sha1, (BYTE *) "\x01", 1);
703 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
704 mpz_init(f), mpz_init(q);
705 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
706 @@ -805,14 +805,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl
707 sizeof(session->DAA_tpmSpecific.DAA_rekey));
708 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
709 sizeof(session->DAA_tpmSpecific.DAA_count));
710 - sha1_update(&sha1, "\x00", 1);
711 + sha1_update(&sha1, (BYTE *) "\x00", 1);
712 sha1_final(&sha1, scratch);
713 sha1_init(&sha1);
714 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
715 sizeof(session->DAA_tpmSpecific.DAA_rekey));
716 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
717 sizeof(session->DAA_tpmSpecific.DAA_count));
718 - sha1_update(&sha1, "\x01", 1);
719 + sha1_update(&sha1, (BYTE *) "\x01", 1);
720 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
721 mpz_init(f), mpz_init(q);
722 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
723 @@ -1489,14 +1489,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl
724 sizeof(session->DAA_tpmSpecific.DAA_rekey));
725 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
726 sizeof(session->DAA_tpmSpecific.DAA_count));
727 - sha1_update(&sha1, "\x00", 1);
728 + sha1_update(&sha1, (BYTE *) "\x00", 1);
729 sha1_final(&sha1, scratch);
730 sha1_init(&sha1);
731 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
732 sizeof(session->DAA_tpmSpecific.DAA_rekey));
733 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
734 sizeof(session->DAA_tpmSpecific.DAA_count));
735 - sha1_update(&sha1, "\x01", 1);
736 + sha1_update(&sha1, (BYTE *) "\x01", 1);
737 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
738 mpz_init(f), mpz_init(q);
739 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
740 @@ -1712,14 +1712,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl
741 sizeof(session->DAA_tpmSpecific.DAA_rekey));
742 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
743 sizeof(session->DAA_tpmSpecific.DAA_count));
744 - sha1_update(&sha1, "\x00", 1);
745 + sha1_update(&sha1, (BYTE *) "\x00", 1);
746 sha1_final(&sha1, scratch);
747 sha1_init(&sha1);
748 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
749 sizeof(session->DAA_tpmSpecific.DAA_rekey));
750 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
751 sizeof(session->DAA_tpmSpecific.DAA_count));
752 - sha1_update(&sha1, "\x01", 1);
753 + sha1_update(&sha1, (BYTE *) "\x01", 1);
754 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
755 mpz_init(f), mpz_init(q);
756 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
757 @@ -1793,14 +1793,14 @@ TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl
758 sizeof(session->DAA_tpmSpecific.DAA_rekey));
759 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
760 sizeof(session->DAA_tpmSpecific.DAA_count));
761 - sha1_update(&sha1, "\x00", 1);
762 + sha1_update(&sha1, (BYTE *) "\x00", 1);
763 sha1_final(&sha1, scratch);
764 sha1_init(&sha1);
765 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
766 sizeof(session->DAA_tpmSpecific.DAA_rekey));
767 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
768 sizeof(session->DAA_tpmSpecific.DAA_count));
769 - sha1_update(&sha1, "\x01", 1);
770 + sha1_update(&sha1, (BYTE *) "\x01", 1);
771 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
772 mpz_init(f), mpz_init(q);
773 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
774 @@ -2918,14 +2918,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
775 sizeof(session->DAA_tpmSpecific.DAA_rekey));
776 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
777 sizeof(session->DAA_tpmSpecific.DAA_count));
778 - sha1_update(&sha1, "\x00", 1);
779 + sha1_update(&sha1, (BYTE *) "\x00", 1);
780 sha1_final(&sha1, scratch);
781 sha1_init(&sha1);
782 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
783 sizeof(session->DAA_tpmSpecific.DAA_rekey));
784 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
785 sizeof(session->DAA_tpmSpecific.DAA_count));
786 - sha1_update(&sha1, "\x01", 1);
787 + sha1_update(&sha1, (BYTE *) "\x01", 1);
788 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
789 mpz_init(f), mpz_init(q);
790 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
791 @@ -3143,7 +3143,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
792 sha1_init(&sha1);
793 sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest,
794 sizeof(session->DAA_session.DAA_digest));
795 - sha1_update(&sha1, "\x01", 1);
796 + sha1_update(&sha1, (BYTE *) "\x01", 1);
797 sha1_update(&sha1, inputData1, inputSize1);
798 sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest);
799 }
800 @@ -3172,7 +3172,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
801 sha1_init(&sha1);
802 sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest,
803 sizeof(session->DAA_session.DAA_digest));
804 - sha1_update(&sha1, "\x00", 1);
805 + sha1_update(&sha1, (BYTE*) "\x00", 1);
806 rsa_export_modulus(&aikData->key, scratch, &size);
807 sha1_update(&sha1, scratch, size);
808 sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest);
809 @@ -3229,14 +3229,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
810 sizeof(session->DAA_tpmSpecific.DAA_rekey));
811 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
812 sizeof(session->DAA_tpmSpecific.DAA_count));
813 - sha1_update(&sha1, "\x00", 1);
814 + sha1_update(&sha1, (BYTE *) "\x00", 1);
815 sha1_final(&sha1, scratch);
816 sha1_init(&sha1);
817 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
818 sizeof(session->DAA_tpmSpecific.DAA_rekey));
819 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
820 sizeof(session->DAA_tpmSpecific.DAA_count));
821 - sha1_update(&sha1, "\x01", 1);
822 + sha1_update(&sha1, (BYTE *) "\x01", 1);
823 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
824 mpz_init(f), mpz_init(q);
825 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
826 @@ -3309,14 +3309,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
827 sizeof(session->DAA_tpmSpecific.DAA_rekey));
828 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
829 sizeof(session->DAA_tpmSpecific.DAA_count));
830 - sha1_update(&sha1, "\x00", 1);
831 + sha1_update(&sha1, (BYTE *) "\x00", 1);
832 sha1_final(&sha1, scratch);
833 sha1_init(&sha1);
834 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey,
835 sizeof(session->DAA_tpmSpecific.DAA_rekey));
836 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count,
837 sizeof(session->DAA_tpmSpecific.DAA_count));
838 - sha1_update(&sha1, "\x01", 1);
839 + sha1_update(&sha1, (BYTE *) "\x01", 1);
840 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
841 mpz_init(f), mpz_init(q);
842 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
843 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_data.c tpm_emulator/tpm/tpm_data.c
844 --- orig/tpm_emulator-0.4/tpm/tpm_data.c 2006-06-23 03:37:07.000000000 -0700
845 +++ tpm_emulator/tpm/tpm_data.c 2006-07-24 14:35:35.000000000 -0700
846 @@ -40,6 +40,7 @@ static inline void init_pcr_attr(int pcr
847 void tpm_init_data(void)
848 {
849 /* endorsement key */
850 +#ifndef TPM_GENERATE_EK
851 uint8_t ek_n[] = "\xa8\xdb\xa9\x42\xa8\xf3\xb8\x06\x85\x90\x76\x93\xad\xf7"
852 "\x74\xec\x3f\xd3\x3d\x9d\xe8\x2e\xff\x15\xed\x0e\xce\x5f\x93"
853 "\x92\xeb\xd1\x96\x2b\x72\x18\x81\x79\x12\x9d\x9c\x40\xd7\x1a"
854 @@ -77,6 +78,8 @@ void tpm_init_data(void)
855 "\xd1\xc0\x8b\x5b\xa2\x2e\xa7\x15\xca\x50\x75\x10\x48\x9c\x2b"
856 "\x18\xb9\x67\x8f\x5d\x64\xc3\x28\x9f\x2f\x16\x2f\x08\xda\x47"
857 "\xec\x86\x43\x0c\x80\x99\x07\x34\x0f";
858 +#endif
859 +
860 int i;
861 /* reset all data to NULL, FALSE or 0 */
862 memset(&tpmData, 0, sizeof(tpmData));
863 @@ -152,44 +155,43 @@ void tpm_release_data(void)
865 #ifdef TPM_STORE_TO_FILE
867 -#include <linux/fs.h>
868 -#include <linux/unistd.h>
869 -#include <asm/uaccess.h>
870 +#include <sys/types.h>
871 +#include <sys/stat.h>
872 +#include <fcntl.h>
873 +#include <unistd.h>
875 #define TPM_STORAGE_FILE "/var/tpm/tpm_emulator-1.2." STR(VERSION_MAJOR) "." STR(VERSION_MINOR)
877 static int write_to_file(uint8_t *data, size_t data_length)
878 {
879 int res;
880 - struct file *fp;
881 - mm_segment_t old_fs = get_fs();
882 - fp = filp_open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
883 - if (IS_ERR(fp)) return -1;
884 - set_fs(get_ds());
885 - res = fp->f_op->write(fp, data, data_length, &fp->f_pos);
886 - set_fs(old_fs);
887 - filp_close(fp, NULL);
888 + int fp;
889 + fp = open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
890 + res = write(fp, data, data_length);
891 + close(fp);
892 return (res == data_length) ? 0 : -1;
893 }
895 static int read_from_file(uint8_t **data, size_t *data_length)
896 {
897 int res;
898 - struct file *fp;
899 - mm_segment_t old_fs = get_fs();
900 - fp = filp_open(TPM_STORAGE_FILE, O_RDONLY, 0);
901 - if (IS_ERR(fp)) return -1;
902 - *data_length = (size_t)fp->f_dentry->d_inode->i_size;
903 - /* *data_length = i_size_read(fp->f_dentry->d_inode); */
904 + int fp, file_status;
905 + struct stat file_info;
906 + fp = open(TPM_STORAGE_FILE, O_RDONLY, 0);
907 + file_status = fstat(fp, &file_info);
908 + if (file_status < 0) {
909 + close(fp);
910 + return -1;
911 + }
912 +
913 + *data_length = file_info.st_size;
914 *data = tpm_malloc(*data_length);
915 if (*data == NULL) {
916 - filp_close(fp, NULL);
917 + close(fp);
918 return -1;
919 }
920 - set_fs(get_ds());
921 - res = fp->f_op->read(fp, *data, *data_length, &fp->f_pos);
922 - set_fs(old_fs);
923 - filp_close(fp, NULL);
924 + res = read(fp, *data, *data_length);
925 + close(fp);
926 if (res != *data_length) {
927 tpm_free(*data);
928 return -1;
929 @@ -216,23 +218,30 @@ static int read_from_file(uint8_t **data
930 int tpm_store_permanent_data(void)
931 {
932 uint8_t *buf, *ptr;
933 - size_t buf_length, len;
934 + UINT32 buf_length, len;
936 /* marshal data */
937 - buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
938 - + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) + 2
939 - + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data);
940 + buf_length = len = 4 + sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
941 + + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags)
942 + + sizeof_TPM_STANY_FLAGS(tpmData.stany.flags) + 2
943 + + sizeof_TPM_STCLEAR_DATA(tpmData.stclear.data)
944 + + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data)
945 + + sizeof_TPM_STANY_DATA(tpmData.stany.data);
946 buf = ptr = tpm_malloc(buf_length);
947 if (buf == NULL
948 || tpm_marshal_TPM_VERSION(&ptr, &len, &tpmData.permanent.data.version)
949 || tpm_marshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags)
950 || tpm_marshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags)
951 + || tpm_marshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags)
952 || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.selfTestSucceeded)
953 || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.owned)
954 - || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) {
955 + || tpm_marshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data)
956 + || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)
957 + || tpm_marshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) {
958 tpm_free(buf);
959 return -1;
960 }
961 +
962 if (write_to_file(buf, buf_length - len)) {
963 tpm_free(buf);
964 return -1;
965 @@ -244,31 +253,36 @@ int tpm_store_permanent_data(void)
966 int tpm_restore_permanent_data(void)
967 {
968 uint8_t *buf, *ptr;
969 - size_t buf_length, len;
970 + size_t buf_length;
971 + UINT32 len;
972 TPM_VERSION ver;
974 /* read data */
975 if (read_from_file(&buf, &buf_length)) return -1;
976 ptr = buf;
977 - len = buf_length;
978 + len = (uint32_t) buf_length;
979 /* unmarshal data */
980 if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
981 || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
982 || tpm_unmarshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags)
983 || tpm_unmarshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags)
984 + || tpm_unmarshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags)
985 || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.selfTestSucceeded)
986 || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.owned)
987 - || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) {
988 + || tpm_unmarshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data)
989 + || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)
990 + || tpm_unmarshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) {
991 tpm_free(buf);
992 return -1;
993 }
994 +
995 tpm_free(buf);
996 return 0;
997 }
999 int tpm_erase_permanent_data(void)
1001 - int res = write_to_file("", 0);
1002 + int res = write_to_file((uint8_t *) "", 0);
1003 return res;
1006 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_deprecated.c tpm_emulator/tpm/tpm_deprecated.c
1007 --- orig/tpm_emulator-0.4/tpm/tpm_deprecated.c 2006-06-23 03:37:07.000000000 -0700
1008 +++ tpm_emulator/tpm/tpm_deprecated.c 2006-07-24 14:35:35.000000000 -0700
1009 @@ -1,6 +1,7 @@
1010 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1011 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1012 * Swiss Federal Institute of Technology (ETH) Zurich
1013 + * Copyright (C) 2005 INTEL Corp
1015 * This module is free software; you can redistribute it and/or modify
1016 * it under the terms of the GNU General Public License as published
1017 @@ -50,7 +51,7 @@ TPM_RESULT TPM_SaveKeyContext(TPM_KEY_HA
1018 BYTE *ptr;
1019 UINT32 len;
1020 info("TPM_SaveKeyContext()");
1021 - res = TPM_SaveContext(keyHandle, TPM_RT_KEY, "SaveKeyContext..",
1022 + res = TPM_SaveContext(keyHandle, TPM_RT_KEY, (BYTE*)"SaveKeyContext..",
1023 keyContextSize, &contextBlob);
1024 if (res != TPM_SUCCESS) return res;
1025 len = *keyContextSize;
1026 @@ -82,7 +83,7 @@ TPM_RESULT TPM_SaveAuthContext(TPM_AUTHH
1027 BYTE *ptr;
1028 UINT32 len;
1029 info("TPM_SaveAuthContext()");
1030 - res = TPM_SaveContext(authHandle, TPM_RT_KEY, "SaveAuthContext.",
1031 + res = TPM_SaveContext(authHandle, TPM_RT_KEY, (BYTE*)"SaveAuthContext.",
1032 authContextSize, &contextBlob);
1033 if (res != TPM_SUCCESS) return res;
1034 len = *authContextSize;
1035 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_emulator.h tpm_emulator/tpm/tpm_emulator.h
1036 --- orig/tpm_emulator-0.4/tpm/tpm_emulator.h 2006-06-23 03:37:07.000000000 -0700
1037 +++ tpm_emulator/tpm/tpm_emulator.h 2006-07-24 14:35:35.000000000 -0700
1038 @@ -1,5 +1,6 @@
1039 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1040 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1041 + * Copyright (C) 2005 INTEL Corp
1043 * This module is free software; you can redistribute it and/or modify
1044 * it under the terms of the GNU General Public License as published
1045 @@ -22,7 +23,8 @@
1046 /* TPM configuration */
1047 #define TPM_STORE_TO_FILE 1
1048 #undef TPM_STRONG_PERSISTENCE
1049 -#undef TPM_GENERATE_EK
1050 +//#undef TPM_GENERATE_EK
1051 +#define TPM_GENERATE_EK
1052 #undef TPM_GENERATE_SEED_DAA
1054 #define TPM_MANUFACTURER 0x4554485A /* 'ETHZ' */
1055 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_marshalling.c tpm_emulator/tpm/tpm_marshalling.c
1056 --- orig/tpm_emulator-0.4/tpm/tpm_marshalling.c 2006-06-23 03:37:07.000000000 -0700
1057 +++ tpm_emulator/tpm/tpm_marshalling.c 2006-07-24 14:35:35.000000000 -0700
1058 @@ -1312,7 +1312,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
1060 int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
1062 - UINT32 m_len, e_len, q_len;
1063 + size_t m_len, e_len, q_len;
1064 if (*length < sizeof_RSA((*v))) return -1;
1065 if (v->size > 0) {
1066 rsa_export_modulus(v, &(*ptr)[6], &m_len);
1067 @@ -1460,6 +1460,66 @@ int tpm_unmarshal_TPM_PERMANENT_DATA(BYT
1068 return 0;
1071 +int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v)
1072 +{
1073 + if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag)
1074 + || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceKey)
1075 + || tpm_marshal_TPM_COUNT_ID(ptr, length, v->countID) ) return -1;
1077 + return 0;
1078 +}
1080 +int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v)
1081 +{
1082 + if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag)
1083 + || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceKey)
1084 + || tpm_unmarshal_TPM_COUNT_ID(ptr, length, &v->countID) ) return -1;
1086 + return 0;
1087 +}
1089 +int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v)
1090 +{
1091 + UINT32 i;
1092 + if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag)
1093 + || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceSession)
1094 + || tpm_marshal_TPM_DIGEST(ptr, length, &v->auditDigest)
1095 + || tpm_marshal_BOOL(ptr, length, v->auditSession)
1096 + || tpm_marshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks)
1097 + || tpm_marshal_UINT32(ptr, length, v->contextCount)
1098 + || tpm_marshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1;
1099 + for (i = 0; i < TPM_MAX_SESSIONS; i++) {
1100 + if (tpm_marshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1;
1101 + }
1102 + for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) {
1103 + if (tpm_marshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1;
1104 + }
1105 + if (tpm_marshal_TPM_TRANSHANDLE(ptr, length, v->transExclusive)) return -1;
1107 + return 0;
1108 +}
1110 +int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v)
1111 +{
1112 + UINT32 i;
1113 + if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag)
1114 + || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceSession)
1115 + || tpm_unmarshal_TPM_DIGEST(ptr, length, &v->auditDigest)
1116 + || tpm_unmarshal_BOOL(ptr, length, &v->auditSession)
1117 + || tpm_unmarshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks)
1118 + || tpm_unmarshal_UINT32(ptr, length, &v->contextCount)
1119 + || tpm_unmarshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1;
1120 + for (i = 0; i < TPM_MAX_SESSIONS; i++) {
1121 + if (tpm_unmarshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1;
1122 + }
1123 + for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) {
1124 + if (tpm_unmarshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1;
1125 + }
1126 + if (tpm_unmarshal_TPM_TRANSHANDLE(ptr, length, &v->transExclusive)) return -1;
1128 + return 0;
1129 +}
1131 int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v)
1133 if (tpm_marshal_BYTE(ptr, length, v->type)
1134 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_marshalling.h tpm_emulator/tpm/tpm_marshalling.h
1135 --- orig/tpm_emulator-0.4/tpm/tpm_marshalling.h 2006-06-23 03:37:07.000000000 -0700
1136 +++ tpm_emulator/tpm/tpm_marshalling.h 2006-07-24 14:35:35.000000000 -0700
1137 @@ -432,6 +432,12 @@ int tpm_unmarshal_TPM_KEY_DATA(BYTE **pt
1138 int tpm_marshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *);
1139 int tpm_unmarshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *);
1141 +int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v);
1142 +int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v);
1144 +int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v);
1145 +int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v);
1147 int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v);
1148 int tpm_unmarshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v);
1150 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_owner.c tpm_emulator/tpm/tpm_owner.c
1151 --- orig/tpm_emulator-0.4/tpm/tpm_owner.c 2006-06-23 03:37:07.000000000 -0700
1152 +++ tpm_emulator/tpm/tpm_owner.c 2006-07-24 14:35:35.000000000 -0700
1153 @@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
1154 TPM_RESULT res;
1155 rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
1156 TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
1157 - UINT32 buf_size = ek->size >> 3;
1158 + size_t buf_size = ek->size >> 3, key_length;
1159 BYTE buf[buf_size];
1161 info("TPM_TakeOwnership()");
1162 @@ -173,7 +173,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
1163 return TPM_FAIL;
1165 rsa_export_modulus(&srk->key, srkPub->pubKey.key,
1166 - &srkPub->pubKey.keyLength);
1167 + &key_length);
1168 + srkPub->pubKey.keyLength = (UINT32) key_length;
1169 /* setup tpmProof and set state to owned */
1170 tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce,
1171 sizeof(tpmData.permanent.data.tpmProof.nonce));
1172 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_startup.c tpm_emulator/tpm/tpm_startup.c
1173 --- orig/tpm_emulator-0.4/tpm/tpm_startup.c 2006-06-23 03:37:07.000000000 -0700
1174 +++ tpm_emulator/tpm/tpm_startup.c 2006-07-24 14:35:35.000000000 -0700
1175 @@ -41,26 +41,29 @@ void TPM_Init(TPM_STARTUP_TYPE startupTy
1176 TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE startupType)
1178 int i;
1179 + int restore_fail;
1180 info("TPM_Startup(%d)", startupType);
1181 if (tpmData.stany.flags.postInitialise == FALSE) return TPM_INVALID_POSTINIT;
1182 - /* reset STANY_FLAGS */
1183 - SET_TO_ZERO(&tpmData.stany.flags);
1184 - tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS;
1185 - /* reset STANY_DATA (invalidates ALL sessions) */
1186 - SET_TO_ZERO(&tpmData.stany.data);
1187 - tpmData.stany.data.tag = TPM_TAG_STANY_DATA;
1188 - /* init session-context nonce */
1189 - SET_TO_RAND(&tpmData.stany.data.contextNonceSession);
1191 + /* try and restore state to get EK, SRK, etc */
1192 + restore_fail = tpm_restore_permanent_data();
1194 /* set data and flags according to the given startup type */
1195 if (startupType == TPM_ST_CLEAR) {
1196 - /* if available, restore permanent data */
1197 - tpm_restore_permanent_data();
1198 + /* reset STANY_FLAGS */
1199 + SET_TO_ZERO(&tpmData.stany.flags);
1200 + tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS;
1201 + /* reset STANY_DATA (invalidates ALL sessions) */
1202 + SET_TO_ZERO(&tpmData.stany.data);
1203 + tpmData.stany.data.tag = TPM_TAG_STANY_DATA;
1204 + /* init session-context nonce */
1205 + SET_TO_RAND(&tpmData.stany.data.contextNonceSession);
1206 /* reset PCR values */
1207 for (i = 0; i < TPM_NUM_PCR; i++) {
1208 - if (tpmData.permanent.data.pcrAttrib[i].pcrReset)
1209 - SET_TO_ZERO(tpmData.permanent.data.pcrValue[i].digest);
1210 + if (!tpmData.permanent.data.pcrAttrib[i].pcrReset)
1211 + SET_TO_ZERO(&tpmData.permanent.data.pcrValue[i].digest);
1212 else
1213 - SET_TO_0xFF(tpmData.permanent.data.pcrValue[i].digest);
1214 + SET_TO_0xFF(&tpmData.permanent.data.pcrValue[i].digest);
1216 /* reset STCLEAR_FLAGS */
1217 SET_TO_ZERO(&tpmData.stclear.flags);
1218 @@ -79,7 +82,8 @@ TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE
1219 /* init key-context nonce */
1220 SET_TO_RAND(&tpmData.stclear.data.contextNonceKey);
1221 } else if (startupType == TPM_ST_STATE) {
1222 - if (tpm_restore_permanent_data()) {
1223 + /* restore must have been successful for TPM_ST_STATE */
1224 + if (restore_fail) {
1225 error("restoring permanent data failed");
1226 tpmData.permanent.data.testResult = "tpm_restore_permanent_data() failed";
1227 tpmData.permanent.flags.selfTestSucceeded = FALSE;
1228 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_storage.c tpm_emulator/tpm/tpm_storage.c
1229 --- orig/tpm_emulator-0.4/tpm/tpm_storage.c 2006-06-23 03:37:07.000000000 -0700
1230 +++ tpm_emulator/tpm/tpm_storage.c 2006-07-24 14:35:35.000000000 -0700
1231 @@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
1232 BYTE *enc, UINT32 *enc_size)
1234 UINT32 len;
1235 + size_t enc_size32 = *enc_size;
1236 BYTE *buf, *ptr;
1237 rsa_public_key_t pub_key;
1238 int scheme;
1239 @@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
1240 if (buf == NULL
1241 || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal)
1242 || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)),
1243 - enc, enc_size)) {
1244 + enc, &enc_size32)) {
1245 tpm_free(buf);
1246 rsa_release_public_key(&pub_key);
1247 return -1;
1248 @@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
1249 int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
1250 TPM_SEALED_DATA *seal, BYTE **buf)
1252 - UINT32 len;
1253 + size_t len;
1254 + UINT32 len32;
1255 BYTE *ptr;
1256 int scheme;
1257 switch (key->encScheme) {
1258 @@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke
1259 len = enc_size;
1260 *buf = ptr = tpm_malloc(len);
1261 if (*buf == NULL
1262 - || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
1263 - || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) {
1264 + || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){
1265 + tpm_free(*buf);
1266 + return -1;
1267 + }
1268 + len32 = len;
1269 + if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) {
1270 tpm_free(*buf);
1271 return -1;
1273 @@ -240,11 +246,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par
1275 TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize,
1276 BYTE *inData, TPM_AUTH *auth1,
1277 - UINT32 *outDataSize, BYTE **outData)
1278 + UINT32 *outDataSize32, BYTE **outData)
1280 TPM_RESULT res;
1281 TPM_KEY_DATA *key;
1282 int scheme;
1283 + size_t outDataSize;
1285 info("TPM_UnBind()");
1286 /* get key */
1287 @@ -262,8 +269,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
1288 /* the size of the input data muss be greater than zero */
1289 if (inDataSize == 0) return TPM_BAD_PARAMETER;
1290 /* decrypt data */
1291 - *outDataSize = inDataSize;
1292 - *outData = tpm_malloc(*outDataSize);
1293 + outDataSize = inDataSize;
1294 + *outData = tpm_malloc(outDataSize);
1295 if (*outData == NULL) return TPM_NOSPACE;
1296 switch (key->encScheme) {
1297 case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
1298 @@ -271,20 +278,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
1299 default: tpm_free(*outData); return TPM_DECRYPT_ERROR;
1301 if (rsa_decrypt(&key->key, scheme, inData, inDataSize,
1302 - *outData, outDataSize)) {
1303 + *outData, &outDataSize)) {
1304 tpm_free(*outData);
1305 return TPM_DECRYPT_ERROR;
1307 /* verify data if it is of type TPM_BOUND_DATA */
1308 if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1
1309 || key->keyUsage != TPM_KEY_LEGACY) {
1310 - if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
1311 + if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
1312 tpm_free(*outData);
1313 return TPM_DECRYPT_ERROR;
1315 - *outDataSize -= 5;
1316 - memmove(*outData, &(*outData)[5], *outDataSize);
1317 + outDataSize -= 5;
1318 + memmove(*outData, &(*outData)[5], outDataSize);
1320 + *outDataSize32 = (UINT32) outDataSize;
1321 return TPM_SUCCESS;
1324 @@ -334,12 +342,13 @@ int compute_pubkey_digest(TPM_PUBKEY *ke
1327 int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store,
1328 - BYTE *enc, UINT32 *enc_size)
1329 + BYTE *enc, UINT32 *enc_size32)
1331 UINT32 len;
1332 BYTE *buf, *ptr;
1333 rsa_public_key_t pub_key;
1334 int scheme;
1335 + size_t enc_size;
1336 switch (key->encScheme) {
1337 case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
1338 case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break;
1339 @@ -351,11 +360,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke
1340 if (buf == NULL
1341 || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store)
1342 || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)),
1343 - enc, enc_size)) {
1344 + enc, &enc_size)) {
1345 tpm_free(buf);
1346 rsa_release_public_key(&pub_key);
1347 return -1;
1349 + *enc_size32 = (UINT32) enc_size;
1350 tpm_free(buf);
1351 rsa_release_public_key(&pub_key);
1352 return 0;
1353 @@ -364,7 +374,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke
1354 int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
1355 TPM_STORE_ASYMKEY *store, BYTE **buf)
1357 - UINT32 len;
1358 + UINT32 len32;
1359 + size_t len;
1360 BYTE *ptr;
1361 int scheme;
1362 switch (key->encScheme) {
1363 @@ -375,8 +386,12 @@ int decrypt_private_key(TPM_KEY_DATA *ke
1364 len = enc_size;
1365 *buf = ptr = tpm_malloc(len);
1366 if (*buf == NULL
1367 - || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
1368 - || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) {
1369 + || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) {
1370 + tpm_free(*buf);
1371 + return -1;
1372 + }
1373 + len32 = (UINT32) len;
1374 + if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) {
1375 tpm_free(*buf);
1376 return -1;
1378 @@ -394,7 +409,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
1379 TPM_SESSION_DATA *session;
1380 TPM_STORE_ASYMKEY store;
1381 rsa_private_key_t rsa;
1382 - UINT32 key_length;
1383 + size_t key_length;
1385 info("TPM_CreateWrapKey()");
1386 /* get parent key */
1387 @@ -450,11 +465,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
1390 /* generate key and store it */
1391 - key_length = keyInfo->algorithmParms.parms.rsa.keyLength;
1392 - if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL;
1393 - wrappedKey->pubKey.keyLength = key_length >> 3;
1394 + if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength))
1395 + return TPM_FAIL;
1396 + wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3;
1397 wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength);
1398 - store.privKey.keyLength = key_length >> 4;
1399 + store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4;
1400 store.privKey.key = tpm_malloc(store.privKey.keyLength);
1401 wrappedKey->encDataSize = parent->key.size >> 3;
1402 wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize);
1403 @@ -466,9 +481,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
1404 tpm_free(wrappedKey->encData);
1405 return TPM_NOSPACE;
1407 - rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
1408 - &wrappedKey->pubKey.keyLength);
1409 - rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength);
1410 + rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
1411 + &key_length);
1412 + wrappedKey->pubKey.keyLength = (UINT32) key_length;
1413 + rsa_export_prime1(&rsa, store.privKey.key, &key_length);
1414 + store.privKey.keyLength = (UINT32) key_length;
1415 rsa_release_private_key(&rsa);
1416 /* compute the digest of the wrapped key (without encData) */
1417 if (compute_key_digest(wrappedKey, &store.pubDataDigest)) {
1418 @@ -602,6 +619,7 @@ TPM_RESULT TPM_LoadKey2(TPM_KEY_HANDLE p
1420 int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms)
1422 + size_t key_length;
1423 parms->algorithmID = TPM_ALG_RSA;
1424 parms->encScheme = key->encScheme;
1425 parms->sigScheme = key->sigScheme;
1426 @@ -611,7 +629,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke
1427 parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize);
1428 if (parms->parms.rsa.exponent == NULL) return -1;
1429 rsa_export_exponent(&key->key, parms->parms.rsa.exponent,
1430 - &parms->parms.rsa.exponentSize);
1431 + &key_length);
1432 + parms->parms.rsa.exponentSize = (UINT32) key_length;
1433 parms->parmSize = 12 + parms->parms.rsa.exponentSize;
1434 return 0;
1436 @@ -622,6 +641,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE
1437 TPM_RESULT res;
1438 TPM_KEY_DATA *key;
1439 TPM_DIGEST digest;
1440 + size_t key_length;
1441 info("TPM_GetPubKey()");
1442 /* get key */
1443 if (keyHandle == TPM_KH_SRK
1444 @@ -650,8 +670,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE
1445 pubKey->pubKey.keyLength = key->key.size >> 3;
1446 pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength);
1447 if (pubKey->pubKey.key == NULL) return TPM_NOSPACE;
1448 - rsa_export_modulus(&key->key, pubKey->pubKey.key,
1449 - &pubKey->pubKey.keyLength);
1450 + rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length);
1451 + pubKey->pubKey.keyLength = (UINT32) key_length;
1452 if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
1453 error("TPM_GetPubKey(): tpm_setup_key_parms() failed.");
1454 tpm_free(pubKey->pubKey.key);
1455 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_structures.h tpm_emulator/tpm/tpm_structures.h
1456 --- orig/tpm_emulator-0.4/tpm/tpm_structures.h 2006-06-23 03:37:07.000000000 -0700
1457 +++ tpm_emulator/tpm/tpm_structures.h 2006-07-24 14:35:35.000000000 -0700
1458 @@ -1958,6 +1958,7 @@ typedef struct tdTPM_DAA_ISSUER {
1459 TPM_DIGEST DAA_digest_gamma;
1460 BYTE DAA_generic_q[26];
1461 } TPM_DAA_ISSUER;
1462 +#define sizeof_TPM_DAA_ISSUER(s) (2 + (20 * 6) + 26 )
1464 /*
1465 * TPM_DAA_TPM ([TPM_Part2], Section 22.4)
1466 @@ -1973,6 +1974,7 @@ typedef struct tdTPM_DAA_TPM {
1467 TPM_DIGEST DAA_rekey;
1468 UINT32 DAA_count;
1469 } TPM_DAA_TPM;
1470 +#define sizeof_TPM_DAA_TPM(s) (2 + (4 * 20) + 4)
1472 /*
1473 * TPM_DAA_CONTEXT ([TPM_Part2], Section 22.5)
1474 @@ -1987,6 +1989,7 @@ typedef struct tdTPM_DAA_CONTEXT {
1475 BYTE DAA_scratch[256];
1476 BYTE DAA_stage;
1477 } TPM_DAA_CONTEXT;
1478 +#define sizeof_TPM_DAA_CONTEXT(s) (2 + (3 * 20) + 256 + 1)
1480 /*
1481 * TPM_DAA_JOINDATA ([TPM_Part2], Section 22.6)
1482 @@ -1998,6 +2001,7 @@ typedef struct tdTPM_DAA_JOINDATA {
1483 BYTE DAA_join_u1[138];
1484 TPM_DIGEST DAA_digest_n0;
1485 } TPM_DAA_JOINDATA;
1486 +#define sizeof_TPM_DAA_JOINDATA(s) (1 + 1 + 20)
1488 /*
1489 * TPM_DAA_BLOB ([TPM_Part2], Section 22.8)
1490 @@ -2202,6 +2206,7 @@ typedef struct tdTPM_STCLEAR_DATA {
1491 //UINT32 ownerReference;
1492 //BOOL disableResetLock;
1493 } TPM_STCLEAR_DATA;
1494 +#define sizeof_TPM_STCLEAR_DATA(s) (2 + 20 + 4)
1496 /*
1497 * TPM_SESSION_DATA
1498 @@ -2238,6 +2243,11 @@ typedef struct tdTPM_DAA_SESSION_DATA {
1499 TPM_DAA_JOINDATA DAA_joinSession;
1500 TPM_HANDLE handle;
1501 } TPM_DAA_SESSION_DATA;
1502 +#define sizeof_TPM_DAA_SESSION_DATA(s) ( 1 \
1503 + + sizeof_TPM_DAA_ISSUER(s.DAA_issuerSettings) \
1504 + + sizeof_TPM_DAA_TPM(s.DAA_tpmSpecific) \
1505 + + sizeof_TPM_DAA_CONTEXT(s.DAA_session) \
1506 + + sizeof_TPM_DAA_JOINDATA(s.DAA_joinSession) + 4)
1508 /*
1509 * TPM_STANY_DATA ([TPM_Part2], Section 7.6)
1510 @@ -2262,6 +2272,11 @@ typedef struct tdTPM_STANY_DATA {
1511 TPM_DAAHANDLE currentDAA;
1512 TPM_TRANSHANDLE transExclusive;
1513 } TPM_STANY_DATA;
1514 +#define sizeof_TPM_STANY_DATA(s) (2 + 20 + 20 + 1 \
1515 + + sizeof_TPM_CURRENT_TICKS(s.currentTicks) \
1516 + + 4 + (4 * TPM_MAX_SESSION_LIST) \
1517 + + (sizeof_TPM_SESSION_DATA(s.sessions[0]) * TPM_MAX_SESSION_LIST) \
1518 + + (sizeof_TPM_DAA_SESSION_DATA(s.sessionsDAA[0]) * TPM_MAX_SESSIONS_DAA) + 4)
1520 /*
1521 * TPM_DATA
1522 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_testing.c tpm_emulator/tpm/tpm_testing.c
1523 --- orig/tpm_emulator-0.4/tpm/tpm_testing.c 2006-06-23 03:37:07.000000000 -0700
1524 +++ tpm_emulator/tpm/tpm_testing.c 2006-07-24 14:35:35.000000000 -0700
1525 @@ -1,6 +1,7 @@
1526 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1527 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1528 * Swiss Federal Institute of Technology (ETH) Zurich
1529 + * Copyright (C) 2005 INTEL Corp
1531 * This module is free software; you can redistribute it and/or modify
1532 * it under the terms of the GNU General Public License as published
1533 @@ -95,24 +96,24 @@ static int tpm_test_sha1(void)
1534 struct {
1535 uint8_t *data; uint32_t repetitions; uint8_t *digest;
1536 } test_cases[] = {{
1537 - "abc", 1,
1538 - "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D"
1539 + (uint8_t*)"abc", 1,
1540 + (uint8_t*)"\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D"
1541 }, {
1542 - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
1543 - "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1"
1544 + (uint8_t*)"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
1545 + (uint8_t*)"\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1"
1546 }, {
1547 - "a", 1000000,
1548 - "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F"
1549 + (uint8_t*)"a", 1000000,
1550 + (uint8_t*)"\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F"
1551 }, {
1552 - "0123456701234567012345670123456701234567012345670123456701234567", 10,
1553 - "\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52"
1554 + (uint8_t*)"0123456701234567012345670123456701234567012345670123456701234567", 10,
1555 + (uint8_t*)"\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52"
1556 }};
1558 debug("tpm_test_sha1()");
1559 for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
1560 sha1_init(&ctx);
1561 for (j = 0; j < test_cases[i].repetitions; j++)
1562 - sha1_update(&ctx, test_cases[i].data, strlen(test_cases[i].data));
1563 + sha1_update(&ctx, test_cases[i].data, strlen((char*)test_cases[i].data));
1564 sha1_final(&ctx, digest);
1565 if (memcmp(digest, test_cases[i].digest, SHA1_DIGEST_LENGTH) != 0) return -1;
1567 @@ -128,41 +129,41 @@ static int tpm_test_hmac(void)
1568 struct {
1569 uint8_t *key, key_len, *data, data_len, *digest;
1570 } test_cases[] = {{
1571 - "\x0b", 20, "Hi There", 8,
1572 - "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00"
1573 + (uint8_t*)"\x0b", 20, (uint8_t*)"Hi There", 8,
1574 + (uint8_t*)"\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00"
1575 }, {
1576 - "Jefe", 4, "what do ya want for nothing?", 28,
1577 - "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79"
1578 + (uint8_t*)"Jefe", 4, (uint8_t*)"what do ya want for nothing?", 28,
1579 + (uint8_t*)"\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79"
1580 }, {
1581 - "\xaa", 20, "\xdd", 50,
1582 - "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3"
1583 + (uint8_t*)"\xaa", 20, (uint8_t*)"\xdd", 50,
1584 + (uint8_t*)"\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3"
1585 }, {
1586 - "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1587 - "\x15\x16\x17\x18\x19", 25, "\xcd", 50,
1588 - "\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda"
1589 + (uint8_t*)"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1590 + "\x15\x16\x17\x18\x19", 25, (uint8_t*)"\xcd", 50,
1591 + (uint8_t*)"\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda"
1592 }, {
1593 - "\x0c", 20, "Test With Truncation", 20,
1594 - "\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04"
1595 + (uint8_t*)"\x0c", 20, (uint8_t*)"Test With Truncation", 20,
1596 + (uint8_t*)"\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04"
1597 }, {
1598 - "\xaa", 80, "Test Using Larger Than Block-Size Key - Hash Key First", 54,
1599 - "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12"
1600 + (uint8_t*)"\xaa", 80, (uint8_t*)"Test Using Larger Than Block-Size Key - Hash Key First", 54,
1601 + (uint8_t*)"\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12"
1602 }, {
1603 - "\xaa", 80,
1604 - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73,
1605 - "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91"
1606 + (uint8_t*)"\xaa", 80,
1607 + (uint8_t*)"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73,
1608 + (uint8_t*)"\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91"
1609 }};
1611 debug("tpm_test_hmac()");
1612 for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
1613 - if (strlen(test_cases[i].key) < test_cases[i].key_len) {
1614 + if (strlen((char*)test_cases[i].key) < test_cases[i].key_len) {
1615 uint8_t key[test_cases[i].key_len];
1616 memset(key, test_cases[i].key[0], test_cases[i].key_len);
1617 hmac_init(&ctx, key, test_cases[i].key_len);
1618 } else {
1619 hmac_init(&ctx, test_cases[i].key, test_cases[i].key_len);
1621 - for (j = 0; j < test_cases[i].data_len; j += strlen(test_cases[i].data)) {
1622 - hmac_update(&ctx, test_cases[i].data, strlen(test_cases[i].data));
1623 + for (j = 0; j < test_cases[i].data_len; j += strlen((char*)test_cases[i].data)) {
1624 + hmac_update(&ctx, test_cases[i].data, strlen((char*)test_cases[i].data));
1626 hmac_final(&ctx, digest);
1627 if (memcmp(digest, test_cases[i].digest, SHA1_DIGEST_LENGTH) != 0) return -1;
1628 @@ -173,9 +174,9 @@ static int tpm_test_hmac(void)
1629 static int tpm_test_rsa_EK(void)
1631 int res = 0;
1632 - char *data = "RSA PKCS #1 v1.5 Test-String";
1633 + uint8_t *data = (uint8_t*)"RSA PKCS #1 v1.5 Test-String";
1634 uint8_t buf[256];
1635 - size_t buf_len, data_len = strlen(data);
1636 + size_t buf_len, data_len = strlen((char*)data);
1637 rsa_private_key_t priv_key;
1638 rsa_public_key_t pub_key;
1640 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_ticks.c tpm_emulator/tpm/tpm_ticks.c
1641 --- orig/tpm_emulator-0.4/tpm/tpm_ticks.c 2006-06-23 03:37:07.000000000 -0700
1642 +++ tpm_emulator/tpm/tpm_ticks.c 2006-07-24 14:35:35.000000000 -0700
1643 @@ -1,6 +1,7 @@
1644 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1645 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1646 * Swiss Federal Institute of Technology (ETH) Zurich
1647 + * Copyright (C) 2005 INTEL Corp
1649 * This module is free software; you can redistribute it and/or modify
1650 * it under the terms of the GNU General Public License as published
1651 @@ -39,9 +40,7 @@ TPM_RESULT TPM_SetTickType(TPM_TICKTYPE
1652 TPM_RESULT TPM_GetTicks(TPM_CURRENT_TICKS *currentTime)
1654 info("TPM_GetTicks()");
1655 - memcpy(currentTime, &tpmData.stany.data.currentTicks,
1656 - sizeof(TPM_CURRENT_TICKS));
1657 - return TPM_SUCCESS;
1658 + return TPM_DISABLED_CMD;
1661 TPM_RESULT TPM_TickStampBlob(TPM_KEY_HANDLE keyHandle, TPM_NONCE *antiReplay,
1662 @@ -49,64 +48,11 @@ TPM_RESULT TPM_TickStampBlob(TPM_KEY_HAN
1663 TPM_CURRENT_TICKS *currentTicks,
1664 UINT32 *sigSize, BYTE **sig)
1666 - TPM_RESULT res;
1667 - TPM_KEY_DATA *key;
1668 - BYTE *info, *p;
1669 - UINT32 info_length, length;
1670 info("TPM_TickStampBlob()");
1671 - /* get key */
1672 - key = tpm_get_key(keyHandle);
1673 - if (key == NULL) return TPM_INVALID_KEYHANDLE;
1674 - /* verify authorization */
1675 - res = tpm_verify_auth(auth1, key->usageAuth, keyHandle);
1676 - if (res != TPM_SUCCESS) return res;
1677 - if (key->keyUsage != TPM_KEY_SIGNING && key->keyUsage != TPM_KEY_LEGACY
1678 - && key->keyUsage != TPM_KEY_IDENTITY) return TPM_INVALID_KEYUSAGE;
1679 - /* get current ticks */
1680 - TPM_GetTicks(currentTicks);
1681 - /* sign data using signature scheme PKCS1_SHA1 and TPM_SIGN_INFO container */
1682 - *sigSize = key->key.size >> 3;
1683 - *sig = tpm_malloc(*sigSize);
1684 - if (*sig == NULL) return TPM_FAIL;
1685 - /* setup TPM_SIGN_INFO structure */
1686 - info_length = 30 + sizeof(TPM_DIGEST) + sizeof_TPM_CURRENT_TICKS(currentTicks);
1687 - info = tpm_malloc(info_length);
1688 - if (info == NULL) {
1689 - tpm_free(*sig);
1690 - return TPM_FAIL;
1691 - }
1692 - memcpy(&info[0], "\x05\x00TSTP", 6);
1693 - memcpy(&info[6], antiReplay->nonce, 20);
1694 - *(UINT32*)&info[26] = CPU_TO_BE32(20
1695 - + sizeof_TPM_CURRENT_TICKS(currentTicks));
1696 - memcpy(&info[30], digestToStamp->digest, sizeof(TPM_DIGEST));
1697 - p = &info[30 + sizeof(TPM_DIGEST)];
1698 - length = sizeof_TPM_CURRENT_TICKS(currentTicks);
1699 - if (tpm_marshal_TPM_CURRENT_TICKS(&p, &length, currentTicks)
1700 - || rsa_sign(&key->key, RSA_SSA_PKCS1_SHA1, info, info_length, *sig)) {
1701 - tpm_free(*sig);
1702 - tpm_free(info);
1703 - return TPM_FAIL;
1704 - }
1705 - return TPM_SUCCESS;
1706 + return TPM_DISABLED_CMD;
1709 void tpm_update_ticks(void)
1711 - if (tpmData.stany.data.currentTicks.tag == 0) {
1712 - tpmData.stany.data.currentTicks.tag = TPM_TAG_CURRENT_TICKS;
1713 - tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks();
1714 -/* removed since v1.2 rev 94
1715 - tpmData.stany.data.currentTicks.tickType = tpmData.permanent.data.tickType;
1716 -*/
1717 - tpm_get_random_bytes(tpmData.stany.data.currentTicks.tickNonce.nonce,
1718 - sizeof(TPM_NONCE));
1719 - tpmData.stany.data.currentTicks.tickRate = 1;
1720 -/* removed since v1.2 rev 94
1721 - tpmData.stany.data.currentTicks.tickSecurity = TICK_SEC_NO_CHECK;
1722 -*/
1723 - } else {
1724 - tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks();
1725 - }
1728 diff -uprN orig/tpm_emulator-0.4/tpm/tpm_transport.c tpm_emulator/tpm/tpm_transport.c
1729 --- orig/tpm_emulator-0.4/tpm/tpm_transport.c 2006-06-23 03:37:07.000000000 -0700
1730 +++ tpm_emulator/tpm/tpm_transport.c 2006-07-24 14:35:35.000000000 -0700
1731 @@ -189,7 +189,7 @@ static void decrypt_wrapped_command(BYTE
1732 sha1_init(&sha1);
1733 sha1_update(&sha1, auth->nonceEven.nonce, sizeof(auth->nonceEven.nonce));
1734 sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce));
1735 - sha1_update(&sha1, "in", 2);
1736 + sha1_update(&sha1, (BYTE*)"in", 2);
1737 sha1_update(&sha1, secret, sizeof(TPM_SECRET));
1738 j = CPU_TO_BE32(i);
1739 sha1_update(&sha1, (BYTE*)&j, 4);
1740 @@ -211,7 +211,7 @@ static void encrypt_wrapped_command(BYTE
1741 sha1_init(&sha1);
1742 sha1_update(&sha1, auth->nonceEven.nonce, sizeof(auth->nonceEven.nonce));
1743 sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce));
1744 - sha1_update(&sha1, "out", 3);
1745 + sha1_update(&sha1, (BYTE*)"out", 3);
1746 sha1_update(&sha1, secret, sizeof(TPM_SECRET));
1747 j = CPU_TO_BE32(i);
1748 sha1_update(&sha1, (BYTE*)&j, 4);
1749 diff -uprN orig/tpm_emulator-0.4/tpmd.c tpm_emulator/tpmd.c
1750 --- orig/tpm_emulator-0.4/tpmd.c 1969-12-31 16:00:00.000000000 -0800
1751 +++ tpm_emulator/tpmd.c 2006-07-24 14:35:35.000000000 -0700
1752 @@ -0,0 +1,156 @@
1753 +/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1754 + * Copyright (C) 2005 INTEL Corp
1755 + *
1756 + * This module is free software; you can redistribute it and/or modify
1757 + * it under the terms of the GNU General Public License as published
1758 + * by the Free Software Foundation; either version 2 of the License,
1759 + * or (at your option) any later version.
1760 + *
1761 + * This module is distributed in the hope that it will be useful,
1762 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1763 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1764 + * GNU General Public License for more details.
1765 + *
1766 + */
1768 +#include <stdio.h>
1769 +#include <stdlib.h>
1770 +#include <unistd.h>
1771 +#include <string.h>
1772 +#include <sys/types.h>
1773 +#include <sys/stat.h>
1774 +#include <fcntl.h>
1775 +#include <sys/time.h>
1777 +#include "tpm_emulator.h"
1779 +#define TPM_RX_FNAME "/var/tpm/tpm_in.fifo"
1780 +#define TPM_TX_FNAME "/var/tpm/tpm_out.fifo"
1782 +#define BUFFER_SIZE 2048
1784 +static int devurandom=0;
1786 +void get_random_bytes(void *buf, int nbytes) {
1788 + if (devurandom == 0) {
1789 + devurandom = open("/dev/urandom", O_RDONLY);
1790 + }
1792 + if (read(devurandom, buf, nbytes) != nbytes) {
1793 + printf("Can't get random number.\n");
1794 + exit(-1);
1795 + }
1796 +}
1798 +uint64_t tpm_get_ticks(void)
1799 +{
1800 + //struct timeval tv;
1801 + //int gettimeofday(&tv, struct timezone *tz);
1802 + return 0;
1803 +}
1805 +int main(int argc, char **argv)
1806 +{
1807 + uint8_t in[BUFFER_SIZE], *out;
1808 + uint32_t out_size;
1809 + int in_size, written;
1810 + int i;
1811 + struct stat file_info;
1813 + int tpm_tx_fh=-1, tpm_rx_fh=-1;
1814 + if (argc < 2) {
1815 + printf("Usage: tpmd clear|save|deactivated\n" );
1816 + return -1;
1817 + }
1819 + /* initialize TPM emulator */
1820 + if (!strcmp(argv[1], "clear")) {
1821 + printf("Initializing tpm: %s\n", argv[1]);
1822 + tpm_emulator_init(1);
1823 + } else if (!strcmp(argv[1], "save")) {
1824 + printf("Initializing tpm: %s\n", argv[1]);
1825 + tpm_emulator_init(2);
1826 + } else if (!strcmp(argv[1], "deactivated")) {
1827 + printf("Initializing tpm: %s\n", argv[1]);
1828 + tpm_emulator_init(3);
1829 + } else {
1830 + printf("invalid startup mode '%s'; must be 'clear', "
1831 + "'save' (default) or 'deactivated", argv[1]);
1832 + return -1;
1833 + }
1835 + if ( stat(TPM_RX_FNAME, &file_info) == -1) {
1836 + if ( mkfifo(TPM_RX_FNAME, S_IWUSR | S_IRUSR ) ) {
1837 + printf("Failed to create fifo %s.\n", TPM_RX_FNAME);
1838 + return -1;
1839 + }
1840 + }
1842 + if ( stat(TPM_TX_FNAME, &file_info) == -1) {
1843 + if ( mkfifo(TPM_TX_FNAME, S_IWUSR | S_IRUSR ) ) {
1844 + printf("Failed to create fifo %s.\n", TPM_TX_FNAME);
1845 + return -1;
1846 + }
1847 + }
1849 + while (1) {
1850 +abort_command:
1851 + if (tpm_rx_fh < 0) {
1852 + tpm_rx_fh = open(TPM_RX_FNAME, O_RDONLY);
1853 + }
1855 + if (tpm_rx_fh < 0) {
1856 + printf("ERROR: failed to open devices to listen to guest.\n");
1857 + return -1;
1858 + }
1860 + if (tpm_tx_fh < 0) {
1861 + tpm_tx_fh = open(TPM_TX_FNAME, O_WRONLY);
1862 + }
1864 + if (tpm_tx_fh < 0) {
1865 + printf("ERROR: failed to open devices to respond to guest.\n");
1866 + return -1;
1867 + }
1869 + in_size = read(tpm_rx_fh, in, BUFFER_SIZE);
1870 + if (in_size < 6) { // Magic size of minium TPM command
1871 + printf("Recv[%d] to small: 0x", in_size);
1872 + if (in_size <= 0) {
1873 + close(tpm_rx_fh);
1874 + tpm_rx_fh = -1;
1875 + goto abort_command;
1876 + }
1877 + } else {
1878 + printf("Recv[%d]: 0x", in_size);
1879 + for (i=0; i< in_size; i++)
1880 + printf("%x ", in[i]);
1881 + printf("\n");
1882 + }
1885 + if (tpm_handle_command(in, in_size, &out, &out_size) != 0) {
1886 + printf("ERROR: Handler Failed.\n");
1887 + }
1889 + written = write(tpm_tx_fh, out, out_size);
1891 + if (written != out_size ) {
1892 + printf("ERROR: Part of response not written %d/%d.\nAttempt: ", written, out_size);
1893 + } else {
1894 + printf("Sent[%Zu]: ", out_size);
1895 + }
1896 + for (i=0; i< out_size; i++)
1897 + printf("%x ", out[i]);
1898 + printf("\n");
1899 + tpm_free(out);
1901 + } // loop
1903 + tpm_emulator_shutdown();
1905 + close(tpm_tx_fh);
1906 + close(tpm_rx_fh);
1908 +}
1909 Binary files orig/tpm_emulator-0.4/tpm_emulator and tpm_emulator/tpm_emulator differ
1910 diff -uprN orig/tpm_emulator-0.4/tpm_version.h tpm_emulator/tpm_version.h
1911 --- orig/tpm_emulator-0.4/tpm_version.h 2006-06-23 03:37:07.000000000 -0700
1912 +++ tpm_emulator/tpm_version.h 2006-07-24 14:35:41.000000000 -0700
1913 @@ -2,5 +2,5 @@
1914 #define _TPM_VERSION_H_
1915 #define VERSION_MAJOR 0
1916 #define VERSION_MINOR 4
1917 -#define VERSION_BUILD 1151058734
1918 +#define VERSION_BUILD 1153776940
1919 #endif /* _TPM_VERSION_H_ */