u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH 1/3] tpm: Add tpm2 headers for TCG2 eventlog support
Date: Sun, 29 Nov 2020 15:22:16 +0200	[thread overview]
Message-ID: <X8OgiO7saHIWYGMV@apalos.home> (raw)
In-Reply-To: <3a8ad3eb-d7b3-a231-3db6-6400270367e9@gmx.de>

Hi Heinrich,

On Sun, Nov 29, 2020 at 06:28:39AM +0100, Heinrich Schuchardt wrote:
> On 11/27/20 5:29 PM, Ilias Apalodimas wrote:
> > A following patch introduces support for the EFI_TCG2_PROTOCOL
> > evenlog management.
> 
> %s/evenlog/eventlog/
> 
> > Introduce the necessary tpm related headers
> > 
> > Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > ---
> >   include/tpm-v2.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
> >   1 file changed, 59 insertions(+)
> > 
> > diff --git a/include/tpm-v2.h b/include/tpm-v2.h
> > index d8c9feda28dc..9637f9be998e 100644
> > --- a/include/tpm-v2.h
> > +++ b/include/tpm-v2.h
> > @@ -18,6 +18,12 @@
> > 
> >   #define TPM2_DIGEST_LEN		32
> 
> Shouldn't TPM2_DIGEST_LEN be renamed to TPM2_SHA256_DIGEST_SIZE in all
> of our code?

Ideally yes. The current tpm2 pre-existing code (apart from tpm2_pcr_extend()
which I changed) uses a hardware SHA256 algorithm.
Should we do it in this patchset though?

> 
> > 
> > +#define TPM2_SHA1_DIGEST_SIZE 20
> > +#define TPM2_SHA256_DIGEST_SIZE	32
> > +#define TPM2_SHA384_DIGEST_SIZE	48
> > +#define TPM2_SHA512_DIGEST_SIZE	64
> > +#define TPM2_SM3_256_DIGEST_SIZE 32
> > +
> >   #define TPM2_MAX_PCRS 32
> >   #define TPM2_PCR_SELECT_MAX ((TPM2_MAX_PCRS + 7) / 8)
> >   #define TPM2_MAX_CAP_BUFFER 1024
> > @@ -45,6 +51,15 @@
> >   #define TPM2_PT_MAX_COMMAND_SIZE	(u32)(TPM2_PT_FIXED + 30)
> >   #define TPM2_PT_MAX_RESPONSE_SIZE	(u32)(TPM2_PT_FIXED + 31)
> > 
> > +/* event types */
> > +#define EV_POST_CODE		((u32)0x00000001)
> > +#define EV_NO_ACTION		((u32)0x00000003)
> > +#define EV_SEPARATOR		((u32)0x00000004)
> > +#define EV_S_CRTM_CONTENTS	((u32)0x00000007)
> > +#define EV_S_CRTM_VERSION	((u32)0x00000008)
> > +#define EV_CPU_MICROCODE	((u32)0x00000009)
> > +#define EV_TABLE_OF_DEVICES	((u32)0x0000000B)
> > +
> >   /* TPMS_TAGGED_PROPERTY Structure */
> >   struct tpms_tagged_property {
> >   	u32 property;
> > @@ -86,6 +101,50 @@ struct tpms_capability_data {
> >   	union tpmu_capabilities data;
> >   } __packed;
> > 
> > +/* defined as TPM_SHA1_160_HASH_LEN in spec */
> > +struct tpm_digest {
> > +	u8 digest[TPM2_SHA1_DIGEST_SIZE];
> > +} __packed;
> > +
> > +/* SHA1 Event Log Entry Format */
> 
> Please, use Sphinx style comments for structures. This allows us to add
> them to the HTML documentation. See
> 
> https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#structure-union-and-enumeration-documentation
> 
> I would appreciate member descriptions, too.
> 

Ok I assumed refering to the spec would be fine.
I'll add description on v2

> > +struct tcg_pcr_event {
> > +	u32 pcr_index;
> > +	u32 event_type;
> > +	struct tpm_digest digest;
> 
> struct tpm_digest is only used here in your patch series.
> 
> The standard has
> 
>     typedef UINT8 TCG_DIGEST[TPM2_SHA1_DIGEST_SIZE];
> 
> Can't we simply write
> 
> 	u8 digest[20];
> 
> here and get rid of struct tpm_digest?

Yea we can. since it's a complex spec though I am trying to adhere
to it as much as possible to make review and future extentions easier.
I'd prefer keeping this as is tbh.

> 
> Otherwise looks ok to me.
> 

Thanks for the review!. I'll wait a few more days, fix your remarks and post a v2

Cheers
/Ilias
> Best regards
> 
> Heinrich
> 
> > +	u32 event_size;
> > +	u8 event[];
> > +} __packed;
> > +
> > +/* Definition of TPMU_HA Union */
> > +union tmpu_ha {
> > +	u8 sha1[TPM2_SHA1_DIGEST_SIZE];
> > +	u8 sha256[TPM2_SHA256_DIGEST_SIZE];
> > +	u8 sm3_256[TPM2_SM3_256_DIGEST_SIZE];
> > +	u8 sha384[TPM2_SHA384_DIGEST_SIZE];
> > +	u8 sha512[TPM2_SHA512_DIGEST_SIZE];
> > +} __packed;
> > +
> > +/* Definition of TPMT_HA Structure */
> > +struct tpmt_ha {
> > +	u16 hash_alg;
> > +	union tmpu_ha digest;
> > +} __packed;
> > +
> > +/* Definition of TPML_DIGEST_VALUES Structure */
> > +struct tpml_digest_values {
> > +	u32 count;
> > +	struct tpmt_ha digests[TPM2_NUM_PCR_BANKS];
> > +} __packed;
> > +
> > +/* Crypto Agile Log Entry Format */
> > +struct tcg_pcr_event2 {
> > +	u32 pcr_index;
> > +	u32 event_type;
> > +	struct tpml_digest_values digests;
> > +	u32 event_size;
> > +	u8 event[];
> > +} __packed;
> > +
> >   /**
> >    * TPM2 Structure Tags for command/response buffers.
> >    *
> > 
> 

  reply	other threads:[~2020-11-29 13:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27 16:29 [PATCH 0/3] extend EFI_TCG2_PROTOCOL support Ilias Apalodimas
2020-11-27 16:29 ` [PATCH 1/3] tpm: Add tpm2 headers for TCG2 eventlog support Ilias Apalodimas
2020-11-29  5:28   ` Heinrich Schuchardt
2020-11-29 13:22     ` Ilias Apalodimas [this message]
2020-11-27 16:29 ` [PATCH 2/3] efi_loader: Introduce eventlog support for TCG2_PROTOCOL Ilias Apalodimas
2020-11-29  6:02   ` Heinrich Schuchardt
2020-11-29 13:27     ` Ilias Apalodimas
2020-11-29 13:49       ` Heinrich Schuchardt
2020-11-29 14:02         ` Ilias Apalodimas
2020-11-27 16:29 ` [PATCH 3/3] cmd: efidebug: Add support for TCG2 final events table 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=X8OgiO7saHIWYGMV@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).