source:
trunk/packages/xen-3.1/xen-3.1/tools/vtpm/tpm_emulator.patch
@
34
Last change on this file since 34 was 34, checked in by hartmans, 18 years ago | |
---|---|
|
|
File size: 71.8 KB |
-
AUTHORS
diff -uprN orig/tpm_emulator-0.4/AUTHORS tpm_emulator/AUTHORS
old new 1 1 Mario Strasser <mast@gmx.net> 2 2 Heiko Stamer <stamer@gaos.org> [DAA] 3 INTEL Corp <> [Dropped to Ring3] -
ChangeLog
diff -uprN orig/tpm_emulator-0.4/ChangeLog tpm_emulator/ChangeLog
old new 1 ????-??-?? Intel Corp 2 * Moved module out of kernel to run as a ring 3 app 3 1 4 2006-06-23 Mario Strasser <mast@gmx.net> 2 5 * tpm_startup.c: behaviour of ST_CLEAR and storage of 3 6 persistent data adapted -
crypto/gmp_kernel_wrapper.c
diff -uprN orig/tpm_emulator-0.4/crypto/gmp_kernel_wrapper.c tpm_emulator/crypto/gmp_kernel_wrapper.c
old new 1 1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 2 2 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3 * Copyright (C) 2005 INTEL Corp 3 4 * 4 5 * This module is free software; you can redistribute it and/or modify 5 6 * it under the terms of the GNU General Public License as published … … int __gmp_junk; 24 25 void __attribute__ ((regparm(0))) __gmp_assert_fail(const char *filename, 25 26 int linenum, const char *expr) 26 27 { 27 panic(KERN_CRIT TPM_MODULE_NAME"%s:%d: GNU MP assertion failed: %s\n",28 error("%s:%d: GNU MP assertion failed: %s\n", 28 29 filename, linenum, expr); 29 30 } 30 31 31 void __attribute__ ((regparm(0))) abort(void)32 {33 panic(KERN_CRIT TPM_MODULE_NAME "GNU MP abort() was called\n");34 }35 36 32 /* overwrite GNU MP random functions (used by mpz/millerrabin.c) */ 37 33 38 34 void __attribute__ ((regparm(0))) gmp_randinit(gmp_randstate_t rstate, … … void __attribute__ ((regparm(0))) mpz_ur 77 73 78 74 void __attribute__ ((regparm(0))) *kernel_allocate(size_t size) 79 75 { 80 void *ret = (void*)kmalloc(size, GFP_KERNEL); 81 if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 82 "GMP: cannot allocate memory (size=%u)\n", size); 76 void *ret = (void*)malloc(size); 77 if (!ret) error("GMP: cannot allocate memory (size=%Zu)\n", size); 83 78 return ret; 84 79 } 85 80 86 81 void __attribute__ ((regparm(0))) *kernel_reallocate(void *oldptr, 87 82 size_t old_size, size_t new_size) 88 83 { 89 void *ret = (void*) kmalloc(new_size, GFP_KERNEL);90 if (!ret) panic(KERN_CRIT TPM_MODULE_NAME"GMP: Cannot reallocate memory "91 "(old_size=% u new_size=%u)\n", old_size, new_size);84 void *ret = (void*)malloc(new_size); 85 if (!ret) error("GMP: Cannot reallocate memory " 86 "(old_size=%Zu new_size=%Zu)\n", old_size, new_size); 92 87 memcpy(ret, oldptr, old_size); 93 kfree(oldptr);88 free(oldptr); 94 89 return ret; 95 90 } 96 91 … … void __attribute__ ((regparm(0))) kernel 99 94 /* overwrite used memory */ 100 95 if (blk_ptr != NULL) { 101 96 memset(blk_ptr, 0, blk_size); 102 kfree(blk_ptr);97 free(blk_ptr); 103 98 } 104 99 } 105 100 -
crypto/rsa.c
diff -uprN orig/tpm_emulator-0.4/crypto/rsa.c tpm_emulator/crypto/rsa.c
old new 1 1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 2 2 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3 * Copyright (C) 2005 INTEL Corp 3 4 * 4 5 * This module is free software; you can redistribute it and/or modify 5 6 * it under the terms of the GNU General Public License as published … … static int encode_message(int type, uint 381 382 msg[0] = 0x00; 382 383 get_random_bytes(&msg[1], SHA1_DIGEST_LENGTH); 383 384 sha1_init(&ctx); 384 sha1_update(&ctx, "TCPA", 4);385 sha1_update(&ctx, (uint8_t *) "TCPA", 4); 385 386 sha1_final(&ctx, &msg[1 + SHA1_DIGEST_LENGTH]); 386 387 memset(&msg[1 + 2 * SHA1_DIGEST_LENGTH], 0x00, 387 388 msg_len - data_len - 2 * SHA1_DIGEST_LENGTH - 2); … … static int decode_message(int type, uint 429 430 mask_generation(&msg[1], SHA1_DIGEST_LENGTH, 430 431 &msg[1 + SHA1_DIGEST_LENGTH], msg_len - SHA1_DIGEST_LENGTH - 1); 431 432 sha1_init(&ctx); 432 sha1_update(&ctx, "TCPA", 4);433 sha1_update(&ctx, (uint8_t *) "TCPA", 4); 433 434 sha1_final(&ctx, &msg[1]); 434 435 if (memcmp(&msg[1], &msg[1 + SHA1_DIGEST_LENGTH], 435 436 SHA1_DIGEST_LENGTH) != 0) return -1; -
linux_module.c
diff -uprN orig/tpm_emulator-0.4/linux_module.c tpm_emulator/linux_module.c
old new 1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux2 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,3 *4 * This module is free software; you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published6 * by the Free Software Foundation; either version 2 of the License,7 * or (at your option) any later version.8 *9 * This module is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * $Id: linux_module.c 91 2006-03-13 13:51:41Z mast $15 */16 17 #include <linux/module.h>18 #include <linux/kernel.h>19 #include <linux/init.h>20 #include <linux/miscdevice.h>21 #include <linux/poll.h>22 #include "linux_module.h"23 #include "tpm/tpm_emulator.h"24 25 MODULE_LICENSE("GPL");26 MODULE_AUTHOR("Mario Strasser <mast@gmx.net>");27 MODULE_DESCRIPTION("Trusted Platform Module (TPM) Emulator");28 MODULE_SUPPORTED_DEVICE(TPM_DEVICE_NAME);29 30 /* module startup parameters */31 char *startup = "save";32 module_param(startup, charp, 0444);33 MODULE_PARM_DESC(startup, " Sets the startup mode of the TPM. "34 "Possible values are 'clear', 'save' (default) and 'deactivated.");35 char *storage_file = "/var/tpm/tpm_emulator-1.2.0.2";36 module_param(storage_file, charp, 0644);37 MODULE_PARM_DESC(storage_file, " Sets the persistent-data storage "38 "file of the TPM.");39 40 /* TPM lock */41 static struct semaphore tpm_mutex;42 43 /* TPM command response */44 static struct {45 uint8_t *data;46 uint32_t size;47 } tpm_response;48 49 /* module state */50 #define STATE_IS_OPEN 051 static uint32_t module_state;52 static struct timespec old_time;53 54 static int tpm_open(struct inode *inode, struct file *file)55 {56 debug("%s()", __FUNCTION__);57 if (test_and_set_bit(STATE_IS_OPEN, (void*)&module_state)) return -EBUSY;58 return 0;59 }60 61 static int tpm_release(struct inode *inode, struct file *file)62 {63 debug("%s()", __FUNCTION__);64 clear_bit(STATE_IS_OPEN, (void*)&module_state);65 down(&tpm_mutex);66 if (tpm_response.data != NULL) {67 kfree(tpm_response.data);68 tpm_response.data = NULL;69 }70 up(&tpm_mutex);71 return 0;72 }73 74 static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)75 {76 debug("%s(%d)", __FUNCTION__, count);77 down(&tpm_mutex);78 if (tpm_response.data != NULL) {79 count = min(count, (size_t)tpm_response.size - (size_t)*ppos);80 count -= copy_to_user(buf, &tpm_response.data[*ppos], count);81 *ppos += count;82 if ((size_t)tpm_response.size == (size_t)*ppos) {83 kfree(tpm_response.data);84 tpm_response.data = NULL;85 }86 } else {87 count = 0;88 }89 up(&tpm_mutex);90 return count;91 }92 93 static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)94 {95 debug("%s(%d)", __FUNCTION__, count);96 down(&tpm_mutex);97 *ppos = 0;98 if (tpm_response.data != NULL) kfree(tpm_response.data);99 if (tpm_handle_command(buf, count, &tpm_response.data,100 &tpm_response.size) != 0) {101 count = -EILSEQ;102 tpm_response.data = NULL;103 }104 up(&tpm_mutex);105 return count;106 }107 108 #define TPMIOC_CANCEL _IO('T', 0x00)109 #define TPMIOC_TRANSMIT _IO('T', 0x01)110 111 static int tpm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)112 {113 debug("%s(%d, %p)", __FUNCTION__, cmd, (char*)arg);114 if (cmd == TPMIOC_TRANSMIT) {115 uint32_t count = ntohl(*(uint32_t*)(arg + 2));116 down(&tpm_mutex);117 if (tpm_response.data != NULL) kfree(tpm_response.data);118 if (tpm_handle_command((char*)arg, count, &tpm_response.data,119 &tpm_response.size) == 0) {120 tpm_response.size -= copy_to_user((char*)arg, tpm_response.data,121 tpm_response.size);122 kfree(tpm_response.data);123 tpm_response.data = NULL;124 } else {125 tpm_response.size = 0;126 tpm_response.data = NULL;127 }128 up(&tpm_mutex);129 return tpm_response.size;130 }131 return -1;132 }133 134 struct file_operations fops = {135 .owner = THIS_MODULE,136 .open = tpm_open,137 .release = tpm_release,138 .read = tpm_read,139 .write = tpm_write,140 .ioctl = tpm_ioctl,141 };142 143 static struct miscdevice tpm_dev = {144 .minor = TPM_DEVICE_MINOR,145 .name = TPM_DEVICE_NAME,146 .fops = &fops,147 };148 149 int __init init_tpm_module(void)150 {151 int res = misc_register(&tpm_dev);152 if (res != 0) {153 error("misc_register() failed for minor %d\n", TPM_DEVICE_MINOR);154 return res;155 }156 /* initialize variables */157 sema_init(&tpm_mutex, 1);158 module_state = 0;159 tpm_response.data = NULL;160 old_time = current_kernel_time();161 /* initialize TPM emulator */162 if (!strcmp(startup, "clear")) {163 tpm_emulator_init(1);164 } else if (!strcmp(startup, "save")) {165 tpm_emulator_init(2);166 } else if (!strcmp(startup, "deactivated")) {167 tpm_emulator_init(3);168 } else {169 error("invalid startup mode '%s'; must be 'clear', "170 "'save' (default) or 'deactivated", startup);171 misc_deregister(&tpm_dev);172 return -EINVAL;173 }174 return 0;175 }176 177 void __exit cleanup_tpm_module(void)178 {179 tpm_emulator_shutdown();180 misc_deregister(&tpm_dev);181 if (tpm_response.data != NULL) kfree(tpm_response.data);182 }183 184 module_init(init_tpm_module);185 module_exit(cleanup_tpm_module);186 187 uint64_t tpm_get_ticks(void)188 {189 struct timespec new_time = current_kernel_time();190 uint64_t ticks = (uint64_t)(new_time.tv_sec - old_time.tv_sec) * 1000000191 + (new_time.tv_nsec - old_time.tv_nsec) / 1000;192 old_time = new_time;193 return (ticks > 0) ? ticks : 1;194 }195 -
linux_module.h
diff -uprN orig/tpm_emulator-0.4/linux_module.h tpm_emulator/linux_module.h
old new 1 1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 2 2 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3 * Copyright (C) 2005 INTEL Corp 3 4 * 4 5 * This module is free software; you can redistribute it and/or modify 5 6 * it under the terms of the GNU General Public License as published … … 17 18 #ifndef _LINUX_MODULE_H_ 18 19 #define _LINUX_MODULE_H_ 19 20 20 #include <linux/version.h> 21 #include <linux/kernel.h> 22 #include <linux/slab.h> 21 #include <malloc.h> 22 #include <stdint.h> 23 #include <stdio.h> 24 #include <string.h> 23 25 #include <linux/types.h> 24 #include <linux/string.h>25 #include <linux/random.h>26 #include <linux/time.h>27 #include <asm/byteorder.h>28 26 29 /* module settings */ 27 #include <endian.h> 28 #define __BYTEORDER_HAS_U64__ 29 #ifdef LITTLE_ENDIAN 30 #include <linux/byteorder/little_endian.h> 31 #else 32 #include <linux/byteorder/big_endian.h> 33 #endif 30 34 35 /* module settings */ 36 #define min(A,B) ((A)<(B)?(A):(B)) 37 #ifndef STR 31 38 #define STR(s) __STR__(s) 32 39 #define __STR__(s) #s 40 #endif 33 41 #include "tpm_version.h" 34 42 35 43 #define TPM_DEVICE_MINOR 224 36 44 #define TPM_DEVICE_NAME "tpm" 37 45 #define TPM_MODULE_NAME "tpm_emulator" 38 46 39 /* debug and log output functions */40 41 47 #ifdef DEBUG 42 #define debug(fmt, ...) print k(KERN_DEBUG "%s%s:%d: Debug: " fmt "\n", \43 TPM_MODULE_NAME,__FILE__, __LINE__, ## __VA_ARGS__)48 #define debug(fmt, ...) printf("TPMD: %s:%d: Debug: " fmt "\n", \ 49 __FILE__, __LINE__, ## __VA_ARGS__) 44 50 #else 45 51 #define debug(fmt, ...) 46 52 #endif 47 #define info(fmt, ...) print k(KERN_INFO "%s%s:%d: Info: " fmt "\n", \48 TPM_MODULE_NAME,__FILE__, __LINE__, ## __VA_ARGS__)49 #define error(fmt, ...) print k(KERN_ERR "%s%s:%d: Error: " fmt "\n", \50 TPM_MODULE_NAME,__FILE__, __LINE__, ## __VA_ARGS__)51 #define alert(fmt, ...) print k(KERN_ALERT "%s%s:%d: Alert: " fmt "\n", \52 TPM_MODULE_NAME,__FILE__, __LINE__, ## __VA_ARGS__)53 #define info(fmt, ...) printf("TPMD: %s:%d: Info: " fmt "\n", \ 54 __FILE__, __LINE__, ## __VA_ARGS__) 55 #define error(fmt, ...) printf("TPMD: %s:%d: Error: " fmt "\n", \ 56 __FILE__, __LINE__, ## __VA_ARGS__) 57 #define alert(fmt, ...) printf("TPMD: %s:%d: Alert: " fmt "\n", \ 58 __FILE__, __LINE__, ## __VA_ARGS__) 53 59 54 60 /* memory allocation */ 55 61 56 62 static inline void *tpm_malloc(size_t size) 57 63 { 58 return kmalloc(size, GFP_KERNEL);64 return malloc(size); 59 65 } 60 66 61 67 static inline void tpm_free(const void *ptr) 62 68 { 63 if (ptr != NULL) kfree(ptr);69 if (ptr != NULL) free( (void *) ptr); 64 70 } 65 71 66 72 /* random numbers */ 67 73 74 //FIXME; 75 void get_random_bytes(void *buf, int nbytes); 76 68 77 static inline void tpm_get_random_bytes(void *buf, int nbytes) 69 78 { 70 79 get_random_bytes(buf, nbytes); … … uint64_t tpm_get_ticks(void); 84 93 #define CPU_TO_LE16(x) __cpu_to_le16(x) 85 94 86 95 #define BE64_TO_CPU(x) __be64_to_cpu(x) 87 #define LE64_TO_CPU(x) __ be64_to_cpu(x)96 #define LE64_TO_CPU(x) __le64_to_cpu(x) 88 97 #define BE32_TO_CPU(x) __be32_to_cpu(x) 89 #define LE32_TO_CPU(x) __ be32_to_cpu(x)98 #define LE32_TO_CPU(x) __le32_to_cpu(x) 90 99 #define BE16_TO_CPU(x) __be16_to_cpu(x) 91 100 #define LE16_TO_CPU(x) __le16_to_cpu(x) 92 101 -
Makefile
diff -uprN orig/tpm_emulator-0.4/Makefile tpm_emulator/Makefile
old new 1 1 # Software-Based Trusted Platform Module (TPM) Emulator for Linux 2 2 # Copyright (C) 2004 Mario Strasser <mast@gmx.net> 3 # Copyright (C) 2006 INTEL Corp. 3 4 # 4 5 # $Id: Makefile 115 2006-06-23 10:36:44Z mast $ 5 6 6 # kernel settings 7 KERNEL_RELEASE := $(shell uname -r) 8 KERNEL_BUILD := /lib/modules/$(KERNEL_RELEASE)/build 9 MOD_SUBDIR := misc 7 COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/) 10 8 11 9 # module settings 12 MODULE_NAME:= tpm_emulator10 BIN := tpm_emulator 13 11 VERSION_MAJOR := 0 14 12 VERSION_MINOR := 4 15 13 VERSION_BUILD := $(shell date +"%s") 16 14 17 # enable/disable DEBUG messages 18 EXTRA_CFLAGS += -Wall -DDEBUG -g 15 # Installation program and options 16 INSTALL = install 17 INSTALL_PROG = $(INSTALL) -m0755 18 INSTALL_DIR = $(INSTALL) -d -m0755 19 20 # Xen tools installation directory 21 TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin 22 23 CC := gcc 24 CFLAGS += -g -Wall $(INCLUDE) -DDEBUG 25 CFLAGS += -I. -Itpm 26 27 # Is the simulator running in it's own vm? 28 #CFLAGS += -DVTPM_MULTI_VM 29 30 ifeq ($(COMPILE_ARCH),x86_64) 31 LIBDIR = lib64 32 else 33 LIBDIR = lib 34 endif 19 35 20 36 # GNU MP configuration 21 GMP_LIB := /usr/ lib/libgmp.a37 GMP_LIB := /usr/$(LIBDIR)/libgmp.a 22 38 GMP_HEADER := /usr/include/gmp.h 23 39 24 40 # sources and objects … … DIRS := . crypto tpm 27 43 SRCS := $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.c)) 28 44 OBJS := $(patsubst %.c, %.o, $(SRCS)) 29 45 SRCS += $(foreach dir, $(DIRS), $(wildcard $(src)/$(dir)/*.h)) 30 DISTSRC := ./README ./AUTHORS ./ChangeLog ./Makefile $(SRCS)31 DISTDIR := tpm_emulator-$(VERSION_MAJOR).$(VERSION_MINOR)32 46 33 obj-m := $( MODULE_NAME).o34 $( MODULE_NAME)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a47 obj-m := $(BIN) 48 $(BIN)-objs := $(patsubst $(src)/%.o, %.o, $(OBJS)) crypto/libgmp.a 35 49 36 50 EXTRA_CFLAGS += -I$(src) -I$(src)/crypto -I$(src)/tpm 37 51 38 52 # do not print "Entering directory ..." 39 53 MAKEFLAGS += --no-print-directory 40 54 41 all: $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version 42 @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules 55 all: $(BIN) 43 56 44 install: 45 @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) modules_install 46 test -d /var/tpm || mkdir /var/tpm 47 test -c /dev/tpm || mknod /dev/tpm c 10 224 48 chmod 666 /dev/tpm 49 depmod -a 57 $(BIN): $(src)/crypto/gmp.h $(src)/crypto/libgmp.a version $(SRCS) $(OBJS) 58 $(CC) $(CFLAGS) $(OBJS) $(src)/crypto/libgmp.a -o $(BIN) 59 60 %.o: %.c 61 $(CC) $(CFLAGS) -c $< -o $@ 62 63 install: $(BIN) 64 $(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR) 65 @if [ ! -d "/var/tpm" ]; then mkdir /var/tpm; fi 50 66 51 67 clean: 52 @$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) clean 53 rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a 68 rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS) 54 69 55 dist: $(DISTSRC) 56 rm -rf $(DISTDIR) 57 mkdir $(DISTDIR) 58 cp --parents $(DISTSRC) $(DISTDIR)/ 59 rm -f $(DISTDIR)/crypto/gmp.h 60 tar -chzf $(DISTDIR).tar.gz $(DISTDIR) 61 rm -rf $(DISTDIR) 70 mrproper: clean 71 rm -f $(BIN) tpm_version.h 62 72 63 73 $(src)/crypto/libgmp.a: 64 74 test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a … … version: 88 98 @echo "#endif /* _TPM_VERSION_H_ */" >> $(src)/tpm_version.h 89 99 90 100 .PHONY: all install clean dist gmp version 91 -
README
diff -uprN orig/tpm_emulator-0.4/README tpm_emulator/README
old new $Id: README 113 2006-06-18 12:38:13Z hst 13 13 Copyright 14 14 -------------------------------------------------------------------------- 15 15 Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal 16 Institute of Technology (ETH) Zurich. 16 Institute of Technology (ETH) Zurich. 17 Copyright (C) 2005 INTEL Corp 17 18 18 19 This program is free software; you can redistribute it and/or modify 19 20 it under the terms of the GNU General Public License as published by … … Example: 43 44 GMP_LIB := /usr/lib/libgmp.a 44 45 GMP_HEADER := /usr/include/gmp.h 45 46 47 GNU MP Library on 64 bit Systems 48 -------------------------------------------------------------------------- 49 Some 64-bit kernels have problems with importing the user-space gmp 50 library (/usr/lib*/libgmp.a) into kernel space. These kernels will require 51 that the gmp library be recompiled for kernel space with -mcmodel=kernel. 52 46 53 Installation 47 54 -------------------------------------------------------------------------- 48 55 The compilation and installation process uses the build environment for -
tpm/tpm_credentials.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_credentials.c tpm_emulator/tpm/tpm_credentials.c
old new int tpm_compute_pubkey_checksum(TPM_NONC 47 47 48 48 TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey) 49 49 { 50 UINT32key_length;50 size_t key_length; 51 51 if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT; 52 52 /* setup TPM_PUBKEY structure */ 53 key_length = tpmData.permanent.data.endorsementKey.size; 54 pubEndorsementKey->pubKey.keyLength = key_length >> 3; 53 pubEndorsementKey->pubKey.keyLength = tpmData.permanent.data.endorsementKey.size >> 3; 55 54 pubEndorsementKey->pubKey.key = tpm_malloc(pubEndorsementKey->pubKey.keyLength); 56 55 if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL; 57 56 rsa_export_modulus(&tpmData.permanent.data.endorsementKey, 58 pubEndorsementKey->pubKey.key, 59 &pubEndorsementKey->pubKey.keyLength); 57 pubEndorsementKey->pubKey.key, 58 &key_length); 59 pubEndorsementKey->pubKey.keyLength = key_length; 60 60 pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA; 61 61 pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1; 62 62 pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE; … … TPM_RESULT TPM_OwnerReadInternalPub(TPM_ 175 175 { 176 176 TPM_RESULT res; 177 177 TPM_KEY_DATA *srk = &tpmData.permanent.data.srk; 178 size_t key_length; 178 179 info("TPM_OwnerReadInternalPub()"); 179 180 /* verify authorization */ 180 181 res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER); … … TPM_RESULT TPM_OwnerReadInternalPub(TPM_ 186 187 publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength); 187 188 if (publicPortion->pubKey.key == NULL) return TPM_FAIL; 188 189 rsa_export_modulus(&srk->key, publicPortion->pubKey.key, 189 &publicPortion->pubKey.keyLength); 190 &key_length); 191 publicPortion->pubKey.keyLength = key_length; 190 192 publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA; 191 193 publicPortion->algorithmParms.encScheme = srk->encScheme; 192 194 publicPortion->algorithmParms.sigScheme = srk->sigScheme; -
tpm/tpm_crypto.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_crypto.c tpm_emulator/tpm/tpm_crypto.c
old new TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE 182 182 TPM_KEY_DATA *cert, *key; 183 183 sha1_ctx_t sha1_ctx; 184 184 BYTE *buf, *p; 185 UINT32 length; 185 UINT32 length32; 186 size_t length; 186 187 info("TPM_CertifyKey()"); 187 188 /* get keys */ 188 189 cert = tpm_get_key(certHandle); … … TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE 264 265 /* compute the digest of the CERTIFY_INFO[2] structure and sign it */ 265 266 length = sizeof_TPM_CERTIFY_INFO((*certifyInfo)); 266 267 p = buf = tpm_malloc(length); 268 length32=(UINT32) length; 267 269 if (buf == NULL 268 || tpm_marshal_TPM_CERTIFY_INFO(&p, &length , certifyInfo)) {270 || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) { 269 271 free_TPM_KEY_PARMS(certifyInfo->algorithmParms); 270 272 return TPM_FAIL; 271 273 } 272 274 length = sizeof_TPM_CERTIFY_INFO((*certifyInfo)); 273 275 sha1_init(&sha1_ctx); 274 sha1_update(&sha1_ctx, buf, length);276 sha1_update(&sha1_ctx, buf, (size_t) length); 275 277 sha1_final(&sha1_ctx, buf); 276 278 res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSize); 277 279 tpm_free(buf); … … TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL 292 294 TPM_KEY_DATA *cert, *key; 293 295 sha1_ctx_t sha1_ctx; 294 296 BYTE *buf, *p; 295 UINT32 length; 297 size_t length; 298 UINT32 length32; 296 299 info("TPM_CertifyKey2()"); 297 300 /* get keys */ 298 301 cert = tpm_get_key(certHandle); … … TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL 362 365 /* compute the digest of the CERTIFY_INFO[2] structure and sign it */ 363 366 length = sizeof_TPM_CERTIFY_INFO((*certifyInfo)); 364 367 p = buf = tpm_malloc(length); 368 length32 = (UINT32) length; 365 369 if (buf == NULL 366 || tpm_marshal_TPM_CERTIFY_INFO(&p, &length , certifyInfo)) {370 || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) { 367 371 free_TPM_KEY_PARMS(certifyInfo->algorithmParms); 368 372 return TPM_FAIL; 369 373 } -
tpm/tpm_daa.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_daa.c tpm_emulator/tpm/tpm_daa.c
old new TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl 716 716 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 717 717 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 718 718 sizeof(session->DAA_tpmSpecific.DAA_count)); 719 sha1_update(&sha1, "\x00", 1);719 sha1_update(&sha1, (BYTE *) "\x00", 1); 720 720 sha1_final(&sha1, scratch); 721 721 sha1_init(&sha1); 722 722 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 723 723 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 724 724 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 725 725 sizeof(session->DAA_tpmSpecific.DAA_count)); 726 sha1_update(&sha1, "\x01", 1);726 sha1_update(&sha1, (BYTE *) "\x01", 1); 727 727 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 728 728 mpz_init(f), mpz_init(q); 729 729 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); … … TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl 805 805 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 806 806 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 807 807 sizeof(session->DAA_tpmSpecific.DAA_count)); 808 sha1_update(&sha1, "\x00", 1);808 sha1_update(&sha1, (BYTE *) "\x00", 1); 809 809 sha1_final(&sha1, scratch); 810 810 sha1_init(&sha1); 811 811 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 812 812 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 813 813 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 814 814 sizeof(session->DAA_tpmSpecific.DAA_count)); 815 sha1_update(&sha1, "\x01", 1);815 sha1_update(&sha1, (BYTE *) "\x01", 1); 816 816 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 817 817 mpz_init(f), mpz_init(q); 818 818 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); … … TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl 1489 1489 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 1490 1490 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 1491 1491 sizeof(session->DAA_tpmSpecific.DAA_count)); 1492 sha1_update(&sha1, "\x00", 1);1492 sha1_update(&sha1, (BYTE *) "\x00", 1); 1493 1493 sha1_final(&sha1, scratch); 1494 1494 sha1_init(&sha1); 1495 1495 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 1496 1496 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 1497 1497 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 1498 1498 sizeof(session->DAA_tpmSpecific.DAA_count)); 1499 sha1_update(&sha1, "\x01", 1);1499 sha1_update(&sha1, (BYTE *) "\x01", 1); 1500 1500 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 1501 1501 mpz_init(f), mpz_init(q); 1502 1502 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); … … TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl 1712 1712 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 1713 1713 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 1714 1714 sizeof(session->DAA_tpmSpecific.DAA_count)); 1715 sha1_update(&sha1, "\x00", 1);1715 sha1_update(&sha1, (BYTE *) "\x00", 1); 1716 1716 sha1_final(&sha1, scratch); 1717 1717 sha1_init(&sha1); 1718 1718 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 1719 1719 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 1720 1720 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 1721 1721 sizeof(session->DAA_tpmSpecific.DAA_count)); 1722 sha1_update(&sha1, "\x01", 1);1722 sha1_update(&sha1, (BYTE *) "\x01", 1); 1723 1723 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 1724 1724 mpz_init(f), mpz_init(q); 1725 1725 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); … … TPM_RESULT TPM_DAA_Join(TPM_HANDLE handl 1793 1793 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 1794 1794 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 1795 1795 sizeof(session->DAA_tpmSpecific.DAA_count)); 1796 sha1_update(&sha1, "\x00", 1);1796 sha1_update(&sha1, (BYTE *) "\x00", 1); 1797 1797 sha1_final(&sha1, scratch); 1798 1798 sha1_init(&sha1); 1799 1799 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 1800 1800 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 1801 1801 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 1802 1802 sizeof(session->DAA_tpmSpecific.DAA_count)); 1803 sha1_update(&sha1, "\x01", 1);1803 sha1_update(&sha1, (BYTE *) "\x01", 1); 1804 1804 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 1805 1805 mpz_init(f), mpz_init(q); 1806 1806 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); … … TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 2918 2918 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 2919 2919 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 2920 2920 sizeof(session->DAA_tpmSpecific.DAA_count)); 2921 sha1_update(&sha1, "\x00", 1);2921 sha1_update(&sha1, (BYTE *) "\x00", 1); 2922 2922 sha1_final(&sha1, scratch); 2923 2923 sha1_init(&sha1); 2924 2924 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 2925 2925 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 2926 2926 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 2927 2927 sizeof(session->DAA_tpmSpecific.DAA_count)); 2928 sha1_update(&sha1, "\x01", 1);2928 sha1_update(&sha1, (BYTE *) "\x01", 1); 2929 2929 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 2930 2930 mpz_init(f), mpz_init(q); 2931 2931 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); … … TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3143 3143 sha1_init(&sha1); 3144 3144 sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest, 3145 3145 sizeof(session->DAA_session.DAA_digest)); 3146 sha1_update(&sha1, "\x01", 1);3146 sha1_update(&sha1, (BYTE *) "\x01", 1); 3147 3147 sha1_update(&sha1, inputData1, inputSize1); 3148 3148 sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest); 3149 3149 } … … TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3172 3172 sha1_init(&sha1); 3173 3173 sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest, 3174 3174 sizeof(session->DAA_session.DAA_digest)); 3175 sha1_update(&sha1, "\x00", 1);3175 sha1_update(&sha1, (BYTE*) "\x00", 1); 3176 3176 rsa_export_modulus(&aikData->key, scratch, &size); 3177 3177 sha1_update(&sha1, scratch, size); 3178 3178 sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest); … … TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3229 3229 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3230 3230 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3231 3231 sizeof(session->DAA_tpmSpecific.DAA_count)); 3232 sha1_update(&sha1, "\x00", 1);3232 sha1_update(&sha1, (BYTE *) "\x00", 1); 3233 3233 sha1_final(&sha1, scratch); 3234 3234 sha1_init(&sha1); 3235 3235 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 3236 3236 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3237 3237 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3238 3238 sizeof(session->DAA_tpmSpecific.DAA_count)); 3239 sha1_update(&sha1, "\x01", 1);3239 sha1_update(&sha1, (BYTE *) "\x01", 1); 3240 3240 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 3241 3241 mpz_init(f), mpz_init(q); 3242 3242 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); … … TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl 3309 3309 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3310 3310 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3311 3311 sizeof(session->DAA_tpmSpecific.DAA_count)); 3312 sha1_update(&sha1, "\x00", 1);3312 sha1_update(&sha1, (BYTE *) "\x00", 1); 3313 3313 sha1_final(&sha1, scratch); 3314 3314 sha1_init(&sha1); 3315 3315 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 3316 3316 sizeof(session->DAA_tpmSpecific.DAA_rekey)); 3317 3317 sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 3318 3318 sizeof(session->DAA_tpmSpecific.DAA_count)); 3319 sha1_update(&sha1, "\x01", 1);3319 sha1_update(&sha1, (BYTE *) "\x01", 1); 3320 3320 sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH); 3321 3321 mpz_init(f), mpz_init(q); 3322 3322 mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch); -
tpm/tpm_data.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_data.c tpm_emulator/tpm/tpm_data.c
old new static inline void init_pcr_attr(int pcr 40 40 void tpm_init_data(void) 41 41 { 42 42 /* endorsement key */ 43 #ifndef TPM_GENERATE_EK 43 44 uint8_t ek_n[] = "\xa8\xdb\xa9\x42\xa8\xf3\xb8\x06\x85\x90\x76\x93\xad\xf7" 44 45 "\x74\xec\x3f\xd3\x3d\x9d\xe8\x2e\xff\x15\xed\x0e\xce\x5f\x93" 45 46 "\x92\xeb\xd1\x96\x2b\x72\x18\x81\x79\x12\x9d\x9c\x40\xd7\x1a" … … void tpm_init_data(void) 77 78 "\xd1\xc0\x8b\x5b\xa2\x2e\xa7\x15\xca\x50\x75\x10\x48\x9c\x2b" 78 79 "\x18\xb9\x67\x8f\x5d\x64\xc3\x28\x9f\x2f\x16\x2f\x08\xda\x47" 79 80 "\xec\x86\x43\x0c\x80\x99\x07\x34\x0f"; 81 #endif 82 80 83 int i; 81 84 /* reset all data to NULL, FALSE or 0 */ 82 85 memset(&tpmData, 0, sizeof(tpmData)); … … void tpm_release_data(void) 152 155 153 156 #ifdef TPM_STORE_TO_FILE 154 157 155 #include <linux/fs.h> 156 #include <linux/unistd.h> 157 #include <asm/uaccess.h> 158 #include <sys/types.h> 159 #include <sys/stat.h> 160 #include <fcntl.h> 161 #include <unistd.h> 158 162 159 163 #define TPM_STORAGE_FILE "/var/tpm/tpm_emulator-1.2." STR(VERSION_MAJOR) "." STR(VERSION_MINOR) 160 164 161 165 static int write_to_file(uint8_t *data, size_t data_length) 162 166 { 163 167 int res; 164 struct file *fp; 165 mm_segment_t old_fs = get_fs(); 166 fp = filp_open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR); 167 if (IS_ERR(fp)) return -1; 168 set_fs(get_ds()); 169 res = fp->f_op->write(fp, data, data_length, &fp->f_pos); 170 set_fs(old_fs); 171 filp_close(fp, NULL); 168 int fp; 169 fp = open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR); 170 res = write(fp, data, data_length); 171 close(fp); 172 172 return (res == data_length) ? 0 : -1; 173 173 } 174 174 175 175 static int read_from_file(uint8_t **data, size_t *data_length) 176 176 { 177 177 int res; 178 struct file *fp; 179 mm_segment_t old_fs = get_fs(); 180 fp = filp_open(TPM_STORAGE_FILE, O_RDONLY, 0); 181 if (IS_ERR(fp)) return -1; 182 *data_length = (size_t)fp->f_dentry->d_inode->i_size; 183 /* *data_length = i_size_read(fp->f_dentry->d_inode); */ 178 int fp, file_status; 179 struct stat file_info; 180 fp = open(TPM_STORAGE_FILE, O_RDONLY, 0); 181 file_status = fstat(fp, &file_info); 182 if (file_status < 0) { 183 close(fp); 184 return -1; 185 } 186 187 *data_length = file_info.st_size; 184 188 *data = tpm_malloc(*data_length); 185 189 if (*data == NULL) { 186 filp_close(fp, NULL);190 close(fp); 187 191 return -1; 188 192 } 189 set_fs(get_ds()); 190 res = fp->f_op->read(fp, *data, *data_length, &fp->f_pos); 191 set_fs(old_fs); 192 filp_close(fp, NULL); 193 res = read(fp, *data, *data_length); 194 close(fp); 193 195 if (res != *data_length) { 194 196 tpm_free(*data); 195 197 return -1; … … static int read_from_file(uint8_t **data 216 218 int tpm_store_permanent_data(void) 217 219 { 218 220 uint8_t *buf, *ptr; 219 size_tbuf_length, len;221 UINT32 buf_length, len; 220 222 221 223 /* marshal data */ 222 buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags) 223 + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) + 2 224 + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data); 224 buf_length = len = 4 + sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags) 225 + sizeof_TPM_PERMANENT_FLAGS(tpmData.permanent.flags) 226 + sizeof_TPM_STANY_FLAGS(tpmData.stany.flags) + 2 227 + sizeof_TPM_STCLEAR_DATA(tpmData.stclear.data) 228 + sizeof_TPM_PERMANENT_DATA(tpmData.permanent.data) 229 + sizeof_TPM_STANY_DATA(tpmData.stany.data); 225 230 buf = ptr = tpm_malloc(buf_length); 226 231 if (buf == NULL 227 232 || tpm_marshal_TPM_VERSION(&ptr, &len, &tpmData.permanent.data.version) 228 233 || tpm_marshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags) 229 234 || tpm_marshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags) 235 || tpm_marshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags) 230 236 || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.selfTestSucceeded) 231 237 || tpm_marshal_BOOL(&ptr, &len, tpmData.permanent.flags.owned) 232 || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) { 238 || tpm_marshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data) 239 || tpm_marshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data) 240 || tpm_marshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) { 233 241 tpm_free(buf); 234 242 return -1; 235 243 } 244 236 245 if (write_to_file(buf, buf_length - len)) { 237 246 tpm_free(buf); 238 247 return -1; … … int tpm_store_permanent_data(void) 244 253 int tpm_restore_permanent_data(void) 245 254 { 246 255 uint8_t *buf, *ptr; 247 size_t buf_length, len; 256 size_t buf_length; 257 UINT32 len; 248 258 TPM_VERSION ver; 249 259 250 260 /* read data */ 251 261 if (read_from_file(&buf, &buf_length)) return -1; 252 262 ptr = buf; 253 len = buf_length;263 len = (uint32_t) buf_length; 254 264 /* unmarshal data */ 255 265 if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver) 256 266 || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION)) 257 267 || tpm_unmarshal_TPM_STCLEAR_FLAGS(&ptr, &len, &tpmData.stclear.flags) 258 268 || tpm_unmarshal_TPM_PERMANENT_FLAGS(&ptr, &len, &tpmData.permanent.flags) 269 || tpm_unmarshal_TPM_STANY_FLAGS(&ptr, &len, &tpmData.stany.flags) 259 270 || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.selfTestSucceeded) 260 271 || tpm_unmarshal_BOOL(&ptr, &len, &tpmData.permanent.flags.owned) 261 || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data)) { 272 || tpm_unmarshal_TPM_STCLEAR_DATA(&ptr, &len, &tpmData.stclear.data) 273 || tpm_unmarshal_TPM_PERMANENT_DATA(&ptr, &len, &tpmData.permanent.data) 274 || tpm_unmarshal_TPM_STANY_DATA(&ptr, &len, &tpmData.stany.data)) { 262 275 tpm_free(buf); 263 276 return -1; 264 277 } 278 265 279 tpm_free(buf); 266 280 return 0; 267 281 } 268 282 269 283 int tpm_erase_permanent_data(void) 270 284 { 271 int res = write_to_file( "", 0);285 int res = write_to_file((uint8_t *) "", 0); 272 286 return res; 273 287 } 274 288 -
tpm/tpm_deprecated.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_deprecated.c tpm_emulator/tpm/tpm_deprecated.c
old new 1 1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 2 2 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3 3 * Swiss Federal Institute of Technology (ETH) Zurich 4 * Copyright (C) 2005 INTEL Corp 4 5 * 5 6 * This module is free software; you can redistribute it and/or modify 6 7 * it under the terms of the GNU General Public License as published … … TPM_RESULT TPM_SaveKeyContext(TPM_KEY_HA 50 51 BYTE *ptr; 51 52 UINT32 len; 52 53 info("TPM_SaveKeyContext()"); 53 res = TPM_SaveContext(keyHandle, TPM_RT_KEY, "SaveKeyContext..",54 res = TPM_SaveContext(keyHandle, TPM_RT_KEY, (BYTE*)"SaveKeyContext..", 54 55 keyContextSize, &contextBlob); 55 56 if (res != TPM_SUCCESS) return res; 56 57 len = *keyContextSize; … … TPM_RESULT TPM_SaveAuthContext(TPM_AUTHH 82 83 BYTE *ptr; 83 84 UINT32 len; 84 85 info("TPM_SaveAuthContext()"); 85 res = TPM_SaveContext(authHandle, TPM_RT_KEY, "SaveAuthContext.",86 res = TPM_SaveContext(authHandle, TPM_RT_KEY, (BYTE*)"SaveAuthContext.", 86 87 authContextSize, &contextBlob); 87 88 if (res != TPM_SUCCESS) return res; 88 89 len = *authContextSize; -
tpm/tpm_emulator.h
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_emulator.h tpm_emulator/tpm/tpm_emulator.h
old new 1 1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 2 2 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3 * Copyright (C) 2005 INTEL Corp 3 4 * 4 5 * This module is free software; you can redistribute it and/or modify 5 6 * it under the terms of the GNU General Public License as published … … 22 23 /* TPM configuration */ 23 24 #define TPM_STORE_TO_FILE 1 24 25 #undef TPM_STRONG_PERSISTENCE 25 #undef TPM_GENERATE_EK 26 //#undef TPM_GENERATE_EK 27 #define TPM_GENERATE_EK 26 28 #undef TPM_GENERATE_SEED_DAA 27 29 28 30 #define TPM_MANUFACTURER 0x4554485A /* 'ETHZ' */ -
tpm/tpm_marshalling.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_marshalling.c tpm_emulator/tpm/tpm_marshalling.c
old new int tpm_unmarshal_TPM_STANY_FLAGS(BYTE * 1312 1312 1313 1313 int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v) 1314 1314 { 1315 UINT32m_len, e_len, q_len;1315 size_t m_len, e_len, q_len; 1316 1316 if (*length < sizeof_RSA((*v))) return -1; 1317 1317 if (v->size > 0) { 1318 1318 rsa_export_modulus(v, &(*ptr)[6], &m_len); … … int tpm_unmarshal_TPM_PERMANENT_DATA(BYT 1460 1460 return 0; 1461 1461 } 1462 1462 1463 int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v) 1464 { 1465 if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag) 1466 || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceKey) 1467 || tpm_marshal_TPM_COUNT_ID(ptr, length, v->countID) ) return -1; 1468 1469 return 0; 1470 } 1471 1472 int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v) 1473 { 1474 if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag) 1475 || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceKey) 1476 || tpm_unmarshal_TPM_COUNT_ID(ptr, length, &v->countID) ) return -1; 1477 1478 return 0; 1479 } 1480 1481 int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v) 1482 { 1483 UINT32 i; 1484 if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag) 1485 || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceSession) 1486 || tpm_marshal_TPM_DIGEST(ptr, length, &v->auditDigest) 1487 || tpm_marshal_BOOL(ptr, length, v->auditSession) 1488 || tpm_marshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks) 1489 || tpm_marshal_UINT32(ptr, length, v->contextCount) 1490 || tpm_marshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1; 1491 for (i = 0; i < TPM_MAX_SESSIONS; i++) { 1492 if (tpm_marshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1; 1493 } 1494 for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) { 1495 if (tpm_marshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1; 1496 } 1497 if (tpm_marshal_TPM_TRANSHANDLE(ptr, length, v->transExclusive)) return -1; 1498 1499 return 0; 1500 } 1501 1502 int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v) 1503 { 1504 UINT32 i; 1505 if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag) 1506 || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceSession) 1507 || tpm_unmarshal_TPM_DIGEST(ptr, length, &v->auditDigest) 1508 || tpm_unmarshal_BOOL(ptr, length, &v->auditSession) 1509 || tpm_unmarshal_TPM_CURRENT_TICKS(ptr, length, &v->currentTicks) 1510 || tpm_unmarshal_UINT32(ptr, length, &v->contextCount) 1511 || tpm_unmarshal_UINT32_ARRAY(ptr, length, v->contextList, TPM_MAX_SESSION_LIST)) return -1; 1512 for (i = 0; i < TPM_MAX_SESSIONS; i++) { 1513 if (tpm_unmarshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1; 1514 } 1515 for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) { 1516 if (tpm_unmarshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) return -1; 1517 } 1518 if (tpm_unmarshal_TPM_TRANSHANDLE(ptr, length, &v->transExclusive)) return -1; 1519 1520 return 0; 1521 } 1522 1463 1523 int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v) 1464 1524 { 1465 1525 if (tpm_marshal_BYTE(ptr, length, v->type) -
tpm/tpm_marshalling.h
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_marshalling.h tpm_emulator/tpm/tpm_marshalling.h
old new int tpm_unmarshal_TPM_KEY_DATA(BYTE **pt 432 432 int tpm_marshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *); 433 433 int tpm_unmarshal_TPM_PERMANENT_DATA(BYTE **ptr, UINT32 *length, TPM_PERMANENT_DATA *); 434 434 435 int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v); 436 int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v); 437 438 int tpm_marshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v); 439 int tpm_unmarshal_TPM_STANY_DATA(BYTE **ptr, UINT32 *length, TPM_STANY_DATA *v); 440 435 441 int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v); 436 442 int tpm_unmarshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v); 437 443 -
tpm/tpm_owner.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_owner.c tpm_emulator/tpm/tpm_owner.c
old new TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO 108 108 TPM_RESULT res; 109 109 rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey; 110 110 TPM_KEY_DATA *srk = &tpmData.permanent.data.srk; 111 UINT32 buf_size = ek->size >> 3;111 size_t buf_size = ek->size >> 3, key_length; 112 112 BYTE buf[buf_size]; 113 113 114 114 info("TPM_TakeOwnership()"); … … TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO 173 173 return TPM_FAIL; 174 174 } 175 175 rsa_export_modulus(&srk->key, srkPub->pubKey.key, 176 &srkPub->pubKey.keyLength); 176 &key_length); 177 srkPub->pubKey.keyLength = (UINT32) key_length; 177 178 /* setup tpmProof and set state to owned */ 178 179 tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 179 180 sizeof(tpmData.permanent.data.tpmProof.nonce)); -
tpm/tpm_startup.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_startup.c tpm_emulator/tpm/tpm_startup.c
old new void TPM_Init(TPM_STARTUP_TYPE startupTy 41 41 TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE startupType) 42 42 { 43 43 int i; 44 int restore_fail; 44 45 info("TPM_Startup(%d)", startupType); 45 46 if (tpmData.stany.flags.postInitialise == FALSE) return TPM_INVALID_POSTINIT; 46 /* reset STANY_FLAGS */ 47 SET_TO_ZERO(&tpmData.stany.flags); 48 tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS; 49 /* reset STANY_DATA (invalidates ALL sessions) */ 50 SET_TO_ZERO(&tpmData.stany.data); 51 tpmData.stany.data.tag = TPM_TAG_STANY_DATA; 52 /* init session-context nonce */ 53 SET_TO_RAND(&tpmData.stany.data.contextNonceSession); 47 48 /* try and restore state to get EK, SRK, etc */ 49 restore_fail = tpm_restore_permanent_data(); 50 54 51 /* set data and flags according to the given startup type */ 55 52 if (startupType == TPM_ST_CLEAR) { 56 /* if available, restore permanent data */ 57 tpm_restore_permanent_data(); 53 /* reset STANY_FLAGS */ 54 SET_TO_ZERO(&tpmData.stany.flags); 55 tpmData.stany.flags.tag = TPM_TAG_STANY_FLAGS; 56 /* reset STANY_DATA (invalidates ALL sessions) */ 57 SET_TO_ZERO(&tpmData.stany.data); 58 tpmData.stany.data.tag = TPM_TAG_STANY_DATA; 59 /* init session-context nonce */ 60 SET_TO_RAND(&tpmData.stany.data.contextNonceSession); 58 61 /* reset PCR values */ 59 62 for (i = 0; i < TPM_NUM_PCR; i++) { 60 if ( tpmData.permanent.data.pcrAttrib[i].pcrReset)61 SET_TO_ZERO( tpmData.permanent.data.pcrValue[i].digest);63 if (!tpmData.permanent.data.pcrAttrib[i].pcrReset) 64 SET_TO_ZERO(&tpmData.permanent.data.pcrValue[i].digest); 62 65 else 63 SET_TO_0xFF( tpmData.permanent.data.pcrValue[i].digest);66 SET_TO_0xFF(&tpmData.permanent.data.pcrValue[i].digest); 64 67 } 65 68 /* reset STCLEAR_FLAGS */ 66 69 SET_TO_ZERO(&tpmData.stclear.flags); … … TPM_RESULT TPM_Startup(TPM_STARTUP_TYPE 79 82 /* init key-context nonce */ 80 83 SET_TO_RAND(&tpmData.stclear.data.contextNonceKey); 81 84 } else if (startupType == TPM_ST_STATE) { 82 if (tpm_restore_permanent_data()) { 85 /* restore must have been successful for TPM_ST_STATE */ 86 if (restore_fail) { 83 87 error("restoring permanent data failed"); 84 88 tpmData.permanent.data.testResult = "tpm_restore_permanent_data() failed"; 85 89 tpmData.permanent.flags.selfTestSucceeded = FALSE; -
tpm/tpm_storage.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_storage.c tpm_emulator/tpm/tpm_storage.c
old new int encrypt_sealed_data(TPM_KEY_DATA *ke 58 58 BYTE *enc, UINT32 *enc_size) 59 59 { 60 60 UINT32 len; 61 size_t enc_size32 = *enc_size; 61 62 BYTE *buf, *ptr; 62 63 rsa_public_key_t pub_key; 63 64 int scheme; … … int encrypt_sealed_data(TPM_KEY_DATA *ke 72 73 if (buf == NULL 73 74 || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal) 74 75 || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)), 75 enc, enc_size)) {76 enc, &enc_size32)) { 76 77 tpm_free(buf); 77 78 rsa_release_public_key(&pub_key); 78 79 return -1; … … int encrypt_sealed_data(TPM_KEY_DATA *ke 85 86 int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 86 87 TPM_SEALED_DATA *seal, BYTE **buf) 87 88 { 88 UINT32 len; 89 size_t len; 90 UINT32 len32; 89 91 BYTE *ptr; 90 92 int scheme; 91 93 switch (key->encScheme) { … … int decrypt_sealed_data(TPM_KEY_DATA *ke 96 98 len = enc_size; 97 99 *buf = ptr = tpm_malloc(len); 98 100 if (*buf == NULL 99 || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) 100 || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) { 101 || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){ 102 tpm_free(*buf); 103 return -1; 104 } 105 len32 = len; 106 if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) { 101 107 tpm_free(*buf); 102 108 return -1; 103 109 } … … TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par 240 246 241 247 TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize, 242 248 BYTE *inData, TPM_AUTH *auth1, 243 UINT32 *outDataSize , BYTE **outData)249 UINT32 *outDataSize32, BYTE **outData) 244 250 { 245 251 TPM_RESULT res; 246 252 TPM_KEY_DATA *key; 247 253 int scheme; 254 size_t outDataSize; 248 255 249 256 info("TPM_UnBind()"); 250 257 /* get key */ … … TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key 262 269 /* the size of the input data muss be greater than zero */ 263 270 if (inDataSize == 0) return TPM_BAD_PARAMETER; 264 271 /* decrypt data */ 265 *outDataSize = inDataSize;266 *outData = tpm_malloc( *outDataSize);272 outDataSize = inDataSize; 273 *outData = tpm_malloc(outDataSize); 267 274 if (*outData == NULL) return TPM_NOSPACE; 268 275 switch (key->encScheme) { 269 276 case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break; … … TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key 271 278 default: tpm_free(*outData); return TPM_DECRYPT_ERROR; 272 279 } 273 280 if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 274 *outData, outDataSize)) {281 *outData, &outDataSize)) { 275 282 tpm_free(*outData); 276 283 return TPM_DECRYPT_ERROR; 277 284 } 278 285 /* verify data if it is of type TPM_BOUND_DATA */ 279 286 if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 280 287 || key->keyUsage != TPM_KEY_LEGACY) { 281 if ( *outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {288 if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) { 282 289 tpm_free(*outData); 283 290 return TPM_DECRYPT_ERROR; 284 291 } 285 *outDataSize -= 5;286 memmove(*outData, &(*outData)[5], *outDataSize);292 outDataSize -= 5; 293 memmove(*outData, &(*outData)[5], outDataSize); 287 294 } 295 *outDataSize32 = (UINT32) outDataSize; 288 296 return TPM_SUCCESS; 289 297 } 290 298 … … int compute_pubkey_digest(TPM_PUBKEY *ke 334 342 } 335 343 336 344 int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store, 337 BYTE *enc, UINT32 *enc_size )345 BYTE *enc, UINT32 *enc_size32) 338 346 { 339 347 UINT32 len; 340 348 BYTE *buf, *ptr; 341 349 rsa_public_key_t pub_key; 342 350 int scheme; 351 size_t enc_size; 343 352 switch (key->encScheme) { 344 353 case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break; 345 354 case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break; … … int encrypt_private_key(TPM_KEY_DATA *ke 351 360 if (buf == NULL 352 361 || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store) 353 362 || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)), 354 enc, enc_size)) {363 enc, &enc_size)) { 355 364 tpm_free(buf); 356 365 rsa_release_public_key(&pub_key); 357 366 return -1; 358 367 } 368 *enc_size32 = (UINT32) enc_size; 359 369 tpm_free(buf); 360 370 rsa_release_public_key(&pub_key); 361 371 return 0; … … int encrypt_private_key(TPM_KEY_DATA *ke 364 374 int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 365 375 TPM_STORE_ASYMKEY *store, BYTE **buf) 366 376 { 367 UINT32 len; 377 UINT32 len32; 378 size_t len; 368 379 BYTE *ptr; 369 380 int scheme; 370 381 switch (key->encScheme) { … … int decrypt_private_key(TPM_KEY_DATA *ke 375 386 len = enc_size; 376 387 *buf = ptr = tpm_malloc(len); 377 388 if (*buf == NULL 378 || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) 379 || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) { 389 || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) { 390 tpm_free(*buf); 391 return -1; 392 } 393 len32 = (UINT32) len; 394 if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) { 380 395 tpm_free(*buf); 381 396 return -1; 382 397 } … … TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN 394 409 TPM_SESSION_DATA *session; 395 410 TPM_STORE_ASYMKEY store; 396 411 rsa_private_key_t rsa; 397 UINT32key_length;412 size_t key_length; 398 413 399 414 info("TPM_CreateWrapKey()"); 400 415 /* get parent key */ … … TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN 450 465 } 451 466 } 452 467 /* generate key and store it */ 453 key_length = keyInfo->algorithmParms.parms.rsa.keyLength;454 if (rsa_generate_key(&rsa, key_length))return TPM_FAIL;455 wrappedKey->pubKey.keyLength = key _length >> 3;468 if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 469 return TPM_FAIL; 470 wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3; 456 471 wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength); 457 store.privKey.keyLength = key _length >> 4;472 store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4; 458 473 store.privKey.key = tpm_malloc(store.privKey.keyLength); 459 474 wrappedKey->encDataSize = parent->key.size >> 3; 460 475 wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize); … … TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN 466 481 tpm_free(wrappedKey->encData); 467 482 return TPM_NOSPACE; 468 483 } 469 rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 470 &wrappedKey->pubKey.keyLength); 471 rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength); 484 rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 485 &key_length); 486 wrappedKey->pubKey.keyLength = (UINT32) key_length; 487 rsa_export_prime1(&rsa, store.privKey.key, &key_length); 488 store.privKey.keyLength = (UINT32) key_length; 472 489 rsa_release_private_key(&rsa); 473 490 /* compute the digest of the wrapped key (without encData) */ 474 491 if (compute_key_digest(wrappedKey, &store.pubDataDigest)) { … … TPM_RESULT TPM_LoadKey2(TPM_KEY_HANDLE p 602 619 603 620 int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms) 604 621 { 622 size_t key_length; 605 623 parms->algorithmID = TPM_ALG_RSA; 606 624 parms->encScheme = key->encScheme; 607 625 parms->sigScheme = key->sigScheme; … … int tpm_setup_key_parms(TPM_KEY_DATA *ke 611 629 parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize); 612 630 if (parms->parms.rsa.exponent == NULL) return -1; 613 631 rsa_export_exponent(&key->key, parms->parms.rsa.exponent, 614 &parms->parms.rsa.exponentSize); 632 &key_length); 633 parms->parms.rsa.exponentSize = (UINT32) key_length; 615 634 parms->parmSize = 12 + parms->parms.rsa.exponentSize; 616 635 return 0; 617 636 } … … TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 622 641 TPM_RESULT res; 623 642 TPM_KEY_DATA *key; 624 643 TPM_DIGEST digest; 644 size_t key_length; 625 645 info("TPM_GetPubKey()"); 626 646 /* get key */ 627 647 if (keyHandle == TPM_KH_SRK … … TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 650 670 pubKey->pubKey.keyLength = key->key.size >> 3; 651 671 pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength); 652 672 if (pubKey->pubKey.key == NULL) return TPM_NOSPACE; 653 rsa_export_modulus(&key->key, pubKey->pubKey.key, 654 &pubKey->pubKey.keyLength);673 rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 674 pubKey->pubKey.keyLength = (UINT32) key_length; 655 675 if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) { 656 676 error("TPM_GetPubKey(): tpm_setup_key_parms() failed."); 657 677 tpm_free(pubKey->pubKey.key); -
tpm/tpm_structures.h
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_structures.h tpm_emulator/tpm/tpm_structures.h
old new typedef struct tdTPM_DAA_ISSUER { 1958 1958 TPM_DIGEST DAA_digest_gamma; 1959 1959 BYTE DAA_generic_q[26]; 1960 1960 } TPM_DAA_ISSUER; 1961 #define sizeof_TPM_DAA_ISSUER(s) (2 + (20 * 6) + 26 ) 1961 1962 1962 1963 /* 1963 1964 * TPM_DAA_TPM ([TPM_Part2], Section 22.4) … … typedef struct tdTPM_DAA_TPM { 1973 1974 TPM_DIGEST DAA_rekey; 1974 1975 UINT32 DAA_count; 1975 1976 } TPM_DAA_TPM; 1977 #define sizeof_TPM_DAA_TPM(s) (2 + (4 * 20) + 4) 1976 1978 1977 1979 /* 1978 1980 * TPM_DAA_CONTEXT ([TPM_Part2], Section 22.5) … … typedef struct tdTPM_DAA_CONTEXT { 1987 1989 BYTE DAA_scratch[256]; 1988 1990 BYTE DAA_stage; 1989 1991 } TPM_DAA_CONTEXT; 1992 #define sizeof_TPM_DAA_CONTEXT(s) (2 + (3 * 20) + 256 + 1) 1990 1993 1991 1994 /* 1992 1995 * TPM_DAA_JOINDATA ([TPM_Part2], Section 22.6) … … typedef struct tdTPM_DAA_JOINDATA { 1998 2001 BYTE DAA_join_u1[138]; 1999 2002 TPM_DIGEST DAA_digest_n0; 2000 2003 } TPM_DAA_JOINDATA; 2004 #define sizeof_TPM_DAA_JOINDATA(s) (1 + 1 + 20) 2001 2005 2002 2006 /* 2003 2007 * TPM_DAA_BLOB ([TPM_Part2], Section 22.8) … … typedef struct tdTPM_STCLEAR_DATA { 2202 2206 //UINT32 ownerReference; 2203 2207 //BOOL disableResetLock; 2204 2208 } TPM_STCLEAR_DATA; 2209 #define sizeof_TPM_STCLEAR_DATA(s) (2 + 20 + 4) 2205 2210 2206 2211 /* 2207 2212 * TPM_SESSION_DATA … … typedef struct tdTPM_DAA_SESSION_DATA { 2238 2243 TPM_DAA_JOINDATA DAA_joinSession; 2239 2244 TPM_HANDLE handle; 2240 2245 } TPM_DAA_SESSION_DATA; 2246 #define sizeof_TPM_DAA_SESSION_DATA(s) ( 1 \ 2247 + sizeof_TPM_DAA_ISSUER(s.DAA_issuerSettings) \ 2248 + sizeof_TPM_DAA_TPM(s.DAA_tpmSpecific) \ 2249 + sizeof_TPM_DAA_CONTEXT(s.DAA_session) \ 2250 + sizeof_TPM_DAA_JOINDATA(s.DAA_joinSession) + 4) 2241 2251 2242 2252 /* 2243 2253 * TPM_STANY_DATA ([TPM_Part2], Section 7.6) … … typedef struct tdTPM_STANY_DATA { 2262 2272 TPM_DAAHANDLE currentDAA; 2263 2273 TPM_TRANSHANDLE transExclusive; 2264 2274 } TPM_STANY_DATA; 2275 #define sizeof_TPM_STANY_DATA(s) (2 + 20 + 20 + 1 \ 2276 + sizeof_TPM_CURRENT_TICKS(s.currentTicks) \ 2277 + 4 + (4 * TPM_MAX_SESSION_LIST) \ 2278 + (sizeof_TPM_SESSION_DATA(s.sessions[0]) * TPM_MAX_SESSION_LIST) \ 2279 + (sizeof_TPM_DAA_SESSION_DATA(s.sessionsDAA[0]) * TPM_MAX_SESSIONS_DAA) + 4) 2265 2280 2266 2281 /* 2267 2282 * TPM_DATA -
tpm/tpm_testing.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_testing.c tpm_emulator/tpm/tpm_testing.c
old new 1 1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 2 2 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3 3 * Swiss Federal Institute of Technology (ETH) Zurich 4 * Copyright (C) 2005 INTEL Corp 4 5 * 5 6 * This module is free software; you can redistribute it and/or modify 6 7 * it under the terms of the GNU General Public License as published … … static int tpm_test_sha1(void) 95 96 struct { 96 97 uint8_t *data; uint32_t repetitions; uint8_t *digest; 97 98 } test_cases[] = {{ 98 99 "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D"99 (uint8_t*)"abc", 1, 100 (uint8_t*)"\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D" 100 101 }, { 101 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,102 "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1"102 (uint8_t*)"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1, 103 (uint8_t*)"\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1" 103 104 }, { 104 "a", 1000000,105 "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F"105 (uint8_t*)"a", 1000000, 106 (uint8_t*)"\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F" 106 107 }, { 107 "0123456701234567012345670123456701234567012345670123456701234567", 10,108 "\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52"108 (uint8_t*)"0123456701234567012345670123456701234567012345670123456701234567", 10, 109 (uint8_t*)"\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52" 109 110 }}; 110 111 111 112 debug("tpm_test_sha1()"); 112 113 for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) { 113 114 sha1_init(&ctx); 114 115 for (j = 0; j < test_cases[i].repetitions; j++) 115 sha1_update(&ctx, test_cases[i].data, strlen( test_cases[i].data));116 sha1_update(&ctx, test_cases[i].data, strlen((char*)test_cases[i].data)); 116 117 sha1_final(&ctx, digest); 117 118 if (memcmp(digest, test_cases[i].digest, SHA1_DIGEST_LENGTH) != 0) return -1; 118 119 } … … static int tpm_test_hmac(void) 128 129 struct { 129 130 uint8_t *key, key_len, *data, data_len, *digest; 130 131 } test_cases[] = {{ 131 "\x0b", 20,"Hi There", 8,132 "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00"132 (uint8_t*)"\x0b", 20, (uint8_t*)"Hi There", 8, 133 (uint8_t*)"\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00" 133 134 }, { 134 "Jefe", 4,"what do ya want for nothing?", 28,135 "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79"135 (uint8_t*)"Jefe", 4, (uint8_t*)"what do ya want for nothing?", 28, 136 (uint8_t*)"\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79" 136 137 }, { 137 "\xaa", 20,"\xdd", 50,138 "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3"138 (uint8_t*)"\xaa", 20, (uint8_t*)"\xdd", 50, 139 (uint8_t*)"\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3" 139 140 }, { 140 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"141 "\x15\x16\x17\x18\x19", 25, "\xcd", 50,142 "\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda"141 (uint8_t*)"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 142 "\x15\x16\x17\x18\x19", 25, (uint8_t*)"\xcd", 50, 143 (uint8_t*)"\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda" 143 144 }, { 144 "\x0c", 20,"Test With Truncation", 20,145 "\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04"145 (uint8_t*)"\x0c", 20, (uint8_t*)"Test With Truncation", 20, 146 (uint8_t*)"\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04" 146 147 }, { 147 "\xaa", 80,"Test Using Larger Than Block-Size Key - Hash Key First", 54,148 "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12"148 (uint8_t*)"\xaa", 80, (uint8_t*)"Test Using Larger Than Block-Size Key - Hash Key First", 54, 149 (uint8_t*)"\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12" 149 150 }, { 150 "\xaa", 80,151 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73,152 "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91"151 (uint8_t*)"\xaa", 80, 152 (uint8_t*)"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73, 153 (uint8_t*)"\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91" 153 154 }}; 154 155 155 156 debug("tpm_test_hmac()"); 156 157 for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) { 157 if (strlen( test_cases[i].key) < test_cases[i].key_len) {158 if (strlen((char*)test_cases[i].key) < test_cases[i].key_len) { 158 159 uint8_t key[test_cases[i].key_len]; 159 160 memset(key, test_cases[i].key[0], test_cases[i].key_len); 160 161 hmac_init(&ctx, key, test_cases[i].key_len); 161 162 } else { 162 163 hmac_init(&ctx, test_cases[i].key, test_cases[i].key_len); 163 164 } 164 for (j = 0; j < test_cases[i].data_len; j += strlen( test_cases[i].data)) {165 hmac_update(&ctx, test_cases[i].data, strlen( test_cases[i].data));165 for (j = 0; j < test_cases[i].data_len; j += strlen((char*)test_cases[i].data)) { 166 hmac_update(&ctx, test_cases[i].data, strlen((char*)test_cases[i].data)); 166 167 } 167 168 hmac_final(&ctx, digest); 168 169 if (memcmp(digest, test_cases[i].digest, SHA1_DIGEST_LENGTH) != 0) return -1; … … static int tpm_test_hmac(void) 173 174 static int tpm_test_rsa_EK(void) 174 175 { 175 176 int res = 0; 176 char *data ="RSA PKCS #1 v1.5 Test-String";177 uint8_t *data = (uint8_t*)"RSA PKCS #1 v1.5 Test-String"; 177 178 uint8_t buf[256]; 178 size_t buf_len, data_len = strlen( data);179 size_t buf_len, data_len = strlen((char*)data); 179 180 rsa_private_key_t priv_key; 180 181 rsa_public_key_t pub_key; 181 182 -
tpm/tpm_ticks.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_ticks.c tpm_emulator/tpm/tpm_ticks.c
old new 1 1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 2 2 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 3 3 * Swiss Federal Institute of Technology (ETH) Zurich 4 * Copyright (C) 2005 INTEL Corp 4 5 * 5 6 * This module is free software; you can redistribute it and/or modify 6 7 * it under the terms of the GNU General Public License as published … … TPM_RESULT TPM_SetTickType(TPM_TICKTYPE 39 40 TPM_RESULT TPM_GetTicks(TPM_CURRENT_TICKS *currentTime) 40 41 { 41 42 info("TPM_GetTicks()"); 42 memcpy(currentTime, &tpmData.stany.data.currentTicks, 43 sizeof(TPM_CURRENT_TICKS)); 44 return TPM_SUCCESS; 43 return TPM_DISABLED_CMD; 45 44 } 46 45 47 46 TPM_RESULT TPM_TickStampBlob(TPM_KEY_HANDLE keyHandle, TPM_NONCE *antiReplay, … … TPM_RESULT TPM_TickStampBlob(TPM_KEY_HAN 49 48 TPM_CURRENT_TICKS *currentTicks, 50 49 UINT32 *sigSize, BYTE **sig) 51 50 { 52 TPM_RESULT res;53 TPM_KEY_DATA *key;54 BYTE *info, *p;55 UINT32 info_length, length;56 51 info("TPM_TickStampBlob()"); 57 /* get key */ 58 key = tpm_get_key(keyHandle); 59 if (key == NULL) return TPM_INVALID_KEYHANDLE; 60 /* verify authorization */ 61 res = tpm_verify_auth(auth1, key->usageAuth, keyHandle); 62 if (res != TPM_SUCCESS) return res; 63 if (key->keyUsage != TPM_KEY_SIGNING && key->keyUsage != TPM_KEY_LEGACY 64 && key->keyUsage != TPM_KEY_IDENTITY) return TPM_INVALID_KEYUSAGE; 65 /* get current ticks */ 66 TPM_GetTicks(currentTicks); 67 /* sign data using signature scheme PKCS1_SHA1 and TPM_SIGN_INFO container */ 68 *sigSize = key->key.size >> 3; 69 *sig = tpm_malloc(*sigSize); 70 if (*sig == NULL) return TPM_FAIL; 71 /* setup TPM_SIGN_INFO structure */ 72 info_length = 30 + sizeof(TPM_DIGEST) + sizeof_TPM_CURRENT_TICKS(currentTicks); 73 info = tpm_malloc(info_length); 74 if (info == NULL) { 75 tpm_free(*sig); 76 return TPM_FAIL; 77 } 78 memcpy(&info[0], "\x05\x00TSTP", 6); 79 memcpy(&info[6], antiReplay->nonce, 20); 80 *(UINT32*)&info[26] = CPU_TO_BE32(20 81 + sizeof_TPM_CURRENT_TICKS(currentTicks)); 82 memcpy(&info[30], digestToStamp->digest, sizeof(TPM_DIGEST)); 83 p = &info[30 + sizeof(TPM_DIGEST)]; 84 length = sizeof_TPM_CURRENT_TICKS(currentTicks); 85 if (tpm_marshal_TPM_CURRENT_TICKS(&p, &length, currentTicks) 86 || rsa_sign(&key->key, RSA_SSA_PKCS1_SHA1, info, info_length, *sig)) { 87 tpm_free(*sig); 88 tpm_free(info); 89 return TPM_FAIL; 90 } 91 return TPM_SUCCESS; 52 return TPM_DISABLED_CMD; 92 53 } 93 54 94 55 void tpm_update_ticks(void) 95 56 { 96 if (tpmData.stany.data.currentTicks.tag == 0) {97 tpmData.stany.data.currentTicks.tag = TPM_TAG_CURRENT_TICKS;98 tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks();99 /* removed since v1.2 rev 94100 tpmData.stany.data.currentTicks.tickType = tpmData.permanent.data.tickType;101 */102 tpm_get_random_bytes(tpmData.stany.data.currentTicks.tickNonce.nonce,103 sizeof(TPM_NONCE));104 tpmData.stany.data.currentTicks.tickRate = 1;105 /* removed since v1.2 rev 94106 tpmData.stany.data.currentTicks.tickSecurity = TICK_SEC_NO_CHECK;107 */108 } else {109 tpmData.stany.data.currentTicks.currentTicks += tpm_get_ticks();110 }111 57 } 112 58 -
tpm/tpm_transport.c
diff -uprN orig/tpm_emulator-0.4/tpm/tpm_transport.c tpm_emulator/tpm/tpm_transport.c
old new static void decrypt_wrapped_command(BYTE 189 189 sha1_init(&sha1); 190 190 sha1_update(&sha1, auth->nonceEven.nonce, sizeof(auth->nonceEven.nonce)); 191 191 sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce)); 192 sha1_update(&sha1, "in", 2);192 sha1_update(&sha1, (BYTE*)"in", 2); 193 193 sha1_update(&sha1, secret, sizeof(TPM_SECRET)); 194 194 j = CPU_TO_BE32(i); 195 195 sha1_update(&sha1, (BYTE*)&j, 4); … … static void encrypt_wrapped_command(BYTE 211 211 sha1_init(&sha1); 212 212 sha1_update(&sha1, auth->nonceEven.nonce, sizeof(auth->nonceEven.nonce)); 213 213 sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce)); 214 sha1_update(&sha1, "out", 3);214 sha1_update(&sha1, (BYTE*)"out", 3); 215 215 sha1_update(&sha1, secret, sizeof(TPM_SECRET)); 216 216 j = CPU_TO_BE32(i); 217 217 sha1_update(&sha1, (BYTE*)&j, 4); -
tpmd.c
diff -uprN orig/tpm_emulator-0.4/tpmd.c tpm_emulator/tpmd.c
old new 1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 2 * Copyright (C) 2005 INTEL Corp 3 * 4 * This module is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published 6 * by the Free Software Foundation; either version 2 of the License, 7 * or (at your option) any later version. 8 * 9 * This module is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 */ 15 16 #include <stdio.h> 17 #include <stdlib.h> 18 #include <unistd.h> 19 #include <string.h> 20 #include <sys/types.h> 21 #include <sys/stat.h> 22 #include <fcntl.h> 23 #include <sys/time.h> 24 25 #include "tpm_emulator.h" 26 27 #define TPM_RX_FNAME "/var/tpm/tpm_in.fifo" 28 #define TPM_TX_FNAME "/var/tpm/tpm_out.fifo" 29 30 #define BUFFER_SIZE 2048 31 32 static int devurandom=0; 33 34 void get_random_bytes(void *buf, int nbytes) { 35 36 if (devurandom == 0) { 37 devurandom = open("/dev/urandom", O_RDONLY); 38 } 39 40 if (read(devurandom, buf, nbytes) != nbytes) { 41 printf("Can't get random number.\n"); 42 exit(-1); 43 } 44 } 45 46 uint64_t tpm_get_ticks(void) 47 { 48 //struct timeval tv; 49 //int gettimeofday(&tv, struct timezone *tz); 50 return 0; 51 } 52 53 int main(int argc, char **argv) 54 { 55 uint8_t in[BUFFER_SIZE], *out; 56 uint32_t out_size; 57 int in_size, written; 58 int i; 59 struct stat file_info; 60 61 int tpm_tx_fh=-1, tpm_rx_fh=-1; 62 if (argc < 2) { 63 printf("Usage: tpmd clear|save|deactivated\n" ); 64 return -1; 65 } 66 67 /* initialize TPM emulator */ 68 if (!strcmp(argv[1], "clear")) { 69 printf("Initializing tpm: %s\n", argv[1]); 70 tpm_emulator_init(1); 71 } else if (!strcmp(argv[1], "save")) { 72 printf("Initializing tpm: %s\n", argv[1]); 73 tpm_emulator_init(2); 74 } else if (!strcmp(argv[1], "deactivated")) { 75 printf("Initializing tpm: %s\n", argv[1]); 76 tpm_emulator_init(3); 77 } else { 78 printf("invalid startup mode '%s'; must be 'clear', " 79 "'save' (default) or 'deactivated", argv[1]); 80 return -1; 81 } 82 83 if ( stat(TPM_RX_FNAME, &file_info) == -1) { 84 if ( mkfifo(TPM_RX_FNAME, S_IWUSR | S_IRUSR ) ) { 85 printf("Failed to create fifo %s.\n", TPM_RX_FNAME); 86 return -1; 87 } 88 } 89 90 if ( stat(TPM_TX_FNAME, &file_info) == -1) { 91 if ( mkfifo(TPM_TX_FNAME, S_IWUSR | S_IRUSR ) ) { 92 printf("Failed to create fifo %s.\n", TPM_TX_FNAME); 93 return -1; 94 } 95 } 96 97 while (1) { 98 abort_command: 99 if (tpm_rx_fh < 0) { 100 tpm_rx_fh = open(TPM_RX_FNAME, O_RDONLY); 101 } 102 103 if (tpm_rx_fh < 0) { 104 printf("ERROR: failed to open devices to listen to guest.\n"); 105 return -1; 106 } 107 108 if (tpm_tx_fh < 0) { 109 tpm_tx_fh = open(TPM_TX_FNAME, O_WRONLY); 110 } 111 112 if (tpm_tx_fh < 0) { 113 printf("ERROR: failed to open devices to respond to guest.\n"); 114 return -1; 115 } 116 117 in_size = read(tpm_rx_fh, in, BUFFER_SIZE); 118 if (in_size < 6) { // Magic size of minium TPM command 119 printf("Recv[%d] to small: 0x", in_size); 120 if (in_size <= 0) { 121 close(tpm_rx_fh); 122 tpm_rx_fh = -1; 123 goto abort_command; 124 } 125 } else { 126 printf("Recv[%d]: 0x", in_size); 127 for (i=0; i< in_size; i++) 128 printf("%x ", in[i]); 129 printf("\n"); 130 } 131 132 133 if (tpm_handle_command(in, in_size, &out, &out_size) != 0) { 134 printf("ERROR: Handler Failed.\n"); 135 } 136 137 written = write(tpm_tx_fh, out, out_size); 138 139 if (written != out_size ) { 140 printf("ERROR: Part of response not written %d/%d.\nAttempt: ", written, out_size); 141 } else { 142 printf("Sent[%Zu]: ", out_size); 143 } 144 for (i=0; i< out_size; i++) 145 printf("%x ", out[i]); 146 printf("\n"); 147 tpm_free(out); 148 149 } // loop 150 151 tpm_emulator_shutdown(); 152 153 close(tpm_tx_fh); 154 close(tpm_rx_fh); 155 156 } -
tpm_version.h
Binary files orig/tpm_emulator-0.4/tpm_emulator and tpm_emulator/tpm_emulator differ diff -uprN orig/tpm_emulator-0.4/tpm_version.h tpm_emulator/tpm_version.h
old new 2 2 #define _TPM_VERSION_H_ 3 3 #define VERSION_MAJOR 0 4 4 #define VERSION_MINOR 4 5 #define VERSION_BUILD 115 10587345 #define VERSION_BUILD 1153776940 6 6 #endif /* _TPM_VERSION_H_ */
Note: See TracBrowser
for help on using the repository browser.