summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto Sassu <roberto.sassu@huawei.com>2019-02-06 11:24:48 -0500
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>2019-02-13 02:48:51 -0500
commitaa042475938f5818b0c1b6203061e85ad2535dbc (patch)
treefc8877456080261012f396f53514626c122fac33
parentbcfff8384f6c4e6627676ef07ccad9cfacd67849 (diff)
tpm: rename and export tpm2_digest and tpm2_algorithms
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>
-rw-r--r--drivers/char/tpm/tpm-interface.c2
-rw-r--r--drivers/char/tpm/tpm.h13
-rw-r--r--drivers/char/tpm/tpm1-cmd.c2
-rw-r--r--drivers/char/tpm/tpm2-cmd.c18
-rw-r--r--include/linux/tpm.h19
-rw-r--r--include/linux/tpm_eventlog.h9
6 files changed, 33 insertions, 30 deletions
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 2b31eff06b0e..9c6aa77b5dee 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -318,7 +318,7 @@ EXPORT_SYMBOL_GPL(tpm_pcr_read);
318int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash) 318int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash)
319{ 319{
320 int rc; 320 int rc;
321 struct tpm2_digest *digest_list; 321 struct tpm_digest *digest_list;
322 int i; 322 int i;
323 323
324 chip = tpm_find_get_ops(chip); 324 chip = tpm_find_get_ops(chip);
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index cd330ace6248..0e54061d3fd1 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -122,17 +122,6 @@ enum tpm2_return_codes {
122 TPM2_RC_RETRY = 0x0922, 122 TPM2_RC_RETRY = 0x0922,
123}; 123};
124 124
125enum tpm2_algorithms {
126 TPM2_ALG_ERROR = 0x0000,
127 TPM2_ALG_SHA1 = 0x0004,
128 TPM2_ALG_KEYEDHASH = 0x0008,
129 TPM2_ALG_SHA256 = 0x000B,
130 TPM2_ALG_SHA384 = 0x000C,
131 TPM2_ALG_SHA512 = 0x000D,
132 TPM2_ALG_NULL = 0x0010,
133 TPM2_ALG_SM3_256 = 0x0012,
134};
135
136enum tpm2_command_codes { 125enum tpm2_command_codes {
137 TPM2_CC_FIRST = 0x011F, 126 TPM2_CC_FIRST = 0x011F,
138 TPM2_CC_HIERARCHY_CONTROL = 0x0121, 127 TPM2_CC_HIERARCHY_CONTROL = 0x0121,
@@ -545,7 +534,7 @@ static inline u32 tpm2_rc_value(u32 rc)
545int tpm2_get_timeouts(struct tpm_chip *chip); 534int tpm2_get_timeouts(struct tpm_chip *chip);
546int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf); 535int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
547int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count, 536int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count,
548 struct tpm2_digest *digests); 537 struct tpm_digest *digests);
549int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max); 538int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
550void tpm2_flush_context(struct tpm_chip *chip, u32 handle); 539void tpm2_flush_context(struct tpm_chip *chip, u32 handle);
551int tpm2_seal_trusted(struct tpm_chip *chip, 540int tpm2_seal_trusted(struct tpm_chip *chip,
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index e7d3228a0f37..3eb7e03889a0 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -703,7 +703,7 @@ int tpm1_auto_startup(struct tpm_chip *chip)
703 goto out; 703 goto out;
704 } 704 }
705 705
706 chip->allocated_banks[0] = TPM2_ALG_SHA1; 706 chip->allocated_banks[0] = TPM_ALG_SHA1;
707 chip->nr_allocated_banks = 1; 707 chip->nr_allocated_banks = 1;
708 708
709 return rc; 709 return rc;
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index bd20b9a61fc0..440ae6ee29e4 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -33,11 +33,11 @@ struct tpm2_hash {
33}; 33};
34 34
35static struct tpm2_hash tpm2_hash_map[] = { 35static struct tpm2_hash tpm2_hash_map[] = {
36 {HASH_ALGO_SHA1, TPM2_ALG_SHA1}, 36 {HASH_ALGO_SHA1, TPM_ALG_SHA1},
37 {HASH_ALGO_SHA256, TPM2_ALG_SHA256}, 37 {HASH_ALGO_SHA256, TPM_ALG_SHA256},
38 {HASH_ALGO_SHA384, TPM2_ALG_SHA384}, 38 {HASH_ALGO_SHA384, TPM_ALG_SHA384},
39 {HASH_ALGO_SHA512, TPM2_ALG_SHA512}, 39 {HASH_ALGO_SHA512, TPM_ALG_SHA512},
40 {HASH_ALGO_SM3_256, TPM2_ALG_SM3_256}, 40 {HASH_ALGO_SM3_256, TPM_ALG_SM3_256},
41}; 41};
42 42
43int tpm2_get_timeouts(struct tpm_chip *chip) 43int 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)
192 pcr_select[pcr_idx >> 3] = 1 << (pcr_idx & 0x7); 192 pcr_select[pcr_idx >> 3] = 1 << (pcr_idx & 0x7);
193 193
194 tpm_buf_append_u32(&buf, 1); 194 tpm_buf_append_u32(&buf, 1);
195 tpm_buf_append_u16(&buf, TPM2_ALG_SHA1); 195 tpm_buf_append_u16(&buf, TPM_ALG_SHA1);
196 tpm_buf_append_u8(&buf, TPM2_PCR_SELECT_MIN); 196 tpm_buf_append_u8(&buf, TPM2_PCR_SELECT_MIN);
197 tpm_buf_append(&buf, (const unsigned char *)pcr_select, 197 tpm_buf_append(&buf, (const unsigned char *)pcr_select,
198 sizeof(pcr_select)); 198 sizeof(pcr_select));
@@ -226,7 +226,7 @@ struct tpm2_null_auth_area {
226 * Return: Same as with tpm_transmit_cmd. 226 * Return: Same as with tpm_transmit_cmd.
227 */ 227 */
228int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count, 228int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count,
229 struct tpm2_digest *digests) 229 struct tpm_digest *digests)
230{ 230{
231 struct tpm_buf buf; 231 struct tpm_buf buf;
232 struct tpm2_null_auth_area auth_area; 232 struct tpm2_null_auth_area auth_area;
@@ -443,7 +443,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
443 443
444 /* public */ 444 /* public */
445 tpm_buf_append_u16(&buf, 14 + options->policydigest_len); 445 tpm_buf_append_u16(&buf, 14 + options->policydigest_len);
446 tpm_buf_append_u16(&buf, TPM2_ALG_KEYEDHASH); 446 tpm_buf_append_u16(&buf, TPM_ALG_KEYEDHASH);
447 tpm_buf_append_u16(&buf, hash); 447 tpm_buf_append_u16(&buf, hash);
448 448
449 /* policy */ 449 /* policy */
@@ -458,7 +458,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
458 } 458 }
459 459
460 /* public parameters */ 460 /* public parameters */
461 tpm_buf_append_u16(&buf, TPM2_ALG_NULL); 461 tpm_buf_append_u16(&buf, TPM_ALG_NULL);
462 tpm_buf_append_u16(&buf, 0); 462 tpm_buf_append_u16(&buf, 0);
463 463
464 /* outside info */ 464 /* outside info */
diff --git a/include/linux/tpm.h b/include/linux/tpm.h
index 13563b8c0c3a..9fe8c9816cf0 100644
--- a/include/linux/tpm.h
+++ b/include/linux/tpm.h
@@ -22,12 +22,31 @@
22#ifndef __LINUX_TPM_H__ 22#ifndef __LINUX_TPM_H__
23#define __LINUX_TPM_H__ 23#define __LINUX_TPM_H__
24 24
25#include <crypto/hash_info.h>
26
25#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */ 27#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */
28#define TPM_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
26 29
27struct tpm_chip; 30struct tpm_chip;
28struct trusted_key_payload; 31struct trusted_key_payload;
29struct trusted_key_options; 32struct trusted_key_options;
30 33
34enum tpm_algorithms {
35 TPM_ALG_ERROR = 0x0000,
36 TPM_ALG_SHA1 = 0x0004,
37 TPM_ALG_KEYEDHASH = 0x0008,
38 TPM_ALG_SHA256 = 0x000B,
39 TPM_ALG_SHA384 = 0x000C,
40 TPM_ALG_SHA512 = 0x000D,
41 TPM_ALG_NULL = 0x0010,
42 TPM_ALG_SM3_256 = 0x0012,
43};
44
45struct tpm_digest {
46 u16 alg_id;
47 u8 digest[TPM_MAX_DIGEST_SIZE];
48} __packed;
49
31enum TPM_OPS_FLAGS { 50enum TPM_OPS_FLAGS {
32 TPM_OPS_AUTO_STARTUP = BIT(0), 51 TPM_OPS_AUTO_STARTUP = BIT(0),
33}; 52};
diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h
index f47342361e87..81519f163211 100644
--- a/include/linux/tpm_eventlog.h
+++ b/include/linux/tpm_eventlog.h
@@ -3,7 +3,7 @@
3#ifndef __LINUX_TPM_EVENTLOG_H__ 3#ifndef __LINUX_TPM_EVENTLOG_H__
4#define __LINUX_TPM_EVENTLOG_H__ 4#define __LINUX_TPM_EVENTLOG_H__
5 5
6#include <crypto/hash_info.h> 6#include <linux/tpm.h>
7 7
8#define TCG_EVENT_NAME_LEN_MAX 255 8#define TCG_EVENT_NAME_LEN_MAX 255
9#define MAX_TEXT_EVENT 1000 /* Max event string length */ 9#define MAX_TEXT_EVENT 1000 /* Max event string length */
@@ -105,16 +105,11 @@ struct tcg_event_field {
105 u8 event[0]; 105 u8 event[0];
106} __packed; 106} __packed;
107 107
108struct tpm2_digest {
109 u16 alg_id;
110 u8 digest[SHA512_DIGEST_SIZE];
111} __packed;
112
113struct tcg_pcr_event2_head { 108struct tcg_pcr_event2_head {
114 u32 pcr_idx; 109 u32 pcr_idx;
115 u32 event_type; 110 u32 event_type;
116 u32 count; 111 u32 count;
117 struct tpm2_digest digests[]; 112 struct tpm_digest digests[];
118} __packed; 113} __packed;
119 114
120#endif 115#endif