tbbr_cot_bl1_r64.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (c) 2021-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 unsigned char trusted_world_pk_buf[PK_DER_LEN];
  17. static unsigned char non_trusted_world_pk_buf[PK_DER_LEN];
  18. static unsigned char content_pk_buf[PK_DER_LEN];
  19. static unsigned char nt_fw_config_hash_buf[HASH_DER_LEN];
  20. static auth_param_type_desc_t non_trusted_nv_ctr = AUTH_PARAM_TYPE_DESC(
  21. AUTH_PARAM_NV_CTR, NON_TRUSTED_FW_NVCOUNTER_OID);
  22. static auth_param_type_desc_t trusted_world_pk = AUTH_PARAM_TYPE_DESC(
  23. AUTH_PARAM_PUB_KEY, TRUSTED_WORLD_PK_OID);
  24. static auth_param_type_desc_t non_trusted_world_pk = AUTH_PARAM_TYPE_DESC(
  25. AUTH_PARAM_PUB_KEY, NON_TRUSTED_WORLD_PK_OID);
  26. static auth_param_type_desc_t nt_fw_content_pk = AUTH_PARAM_TYPE_DESC(
  27. AUTH_PARAM_PUB_KEY, NON_TRUSTED_FW_CONTENT_CERT_PK_OID);
  28. static auth_param_type_desc_t nt_world_bl_hash = AUTH_PARAM_TYPE_DESC(
  29. AUTH_PARAM_HASH, NON_TRUSTED_WORLD_BOOTLOADER_HASH_OID);
  30. static auth_param_type_desc_t nt_fw_config_hash = AUTH_PARAM_TYPE_DESC(
  31. AUTH_PARAM_HASH, NON_TRUSTED_FW_CONFIG_HASH_OID);
  32. /*
  33. * Trusted key certificate
  34. */
  35. static const auth_img_desc_t trusted_key_cert = {
  36. .img_id = TRUSTED_KEY_CERT_ID,
  37. .img_type = IMG_CERT,
  38. .parent = NULL,
  39. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  40. [0] = {
  41. .type = AUTH_METHOD_SIG,
  42. .param.sig = {
  43. .pk = &subject_pk,
  44. .sig = &sig,
  45. .alg = &sig_alg,
  46. .data = &raw_data
  47. }
  48. },
  49. [1] = {
  50. .type = AUTH_METHOD_NV_CTR,
  51. .param.nv_ctr = {
  52. .cert_nv_ctr = &trusted_nv_ctr,
  53. .plat_nv_ctr = &trusted_nv_ctr
  54. }
  55. }
  56. },
  57. .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
  58. [0] = {
  59. .type_desc = &trusted_world_pk,
  60. .data = {
  61. .ptr = (void *)trusted_world_pk_buf,
  62. .len = (unsigned int)PK_DER_LEN
  63. }
  64. },
  65. [1] = {
  66. .type_desc = &non_trusted_world_pk,
  67. .data = {
  68. .ptr = (void *)non_trusted_world_pk_buf,
  69. .len = (unsigned int)PK_DER_LEN
  70. }
  71. }
  72. }
  73. };
  74. /*
  75. * Non-Trusted Firmware
  76. */
  77. static const auth_img_desc_t non_trusted_fw_key_cert = {
  78. .img_id = NON_TRUSTED_FW_KEY_CERT_ID,
  79. .img_type = IMG_CERT,
  80. .parent = &trusted_key_cert,
  81. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  82. [0] = {
  83. .type = AUTH_METHOD_SIG,
  84. .param.sig = {
  85. .pk = &non_trusted_world_pk,
  86. .sig = &sig,
  87. .alg = &sig_alg,
  88. .data = &raw_data
  89. }
  90. },
  91. [1] = {
  92. .type = AUTH_METHOD_NV_CTR,
  93. .param.nv_ctr = {
  94. .cert_nv_ctr = &non_trusted_nv_ctr,
  95. .plat_nv_ctr = &non_trusted_nv_ctr
  96. }
  97. }
  98. },
  99. .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
  100. [0] = {
  101. .type_desc = &nt_fw_content_pk,
  102. .data = {
  103. .ptr = (void *)content_pk_buf,
  104. .len = (unsigned int)PK_DER_LEN
  105. }
  106. }
  107. }
  108. };
  109. static const auth_img_desc_t non_trusted_fw_content_cert = {
  110. .img_id = NON_TRUSTED_FW_CONTENT_CERT_ID,
  111. .img_type = IMG_CERT,
  112. .parent = &non_trusted_fw_key_cert,
  113. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  114. [0] = {
  115. .type = AUTH_METHOD_SIG,
  116. .param.sig = {
  117. .pk = &nt_fw_content_pk,
  118. .sig = &sig,
  119. .alg = &sig_alg,
  120. .data = &raw_data
  121. }
  122. },
  123. [1] = {
  124. .type = AUTH_METHOD_NV_CTR,
  125. .param.nv_ctr = {
  126. .cert_nv_ctr = &non_trusted_nv_ctr,
  127. .plat_nv_ctr = &non_trusted_nv_ctr
  128. }
  129. }
  130. },
  131. .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
  132. [0] = {
  133. .type_desc = &nt_world_bl_hash,
  134. .data = {
  135. .ptr = (void *)nt_world_bl_hash_buf,
  136. .len = (unsigned int)HASH_DER_LEN
  137. }
  138. },
  139. [1] = {
  140. .type_desc = &nt_fw_config_hash,
  141. .data = {
  142. .ptr = (void *)nt_fw_config_hash_buf,
  143. .len = (unsigned int)HASH_DER_LEN
  144. }
  145. }
  146. }
  147. };
  148. static const auth_img_desc_t bl33_image = {
  149. .img_id = BL33_IMAGE_ID,
  150. .img_type = IMG_RAW,
  151. .parent = &non_trusted_fw_content_cert,
  152. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  153. [0] = {
  154. .type = AUTH_METHOD_HASH,
  155. .param.hash = {
  156. .data = &raw_data,
  157. .hash = &nt_world_bl_hash
  158. }
  159. }
  160. }
  161. };
  162. static const auth_img_desc_t * const cot_desc[] = {
  163. [TRUSTED_KEY_CERT_ID] = &trusted_key_cert,
  164. [NON_TRUSTED_FW_KEY_CERT_ID] = &non_trusted_fw_key_cert,
  165. [NON_TRUSTED_FW_CONTENT_CERT_ID] = &non_trusted_fw_content_cert,
  166. [BL33_IMAGE_ID] = &bl33_image,
  167. };
  168. /* Register the CoT in the authentication module */
  169. REGISTER_COT(cot_desc);