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