diff options
author | Allen Webb <allenwebb@google.com> | 2018-02-21 11:23:27 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2018-12-05 00:50:20 +0000 |
commit | 92df7b7a32728f58d95a4afba92a8eec51bb29cf (patch) | |
tree | 377c72c2a2d6b5560cd9cceb77e2b43ae02f5bfd | |
parent | 7abac570c4f6b22d87469818221cd665c48d3923 (diff) | |
download | chrome-ec-92df7b7a32728f58d95a4afba92a8eec51bb29cf.tar.gz |
Cr50: Add VENDOR_CC_PINWEAVER vendor command.
This connects the pinweaver code to the tpm vendor
specific command code.
CQ-DEPEND=CL:895395
BRANCH=none
BUG=chromium:809741
TEST=TBD
Change-Id: I2a6c4bf52ad77b7bf0395095404e925e1dd48dbc
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/929430
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/1333292
Reviewed-by: Marco Chen <marcochen@chromium.org>
Commit-Queue: Marco Chen <marcochen@chromium.org>
Tested-by: Marco Chen <marcochen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/1360492
Reviewed-by: Chia-Hsiu Chang <chia-hsiu.chang@quanta.corp-partner.google.com>
Tested-by: Chia-Hsiu Chang <chia-hsiu.chang@quanta.corp-partner.google.com>
Commit-Queue: Chia-Hsiu Chang <chia-hsiu.chang@quanta.corp-partner.google.com>
-rw-r--r-- | common/pinweaver.c | 64 | ||||
-rw-r--r-- | include/tpm_vendor_cmds.h | 1 |
2 files changed, 59 insertions, 6 deletions
diff --git a/common/pinweaver.c b/common/pinweaver.c index 63e1a4522e..a1743d8fdc 100644 --- a/common/pinweaver.c +++ b/common/pinweaver.c @@ -6,10 +6,13 @@ #include <common.h> #include <console.h> #include <dcrypto.h> +#include <extension.h> +#include <hooks.h> #include <pinweaver.h> #include <pinweaver_tpm_imports.h> #include <pinweaver_types.h> #include <timer.h> +#include <tpm_vendor_cmds.h> #include <trng.h> #include <tpm_registers.h> #include <util.h> @@ -35,13 +38,13 @@ BUILD_ASSERT(PW_MAX_MESSAGE_SIZE >= sizeof(struct leaf_sensitive_data_t) + PW_MAX_PATH_SIZE); +#define PW_MAX_RESPONSE_SIZE (sizeof(struct pw_response_header_t) + \ + sizeof(union {struct pw_response_insert_leaf_t insert_leaf; \ + struct pw_response_try_auth_t try_auth; \ + struct pw_response_reset_auth_t reset_auth; }) + \ + PW_LEAF_PAYLOAD_SIZE) /* Verify that the request structs will fit into the message. */ -BUILD_ASSERT(PW_MAX_MESSAGE_SIZE >= - sizeof(struct pw_response_header_t) + - sizeof(union {struct pw_response_insert_leaf_t insert_leaf; - struct pw_response_try_auth_t try_auth; - struct pw_response_reset_auth_t reset_auth; }) + - PW_LEAF_PAYLOAD_SIZE); +BUILD_ASSERT(PW_MAX_MESSAGE_SIZE >= PW_MAX_RESPONSE_SIZE); /* Make sure the largest possible message would fit in * (struct tpm_register_file).data_fifo. */ @@ -787,6 +790,55 @@ static int pw_handle_reset_auth(struct merkle_tree_t *merkle_tree, return ret; } +struct merkle_tree_t pw_merkle_tree; + +/* + * Handle the VENDOR_CC_PINWEAVER command. + */ +static enum vendor_cmd_rc pw_vendor_specific_command(enum vendor_cmd_cc code, + void *buf, + size_t input_size, + size_t *response_size) +{ + const struct pw_request_t *request = buf; + struct pw_response_t *response = buf; + + if (input_size < sizeof(request->header)) { + ccprintf("PinWeaver: message smaller than a header (%d).\n", + input_size); + return VENDOR_RC_INTERNAL_ERROR; + } + + if (input_size != request->header.data_length + + sizeof(request->header)) { + ccprintf("PinWeaver: header size mismatch %d != %d.\n", + input_size, request->header.data_length + + sizeof(request->header)); + return VENDOR_RC_REQUEST_TOO_BIG; + } + + /* The response_size is validated by compile time checks. */ + + /* The return value of this function call is intentionally unused. */ + pw_handle_request(&pw_merkle_tree, request, response); + + *response_size = response->header.data_length + + sizeof(response->header); + + /* The response is only sent for EC_SUCCESS so it is used even for + * errors which are reported through header.return_code. + */ + return VENDOR_RC_SUCCESS; +} +DECLARE_VENDOR_COMMAND(VENDOR_CC_PINWEAVER, + pw_vendor_specific_command); + +static void pinweaver_init(void) +{ + /* TODO(allenwebb) load merkle_tree from flash here. */ +} +DECLARE_HOOK(HOOK_INIT, pinweaver_init, HOOK_PRIO_LAST); + /******************************************************************************/ /* Non-static functions. */ diff --git a/include/tpm_vendor_cmds.h b/include/tpm_vendor_cmds.h index 6867e999eb..92530c502a 100644 --- a/include/tpm_vendor_cmds.h +++ b/include/tpm_vendor_cmds.h @@ -58,6 +58,7 @@ enum vendor_cmd_cc { VENDOR_CC_CCD = 34, VENDOR_CC_GET_ALERTS_DATA = 35, VENDOR_CC_SPI_HASH = 36, + VENDOR_CC_PINWEAVER = 37, LAST_VENDOR_COMMAND = 65535, }; |