Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: src/platform/tpm_lite/src/tlcl/tlcl.c

Issue 847005: Bug fixes and timing code. This is the first fully functional code, (Closed)
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 /* A lightweight TPM command library. 6 /* A lightweight TPM command library.
7 * 7 *
8 * The general idea is that TPM commands are array of bytes whose fields are 8 * The general idea is that TPM commands are array of bytes whose fields are
9 * mostly compile-time constant. The goal is to build much of the commands at 9 * mostly compile-time constant. The goal is to build much of the commands at
10 * compile time (or build time) and change some of the fields at run time as 10 * compile time (or build time) and change some of the fields at run time as
11 * needed. The code in generator.c builds structures containing the commands, 11 * needed. The code in generator.c builds structures containing the commands,
12 * as well as the offsets of the fields that need to be set at run time. 12 * as well as the offsets of the fields that need to be set at run time.
13 */ 13 */
14 14
15 #include "tlcl.h" 15 #include "tlcl.h"
16 16
17 #include <errno.h> 17 #include <errno.h>
18 #include <fcntl.h> 18 #include <fcntl.h>
19 #include <string.h> 19 #include <string.h>
20 #include <sys/time.h>
20 #include <sys/types.h> 21 #include <sys/types.h>
21 #include <sys/stat.h> 22 #include <sys/stat.h>
22 #include <tss/tcs.h> 23 #include <tss/tcs.h>
23 #include <unistd.h> 24 #include <unistd.h>
24 25
25 #include "structures.h" 26 #include "structures.h"
26 #include "tlcl_internal.h" 27 #include "tlcl_internal.h"
27 #if USE_TPM_EMULATOR 28 #if USE_TPM_EMULATOR
28 #include "tpmemu.h" 29 #include "tpmemu.h"
29 #endif 30 #endif
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 128
128 /* Sends a request and receive a response. 129 /* Sends a request and receive a response.
129 */ 130 */
130 static void SendReceive(uint8_t* request, uint8_t* response, int max_length) { 131 static void SendReceive(uint8_t* request, uint8_t* response, int max_length) {
131 uint32_t response_length = max_length; 132 uint32_t response_length = max_length;
132 int tag, response_tag; 133 int tag, response_tag;
133 134
134 #if USE_TPM_EMULATOR 135 #if USE_TPM_EMULATOR
135 tpmemu_execute(request, TpmCommandSize(request), response, &response_length); 136 tpmemu_execute(request, TpmCommandSize(request), response, &response_length);
136 #else 137 #else
138 struct timeval before, after;
139 gettimeofday(&before, NULL);
gauravsh 2010/03/13 00:47:47 For better precision I would recommend using clock
137 TpmExecute(request, TpmCommandSize(request), response, &response_length); 140 TpmExecute(request, TpmCommandSize(request), response, &response_length);
141 gettimeofday(&after, NULL);
138 #endif 142 #endif
139 143
140 { 144 {
141 int x = TpmCommandSize(request); 145 int x = TpmCommandSize(request);
142 int y = response_length; 146 int y = response_length;
143 printf("request (%d bytes): ", x); 147 printf("request (%d bytes): ", x);
144 PrintBytes(request, 10); 148 PrintBytes(request, 10);
145 PrintBytes(request + 10, x - 10); 149 PrintBytes(request + 10, x - 10);
146 printf("response (%d bytes): ", y); 150 printf("response (%d bytes): ", y);
147 PrintBytes(response, 10); 151 PrintBytes(response, 10);
148 PrintBytes(response + 10, y - 10); 152 PrintBytes(response + 10, y - 10);
153 printf("execution time: %dms\n",
154 (int) ((after.tv_sec - before.tv_sec) * 1000 +
155 (after.tv_usec - before.tv_usec) / 1000));
149 } 156 }
150 157
151 /* sanity checks */ 158 /* sanity checks */
152 tag = TpmTag(request); 159 tag = TpmTag(request);
153 response_tag = TpmTag(response); 160 response_tag = TpmTag(response);
154 assert( 161 assert(
155 (tag == TPM_TAG_RQU_COMMAND && 162 (tag == TPM_TAG_RQU_COMMAND &&
156 response_tag == TPM_TAG_RSP_COMMAND) || 163 response_tag == TPM_TAG_RSP_COMMAND) ||
157 (tag == TPM_TAG_RQU_AUTH1_COMMAND && 164 (tag == TPM_TAG_RQU_AUTH1_COMMAND &&
158 response_tag == TPM_TAG_RSP_AUTH1_COMMAND) || 165 response_tag == TPM_TAG_RSP_AUTH1_COMMAND) ||
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 TlclDefineSpace(TPM_NV_INDEX_LOCK, 0, 0); 266 TlclDefineSpace(TPM_NV_INDEX_LOCK, 0, 0);
260 } 267 }
261 268
262 int TlclIsOwned(void) { 269 int TlclIsOwned(void) {
263 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE + TPM_PUBEK_SIZE]; 270 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE + TPM_PUBEK_SIZE];
264 uint32_t result; 271 uint32_t result;
265 SendReceive(tpm_readpubek_cmd.buffer, response, sizeof(response)); 272 SendReceive(tpm_readpubek_cmd.buffer, response, sizeof(response));
266 result = TpmReturnCode(response); 273 result = TpmReturnCode(response);
267 return (result != TPM_SUCCESS); 274 return (result != TPM_SUCCESS);
268 } 275 }
OLDNEW
« no previous file with comments | « src/platform/tpm_lite/src/tlcl/generator.c ('k') | src/platform/tpm_lite/src/tlcl/tlcl_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698