From patchwork Tue Nov 23 11:50:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruchika Gupta X-Patchwork-Id: 519311 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp8502620imj; Tue, 23 Nov 2021 03:51:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYU4j297fFXCpIFkTNQMU1u2qGz43AmnUAVWHhzUWbhlTzq8ZXcGIoGFz/AzKS62yfg6qg X-Received: by 2002:a05:6402:1849:: with SMTP id v9mr8139665edy.335.1637668304368; Tue, 23 Nov 2021 03:51:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637668304; cv=none; d=google.com; s=arc-20160816; b=pl+VnwIlWjy//lI5yx+VE/GavT9QrCOsI46SaT6UUBnFIPg9UW/cilGEw6Dh8qHTIt 9LwQUCeHicu88D/ZyHaXUrd8yjZ/fVMpp0p6znJLi9PMBUBTGzF153cK9TBwF1n6884y x3cfGjJ3vKr+c+HGiDdU7/M2Yrup5TyyK8i2ALUmsb5YXKPGuCH4LZzYgoRrbhcGGUjo tKLbTQgonpWuV4QKf0bQRhkx3EzI0q7gT9+7k8S+759yiPjPO0XWGrUvKZyY6X5+wNiL O0uChhVM8itQPIy9QyBoVNzTOOfxLbHsZx0QIDabhqt0jOeomk/lw3h25d02qwc3txjm I58w== 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=Bff2wf29QQNRVoQJkjSfdwfzFPR/ux7Xoyrtoc3m6uo=; b=GdGgZF5QGb3+1eHXyLhLXUohgHxMWGoRjD+LxgVUHOrtRb07dzXuLFe7brLKBzMw2/ FokyMpAb0AuQx/lClk1hudh1Tn43EHLyjsdowsi0BqfwbyT+R/LS3+GVgYEDP10EyrKT lyWaYCqD3Y7C1c2eEBIiSFyt4HLeSdMWJDubRJ1IUTbBML4FbwCFw5CrIxnWIfJ/0j03 rQo27qLFWVPjjh5zNWfTtqPqd1ylXz8PKvmy2qJi0d8t0v5PCHv+O+kn1k+j4Y3ebFC1 L+goq/ht7nacjtQkHK/OwVU9D9vihRyPZ1M5CmWfdrO+YF9Dn5Nksi0mTDNCaBku8ER3 2VRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rD+m68yJ; 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 ji1si34028245ejc.121.2021.11.23.03.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:51:44 -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=rD+m68yJ; 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 73065834D5; Tue, 23 Nov 2021 12:51:35 +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="rD+m68yJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3DB3482C88; Tue, 23 Nov 2021 12:51:30 +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-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (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 CA16282DF6 for ; Tue, 23 Nov 2021 12:51:26 +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-x42f.google.com with SMTP id n85so19185497pfd.10 for ; Tue, 23 Nov 2021 03:51:26 -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=Bff2wf29QQNRVoQJkjSfdwfzFPR/ux7Xoyrtoc3m6uo=; b=rD+m68yJ6UkjULa7IWUeIaUdjX/JQPJCZn8fWPmrYC2k1ABwukiKanlmvgwPHOSy4Q tnWq15S8tR6QieMTtcNTIhqtjVW8K3ID/8xx2stRLbHXUSbHRqmEn9BGp11Or7R2hk5r NPVT7RvayZhHmOi8VRB+S6ADQWcfM/3pNLR1ZAWDr0WvkD/XUZsqnSWcro83JZSzbzk7 reO6t9H2zWbnRVFGE9NvwjyIR/sci0Ou30pRh/GT6ducgTIFVA351tKN/DTNdRz/7ZSu UF/r2iy4FrUW6vdTCD5EUGLG64R1/7whhlE8qq4RKJrUwJT3kK9eu92L5sQm47hgSEKi CGkg== 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=Bff2wf29QQNRVoQJkjSfdwfzFPR/ux7Xoyrtoc3m6uo=; b=VFEqfJtd0K2MZUiRWQmqa9GJRwy68U6Ceud0Mwm6Hkh24d2CE5Jm3NGbBXMGLOiH82 54s5yYLrEMpvlNDVGLaxP+U8Mb+/FR44WKtR0vremm2eXA9KDACFE7cgTSnol9ZhkvYZ vjwd4VaWKYNW+fbHVePFmuNeUPowCGypm/UiUntyIWceqXVCowhFO+yJV2ZgRvHcoydl UNrpRCACZDWn1i5p4pWuHpEKFvVZwICnKIzCTLsTckbAL28UIwnqraLjLYkZo7QH5E12 kI6nLQqc9dPLTw4FDZ9zdr8mvsvoVrdpQbWN5yvQdIQKB3QrItLWMhSP2e6FjICNR0ma FRxw== X-Gm-Message-State: AOAM531cOYAFndzCokBphGIWOnvxhhH8iNECw3NVDAFaEgI+KSTHixD2 JnJaQQKL3sIGwJO0Df8eEg9v6XRHjV7iuw== X-Received: by 2002:a65:6702:: with SMTP id u2mr2776636pgf.24.1637668284908; Tue, 23 Nov 2021 03:51:24 -0800 (PST) Received: from localhost.localdomain ([106.215.91.146]) by smtp.gmail.com with ESMTPSA id p66sm9159468pga.31.2021.11.23.03.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:51:24 -0800 (PST) From: Ruchika Gupta To: u-boot@lists.denx.de Cc: Ruchika Gupta Subject: [v2] [PATCH 2/3] tpm: use more algorithms than sha256 on pcr_read Date: Tue, 23 Nov 2021 17:20:51 +0530 Message-Id: <20211123115052.124941-2-ruchika.gupta@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211123115052.124941-1-ruchika.gupta@linaro.org> References: <20211123115052.124941-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 --- 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)