Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2010 IBM Corporation
4 * Author: David Safford <safford@us.ibm.com>
5 */
6
7#ifndef _KEYS_TRUSTED_TYPE_H
8#define _KEYS_TRUSTED_TYPE_H
9
10#include <linux/key.h>
11#include <linux/rcupdate.h>
12#include <linux/tpm.h>
13
14#ifdef pr_fmt
15#undef pr_fmt
16#endif
17
18#define pr_fmt(fmt) "trusted_key: " fmt
19
20#define MIN_KEY_SIZE 32
21#define MAX_KEY_SIZE 128
22#if IS_ENABLED(CONFIG_TRUSTED_KEYS_PKWM)
23#define MAX_BLOB_SIZE 1152
24#else
25#define MAX_BLOB_SIZE 512
26#endif
27#define MAX_PCRINFO_SIZE 64
28#define MAX_DIGEST_SIZE 64
29
30struct trusted_key_payload {
31 struct rcu_head rcu;
32 unsigned int key_len;
33 unsigned int blob_len;
34 unsigned char migratable;
35 unsigned char old_format;
36 unsigned char key[MAX_KEY_SIZE + 1];
37 unsigned char blob[MAX_BLOB_SIZE];
38};
39
40struct trusted_key_options {
41 uint16_t keytype;
42 uint32_t keyhandle;
43 unsigned char keyauth[TPM_DIGEST_SIZE];
44 uint32_t blobauth_len;
45 unsigned char blobauth[TPM_DIGEST_SIZE];
46 uint32_t pcrinfo_len;
47 unsigned char pcrinfo[MAX_PCRINFO_SIZE];
48 int pcrlock;
49 uint32_t hash;
50 uint32_t policydigest_len;
51 unsigned char policydigest[MAX_DIGEST_SIZE];
52 uint32_t policyhandle;
53 void *private;
54};
55
56struct trusted_key_ops {
57 /*
58 * flag to indicate if trusted key implementation supports migration
59 * or not.
60 */
61 unsigned char migratable;
62
63 /* Initialize key interface. */
64 int (*init)(void);
65
66 /* Seal a key. */
67 int (*seal)(struct trusted_key_payload *p, char *datablob);
68
69 /* Unseal a key. */
70 int (*unseal)(struct trusted_key_payload *p, char *datablob);
71
72 /* Optional: Get a randomized key. */
73 int (*get_random)(unsigned char *key, size_t key_len);
74
75 /* Exit key interface. */
76 void (*exit)(void);
77};
78
79struct trusted_key_source {
80 char *name;
81 struct trusted_key_ops *ops;
82};
83
84extern struct key_type key_type_trusted;
85
86#define TRUSTED_DEBUG 0
87
88#if TRUSTED_DEBUG
89static inline void dump_payload(struct trusted_key_payload *p)
90{
91 pr_info("key_len %d\n", p->key_len);
92 print_hex_dump(KERN_INFO, "key ", DUMP_PREFIX_NONE,
93 16, 1, p->key, p->key_len, 0);
94 pr_info("bloblen %d\n", p->blob_len);
95 print_hex_dump(KERN_INFO, "blob ", DUMP_PREFIX_NONE,
96 16, 1, p->blob, p->blob_len, 0);
97 pr_info("migratable %d\n", p->migratable);
98}
99#else
100static inline void dump_payload(struct trusted_key_payload *p)
101{
102}
103#endif
104
105#endif /* _KEYS_TRUSTED_TYPE_H */