Skip to content

Commit 720a485

Browse files
Eric Biggersjarkkojs
authored andcommitted
KEYS: trusted_tpm1: Move private functionality out of public header
Move functionality used only by trusted_tpm1.c out of the public header <keys/trusted_tpm.h>. Specifically, change the exported functions into static functions, since they are not used outside trusted_tpm1.c, and move various other definitions and inline functions to trusted_tpm1.c. Signed-off-by: Eric Biggers <ebiggers@kernel.org> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 366284c commit 720a485

2 files changed

Lines changed: 72 additions & 87 deletions

File tree

include/keys/trusted_tpm.h

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,92 +5,13 @@
55
#include <keys/trusted-type.h>
66
#include <linux/tpm_command.h>
77

8-
/* implementation specific TPM constants */
9-
#define TPM_SIZE_OFFSET 2
10-
#define TPM_RETURN_OFFSET 6
11-
#define TPM_DATA_OFFSET 10
12-
13-
#define LOAD32(buffer, offset) (ntohl(*(uint32_t *)&buffer[offset]))
14-
#define LOAD32N(buffer, offset) (*(uint32_t *)&buffer[offset])
15-
#define LOAD16(buffer, offset) (ntohs(*(uint16_t *)&buffer[offset]))
16-
178
extern struct trusted_key_ops trusted_key_tpm_ops;
189

19-
struct osapsess {
20-
uint32_t handle;
21-
unsigned char secret[SHA1_DIGEST_SIZE];
22-
unsigned char enonce[TPM_NONCE_SIZE];
23-
};
24-
25-
/* discrete values, but have to store in uint16_t for TPM use */
26-
enum {
27-
SEAL_keytype = 1,
28-
SRK_keytype = 4
29-
};
30-
31-
int TSS_authhmac(unsigned char *digest, const unsigned char *key,
32-
unsigned int keylen, unsigned char *h1,
33-
unsigned char *h2, unsigned int h3, ...);
34-
int TSS_checkhmac1(unsigned char *buffer,
35-
const uint32_t command,
36-
const unsigned char *ononce,
37-
const unsigned char *key,
38-
unsigned int keylen, ...);
39-
40-
int trusted_tpm_send(unsigned char *cmd, size_t buflen);
41-
int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce);
42-
4310
int tpm2_seal_trusted(struct tpm_chip *chip,
4411
struct trusted_key_payload *payload,
4512
struct trusted_key_options *options);
4613
int tpm2_unseal_trusted(struct tpm_chip *chip,
4714
struct trusted_key_payload *payload,
4815
struct trusted_key_options *options);
4916

50-
#define TPM_DEBUG 0
51-
52-
#if TPM_DEBUG
53-
static inline void dump_options(struct trusted_key_options *o)
54-
{
55-
pr_info("sealing key type %d\n", o->keytype);
56-
pr_info("sealing key handle %0X\n", o->keyhandle);
57-
pr_info("pcrlock %d\n", o->pcrlock);
58-
pr_info("pcrinfo %d\n", o->pcrinfo_len);
59-
print_hex_dump(KERN_INFO, "pcrinfo ", DUMP_PREFIX_NONE,
60-
16, 1, o->pcrinfo, o->pcrinfo_len, 0);
61-
}
62-
63-
static inline void dump_sess(struct osapsess *s)
64-
{
65-
print_hex_dump(KERN_INFO, "trusted-key: handle ", DUMP_PREFIX_NONE,
66-
16, 1, &s->handle, 4, 0);
67-
pr_info("secret:\n");
68-
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE,
69-
16, 1, &s->secret, SHA1_DIGEST_SIZE, 0);
70-
pr_info("trusted-key: enonce:\n");
71-
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE,
72-
16, 1, &s->enonce, SHA1_DIGEST_SIZE, 0);
73-
}
74-
75-
static inline void dump_tpm_buf(unsigned char *buf)
76-
{
77-
int len;
78-
79-
pr_info("\ntpm buffer\n");
80-
len = LOAD32(buf, TPM_SIZE_OFFSET);
81-
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, buf, len, 0);
82-
}
83-
#else
84-
static inline void dump_options(struct trusted_key_options *o)
85-
{
86-
}
87-
88-
static inline void dump_sess(struct osapsess *s)
89-
{
90-
}
91-
92-
static inline void dump_tpm_buf(unsigned char *buf)
93-
{
94-
}
95-
#endif
9617
#endif

security/keys/trusted-keys/trusted_tpm1.c

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,74 @@
2424
static struct tpm_chip *chip;
2525
static struct tpm_digest *digests;
2626

