xref: /rk3399_ARM-atf/include/drivers/auth/auth_mod.h (revision 0aa0b3afd643379805440dddffffeb21dab52523)
105799ae0SJuan Castillo /*
2*0aa0b3afSManish V Badarkhe  * Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved.
305799ae0SJuan Castillo  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
505799ae0SJuan Castillo  */
605799ae0SJuan Castillo 
7c3cf06f1SAntonio Nino Diaz #ifndef AUTH_MOD_H
8c3cf06f1SAntonio Nino Diaz #define AUTH_MOD_H
905799ae0SJuan Castillo 
1009d40e0eSAntonio Nino Diaz #include <common/tbbr/cot_def.h>
1109d40e0eSAntonio Nino Diaz #include <common/tbbr/tbbr_img_def.h>
1209d40e0eSAntonio Nino Diaz #include <drivers/auth/auth_common.h>
1309d40e0eSAntonio Nino Diaz #include <drivers/auth/img_parser_mod.h>
1405799ae0SJuan Castillo 
156f8a2565SSandrine Bailleux #include <lib/utils_def.h>
166f8a2565SSandrine Bailleux 
1705799ae0SJuan Castillo /*
1805799ae0SJuan Castillo  * Image flags
1905799ae0SJuan Castillo  */
2005799ae0SJuan Castillo #define IMG_FLAG_AUTHENTICATED		(1 << 0)
2105799ae0SJuan Castillo 
2228e9a55fSManish V Badarkhe #if COT_DESC_IN_DTB && !IMAGE_BL1
2328e9a55fSManish V Badarkhe /*
2428e9a55fSManish V Badarkhe  * Authentication image descriptor
2528e9a55fSManish V Badarkhe  */
2628e9a55fSManish V Badarkhe typedef struct auth_img_desc_s {
2728e9a55fSManish V Badarkhe 	unsigned int img_id;
2828e9a55fSManish V Badarkhe 	img_type_t img_type;
2928e9a55fSManish V Badarkhe 	const struct auth_img_desc_s *parent;
3028e9a55fSManish V Badarkhe 	auth_method_desc_t *img_auth_methods;
3128e9a55fSManish V Badarkhe 	auth_param_desc_t *authenticated_data;
3228e9a55fSManish V Badarkhe } auth_img_desc_t;
3328e9a55fSManish V Badarkhe #else
3405799ae0SJuan Castillo /*
3505799ae0SJuan Castillo  * Authentication image descriptor
3605799ae0SJuan Castillo  */
3705799ae0SJuan Castillo typedef struct auth_img_desc_s {
3805799ae0SJuan Castillo 	unsigned int img_id;
3905799ae0SJuan Castillo 	img_type_t img_type;
40b313d755SSoby Mathew 	const struct auth_img_desc_s *parent;
4130070427SJoel Hutton 	const auth_method_desc_t *const img_auth_methods;
4230070427SJoel Hutton 	const auth_param_desc_t *const authenticated_data;
4305799ae0SJuan Castillo } auth_img_desc_t;
4428e9a55fSManish V Badarkhe #endif /* COT_DESC_IN_DTB && !IMAGE_BL1 */
4505799ae0SJuan Castillo 
4605799ae0SJuan Castillo /* Public functions */
47*0aa0b3afSManish V Badarkhe #if TRUSTED_BOARD_BOOT
4805799ae0SJuan Castillo void auth_mod_init(void);
49*0aa0b3afSManish V Badarkhe #else
50*0aa0b3afSManish V Badarkhe static inline void auth_mod_init(void)
51*0aa0b3afSManish V Badarkhe {
52*0aa0b3afSManish V Badarkhe }
53*0aa0b3afSManish V Badarkhe #endif /* TRUSTED_BOARD_BOOT */
5405799ae0SJuan Castillo int auth_mod_get_parent_id(unsigned int img_id, unsigned int *parent_id);
5505799ae0SJuan Castillo int auth_mod_verify_img(unsigned int img_id,
5605799ae0SJuan Castillo 			void *img_ptr,
5705799ae0SJuan Castillo 			unsigned int img_len);
5805799ae0SJuan Castillo 
590b6377d1SJoel Hutton /* Macro to register a CoT defined as an array of auth_img_desc_t pointers */
6005799ae0SJuan Castillo #define REGISTER_COT(_cot) \
612efb7ddcSSandrine Bailleux 	const auth_img_desc_t *const *const cot_desc_ptr = (_cot); \
626f8a2565SSandrine Bailleux 	const size_t cot_desc_size = ARRAY_SIZE(_cot);		   \
63735181b6SRoberto Vargas 	unsigned int auth_img_flags[MAX_NUMBER_IDS]
6405799ae0SJuan Castillo 
652efb7ddcSSandrine Bailleux extern const auth_img_desc_t *const *const cot_desc_ptr;
666f8a2565SSandrine Bailleux extern const size_t cot_desc_size;
673b94189aSRoberto Vargas extern unsigned int auth_img_flags[MAX_NUMBER_IDS];
683b94189aSRoberto Vargas 
6944f1aa8eSManish Pandey #if defined(SPD_spmd)
702947412dSManish Pandey 
712947412dSManish Pandey #define DEFINE_SIP_SP_PKG(n)		DEFINE_SP_PKG(n, sip_sp_content_cert)
722947412dSManish Pandey #define DEFINE_PLAT_SP_PKG(n)		DEFINE_SP_PKG(n, plat_sp_content_cert)
732947412dSManish Pandey 
742947412dSManish Pandey #define DEFINE_SP_PKG(n, cert) \
7544f1aa8eSManish Pandey 	static const auth_img_desc_t sp_pkg##n = { \
7603a5225cSManish Pandey 		.img_id = SP_PKG##n##_ID, \
7744f1aa8eSManish Pandey 		.img_type = IMG_RAW, \
782947412dSManish Pandey 		.parent = &cert, \
7944f1aa8eSManish Pandey 		.img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { \
8044f1aa8eSManish Pandey 			[0] = { \
8144f1aa8eSManish Pandey 				.type = AUTH_METHOD_HASH, \
8244f1aa8eSManish Pandey 				.param.hash = { \
8344f1aa8eSManish Pandey 					.data = &raw_data, \
8444f1aa8eSManish Pandey 					.hash = &sp_pkg##n##_hash \
8544f1aa8eSManish Pandey 				} \
8644f1aa8eSManish Pandey 			} \
8744f1aa8eSManish Pandey 		} \
8844f1aa8eSManish Pandey 	}
892947412dSManish Pandey 
9044f1aa8eSManish Pandey #endif
9144f1aa8eSManish Pandey 
92c3cf06f1SAntonio Nino Diaz #endif /* AUTH_MOD_H */
93