diff mbox series

[U-Boot,v2,12/19] tpm: rename the _extend() function to be _pcr_event()

Message ID 20180329074401.8691-13-miquel.raynal@bootlin.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series Introduce SPI TPM v2.0 support | expand

Commit Message

Miquel Raynal March 29, 2018, 7:43 a.m. UTC
The function currently called _extend() actually does what the
specification defines as a _pcr_event(). Rename the function
accordingly before implementing the actual _extend() command.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 cmd/tpm.c      | 18 ++++++++++--------
 cmd/tpm_test.c |  4 ++--
 include/tpm.h  |  4 ++--
 lib/tpm.c      |  2 +-
 4 files changed, 15 insertions(+), 13 deletions(-)

Comments

Reinhard Pfau March 29, 2018, 9:44 a.m. UTC | #1
Hi,

Am 2018-03-29 09:43, schrieb Miquel Raynal:
> The function currently called _extend() actually does what the
> specification defines as a _pcr_event(). Rename the function
> accordingly before implementing the actual _extend() command.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---

The TPM 1.2 spec calls this function "TPM_Extend"!
So renaming this func will be misleading for users of TPM1.2
devices.

Since TPM1.2 and TPM2 seems to be really different it might be an
idea to create a separate command ("tpm2"?) for TPM2 devices...
(seperate lib, too?)

For this renaming (as user of TPM1.2 devices): NAK

Greetings,
Reinhard Pfau
Guntermann & Drunck GmbH
Miquel Raynal March 29, 2018, 9:46 a.m. UTC | #2
Hi Reinhard,

On Thu, 29 Mar 2018 11:44:28 +0200, Reinhard Pfau
<reinhard.pfau@gdsys.cc> wrote:

> Hi,
> 
> Am 2018-03-29 09:43, schrieb Miquel Raynal:
> > The function currently called _extend() actually does what the
> > specification defines as a _pcr_event(). Rename the function
> > accordingly before implementing the actual _extend() command.  
> > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>  
> > ---  
> 
> The TPM 1.2 spec calls this function "TPM_Extend"!
> So renaming this func will be misleading for users of TPM1.2
> devices.
> 
> Since TPM1.2 and TPM2 seems to be really different it might be an
> idea to create a separate command ("tpm2"?) for TPM2 devices...
> (seperate lib, too?)

I used that trick for other commands (prefixing tpm1_ and tpm2_), I
will do the same here to avoid confusion. Thanks for pointing it.

> 
> For this renaming (as user of TPM1.2 devices): NAK
> 
> Greetings,
> Reinhard Pfau
> Guntermann & Drunck GmbH
> 
> 
>
diff mbox series

Patch

diff --git a/cmd/tpm.c b/cmd/tpm.c
index 32921e1a70..93dcd1a65c 100644
--- a/cmd/tpm.c
+++ b/cmd/tpm.c
@@ -324,8 +324,8 @@  static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(rc);
 }
 
