Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | */ |
| 5 | |
| 6 | /* A lightweight TPM command library. |
| 7 | * |
| 8 | * The general idea is that TPM commands are array of bytes whose |
| 9 | * fields are mostly compile-time constant. The goal is to build much |
| 10 | * of the commands at compile time (or build time) and change some of |
| 11 | * the fields at run time as needed. The code in |
| 12 | * utility/tlcl_generator.c builds structures containing the commands, |
| 13 | * as well as the offsets of the fields that need to be set at run |
| 14 | * time. |
| 15 | */ |
| 16 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 17 | #include <assert.h> |
Randall Spangler | 144c228 | 2014-12-03 17:35:53 -0800 | [diff] [blame] | 18 | #include <string.h> |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 19 | #include <tpm_lite/tlcl.h> |
| 20 | #include <tpm.h> |
Randall Spangler | 144c228 | 2014-12-03 17:35:53 -0800 | [diff] [blame] | 21 | #include <vb2_api.h> |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 22 | #include "tlcl_internal.h" |
| 23 | #include "tlcl_structures.h" |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 24 | |
| 25 | #ifdef FOR_TEST |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #define VBDEBUG(format, args...) printf(format, ## args) |
| 28 | #else |
| 29 | #include <console/console.h> |
| 30 | #define VBDEBUG(format, args...) printk(BIOS_DEBUG, format, ## args) |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 31 | #endif |
| 32 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 33 | static int tpm_send_receive(const uint8_t *request, |
| 34 | uint32_t request_length, |
| 35 | uint8_t *response, |
| 36 | uint32_t *response_length) |
| 37 | { |
| 38 | size_t len = *response_length; |
| 39 | if (tis_sendrecv(request, request_length, response, &len)) |
| 40 | return VB2_ERROR_UNKNOWN; |
| 41 | /* check 64->32bit overflow and (re)check response buffer overflow */ |
| 42 | if (len > *response_length) |
| 43 | return VB2_ERROR_UNKNOWN; |
| 44 | *response_length = len; |
| 45 | return VB2_SUCCESS; |
| 46 | } |
| 47 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 48 | /* Sets the size field of a TPM command. */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 49 | static inline void set_tpm_command_size(uint8_t* buffer, uint32_t size) { |
| 50 | to_tpm_uint32(buffer + sizeof(uint16_t), size); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /* Gets the size field of a TPM command. */ |
| 54 | __attribute__((unused)) |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 55 | static inline int tpm_command_size(const uint8_t* buffer) { |
| 56 | uint32_t size; |
| 57 | from_tpm_uint32(buffer + sizeof(uint16_t), &size); |
| 58 | return (int) size; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* Gets the code field of a TPM command. */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 62 | static inline int tpm_command_code(const uint8_t* buffer) { |
| 63 | uint32_t code; |
| 64 | from_tpm_uint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &code); |
| 65 | return code; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /* Gets the return code field of a TPM result. */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 69 | static inline int tpm_return_code(const uint8_t* buffer) { |
| 70 | return tpm_command_code(buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* Like TlclSendReceive below, but do not retry if NEEDS_SELFTEST or |
| 74 | * DOING_SELFTEST errors are returned. |
| 75 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 76 | static uint32_t tlcl_send_receive_no_retry(const uint8_t* request, |
| 77 | uint8_t* response, int max_length) { |
| 78 | uint32_t response_length = max_length; |
| 79 | uint32_t result; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 80 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 81 | result = tpm_send_receive(request, tpm_command_size(request), |
| 82 | response, &response_length); |
| 83 | if (0 != result) { |
| 84 | /* Communication with TPM failed, so response is garbage */ |
| 85 | VBDEBUG("TPM: command 0x%x send/receive failed: 0x%x\n", |
| 86 | tpm_command_code(request), result); |
| 87 | return result; |
| 88 | } |
| 89 | /* Otherwise, use the result code from the response */ |
| 90 | result = tpm_return_code(response); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 91 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 92 | /* TODO: add paranoia about returned response_length vs. max_length |
| 93 | * (and possibly expected length from the response header). See |
| 94 | * crosbug.com/17017 */ |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 95 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 96 | VBDEBUG("TPM: command 0x%x returned 0x%x\n", |
| 97 | tpm_command_code(request), result); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 98 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 99 | return result; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | |
| 103 | /* Sends a TPM command and gets a response. Returns 0 if success or the TPM |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 104 | * error code if error. Waits for the self test to complete if needed. */ |
| 105 | uint32_t tlcl_send_receive(const uint8_t* request, uint8_t* response, |
| 106 | int max_length) { |
| 107 | uint32_t result = tlcl_send_receive_no_retry(request, response, |
| 108 | max_length); |
| 109 | /* If the command fails because the self test has not completed, try it |
| 110 | * again after attempting to ensure that the self test has completed. */ |
| 111 | if (result == TPM_E_NEEDS_SELFTEST || result == TPM_E_DOING_SELFTEST) { |
| 112 | result = tlcl_continue_self_test(); |
| 113 | if (result != TPM_SUCCESS) |
| 114 | return result; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 115 | #if defined(TPM_BLOCKING_CONTINUESELFTEST) || defined(VB_RECOVERY_MODE) |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 116 | /* Retry only once */ |
| 117 | result = tlcl_send_receive_no_retry(request, response, |
| 118 | max_length); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 119 | #else |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 120 | /* This needs serious testing. The TPM specification says: "iii. |
| 121 | * The caller MUST wait for the actions of TPM_ContinueSelfTest |
| 122 | * to complete before reissuing the command C1." But, if |
| 123 | * ContinueSelfTest is non-blocking, how do we know that the |
| 124 | * actions have completed other than trying again? */ |
| 125 | do { |
| 126 | result = tlcl_send_receive_no_retry(request, response, |
| 127 | max_length); |
| 128 | } while (result == TPM_E_DOING_SELFTEST); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 129 | #endif |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 130 | } |
| 131 | return result; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* Sends a command and returns the error code. */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 135 | static uint32_t send(const uint8_t* command) { |
| 136 | uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
| 137 | return tlcl_send_receive(command, response, sizeof(response)); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* Exported functions. */ |
| 141 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 142 | uint32_t tlcl_lib_init(void) { |
| 143 | if (tis_init()) |
| 144 | return VB2_ERROR_UNKNOWN; |
| 145 | if (tis_open()) |
| 146 | return VB2_ERROR_UNKNOWN; |
| 147 | return VB2_SUCCESS; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 150 | uint32_t tlcl_startup(void) { |
| 151 | VBDEBUG("TPM: Startup\n"); |
| 152 | return send(tpm_startup_cmd.buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 155 | uint32_t tlcl_resume(void) { |
| 156 | VBDEBUG("TPM: Resume\n"); |
| 157 | return send(tpm_resume_cmd.buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 160 | uint32_t tlcl_self_test_full(void) |
| 161 | { |
| 162 | VBDEBUG("TPM: Self test full\n"); |
| 163 | return send(tpm_selftestfull_cmd.buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 166 | uint32_t tlcl_continue_self_test(void) |
| 167 | { |
| 168 | uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
| 169 | VBDEBUG("TPM: Continue self test\n"); |
| 170 | /* Call the No Retry version of SendReceive to avoid recursion. */ |
| 171 | return tlcl_send_receive_no_retry(tpm_continueselftest_cmd.buffer, |
| 172 | response, sizeof(response)); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 175 | uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size) |
| 176 | { |
| 177 | struct s_tpm_nv_definespace_cmd cmd; |
| 178 | VBDEBUG("TPM: TlclDefineSpace(0x%x, 0x%x, %d)\n", index, perm, size); |
| 179 | memcpy(&cmd, &tpm_nv_definespace_cmd, sizeof(cmd)); |
| 180 | to_tpm_uint32(cmd.buffer + tpm_nv_definespace_cmd.index, index); |
| 181 | to_tpm_uint32(cmd.buffer + tpm_nv_definespace_cmd.perm, perm); |
| 182 | to_tpm_uint32(cmd.buffer + tpm_nv_definespace_cmd.size, size); |
| 183 | return send(cmd.buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 186 | uint32_t tlcl_write(uint32_t index, const void* data, uint32_t length) |
| 187 | { |
| 188 | struct s_tpm_nv_write_cmd cmd; |
| 189 | uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
| 190 | const int total_length = |
| 191 | kTpmRequestHeaderLength + kWriteInfoLength + length; |
| 192 | |
| 193 | VBDEBUG("TPM: tlcl_write(0x%x, %d)\n", index, length); |
| 194 | memcpy(&cmd, &tpm_nv_write_cmd, sizeof(cmd)); |
| 195 | assert(total_length <= TPM_LARGE_ENOUGH_COMMAND_SIZE); |
| 196 | set_tpm_command_size(cmd.buffer, total_length); |
| 197 | |
| 198 | to_tpm_uint32(cmd.buffer + tpm_nv_write_cmd.index, index); |
| 199 | to_tpm_uint32(cmd.buffer + tpm_nv_write_cmd.length, length); |
| 200 | memcpy(cmd.buffer + tpm_nv_write_cmd.data, data, length); |
| 201 | |
| 202 | return tlcl_send_receive(cmd.buffer, response, sizeof(response)); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 205 | uint32_t tlcl_read(uint32_t index, void* data, uint32_t length) |
| 206 | { |
| 207 | struct s_tpm_nv_read_cmd cmd; |
| 208 | uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
| 209 | uint32_t result_length; |
| 210 | uint32_t result; |
| 211 | |
| 212 | VBDEBUG("TPM: tlcl_read(0x%x, %d)\n", index, length); |
| 213 | memcpy(&cmd, &tpm_nv_read_cmd, sizeof(cmd)); |
| 214 | to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.index, index); |
| 215 | to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.length, length); |
| 216 | |
| 217 | result = tlcl_send_receive(cmd.buffer, response, sizeof(response)); |
| 218 | if (result == TPM_SUCCESS && length > 0) { |
| 219 | uint8_t* nv_read_cursor = response + kTpmResponseHeaderLength; |
| 220 | from_tpm_uint32(nv_read_cursor, &result_length); |
| 221 | nv_read_cursor += sizeof(uint32_t); |
| 222 | memcpy(data, nv_read_cursor, result_length); |
| 223 | } |
| 224 | |
| 225 | return result; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 228 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 229 | uint32_t tlcl_assert_physical_presence(void) { |
| 230 | VBDEBUG("TPM: Asserting physical presence\n"); |
| 231 | return send(tpm_ppassert_cmd.buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 234 | uint32_t tlcl_physical_presence_cmd_enable(void) { |
| 235 | VBDEBUG("TPM: Enable the physical presence command\n"); |
| 236 | return send(tpm_ppenable_cmd.buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 239 | uint32_t tlcl_finalize_physical_presence(void) { |
| 240 | VBDEBUG("TPM: Enable PP cmd, disable HW pp, and set lifetime lock\n"); |
| 241 | return send(tpm_finalizepp_cmd.buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 244 | uint32_t tlcl_set_nv_locked(void) { |
| 245 | VBDEBUG("TPM: Set NV locked\n"); |
| 246 | return tlcl_define_space(TPM_NV_INDEX_LOCK, 0, 0); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 249 | uint32_t tlcl_force_clear(void) { |
| 250 | VBDEBUG("TPM: Force clear\n"); |
| 251 | return send(tpm_forceclear_cmd.buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 254 | uint32_t tlcl_set_enable(void) { |
| 255 | VBDEBUG("TPM: Enabling TPM\n"); |
| 256 | return send(tpm_physicalenable_cmd.buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 259 | uint32_t tlcl_set_deactivated(uint8_t flag) |
| 260 | { |
| 261 | struct s_tpm_physicalsetdeactivated_cmd cmd; |
| 262 | VBDEBUG("TPM: SetDeactivated(%d)\n", flag); |
| 263 | memcpy(&cmd, &tpm_physicalsetdeactivated_cmd, sizeof(cmd)); |
| 264 | *(cmd.buffer + cmd.deactivated) = flag; |
| 265 | return send(cmd.buffer); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 268 | uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS* pflags) |
| 269 | { |
| 270 | uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
| 271 | uint32_t size; |
| 272 | uint32_t result = tlcl_send_receive(tpm_getflags_cmd.buffer, response, |
| 273 | sizeof(response)); |
| 274 | if (result != TPM_SUCCESS) |
| 275 | return result; |
| 276 | from_tpm_uint32(response + kTpmResponseHeaderLength, &size); |
| 277 | assert(size == sizeof(TPM_PERMANENT_FLAGS)); |
| 278 | memcpy(pflags, response + kTpmResponseHeaderLength + sizeof(size), |
| 279 | sizeof(TPM_PERMANENT_FLAGS)); |
| 280 | return result; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 283 | uint32_t tlcl_get_flags(uint8_t* disable, uint8_t* deactivated, |
| 284 | uint8_t *nvlocked) |
| 285 | { |
| 286 | TPM_PERMANENT_FLAGS pflags; |
| 287 | uint32_t result = tlcl_get_permanent_flags(&pflags); |
| 288 | if (result == TPM_SUCCESS) { |
| 289 | if (disable) |
| 290 | *disable = pflags.disable; |
| 291 | if (deactivated) |
| 292 | *deactivated = pflags.deactivated; |
| 293 | if (nvlocked) |
| 294 | *nvlocked = pflags.nvLocked; |
| 295 | VBDEBUG("TPM: flags disable=%d, deactivated=%d, nvlocked=%d\n", |
| 296 | pflags.disable, pflags.deactivated, pflags.nvLocked); |
| 297 | } |
| 298 | return result; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 301 | uint32_t tlcl_set_global_lock(void) |
| 302 | { |
| 303 | uint32_t x; |
| 304 | VBDEBUG("TPM: Set global lock\n"); |
| 305 | return tlcl_write(TPM_NV_INDEX0, (uint8_t*) &x, 0); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 308 | uint32_t tlcl_extend(int pcr_num, const uint8_t* in_digest, |
| 309 | uint8_t* out_digest) |
| 310 | { |
| 311 | struct s_tpm_extend_cmd cmd; |
| 312 | uint8_t response[kTpmResponseHeaderLength + kPcrDigestLength]; |
| 313 | uint32_t result; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 314 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 315 | memcpy(&cmd, &tpm_extend_cmd, sizeof(cmd)); |
| 316 | to_tpm_uint32(cmd.buffer + tpm_extend_cmd.pcrNum, pcr_num); |
| 317 | memcpy(cmd.buffer + cmd.inDigest, in_digest, kPcrDigestLength); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 318 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 319 | result = tlcl_send_receive(cmd.buffer, response, sizeof(response)); |
| 320 | if (result != TPM_SUCCESS) |
| 321 | return result; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 322 | |
Julius Werner | 76e3303 | 2015-01-30 18:45:27 -0800 | [diff] [blame] | 323 | if (out_digest) |
| 324 | memcpy(out_digest, response + kTpmResponseHeaderLength, |
| 325 | kPcrDigestLength); |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 326 | return result; |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 327 | } |