Skip to content

Commit aa04247

Browse files
robertosassuJarkko Sakkinen
authored andcommitted
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 <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: Jarkko Sakkinen <[email protected]> Acked-by: Mimi Zohar <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent bcfff83 commit aa04247

File tree

6 files changed

+33
-30
lines changed

6 files changed

+33
-30
lines changed

drivers/char/tpm/tpm-interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ EXPORT_SYMBOL_GPL(tpm_pcr_read);
318318
int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash)
319319
{
320320
int rc;
321-
struct tpm2_digest *digest_list;
321+
struct tpm_digest *digest_list;
322322
int i;
323323

324324
chip = tpm_find_get_ops(chip);

drivers/char/tpm/tpm.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ enum tpm2_return_codes {
122122
TPM2_RC_RETRY = 0x0922,
123123
};
124124

125-
enum 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-
136125
enum tpm2_command_codes {
137126
TPM2_CC_FIRST = 0x011F,
138127
TPM2_CC_HIERARCHY_CONTROL = 0x0121,
@@ -545,7 +534,7 @@ static inline u32 tpm2_rc_value(u32 rc)
545534
int tpm2_get_timeouts(struct tpm_chip *chip);
546535
int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
547536
int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count,
548-
struct tpm2_digest *digests);
537+
struct tpm_digest *digests);
549538
int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
550539
void tpm2_flush_context(struct tpm_chip *chip, u32 handle);
551540
int tpm2_seal_trusted(struct tpm_chip *chip,

drivers/char/tpm/tpm1-cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ int tpm1_auto_startup(struct tpm_chip *chip)
703703
goto out;
704704
}
705705

706-
chip->allocated_banks[0] = TPM2_ALG_SHA1;
706+
chip->allocated_banks[0] = TPM_ALG_SHA1;
707707
chip->nr_allocated_banks = 1;
708708

709709
return rc;

drivers/char/tpm/tpm2-cmd.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ struct tpm2_hash {
3333
};
3434

3535
static struct tpm2_hash tpm2_hash_map[] = {
36-
{HASH_ALGO_SHA1, TPM2_ALG_SHA1},
37-
{HASH_ALGO_SHA256, TPM2_ALG_SHA256},
38-
{HASH_ALGO_SHA384, TPM2_ALG_SHA384},
39-
{HASH_ALGO_SHA512, TPM2_ALG_SHA512},
40-
{HASH_ALGO_SM3_256, TPM2_ALG_SM3_256},
36+
{HASH_ALGO_SHA1, TPM_ALG_SHA1},
37+
{HASH_ALGO_SHA256, TPM_ALG_SHA256},
38+
{HASH_ALGO_SHA384, TPM_ALG_SHA384},
39+
{HASH_ALGO_SHA512, TPM_ALG_SHA512},
40+
{HASH_ALGO_SM3_256, TPM_ALG_SM3_256},
4141
};
4242

4343
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)
192192
pcr_select[pcr_idx >> 3] = 1 << (pcr_idx & 0x7);
193193

194194
tpm_buf_append_u32(&buf, 1);
195-
tpm_buf_append_u16(&buf, TPM2_ALG_SHA1);
195+
tpm_buf_append_u16(&buf, TPM_ALG_SHA1);
196196
tpm_buf_append_u8(&buf, TPM2_PCR_SELECT_MIN);
197197
tpm_buf_append(&buf, (const unsigned char *)pcr_select,
198198
sizeof(pcr_select));
@@ -226,7 +226,7 @@ struct tpm2_null_auth_area {
226226
* Return: Same as with tpm_transmit_cmd.
227227
*/
228228
int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count,
229-
struct tpm2_digest *digests)
229+
struct tpm_digest *digests)
230230
{
231231
struct tpm_buf buf;
232232
struct tpm2_null_auth_area auth_area;
@@ -443,7 +443,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
443443

444444
/* public */
445445
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);
447447
tpm_buf_append_u16(&buf, hash);
448448

449449
/* policy */
@@ -458,7 +458,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
458458
}
459459

460460
/* public parameters */
461-
tpm_buf_append_u16(&buf, TPM2_ALG_NULL);
461+
tpm_buf_append_u16(&buf, TPM_ALG_NULL);
462462
tpm_buf_append_u16(&buf, 0);
463463

464464
/* outside info */

include/linux/tpm.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,31 @@
2222
#ifndef __LINUX_TPM_H__
2323
#define __LINUX_TPM_H__
2424

25+
#include <crypto/hash_info.h>
26+
2527
#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */
28+
#define TPM_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
2629

2730
struct tpm_chip;
2831
struct trusted_key_payload;
2932
struct trusted_key_options;
3033

34+
enum 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+
45+
struct tpm_digest {
46+
u16 alg_id;
47+
u8 digest[TPM_MAX_DIGEST_SIZE];
48+
} __packed;
49+
3150
enum TPM_OPS_FLAGS {
3251
TPM_OPS_AUTO_STARTUP = BIT(0),
3352
};

include/linux/tpm_eventlog.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#ifndef __LINUX_TPM_EVENTLOG_H__
44
#define __LINUX_TPM_EVENTLOG_H__
55

6-
#include <crypto/hash_info.h>
6+
#include <linux/tpm.h>
77

88
#define TCG_EVENT_NAME_LEN_MAX 255
99
#define MAX_TEXT_EVENT 1000 /* Max event string length */
@@ -105,16 +105,11 @@ struct tcg_event_field {
105105
u8 event[0];
106106
} __packed;
107107

108-
struct tpm2_digest {
109-
u16 alg_id;
110-
u8 digest[SHA512_DIGEST_SIZE];
111-
} __packed;
112-
113108
struct tcg_pcr_event2_head {
114109
u32 pcr_idx;
115110
u32 event_type;
116111
u32 count;
117-
struct tpm2_digest digests[];
112+
struct tpm_digest digests[];
118113
} __packed;
119114

120115
#endif

0 commit comments

Comments
 (0)