From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH v3 07/11] tpm: Reduce duplication in a few functions
Date: Mon, 25 Jan 2021 10:34:40 +0200 [thread overview]
Message-ID: <YA6CoCokNrGAUip0@apalos.home> (raw)
In-Reply-To: <20210123172607.2879600-7-sjg@chromium.org>
On Sat, Jan 23, 2021 at 10:26:03AM -0700, Simon Glass wrote:
> Update tpm2_clear() and tpm2_pcr_extend() so that the command size
> is not repeated twice. Add a small comment to the latter.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - Add comments for the offset value
>
> lib/tpm-v2.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
> index 1f3deb06e48..c4e869ec5b5 100644
> --- a/lib/tpm-v2.c
> +++ b/lib/tpm-v2.c
> @@ -47,9 +47,11 @@ u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no full_test)
> u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
> const ssize_t pw_sz)
> {
> + /* Length of the message header, up to start of password */
> + uint offset = 27;
> u8 command_v2[COMMAND_BUFFER_SIZE] = {
> tpm_u16(TPM2_ST_SESSIONS), /* TAG */
> - tpm_u32(27 + pw_sz), /* Length */
> + tpm_u32(offset + pw_sz), /* Length */
> tpm_u32(TPM2_CC_CLEAR), /* Command code */
>
> /* HANDLE */
> @@ -64,7 +66,6 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
> tpm_u16(pw_sz), /* Size of <hmac/password> */
> /* STRING(pw) <hmac/password> (if any) */
> };
> - unsigned int offset = 27;
> int ret;
>
> /*
> @@ -83,9 +84,11 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
> u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
> const u8 *digest, u32 digest_len)
> {
> + /* Length of the message header, up to start of digest */
> + uint offset = 33;
> u8 command_v2[COMMAND_BUFFER_SIZE] = {
> tpm_u16(TPM2_ST_SESSIONS), /* TAG */
> - tpm_u32(33 + digest_len), /* Length */
> + tpm_u32(offset + digest_len), /* Length */
> tpm_u32(TPM2_CC_PCR_EXTEND), /* Command code */
>
> /* HANDLE */
> @@ -99,11 +102,12 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
> 0, /* Attributes: Cont/Excl/Rst */
> tpm_u16(0), /* Size of <hmac/password> */
> /* <hmac/password> (if any) */
> +
> + /* hashes */
> tpm_u32(1), /* Count (number of hashes) */
> tpm_u16(algorithm), /* Algorithm of the hash */
> /* STRING(digest) Digest */
> };
> - unsigned int offset = 33;
> int ret;
>
> /*
> @@ -112,7 +116,6 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
> */
> ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
> offset, digest, digest_len);
> - offset += digest_len;
> if (ret)
> return TPM_LIB_ERROR;
>
> --
> 2.30.0.280.ga3ce27912f-goog
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
next prev parent reply other threads:[~2021-01-25 8:34 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-23 17:25 [PATCH v3 00/11] tpm: Support using TPM1 and TPM2 from a single API Simon Glass
2021-01-23 17:25 ` [PATCH v3 01/11] tpm: Don't include cr50 in TPL/SPL Simon Glass
2021-01-25 8:26 ` Ilias Apalodimas
2021-01-23 17:25 ` [PATCH v3 02/11] tpm: Use logging in the uclass Simon Glass
2021-01-25 8:26 ` Ilias Apalodimas
2021-01-23 17:25 ` [PATCH v3 03/11] tpm: Add debugging of request in tpm_sendrecv_command() Simon Glass
2021-01-25 8:28 ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 04/11] tpm: Add an API that can support v1.2 and v2 Simon Glass
2021-01-25 8:31 ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 05/11] tpm: Switch TPMv1 over to use the new API Simon Glass
2021-01-25 8:32 ` Ilias Apalodimas
2021-02-07 14:37 ` Simon Glass
2021-01-23 17:26 ` [PATCH v3 06/11] tpm: Add a basic API implementation for TPMv2 Simon Glass
2021-01-25 8:33 ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 07/11] tpm: Reduce duplication in a few functions Simon Glass
2021-01-25 8:34 ` Ilias Apalodimas [this message]
2021-01-23 17:26 ` [PATCH v3 08/11] tpm: Add an implementation of define_space Simon Glass
2021-01-25 8:36 ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 09/11] tpm: Add TPM2 support for read/write values Simon Glass
2021-01-25 8:37 ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 10/11] tpm: Add TPM2 support for write_lock Simon Glass
2021-01-25 8:38 ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 11/11] tpm: Allow disabling platform hierarchy with TPM2 Simon Glass
2021-01-25 8:38 ` Ilias Apalodimas
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=YA6CoCokNrGAUip0@apalos.home \
--to=ilias.apalodimas@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.