tbbr_cot_bl1.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stddef.h>
  7. #include <mbedtls/version.h>
  8. #include <drivers/auth/auth_mod.h>
  9. #include <drivers/auth/tbbr_cot_common.h>
  10. #if USE_TBBR_DEFS
  11. #include <tools_share/tbbr_oid.h>
  12. #else
  13. #include <platform_oid.h>
  14. #endif
  15. #include <platform_def.h>
  16. static auth_param_type_desc_t scp_bl2u_hash = AUTH_PARAM_TYPE_DESC(
  17. AUTH_PARAM_HASH, SCP_FWU_CFG_HASH_OID);
  18. static auth_param_type_desc_t bl2u_hash = AUTH_PARAM_TYPE_DESC(
  19. AUTH_PARAM_HASH, AP_FWU_CFG_HASH_OID);
  20. static auth_param_type_desc_t ns_bl2u_hash = AUTH_PARAM_TYPE_DESC(
  21. AUTH_PARAM_HASH, FWU_HASH_OID);
  22. static const auth_img_desc_t bl2_image = {
  23. .img_id = BL2_IMAGE_ID,
  24. .img_type = IMG_RAW,
  25. .parent = &trusted_boot_fw_cert,
  26. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  27. [0] = {
  28. .type = AUTH_METHOD_HASH,
  29. .param.hash = {
  30. .data = &raw_data,
  31. .hash = &tb_fw_hash
  32. }
  33. }
  34. }
  35. };
  36. /*
  37. * FWU auth descriptor.
  38. */
  39. static const auth_img_desc_t fwu_cert = {
  40. .img_id = FWU_CERT_ID,
  41. .img_type = IMG_CERT,
  42. .parent = NULL,
  43. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  44. [0] = {
  45. .type = AUTH_METHOD_SIG,
  46. .param.sig = {
  47. .pk = &subject_pk,
  48. .sig = &sig,
  49. .alg = &sig_alg,
  50. .data = &raw_data
  51. }
  52. }
  53. },
  54. .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
  55. [0] = {
  56. .type_desc = &scp_bl2u_hash,
  57. .data = {
  58. .ptr = (void *)scp_fw_hash_buf,
  59. .len = (unsigned int)HASH_DER_LEN
  60. }
  61. },
  62. [1] = {
  63. .type_desc = &bl2u_hash,
  64. .data = {
  65. .ptr = (void *)tb_fw_hash_buf,
  66. .len = (unsigned int)HASH_DER_LEN
  67. }
  68. },
  69. [2] = {
  70. .type_desc = &ns_bl2u_hash,
  71. .data = {
  72. .ptr = (void *)nt_world_bl_hash_buf,
  73. .len = (unsigned int)HASH_DER_LEN
  74. }
  75. }
  76. }
  77. };
  78. /*
  79. * SCP_BL2U
  80. */
  81. static const auth_img_desc_t scp_bl2u_image = {
  82. .img_id = SCP_BL2U_IMAGE_ID,
  83. .img_type = IMG_RAW,
  84. .parent = &fwu_cert,
  85. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  86. [0] = {
  87. .type = AUTH_METHOD_HASH,
  88. .param.hash = {
  89. .data = &raw_data,
  90. .hash = &scp_bl2u_hash
  91. }
  92. }
  93. }
  94. };
  95. /*
  96. * BL2U
  97. */
  98. static const auth_img_desc_t bl2u_image = {
  99. .img_id = BL2U_IMAGE_ID,
  100. .img_type = IMG_RAW,
  101. .parent = &fwu_cert,
  102. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  103. [0] = {
  104. .type = AUTH_METHOD_HASH,
  105. .param.hash = {
  106. .data = &raw_data,
  107. .hash = &bl2u_hash
  108. }
  109. }
  110. }
  111. };
  112. /*
  113. * NS_BL2U
  114. */
  115. static const auth_img_desc_t ns_bl2u_image = {
  116. .img_id = NS_BL2U_IMAGE_ID,
  117. .img_type = IMG_RAW,
  118. .parent = &fwu_cert,
  119. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  120. [0] = {
  121. .type = AUTH_METHOD_HASH,
  122. .param.hash = {
  123. .data = &raw_data,
  124. .hash = &ns_bl2u_hash
  125. }
  126. }
  127. }
  128. };
  129. /*
  130. * TB_FW_CONFIG
  131. */
  132. static const auth_img_desc_t tb_fw_config = {
  133. .img_id = TB_FW_CONFIG_ID,
  134. .img_type = IMG_RAW,
  135. .parent = &trusted_boot_fw_cert,
  136. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  137. [0] = {
  138. .type = AUTH_METHOD_HASH,
  139. .param.hash = {
  140. .data = &raw_data,
  141. .hash = &tb_fw_config_hash
  142. }
  143. }
  144. }
  145. };
  146. static const auth_img_desc_t fw_config = {
  147. .img_id = FW_CONFIG_ID,
  148. .img_type = IMG_RAW,
  149. .parent = &trusted_boot_fw_cert,
  150. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  151. [0] = {
  152. .type = AUTH_METHOD_HASH,
  153. .param.hash = {
  154. .data = &raw_data,
  155. .hash = &fw_config_hash
  156. }
  157. }
  158. }
  159. };
  160. /*
  161. * TBBR Chain of trust definition
  162. */
  163. static const auth_img_desc_t * const cot_desc[] = {
  164. [TRUSTED_BOOT_FW_CERT_ID] = &trusted_boot_fw_cert,
  165. [BL2_IMAGE_ID] = &bl2_image,
  166. [HW_CONFIG_ID] = &hw_config,
  167. [TB_FW_CONFIG_ID] = &tb_fw_config,
  168. [FW_CONFIG_ID] = &fw_config,
  169. [FWU_CERT_ID] = &fwu_cert,
  170. [SCP_BL2U_IMAGE_ID] = &scp_bl2u_image,
  171. [BL2U_IMAGE_ID] = &bl2u_image,
  172. [NS_BL2U_IMAGE_ID] = &ns_bl2u_image
  173. };
  174. /* Register the CoT in the authentication module */
  175. REGISTER_COT(cot_desc);