From patchwork Mon Nov 29 07:39:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruchika Gupta X-Patchwork-Id: 519698 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp5728775imj; Sun, 28 Nov 2021 23:40:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5+fsDz0PURNVm6pBzmIX5nAcgwmJMgk/YLgCm02rw3QtSbPBtF+3nvMtTT5ERd/0Wy5j3 X-Received: by 2002:a05:6402:5158:: with SMTP id n24mr71271219edd.230.1638171622790; Sun, 28 Nov 2021 23:40:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638171622; cv=none; d=google.com; s=arc-20160816; b=lC05SaYpLeqYoD4Q6L+Vnd8lwy4HkjJNX/kqUNf9Y5amySJWL9ZAE5jJj1CZXUa++e d8a36QAnoEkXaRqMWkb35mvf05iBof7mURkyzi3Q1oRmAAwoouHGbUvX8JoGL6af6S7r 9mTHZZuXcPdNvkIUVkTGDFraqqGfLq0KJZC0A/WCQ22M/mUJo2GIVeU7+FkuAhCiW3+0 qViUwc49E4P+zE2wMmXYi9AkYPg/kHrcERibo68DFxrvLD79Fr2r3IomrV71XkQsQ26K OR8ICsY5ldntuXsq7l3aOck7532w/Bbp4X0NuLajdGHb5szBzGlqScCsKhY0Lfc5toFv Mk7Q== 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=YEo69NNBvD63GupIoDlEhSg7bZFsmDo5+pumAut6Rto=; b=hq1ujXemrCF+XPrWbv9DpAc+3gAtNELqmwFMIJIWTAMWfv/LtjVWIjXeeg+JRVX53F 1VG856QS7QnjMYhkX/koc0ziwjG7WVeTEmLaEH+mbY/egLLRK0JeP3NZdYXYWztPsO14 ZnwiEmn88vBKpk9rqCbHhWhj78E8fExEeMH8tVrTCIkFeMRv1RrHszrTxntzmkhzi4gX CM5mzyATFHh+tXQA9Z7jveLR7tFANbR9fUczPvlGcKs11KnJLBAe9hebPmAoruJ4rIhZ YNWawhjH0/YLVHxVsQfI9w+juY1JdiQcMKWsOQ9euIGid53+LRa4PFabsy/jT5+YVjCw /q1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pa98+l0y; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id cs14si24563920ejc.128.2021.11.28.23.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Nov 2021 23:40:22 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pa98+l0y; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 2D03782F58; Mon, 29 Nov 2021 08:40:19 +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="pa98+l0y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2AB3F82E08; Mon, 29 Nov 2021 08:40:15 +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-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) (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 7348782982 for ; Mon, 29 Nov 2021 08:40:09 +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-x431.google.com with SMTP id r130so16010698pfc.1 for ; Sun, 28 Nov 2021 23:40:09 -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=YEo69NNBvD63GupIoDlEhSg7bZFsmDo5+pumAut6Rto=; b=pa98+l0ybR8RNxkf/KZyezY3rZNFuKuOMMjGfxg1/KGyC5eoNvLFm7MP0QZYNG2m0r +2wo9pu1fLDBehKta+1fljVInIHH6v/4PcB1lewrA/N3pjLB7ERRVh289WM6Z5HcpdKk Qvkl/nXzuXY5e8tfU4SNsI0HH7uha3xzmcnORuuDqdaB+GhNW/G7tdUWZFFhfucO1QEd 0Opig0GHfB2WAjPKquNvmHD+DDXqtVPThOVzoxlrUOv/vbncff6XGxZRnmMFxF6cb089 SKpKdpOddx26C6LjvFzriWdmy28UPIEy1QiR6/unupnXgwGA59VfZUpx1TYx4Czm0ZvU DtjQ== 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=YEo69NNBvD63GupIoDlEhSg7bZFsmDo5+pumAut6Rto=; b=tOYVo0pTSIQ0u6LVlwT91PjpHYbwi+8xKZIeXVARIvpjW5FaIHYKVkiOR69nA05/9f FvGhbGyzqfDxITteCs76O8z+huYVj20lxER8PCa0AYSPIcnZG+Gd6wyyNnCbIDSjKXb2 wyaozmchQ9Fq3vtZza+K9Pp3XTqcFBJWetT0+Vopis1WILRzwidDMTm3xicFh0lua+Yy 5vJNIF/9sFPCETcs8zbf8kCPHi14vHedkF03Q92AKUfElGWlYIspw2I6D7kIWhXevQDw AQ3bhLXhEpNGWY4gNa+Qbb4ppzkDDb+NnJxOzxicqsAOai4AHW2CHT2h1yG3Rwb+xPur 6XVQ== X-Gm-Message-State: AOAM532QC73ImuatYQv/NODc8Qt7X61SVreSp2ztnsw3bhmZ5z4UMwSd rczqwYofmqZn72fccupNv9CKgakVlNXdog== X-Received: by 2002:a05:6a00:1892:b0:49f:ffcf:17a3 with SMTP id x18-20020a056a00189200b0049fffcf17a3mr37393009pfh.59.1638171607126; Sun, 28 Nov 2021 23:40:07 -0800 (PST) Received: from localhost.localdomain ([122.177.109.169]) by smtp.gmail.com with ESMTPSA id r16sm11785678pgk.45.2021.11.28.23.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Nov 2021 23:40:06 -0800 (PST) From: Ruchika Gupta To: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, xypron.glpk@gmx.de, agraf@csgraf.de, masahisa.kojima@linaro.org Cc: Ruchika Gupta Subject: [PATCH v8 2/3] tpm: use more algorithms than sha256 on pcr_read Date: Mon, 29 Nov 2021 13:09:45 +0530 Message-Id: <20211129073946.1374496-2-ruchika.gupta@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211129073946.1374496-1-ruchika.gupta@linaro.org> References: <20211129073946.1374496-1-ruchika.gupta@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 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 Reviewed-by: Ilias Apalodimas --- v8: No change v7: No change v6: No change v5: No change v4: No change v3: No change v2: Change algorithm from u32 to u16 Add parameter description in function declaration cmd/tpm-v2.c | 3 ++- include/tpm-v2.h | 5 ++++- lib/tpm-v2.c | 12 ++++++++---- 3 files changed, 14 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 ceff7d245e..4e9dd52cb6 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -512,13 +512,16 @@ u32 tpm2_nv_write_value(struct udevice *dev, u32 index, const void *data, * @dev TPM device * @idx Index of the PCR * @idx_min_sz Minimum size in bytes of the pcrSelect array + * @algorithm Algorithm used, defined in 'enum tpm2_algorithms' * @data Output buffer for contents of the named PCR + * @digest_len len of the data * @updates Optional out parameter: number of updates for this PCR * * @return code of the operation */ u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz, - void *data, unsigned int *updates); + u16 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 2e7b27bd6b..1bf627853a 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) + u16 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)