bdb_struct.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /* Copyright (c) 2015 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. * Boot descriptor block structures
  6. */
  7. #ifndef VBOOT_REFERENCE_BDB_STRUCT_H_
  8. #define VBOOT_REFERENCE_BDB_STRUCT_H_
  9. #include <stdint.h>
  10. /* Size of SHA256 digest in bytes */
  11. #define BDB_SHA256_DIGEST_SIZE 32
  12. /* Size of RSA4096 key data in bytes */
  13. #define BDB_RSA4096_KEY_DATA_SIZE 1032
  14. /* Size of RSA4096 signature in bytes */
  15. #define BDB_RSA4096_SIG_SIZE 512
  16. /* Size of ECDSA521 key data in bytes = ceil(521/8) * 2 */
  17. #define BDB_ECDSA521_KEY_DATA_SIZE 132
  18. /* Size of ECDSA521 signature in bytes = ceil(521/8) * 2 */
  19. #define BDB_ECDSA521_SIG_SIZE 132
  20. /* Size of RSA3072B key data in bytes */
  21. #define BDB_RSA3072B_KEY_DATA_SIZE 776
  22. /* Size of RSA3072B signature in bytes */
  23. #define BDB_RSA3072B_SIG_SIZE 384
  24. /*****************************************************************************/
  25. /* Header for BDB */
  26. /* Magic number for bdb_header.struct_magic */
  27. #define BDB_HEADER_MAGIC 0x30426442
  28. /* Current version of bdb_header struct */
  29. #define BDB_HEADER_VERSION_MAJOR 1
  30. #define BDB_HEADER_VERSION_MINOR 0
  31. /* Expected size of bdb_header struct in bytes */
  32. #define BDB_HEADER_EXPECTED_SIZE 32
  33. struct bdb_header {
  34. /* Magic number to identify struct = BDB_HEADER_MAGIC. */
  35. uint32_t struct_magic;
  36. /* Structure version = BDB_HEADER_VERSION{MAJOR,MINOR} */
  37. uint8_t struct_major_version;
  38. uint8_t struct_minor_version;
  39. /* Size of structure in bytes */
  40. uint16_t struct_size;
  41. /* Recommended address in SP SRAM to load BDB. Set to -1 to use
  42. * default address. */
  43. uint64_t bdb_load_address;
  44. /* Size of the entire BDB in bytes */
  45. uint32_t bdb_size;
  46. /* Number of bytes following the BDB key which are signed by the BDB
  47. * header signature. */
  48. uint32_t signed_size;
  49. /* Size of OEM area 0 in bytes, or 0 if not present */
  50. uint32_t oem_area_0_size;
  51. /* Reserved; set 0 */
  52. uint8_t reserved0[8];
  53. } __attribute__((packed));
  54. /*****************************************************************************/
  55. /* Public key structure for BDB */
  56. /* Magic number for bdb_key.struct_magic */
  57. #define BDB_KEY_MAGIC 0x73334256
  58. /* Current version of bdb_key struct */
  59. #define BDB_KEY_VERSION_MAJOR 1
  60. #define BDB_KEY_VERSION_MINOR 0
  61. /* Supported hash algorithms */
  62. enum bdb_hash_alg {
  63. BDB_HASH_ALG_INVALID = 0, /* Not used; invalid */
  64. BDB_HASH_ALG_SHA256 = 2, /* SHA-256 */
  65. };
  66. /* Supported signature algorithms */
  67. enum bdb_sig_alg {
  68. BDB_SIG_ALG_INVALID = 0, /* Not used; invalid */
  69. BDB_SIG_ALG_RSA4096 = 3, /* RSA-4096, exponent 65537 */
  70. BDB_SIG_ALG_ECSDSA521 = 5, /* ECDSA-521 */
  71. BDB_SIG_ALG_RSA3072B = 7, /* RSA_3072, exponent 3 */
  72. };
  73. /*
  74. * Expected size of bdb_key struct in bytes, not counting variable-length key
  75. * data at end.
  76. */
  77. #define BDB_KEY_EXPECTED_SIZE 80
  78. struct bdb_key {
  79. /* Magic number to identify struct = BDB_KEY_MAGIC. */
  80. uint32_t struct_magic;
  81. /* Structure version = BDB_KEY_VERSION{MAJOR,MINOR} */
  82. uint8_t struct_major_version;
  83. uint8_t struct_minor_version;
  84. /* Size of structure in bytes, including variable-length key data */
  85. uint16_t struct_size;
  86. /* Hash algorithm (enum bdb_hash_alg) */
  87. uint8_t hash_alg;
  88. /* Signature algorithm (enum bdb_sig_alg) */
  89. uint8_t sig_alg;
  90. /* Reserved; set 0 */
  91. uint8_t reserved0[2];
  92. /* Key version */
  93. uint32_t key_version;
  94. /* Description; null-terminated ASCII */
  95. char description[128];
  96. /*
  97. * Key data. Variable-length; size is struct_size -
  98. * offset_of(bdb_key, key_data).
  99. */
  100. uint8_t key_data[0];
  101. } __attribute__((packed));
  102. /*****************************************************************************/
  103. /* Signature structure for BDB */
  104. /* Magic number for bdb_sig.struct_magic */
  105. #define BDB_SIG_MAGIC 0x6b334256
  106. /* Current version of bdb_sig struct */
  107. #define BDB_SIG_VERSION_MAJOR 1
  108. #define BDB_SIG_VERSION_MINOR 0
  109. struct bdb_sig {
  110. /* Magic number to identify struct = BDB_SIG_MAGIC. */
  111. uint32_t struct_magic;
  112. /* Structure version = BDB_SIG_VERSION{MAJOR,MINOR} */
  113. uint8_t struct_major_version;
  114. uint8_t struct_minor_version;
  115. /* Size of structure in bytes, including variable-length signature
  116. * data. */
  117. uint16_t struct_size;
  118. /* Hash algorithm used for this signature (enum bdb_hash_alg) */
  119. uint8_t hash_alg;
  120. /* Signature algorithm (enum bdb_sig_alg) */
  121. uint8_t sig_alg;
  122. /* Reserved; set 0 */
  123. uint8_t reserved0[2];
  124. /* Number of bytes of data signed by this signature */
  125. uint32_t signed_size;
  126. /* Description; null-terminated ASCII */
  127. char description[128];
  128. /* Signature data. Variable-length; size is struct_size -
  129. * offset_of(bdb_sig, sig_data). */
  130. uint8_t sig_data[0];
  131. } __attribute__((packed));
  132. /*****************************************************************************/
  133. /* Data structure for BDB */
  134. /* Magic number for bdb_data.struct_magic */
  135. #define BDB_DATA_MAGIC 0x31426442
  136. /* Current version of bdb_sig struct */
  137. #define BDB_DATA_VERSION_MAJOR 1
  138. #define BDB_DATA_VERSION_MINOR 0
  139. struct bdb_data {
  140. /* Magic number to identify struct = BDB_DATA_MAGIC. */
  141. uint32_t struct_magic;
  142. /* Structure version = BDB_DATA_VERSION{MAJOR,MINOR} */
  143. uint8_t struct_major_version;
  144. uint8_t struct_minor_version;
  145. /* Size of structure in bytes, NOT including hashes which follow. */
  146. uint16_t struct_size;
  147. /* Version of data (RW firmware) contained */
  148. uint32_t data_version;
  149. /* Size of OEM area 1 in bytes, or 0 if not present */
  150. uint32_t oem_area_1_size;
  151. /* Number of hashes which follow */
  152. uint8_t num_hashes;
  153. /* Size of each hash entry in bytes */
  154. uint8_t hash_entry_size;
  155. /* Reserved; set 0 */
  156. uint8_t reserved0[2];
  157. /* Number of bytes of data signed by the subkey, including this
  158. * header */
  159. uint32_t signed_size;
  160. /* Reserved; set 0 */
  161. uint8_t reserved1[8];
  162. /* Description; null-terminated ASCII */
  163. char description[128];
  164. } __attribute__((packed));
  165. /* Type of data for bdb_hash.type */
  166. enum bdb_data_type {
  167. /* Types of data for boot descriptor blocks */
  168. BDB_DATA_SP_RW = 1, /* SP-RW firmware */
  169. BDB_DATA_AP_RW = 2, /* AP-RW firmware */
  170. BDB_DATA_MCU = 3, /* MCU firmware */
  171. /* Types of data for kernel descriptor blocks */
  172. BDB_DATA_KERNEL = 128, /* Kernel */
  173. BDB_DATA_CMD_LINE = 129, /* Command line */
  174. BDB_DATA_HEADER16 = 130, /* 16-bit vmlinuz header */
  175. };
  176. /* Hash entries which follow the structure */
  177. struct bdb_hash {
  178. /* Offset of data from start of partition */
  179. uint64_t offset;
  180. /* Size of data in bytes */
  181. uint32_t size;
  182. /* Partition number containing data */
  183. uint8_t partition;
  184. /* Type of data; enum bdb_data_type */
  185. uint8_t type;
  186. /* Reserved; set 0 */
  187. uint8_t reserved0[2];
  188. /* Address in RAM to load data. -1 means use default. */
  189. uint64_t load_address;
  190. /* SHA-256 hash digest */
  191. uint8_t digest[BDB_SHA256_DIGEST_SIZE];
  192. } __attribute__((packed));
  193. /*****************************************************************************/
  194. #endif /* VBOOT_REFERENCE_BDB_STRUCT_H_ */