From patchwork Thu Nov 18 06:17:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruchika Gupta X-Patchwork-Id: 519236 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp518745imj; Wed, 17 Nov 2021 22:18:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkEBmzzI0VVEqgX9PBBYVkHgHyKulDABMZslbUZQ3T36TZKnR6LMHD31OVLXf09yrdxXPn X-Received: by 2002:aa7:d997:: with SMTP id u23mr7561224eds.164.1637216327576; Wed, 17 Nov 2021 22:18:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637216327; cv=none; d=google.com; s=arc-20160816; b=zCkm137ApK61vyA5qK0aj0Pzb9J+TSFkarZgTexSlY73EasxO7UsZkkQ0koviwiZlA rRtKtJemVpTDPTO1+/FjSKryBcWydt9VDnVvrpfn1MFi3nEPfDmdrHmyqZZ6PDSIZiFo cwN3I9Bo863zvtmXr8XgDK4novvEMUYgPylO85ZPwEKUb0ju2YOdaBOaDaP1xZhgpfbt mmYsp7tiaYlH07C07MxYMfBy2p+db2GRXALUqQZX/PwgM8L93Kjo/NuQnqryoo8B0irL qmcNAYlTU2lEtoOqUJRA0U4Z+TgSAFAjmxuG98vY+cQHEIXfaA/rq4gbP1NMFdUVPNVx cy3g== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OZ8ShBxfCLS7gehzwlLpOyW+9taeYGcGDs5nlsQxF/o=; b=xPMNe1WEe7wBAxJPQ8Kg/vwUF0g3cfSt2z87u9+NjDpUsJMFRq1qWavMmp4fWzqDlr 4r88GIZA76T6/rRnG/KrUlnv6Gm3at3g6AxDnZaKnHDCtbOFcQ8LwjThbqnWhvCbIAUN lWr1Sr7J3DTIN3xyVNp8a6sD40Axgcqift0OeIIZlZxP3lPZ5VHG8XFzn8BzW6lx4Son hEsekGFgn4yd9bfJ08WWrpr9kSDHwrfFp1c+Inv+TXV2ntMjDXJpqDYm9radP1e8Q0oo h65sd04UpObaUVJ+4v3lXcucnmbwKLe7Bcv4HepX00R9Tz8qKYtNPV0KxbgkxOfcp8D/ zalA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="a4xPh/q7"; 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 go31si5558635ejc.244.2021.11.17.22.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 22:18:47 -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="a4xPh/q7"; 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 806B382F70; Thu, 18 Nov 2021 07:18:42 +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="a4xPh/q7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6401A82F67; Thu, 18 Nov 2021 07:18:35 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) (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 F29CF82F49 for ; Thu, 18 Nov 2021 07:18: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=ruchika.gupta@linaro.org Received: by mail-pf1-x435.google.com with SMTP id x5so4996213pfr.0 for ; Wed, 17 Nov 2021 22:18: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=OZ8ShBxfCLS7gehzwlLpOyW+9taeYGcGDs5nlsQxF/o=; b=a4xPh/q7q9PdkVhVjUbAJngIfV1rvbVMZ9M6mzSMv/Wt4pc+6GCUQazPrKUtpPIJ6l M5uRzqRsbpKGpGKA078/XWLcTj8u5NFrIJOrO5X1PkjDaL/5Bh1T5sun/sAPT0fkX9TB 827kxELw8aNOipnGeb3Jx/v/8GERYKxicx+WRALBeGgFjP8TEPRlzZ0NgvzqCvfAvrDv BE9DZG1BFCTWmJYJ7uXRFi8uksylOWQvXSw38d9s6XLsXu7/+fn+vCuoPJ+uCbK5kmRL mJXEixUb6i9pfQLd6R0vu8OeGXyCFFdH8BDuHRue0CqAh7eCzVnuG2j7hbN4lMhMvnT9 tkVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OZ8ShBxfCLS7gehzwlLpOyW+9taeYGcGDs5nlsQxF/o=; b=f7j97q1NdHiTHYeBcNjz415XfyS3/vr4B4o9PWuSJvTL5zOAdz9kjscNamBxQI73vM zVSGAIW4Z6Etfj3H4o95yhzpKeruznaXt76tQmpG3rK3HlzIO7ClDor5/Cd5bu9Esapg OTfBwn+XCBbZQzQRv3ylWkXwx0WY9WdbR+xH0+sGsZ3Peb+TXa5jqPPmlRBAXSEBJr1L RpzU2AiJp95eb74v/Ok01Tynk2wsfjFlLyzeiOtOBzK9akJdyRUvBklvHJ1hm1nE1vHI Ee1xv6sTjok/z/qdzB94g7TDZ7JJjp8k7L0g0lw59wraC9r1Wc9ScgP4AR7B0OHiPxxU a4fA== X-Gm-Message-State: AOAM531hCIX5KRYI0WLdUZZ0FAn08R5BeSVF0rY4cVRca3Ne/2m9ziT9 v8KIrxJHt/pXbpjRqFyczOairN5L3Z22bQ== X-Received: by 2002:a63:804a:: with SMTP id j71mr9612309pgd.472.1637216307064; Wed, 17 Nov 2021 22:18:27 -0800 (PST) Received: from localhost.localdomain ([122.177.104.97]) by smtp.gmail.com with ESMTPSA id h3sm1745920pfc.204.2021.11.17.22.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 22:18:26 -0800 (PST) From: Ruchika Gupta To: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, xypron.glpk@gmx.de, agraf@csgraf.de Cc: Ruchika Gupta Subject: [PATCH 2/3] tpm: use more algorithms than sha256 on pcr_read Date: Thu, 18 Nov 2021 11:47:50 +0530 Message-Id: <20211118061751.3334620-3-ruchika.gupta@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118061751.3334620-1-ruchika.gupta@linaro.org> References: <20211118061751.3334620-1-ruchika.gupta@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.35 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.103.2 at phobos.denx.de X-Virus-Status: Clean The current tpm2_pcr_read is hardcoded using SHA256. Make the actual command to TPM configurable to use wider range of algorithms. The current command line is kept as is i.e limited to SHA-256 only. Signed-off-by: Ruchika Gupta --- cmd/tpm-v2.c | 3 ++- include/tpm-v2.h | 3 ++- lib/tpm-v2.c | 12 ++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c index daae91100a..4ea5f9f094 100644 --- a/cmd/tpm-v2.c +++ b/cmd/tpm-v2.c @@ -151,7 +151,8 @@ static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc, data = map_sysmem(simple_strtoul(argv[2], NULL, 0), 0); - rc = tpm2_pcr_read(dev, index, priv->pcr_select_min, data, &updates); + rc = tpm2_pcr_read(dev, index, priv->pcr_select_min, TPM2_ALG_SHA256, + data, TPM2_DIGEST_LEN, &updates); if (!rc) { printf("PCR #%u content (%u known updates):\n", index, updates); print_byte_string(data, TPM2_DIGEST_LEN); diff --git a/include/tpm-v2.h b/include/tpm-v2.h index e6b68769f3..07dfaa64fb 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -518,7 +518,8 @@ u32 tpm2_nv_write_value(struct udevice *dev, u32 index, const void *data, * @return code of the operation */ u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz, - void *data, unsigned int *updates); + u32 algorithm, void *data, u32 digest_len, + unsigned int *updates); /** * Issue a TPM2_GetCapability command. This implementation is limited diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 235f8c20d4..9f86eab814 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -254,7 +254,8 @@ u32 tpm2_nv_write_value(struct udevice *dev, u32 index, const void *data, } u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz, - void *data, unsigned int *updates) + u32 algorithm, void *data, u32 digest_len, + unsigned int *updates) { u8 idx_array_sz = max(idx_min_sz, DIV_ROUND_UP(idx, 8)); u8 command_v2[COMMAND_BUFFER_SIZE] = { @@ -264,7 +265,7 @@ u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz, /* TPML_PCR_SELECTION */ tpm_u32(1), /* Number of selections */ - tpm_u16(TPM2_ALG_SHA256), /* Algorithm of the hash */ + tpm_u16(algorithm), /* Algorithm of the hash */ idx_array_sz, /* Array size for selection */ /* bitmap(idx) Selected PCR bitmap */ }; @@ -283,10 +284,13 @@ u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz, if (ret) return ret; + if (digest_len > response_len) + return TPM_LIB_ERROR; + if (unpack_byte_string(response, response_len, "ds", 10, &counter, - response_len - TPM2_DIGEST_LEN, data, - TPM2_DIGEST_LEN)) + response_len - digest_len, data, + digest_len)) return TPM_LIB_ERROR; if (updates)