[PATCH] tpm: use more than sha256 on pcr_extend

Simon Glass sjg at chromium.org
Mon Nov 23 02:28:37 CET 2020


Hi Ilias,

On Sat, 21 Nov 2020 at 10:47, Ilias Apalodimas
<ilias.apalodimas at linaro.org> wrote:
>
> The current tpm2_pcr_extend is hardcoded using SHA256.
> Let's make the actual command to the TPM2 configurable so we can support
> a wider range of algorithms and keep the current command line as-is i.e
> limited to SHA256 only
>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> ---
>  cmd/tpm-v2.c     |  3 ++-
>  include/tpm-v2.h |  5 ++++-
>  lib/tpm-v2.c     | 11 ++++++-----
>  3 files changed, 12 insertions(+), 7 deletions(-)
>

Reviewed-by: Simon Glass <sjg at chromium.org>

nit below

> diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c
> index 5fa4788a72de..daae91100a2b 100644
> --- a/cmd/tpm-v2.c
> +++ b/cmd/tpm-v2.c
> @@ -116,7 +116,8 @@ static int do_tpm2_pcr_extend(struct cmd_tbl *cmdtp, int flag, int argc,
>         if (index >= priv->pcr_count)
>                 return -EINVAL;
>
> -       rc = tpm2_pcr_extend(dev, index, digest);
> +       rc = tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, digest,
> +                            TPM2_DIGEST_LEN);
>
>         unmap_sysmem(digest);
>
> diff --git a/include/tpm-v2.h b/include/tpm-v2.h
> index d8cf0ab05185..fde44e5d98cd 100644
> --- a/include/tpm-v2.h
> +++ b/include/tpm-v2.h
> @@ -376,11 +376,14 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
>   *
>   * @dev                TPM device
>   * @index      Index of the PCR
> + * @algorithm  Algorithm used

It is a good idea to reference the enum or #define that describes the
values, as with this comment people will not know what values are
valid.

>   * @digest     Value representing the event to be recorded
> + * @digest_len  len of the hash
>   *
>   * @return code of the operation
>   */
> -u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest);
> +u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
> +                   const u8 *digest, u32 digest_len);
>

Regards,
Simon


More information about the U-Boot mailing list