From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10DA1C433EF for ; Thu, 18 Nov 2021 06:18:46 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C0CE61ABA for ; Thu, 18 Nov 2021 06:18:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1C0CE61ABA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de 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) 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-Google-Smtp-Source: ABdhPJyk1totb7PBJy+KKaOt8dI/UUeari7XgTvWrAfb4w9/5Zgq7PdJ34BAlw9rXlIl3VUoy5LY6Q== 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 Content-Transfer-Encoding: 8bit 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) -- 2.25.1