From patchwork Thu Nov 26 21:07:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 333052 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp1633445ilb; Thu, 26 Nov 2020 13:07:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzd5AvE5I29u9UrvOYaUfMz6Ui5L4AJfobW4Y/AS+dbikt2WmjdZOJew7XHEaZSmZA4yQzD X-Received: by 2002:a17:906:6987:: with SMTP id i7mr4619279ejr.18.1606424857663; Thu, 26 Nov 2020 13:07:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606424857; cv=none; d=google.com; s=arc-20160816; b=ZYMa0yrsgPS+7fDuy/rb5FL5KCuYhs/6UvwiK5MpB/HvjS5rAKonipHQn3SqR7wi2B EJgVAOn5hgU1HBhm9/c3W6SkSErXmsRJRS5CV1f9/IQEwMFns009q3p7cY7sru7LgUza QNwkotYkhyntkWbY7TGgmVBwnt2Na8mbraK3/FhtCbQR2be2XPdEf08DMgrWkJPQE2jc czAJnGKP1cOWT3emdhXbxIBJG0AZ9DKUVjqSayNGoPM7QZpgajOa+LAHdAXGJHdJ1Tjj BzMg7A2murXgbZgROJ89fYhUwm9M09kH+4He4C3OPf3dh3DQhHMtCXPfSwjZyCKV/v3t Wcqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=Y/UiT7oWZ+av/wyBfTBUvPZ77SjbVduwNXDnb5eIvJA=; b=ew+PnhzqBdgVgy7q5OG3LpQNIEoCGt2ZhTurHZSw4ph6xszQDX5abQIqhPEvkxdh4v Onh4AuNo880WXLFdNfTHBGJ3JiUmqqN+XNLj6PDx6vdLcHMuy6TzceexIWFufRDJrx8L sXE03BRZRgGowDNPG/GZJfeQ2Utua6Ob5CA/DinOLJP7zMbOzhbIj23DKZXR9LY2EtrX wxh9Xaj5WSjpryVtFiWZe3PQvIR1pCRv8cUqBa52LEPJyTT74TtlLqVEBzo2Z3etD2fK 5JSAgw0+ltALZlEdNG/Tp0Ovj+Rb/ZkoM2NOxvOW5s5u/MioPUWtHsHM3WvKh8WFMmEB hSeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nDe4GuFn; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id lt13si3925326ejb.564.2020.11.26.13.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 13:07:37 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nDe4GuFn; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2A529826D9; Thu, 26 Nov 2020 22:07:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="nDe4GuFn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1A9DC826DF; Thu, 26 Nov 2020 22:07:31 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1A34A826C9 for ; Thu, 26 Nov 2020 22:07:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x441.google.com with SMTP id 64so3511270wra.11 for ; Thu, 26 Nov 2020 13:07:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Y/UiT7oWZ+av/wyBfTBUvPZ77SjbVduwNXDnb5eIvJA=; b=nDe4GuFnobAdb+SxxGv4hdNe6W/z2oVGo7pGYeUMKZ3U4fFqAJaUoqa/1YtlynG4YY PSIsbyri2oo2rIZkKERKfkma3t4d8GIbYzAFUh7lEO6Zq61tcCHq1B0ETBKkar7iYqY3 oqkAiltoTSRiF3Mw67Vp/8TKlrLdS1FKOwwu1Z2WWqzt75JEX1Cv+6ToF6n7W3zFrrp8 c+C2VxeUjM/7bXxPdnux3rXmR1OIm/KfKBRtU5N/4r5iawwiFNCDWjKbjcU8ZgRSeAf0 sIp7mIsjqK1pcLJIWf/E/pGxtnhx42q6+sMeezZ44IONsJKXFivs62E8yxyrSHFOQyNs B4tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Y/UiT7oWZ+av/wyBfTBUvPZ77SjbVduwNXDnb5eIvJA=; b=E4ILDArnioG0pfUq3agrrnLHV+ZUyaQtRjLleSNDs+0UUHyFl22BnVwyguwVxXegLM fNtUaP0YIrDmNjJ5z5XWB/s4r/8ALh37yrH/9SWf7kRsCdhJ8vUSdkIaTrwWSQV22lDz HHuNOT9kA/Vw89IXLijpWSluslYg1gsI4WMyk21ZKiE2td1ORtDY4EaaC0RpyGTMHOdh ozbBPq5u8DaBszvzqc4ww7l4BuZr4TAkUjpBGLs9GS9gB4uE23TNfHxPjN3wXusVYJWN 4616mpBoUX9XOLEAfm0/yoyJwcs/S8fC4EA1cQ6/v7reFwqDigHIkT+Ywlpn+FI0xf7N v8ow== X-Gm-Message-State: AOAM532dUisAWzjpGHGLPFRE2YXReH9jMNPedezqPBxsKwn//lbBOiF6 3T6YcI+sKHGTwzojrj9DMVcb7w== X-Received: by 2002:adf:f2d2:: with SMTP id d18mr6374006wrp.302.1606424847592; Thu, 26 Nov 2020 13:07:27 -0800 (PST) Received: from apalos.home ([2a02:587:4641:1e88:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id z6sm10310345wmi.1.2020.11.26.13.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 13:07:26 -0800 (PST) From: Ilias Apalodimas To: sjg@chromium.org Cc: Ilias Apalodimas , Heinrich Schuchardt , Philippe Reynes , Miquel Raynal , Bin Meng , Dhananjay Phadke , u-boot@lists.denx.de Subject: [PATCH v2] tpm: use more than sha256 on pcr_extend Date: Thu, 26 Nov 2020 23:07:22 +0200 Message-Id: <20201126210722.1919748-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean The current tpm2_pcr_extend is hardcoded using SHA256. Let's make the actual command to the TPM2 configurable so we can support a wider range of algorithms and keep the current command line as-is i.e limited to SHA256 only Signed-off-by: Ilias Apalodimas Reviewed-by: Simon Glass --- changes since v1: - add reference to the algorithms a user can pass to the function in the comments cmd/tpm-v2.c | 3 ++- include/tpm-v2.h | 5 ++++- lib/tpm-v2.c | 11 ++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) -- 2.29.2 diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c index 5fa4788a72de..daae91100a2b 100644 --- a/cmd/tpm-v2.c +++ b/cmd/tpm-v2.c @@ -116,7 +116,8 @@ static int do_tpm2_pcr_extend(struct cmd_tbl *cmdtp, int flag, int argc, if (index >= priv->pcr_count) return -EINVAL; - rc = tpm2_pcr_extend(dev, index, digest); + rc = tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, digest, + TPM2_DIGEST_LEN); unmap_sysmem(digest); diff --git a/include/tpm-v2.h b/include/tpm-v2.h index 74c14fe7c51d..f1826ff38589 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -309,11 +309,14 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw, * * @dev TPM device * @index Index of the PCR + * @algorithm Algorithm used, defined in 'enum tpm2_algorithms' * @digest Value representing the event to be recorded + * @digest_len len of the hash * * @return code of the operation */ -u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest); +u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm, + const u8 *digest, u32 digest_len); /** * Issue a TPM2_PCR_Read command. diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 91759068cf03..1f3deb06e487 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -80,11 +80,12 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw, return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest) +u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm, + const u8 *digest, u32 digest_len) { u8 command_v2[COMMAND_BUFFER_SIZE] = { tpm_u16(TPM2_ST_SESSIONS), /* TAG */ - tpm_u32(33 + TPM2_DIGEST_LEN), /* Length */ + tpm_u32(33 + digest_len), /* Length */ tpm_u32(TPM2_CC_PCR_EXTEND), /* Command code */ /* HANDLE */ @@ -99,7 +100,7 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest) tpm_u16(0), /* Size of */ /* (if any) */ tpm_u32(1), /* Count (number of hashes) */ - tpm_u16(TPM2_ALG_SHA256), /* Algorithm of the hash */ + tpm_u16(algorithm), /* Algorithm of the hash */ /* STRING(digest) Digest */ }; unsigned int offset = 33; @@ -110,8 +111,8 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest) * - the digest */ ret = pack_byte_string(command_v2, sizeof(command_v2), "s", - offset, digest, TPM2_DIGEST_LEN); - offset += TPM2_DIGEST_LEN; + offset, digest, digest_len); + offset += digest_len; if (ret) return TPM_LIB_ERROR;