Debian Codegraph @

stubdom/vtpmmgr/disk_format.h

raw
1 #ifndef __VTPMMGR_DISK_FORMAT_H
2 #define __VTPMMGR_DISK_FORMAT_H
3
4 static const uint8_t TPM_MGR_MAGIC[12] = {
5 'T','P','M',0xfe,'M','G','R',0xdd,'D','O','M',0x00
6 };
7
8 /**
9 * Sector 0 on disk: stored in plaintext
10 */
11 struct disk_header {
12 char magic[12];
13 #define TPM_MGR_VERSION 0
14 be32_t version;
15 };
16
17 /**
18 * Raw contents of disk sectors that need both encryption and authentication
19 */
20 struct disk_crypt_sector_plain {
21 struct mac128 mac;
22 union {
23 struct {
24 uint8_t iv[16];
25 char data[4096-32];
26 };
27 uint8_t iv_data[4096-16];
28 };
29 };
30
31 /**
32 * Contents of the sealed blob in the root seal list
33 */
34 struct disk_root_sealed_data {
35 #define DISK_ROOT_BOUND_MAGIC "Root"
36 char magic[4];
37 uuid_t tpm_manager_uuid;
38
39 be32_t nvram_slot;
40 struct tpm_authdata nvram_auth;
41 be32_t counter_index;
42 struct tpm_authdata counter_auth;
43
44 /* encrypted (AES-ECB) with key from NVRAM */
45 struct key128 tm_key;
46 };
47
48 /**
49 * Contents of the sealed blob in a group's seal list
50 */
51 struct disk_group_sealed_data {
52 #define DISK_GROUP_BOUND_MAGIC "TGrp"
53 char magic[4];
54 uuid_t tpm_manager_uuid;
55 struct tpm_authdata aik_authdata;
56
57 struct key128 group_key;
58 struct key128 rollback_mac_key;
59 };
60
61 /**
62 * Contents of the seal_list_N sectors on disk (plaintext, linked list)
63 *
64 * The hdr field is unused except in sector 0
65 */
66 struct disk_seal_list {
67 struct disk_header hdr;
68 be32_t length;
69 sector_t next;
70 #define SEALS_PER_ROOT_SEAL_LIST 13
71 struct disk_seal_entry entry[SEALS_PER_ROOT_SEAL_LIST];
72 };
73
74 /**
75 * TODO - overflow for struct disk_group_boot_config_list
76 */
77 struct disk_group_seal_list {
78 sector_t next;
79 #define SEALS_PER_GROUP_SEAL_LIST 13
80 struct disk_seal_entry entry[SEALS_PER_GROUP_SEAL_LIST];
81 };
82
83 /**
84 * Rollback detection MAC entry
85 */
86 struct disk_rb_mac_entry {
87 be32_t id;
88 struct mac128 mac;
89 };
90
91 #define NR_ENTRIES_PER_ROOT 16
92 /**
93 * The area of the root sector protected by rollback MACs
94 */
95 struct disk_root_sector_mac1_area {
96 be64_t sequence;
97 be32_t tpm_counter_value;
98
99 be32_t nr_groups;
100 struct hash256 group_hash[NR_ENTRIES_PER_ROOT];
101 };
102
103 /**
104 * Decrypted contents of the root sector (sector 1 and 2) on disk
105 */
106 struct disk_root_sector {
107 struct disk_root_sector_mac1_area v;
108
109 sector_t group_loc[NR_ENTRIES_PER_ROOT];
110
111 uint8_t pad[8];
112
113 /* Rollback detection MACs */
114 be32_t nr_rb_macs;
115 sector_t rb_next_loc;
116 /* used if rb_macs overflows */
117 struct hash256 rb_next_hash;
118
119 #define NR_RB_MACS_PER_ROOT 128
120 struct disk_rb_mac_entry rb_macs[NR_RB_MACS_PER_ROOT];
121 };
122
123 /**
124 * Hash tree for list expansion. Used for the list of groups in the root and for
125 * the list of vTPMs in a group.
126 */
127 struct disk_itree_sector {
128 #define NR_ENTRIES_PER_ITREE 112
129 sector_t location[NR_ENTRIES_PER_ITREE];
130 /* SECTOR-HASH { */
131 struct hash256 hash[NR_ENTRIES_PER_ITREE];
132 /* SECTOR-HASH } */
133 };
134
135 #define NR_ENTRIES_PER_GROUP_BASE 16
136 /**
137 * Data that must remain constant if a group is not open
138 */
139 struct disk_group_sector_mac3_area {
140 struct group_id_data id_data; /* MAC2 */
141 struct group_details details;
142 struct disk_group_boot_config_list boot_configs;
143
144 be32_t nr_vtpms;
145 struct hash256 vtpm_hash[NR_ENTRIES_PER_GROUP_BASE];
146 };
147
148 /**
149 * Group metadata sector
150 *
151 * Encrypted with TM_KEY - takes 16 bytes for IV; integrity from parent.
152 */
153 struct disk_group_sector {
154 /* SECTOR-HASH { */
155 struct disk_group_sector_mac3_area v;
156
157 /* MAC(MAC3, group_key) */
158 struct mac128 group_mac;
159 /* SECTOR-HASH } */
160
161 sector_t vtpm_location[NR_ENTRIES_PER_GROUP_BASE];
162 sector_t boot_configs_next;
163 };
164
165 /**
166 * Data on a vTPM which is available when its group is not open
167 */
168 struct disk_vtpm_plain {
169 uuid_t uuid;
170 be32_t flags;
171 };
172
173 /**
174 * Data on a vTPM which is only available when its group is open
175 */
176 struct disk_vtpm_secret {
177 uint8_t data[64];
178 };
179
180 /**
181 * Contents of a vTPM data disk sector
182 *
183 * Encrypted with TM_KEY - takes 16 bytes for IV
184 */
185 struct disk_vtpm_sector {
186 /* SECTOR-HASH { */
187 struct disk_vtpm_plain header[VTPMS_PER_SECTOR];
188 struct mac128 iv;
189 struct disk_vtpm_secret data[VTPMS_PER_SECTOR];
190 /* SECTOR-HASH } */
191 };
192
193 #endif