auth_mod.h 2.3 KB

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