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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3C53FC433F5 for ; Wed, 24 Nov 2021 10:44:52 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 72A6682FD0; Wed, 24 Nov 2021 11:44:50 +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="fVL0qcG1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7DDFF83434; Wed, 24 Nov 2021 11:44:47 +0100 (CET) Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) (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 4224182FBE for ; Wed, 24 Nov 2021 11:44: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=ilias.apalodimas@linaro.org Received: by mail-wr1-x42b.google.com with SMTP id r8so3345870wra.7 for ; Wed, 24 Nov 2021 02:44:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=cC85zeUqGkmsH8OJvy17E31obBknG5PdD3SRL1NOAeM=; b=fVL0qcG1l0F673fnpMAIi0Fa8MDNYfea9Aqc3LWVexdOOJ8g7zHFBR498S4pwnW/m2 yhGFqEN7waPfIrd9Mr/sXqfecZUAGCrGsObMzjnEd+9+UryumMX12QrvEQn4iXxX49fT paKTmishsDvzkyOuDDBo6yD7VlmUzO31S8LjGvL0n4xdKOMTGYz9MkEACGJWlTReyy7N 9nZryLTSAjC2+fsmwr1B34ZAxAoz2QSXlJO8wkV/+JGoMRGIiTRMHaoNOkFTp0UONkR5 saH19HIG4Xq38fr/UCg9pm6YO+eUODdggEv72TE/2ws+l7oBx0xyeJqKT9+QXe2HM0fT ivTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cC85zeUqGkmsH8OJvy17E31obBknG5PdD3SRL1NOAeM=; b=GdbW10sVptq3TnVcaupPKUWGc0RrY8b3fnyALPyGAGowrOotoGp7UP/maP+zQNwlZ6 OorAkCOZv6xbcCTbL6DQFLjJAjlFkaBF9pPu/JrE69sbtTXUerB8inKjfCUdKWX8QfQv 5xU61qNWzaz1E6o4mJhBWt1lotSRbEdnCmseA8D0TR0+UuuEt3Ttrz/VzbheoHIe7UbP 7Z7OIfvMlTCtv792uSdO2KamD51sPl0cUz7ZnwmmY98WGEGs5YB/SkirPpJNLRGGpZrz CG4BUQi+/oe6I5VxnJ9+rhPTibLmAOUfTtcDgZ6gC1a9siRYpgAH8iA09r49J1mOkOMZ OlMg== X-Gm-Message-State: AOAM530+rGfDqAyyXwfEf4w3PIrpjdh6CQH2W83KB5shRuigRpuCC5yF CsS7W88cW0tsbR1A59JV/qYj2g== X-Google-Smtp-Source: ABdhPJyOt/V5pllEeju5QeYBLF46zvvnQAJ+4rDf1QG3DiTNQLL4I1ydarUnh/J/zE1UIFygUBZeUQ== X-Received: by 2002:a5d:6da5:: with SMTP id u5mr18066669wrs.374.1637750681736; Wed, 24 Nov 2021 02:44:41 -0800 (PST) Received: from apalos.home (ppp-94-66-220-227.home.otenet.gr. [94.66.220.227]) by smtp.gmail.com with ESMTPSA id y15sm17020945wry.72.2021.11.24.02.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 02:44:41 -0800 (PST) Date: Wed, 24 Nov 2021 12:44:39 +0200 From: Ilias Apalodimas To: Ruchika Gupta Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de, agraf@csgraf.de Subject: Re: [v2] [PATCH 2/3] tpm: use more algorithms than sha256 on pcr_read Message-ID: References: <20211123115335.125252-1-ruchika.gupta@linaro.org> <20211123115335.125252-2-ruchika.gupta@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211123115335.125252-2-ruchika.gupta@linaro.org> 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 On Tue, Nov 23, 2021 at 05:23:34PM +0530, Ruchika Gupta wrote: > 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) > -- > 2.25.1 > Reviewed-by: Ilias Apalodimas