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