From patchwork Sat Nov 21 17:47:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 1404347 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=IgZpwbB/; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CdgqT0p4Hz9sRR for ; Sun, 22 Nov 2020 04:47:38 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8EB1E82591; Sat, 21 Nov 2020 18:47:27 +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="IgZpwbB/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB496825A1; Sat, 21 Nov 2020 18:47:25 +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,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (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 56E5B821A4 for ; Sat, 21 Nov 2020 18:47:22 +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-wm1-x344.google.com with SMTP id c9so13975865wml.5 for ; Sat, 21 Nov 2020 09:47:22 -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=ghpPbFUDYsJzVoHA9dr4yEF+YOyLMRB2L67ez4HC5vk=; b=IgZpwbB/6C92drAGwQrlxRYEnosWDVpxn1urFLEedDr0gE4KYjAaiG5ISYupFFoKwq huCwEEvMxW3q2mTsIziz47/BWd791a09sH+56msHPGuyobl2cOJdWQafrgh+BGdpNQfK jhr0UWwSFabqx+2Ml6LgnTZs1odNmChFtomsd8rkOF4756UxCw46ycvE+EiscD0c0RCN Qzdcm2BaNQf5oKZU7GaysqdIeiJNJx9cwvXVt1kxlCo1q6d4yNdqpAJodBdI3XK/ZUGD jBMXN9ZYesK7P+iZGkylhMDoMrr4xZaUbgXe/UbQ0Lyljux0QgKZmunlutVPSXtah68C fuWg== 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=ghpPbFUDYsJzVoHA9dr4yEF+YOyLMRB2L67ez4HC5vk=; b=ODpcwbybyINY6ygC0KEdYJB8TEu4puZ+5TuCRlvhPLAE5J5kIMTSCI3E6Z4K70wlkI hTJzPYI0EkW+o4uio9OlnmMpuTqX6x+0POzgYvvsW/IpftecRDrpghtTNrApwsTptSPK me7aqI8P9BuDbkWNchIqLNI11u3V8y6xFyD56wfOEQZSbZYdBE8ll9AA0yxCTUg3ZSTW CToweLCT/NQZqCHoLzkzGd7NXSi9kCcPptbm058hg6GpLTOaAXl7TyPJwLPPBDzq4n2s FWqpyONWuO9O3eOfttXBiCSH5aH8gfCXcGA/7w7lJ+AQ64OiHwCf9t9agHVJOPGgPaSi +2Eg== X-Gm-Message-State: AOAM532R7IbiT28XB+i3SJt11rUur1B+cxc+as2VxdOOKkWj1ys6Xagy ls+O3cHRyH537D2M9DDvzq9ghA== X-Google-Smtp-Source: ABdhPJxC6AcVrzCsAUB6NJv4Jwd2VZFxSj/KLafXMzFv3SaDym7v87DXkv+yHSVVT9ee1NMM52FCBQ== X-Received: by 2002:a1c:5605:: with SMTP id k5mr14824820wmb.99.1605980841578; Sat, 21 Nov 2020 09:47:21 -0800 (PST) Received: from apalos.home ([2a02:587:4641:1e88:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id t15sm7823075wmn.19.2020.11.21.09.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 09:47:21 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , Miquel Raynal , Philippe Reynes , Simon Glass , Dhananjay Phadke , Bin Meng , u-boot@lists.denx.de Subject: [PATCH] tpm: use more than sha256 on pcr_extend Date: Sat, 21 Nov 2020 19:47:17 +0200 Message-Id: <20201121174718.949000-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 --- cmd/tpm-v2.c | 3 ++- include/tpm-v2.h | 5 ++++- lib/tpm-v2.c | 11 ++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) 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 d8cf0ab05185..fde44e5d98cd 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -376,11 +376,14 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw, * * @dev TPM device * @index Index of the PCR + * @algorithm Algorithm used * @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;