bl1_cot.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (c) 2022-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/cca_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. /*
  20. * Parameter type descriptors.
  21. */
  22. static auth_param_type_desc_t cca_nv_ctr = AUTH_PARAM_TYPE_DESC(
  23. AUTH_PARAM_NV_CTR, CCA_FW_NVCOUNTER_OID);
  24. static auth_param_type_desc_t subject_pk = AUTH_PARAM_TYPE_DESC(
  25. AUTH_PARAM_PUB_KEY, 0);
  26. static auth_param_type_desc_t sig = AUTH_PARAM_TYPE_DESC(
  27. AUTH_PARAM_SIG, 0);
  28. static auth_param_type_desc_t sig_alg = AUTH_PARAM_TYPE_DESC(
  29. AUTH_PARAM_SIG_ALG, 0);
  30. static auth_param_type_desc_t raw_data = AUTH_PARAM_TYPE_DESC(
  31. AUTH_PARAM_RAW_DATA, 0);
  32. static auth_param_type_desc_t tb_fw_hash = AUTH_PARAM_TYPE_DESC(
  33. AUTH_PARAM_HASH, TRUSTED_BOOT_FW_HASH_OID);
  34. static auth_param_type_desc_t tb_fw_config_hash = AUTH_PARAM_TYPE_DESC(
  35. AUTH_PARAM_HASH, TRUSTED_BOOT_FW_CONFIG_HASH_OID);
  36. static auth_param_type_desc_t fw_config_hash = AUTH_PARAM_TYPE_DESC(
  37. AUTH_PARAM_HASH, FW_CONFIG_HASH_OID);
  38. /* CCA Content Certificate */
  39. static const auth_img_desc_t cca_content_cert = {
  40. .img_id = CCA_CONTENT_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. [1] = {
  54. .type = AUTH_METHOD_NV_CTR,
  55. .param.nv_ctr = {
  56. .cert_nv_ctr = &cca_nv_ctr,
  57. .plat_nv_ctr = &cca_nv_ctr
  58. }
  59. }
  60. },
  61. .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
  62. [0] = {
  63. .type_desc = &tb_fw_hash,
  64. .data = {
  65. .ptr = (void *)tb_fw_hash_buf,
  66. .len = (unsigned int)HASH_DER_LEN
  67. }
  68. },
  69. [1] = {
  70. .type_desc = &tb_fw_config_hash,
  71. .data = {
  72. .ptr = (void *)tb_fw_config_hash_buf,
  73. .len = (unsigned int)HASH_DER_LEN
  74. }
  75. },
  76. [2] = {
  77. .type_desc = &fw_config_hash,
  78. .data = {
  79. .ptr = (void *)fw_config_hash_buf,
  80. .len = (unsigned int)HASH_DER_LEN
  81. }
  82. }
  83. }
  84. };
  85. static const auth_img_desc_t bl2_image = {
  86. .img_id = BL2_IMAGE_ID,
  87. .img_type = IMG_RAW,
  88. .parent = &cca_content_cert,
  89. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  90. [0] = {
  91. .type = AUTH_METHOD_HASH,
  92. .param.hash = {
  93. .data = &raw_data,
  94. .hash = &tb_fw_hash
  95. }
  96. }
  97. }
  98. };
  99. static const auth_img_desc_t tb_fw_config = {
  100. .img_id = TB_FW_CONFIG_ID,
  101. .img_type = IMG_RAW,
  102. .parent = &cca_content_cert,
  103. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  104. [0] = {
  105. .type = AUTH_METHOD_HASH,
  106. .param.hash = {
  107. .data = &raw_data,
  108. .hash = &tb_fw_config_hash
  109. }
  110. }
  111. }
  112. };
  113. static const auth_img_desc_t fw_config = {
  114. .img_id = FW_CONFIG_ID,
  115. .img_type = IMG_RAW,
  116. .parent = &cca_content_cert,
  117. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  118. [0] = {
  119. .type = AUTH_METHOD_HASH,
  120. .param.hash = {
  121. .data = &raw_data,
  122. .hash = &fw_config_hash
  123. }
  124. }
  125. }
  126. };
  127. static const auth_img_desc_t * const cot_desc[] = {
  128. [CCA_CONTENT_CERT_ID] = &cca_content_cert,
  129. [BL2_IMAGE_ID] = &bl2_image,
  130. [TB_FW_CONFIG_ID] = &tb_fw_config,
  131. [FW_CONFIG_ID] = &fw_config,
  132. };
  133. REGISTER_COT(cot_desc);