]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
tpm: rename and export tpm2_digest and tpm2_algorithms
authorRoberto Sassu <roberto.sassu@huawei.com>
Wed, 6 Feb 2019 16:24:48 +0000 (17:24 +0100)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Wed, 13 Feb 2019 07:48:51 +0000 (09:48 +0200)
Rename tpm2_* to tpm_* and move the definitions to include/linux/tpm.h so
that these can be used by other kernel subsystems (e.g. IMA).

Also, set the length of the digest array in tpm_digest to a new constant
named TPM_MAX_DIGEST_SIZE, equal to SHA512_DIGEST_SIZE.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
drivers/char/tpm/tpm-interface.c
drivers/char/tpm/tpm.h
drivers/char/tpm/tpm1-cmd.c
drivers/char/tpm/tpm2-cmd.c
include/linux/tpm.h
include/linux/tpm_eventlog.h

index 2b31eff06b0e24e312dd8536d7bb673c834447c5..9c6aa77b5dee47192861693ca5bc2dd0c6607bb1 100644 (file)
@@ -318,7 +318,7 @@ EXPORT_SYMBOL_GPL(tpm_pcr_read);
 int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash)
 {
        int rc;
-       struct tpm2_digest *digest_list;
+       struct tpm_digest *digest_list;
        int i;
 
        chip = tpm_find_get_ops(chip);
index cd330ace62481f5b5705751747e0d26d8d0d93d1..0e54061d3fd1f51d7ac57db24fb75ac25ddb2d40 100644 (file)
@@ -122,17 +122,6 @@ enum tpm2_return_codes {
        TPM2_RC_RETRY           = 0x0922,
 };
 
-enum tpm2_algorithms {
-       TPM2_ALG_ERROR          = 0x0000,
-       TPM2_ALG_SHA1           = 0x0004,
-       TPM2_ALG_KEYEDHASH      = 0x0008,
-       TPM2_ALG_SHA256         = 0x000B,
-       TPM2_ALG_SHA384         = 0x000C,
-       TPM2_ALG_SHA512         = 0x000D,
-       TPM2_ALG_NULL           = 0x0010,
-       TPM2_ALG_SM3_256        = 0x0012,
-};
-
 enum tpm2_command_codes {
        TPM2_CC_FIRST                   = 0x011F,
        TPM2_CC_HIERARCHY_CONTROL       = 0x0121,
@@ -545,7 +534,7 @@ static inline u32 tpm2_rc_value(u32 rc)
 int tpm2_get_timeouts(struct tpm_chip *chip);
 int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
 int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count,
-                   struct tpm2_digest *digests);
+                   struct tpm_digest *digests);
 int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
 void tpm2_flush_context(struct tpm_chip *chip, u32 handle);
 int tpm2_seal_trusted(struct tpm_chip *chip,
index e7d3228a0f37d5b44106545840bbb7a0be3c3619..3eb7e03889a0cba177583a467dd1b0bf9b252eb8 100644 (file)
@@ -703,7 +703,7 @@ int tpm1_auto_startup(struct tpm_chip *chip)
                goto out;
        }
 
-       chip->allocated_banks[0] = TPM2_ALG_SHA1;
+       chip->allocated_banks[0] = TPM_ALG_SHA1;
        chip->nr_allocated_banks = 1;
 
        return rc;
index bd20b9a61fc011e7d43cb4ca8aef567c8e49a8f6..440ae6ee29e4e3022e0a1b80210b33f0cc73156c 100644 (file)
@@ -33,11 +33,11 @@ struct tpm2_hash {
 };
 
 static struct tpm2_hash tpm2_hash_map[] = {
-       {HASH_ALGO_SHA1, TPM2_ALG_SHA1},
-       {HASH_ALGO_SHA256, TPM2_ALG_SHA256},
-       {HASH_ALGO_SHA384, TPM2_ALG_SHA384},
-       {HASH_ALGO_SHA512, TPM2_ALG_SHA512},
-       {HASH_ALGO_SM3_256, TPM2_ALG_SM3_256},
+       {HASH_ALGO_SHA1, TPM_ALG_SHA1},
+       {HASH_ALGO_SHA256, TPM_ALG_SHA256},
+       {HASH_ALGO_SHA384, TPM_ALG_SHA384},
+       {HASH_ALGO_SHA512, TPM_ALG_SHA512},
+       {HASH_ALGO_SM3_256, TPM_ALG_SM3_256},
 };
 
 int tpm2_get_timeouts(struct tpm_chip *chip)
