debuggers.hg

annotate tools/vtpm/tpm_emulator.patch @ 22848:6341fe0f4e5a

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