OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 * | 4 * |
5 * Data structure and API definitions for a verified boot kernel image. | 5 * Data structure and API definitions for a verified boot kernel image. |
6 * (Firmware Portion) | 6 * (Firmware Portion) |
7 */ | 7 */ |
8 | 8 |
9 #ifndef VBOOT_REFERENCE_KERNEL_IMAGE_FW_H_ | 9 #ifndef VBOOT_REFERENCE_KERNEL_IMAGE_FW_H_ |
10 #define VBOOT_REFERENCE_KERNEL_IMAGE_FW_H_ | 10 #define VBOOT_REFERENCE_KERNEL_IMAGE_FW_H_ |
11 | 11 |
12 #include <stdint.h> | 12 #include <stdint.h> |
13 | 13 |
14 #include "cryptolib.h" | 14 #include "cryptolib.h" |
15 | 15 |
16 #define KERNEL_MAGIC "CHROMEOS" | 16 #define KERNEL_MAGIC "CHROMEOS" |
17 #define KERNEL_MAGIC_SIZE 8 | 17 #define KERNEL_MAGIC_SIZE 8 |
18 #define KERNEL_CONFIG_SIZE 4096 | |
19 | 18 |
20 #define DEV_MODE_ENABLED 1 | 19 #define DEV_MODE_ENABLED 1 |
21 #define DEV_MODE_DISABLED 0 | 20 #define DEV_MODE_DISABLED 0 |
22 | 21 |
23 typedef struct KernelImage { | 22 typedef struct KernelImage { |
24 uint8_t magic[KERNEL_MAGIC_SIZE]; | 23 uint8_t magic[KERNEL_MAGIC_SIZE]; |
25 /* Key header */ | 24 /* Key header */ |
26 uint16_t header_version; /* Header version. */ | 25 uint16_t header_version; /* Header version. */ |
27 uint16_t header_len; /* Length of the header. */ | 26 uint16_t header_len; /* Length of the header. */ |
28 uint16_t firmware_sign_algorithm; /* Signature algorithm used by the firmware | 27 uint16_t firmware_sign_algorithm; /* Signature algorithm used by the firmware |
29 * signing key (used to sign this kernel | 28 * signing key (used to sign this kernel |
30 * header. */ | 29 * header. */ |
31 uint16_t kernel_sign_algorithm; /* Signature algorithm used by the kernel | 30 uint16_t kernel_sign_algorithm; /* Signature algorithm used by the kernel |
32 * signing key. */ | 31 * signing key. */ |
33 uint16_t kernel_key_version; /* Key Version# for preventing rollbacks. */ | 32 uint16_t kernel_key_version; /* Key Version# for preventing rollbacks. */ |
34 uint8_t* kernel_sign_key; /* Pre-processed public half of signing key. */ | 33 uint8_t* kernel_sign_key; /* Pre-processed public half of signing key. */ |
35 /* TODO(gauravsh): Do we need a choice of digest algorithms for the header | 34 /* TODO(gauravsh): Do we need a choice of digest algorithms for the header |
36 * checksum? */ | 35 * checksum? */ |
37 uint8_t header_checksum[SHA512_DIGEST_SIZE]; /* SHA-512 Crytographic hash of | 36 uint8_t header_checksum[SHA512_DIGEST_SIZE]; /* SHA-512 Crytographic hash of |
38 * the concatenation of the | 37 * the concatenation of the |
39 * header fields, i.e. | 38 * header fields, i.e. |
40 * [header_len, | 39 * [header_len, |
41 * firmware_sign_algorithm, | 40 * firmware_sign_algorithm, |
42 * sign_algorithm, sign_key, | 41 * sign_algorithm, sign_key, |
43 * key_version] */ | 42 * key_version] */ |
44 | 43 /* End of kernel key header. */ |
45 uint8_t* kernel_key_signature; /* Signature of the header above. */ | 44 uint8_t* kernel_key_signature; /* Signature of the header above. */ |
46 | 45 |
47 /* Kernel preamble */ | 46 /* Kernel preamble */ |
48 uint16_t kernel_version; /* Kernel Version# for preventing rollbacks. */ | 47 uint16_t kernel_version; /* Kernel Version# for preventing rollbacks. */ |
49 uint64_t kernel_len; /* Length of the actual kernel image. */ | 48 uint64_t kernel_len; /* Length of the actual kernel image. */ |
50 uint64_t bootloader_offset; /* Offset of bootloader in kernel_data. */ | 49 uint64_t bootloader_offset; /* Offset of bootloader in kernel_data. */ |
51 uint64_t bootloader_size; /* Size of bootloader in bytes. */ | 50 uint64_t bootloader_size; /* Size of bootloader in bytes. */ |
52 uint8_t* config_signature; /* Signature on the concatenation of | 51 uint64_t padded_header_size; /* start of kernel_data in disk partition */ |
53 * [kernel_version], [kernel_len] and | 52 /* end of preamble */ |
54 * [kernel_config]. */ | 53 |
| 54 uint8_t* preamble_signature; /* Signature on the kernel preamble. */ |
| 55 |
55 /* The kernel signature comes first as it may allow us to parallelize | 56 /* The kernel signature comes first as it may allow us to parallelize |
56 * the kernel data fetch and RSA public key operation. | 57 * the kernel data fetch and RSA public key operation. |
57 */ | 58 */ |
58 uint8_t* kernel_signature; /* Signature on the concatenation of | 59 uint8_t* kernel_signature; /* Signature on the concatenation of |
59 * [kernel_version], [kernel_len], [kernel_config] | 60 * the kernel preamble and [kernel_data]. */ |
60 * and [kernel_data]. */ | |
61 /* The kernel config string is stored right before the kernel image data for | |
62 * easy mapping while loading into the memory. */ | |
63 uint8_t kernel_config[KERNEL_CONFIG_SIZE]; /* Kernel Config command line. */ | |
64 uint8_t* kernel_data; /* Actual kernel data. */ | 61 uint8_t* kernel_data; /* Actual kernel data. */ |
65 | 62 |
66 } KernelImage; | 63 } KernelImage; |
67 | 64 |
68 /* Error Codes for VerifyFirmware. */ | 65 /* Error Codes for VerifyFirmware. */ |
69 #define VERIFY_KERNEL_SUCCESS 0 | 66 #define VERIFY_KERNEL_SUCCESS 0 |
70 #define VERIFY_KERNEL_INVALID_IMAGE 1 | 67 #define VERIFY_KERNEL_INVALID_IMAGE 1 |
71 #define VERIFY_KERNEL_KEY_SIGNATURE_FAILED 2 | 68 #define VERIFY_KERNEL_KEY_SIGNATURE_FAILED 2 |
72 #define VERIFY_KERNEL_INVALID_ALGORITHM 3 | 69 #define VERIFY_KERNEL_INVALID_ALGORITHM 3 |
73 #define VERIFY_KERNEL_CONFIG_SIGNATURE_FAILED 4 | 70 #define VERIFY_KERNEL_PREAMBLE_SIGNATURE_FAILED 4 |
74 #define VERIFY_KERNEL_SIGNATURE_FAILED 5 | 71 #define VERIFY_KERNEL_SIGNATURE_FAILED 5 |
75 #define VERIFY_KERNEL_WRONG_MAGIC 6 | 72 #define VERIFY_KERNEL_WRONG_MAGIC 6 |
76 #define VERIFY_KERNEL_MAX 7 /* Generic catch-all. */ | 73 #define VERIFY_KERNEL_MAX 7 /* Generic catch-all. */ |
77 | 74 |
78 extern char* kVerifyKernelErrors[VERIFY_KERNEL_MAX]; | 75 extern char* kVerifyKernelErrors[VERIFY_KERNEL_MAX]; |
79 | 76 |
| 77 /* Returns the length of the verified boot kernel preamble. */ |
| 78 uint64_t GetKernelPreambleLen(void); |
| 79 |
80 /* Returns the length of the Kernel Verified Boot header excluding | 80 /* Returns the length of the Kernel Verified Boot header excluding |
81 * [kernel_config] and [kernel_data]. | 81 * [kernel_data]. |
82 * | 82 * |
83 * This is always non-zero, so a return value of 0 signifies an error. | 83 * This is always non-zero, so a return value of 0 signifies an error. |
84 */ | 84 */ |
85 uint64_t GetVBlockHeaderSize(const uint8_t* vkernel_blob); | 85 uint64_t GetVBlockHeaderSize(const uint8_t* vkernel_blob); |
86 | 86 |
87 /* Checks for the sanity of the kernel header pointed by [kernel_header_blob]. | 87 /* Checks for the sanity of the kernel key header at [kernel_header_blob]. |
88 * If [dev_mode] is enabled, also checks the firmware key signature using the | 88 * If [dev_mode] is enabled, also checks the kernel key signature using the |
89 * pre-processed public firmware signing key [firmware_sign_key_blob]. | 89 * pre-processed public firmware signing key [firmware_sign_key_blob]. |
90 * | 90 * |
91 * On success, put firmware signature algorithm in [firmware_algorithm], | 91 * On success, puts firmware signature algorithm in [firmware_algorithm], |
92 * kernel signature algorithm in [kernel_algorithm], kernel header | 92 * kernel signature algorithm in [kernel_algorithm], kernel header |
93 * length in [header_len], and return 0. | 93 * length in [header_len], and return 0. |
94 * Else, return error code on failure. | 94 * Else, return error code on failure. |
95 */ | 95 */ |
96 int VerifyKernelHeader(const uint8_t* firmware_sign_key_blob, | 96 int VerifyKernelKeyHeader(const uint8_t* firmware_sign_key_blob, |
97 const uint8_t* kernel_header_blob, | 97 const uint8_t* kernel_header_blob, |
98 const int dev_mode, | 98 const int dev_mode, |
99 int* firmware_algorithm, | 99 int* firmware_algorithm, |
100 int* kernel_algorithm, | 100 int* kernel_algorithm, |
101 int* header_len); | 101 int* header_len); |
102 | 102 |
103 /* Checks the kernel config (analogous to preamble for firmware) signature on | 103 /* Checks the kernel preamble signature at [kernel_preamble_blob] |
104 * kernel config pointed by [kernel_config_blob] using the signing key | 104 * using the signing key [kernel_sign_key]. |
105 * [kernel_sign_key]. | |
106 * | 105 * |
107 * On success, put kernel length into [kernel_len], and return 0. | 106 * On success, put kernel length into [kernel_len], and return 0. |
108 * Else, return error code on failure. | 107 * Else, return error code on failure. |
109 */ | 108 */ |
110 int VerifyKernelConfig(RSAPublicKey* kernel_sign_key, | 109 int VerifyKernelPreamble(RSAPublicKey* kernel_sign_key, |
111 const uint8_t* kernel_config_blob, | 110 const uint8_t* kernel_preamble_blob, |
112 int algorithm, | 111 int algorithm, |
113 uint64_t* kernel_len); | 112 uint64_t* kernel_len); |
114 | 113 |
115 /* Checks the signature on the kernel data at location [kernel_data_start]. | 114 /* Checks the signature on the kernel data at location [kernel_data_start]. |
116 * The length of the actual kernel data is kernel _len and it is assumed to | 115 * The length of the actual kernel data is kernel_len and it is assumed to |
117 * be prepended with the signature whose size depends on the signature_algorithm | 116 * be prepended with the signature whose size depends on the signature_algorithm |
118 * [algorithm]. | 117 * [algorithm]. |
119 * | 118 * |
120 * Return 0 on success, error code on failure. | 119 * Return 0 on success, error code on failure. |
121 */ | 120 */ |
122 int VerifyKernelData(RSAPublicKey* kernel_sign_key, | 121 int VerifyKernelData(RSAPublicKey* kernel_sign_key, |
123 const uint8_t* kernel_config_start, | 122 const uint8_t* kernel_config_start, |
124 const uint8_t* kernel_data_start, | 123 const uint8_t* kernel_data_start, |
125 uint64_t kernel_len, | 124 uint64_t kernel_len, |
126 int algorithm); | 125 int algorithm); |
127 | 126 |
| 127 /* Verifies the kernel key header and preamble at [kernel_header_blob] |
| 128 * using the firmware public key [firmware_key_blob]. If [dev_mode] is 1 |
| 129 * (active), then key header verification is skipped. |
| 130 * |
| 131 * Fills in a pointer to preamble blob within [kernel_header_blob] in |
| 132 * [preamble_blob], pointer to expected kernel data signature |
| 133 * within [kernel_header_blob] in [expected_kernel_signature]. |
| 134 * |
| 135 * The signing key to use for kernel data verification is returned in |
| 136 * [kernel_sign_key], This must be free-d explicitly by the caller after use. |
| 137 * The kernel signing algorithm is returned in [kernel_sign_algorithm] and its |
| 138 * length in [kernel_len]. |
| 139 * |
| 140 * Returns 0 on success, error code on failure. |
| 141 */ |
| 142 int VerifyKernelHeader(const uint8_t* firmware_key_blob, |
| 143 const uint8_t* kernel_header_blob, |
| 144 const int dev_mode, |
| 145 const uint8_t** preamble_blob, |
| 146 const uint8_t** expected_kernel_signature, |
| 147 RSAPublicKey** kernel_sign_key, |
| 148 int* kernel_sign_algorithm, |
| 149 uint64_t* kernel_len); |
| 150 |
128 /* Performs a chained verify of the kernel blob [kernel_blob]. If | 151 /* Performs a chained verify of the kernel blob [kernel_blob]. If |
129 * [dev_mode] is 0 [inactive], then the pre-processed public signing key | 152 * [dev_mode] is 0 [inactive], then the pre-processed public signing key |
130 * [root_key_blob] is used to verify the signature of the signing key, | 153 * [root_key_blob] is used to verify the signature of the signing key, |
131 * else the check is skipped. | 154 * else the check is skipped. |
132 * | 155 * |
133 * TODO(gauravsh): Does the dev mode only effect the R/W firmware verification, | |
134 * or kernel verification, or both? | |
135 * | 156 * |
136 * Returns 0 on success, error code on failure. | 157 * Returns 0 on success, error code on failure. |
137 * | 158 * |
138 * NOTE: The length of the kernel blob is derived from reading the fields | 159 * NOTE: The length of the kernel blob is derived from reading the fields |
139 * in the first few bytes of the buffer. This might look risky but in firmware | 160 * in the first few bytes of the buffer. This might look risky but in firmware |
140 * land, the start address of the kernel_blob will always be fixed depending | 161 * land, the start address of the kernel_blob will always be fixed depending |
141 * on the memory map on the particular platform. In addition, the signature on | 162 * on the memory map on the particular platform. In addition, the signature on |
142 * length itself is checked early in the verification process for extra safety. | 163 * length itself is checked early in the verification process for extra safety. |
143 */ | 164 */ |
144 int VerifyKernel(const uint8_t* signing_key_blob, | 165 int VerifyKernel(const uint8_t* signing_key_blob, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 * BOOT_KERNEL_A_CONTINUE Boot from Kenrel A | 198 * BOOT_KERNEL_A_CONTINUE Boot from Kenrel A |
178 * BOOT_KERNEL_B_CONTINUE Boot from Kernel B | 199 * BOOT_KERNEL_B_CONTINUE Boot from Kernel B |
179 * BOOT_KERNEL_RECOVERY_CONTINUE Jump to recovery mode | 200 * BOOT_KERNEL_RECOVERY_CONTINUE Jump to recovery mode |
180 */ | 201 */ |
181 int VerifyKernelDriver_f(uint8_t* firmware_key_blob, | 202 int VerifyKernelDriver_f(uint8_t* firmware_key_blob, |
182 kernel_entry* kernelA, | 203 kernel_entry* kernelA, |
183 kernel_entry* kernelB, | 204 kernel_entry* kernelB, |
184 int dev_mode); | 205 int dev_mode); |
185 | 206 |
186 #endif /* VBOOT_REFERENCE_KERNEL_IMAGE_FW_H_ */ | 207 #endif /* VBOOT_REFERENCE_KERNEL_IMAGE_FW_H_ */ |
OLD | NEW |