@@ -192,7 +192,7 @@ int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)
        pcr_select[pcr_idx >> 3] = 1 << (pcr_idx & 0x7);
 
        tpm_buf_append_u32(&buf, 1);
-       tpm_buf_append_u16(&buf, TPM2_ALG_SHA1);
+       tpm_buf_append_u16(&buf, TPM_ALG_SHA1);
        tpm_buf_append_u8(&buf, TPM2_PCR_SELECT_MIN);
        tpm_buf_append(&buf, (const unsigned char *)pcr_select,
                       sizeof(pcr_select));
@@ -226,7 +226,7 @@ struct tpm2_null_auth_area {
  * Return: Same as with tpm_transmit_cmd.
  */
 int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count,
-                   struct tpm2_digest *digests)
+                   struct tpm_digest *digests)
 {
        struct tpm_buf buf;
        struct tpm2_null_auth_area auth_area;
@@ -443,7 +443,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
 
        /* public */
        tpm_buf_append_u16(&buf, 14 + options->policydigest_len);
-       tpm_buf_append_u16(&buf, TPM2_ALG_KEYEDHASH);
+       tpm_buf_append_u16(&buf, TPM_ALG_KEYEDHASH);
        tpm_buf_append_u16(&buf, hash);
 
        /* policy */
@@ -458,7 +458,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
        }
 
        /* public parameters */
-       tpm_buf_append_u16(&buf, TPM2_ALG_NULL);
+       tpm_buf_append_u16(&buf, TPM_ALG_NULL);
        tpm_buf_append_u16(&buf, 0);
 
        /* outside info */
index 13563b8c0c3a9bd5ba95b7c45acad13f4d53e97a..9fe8c9816cf089d478fcd6c8901273963954ceed 100644 (file)
 #ifndef __LINUX_TPM_H__
 #define __LINUX_TPM_H__
 
+#include <crypto/hash_info.h>
+
 #define TPM_DIGEST_SIZE 20     /* Max TPM v1.2 PCR size */
+#define TPM_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
 
 struct tpm_chip;
 struct trusted_key_payload;
 struct trusted_key_options;
 
+enum tpm_algorithms {
+       TPM_ALG_ERROR           = 0x0000,
+       TPM_ALG_SHA1            = 0x0004,
+       TPM_ALG_KEYEDHASH       = 0x0008,
+       TPM_ALG_SHA256          = 0x000B,
+       TPM_ALG_SHA384          = 0x000C,
+       TPM_ALG_SHA512          = 0x000D,
+       TPM_ALG_NULL            = 0x0010,
+       TPM_ALG_SM3_256         = 0x0012,
+};
+
+struct tpm_digest {
+       u16 alg_id;
+       u8 digest[TPM_MAX_DIGEST_SIZE];
+} __packed;
+
 enum TPM_OPS_FLAGS {
        TPM_OPS_AUTO_STARTUP = BIT(0),
 };
index f47342361e876920bf7705a4855c3756c0c6b09c..81519f1632111ec1d26862322738e5aa5adf7c74 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef __LINUX_TPM_EVENTLOG_H__
 #define __LINUX_TPM_EVENTLOG_H__
 
-#include <crypto/hash_info.h>
+#include <linux/tpm.h>
 
 #define TCG_EVENT_NAME_LEN_MAX 255
 #define MAX_TEXT_EVENT         1000    /* Max event string length */
@@ -105,16 +105,11 @@ struct tcg_event_field {
        u8 event[0];
 } __packed;
 
-struct tpm2_digest {
-       u16 alg_id;
-       u8 digest[SHA512_DIGEST_SIZE];
-} __packed;
-
 struct tcg_pcr_event2_head {
        u32 pcr_idx;
        u32 event_type;
        u32 count;
-       struct tpm2_digest digests[];
+       struct tpm_digest digests[];
 } __packed;
 
 #endif