tbbr_cot_common.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2015-2024, 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. /*
  17. * The platform must allocate buffers to store the authentication parameters
  18. * extracted from the certificates. In this case, because of the way the CoT is
  19. * established, we can reuse some of the buffers on different stages
  20. */
  21. static unsigned char fw_config_hash_buf[HASH_DER_LEN];
  22. static unsigned char tb_fw_config_hash_buf[HASH_DER_LEN];
  23. static unsigned char hw_config_hash_buf[HASH_DER_LEN];
  24. unsigned char tb_fw_hash_buf[HASH_DER_LEN];
  25. unsigned char scp_fw_hash_buf[HASH_DER_LEN];
  26. unsigned char nt_world_bl_hash_buf[HASH_DER_LEN];
  27. /*
  28. * common Parameter type descriptors across BL1 and BL2
  29. */
  30. auth_param_type_desc_t trusted_nv_ctr = AUTH_PARAM_TYPE_DESC(
  31. AUTH_PARAM_NV_CTR, TRUSTED_FW_NVCOUNTER_OID);
  32. auth_param_type_desc_t subject_pk = AUTH_PARAM_TYPE_DESC(
  33. AUTH_PARAM_PUB_KEY, 0);
  34. auth_param_type_desc_t sig = AUTH_PARAM_TYPE_DESC(
  35. AUTH_PARAM_SIG, 0);
  36. auth_param_type_desc_t sig_alg = AUTH_PARAM_TYPE_DESC(
  37. AUTH_PARAM_SIG_ALG, 0);
  38. auth_param_type_desc_t raw_data = AUTH_PARAM_TYPE_DESC(
  39. AUTH_PARAM_RAW_DATA, 0);
  40. /* common hash used across BL1 and BL2 */
  41. auth_param_type_desc_t tb_fw_hash = AUTH_PARAM_TYPE_DESC(
  42. AUTH_PARAM_HASH, TRUSTED_BOOT_FW_HASH_OID);
  43. auth_param_type_desc_t tb_fw_config_hash = AUTH_PARAM_TYPE_DESC(
  44. AUTH_PARAM_HASH, TRUSTED_BOOT_FW_CONFIG_HASH_OID);
  45. auth_param_type_desc_t fw_config_hash = AUTH_PARAM_TYPE_DESC(
  46. AUTH_PARAM_HASH, FW_CONFIG_HASH_OID);
  47. auth_param_type_desc_t hw_config_hash = AUTH_PARAM_TYPE_DESC(
  48. AUTH_PARAM_HASH, HW_CONFIG_HASH_OID);
  49. /* trusted_boot_fw_cert */
  50. const auth_img_desc_t trusted_boot_fw_cert = {
  51. .img_id = TRUSTED_BOOT_FW_CERT_ID,
  52. .img_type = IMG_CERT,
  53. .parent = NULL,
  54. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
  55. [0] = {
  56. .type = AUTH_METHOD_SIG,
  57. .param.sig = {
  58. .pk = &subject_pk,
  59. .sig = &sig,
  60. .alg = &sig_alg,
  61. .data = &raw_data
  62. }
  63. },
  64. [1] = {
  65. .type = AUTH_METHOD_NV_CTR,
  66. .param.nv_ctr = {
  67. .cert_nv_ctr = &trusted_nv_ctr,
  68. .plat_nv_ctr = &trusted_nv_ctr
  69. }
  70. }
  71. },
  72. .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
  73. [0] = {
  74. .type_desc = &tb_fw_hash,
  75. .data = {
  76. .ptr = (void *)tb_fw_hash_buf,
  77. .len = (unsigned int)HASH_DER_LEN
  78. }
  79. },
  80. [1] = {
  81. .type_desc = &tb_fw_config_hash,
  82. .data = {
  83. .ptr = (void *)tb_fw_config_hash_buf,
  84. .len = (unsigned int)HASH_DER_LEN
  85. }
  86. },
  87. [2] = {
  88. .type_desc = &hw_config_hash,
  89. .data = {
  90. .ptr = (void *)hw_config_hash_buf,
  91. .len = (unsigned int)HASH_DER_LEN
  92. }
  93. },
  94. [3] = {
  95. .type_desc = &fw_config_hash,
  96. .data = {
  97. .ptr = (void *)fw_config_hash_buf,
  98. .len = (unsigned int)HASH_DER_LEN
  99. }
  100. }
  101. }
  102. };