auth_mod.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef AUTH_MOD_H
  7. #define AUTH_MOD_H
  8. #include <common/tbbr/tbbr_img_def.h>
  9. #include <drivers/auth/auth_common.h>
  10. #include <drivers/auth/img_parser_mod.h>
  11. #include <lib/utils_def.h>
  12. /*
  13. * Image flags
  14. */
  15. #define IMG_FLAG_AUTHENTICATED (1 << 0)
  16. #if COT_DESC_IN_DTB && !IMAGE_BL1
  17. /*
  18. * Authentication image descriptor
  19. */
  20. typedef struct auth_img_desc_s {
  21. unsigned int img_id;
  22. img_type_t img_type;
  23. const struct auth_img_desc_s *parent;
  24. auth_method_desc_t *img_auth_methods;
  25. auth_param_desc_t *authenticated_data;
  26. } auth_img_desc_t;
  27. #else
  28. /*
  29. * Authentication image descriptor
  30. */
  31. typedef struct auth_img_desc_s {
  32. unsigned int img_id;
  33. img_type_t img_type;
  34. const struct auth_img_desc_s *parent;
  35. const auth_method_desc_t *const img_auth_methods;
  36. const auth_param_desc_t *const authenticated_data;
  37. } auth_img_desc_t;
  38. #endif /* COT_DESC_IN_DTB && !IMAGE_BL1 */
  39. /* Public functions */
  40. #if TRUSTED_BOARD_BOOT
  41. void auth_mod_init(void);
  42. #else
  43. static inline void auth_mod_init(void)
  44. {
  45. }
  46. #endif /* TRUSTED_BOARD_BOOT */
  47. int auth_mod_get_parent_id(unsigned int img_id, unsigned int *parent_id);
  48. int auth_mod_verify_img(unsigned int img_id,
  49. void *img_ptr,
  50. unsigned int img_len);
  51. /* Macro to register a CoT defined as an array of auth_img_desc_t pointers */
  52. #define REGISTER_COT(_cot) \
  53. const auth_img_desc_t *const *const cot_desc_ptr = (_cot); \
  54. const size_t cot_desc_size = ARRAY_SIZE(_cot); \
  55. unsigned int auth_img_flags[MAX_NUMBER_IDS]
  56. extern const auth_img_desc_t *const *const cot_desc_ptr;
  57. extern const size_t cot_desc_size;
  58. extern unsigned int auth_img_flags[MAX_NUMBER_IDS];
  59. #if defined(SPD_spmd)
  60. #define DEFINE_SIP_SP_PKG(n) DEFINE_SP_PKG(n, sip_sp_content_cert)
  61. #define DEFINE_PLAT_SP_PKG(n) DEFINE_SP_PKG(n, plat_sp_content_cert)
  62. #define DEFINE_SP_PKG(n, cert) \
  63. static const auth_img_desc_t sp_pkg##n = { \
  64. .img_id = SP_PKG##n##_ID, \
  65. .img_type = IMG_RAW, \
  66. .parent = &cert, \
  67. .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { \
  68. [0] = { \
  69. .type = AUTH_METHOD_HASH, \
  70. .param.hash = { \
  71. .data = &raw_data, \
  72. .hash = &sp_pkg##n##_hash \
  73. } \
  74. } \
  75. } \
  76. }
  77. #endif
  78. #endif /* AUTH_MOD_H */