bl1_cot.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (c) 2020-2024, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stddef.h>
  7. #include <mbedtls/version.h>
  8. #include <common/tbbr/cot_def.h>
  9. #include <drivers/auth/auth_mod.h>
  10. #include <platform_def.h>
  11. #include <tools_share/dualroot_oid.h>
  12. /*
  13. * Allocate static buffers to store the authentication parameters extracted from
  14. * the certificates.
  15. */
  16. static unsigned char fw_config_hash_buf[HASH_DER_LEN];
  17. static unsigned char tb_fw_hash_buf[HASH_DER_LEN];
  18. static unsigned char tb_fw_config_hash_buf[HASH_DER_LEN];
  19. static unsigned char scp_fw_hash_buf[HASH_DER_LEN];
  20. static unsigned char nt_world_bl_hash_buf[HASH_DER_LEN];
  21. /*
  22. * Parameter type descriptors.
  23. */
  24. static auth_param_type_desc_t trusted_nv_ctr = AUTH_PARAM_TYPE_DESC(
  25. AUTH_PARAM_NV_CTR, TRUSTED_FW_NVCOUNTER_OID);
  26. static auth_param_type_desc_t subject_pk = AUTH_PARAM_TYPE_DESC(
  27. AUTH_PARAM_PUB_KEY, 0);
  28. static auth_param_type_desc_t sig = AUTH_PARAM_TYPE_DESC(
  29. AUTH_PARAM_SIG, 0);
  30. static auth_param_type_desc_t sig_alg = AUTH_PARAM_TYPE_DESC(
  31. AUTH_PARAM_SIG_ALG, 0);
  32. static auth_param_type_desc_t raw_data = AUTH_PARAM_TYPE_DESC(
  33. AUTH_PARAM_RAW_DATA, 0);
  34. static auth_param_type_desc_t tb_fw_hash = AUTH_PARAM_TYPE_DESC(
  35. AUTH_PARAM_HASH, TRUSTED_BOOT_FW_HASH_OID);
  36. static auth_param_type_desc_t tb_fw_config_hash = AUTH_PARAM_TYPE_DESC(
  37. AUTH_PARAM_HASH, TRUSTED_BOOT_FW_CONFIG_HASH_OID);
  38. static auth_param_type_desc_t fw_config_hash = AUTH_PARAM_TYPE_DESC(
  39. AUTH_PARAM_HASH, FW_CONFIG_HASH_OID);
  40. static auth_param_type_desc_t scp_bl2u_hash = AUTH_PARAM_TYPE_DESC(
  41. AUTH_PARAM_HASH, SCP_FWU_CFG_HASH_OID);
  42. static auth_param_type_desc_t bl2u_hash = AUTH_PARAM_TYPE_DESC(
  43. AUTH_PARAM_HASH, AP_FWU_CFG_HASH_OID);
  44. static auth_param_type_desc_t ns_bl2u_hash = AUTH_PARAM_TYPE_DESC(
  45. AUTH_PARAM_HASH, FWU_HASH_OID);
  46. static const auth_img_desc_t trusted_boot_fw_cert = {
  47. .img_id = TRUSTED_BOOT_FW_CERT_ID,
  48. .img_type = IMG_CERT,
  49. .parent = NULL,
  50. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  51. [0] = {
  52. .type = AUTH_METHOD_SIG,
  53. .param.sig = {
  54. .pk = &subject_pk,
  55. .sig = &sig,
  56. .alg = &sig_alg,
  57. .data = &raw_data
  58. }
  59. },
  60. [1] = {
  61. .type = AUTH_METHOD_NV_CTR,
  62. .param.nv_ctr = {
  63. .cert_nv_ctr = &trusted_nv_ctr,
  64. .plat_nv_ctr = &trusted_nv_ctr
  65. }
  66. }
  67. },
  68. .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
  69. [0] = {
  70. .type_desc = &tb_fw_hash,
  71. .data = {
  72. .ptr = (void *)tb_fw_hash_buf,
  73. .len = (unsigned int)HASH_DER_LEN
  74. }
  75. },
  76. [1] = {
  77. .type_desc = &tb_fw_config_hash,
  78. .data = {
  79. .ptr = (void *)tb_fw_config_hash_buf,
  80. .len = (unsigned int)HASH_DER_LEN
  81. }
  82. },
  83. [2] = {
  84. .type_desc = &fw_config_hash,
  85. .data = {
  86. .ptr = (void *)fw_config_hash_buf,
  87. .len = (unsigned int)HASH_DER_LEN
  88. }
  89. }
  90. }
  91. };
  92. static const auth_img_desc_t bl2_image = {
  93. .img_id = BL2_IMAGE_ID,
  94. .img_type = IMG_RAW,
  95. .parent = &trusted_boot_fw_cert,
  96. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  97. [0] = {
  98. .type = AUTH_METHOD_HASH,
  99. .param.hash = {
  100. .data = &raw_data,
  101. .hash = &tb_fw_hash
  102. }
  103. }
  104. }
  105. };
  106. /* TB FW Config */
  107. static const auth_img_desc_t tb_fw_config = {
  108. .img_id = TB_FW_CONFIG_ID,
  109. .img_type = IMG_RAW,
  110. .parent = &trusted_boot_fw_cert,
  111. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  112. [0] = {
  113. .type = AUTH_METHOD_HASH,
  114. .param.hash = {
  115. .data = &raw_data,
  116. .hash = &tb_fw_config_hash
  117. }
  118. }
  119. }
  120. };
  121. static const auth_img_desc_t fw_config = {
  122. .img_id = FW_CONFIG_ID,
  123. .img_type = IMG_RAW,
  124. .parent = &trusted_boot_fw_cert,
  125. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  126. [0] = {
  127. .type = AUTH_METHOD_HASH,
  128. .param.hash = {
  129. .data = &raw_data,
  130. .hash = &fw_config_hash
  131. }
  132. }
  133. }
  134. };
  135. /* FWU auth descriptor */
  136. static const auth_img_desc_t fwu_cert = {
  137. .img_id = FWU_CERT_ID,
  138. .img_type = IMG_CERT,
  139. .parent = NULL,
  140. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  141. [0] = {
  142. .type = AUTH_METHOD_SIG,
  143. .param.sig = {
  144. .pk = &subject_pk,
  145. .sig = &sig,
  146. .alg = &sig_alg,
  147. .data = &raw_data
  148. }
  149. }
  150. },
  151. .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
  152. [0] = {
  153. .type_desc = &scp_bl2u_hash,
  154. .data = {
  155. .ptr = (void *)scp_fw_hash_buf,
  156. .len = (unsigned int)HASH_DER_LEN
  157. }
  158. },
  159. [1] = {
  160. .type_desc = &bl2u_hash,
  161. .data = {
  162. .ptr = (void *)tb_fw_hash_buf,
  163. .len = (unsigned int)HASH_DER_LEN
  164. }
  165. },
  166. [2] = {
  167. .type_desc = &ns_bl2u_hash,
  168. .data = {
  169. .ptr = (void *)nt_world_bl_hash_buf,
  170. .len = (unsigned int)HASH_DER_LEN
  171. }
  172. }
  173. }
  174. };
  175. /* SCP_BL2U */
  176. static const auth_img_desc_t scp_bl2u_image = {
  177. .img_id = SCP_BL2U_IMAGE_ID,
  178. .img_type = IMG_RAW,
  179. .parent = &fwu_cert,
  180. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  181. [0] = {
  182. .type = AUTH_METHOD_HASH,
  183. .param.hash = {
  184. .data = &raw_data,
  185. .hash = &scp_bl2u_hash
  186. }
  187. }
  188. }
  189. };
  190. /* BL2U */
  191. static const auth_img_desc_t bl2u_image = {
  192. .img_id = BL2U_IMAGE_ID,
  193. .img_type = IMG_RAW,
  194. .parent = &fwu_cert,
  195. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  196. [0] = {
  197. .type = AUTH_METHOD_HASH,
  198. .param.hash = {
  199. .data = &raw_data,
  200. .hash = &bl2u_hash
  201. }
  202. }
  203. }
  204. };
  205. /* NS_BL2U */
  206. static const auth_img_desc_t ns_bl2u_image = {
  207. .img_id = NS_BL2U_IMAGE_ID,
  208. .img_type = IMG_RAW,
  209. .parent = &fwu_cert,
  210. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  211. [0] = {
  212. .type = AUTH_METHOD_HASH,
  213. .param.hash = {
  214. .data = &raw_data,
  215. .hash = &ns_bl2u_hash
  216. }
  217. }
  218. }
  219. };
  220. static const auth_img_desc_t * const cot_desc[] = {
  221. [TRUSTED_BOOT_FW_CERT_ID] = &trusted_boot_fw_cert,
  222. [BL2_IMAGE_ID] = &bl2_image,
  223. [TB_FW_CONFIG_ID] = &tb_fw_config,
  224. [FW_CONFIG_ID] = &fw_config,
  225. [FWU_CERT_ID] = &fwu_cert,
  226. [SCP_BL2U_IMAGE_ID] = &scp_bl2u_image,
  227. [BL2U_IMAGE_ID] = &bl2u_image,
  228. [NS_BL2U_IMAGE_ID] = &ns_bl2u_image
  229. };
  230. REGISTER_COT(cot_desc);