27+
/* implementation specific TPM constants */
28+
#define TPM_SIZE_OFFSET 2
29+
#define TPM_RETURN_OFFSET 6
30+
#define TPM_DATA_OFFSET 10
31+
32+
#define LOAD32(buffer, offset) (ntohl(*(uint32_t *)&buffer[offset]))
33+
#define LOAD32N(buffer, offset) (*(uint32_t *)&buffer[offset])
34+
#define LOAD16(buffer, offset) (ntohs(*(uint16_t *)&buffer[offset]))
35+
36+
struct osapsess {
37+
uint32_t handle;
38+
unsigned char secret[SHA1_DIGEST_SIZE];
39+
unsigned char enonce[TPM_NONCE_SIZE];
40+
};
41+
42+
/* discrete values, but have to store in uint16_t for TPM use */
43+
enum {
44+
SEAL_keytype = 1,
45+
SRK_keytype = 4
46+
};
47+
48+
#define TPM_DEBUG 0
49+
50+
#if TPM_DEBUG
51+
static inline void dump_options(struct trusted_key_options *o)
52+
{
53+
pr_info("sealing key type %d\n", o->keytype);
54+
pr_info("sealing key handle %0X\n", o->keyhandle);
55+
pr_info("pcrlock %d\n", o->pcrlock);
56+
pr_info("pcrinfo %d\n", o->pcrinfo_len);
57+
print_hex_dump(KERN_INFO, "pcrinfo ", DUMP_PREFIX_NONE,
58+
16, 1, o->pcrinfo, o->pcrinfo_len, 0);
59+
}
60+
61+
static inline void dump_sess(struct osapsess *s)
62+
{
63+
print_hex_dump(KERN_INFO, "trusted-key: handle ", DUMP_PREFIX_NONE,
64+
16, 1, &s->handle, 4, 0);
65+
pr_info("secret:\n");
66+
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE,
67+
16, 1, &s->secret, SHA1_DIGEST_SIZE, 0);
68+
pr_info("trusted-key: enonce:\n");
69+
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE,
70+
16, 1, &s->enonce, SHA1_DIGEST_SIZE, 0);
71+
}
72+
73+
static inline void dump_tpm_buf(unsigned char *buf)
74+
{
75+
int len;
76+
77+
pr_info("\ntpm buffer\n");
78+
len = LOAD32(buf, TPM_SIZE_OFFSET);
79+
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, buf, len, 0);
80+
}
81+
#else
82+
static inline void dump_options(struct trusted_key_options *o)
83+
{
84+
}
85+
86+
static inline void dump_sess(struct osapsess *s)
87+
{
88+
}
89+
90+
static inline void dump_tpm_buf(unsigned char *buf)
91+
{
92+
}
93+
#endif
94+
2795
static int TSS_rawhmac(unsigned char *digest, const unsigned char *key,
2896
unsigned int keylen, ...)
2997
{
@@ -56,7 +124,7 @@ static int TSS_rawhmac(unsigned char *digest, const unsigned char *key,
56124
/*
57125
* calculate authorization info fields to send to TPM
58126
*/
59-
int TSS_authhmac(unsigned char *digest, const unsigned char *key,
127+
static int TSS_authhmac(unsigned char *digest, const unsigned char *key,
60128
unsigned int keylen, unsigned char *h1,
61129
unsigned char *h2, unsigned int h3, ...)
62130
{
@@ -94,12 +162,11 @@ int TSS_authhmac(unsigned char *digest, const unsigned char *key,
94162
TPM_NONCE_SIZE, h2, 1, &c, 0, 0);
95163
return ret;
96164
}
97-
EXPORT_SYMBOL_GPL(TSS_authhmac);
98165

99166
/*
100167
* verify the AUTH1_COMMAND (Seal) result from TPM
101168
*/
102-
int TSS_checkhmac1(unsigned char *buffer,
169+
static int TSS_checkhmac1(unsigned char *buffer,
103170
const uint32_t command,
104171
const unsigned char *ononce,
105172
const unsigned char *key,
@@ -159,7 +226,6 @@ int TSS_checkhmac1(unsigned char *buffer,
159226
return -EINVAL;
160227
return 0;
161228
}
162-
EXPORT_SYMBOL_GPL(TSS_checkhmac1);
163229

164230
/*
165231
* verify the AUTH2_COMMAND (unseal) result from TPM
@@ -244,7 +310,7 @@ static int TSS_checkhmac2(unsigned char *buffer,
244310
* For key specific tpm requests, we will generate and send our
245311
* own TPM command packets using the drivers send function.
246312
*/
247-
int trusted_tpm_send(unsigned char *cmd, size_t buflen)
313+
static int trusted_tpm_send(unsigned char *cmd, size_t buflen)
248314
{
249315
struct tpm_buf buf;
250316
int rc;
@@ -270,7 +336,6 @@ int trusted_tpm_send(unsigned char *cmd, size_t buflen)
270336
tpm_put_ops(chip);
271337
return rc;
272338
}
273-
EXPORT_SYMBOL_GPL(trusted_tpm_send);
274339

275340
/*
276341
* Lock a trusted key, by extending a selected PCR.
@@ -324,7 +389,7 @@ static int osap(struct tpm_buf *tb, struct osapsess *s,
324389
/*
325390
* Create an object independent authorisation protocol (oiap) session
326391
*/
327-
int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce)
392+
static int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce)
328393
{
329394
int ret;
330395

@@ -341,7 +406,6 @@ int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce)
341406
TPM_NONCE_SIZE);
342407
return 0;
343408
}
344-
EXPORT_SYMBOL_GPL(oiap);
345409

346410
struct tpm_digests {
347411
unsigned char encauth[SHA1_DIGEST_SIZE];

0 commit comments

Comments
 (0)