blob: b2b35f24efb4e7eada03854d346dc7f7314b03b9 [file] [log] [blame]
Randall Spangler3333e572014-05-14 11:37:52 -07001/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 *
5 * Data structure definitions for verified boot, for on-disk / in-eeprom
6 * data.
7 */
8
9#ifndef VBOOT_REFERENCE_VBOOT_2STRUCT_H_
10#define VBOOT_REFERENCE_VBOOT_2STRUCT_H_
11#include <stdint.h>
12
Randall Spangler7c1eee02014-11-14 09:39:42 -080013#include "2guid.h"
Randall Spanglercc7cddb2014-10-31 11:38:14 -070014
Randall Spangler108d9912014-12-02 15:55:56 -080015/* Algorithm types for signatures */
16enum vb2_signature_algorithm {
17 /* Invalid or unsupported signature type */
18 VB2_SIG_INVALID = 0,
19
20 /*
21 * No signature algorithm. The digest is unsigned. See
22 * VB2_GUID_NONE_* above for key GUIDs to use with this algorithm.
23 */
24 VB2_SIG_NONE = 1,
25
26 /* RSA algorithms of the given length in bits (1024-8192) */
27 VB2_SIG_RSA1024 = 2, /* Warning! This is likely to be deprecated! */
28 VB2_SIG_RSA2048 = 3,
29 VB2_SIG_RSA4096 = 4,
30 VB2_SIG_RSA8192 = 5,
31};
32
33/* Algorithm types for hash digests */
34enum vb2_hash_algorithm {
35 /* Invalid or unsupported digest type */
36 VB2_HASH_INVALID = 0,
37
38 /* SHA-1. Warning: This is likely to be deprecated soon! */
39 VB2_HASH_SHA1 = 1,
40
41 /* SHA-256 and SHA-512 */
42 VB2_HASH_SHA256 = 2,
43 VB2_HASH_SHA512 = 3,
44};
45
Randall Spangler21f100c2014-10-16 10:32:43 -070046/****************************************************************************/
Randall Spangler3333e572014-05-14 11:37:52 -070047/*
Randall Spangler21f100c2014-10-16 10:32:43 -070048 * Vboot1-compatible data structures
49 *
50 *
Randall Spangler3333e572014-05-14 11:37:52 -070051 * Note: Many of the structs have pairs of 32-bit fields and reserved fields.
52 * This is to be backwards-compatible with older verified boot data which used
53 * 64-bit fields (when we thought that hey, UEFI is 64-bit so all our fields
54 * should be too).
55 */
56
57/* Packed public key data */
58struct vb2_packed_key {
59 /* Offset of key data from start of this struct */
60 uint32_t key_offset;
61 uint32_t reserved0;
62
63 /* Size of key data in bytes (NOT strength of key in bits) */
64 uint32_t key_size;
65 uint32_t reserved1;
66
Randall Spanglerf2f88042014-10-15 13:41:52 -070067 /* Signature algorithm used by the key (enum vb2_crypto_algorithm) */
Randall Spangler3333e572014-05-14 11:37:52 -070068 uint32_t algorithm;
69 uint32_t reserved2;
70
71 /* Key version */
72 uint32_t key_version;
73 uint32_t reserved3;
74
75 /* TODO: when redoing this struct, add a text description of the key */
76} __attribute__((packed));
77
Randall Spangler21f100c2014-10-16 10:32:43 -070078#define EXPECTED_VB2_PACKED_KEY_SIZE 32
Randall Spangler3333e572014-05-14 11:37:52 -070079
80/* Signature data (a secure hash, possibly signed) */
81struct vb2_signature {
82 /* Offset of signature data from start of this struct */
83 uint32_t sig_offset;
84 uint32_t reserved0;
85
86 /* Size of signature data in bytes */
87 uint32_t sig_size;
88 uint32_t reserved1;
89
90 /* Size of the data block which was signed in bytes */
91 uint32_t data_size;
92 uint32_t reserved2;
Randall Spangler3333e572014-05-14 11:37:52 -070093} __attribute__((packed));
94
Randall Spangler21f100c2014-10-16 10:32:43 -070095#define EXPECTED_VB2_SIGNATURE_SIZE 24
Randall Spangler3333e572014-05-14 11:37:52 -070096
97#define KEY_BLOCK_MAGIC "CHROMEOS"
98#define KEY_BLOCK_MAGIC_SIZE 8
99
100#define KEY_BLOCK_HEADER_VERSION_MAJOR 2
101#define KEY_BLOCK_HEADER_VERSION_MINOR 1
102
103/*
104 * The following flags set where the key is valid. Not used by firmware
105 * verification; only kernel verification.
106 */
107#define VB2_KEY_BLOCK_FLAG_DEVELOPER_0 0x01 /* Developer switch off */
108#define VB2_KEY_BLOCK_FLAG_DEVELOPER_1 0x02 /* Developer switch on */
109#define VB2_KEY_BLOCK_FLAG_RECOVERY_0 0x04 /* Not recovery mode */
110#define VB2_KEY_BLOCK_FLAG_RECOVERY_1 0x08 /* Recovery mode */
111
112/*
113 * Key block, containing the public key used to sign some other chunk of data.
114 *
115 * This should be followed by:
116 * 1) The data_key key data, pointed to by data_key.key_offset.
117 * 2) The checksum data for (vb2_keyblock + data_key data), pointed to
118 * by keyblock_checksum.sig_offset.
119 * 3) The signature data for (vb2_keyblock + data_key data), pointed to
120 * by keyblock_signature.sig_offset.
121 */
122struct vb2_keyblock {
123 /* Magic number */
124 uint8_t magic[KEY_BLOCK_MAGIC_SIZE];
125
126 /* Version of this header format */
127 uint32_t header_version_major;
128
129 /* Version of this header format */
130 uint32_t header_version_minor;
131
132 /*
133 * Length of this entire key block, including keys, signatures, and
134 * padding, in bytes
135 */
136 uint32_t keyblock_size;
137 uint32_t reserved0;
138
139 /*
140 * Signature for this key block (header + data pointed to by data_key)
141 * For use with signed data keys
142 */
143 struct vb2_signature keyblock_signature;
144
145 /*
146 * SHA-512 checksum for this key block (header + data pointed to by
147 * data_key) For use with unsigned data keys.
148 *
149 * Note that the vb2 lib currently only supports signed blocks.
150 */
151 struct vb2_signature keyblock_checksum_unused;
152
153 /* Flags for key (VB2_KEY_BLOCK_FLAG_*) */
154 uint32_t keyblock_flags;
155 uint32_t reserved1;
156
157 /* Key to verify the chunk of data */
158 struct vb2_packed_key data_key;
159} __attribute__((packed));
160
Randall Spangler21f100c2014-10-16 10:32:43 -0700161#define EXPECTED_VB2_KEYBLOCK_SIZE 112
Randall Spangler3333e572014-05-14 11:37:52 -0700162
Randall Spangler3333e572014-05-14 11:37:52 -0700163
164/* Firmware preamble header */
165#define FIRMWARE_PREAMBLE_HEADER_VERSION_MAJOR 2
166#define FIRMWARE_PREAMBLE_HEADER_VERSION_MINOR 1
167
168/* Flags for VbFirmwarePreambleHeader.flags */
169/* Reserved; do not use */
170#define VB2_FIRMWARE_PREAMBLE_RESERVED0 0x00000001
171
172/* Premable block for rewritable firmware, version 2.1.
173 *
174 * The firmware preamble header should be followed by:
175 * 1) The kernel_subkey key data, pointed to by kernel_subkey.key_offset.
176 * 2) The signature data for the firmware body, pointed to by
177 * body_signature.sig_offset.
178 * 3) The signature data for (header + kernel_subkey data + body signature
179 * data), pointed to by preamble_signature.sig_offset.
180 */
181struct vb2_fw_preamble {
182 /*
183 * Size of this preamble, including keys, signatures, and padding, in
184 * bytes
185 */
186 uint32_t preamble_size;
187 uint32_t reserved0;
188
189 /*
190 * Signature for this preamble (header + kernel subkey + body
191 * signature)
192 */
193 struct vb2_signature preamble_signature;
194
195 /* Version of this header format */
196 uint32_t header_version_major;
197 uint32_t header_version_minor;
198
199 /* Firmware version */
200 uint32_t firmware_version;
201 uint32_t reserved1;
202
203 /* Key to verify kernel key block */
204 struct vb2_packed_key kernel_subkey;
205
206 /* Signature for the firmware body */
207 struct vb2_signature body_signature;
208
209 /*
210 * Fields added in header version 2.1. You must verify the header
211 * version before reading these fields!
212 */
213
214 /*
215 * Flags; see VB2_FIRMWARE_PREAMBLE_*. Readers should return 0 for
216 * header version < 2.1.
217 */
218 uint32_t flags;
219} __attribute__((packed));
220
Randall Spangler21f100c2014-10-16 10:32:43 -0700221#define EXPECTED_VB2_FW_PREAMBLE_SIZE 108
222
223/****************************************************************************/
Randall Spangler3333e572014-05-14 11:37:52 -0700224
225/* Flags for vb2_shared_data.flags */
226enum vb2_shared_data_flags {
227 /* User has explicitly and physically requested recovery */
228 VB2_SD_FLAG_MANUAL_RECOVERY = (1 << 0),
229
230 /* Developer mode is enabled */
231 VB2_SD_DEV_MODE_ENABLED = (1 << 1),
232
233 /*
234 * TODO: might be nice to add flags for why dev mode is enabled - via
235 * gbb, virtual dev switch, or forced on for testing.
236 */
237};
238
239/* Flags for vb2_shared_data.status */
240enum vb2_shared_data_status {
241 /* Reinitialized NV data due to invalid checksum */
242 VB2_SD_STATUS_NV_REINIT = (1 << 0),
243
244 /* NV data has been initialized */
245 VB2_SD_STATUS_NV_INIT = (1 << 1),
246
247 /* Secure data initialized */
248 VB2_SD_STATUS_SECDATA_INIT = (1 << 2),
249
250 /* Chose a firmware slot */
251 VB2_SD_STATUS_CHOSE_SLOT = (1 << 3),
252};
253
254/*
255 * Data shared between vboot API calls. Stored at the start of the work
256 * buffer.
257 */
258struct vb2_shared_data {
259 /* Flags; see enum vb2_shared_data_flags */
260 uint32_t flags;
261
262 /* Flags from GBB header */
263 uint32_t gbb_flags;
264
Randall Spanglerf2f88042014-10-15 13:41:52 -0700265 /*
266 * Reason we are in recovery mode this boot (enum vb2_nv_recovery), or
267 * 0 if we aren't.
268 */
Randall Spangler3333e572014-05-14 11:37:52 -0700269 uint32_t recovery_reason;
270
271 /* Firmware slot used last boot (0=A, 1=B) */
272 uint32_t last_fw_slot;
273
274 /* Result of last boot (enum vb2_fw_result) */
275 uint32_t last_fw_result;
276
277 /* Firmware slot used this boot */
278 uint32_t fw_slot;
279
280 /*
281 * Version for this slot (top 16 bits = key, lower 16 bits = firmware).
282 *
283 * TODO: Make this a union to allow getting/setting those versions
284 * separately?
285 */
286 uint32_t fw_version;
287
288 /*
289 * Status flags for this boot; see enum vb2_shared_data_status. Status
290 * is "what we've done"; flags above are "decisions we've made".
291 */
292 uint32_t status;
293
294 /**********************************************************************
295 * Temporary variables used during firmware verification. These don't
296 * really need to persist through to the OS, but there's nowhere else
297 * we can put them.
298 */
299
300 /* Root key offset and size from GBB header */
301 uint32_t gbb_rootkey_offset;
302 uint32_t gbb_rootkey_size;
303
304 /* Offset of preamble from start of vblock */
305 uint32_t vblock_preamble_offset;
306
307 /*
308 * Offset and size of packed data key in work buffer. Size is 0 if
309 * data key is not stored in the work buffer.
310 */
311 uint32_t workbuf_data_key_offset;
312 uint32_t workbuf_data_key_size;
313
314 /*
315 * Offset and size of firmware preamble in work buffer. Size if 0 if
316 * preamble is not stored in the work buffer.
317 */
318 uint32_t workbuf_preamble_offset;
319 uint32_t workbuf_preamble_size;
320
321 /*
322 * Offset and size of hash context in work buffer. Size if 0 if
323 * hash context is not stored in the work buffer.
324 */
325 uint32_t workbuf_hash_offset;
326 uint32_t workbuf_hash_size;
327
Randall Spanglerefa37b82014-11-12 16:20:50 -0800328 /*
329 * Current tag we're hashing
330 *
331 * For new structs, this is the offset of the vb2_signature2 struct
332 * in the work buffer.
333 *
334 * TODO: rename to workbuf_hash_sig_offset when vboot1 structs are
335 * deprecated.
336 */
Randall Spangler3333e572014-05-14 11:37:52 -0700337 uint32_t hash_tag;
338
339 /* Amount of data we still expect to hash */
340 uint32_t hash_remaining_size;
341
342} __attribute__((packed));
343
344/****************************************************************************/
345
Daisuke Nojirifc173082014-06-24 12:26:39 -0700346/* Signature at start of the GBB
347 * Note that if you compile in the signature as is, you are likely to break any
348 * tools that search for the signature. */
Randall Spangler3333e572014-05-14 11:37:52 -0700349#define VB2_GBB_SIGNATURE "$GBB"
350#define VB2_GBB_SIGNATURE_SIZE 4
Daisuke Nojirifc173082014-06-24 12:26:39 -0700351#define VB2_GBB_XOR_CHARS "****"
352/* TODO: can we write a macro to produce this at compile time? */
353#define VB2_GBB_XOR_SIGNATURE { 0x0e, 0x6d, 0x68, 0x68 }
Randall Spangler3333e572014-05-14 11:37:52 -0700354
355/* VB2 GBB struct version */
356#define VB2_GBB_MAJOR_VER 1
Bill Richardson6df3e332014-10-02 18:50:33 -0700357#define VB2_GBB_MINOR_VER 2
358/* v1.2 - added fields for sha256 digest of the HWID */
Randall Spangler3333e572014-05-14 11:37:52 -0700359
360/* Flags for vb2_gbb_header.flags */
361enum vb2_gbb_flag {
362 /*
363 * Reduce the dev screen delay to 2 sec from 30 sec to speed up
364 * factory.
365 */
366 VB2_GBB_FLAG_DEV_SCREEN_SHORT_DELAY = (1 << 0),
367
368 /*
369 * BIOS should load option ROMs from arbitrary PCI devices. We'll never
370 * enable this ourselves because it executes non-verified code, but if
371 * a customer wants to void their warranty and set this flag in the
372 * read-only flash, they should be able to do so.
373 */
374 VB2_GBB_FLAG_LOAD_OPTION_ROMS = (1 << 1),
375
376 /*
377 * The factory flow may need the BIOS to boot a non-ChromeOS kernel if
378 * the dev-switch is on. This flag allows that.
379 */
380 VB2_GBB_FLAG_ENABLE_ALTERNATE_OS = (1 << 2),
381
382 /*
383 * Force dev switch on, regardless of physical/keyboard dev switch
384 * position.
385 */
386 VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON = (1 << 3),
387
388 /* Allow booting from USB in dev mode even if dev_boot_usb=0. */
389 VB2_GBB_FLAG_FORCE_DEV_BOOT_USB = (1 << 4),
390
391 /* Disable firmware rollback protection. */
392 VB2_GBB_FLAG_DISABLE_FW_ROLLBACK_CHECK = (1 << 5),
393
394 /* Allow Enter key to trigger dev->tonorm screen transition */
395 VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM = (1 << 6),
396
397 /* Allow booting Legacy OSes in dev mode even if dev_boot_legacy=0. */
398 VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY = (1 << 7),
399
400 /* Allow booting using alternate keys for FAFT servo testing */
401 VB2_GBB_FLAG_FAFT_KEY_OVERIDE = (1 << 8),
402
403 /* Disable EC software sync */
404 VB2_GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC = (1 << 9),
405
406 /* Default to booting legacy OS when dev screen times out */
407 VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY = (1 << 10),
Duncan Laurie277dc522014-08-11 12:30:04 -0700408
409 /* Disable PD software sync */
410 VB2_GBB_FLAG_DISABLE_PD_SOFTWARE_SYNC = (1 << 11),
Randall Spangler3333e572014-05-14 11:37:52 -0700411};
412
413struct vb2_gbb_header {
414 /* Fields present in version 1.1 */
415 uint8_t signature[VB2_GBB_SIGNATURE_SIZE]; /* VB2_GBB_SIGNATURE */
416 uint16_t major_version; /* See VB2_GBB_MAJOR_VER */
417 uint16_t minor_version; /* See VB2_GBB_MINOR_VER */
418 uint32_t header_size; /* Size of GBB header in bytes */
419 uint32_t flags; /* Flags (see enum vb2_gbb_flag) */
420
421 /* Offsets (from start of header) and sizes (in bytes) of components */
422 uint32_t hwid_offset; /* HWID */
423 uint32_t hwid_size;
424 uint32_t rootkey_offset; /* Root key */
425 uint32_t rootkey_size;
426 uint32_t bmpfv_offset; /* BMP FV */
427 uint32_t bmpfv_size;
428 uint32_t recovery_key_offset; /* Recovery key */
429 uint32_t recovery_key_size;
430
Bill Richardson6df3e332014-10-02 18:50:33 -0700431 /* Added in version 1.2 */
Randall Spangler21f100c2014-10-16 10:32:43 -0700432 uint8_t hwid_digest[32]; /* SHA-256 of HWID */
Bill Richardson6df3e332014-10-02 18:50:33 -0700433
Randall Spangler21f100c2014-10-16 10:32:43 -0700434 /* Pad to match EXPECETED_VB2_GBB_HEADER_SIZE. Initialize to 0. */
435 uint8_t pad[48];
Randall Spangler3333e572014-05-14 11:37:52 -0700436} __attribute__((packed));
437
Bill Richardson6df3e332014-10-02 18:50:33 -0700438/* The GBB is used outside of vboot_reference, so this size is important. */
Randall Spangler21f100c2014-10-16 10:32:43 -0700439#define EXPECTED_VB2_GBB_HEADER_SIZE 128
Bill Richardson6df3e332014-10-02 18:50:33 -0700440
Randall Spangler3333e572014-05-14 11:37:52 -0700441#endif /* VBOOT_REFERENCE_VBOOT_2STRUCT_H_ */