From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Oleksandr Suvorov <oleksandr.suvorov@foundries.io>
Cc: u-boot@lists.denx.de, Jorge Ramirez-Ortiz <jorge@foundries.io>,
Ruchika Gupta <ruchika.gupta@linaro.org>
Subject: Re: [PATCH] cmd: tpm-v2: add get_random
Date: Wed, 17 Aug 2022 15:13:46 +0300 [thread overview]
Message-ID: <YvzbemBQIBQ3X8We@hera> (raw)
In-Reply-To: <20220817102716.42038-1-oleksandr.suvorov@foundries.io>
Hi Oleksandr
On Wed, Aug 17, 2022 at 01:27:16PM +0300, Oleksandr Suvorov wrote:
> From: Jorge Ramirez-Ortiz <jorge@foundries.io>
>
> Enable getting randomness from the tpm command line.
Does it have to be the tpm command lime?
As of 87ab234c1cf ("cmd: rng: Add support for selecting RNG device") you can
explicitly select the device on the default rng command. That series also
plugs in the TPM RNG into the DM and allows wider usage (e.g from the EFI_RNG_PROTOCOL)
So the rng command should be good enough?
Thanks
/Ilias
>
> Signed-off-by: Jorge Ramirez-Ortiz <jorge@foundries.io>
> Co-developed-by: Oleksandr Suvorov <oleksandr.suvorov@foundries.io>
> Signed-off-by: Oleksandr Suvorov <oleksandr.suvorov@foundries.io>
> ---
>
> cmd/tpm-v2.c | 36 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 36 insertions(+)
>
> diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c
> index 4ea5f9f094f..5b53953e207 100644
> --- a/cmd/tpm-v2.c
> +++ b/cmd/tpm-v2.c
> @@ -6,8 +6,10 @@
>
> #include <common.h>
> #include <command.h>
> +#include <display_options.h>
> #include <dm.h>
> #include <log.h>
> +#include <malloc.h>
> #include <mapmem.h>
> #include <tpm-common.h>
> #include <tpm-v2.h>
> @@ -206,6 +208,37 @@ unmap_data:
> return report_return_code(rc);
> }
>
> +static int do_tpm2_get_random(struct cmd_tbl *cmdtp, int flag, int argc,
> + char *const argv[])
> +{
> + struct udevice *dev;
> + char *buffer;
> + u32 len;
> + int ret;
> +
> + ret = get_tpm(&dev);
> + if (ret) {
> + printf("Can't get tpm\n");
> + return ret;
> + }
> +
> + if (argc != 2)
> + return CMD_RET_USAGE;
> +
> + len = simple_strtoul(argv[1], NULL, 10);
> + buffer = calloc(1, len);
> + if (!buffer)
> + return -ENOMEM;
> +
> + ret = tpm2_get_random(dev, buffer, len);
> + if (!ret)
> + print_buffer(0, buffer, 1, len, 0);
> +
> + free(buffer);
> +
> + return report_return_code(ret);
> +}
> +
> static int do_tpm_dam_reset(struct cmd_tbl *cmdtp, int flag, int argc,
> char *const argv[])
> {
> @@ -366,6 +399,7 @@ static struct cmd_tbl tpm2_commands[] = {
> U_BOOT_CMD_MKENT(pcr_extend, 0, 1, do_tpm2_pcr_extend, "", ""),
> U_BOOT_CMD_MKENT(pcr_read, 0, 1, do_tpm_pcr_read, "", ""),
> U_BOOT_CMD_MKENT(get_capability, 0, 1, do_tpm_get_capability, "", ""),
> + U_BOOT_CMD_MKENT(get_random, 0, 1, do_tpm2_get_random, "", ""),
> U_BOOT_CMD_MKENT(dam_reset, 0, 1, do_tpm_dam_reset, "", ""),
> U_BOOT_CMD_MKENT(dam_parameters, 0, 1, do_tpm_dam_parameters, "", ""),
> U_BOOT_CMD_MKENT(change_auth, 0, 1, do_tpm_change_auth, "", ""),
> @@ -421,6 +455,8 @@ U_BOOT_CMD(tpm2, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
> " <property>: property\n"
> " <addr>: address to store <count> entries of 4 bytes\n"
> " <count>: number of entries to retrieve\n"
> +"get_random <len>\n"
> +" Get <len> random bytes.\n"
> "dam_reset [<password>]\n"
> " If the TPM is not in a LOCKOUT state, reset the internal error counter.\n"
> " <password>: optional password\n"
> --
> 2.37.2
>
next prev parent reply other threads:[~2022-08-17 12:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-17 10:27 [PATCH] cmd: tpm-v2: add get_random Oleksandr Suvorov
2022-08-17 12:13 ` Ilias Apalodimas [this message]
2022-08-17 18:53 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YvzbemBQIBQ3X8We@hera \
--to=ilias.apalodimas@linaro.org \
--cc=jorge@foundries.io \
--cc=oleksandr.suvorov@foundries.io \
--cc=ruchika.gupta@linaro.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.