-static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_pcr_event(cmd_tbl_t *cmdtp, int flag,
+			    int argc, char * const argv[])
 {
 	uint8_t in_digest[TPM1_DIGEST_LENGTH];
 	uint8_t out_digest[TPM1_DIGEST_LENGTH];
@@ -333,13 +333,14 @@  static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
 
 	if (argc != 3)
 		return CMD_RET_USAGE;
+
 	index = simple_strtoul(argv[1], NULL, 0);
 	if (!parse_byte_string(argv[2], in_digest, NULL)) {
 		printf("Couldn't parse byte string %s\n", argv[2]);
 		return CMD_RET_FAILURE;
 	}
 
-	rc = tpm_extend(index, in_digest, out_digest);
+	rc = tpm_pcr_event(index, in_digest, out_digest);
 	if (!rc) {
 		puts("PCR value after execution of the command:\n");
 		print_byte_string(out_digest, TPM1_DIGEST_LENGTH);
@@ -887,8 +888,8 @@  static cmd_tbl_t tpm_commands[] = {
 			 do_tpm_nv_read_value, "", ""),
 	U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
 			 do_tpm_nv_write_value, "", ""),
-	U_BOOT_CMD_MKENT(extend, 0, 1,
-			 do_tpm_extend, "", ""),
+	U_BOOT_CMD_MKENT(pcr_event, 0, 1,
+			 do_tpm_pcr_event, "", ""),
 	U_BOOT_CMD_MKENT(pcr_read, 0, 1,
 			 do_tpm_pcr_read, "", ""),
 	U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
@@ -1019,9 +1020,10 @@  U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
 "    - Read <count> bytes of the public endorsement key to memory\n"
 "      address <addr>\n"
 "Integrity Collection and Reporting Commands:\n"
-"  extend index digest_hex_string\n"
-"    - Add a new measurement to a PCR.  Update PCR <index> with the 20-bytes\n"
-"      <digest_hex_string>\n"
+"  pcr_event <index> <digest_in> <digest_out>\n"
+"    - Add a new measurement to a PCR.  Update PCR <index> with\n"
+"      <digest_in>. It must be a 20 byte digest for TPMv1 or a SHA256\n"
+"      digest of 32 bytes for TPMv2. Value of the PCR is given at <digest_out>\n"
 "  pcr_read index addr count\n"
 "    - Read <count> bytes from PCR <index> to memory address <addr>.\n"
 #ifdef CONFIG_TPM_AUTH_SESSIONS
diff --git a/cmd/tpm_test.c b/cmd/tpm_test.c
index da40dbc423..0bbbdab4ee 100644
--- a/cmd/tpm_test.c
+++ b/cmd/tpm_test.c
@@ -104,7 +104,7 @@  static int test_early_extend(void)
 	tpm_init();
 	TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
 	TPM_CHECK(tpm_continue_self_test());
-	TPM_CHECK(tpm_extend(1, value_in, value_out));
+	TPM_CHECK(tpm_pcr_event(1, value_in, value_out));
 	printf("done\n");
 	return 0;
 }
@@ -439,7 +439,7 @@  static int test_timing(void)
 	TTPM_CHECK(tpm_tsc_physical_presence(PRESENCE), 100);
 	TTPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&x, sizeof(x)), 100);
 	TTPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)), 100);
-	TTPM_CHECK(tpm_extend(0, in, out), 200);
+	TTPM_CHECK(tpm_pcr_event(0, in, out), 200);
 	TTPM_CHECK(tpm_set_global_lock(), 50);
 	TTPM_CHECK(tpm_tsc_physical_presence(PHYS_PRESENCE), 100);
 	printf("done\n");
diff --git a/include/tpm.h b/include/tpm.h
index 2f17166662..a863ac6196 100644
--- a/include/tpm.h
+++ b/include/tpm.h
@@ -537,7 +537,7 @@  uint32_t tpm_nv_read_value(uint32_t index, void *data, uint32_t count);
 uint32_t tpm_nv_write_value(uint32_t index, const void *data, uint32_t length);
 
 /**
- * Issue a TPM_Extend command.
+ * Issue a TPM_PCR_Event command.
  *
  * @param index		index of the PCR
  * @param in_digest	160-bit value representing the event to be
@@ -546,7 +546,7 @@  uint32_t tpm_nv_write_value(uint32_t index, const void *data, uint32_t length);
  *			command
  * @return return code of the operation
  */
-uint32_t tpm_extend(uint32_t index, const void *in_digest, void *out_digest);
+int tpm_pcr_event(u32 index, const void *in_digest, void *out_digest);
 
 /**
  * Issue a TPM_PCRRead command.
diff --git a/lib/tpm.c b/lib/tpm.c
index 9a46ac09e6..46250a86cf 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -493,7 +493,7 @@  uint32_t tpm_nv_write_value(uint32_t index, const void *data, uint32_t length)
 	return 0;
 }
 
-uint32_t tpm_extend(uint32_t index, const void *in_digest, void *out_digest)
+int tpm_pcr_event(u32 index, const void *in_digest, void *out_digest)
 {
 	const uint8_t command[34] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0x22, 0x0, 0x0, 0x0, 0x14,