vb2_struct.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* 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. * Vboot 2.0 data structures (compatible with vboot1)
  6. *
  7. * Note: Many of the structs have pairs of 32-bit fields and reserved fields.
  8. * This is to be backwards-compatible with older verified boot data which used
  9. * 64-bit fields (when we thought that hey, UEFI is 64-bit so all our fields
  10. * should be too).
  11. *
  12. * Offsets should be padded to 32-bit boundaries, since some architectures
  13. * have trouble with accessing unaligned integers.
  14. */
  15. #ifndef VBOOT_REFERENCE_VB2_STRUCT_H_
  16. #define VBOOT_REFERENCE_VB2_STRUCT_H_
  17. #include <stdint.h>
  18. /*
  19. * Rollback protection currently uses a 32-bit value comprised of the bottom 16
  20. * bits of the (firmware or kernel) preamble version and the bottom 16 bits of
  21. * the key version. So each of those versions is effectively limited to 16
  22. * bits even though they get stored in 32-bit fields.
  23. */
  24. #define VB2_MAX_KEY_VERSION 0xffff
  25. #define VB2_MAX_PREAMBLE_VERSION 0xffff
  26. /* Packed public key data */
  27. struct vb2_packed_key {
  28. /* Offset of key data from start of this struct */
  29. uint32_t key_offset;
  30. uint32_t reserved0;
  31. /* Size of key data in bytes (NOT strength of key in bits) */
  32. uint32_t key_size;
  33. uint32_t reserved1;
  34. /* Signature algorithm used by the key (enum vb2_crypto_algorithm) */
  35. uint32_t algorithm;
  36. uint32_t reserved2;
  37. /* Key version */
  38. uint32_t key_version;
  39. uint32_t reserved3;
  40. /* TODO: when redoing this struct, add a text description of the key */
  41. } __attribute__((packed));
  42. #define EXPECTED_VB2_PACKED_KEY_SIZE 32
  43. /* Signature data (a secure hash, possibly signed) */
  44. struct vb2_signature {
  45. /* Offset of signature data from start of this struct */
  46. uint32_t sig_offset;
  47. uint32_t reserved0;
  48. /* Size of signature data in bytes */
  49. uint32_t sig_size;
  50. uint32_t reserved1;
  51. /* Size of the data block which was signed in bytes */
  52. uint32_t data_size;
  53. uint32_t reserved2;
  54. } __attribute__((packed));
  55. #define EXPECTED_VB2_SIGNATURE_SIZE 24
  56. #define KEY_BLOCK_MAGIC "CHROMEOS"
  57. #define KEY_BLOCK_MAGIC_SIZE 8
  58. #define KEY_BLOCK_HEADER_VERSION_MAJOR 2
  59. #define KEY_BLOCK_HEADER_VERSION_MINOR 1
  60. /*
  61. * Key block, containing the public key used to sign some other chunk of data.
  62. *
  63. * This should be followed by:
  64. * 1) The data_key key data, pointed to by data_key.key_offset.
  65. * 2) The checksum data for (vb2_keyblock + data_key data), pointed to
  66. * by keyblock_checksum.sig_offset.
  67. * 3) The signature data for (vb2_keyblock + data_key data), pointed to
  68. * by keyblock_signature.sig_offset.
  69. */
  70. struct vb2_keyblock {
  71. /* Magic number */
  72. uint8_t magic[KEY_BLOCK_MAGIC_SIZE];
  73. /* Version of this header format */
  74. uint32_t header_version_major;
  75. uint32_t header_version_minor;
  76. /*
  77. * Length of this entire key block, including keys, signatures, and
  78. * padding, in bytes
  79. */
  80. uint32_t keyblock_size;
  81. uint32_t reserved0;
  82. /*
  83. * Signature for this key block (header + data pointed to by data_key)
  84. * For use with signed data keys
  85. */
  86. struct vb2_signature keyblock_signature;
  87. /*
  88. * SHA-512 hash for this key block (header + data pointed to by
  89. * data_key) For use with unsigned data keys.
  90. *
  91. * Only supported for kernel keyblocks, not firmware keyblocks.
  92. */
  93. struct vb2_signature keyblock_hash;
  94. /* Flags for key (VB2_KEY_BLOCK_FLAG_*) */
  95. uint32_t keyblock_flags;
  96. uint32_t reserved1;
  97. /* Key to verify the chunk of data */
  98. struct vb2_packed_key data_key;
  99. } __attribute__((packed));
  100. #define EXPECTED_VB2_KEYBLOCK_SIZE 112
  101. /* Firmware preamble header */
  102. #define FIRMWARE_PREAMBLE_HEADER_VERSION_MAJOR 2
  103. #define FIRMWARE_PREAMBLE_HEADER_VERSION_MINOR 1
  104. /* Flags for vb2_fw_preamble.flags */
  105. /* Use RO-normal firmware (deprecated; do not use) */
  106. #define VB2_FIRMWARE_PREAMBLE_USE_RO_NORMAL 0x00000001
  107. /* Do not allow use of any hardware crypto accelerators. */
  108. #define VB2_FIRMWARE_PREAMBLE_DISALLOW_HWCRYPTO 0x00000002
  109. /* Premable block for rewritable firmware, vboot1 version 2.1.
  110. *
  111. * The firmware preamble header should be followed by:
  112. * 1) The kernel_subkey key data, pointed to by kernel_subkey.key_offset.
  113. * 2) The signature data for the firmware body, pointed to by
  114. * body_signature.sig_offset.
  115. * 3) The signature data for (header + kernel_subkey data + body signature
  116. * data), pointed to by preamble_signature.sig_offset.
  117. */
  118. struct vb2_fw_preamble {
  119. /*
  120. * Size of this preamble, including keys, signatures, and padding, in
  121. * bytes
  122. */
  123. uint32_t preamble_size;
  124. uint32_t reserved0;
  125. /*
  126. * Signature for this preamble (header + kernel subkey + body
  127. * signature)
  128. */
  129. struct vb2_signature preamble_signature;
  130. /* Version of this header format */
  131. uint32_t header_version_major;
  132. uint32_t header_version_minor;
  133. /* Firmware version */
  134. uint32_t firmware_version;
  135. uint32_t reserved1;
  136. /* Key to verify kernel key block */
  137. struct vb2_packed_key kernel_subkey;
  138. /* Signature for the firmware body */
  139. struct vb2_signature body_signature;
  140. /*
  141. * Fields added in header version 2.1. You must verify the header
  142. * version before reading these fields!
  143. */
  144. /*
  145. * Flags; see VB2_FIRMWARE_PREAMBLE_*. Readers should return 0 for
  146. * header version < 2.1.
  147. */
  148. uint32_t flags;
  149. } __attribute__((packed));
  150. #define EXPECTED_VB2_FW_PREAMBLE_SIZE 108
  151. /* Kernel preamble header */
  152. #define KERNEL_PREAMBLE_HEADER_VERSION_MAJOR 2
  153. #define KERNEL_PREAMBLE_HEADER_VERSION_MINOR 2
  154. /* Flags for vb2_kernel_preamble.flags */
  155. /* Kernel image type = bits 1:0 */
  156. #define VB2_KERNEL_PREAMBLE_KERNEL_TYPE_MASK 0x00000003
  157. #define VB2_KERNEL_PREAMBLE_KERNEL_TYPE_CROS 0
  158. #define VB2_KERNEL_PREAMBLE_KERNEL_TYPE_BOOTIMG 1
  159. /* Kernel types 2,3 are reserved for future use */
  160. /*
  161. * Preamble block for kernel, version 2.2
  162. *
  163. * This should be followed by:
  164. * 1) The signature data for the kernel body, pointed to by
  165. * body_signature.sig_offset.
  166. * 2) The signature data for (vb2_kernel_preamble + body signature data),
  167. * pointed to by preamble_signature.sig_offset.
  168. * 3) The 16-bit vmlinuz header, which is used for reconstruction of
  169. * vmlinuz image.
  170. */
  171. struct vb2_kernel_preamble {
  172. /*
  173. * Size of this preamble, including keys, signatures, vmlinuz header,
  174. * and padding, in bytes
  175. */
  176. uint32_t preamble_size;
  177. uint32_t reserved0;
  178. /* Signature for this preamble (header + body signature) */
  179. struct vb2_signature preamble_signature;
  180. /* Version of this header format */
  181. uint32_t header_version_major;
  182. uint32_t header_version_minor;
  183. /* Kernel version */
  184. uint32_t kernel_version;
  185. uint32_t reserved1;
  186. /* Load address for kernel body */
  187. uint64_t body_load_address;
  188. /* TODO (vboot 2.1): we never used that */
  189. /* Address of bootloader, after body is loaded at body_load_address */
  190. uint64_t bootloader_address;
  191. /* TODO (vboot 2.1): should be a 32-bit offset */
  192. /* Size of bootloader in bytes */
  193. uint32_t bootloader_size;
  194. uint32_t reserved2;
  195. /* Signature for the kernel body */
  196. struct vb2_signature body_signature;
  197. /*
  198. * TODO (vboot 2.1): fields for kernel offset and size. Right now the
  199. * size is implicitly the same as the size of data signed by the body
  200. * signature, and the offset is implicitly at the end of the preamble.
  201. * But that forces us to pad the preamble to 64KB rather than just
  202. * having a tiny preamble and an offset field.
  203. */
  204. /*
  205. * Fields added in header version 2.1. You must verify the header
  206. * version before reading these fields!
  207. */
  208. /*
  209. * Address of 16-bit header for vmlinuz reassembly. Readers should
  210. * return 0 for header version < 2.1.
  211. */
  212. uint64_t vmlinuz_header_address;
  213. /* Size of 16-bit header for vmlinuz in bytes. Readers should return 0
  214. for header version < 2.1 */
  215. uint32_t vmlinuz_header_size;
  216. uint32_t reserved3;
  217. /*
  218. * Fields added in header version 2.2. You must verify the header
  219. * version before reading these fields!
  220. */
  221. /*
  222. * Flags; see VB2_KERNEL_PREAMBLE_*. Readers should return 0 for
  223. * header version < 2.2.
  224. */
  225. uint32_t flags;
  226. } __attribute__((packed));
  227. #define EXPECTED_VB2_KERNEL_PREAMBLE_2_0_SIZE 96
  228. #define EXPECTED_VB2_KERNEL_PREAMBLE_2_1_SIZE 112
  229. #define EXPECTED_VB2_KERNEL_PREAMBLE_2_2_SIZE 116
  230. #endif /* VBOOT_REFERENCE_VB2_STRUCT_H_ */