From patchwork Wed Nov 24 13:40:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruchika Gupta X-Patchwork-Id: 519348 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp10398945imj; Wed, 24 Nov 2021 05:41:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwD50OMIpb1lsT2F41rTxKbgV9XjxdYRHGKjtkaHS1v46q3sl+l2NKvng5nQC+LAtVKHyqw X-Received: by 2002:a17:906:fca3:: with SMTP id qw3mr20796728ejb.285.1637761281003; Wed, 24 Nov 2021 05:41:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637761280; cv=none; d=google.com; s=arc-20160816; b=qTAY+Bs4ReC0GfKka5/VEf5vVWs7z9LVXWOQHVquqRAI+uS6IM+5zkOp/znCaks9ry +hAC+rvGC8UHJeeFo05kdy9z+aUfYPqVKazBBQ4KQfa5hlz3eL24KvvbaOE1Uxb4CW2D E0/Yg/trWfAsLuPHM1FR/xEntsNGaqjBZFgWK6lNpCUr4dSJoU7taKElQ6B693C3IVnr UlCQ4n/6/L6AO/A3vhbs12soghSFKeemJoFctUsgvUOKLxFzhJrsGt45f0ilEdFDbcBZ KrNrDV3ms24Lq75RsIlVSdJvXP9eaKDz1TrHmFhemxVAIHePN2/K6coGa63vLUOnBcEz k1FQ== 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=uUdRelbQfmazWyOo91y1infRQ7s32CdKbFI6cG0rCsQ=; b=CwG3Gs7CFq6JRGvmqKD7rvdsKYM0euiIxoobsyXhh7NXaWxjXoAWJcZuVuOVaWEQlc yzSzYLyEBmLCt8skO7iFOyS4t6Bs4r1uAnavy8AWczzk3Zocu4upjaRhDdJL/KiuMzJx hdE13F8Nenk4bsi8pnhtJUXJ5xMIlbmN5S4Dz4hSjGXEfvuk7hkvMe03JR6vjk5piG/u pFMeKN5ahC9z0/9V1z18Ww8KUZrUj6PvA8un2Oabh8dxs1R9GQvKC2USK0UXiZ4xFXSJ Z1XN7EUWe0Tvr7otAU0SEsSaV1Q3htvA+AtgcqoMD7xBGbBgKmwRYHjBnTiltHaPeST9 G0WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FBo+YgD3; 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 l18si48376245edb.148.2021.11.24.05.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 05:41:20 -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=FBo+YgD3; 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 6B18882FBC; Wed, 24 Nov 2021 14:41:14 +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="FBo+YgD3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D469480FAE; Wed, 24 Nov 2021 14:41:07 +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-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) (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 D55A980FAE for ; Wed, 24 Nov 2021 14:41:02 +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-pg1-x52c.google.com with SMTP id 71so2175146pgb.4 for ; Wed, 24 Nov 2021 05:41:02 -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=uUdRelbQfmazWyOo91y1infRQ7s32CdKbFI6cG0rCsQ=; b=FBo+YgD3GkCtkIfLxvWHXGKzvfeZ0oP8Meov1GaASf9Qv2D3QNpZ8pWSwTAayQcSpN S7a7GWDnkeOP1UU9ZgtbF5k5/fcvriDn7ztjx1fRN6N6gI+goV/ki8Frpf9+FAToBrzV Oqk2uZRMKLXK6lU5C/rq3oCewNTMN9t+ua2ICVSMw5merdyqqOFey3Qp4UVeCzDhpg9X 9AHPx9sH5zY54b5kS/0SxnsdiWAg5WSSUJutpiGv4oafzf0cJnwbcCn9qP8Efxp0vxrD RzIbJs3n1tRLBvFI3CQsV1E3KgZGZ+V78s1T5d+Fx8/RA7HMYV0mOyO7dQw7bwmbwfkl 8iUw== 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=uUdRelbQfmazWyOo91y1infRQ7s32CdKbFI6cG0rCsQ=; b=421UbhH8NkhlcdfY1S8YQPlIGuPJa+CuK2M7YzkQgFrxvQC/BvWR1RN3rbTPozU9gP PeKq7h0+nUB0o8ZX6c6UMKXtC7G1bVlRDJEiwl+yW0FtCvAL+tT0OrICT7vDazocLfI8 oBF5aEQpfpBrZkg1gH5MrhtCt4xQmq5pIfODmcMW4JOTdlhj9jVPCdKP7yJ3VzFb8Tdo 3Uh63NJTgRSUe9f1LNem6CbkUBk+dliv/IrXPbFesC6SPzAg+kFRLC3VZTl+7e5TVFYJ Xeec7fMNhdDLeLNsWrElOAGN2cCYuNe8PdKP9Ti470KCj1pDonY9YUcVk7en9aVEJwql sxYw== X-Gm-Message-State: AOAM531481JpCjwBQ9mTa/rIrgqQgobLBeiJ5qgAA19aeV1ZHgRs+xGQ vhl9FlZXiXnWyDTHda48sFCbl4FrnCxNUQ== X-Received: by 2002:a05:6a00:ac6:b029:374:a33b:a74 with SMTP id c6-20020a056a000ac6b0290374a33b0a74mr6122316pfl.51.1637761260986; Wed, 24 Nov 2021 05:41:00 -0800 (PST) Received: from localhost.localdomain ([106.215.91.18]) by smtp.gmail.com with ESMTPSA id k19sm16864653pff.20.2021.11.24.05.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 05:41:00 -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 v4 2/3] tpm: use more algorithms than sha256 on pcr_read Date: Wed, 24 Nov 2021 19:10:43 +0530 Message-Id: <20211124134044.454168-2-ruchika.gupta@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124134044.454168-1-ruchika.gupta@linaro.org> References: <20211124134044.454168-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 --- 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)