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