ia64/xen-unstable

view tools/vtpm/vtpm.patch @ 6946:e703abaf6e3d

Add behaviour to the remove methods to remove the transaction's path itself. This allows us to write Remove(path) to remove the specified path rather than having to slice the path ourselves.
author emellor@ewan
date Sun Sep 18 14:42:13 2005 +0100 (2005-09-18)
parents 3233e7ecfa9f
children c0796e18b6a4 f8e7af29daa1
line source
1 diff -uprN orig/tpm_emulator-0.2/AUTHORS vtpm/AUTHORS
2 --- orig/tpm_emulator-0.2/AUTHORS 2005-08-17 10:58:36.000000000 -0700
3 +++ vtpm/AUTHORS 2005-08-17 10:55:52.000000000 -0700
4 @@ -1 +1,2 @@
5 Mario Strasser <mast@gmx.net>
6 +INTEL Corp <>
7 diff -uprN orig/tpm_emulator-0.2/ChangeLog vtpm/ChangeLog
8 --- orig/tpm_emulator-0.2/ChangeLog 2005-08-17 10:58:36.000000000 -0700
9 +++ vtpm/ChangeLog 2005-08-17 10:55:52.000000000 -0700
10 @@ -1,3 +1,7 @@
11 +2005-08-16 Intel Corp
12 + Moved module out of kernel to run as a ring 3 app
13 + Modified save_to_file and load_from_file to call a xen backend driver to call a VTPM manager
14 +
15 2005-08-15 Mario Strasser <mast@gmx.net>
16 * all: some typos corrected
17 * tpm_integrity.c: bug in TPM_Extend fixed
18 diff -uprN orig/tpm_emulator-0.2/Makefile vtpm/Makefile
19 --- orig/tpm_emulator-0.2/Makefile 2005-08-17 10:58:36.000000000 -0700
20 +++ vtpm/Makefile 2005-08-17 10:55:52.000000000 -0700
21 @@ -1,21 +1,29 @@
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 # $Id: Makefile 10 2005-04-26 20:59:50Z mast $
28 -# kernel settings
29 -KERNEL_RELEASE := $(shell uname -r)
30 -KERNEL_BUILD := /lib/modules/$(KERNEL_RELEASE)/build
31 -MOD_SUBDIR := misc
32 -
33 # module settings
34 -MODULE_NAME := tpm_emulator
35 +BIN := vtpmd
36 VERSION_MAJOR := 0
37 VERSION_MINOR := 2
38 VERSION_BUILD := $(shell date +"%s")
40 -# enable/disable DEBUG messages
41 -EXTRA_CFLAGS += -DDEBUG -g
42 +# Installation program and options
43 +INSTALL = install
44 +INSTALL_PROG = $(INSTALL) -m0755
45 +INSTALL_DIR = $(INSTALL) -d -m0755
46 +
47 +# Xen tools installation directory
48 +TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
49 +
50 +CC := gcc
51 +CFLAGS += -g -Wall $(INCLUDE) -DDEBUG
52 +CFLAGS += -I. -Itpm
53 +
54 +# Is the simulator running in it's own vm?
55 +#CFLAGS += -DVTPM_MULTI_VM
57 # GNU MP configuration
58 GMP_LIB := /usr/lib/libgmp.a
59 @@ -27,38 +35,31 @@ DIRS := . crypto tpm
60 SRCS := $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.c))
61 OBJS := $(patsubst %.c, %.o, $(SRCS))
62 SRCS += $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.h))
63 -DISTSRC := ./README ./AUTHORS ./ChangeLog ./Makefile $(SRCS)
64 -DISTDIR := tpm_emulator-$(VERSION_MAJOR).$(VERSION_MINOR)
66 -obj-m := $(MODULE_NAME).o
67 -$(MODULE_NAME)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
68 +obj-m := $(BIN)
69 +$(BIN)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a
71 EXTRA_CFLAGS += -I$(src) -I$(src)/crypto -I$(src)/tpm
73 # do not print "Entering directory ..."
74 MAKEFLAGS += --no-print-directory
76 -all: $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version
77 - @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules
78 +all: $(BIN)
79 +
80 +$(BIN): $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version $(SRCS) $(OBJS)
81 + $(CC) $(CFLAGS) $(OBJS) $(src)/crypto/libgmp.a -o $(BIN)
82 +
83 +%.o: %.c
84 + $(CC) $(CFLAGS) -c $< -o $@
86 install:
87 - @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules_install
88 - test -d /var/tpm || mkdir /var/tpm
89 - test -c /dev/tpm || mknod /dev/tpm c 10 224
90 - chmod 666 /dev/tpm
91 - depmod -a
92 + $(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
94 clean:
95 - @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) clean
96 - rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a
97 + rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS)
99 -dist: $(DISTSRC)
100 - rm -rf $(DISTDIR)
101 - mkdir $(DISTDIR)
102 - cp --parents $(DISTSRC) $(DISTDIR)/
103 - rm -f $(DISTDIR)/crypto/gmp.h
104 - tar -chzf $(DISTDIR).tar.gz $(DISTDIR)
105 - rm -rf $(DISTDIR)
106 +mrproper: clean
107 + rm -f $(BIN)
109 $(src)/crypto/libgmp.a:
110 test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a
111 diff -uprN orig/tpm_emulator-0.2/README vtpm/README
112 --- orig/tpm_emulator-0.2/README 2005-08-17 10:58:36.000000000 -0700
113 +++ vtpm/README 2005-08-17 10:55:52.000000000 -0700
114 @@ -13,7 +13,8 @@ $Id: README 8 2005-01-25 21:11:45Z jmoli
115 Copyright
116 --------------------------------------------------------------------------
117 Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal
118 -Institute of Technology (ETH) Zurich.
119 + Institute of Technology (ETH) Zurich.
120 +Copyright (C) 2005 INTEL Corp
122 This program is free software; you can redistribute it and/or modify
123 it under the terms of the GNU General Public License as published by
124 diff -uprN orig/tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c vtpm/crypto/gmp_kernel_wrapper.c
125 --- orig/tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c 2005-08-17 10:58:36.000000000 -0700
126 +++ vtpm/crypto/gmp_kernel_wrapper.c 2005-08-17 10:55:52.000000000 -0700
127 @@ -1,5 +1,6 @@
128 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
129 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
130 + * Copyright (C) 2005 INTEL Corp
131 *
132 * This module is free software; you can redistribute it and/or modify
133 * it under the terms of the GNU General Public License as published
134 @@ -24,15 +25,10 @@ int __gmp_junk;
135 void __attribute__ ((regparm(0))) __gmp_assert_fail(const char *filename,
136 int linenum, const char *expr)
137 {
138 - panic(KERN_CRIT TPM_MODULE_NAME "%s:%d: GNU MP assertion failed: %s\n",
139 + error("%s:%d: GNU MP assertion failed: %s\n",
140 filename, linenum, expr);
141 }
143 -void __attribute__ ((regparm(0))) abort(void)
144 -{
145 - panic(KERN_CRIT TPM_MODULE_NAME "GNU MP abort() was called\n");
146 -}
147 -
148 /* overwrite GNU MP random functions (used by mpz/millerrabin.c) */
150 void __attribute__ ((regparm(0))) gmp_randinit(gmp_randstate_t rstate,
151 @@ -77,20 +73,19 @@ void __attribute__ ((regparm(0))) mpz_ur
153 void __attribute__ ((regparm(0))) *kernel_allocate(size_t size)
154 {
155 - void *ret = (void*)kmalloc(size, GFP_KERNEL);
156 - if (!ret) panic(KERN_CRIT TPM_MODULE_NAME
157 - "GMP: cannot allocate memory (size=%u)\n", size);
158 + void *ret = (void*)malloc(size);
159 + if (!ret) error("GMP: cannot allocate memory (size=%u)\n", size);
160 return ret;
161 }
163 void __attribute__ ((regparm(0))) *kernel_reallocate(void *oldptr,
164 size_t old_size, size_t new_size)
165 {
166 - void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
167 - if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
168 + void *ret = (void*)malloc(new_size);
169 + if (!ret) error("GMP: Cannot reallocate memory "
170 "(old_size=%u new_size=%u)\n", old_size, new_size);
171 memcpy(ret, oldptr, old_size);
172 - kfree(oldptr);
173 + free(oldptr);
174 return ret;
175 }
177 @@ -99,7 +94,7 @@ void __attribute__ ((regparm(0))) kernel
178 /* overwrite used memory */
179 if (blk_ptr != NULL) {
180 memset(blk_ptr, 0, blk_size);
181 - kfree(blk_ptr);
182 + free(blk_ptr);
183 }
184 }
186 diff -uprN orig/tpm_emulator-0.2/crypto/rsa.c vtpm/crypto/rsa.c
187 --- orig/tpm_emulator-0.2/crypto/rsa.c 2005-08-17 10:58:36.000000000 -0700
188 +++ vtpm/crypto/rsa.c 2005-08-17 10:55:52.000000000 -0700
189 @@ -1,5 +1,6 @@
190 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
191 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
192 + * Copyright (C) 2005 INTEL Corp
193 *
194 * This module is free software; you can redistribute it and/or modify
195 * it under the terms of the GNU General Public License as published
196 @@ -363,7 +364,7 @@ static int encode_message(int type, uint
197 msg[0] = 0x00;
198 get_random_bytes(&msg[1], SHA1_DIGEST_LENGTH);
199 sha1_init(&ctx);
200 - sha1_update(&ctx, "TCPA", 4);
201 + sha1_update(&ctx, (uint8_t *) "TCPA", 4);
202 sha1_final(&ctx, &msg[1 + SHA1_DIGEST_LENGTH]);
203 memset(&msg[1 + 2 * SHA1_DIGEST_LENGTH], 0x00,
204 msg_len - data_len - 2 * SHA1_DIGEST_LENGTH - 2);
205 @@ -411,7 +412,7 @@ static int decode_message(int type, uint
206 mask_generation(&msg[1], SHA1_DIGEST_LENGTH,
207 &msg[1 + SHA1_DIGEST_LENGTH], msg_len - SHA1_DIGEST_LENGTH - 1);
208 sha1_init(&ctx);
209 - sha1_update(&ctx, "TCPA", 4);
210 + sha1_update(&ctx, (uint8_t *) "TCPA", 4);
211 sha1_final(&ctx, &msg[1]);
212 if (memcmp(&msg[1], &msg[1 + SHA1_DIGEST_LENGTH],
213 SHA1_DIGEST_LENGTH) != 0) return -1;
214 diff -uprN orig/tpm_emulator-0.2/linux_module.c vtpm/linux_module.c
215 --- orig/tpm_emulator-0.2/linux_module.c 2005-08-17 10:58:36.000000000 -0700
216 +++ vtpm/linux_module.c 1969-12-31 16:00:00.000000000 -0800
217 @@ -1,163 +0,0 @@
218 -/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
219 - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
220 - *
221 - * This module is free software; you can redistribute it and/or modify
222 - * it under the terms of the GNU General Public License as published
223 - * by the Free Software Foundation; either version 2 of the License,
224 - * or (at your option) any later version.
225 - *
226 - * This module is distributed in the hope that it will be useful,
227 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
228 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
229 - * GNU General Public License for more details.
230 - *
231 - * $Id: linux_module.c 19 2005-05-18 08:29:37Z mast $
232 - */
233 -
234 -#include <linux/module.h>
235 -#include <linux/kernel.h>
236 -#include <linux/init.h>
237 -#include <linux/miscdevice.h>
238 -#include <linux/poll.h>
239 -#include "linux_module.h"
240 -#include "tpm/tpm_emulator.h"
241 -
242 -MODULE_LICENSE("GPL");
243 -MODULE_AUTHOR("Mario Strasser <mast@gmx.net>");
244 -MODULE_DESCRIPTION("Trusted Platform Module (TPM) Emulator");
245 -MODULE_SUPPORTED_DEVICE(TPM_DEVICE_NAME);
246 -
247 -/* module startup parameters */
248 -char *startup = "save";
249 -MODULE_PARM(startup, "s");
250 -MODULE_PARM_DESC(startup, " Sets the startup mode of the TPM. "
251 - "Possible values are 'clear', 'save' (default) and 'deactivated.");
252 -char *storage_file = "/var/tpm/tpm_emulator-1.2.0.1";
253 -MODULE_PARM(storage_file, "s");
254 -MODULE_PARM_DESC(storage_file, " Sets the persistent-data storage "
255 - "file of the TPM.");
256 -
257 -/* TPM lock */
258 -static struct semaphore tpm_mutex;
259 -
260 -/* TPM command response */
261 -static struct {
262 - uint8_t *data;
263 - uint32_t size;
264 -} tpm_response;
265 -
266 -/* module state */
267 -#define STATE_IS_OPEN 0
268 -static uint32_t module_state;
269 -
270 -static int tpm_open(struct inode *inode, struct file *file)
271 -{
272 - debug("%s()", __FUNCTION__);
273 - if (test_and_set_bit(STATE_IS_OPEN, (void*)&module_state)) return -EBUSY;
274 - return 0;
275 -}
276 -
277 -static int tpm_release(struct inode *inode, struct file *file)
278 -{
279 - debug("%s()", __FUNCTION__);
280 - clear_bit(STATE_IS_OPEN, (void*)&module_state);
281 - return 0;
282 -}
283 -
284 -static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)
285 -{
286 - debug("%s(%d)", __FUNCTION__, count);
287 - down(&tpm_mutex);
288 - if (tpm_response.data != NULL) {
289 - count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
290 - count -= copy_to_user(buf, &tpm_response.data[*ppos], count);
291 - *ppos += count;
292 - } else {
293 - count = 0;
294 - }
295 - up(&tpm_mutex);
296 - return count;
297 -}
298 -
299 -static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
300 -{
301 - debug("%s(%d)", __FUNCTION__, count);
302 - down(&tpm_mutex);
303 - *ppos = 0;
304 - if (tpm_response.data != NULL) kfree(tpm_response.data);
305 - if (tpm_handle_command(buf, count, &tpm_response.data,
306 - &tpm_response.size) != 0) {
307 - count = -EILSEQ;
308 - tpm_response.data = NULL;
309 - }
310 - up(&tpm_mutex);
311 - return count;
312 -}
313 -
314 -static int tpm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
315 -{
316 - debug("%s(%d, %ld)", __FUNCTION__, cmd, arg);
317 - return -1;
318 -}
319 -
320 -struct file_operations fops = {
321 - .owner = THIS_MODULE,
322 - .open = tpm_open,
323 - .release = tpm_release,
324 - .read = tpm_read,
325 - .write = tpm_write,
326 - .ioctl = tpm_ioctl,
327 -};
328 -
329 -static struct miscdevice tpm_dev = {
330 - .minor = TPM_DEVICE_MINOR,
331 - .name = TPM_DEVICE_NAME,
332 - .fops = &fops,
333 -};
334 -
335 -int __init init_tpm_module(void)
336 -{
337 - int res = misc_register(&tpm_dev);
338 - if (res != 0) {
339 - error("misc_register() failed for minor %d\n", TPM_DEVICE_MINOR);
340 - return res;
341 - }
342 - /* initialize variables */
343 - sema_init(&tpm_mutex, 1);
344 - module_state = 0;
345 - tpm_response.data = NULL;
346 - /* initialize TPM emulator */
347 - if (!strcmp(startup, "clear")) {
348 - tpm_emulator_init(1);
349 - } else if (!strcmp(startup, "save")) {
350 - tpm_emulator_init(2);
351 - } else if (!strcmp(startup, "deactivated")) {
352 - tpm_emulator_init(3);
353 - } else {
354 - error("invalid startup mode '%s'; must be 'clear', "
355 - "'save' (default) or 'deactivated", startup);
356 - misc_deregister(&tpm_dev);
357 - return -EINVAL;
358 - }
359 - return 0;
360 -}
361 -
362 -void __exit cleanup_tpm_module(void)
363 -{
364 - tpm_emulator_shutdown();
365 - misc_deregister(&tpm_dev);
366 -}
367 -
368 -module_init(init_tpm_module);
369 -module_exit(cleanup_tpm_module);
370 -
371 -uint64_t tpm_get_ticks(void)
372 -{
373 - static struct timespec old_time = {0, 0};
374 - struct timespec new_time = current_kernel_time();
375 - uint64_t ticks = (uint64_t)(old_time.tv_sec - new_time.tv_sec) * 1000000
376 - + (old_time.tv_nsec - new_time.tv_nsec) / 1000;
377 - old_time = new_time;
378 - return (ticks > 0) ? ticks : 1;
379 -}
380 -
381 diff -uprN orig/tpm_emulator-0.2/linux_module.h vtpm/linux_module.h
382 --- orig/tpm_emulator-0.2/linux_module.h 2005-08-17 10:58:36.000000000 -0700
383 +++ vtpm/linux_module.h 2005-08-17 10:55:52.000000000 -0700
384 @@ -1,5 +1,6 @@
385 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
386 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
387 + * Copyright (C) 2005 INTEL Corp
388 *
389 * This module is free software; you can redistribute it and/or modify
390 * it under the terms of the GNU General Public License as published
391 @@ -17,17 +18,22 @@
392 #ifndef _LINUX_MODULE_H_
393 #define _LINUX_MODULE_H_
395 -#include <linux/version.h>
396 -#include <linux/kernel.h>
397 -#include <linux/slab.h>
398 +#include <malloc.h>
399 +#include <stdint.h>
400 +#include <stdio.h>
401 +#include <string.h>
402 #include <linux/types.h>
403 -#include <linux/string.h>
404 -#include <linux/random.h>
405 -#include <linux/time.h>
406 -#include <asm/byteorder.h>
408 -/* module settings */
409 +#include <endian.h>
410 +#define __BYTEORDER_HAS_U64__
411 +#ifdef LITTLE_ENDIAN
412 + #include <linux/byteorder/little_endian.h>
413 +#else
414 + #include <linux/byteorder/big_endian.h>
415 +#endif
417 +/* module settings */
418 +#define min(A,B) ((A)<(B)?(A):(B))
419 #define STR(s) __STR__(s)
420 #define __STR__(s) #s
421 #include "tpm_version.h"
422 @@ -39,32 +45,35 @@
423 /* debug and log output functions */
425 #ifdef DEBUG
426 -#define debug(fmt, ...) printk(KERN_DEBUG "%s %s:%d: Debug: " fmt "\n", \
427 - TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__)
428 +#define debug(fmt, ...) printf("%s:%d: Debug: " fmt "\n", \
429 + __FILE__, __LINE__, ## __VA_ARGS__)
430 #else
431 #define debug(fmt, ...)
432 #endif
433 -#define info(fmt, ...) printk(KERN_INFO "%s %s:%d: Info: " fmt "\n", \
434 - TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__)
435 -#define error(fmt, ...) printk(KERN_ERR "%s %s:%d: Error: " fmt "\n", \
436 - TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__)
437 -#define alert(fmt, ...) printk(KERN_ALERT "%s %s:%d: Alert: " fmt "\n", \
438 - TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__)
439 +#define info(fmt, ...) printf("%s:%d: Info: " fmt "\n", \
440 + __FILE__, __LINE__, ## __VA_ARGS__)
441 +#define error(fmt, ...) printf("%s:%d: Error: " fmt "\n", \
442 + __FILE__, __LINE__, ## __VA_ARGS__)
443 +#define alert(fmt, ...) printf("%s:%d: Alert: " fmt "\n", \
444 + __FILE__, __LINE__, ## __VA_ARGS__)
446 /* memory allocation */
448 static inline void *tpm_malloc(size_t size)
449 {
450 - return kmalloc(size, GFP_KERNEL);
451 + return malloc(size);
452 }
454 static inline void tpm_free(const void *ptr)
455 {
456 - if (ptr != NULL) kfree(ptr);
457 + if (ptr != NULL) free( (void *) ptr);
458 }
460 /* random numbers */
462 +//FIXME;
463 +void get_random_bytes(void *buf, int nbytes);
464 +
465 static inline void tpm_get_random_bytes(void *buf, int nbytes)
466 {
467 get_random_bytes(buf, nbytes);
468 @@ -84,9 +93,9 @@ uint64_t tpm_get_ticks(void);
469 #define CPU_TO_LE16(x) __cpu_to_le16(x)
471 #define BE64_TO_CPU(x) __be64_to_cpu(x)
472 -#define LE64_TO_CPU(x) __be64_to_cpu(x)
473 +#define LE64_TO_CPU(x) __le64_to_cpu(x)
474 #define BE32_TO_CPU(x) __be32_to_cpu(x)
475 -#define LE32_TO_CPU(x) __be32_to_cpu(x)
476 +#define LE32_TO_CPU(x) __le32_to_cpu(x)
477 #define BE16_TO_CPU(x) __be16_to_cpu(x)
478 #define LE16_TO_CPU(x) __le16_to_cpu(x)
480 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_audit.c vtpm/tpm/tpm_audit.c
481 --- orig/tpm_emulator-0.2/tpm/tpm_audit.c 2005-08-17 10:58:36.000000000 -0700
482 +++ vtpm/tpm/tpm_audit.c 2005-08-17 10:55:52.000000000 -0700
483 @@ -1,6 +1,7 @@
484 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
485 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
486 * Swiss Federal Institute of Technology (ETH) Zurich
487 + * Copyright (C) 2005 INTEL Corp
488 *
489 * This module is free software; you can redistribute it and/or modify
490 * it under the terms of the GNU General Public License as published
491 @@ -45,14 +46,14 @@ void tpm_audit_request(TPM_COMMAND_CODE
492 tpmData.permanent.data.auditMonotonicCounter++;
493 }
494 /* update audit digest */
495 - *((UINT16*)&buf[0]) = cpu_to_be16(TPM_TAG_AUDIT_EVENT_IN);
496 - *((UINT32*)&buf[2]) = cpu_to_be32(ordinal);
497 + *((UINT16*)&buf[0]) = CPU_TO_BE16(TPM_TAG_AUDIT_EVENT_IN);
498 + *((UINT32*)&buf[2]) = CPU_TO_BE32(ordinal);
499 sha1_init(&sha1_ctx);
500 sha1_update(&sha1_ctx, req->param, req->paramSize);
501 sha1_final(&sha1_ctx, &buf[6]);
502 - *((UINT16*)&buf[26]) = cpu_to_be16(TPM_TAG_COUNTER_VALUE);
503 + *((UINT16*)&buf[26]) = CPU_TO_BE16(TPM_TAG_COUNTER_VALUE);
504 memset(&buf[30], 0, 4);
505 - *((UINT32*)&buf[34]) = cpu_to_be32(tpmData.permanent.data.auditMonotonicCounter);
506 + *((UINT32*)&buf[34]) = CPU_TO_BE32(tpmData.permanent.data.auditMonotonicCounter);
507 sha1_init(&sha1_ctx);
508 sha1_update(&sha1_ctx, tpmData.stany.data.auditDigest.digest,
509 sizeof(TPM_DIGEST));
510 @@ -70,15 +71,15 @@ void tpm_audit_response(TPM_COMMAND_CODE
511 && (AUDIT_STATUS[ord / 8] & (1 << (ord & 0x07)))) {
512 info("tpm_audit_response()");
513 /* update audit digest */
514 - *((UINT16*)&buf[0]) = cpu_to_be16(TPM_TAG_AUDIT_EVENT_OUT);
515 - *((UINT32*)&buf[2]) = cpu_to_be32(ordinal);
516 + *((UINT16*)&buf[0]) = CPU_TO_BE16(TPM_TAG_AUDIT_EVENT_OUT);
517 + *((UINT32*)&buf[2]) = CPU_TO_BE32(ordinal);
518 sha1_init(&sha1_ctx);
519 sha1_update(&sha1_ctx, rsp->param, rsp->paramSize);
520 sha1_final(&sha1_ctx, &buf[6]);
521 - *((UINT16*)&buf[26]) = cpu_to_be16(TPM_TAG_COUNTER_VALUE);
522 + *((UINT16*)&buf[26]) = CPU_TO_BE16(TPM_TAG_COUNTER_VALUE);
523 memset(&buf[30], 0, 4);
524 - *((UINT32*)&buf[34]) = cpu_to_be32(tpmData.permanent.data.auditMonotonicCounter);
525 - *((UINT32*)&buf[34]) = cpu_to_be32(rsp->result);
526 + *((UINT32*)&buf[34]) = CPU_TO_BE32(tpmData.permanent.data.auditMonotonicCounter);
527 + *((UINT32*)&buf[34]) = CPU_TO_BE32(rsp->result);
528 sha1_init(&sha1_ctx);
529 sha1_update(&sha1_ctx, tpmData.stany.data.auditDigest.digest,
530 sizeof(TPM_DIGEST));
531 @@ -158,7 +159,7 @@ TPM_RESULT TPM_GetAuditDigestSigned(TPM_
532 }
533 memcpy(&buf[0], "\x05\x00ADIG", 6);
534 memcpy(&buf[6], antiReplay->nonce, 20);
535 - *(UINT32*)&buf[26] = cpu_to_be32(buf_size - 30);
536 + *(UINT32*)&buf[26] = CPU_TO_BE32(buf_size - 30);
537 memcpy(&buf[30], auditDigest->digest, 20);
538 ptr = &buf[50];
539 len = buf_size - 50;
540 @@ -198,4 +199,3 @@ TPM_RESULT TPM_SetOrdinalAuditStatus(TPM
541 }
542 return TPM_SUCCESS;
543 }
544 -
545 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_authorization.c vtpm/tpm/tpm_authorization.c
546 --- orig/tpm_emulator-0.2/tpm/tpm_authorization.c 2005-08-17 10:58:36.000000000 -0700
547 +++ vtpm/tpm/tpm_authorization.c 2005-08-17 10:55:52.000000000 -0700
548 @@ -1,6 +1,7 @@
549 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
550 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
551 * Swiss Federal Institute of Technology (ETH) Zurich
552 + * Copyright (C) 2005 INTEL Corp
553 *
554 * This module is free software; you can redistribute it and/or modify
555 * it under the terms of the GNU General Public License as published
556 @@ -268,7 +269,7 @@ TPM_RESULT tpm_verify_auth(TPM_AUTH *aut
557 {
558 hmac_ctx_t ctx;
559 TPM_SESSION_DATA *session;
560 - UINT32 auth_handle = cpu_to_be32(auth->authHandle);
561 + UINT32 auth_handle = CPU_TO_BE32(auth->authHandle);
563 info("tpm_verify_auth(%08x)", auth->authHandle);
564 /* get dedicated authorization session */
565 @@ -316,5 +317,3 @@ void tpm_decrypt_auth_secret(TPM_ENCAUTH
566 for (i = 0; i < sizeof(TPM_SECRET); i++)
567 plainAuth[i] ^= encAuth[i];
568 }
569 -
570 -
571 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_capability.c vtpm/tpm/tpm_capability.c
572 --- orig/tpm_emulator-0.2/tpm/tpm_capability.c 2005-08-17 10:58:36.000000000 -0700
573 +++ vtpm/tpm/tpm_capability.c 2005-08-17 10:55:52.000000000 -0700
574 @@ -1,6 +1,7 @@
575 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
576 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
577 * Swiss Federal Institute of Technology (ETH) Zurich
578 + * Copyright (C) 2005 INTEL Corp
579 *
580 * This module is free software; you can redistribute it and/or modify
581 * it under the terms of the GNU General Public License as published
582 @@ -398,7 +399,7 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL
584 case TPM_CAP_KEY_HANDLE:
585 debug("[TPM_CAP_KEY_HANDLE]");
586 - subCapSize = cpu_to_be32(TPM_RT_KEY);
587 + subCapSize = CPU_TO_BE32(TPM_RT_KEY);
588 return cap_handle(4, (BYTE*)&subCapSize, respSize, resp);
590 case TPM_CAP_CHECK_LOADED:
591 @@ -472,4 +473,3 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL
592 return TPM_BAD_MODE;
593 }
594 }
595 -
596 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_cmd_handler.c vtpm/tpm/tpm_cmd_handler.c
597 --- orig/tpm_emulator-0.2/tpm/tpm_cmd_handler.c 2005-08-17 10:58:36.000000000 -0700
598 +++ vtpm/tpm/tpm_cmd_handler.c 2005-08-17 10:55:52.000000000 -0700
599 @@ -1,6 +1,7 @@
600 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
601 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
602 * Swiss Federal Institute of Technology (ETH) Zurich
603 + * Copyright (C) 2005 INTEL Corp
604 *
605 * This module is free software; you can redistribute it and/or modify
606 * it under the terms of the GNU General Public License as published
607 @@ -26,7 +27,7 @@ static void tpm_compute_in_param_digest(
608 {
609 sha1_ctx_t sha1;
610 UINT32 offset;
611 - UINT32 ord = cpu_to_be32(req->ordinal);
612 + UINT32 ord = CPU_TO_BE32(req->ordinal);
614 /* skip all key-handles at the beginning */
615 switch (req->ordinal) {
616 @@ -82,8 +83,8 @@ static void tpm_compute_in_param_digest(
617 static void tpm_compute_out_param_digest(TPM_COMMAND_CODE ordinal, TPM_RESPONSE *rsp)
618 {
619 sha1_ctx_t sha1;
620 - UINT32 res = cpu_to_be32(rsp->result);
621 - UINT32 ord = cpu_to_be32(ordinal);
622 + UINT32 res = CPU_TO_BE32(rsp->result);
623 + UINT32 ord = CPU_TO_BE32(ordinal);
625 /* compute SHA1 hash */
626 sha1_init(&sha1);
627 @@ -3081,7 +3082,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA
628 hmac_update(&hmac, rsp->auth2->digest, sizeof(rsp->auth2->digest));
629 #if 0
630 if (tpm_get_auth(rsp->auth2->authHandle)->type == TPM_ST_OIAP) {
631 - UINT32 handle = cpu_to_be32(rsp->auth2->authHandle);
632 + UINT32 handle = CPU_TO_BE32(rsp->auth2->authHandle);
633 hmac_update(&hmac, (BYTE*)&handle, 4);
634 }
635 #endif
636 @@ -3096,7 +3097,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA
637 hmac_update(&hmac, rsp->auth1->digest, sizeof(rsp->auth1->digest));
638 #if 0
639 if (tpm_get_auth(rsp->auth1->authHandle)->type == TPM_ST_OIAP) {
640 - UINT32 handle = cpu_to_be32(rsp->auth1->authHandle);
641 + UINT32 handle = CPU_TO_BE32(rsp->auth1->authHandle);
642 hmac_update(&hmac, (BYTE*)&handle, 4);
643 }
644 #endif
645 @@ -3179,7 +3180,9 @@ extern const char *tpm_error_to_string(T
646 static void tpm_execute_command(TPM_REQUEST *req, TPM_RESPONSE *rsp)
647 {
648 TPM_RESULT res;
649 -
650 +
651 + req->tag = (BYTE) req->tag; // VIN HACK!!!
652 +
653 /* setup authorisation as well as response tag and size */
654 memset(rsp, 0, sizeof(*rsp));
655 switch (req->tag) {
656 @@ -3878,4 +3881,3 @@ int tpm_handle_command(const uint8_t *in
657 tpm_free(rsp.param);
658 return 0;
659 }
660 -
661 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_crypto.c vtpm/tpm/tpm_crypto.c
662 --- orig/tpm_emulator-0.2/tpm/tpm_crypto.c 2005-08-17 10:58:36.000000000 -0700
663 +++ vtpm/tpm/tpm_crypto.c 2005-08-17 10:55:52.000000000 -0700
664 @@ -1,6 +1,7 @@
665 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
666 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
667 * Swiss Federal Institute of Technology (ETH) Zurich
668 + * Copyright (C) 2005 INTEL Corp
669 *
670 * This module is free software; you can redistribute it and/or modify
671 * it under the terms of the GNU General Public License as published
672 @@ -106,7 +107,7 @@ TPM_RESULT tpm_sign(TPM_KEY_DATA *key, T
673 /* setup TPM_SIGN_INFO structure */
674 memcpy(&buf[0], "\x05\x00SIGN", 6);
675 memcpy(&buf[6], auth->nonceOdd.nonce, 20);
676 - *(UINT32*)&buf[26] = cpu_to_be32(areaToSignSize);
677 + *(UINT32*)&buf[26] = CPU_TO_BE32(areaToSignSize);
678 memcpy(&buf[30], areaToSign, areaToSignSize);
679 if (rsa_sign(&key->key, RSA_SSA_PKCS1_SHA1,
680 buf, areaToSignSize + 30, *sig)) {
681 @@ -379,4 +380,3 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
682 }
683 return TPM_SUCCESS;
684 }
685 -
686 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_data.c vtpm/tpm/tpm_data.c
687 --- orig/tpm_emulator-0.2/tpm/tpm_data.c 2005-08-17 10:58:36.000000000 -0700
688 +++ vtpm/tpm/tpm_data.c 2005-08-17 10:55:52.000000000 -0700
689 @@ -1,6 +1,7 @@
690 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
691 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
692 * Swiss Federal Institute of Technology (ETH) Zurich
693 + * Copyright (C) 2005 INTEL Corp
694 *
695 * This module is free software; you can redistribute it and/or modify
696 * it under the terms of the GNU General Public License as published
697 @@ -15,9 +16,15 @@
698 * $Id: tpm_data.c 9 2005-04-26 18:15:31Z mast $
699 */
701 +#include <sys/types.h>
702 +#include <sys/stat.h>
703 +#include <fcntl.h>
704 +#include <unistd.h>
705 +
706 #include "tpm_emulator.h"
707 #include "tpm_structures.h"
708 #include "tpm_marshalling.h"
709 +#include "vtpm_manager.h"
711 TPM_DATA tpmData;
713 @@ -28,6 +35,7 @@ BOOL tpm_get_physical_presence(void)
715 void tpm_init_data(void)
716 {
717 +#ifndef TPM_GENERATE_EK
718 /* endorsement key */
719 uint8_t ek_n[] = "\xa8\xdb\xa9\x42\xa8\xf3\xb8\x06\x85\x90\x76\x93\xad\xf7"
720 "\x74\xec\x3f\xd3\x3d\x9d\xe8\x2e\xff\x15\xed\x0e\xce\x5f\x93"
721 @@ -66,6 +74,8 @@ void tpm_init_data(void)
722 "\xd1\xc0\x8b\x5b\xa2\x2e\xa7\x15\xca\x50\x75\x10\x48\x9c\x2b"
723 "\x18\xb9\x67\x8f\x5d\x64\xc3\x28\x9f\x2f\x16\x2f\x08\xda\x47"
724 "\xec\x86\x43\x0c\x80\x99\x07\x34\x0f";
725 +#endif
726 +
727 int i;
728 /* reset all data to NULL, FALSE or 0 */
729 memset(&tpmData, 0, sizeof(tpmData));
730 @@ -85,6 +95,10 @@ void tpm_init_data(void)
731 tpmData.permanent.data.version.revMinor = VERSION_MINOR;
732 /* setup PCR attributes */
733 for (i = 0; i < TPM_NUM_PCR; i++) {
734 + int j;
735 + for (j=0; j < TPM_NUM_LOCALITY; j++) {
736 + tpmData.permanent.data.pcrAttrib[i].pcrExtendLocal[j] = TRUE;
737 + }
738 tpmData.permanent.data.pcrAttrib[i].pcrReset = TRUE;
739 }
740 /* set tick type */
741 @@ -115,49 +129,235 @@ void tpm_release_data(void)
743 #ifdef TPM_STORE_TO_FILE
745 -#include <linux/fs.h>
746 -#include <linux/unistd.h>
747 -#include <asm/uaccess.h>
748 +#include <sys/types.h>
749 +#include <sys/stat.h>
750 +#include <fcntl.h>
751 +
752 + static int vtpm_tx_fh=-1, vtpm_rx_fh=-1;
754 -#define TPM_STORAGE_FILE "/var/tpm/tpm_emulator-1.2." STR(VERSION_MAJOR) "." STR(VERSION_MINOR)
755 +#ifdef VTPM_MUTLI_VM
756 + #define DEV_FE "/dev/tpm"
757 +#else
758 + #define VTPM_RX_FIFO_D "/var/vtpm/fifos/vtpm-to-%d.fifo"
759 + #define VTPM_TX_FIFO "/var/vtpm/fifos/vtpm-from-all.fifo"
760 +
761 + extern int dmi_id;
762 + static char *vtpm_rx_name=NULL;
763 +#endif
765 static int write_to_file(uint8_t *data, size_t data_length)
766 {
767 - int res;
768 - struct file *fp;
769 - mm_segment_t old_fs = get_fs();
770 - fp = filp_open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
771 - if (IS_ERR(fp)) return -1;
772 - set_fs(get_ds());
773 - res = fp->f_op->write(fp, data, data_length, &fp->f_pos);
774 - set_fs(old_fs);
775 - filp_close(fp, NULL);
776 - return (res == data_length) ? 0 : -1;
777 + int res, out_data_size, in_header_size;
778 + BYTE *ptr, *out_data, *in_header;
779 + UINT32 result, len, in_rsp_size;
780 + UINT16 tag = VTPM_TAG_REQ;
781 +
782 + printf("Saving NVM\n");
783 + if (vtpm_tx_fh < 0) {
784 +#ifdef VTPM_MUTLI_VM
785 + vtpm_tx_fh = open(DEV_FE, O_RDWR);
786 +#else
787 + vtpm_tx_fh = open(VTPM_TX_FIFO, O_WRONLY);
788 +#endif
789 + }
790 +
791 + if (vtpm_tx_fh < 0) {
792 + return -1;
793 + }
794 +
795 + // Send request to VTPM Manager to encrypt data
796 +#ifdef VTPM_MUTLI_VM
797 + out_data_size = len = VTPM_COMMAND_HEADER_SIZE_CLT + data_length;
798 +#else
799 + out_data_size = len = VTPM_COMMAND_HEADER_SIZE_SRV + data_length;
800 +#endif
801 +
802 + out_data = ptr = (BYTE *) malloc(len);
803 +
804 + if (ptr == NULL
805 +#ifndef VTPM_MUTLI_VM
806 + || tpm_marshal_UINT32(&ptr, &len, dmi_id)
807 +#endif
808 + || tpm_marshal_UINT16(&ptr, &len, tag)
809 +#ifdef VTPM_MUTLI_VM
810 + || tpm_marshal_UINT32(&ptr, &len, out_data_size)
811 +#else
812 + || tpm_marshal_UINT32(&ptr, &len, out_data_size - sizeof(uint32_t))
813 +#endif
814 + || tpm_marshal_UINT32(&ptr, &len, VTPM_ORD_SAVENVM)
815 + || tpm_marshal_BYTE_ARRAY(&ptr, &len, data, data_length)) {
816 + free(out_data);
817 + return -1;
818 + }
819 +
820 + printf("\tSending SaveNVM Command.\n");
821 + res = write(vtpm_tx_fh, out_data, out_data_size);
822 + free(out_data);
823 + if (res != out_data_size) return -1;
824 +
825 + if (vtpm_rx_fh < 0) {
826 +#ifdef VTPM_MUTLI_VM
827 + vtpm_rx_fh = vtpm_tx_fh
828 +#else
829 + if (vtpm_rx_name == NULL) {
830 + vtpm_rx_name = malloc(10 + strlen(VTPM_RX_FIFO_D));
831 + sprintf(vtpm_rx_name, VTPM_RX_FIFO_D, (uint32_t) dmi_id);
832 + }
833 + vtpm_rx_fh = open(vtpm_rx_name, O_RDONLY);
834 +#endif
835 + }
836 +
837 + if (vtpm_rx_fh < 0) {
838 + return -1;
839 + }
840 +
841 + // Read Header of response so we can get the size & status
842 +#ifdef VTPM_MUTLI_VM
843 + in_header_size = len = VTPM_COMMAND_HEADER_SIZE_CLT;
844 +#else
845 + in_header_size = len = VTPM_COMMAND_HEADER_SIZE_SRV;
846 +#endif
847 + in_header = ptr = malloc(in_header_size);
848 +
849 + printf("\tReading SaveNVM header.\n");
850 + res = read(vtpm_rx_fh, in_header, in_header_size);
851 +
852 + if ( (res != in_header_size)
853 +#ifndef VTPM_MUTLI_VM
854 + || tpm_unmarshal_UINT32(&ptr, &len, (UINT32*)&dmi_id)
855 +#endif
856 + || tpm_unmarshal_UINT16(&ptr, &len, &tag)
857 + || tpm_unmarshal_UINT32(&ptr, &len, &in_rsp_size)
858 + || tpm_unmarshal_UINT32(&ptr, &len, &result) ) {
859 + free(in_header);
860 + return -1;
861 + }
862 + free(in_header);
863 +
864 + if (result != VTPM_SUCCESS) {
865 + return -1;
866 + }
867 +
868 +#ifdef VTPM_MUTLI_VM
869 + close(vtpm_tx_fh); close(vtpm_rx_fh);
870 +#endif
871 +
872 + printf("\tFinishing up SaveNVM\n");
873 + return (0);
874 }
876 static int read_from_file(uint8_t **data, size_t *data_length)
877 {
878 - int res;
879 - struct file *fp;
880 - mm_segment_t old_fs = get_fs();
881 - fp = filp_open(TPM_STORAGE_FILE, O_RDONLY, 0);
882 - if (IS_ERR(fp)) return -1;
883 - *data_length = (size_t)fp->f_dentry->d_inode->i_size;
884 - /* *data_length = i_size_read(fp->f_dentry->d_inode); */
885 - *data = tpm_malloc(*data_length);
886 - if (*data == NULL) {
887 - filp_close(fp, NULL);
888 + int res, out_data_size, in_header_size;
889 + uint8_t *ptr, *out_data, *in_header;
890 + UINT16 tag = VTPM_TAG_REQ;
891 + UINT32 len, in_rsp_size, result;
892 +#ifdef VTPM_MUTLI_VM
893 + int vtpm_rx_fh, vtpm_tx_fh;
894 +#endif
895 +
896 + printf("Loading NVM.\n");
897 + if (vtpm_tx_fh < 0) {
898 +#ifdef VTPM_MUTLI_VM
899 + vtpm_tx_fh = open(DEV_FE, O_RDWR);
900 +#else
901 + vtpm_tx_fh = open(VTPM_TX_FIFO, O_WRONLY);
902 +#endif
903 + }
904 +
905 + if (vtpm_tx_fh < 0) {
906 + return -1;
907 + }
908 +
909 + // Send request to VTPM Manager to encrypt data
910 +#ifdef VTPM_MUTLI_VM
911 + out_data_size = len = VTPM_COMMAND_HEADER_SIZE_CLT;
912 +#else
913 + out_data_size = len = VTPM_COMMAND_HEADER_SIZE_SRV;
914 +#endif
915 + out_data = ptr = (BYTE *) malloc(len);
916 +
917 + if (ptr == NULL
918 +#ifndef VTPM_MUTLI_VM
919 + || tpm_marshal_UINT32(&ptr, &len, dmi_id)
920 +#endif
921 + || tpm_marshal_UINT16(&ptr, &len, tag)
922 +#ifdef VTPM_MUTLI_VM
923 + || tpm_marshal_UINT32(&ptr, &len, out_data_size)
924 +#else
925 + || tpm_marshal_UINT32(&ptr, &len, out_data_size - sizeof(uint32_t))
926 +#endif
927 + || tpm_marshal_UINT32(&ptr, &len, VTPM_ORD_LOADNVM)) {
928 + free(out_data);
929 return -1;
930 }
931 - set_fs(get_ds());
932 - res = fp->f_op->read(fp, *data, *data_length, &fp->f_pos);
933 - set_fs(old_fs);
934 - filp_close(fp, NULL);
935 +
936 + printf("\tSending LoadNVM command\n");
937 + res = write(vtpm_tx_fh, out_data, out_data_size);
938 + free(out_data);
939 + if (res != out_data_size) return -1;
940 +
941 + if (vtpm_rx_fh < 0) {
942 +#ifdef VTPM_MUTLI_VM
943 + vtpm_rx_fh = vtpm_tx_fh;
944 +#else
945 + if (vtpm_rx_name == NULL) {
946 + vtpm_rx_name = malloc(10 + strlen(VTPM_RX_FIFO_D));
947 + sprintf(vtpm_rx_name, VTPM_RX_FIFO_D, (uint32_t) dmi_id);
948 + }
949 + vtpm_rx_fh = open(vtpm_rx_name, O_RDONLY);
950 +#endif
951 + }
952 +
953 + if (vtpm_rx_fh < 0) {
954 + return -1;
955 + }
956 +
957 + // Read Header of response so we can get the size & status
958 +#ifdef VTPM_MUTLI_VM
959 + in_header_size = len = VTPM_COMMAND_HEADER_SIZE_CLT;
960 +#else
961 + in_header_size = len = VTPM_COMMAND_HEADER_SIZE_SRV;
962 +#endif
963 + in_header = ptr = malloc(in_header_size);
964 +
965 + printf("\tReading LoadNVM header\n");
966 + res = read(vtpm_rx_fh, in_header, in_header_size);
967 +
968 + if ( (res != in_header_size)
969 +#ifndef VTPM_MUTLI_VM
970 + || tpm_unmarshal_UINT32(&ptr, &len, (UINT32*)&dmi_id)
971 +#endif
972 + || tpm_unmarshal_UINT16(&ptr, &len, &tag)
973 + || tpm_unmarshal_UINT32(&ptr, &len, &in_rsp_size)
974 + || tpm_unmarshal_UINT32(&ptr, &len, &result) ) {
975 + free(in_header);
976 + return -1;
977 + }
978 + free(in_header);
979 +
980 + if (result != VTPM_SUCCESS) {
981 + return -1;
982 + }
983 +
984 + // Read Encrypted data from VTPM Manager
985 + *data_length = in_rsp_size - VTPM_COMMAND_HEADER_SIZE_CLT;
986 + *data = (uint8_t *) malloc(*data_length);
987 +
988 + printf("\tReading clear data from LoadNVM.\n");
989 + res = read(vtpm_rx_fh, *data, *data_length);
990 +#ifdef VTPM_MUTLI_VM
991 + close(vtpm_rx_fh);close(vtpm_tx_fh);
992 +#endif
993 +
994 + printf("\tReturing from loading NVM\n");
995 if (res != *data_length) {
996 - tpm_free(*data);
997 - return -1;
998 + free(*data);
999 + return -1;
1000 + } else {
1001 + return 0;
1003 - return 0;
1007 #else
1008 @@ -231,7 +431,6 @@ int tpm_restore_permanent_data(void)
1010 int tpm_erase_permanent_data(void)
1012 - int res = write_to_file("", 0);
1013 + int res = write_to_file((uint8_t*)"", 0);
1014 return res;
1017 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_deprecated.c vtpm/tpm/tpm_deprecated.c
1018 --- orig/tpm_emulator-0.2/tpm/tpm_deprecated.c 2005-08-17 10:58:36.000000000 -0700
1019 +++ vtpm/tpm/tpm_deprecated.c 2005-08-17 10:55:52.000000000 -0700
1020 @@ -1,6 +1,7 @@
1021 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1022 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1023 * Swiss Federal Institute of Technology (ETH) Zurich
1024 + * Copyright (C) 2005 INTEL Corp
1026 * This module is free software; you can redistribute it and/or modify
1027 * it under the terms of the GNU General Public License as published
1028 @@ -50,7 +51,7 @@ TPM_RESULT TPM_SaveKeyContext(TPM_KEY_HA
1029 BYTE *ptr;
1030 UINT32 len;
1031 info("TPM_SaveKeyContext()");
1032 - res = TPM_SaveContext(keyHandle, TPM_RT_KEY, "SaveKeyContext..",
1033 + res = TPM_SaveContext(keyHandle, TPM_RT_KEY, (BYTE*)"SaveKeyContext..",
1034 keyContextSize, &contextBlob);
1035 if (res != TPM_SUCCESS) return res;
1036 len = *keyContextSize;
1037 @@ -82,7 +83,7 @@ TPM_RESULT TPM_SaveAuthContext(TPM_AUTHH
1038 BYTE *ptr;
1039 UINT32 len;
1040 info("TPM_SaveAuthContext()");
1041 - res = TPM_SaveContext(authHandle, TPM_RT_KEY, "SaveAuthContext.",
1042 + res = TPM_SaveContext(authHandle, TPM_RT_KEY, (BYTE*)"SaveAuthContext.",
1043 authContextSize, &contextBlob);
1044 if (res != TPM_SUCCESS) return res;
1045 len = *authContextSize;
1046 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_emulator.h vtpm/tpm/tpm_emulator.h
1047 --- orig/tpm_emulator-0.2/tpm/tpm_emulator.h 2005-08-17 10:58:36.000000000 -0700
1048 +++ vtpm/tpm/tpm_emulator.h 2005-08-17 10:55:52.000000000 -0700
1049 @@ -1,5 +1,6 @@
1050 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1051 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1052 + * Copyright (C) 2005 INTEL Corp
1054 * This module is free software; you can redistribute it and/or modify
1055 * it under the terms of the GNU General Public License as published
1056 @@ -22,7 +23,8 @@
1057 /* TPM configuration */
1058 #define TPM_STORE_TO_FILE 1
1059 #undef TPM_STRONG_PERSISTENCE
1060 -#undef TPM_GENERATE_EK
1061 +//#undef TPM_GENERATE_EK
1062 +#define TPM_GENERATE_EK
1064 /**
1065 * tpm_emulator_init - initialises and starts the TPM emulator
1066 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_integrity.c vtpm/tpm/tpm_integrity.c
1067 --- orig/tpm_emulator-0.2/tpm/tpm_integrity.c 2005-08-17 10:58:36.000000000 -0700
1068 +++ vtpm/tpm/tpm_integrity.c 2005-08-17 10:55:52.000000000 -0700
1069 @@ -1,6 +1,7 @@
1070 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1071 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1072 * Swiss Federal Institute of Technology (ETH) Zurich
1073 + * Copyright (C) 2005 INTEL Corp
1075 * This module is free software; you can redistribute it and/or modify
1076 * it under the terms of the GNU General Public License as published
1077 @@ -194,4 +195,3 @@ TPM_RESULT tpm_verify_pcr(TPM_KEY_DATA *
1079 return TPM_SUCCESS;
1082 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_structures.h vtpm/tpm/tpm_structures.h
1083 --- orig/tpm_emulator-0.2/tpm/tpm_structures.h 2005-08-17 10:58:36.000000000 -0700
1084 +++ vtpm/tpm/tpm_structures.h 2005-08-17 10:55:52.000000000 -0700
1085 @@ -1,6 +1,7 @@
1086 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1087 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1088 * Swiss Federal Institute of Technology (ETH) Zurich
1089 + * Copyright (C) 2005 INTEL Corp
1091 * This module is free software; you can redistribute it and/or modify
1092 * it under the terms of the GNU General Public License as published
1093 @@ -18,7 +19,7 @@
1094 #ifndef _TPM_STRUCTURES_H_
1095 #define _TPM_STRUCTURES_H_
1097 -#include <linux/types.h>
1098 +//#include <linux/types.h>
1099 #include "crypto/rsa.h"
1101 /*
1102 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_testing.c vtpm/tpm/tpm_testing.c
1103 --- orig/tpm_emulator-0.2/tpm/tpm_testing.c 2005-08-17 10:58:36.000000000 -0700
1104 +++ vtpm/tpm/tpm_testing.c 2005-08-17 10:55:52.000000000 -0700
1105 @@ -1,6 +1,7 @@
1106 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1107 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1108 * Swiss Federal Institute of Technology (ETH) Zurich
1109 + * Copyright (C) 2005 INTEL Corp
1111 * This module is free software; you can redistribute it and/or modify
1112 * it under the terms of the GNU General Public License as published
1113 @@ -95,24 +96,24 @@ static int tpm_test_sha1(void)
1114 struct {
1115 uint8_t *data; uint32_t repetitions; uint8_t *digest;
1116 } test_cases[] = {{
1117 - "abc", 1,
1118 - "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D"
1119 + (uint8_t*)"abc", 1,
1120 + (uint8_t*)"\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D"
1121 }, {
1122 - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
1123 - "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1"
1124 + (uint8_t*)"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
1125 + (uint8_t*)"\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1"
1126 }, {
1127 - "a", 1000000,
1128 - "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F"
1129 + (uint8_t*)"a", 1000000,
1130 + (uint8_t*)"\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F"
1131 }, {
1132 - "0123456701234567012345670123456701234567012345670123456701234567", 10,
1133 - "\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52"
1134 + (uint8_t*)"0123456701234567012345670123456701234567012345670123456701234567", 10,
1135 + (uint8_t*)"\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52"
1136 }};
1138 debug("tpm_test_sha1()");
1139 for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
1140 sha1_init(&ctx);
1141 for (j = 0; j < test_cases[i].repetitions; j++)
1142 - sha1_update(&ctx, test_cases[i].data, strlen(test_cases[i].data));
1143 + sha1_update(&ctx, test_cases[i].data, strlen((char*)test_cases[i].data));
1144 sha1_final(&ctx, digest);
1145 if (memcmp(digest, test_cases[i].digest, SHA1_DIGEST_LENGTH) != 0) return -1;
1147 @@ -128,41 +129,41 @@ static int tpm_test_hmac(void)
1148 struct {
1149 uint8_t *key, key_len, *data, data_len, *digest;
1150 } test_cases[] = {{
1151 - "\x0b", 20, "Hi There", 8,
1152 - "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00"
1153 + (uint8_t*)"\x0b", 20, (uint8_t*)"Hi There", 8,
1154 + (uint8_t*)"\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00"
1155 }, {
1156 - "Jefe", 4, "what do ya want for nothing?", 28,
1157 - "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79"
1158 + (uint8_t*)"Jefe", 4, (uint8_t*)"what do ya want for nothing?", 28,
1159 + (uint8_t*)"\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79"
1160 }, {
1161 - "\xaa", 20, "\xdd", 50,
1162 - "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3"
1163 + (uint8_t*)"\xaa", 20, (uint8_t*)"\xdd", 50,
1164 + (uint8_t*)"\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3"
1165 }, {
1166 - "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1167 - "\x15\x16\x17\x18\x19", 25, "\xcd", 50,
1168 - "\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda"
1169 + (uint8_t*)"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1170 + "\x15\x16\x17\x18\x19", 25, (uint8_t*)"\xcd", 50,
1171 + (uint8_t*)"\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda"
1172 }, {
1173 - "\x0c", 20, "Test With Truncation", 20,
1174 - "\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04"
1175 + (uint8_t*)"\x0c", 20, (uint8_t*)"Test With Truncation", 20,
1176 + (uint8_t*)"\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04"
1177 }, {
1178 - "\xaa", 80, "Test Using Larger Than Block-Size Key - Hash Key First", 54,
1179 - "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12"
1180 + (uint8_t*)"\xaa", 80, (uint8_t*)"Test Using Larger Than Block-Size Key - Hash Key First", 54,
1181 + (uint8_t*)"\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12"
1182 }, {
1183 - "\xaa", 80,
1184 - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73,
1185 - "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91"
1186 + (uint8_t*)"\xaa", 80,
1187 + (uint8_t*)"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73,
1188 + (uint8_t*)"\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91"
1189 }};
1191 debug("tpm_test_hmac()");
1192 for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
1193 - if (strlen(test_cases[i].key) < test_cases[i].key_len) {
1194 + if (strlen((char*)test_cases[i].key) < test_cases[i].key_len) {
1195 uint8_t key[test_cases[i].key_len];
1196 memset(key, test_cases[i].key[0], test_cases[i].key_len);
1197 hmac_init(&ctx, key, test_cases[i].key_len);
1198 } else {
1199 hmac_init(&ctx, test_cases[i].key, test_cases[i].key_len);
1201 - for (j = 0; j < test_cases[i].data_len; j += strlen(test_cases[i].data)) {
1202 - hmac_update(&ctx, test_cases[i].data, strlen(test_cases[i].data));
1203 + for (j = 0; j < test_cases[i].data_len; j += strlen((char*)test_cases[i].data)) {
1204 + hmac_update(&ctx, test_cases[i].data, strlen((char*)test_cases[i].data));
1206 hmac_final(&ctx, digest);
1207 if (memcmp(digest, test_cases[i].digest, SHA1_DIGEST_LENGTH) != 0) return -1;
1208 @@ -173,9 +174,9 @@ static int tpm_test_hmac(void)
1209 static int tpm_test_rsa_EK(void)
1211 int res = 0;
1212 - char *data = "RSA PKCS #1 v1.5 Test-String";
1213 + uint8_t *data = (uint8_t*)"RSA PKCS #1 v1.5 Test-String";
1214 uint8_t buf[256];
1215 - size_t buf_len, data_len = strlen(data);
1216 + size_t buf_len, data_len = strlen((char*)data);
1217 rsa_private_key_t priv_key;
1218 rsa_public_key_t pub_key;
1220 diff -uprN orig/tpm_emulator-0.2/tpm/tpm_ticks.c vtpm/tpm/tpm_ticks.c
1221 --- orig/tpm_emulator-0.2/tpm/tpm_ticks.c 2005-08-17 10:58:36.000000000 -0700
1222 +++ vtpm/tpm/tpm_ticks.c 2005-08-17 10:55:52.000000000 -0700
1223 @@ -1,6 +1,7 @@
1224 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1225 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
1226 * Swiss Federal Institute of Technology (ETH) Zurich
1227 + * Copyright (C) 2005 INTEL Corp
1229 * This module is free software; you can redistribute it and/or modify
1230 * it under the terms of the GNU General Public License as published
1231 @@ -37,9 +38,7 @@ TPM_RESULT TPM_SetTickType(TPM_TICKTYPE
1232 TPM_RESULT TPM_GetTicks(TPM_CURRENT_TICKS *currentTime)
1234 info("TPM_GetTicks()");
1235 - memcpy(currentTime, &tpmData.stany.data.currentTicks,
1236 - sizeof(TPM_CURRENT_TICKS));
1237 - return TPM_SUCCESS;
1238 + return TPM_DISABLED_CMD;
1241 TPM_RESULT TPM_TickStampBlob(TPM_KEY_HANDLE keyHandle, TPM_NONCE *antiReplay,
1242 @@ -47,61 +46,12 @@ TPM_RESULT TPM_TickStampBlob(TPM_KEY_HAN
1243 TPM_CURRENT_TICKS *currentTicks,
1244 UINT32 *sigSize, BYTE **sig)
1246 - TPM_RESULT res;
1247 - TPM_KEY_DATA *key;
1248 - BYTE *info, *p;
1249 - UINT32 info_length, length;
1250 info("TPM_TickStampBlob()");
1251 - /* get key */
1252 - key = tpm_get_key(keyHandle);
1253 - if (key == NULL) return TPM_INVALID_KEYHANDLE;
1254 - /* verify authorization */
1255 - res = tpm_verify_auth(auth1, key->usageAuth, keyHandle);
1256 - if (res != TPM_SUCCESS) return res;
1257 - if (key->keyUsage != TPM_KEY_SIGNING && key->keyUsage != TPM_KEY_LEGACY
1258 - && key->keyUsage != TPM_KEY_IDENTITY) return TPM_INVALID_KEYUSAGE;
1259 - /* get current ticks */
1260 - TPM_GetTicks(currentTicks);
1261 - /* sign data using signature scheme PKCS1_SHA1 and TPM_SIGN_INFO container */
1262 - *sigSize = key->key.size >> 3;
1263 - *sig = tpm_malloc(*sigSize);
1264 - if (*sig == NULL) return TPM_FAIL;
1265 - /* setup TPM_SIGN_INFO structure */
1266 - info_length = 30 + sizeof(TPM_DIGEST) + sizeof_TPM_CURRENT_TICKS(currentTicks);
1267 - info = tpm_malloc(info_length);
1268 - if (info == NULL) {
1269 - tpm_free(*sig);
1270 - return TPM_FAIL;
1271 - }
1272 - memcpy(&info[0], "\x05\x00TSTP", 6);
1273 - memcpy(&info[6], antiReplay->nonce, 20);
1274 - *(UINT32*)&info[26] = cpu_to_be32(20
1275 - + sizeof_TPM_CURRENT_TICKS(currentTicks));
1276 - memcpy(&info[30], digestToStamp->digest, sizeof(TPM_DIGEST));
1277 - p = &info[30 + sizeof(TPM_DIGEST)];
1278 - length = sizeof_TPM_CURRENT_TICKS(currentTicks);
1279 - if (tpm_marshal_TPM_CURRENT_TICKS(&p, &length, currentTicks)
1280 - || rsa_sign(&key->key, RSA_SSA_PKCS1_SHA1, info, info_length, *sig)) {
1281 - tpm_free(*sig);
1282 - tpm_free(info);
1283 - return TPM_FAIL;
1284 - }
1285 - return TPM_SUCCESS;
1286 + return TPM_DISABLED_CMD;
1289 void tpm_update_ticks(void)
1291 - if (tpmData.stany.data.currentTicks.tag == 0) {
1292 - tpmData.stany.data.currentTicks.tag = TPM_TAG_CURRENT_TICKS;
1293 - tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks();
1294 - tpmData.stany.data.currentTicks.tickType = tpmData.permanent.data.tickType;
1295 - tpm_get_random_bytes(tpmData.stany.data.currentTicks.tickNonce.nonce,
1296 - sizeof(TPM_NONCE));
1297 - tpmData.stany.data.currentTicks.tickRate = 1;
1298 - tpmData.stany.data.currentTicks.tickSecurity = TICK_SEC_NO_CHECK;
1299 - } else {
1300 - tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks();
1301 - }
1305 diff -uprN orig/tpm_emulator-0.2/tpm/vtpm_manager.h vtpm/tpm/vtpm_manager.h
1306 --- orig/tpm_emulator-0.2/tpm/vtpm_manager.h 1969-12-31 16:00:00.000000000 -0800
1307 +++ vtpm/tpm/vtpm_manager.h 2005-08-17 10:55:52.000000000 -0700
1308 @@ -0,0 +1,126 @@
1309 +// ===================================================================
1310 +//
1311 +// Copyright (c) 2005, Intel Corp.
1312 +// All rights reserved.
1313 +//
1314 +// Redistribution and use in source and binary forms, with or without
1315 +// modification, are permitted provided that the following conditions
1316 +// are met:
1317 +//
1318 +// * Redistributions of source code must retain the above copyright
1319 +// notice, this list of conditions and the following disclaimer.
1320 +// * Redistributions in binary form must reproduce the above
1321 +// copyright notice, this list of conditions and the following
1322 +// disclaimer in the documentation and/or other materials provided
1323 +// with the distribution.
1324 +// * Neither the name of Intel Corporation nor the names of its
1325 +// contributors may be used to endorse or promote products derived
1326 +// from this software without specific prior written permission.
1327 +//
1328 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1329 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1330 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1331 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1332 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1333 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1334 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1335 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1336 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1337 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1338 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
1339 +// OF THE POSSIBILITY OF SUCH DAMAGE.
1340 +// ===================================================================
1341 +//
1342 +// vtpm_manager.h
1343 +//
1344 +// Public Interface header for VTPM Manager
1345 +//
1346 +// ==================================================================
1348 +#ifndef __VTPM_MANAGER_H__
1349 +#define __VTPM_MANAGER_H__
1351 +#define VTPM_TAG_REQ 0x01c1
1352 +#define VTPM_TAG_RSP 0x01c4
1353 +#define COMMAND_BUFFER_SIZE 4096
1355 +// Header sizes. Note Header MAY include the DMI
1356 +#define VTPM_COMMAND_HEADER_SIZE_SRV ( sizeof(UINT32) + sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
1357 +#define VTPM_COMMAND_HEADER_SIZE_CLT ( sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
1359 +//************************ Command Codes ****************************
1360 +#define VTPM_ORD_OPEN 1 // ULM Creates New DMI
1361 +#define VTPM_ORD_CLOSE 2 // ULM Closes a DMI
1362 +#define VTPM_ORD_DELETE 3 // ULM Permemently Deletes DMI
1363 +#define VTPM_ORD_SAVENVM 4 // DMI requests Secrets Unseal
1364 +#define VTPM_ORD_LOADNVM 5 // DMI requests Secrets Saved
1365 +#define VTPM_ORD_TPMCOMMAND 6 // DMI issues HW TPM Command
1367 +//************************ Return Codes ****************************
1368 +#define VTPM_SUCCESS 0
1369 +#define VTPM_FAIL 1
1370 +#define VTPM_UNSUPPORTED 2
1371 +#define VTPM_FORBIDDEN 3
1372 +#define VTPM_RESTORE_CONTEXT_FAILED 4
1373 +#define VTPM_INVALID_REQUEST 5
1375 +/******************* Command Parameter API *************************
1377 +VTPM Command Format
1378 + dmi: 4 bytes // Source of message.
1379 + // WARNING: This is prepended by the channel.
1380 + // Thus it is received by VTPM Manager,
1381 + // but not sent by DMI
1382 + tpm tag: 2 bytes
1383 + command size: 4 bytes // Size of command including header but not DMI
1384 + ord: 4 bytes // Command ordinal above
1385 + parameters: size - 10 bytes // Command Parameter
1387 +VTPM Response Format
1388 + tpm tag: 2 bytes
1389 + response_size: 4 bytes
1390 + status: 4 bytes
1391 + parameters: size - 10 bytes
1394 +VTPM_Open:
1395 + Input Parameters:
1396 + Domain_type: 1 byte
1397 + domain_id: 4 bytes
1398 + instance_id: 4 bytes
1399 + Output Parameters:
1400 + None
1402 +VTPM_Close
1403 + Input Parameters:
1404 + instance_id: 4 bytes
1405 + Output Parameters:
1406 + None
1408 +VTPM_Delete
1409 + Input Parameters:
1410 + instance_id: 4 bytes
1411 + Output Parameters:
1412 + None
1414 +VTPM_SaveNVM
1415 + Input Parameters:
1416 + data: n bytes (Header indicates size of data)
1417 + Output Parameters:
1418 + None
1420 +VTPM_LoadNVM
1421 + Input Parameters:
1422 + None
1423 + Output Parameters:
1424 + data: n bytes (Header indicates size of data)
1426 +VTPM_TPMCommand
1427 + Input Parameters:
1428 + TPM Command Byte Stream: n bytes
1429 + Output Parameters:
1430 + TPM Reponse Byte Stream: n bytes
1432 +*********************************************************************/
1434 +#endif //_VTPM_MANAGER_H_
1435 diff -uprN orig/tpm_emulator-0.2/tpmd.c vtpm/tpmd.c
1436 --- orig/tpm_emulator-0.2/tpmd.c 1969-12-31 16:00:00.000000000 -0800
1437 +++ vtpm/tpmd.c 2005-08-17 10:55:52.000000000 -0700
1438 @@ -0,0 +1,207 @@
1439 +/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
1440 + * Copyright (C) 2005 INTEL Corp
1441 + *
1442 + * This module is free software; you can redistribute it and/or modify
1443 + * it under the terms of the GNU General Public License as published
1444 + * by the Free Software Foundation; either version 2 of the License,
1445 + * or (at your option) any later version.
1446 + *
1447 + * This module is distributed in the hope that it will be useful,
1448 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1449 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1450 + * GNU General Public License for more details.
1451 + *
1452 + */
1454 +#include <stdio.h>
1455 +#include <stdlib.h>
1456 +#include <unistd.h>
1457 +#include <string.h>
1458 +#include <sys/types.h>
1459 +#include <sys/stat.h>
1460 +#include <fcntl.h>
1461 +#include <sys/time.h>
1463 +#include "tpm_emulator.h"
1464 +#include "vtpm_manager.h"
1466 +#ifdef VTPM_MULTI_VM
1467 + #define DEV_BE "/dev/vtpm"
1468 +#else
1469 + #define GUEST_RX_FIFO_D "/var/vtpm/fifos/guest-to-%d.fifo"
1470 + #define GUEST_TX_FIFO "/var/vtpm/fifos/guest-from-all.fifo"
1472 + int dmi_id;
1473 +#endif
1475 +#define BUFFER_SIZE 2048
1477 +static uint8_t ctrl_msg[] = { 0, 0, 0, 0, // destination
1478 + 1, 193, // VTPM_TAG
1479 + 0, 0, 0, 10, // Size
1480 + 0, 0, 0, 0}; // TPM_SUCCESS
1483 +static int devurandom=0;
1486 +void get_random_bytes(void *buf, int nbytes) {
1488 + if (devurandom == 0) {
1489 + devurandom = open("/dev/urandom", O_RDONLY);
1490 + }
1492 + if (read(devurandom, buf, nbytes) != nbytes) {
1493 + printf("Can't get random number.\n");
1494 + exit(-1);
1495 + }
1496 +}
1498 +uint64_t tpm_get_ticks(void)
1499 +{
1500 + //struct timeval tv;
1501 + //int gettimeofday(&tv, struct timezone *tz);
1502 + return 0;
1503 +}
1505 +int main(int argc, char **argv)
1506 +{
1507 + uint8_t in[BUFFER_SIZE], *out, *addressed_out;
1508 + uint32_t out_size;
1509 + int in_size, written ;
1510 + int i, guest_id=-1;
1512 + int vtpm_tx_fh=-1, vtpm_rx_fh=-1;
1513 +#ifdef VTPM_MULTI_VM
1514 + if (argc < 2) {
1515 + printf("Usage: tpmd clear|save|deactivated\n" );
1516 +#else
1517 + if (argc < 3) {
1518 + printf("Usage: tpmd clear|save|deactivated vtpmid\n" );
1519 +#endif
1520 + return -1;
1521 + }
1523 +#ifndef VTPM_MULTI_VM
1524 + dmi_id = atoi(argv[2]);
1525 +#endif
1527 + /* initialize TPM emulator */
1528 + if (!strcmp(argv[1], "clear")) {
1529 + printf("Initializing tpm: %s\n", argv[1]);
1530 + tpm_emulator_init(1);
1531 + } else if (!strcmp(argv[1], "save")) {
1532 + printf("Initializing tpm: %s\n", argv[1]);
1533 + tpm_emulator_init(2);
1534 + } else if (!strcmp(argv[1], "deactivated")) {
1535 + printf("Initializing tpm: %s\n", argv[1]);
1536 + tpm_emulator_init(3);
1537 + } else {
1538 + printf("invalid startup mode '%s'; must be 'clear', "
1539 + "'save' (default) or 'deactivated", argv[1]);
1540 + return -1;
1541 + }
1543 + char *guest_rx_file = malloc(10 + strlen(GUEST_RX_FIFO_D));
1544 + sprintf(guest_rx_file, GUEST_RX_FIFO_D, (uint32_t) dmi_id);
1546 + while (1) {
1547 +abort_command:
1548 + if (vtpm_rx_fh < 0) {
1549 +#ifdef VTPM_MUTLI_VM
1550 + vtpm_rx_fh = open(DEV_BE, O_RDWR);
1551 +#else
1552 + vtpm_rx_fh = open(guest_rx_file, O_RDONLY);
1553 +#endif
1554 + }
1556 + if (vtpm_rx_fh < 0) {
1557 + printf("ERROR: failed to open devices to listen to guest.\n");
1558 + return -1;
1559 + }
1561 + in_size = read(vtpm_rx_fh, in, BUFFER_SIZE);
1562 + if (in_size < 6) { // Magic size of minium TPM command
1563 + printf("Recv[%d] to small: 0x", in_size);
1564 + if (in_size <= 0) {
1565 + close(vtpm_rx_fh);
1566 + vtpm_rx_fh = -1;
1567 + goto abort_command;
1568 + }
1569 + } else {
1570 + printf("Recv[%d]: 0x", in_size);
1571 + for (i=0; i< in_size; i++)
1572 + printf("%x ", in[i]);
1573 + printf("\n");
1574 + }
1576 + if (guest_id == -1) {
1577 + guest_id = *((uint32_t *) in);
1578 + *((uint32_t *) ctrl_msg) = *((uint32_t *) in);
1579 + } else {
1580 + if (guest_id != *((uint32_t *) in) ) {
1581 + printf("WARNING: More than one guest attached\n");
1582 + }
1583 + }
1585 + if (vtpm_tx_fh < 0) {
1586 +#ifdef VTPM_MUTLI_VM
1587 + vtpm_tx_fh = open(DEV_BE, O_RDWR);
1588 + vtpm_rx_fh = vtpm_tx_fh;
1589 +#else
1590 + vtpm_tx_fh = open(GUEST_TX_FIFO, O_WRONLY);
1591 +#endif
1592 + }
1594 + if (vtpm_tx_fh < 0) {
1595 + printf("ERROR: failed to open devices to respond to guest.\n");
1596 + return -1;
1597 + }
1599 + // Handle command, but we need to skip the identifier
1600 + if ( BE16_TO_CPU( ((uint16_t *) in)[2] ) == VTPM_TAG_REQ ) { // Control message from xend
1601 + // This DM doesn't really care about ctrl messages. Just ACK the message
1602 + written = write(vtpm_tx_fh, ctrl_msg, sizeof(ctrl_msg));
1604 + if (written != sizeof(ctrl_msg)) {
1605 + printf("ERROR: Part of response not written %d/%d.\n", written, sizeof(ctrl_msg));
1606 + } else {
1607 + printf("Send Ctrl Message confermation\n");
1608 + }
1609 + } else { // Message from Guest
1610 + if (tpm_handle_command(in + sizeof(uint32_t), in_size - sizeof(uint32_t), &out, &out_size) != 0) {
1611 + printf("ERROR: Handler Failed.\n");
1612 + }
1614 + addressed_out = (uint8_t *) tpm_malloc(sizeof(uint32_t) + out_size);
1615 + *(uint32_t *) addressed_out = *(uint32_t *) in;
1616 + memcpy(addressed_out + sizeof(uint32_t), out, out_size);
1618 + written = write(vtpm_tx_fh, addressed_out, out_size + sizeof(uint32_t));
1620 + if (written != out_size + sizeof(uint32_t)) {
1621 + printf("ERROR: Part of response not written %d/%d.\n", written, out_size);
1622 + for (i=0; i< out_size+ sizeof(uint32_t); i++)
1623 + printf("%x ", addressed_out[i]);
1624 + printf("\n");
1625 + } else {
1626 + printf("Sent[%d]: ", out_size + sizeof(uint32_t));
1627 + for (i=0; i< out_size+ sizeof(uint32_t); i++)
1628 + printf("%x ", addressed_out[i]);
1629 + printf("\n");
1630 + }
1631 + tpm_free(out);
1632 + tpm_free(addressed_out);
1633 + }
1635 + } // loop
1637 + tpm_emulator_shutdown();
1639 + close(vtpm_tx_fh);
1640 +#ifndef VTPM_MUTLI_VM
1641 + close(vtpm_rx_fh);
1642 + free (guest_rx_file);
1643 +#endif
1645 +}