105799ae0SJuan Castillo /* 26f8a2565SSandrine Bailleux * Copyright (c) 2015-2020, 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 1005799ae0SJuan Castillo #if TRUSTED_BOARD_BOOT 1105799ae0SJuan Castillo 1209d40e0eSAntonio Nino Diaz #include <common/tbbr/cot_def.h> 1309d40e0eSAntonio Nino Diaz #include <common/tbbr/tbbr_img_def.h> 1409d40e0eSAntonio Nino Diaz #include <drivers/auth/auth_common.h> 1509d40e0eSAntonio Nino Diaz #include <drivers/auth/img_parser_mod.h> 1605799ae0SJuan Castillo 176f8a2565SSandrine Bailleux #include <lib/utils_def.h> 186f8a2565SSandrine Bailleux 1905799ae0SJuan Castillo /* 2005799ae0SJuan Castillo * Image flags 2105799ae0SJuan Castillo */ 2205799ae0SJuan Castillo #define IMG_FLAG_AUTHENTICATED (1 << 0) 2305799ae0SJuan Castillo 24*28e9a55fSManish V Badarkhe #if COT_DESC_IN_DTB && !IMAGE_BL1 25*28e9a55fSManish V Badarkhe /* 26*28e9a55fSManish V Badarkhe * Authentication image descriptor 27*28e9a55fSManish V Badarkhe */ 28*28e9a55fSManish V Badarkhe typedef struct auth_img_desc_s { 29*28e9a55fSManish V Badarkhe unsigned int img_id; 30*28e9a55fSManish V Badarkhe img_type_t img_type; 31*28e9a55fSManish V Badarkhe const struct auth_img_desc_s *parent; 32*28e9a55fSManish V Badarkhe auth_method_desc_t *img_auth_methods; 33*28e9a55fSManish V Badarkhe auth_param_desc_t *authenticated_data; 34*28e9a55fSManish V Badarkhe } auth_img_desc_t; 35*28e9a55fSManish V Badarkhe #else 3605799ae0SJuan Castillo /* 3705799ae0SJuan Castillo * Authentication image descriptor 3805799ae0SJuan Castillo */ 3905799ae0SJuan Castillo typedef struct auth_img_desc_s { 4005799ae0SJuan Castillo unsigned int img_id; 4105799ae0SJuan Castillo img_type_t img_type; 42b313d755SSoby Mathew const struct auth_img_desc_s *parent; 4330070427SJoel Hutton const auth_method_desc_t *const img_auth_methods; 4430070427SJoel Hutton const auth_param_desc_t *const authenticated_data; 4505799ae0SJuan Castillo } auth_img_desc_t; 46*28e9a55fSManish V Badarkhe #endif /* COT_DESC_IN_DTB && !IMAGE_BL1 */ 4705799ae0SJuan Castillo 4805799ae0SJuan Castillo /* Public functions */ 4905799ae0SJuan Castillo void auth_mod_init(void); 5005799ae0SJuan Castillo int auth_mod_get_parent_id(unsigned int img_id, unsigned int *parent_id); 5105799ae0SJuan Castillo int auth_mod_verify_img(unsigned int img_id, 5205799ae0SJuan Castillo void *img_ptr, 5305799ae0SJuan Castillo unsigned int img_len); 5405799ae0SJuan Castillo 550b6377d1SJoel Hutton /* Macro to register a CoT defined as an array of auth_img_desc_t pointers */ 5605799ae0SJuan Castillo #define REGISTER_COT(_cot) \ 572efb7ddcSSandrine Bailleux const auth_img_desc_t *const *const cot_desc_ptr = (_cot); \ 586f8a2565SSandrine Bailleux const size_t cot_desc_size = ARRAY_SIZE(_cot); \ 59735181b6SRoberto Vargas unsigned int auth_img_flags[MAX_NUMBER_IDS] 6005799ae0SJuan Castillo 612efb7ddcSSandrine Bailleux extern const auth_img_desc_t *const *const cot_desc_ptr; 626f8a2565SSandrine Bailleux extern const size_t cot_desc_size; 633b94189aSRoberto Vargas extern unsigned int auth_img_flags[MAX_NUMBER_IDS]; 643b94189aSRoberto Vargas 6544f1aa8eSManish Pandey #if defined(SPD_spmd) 662947412dSManish Pandey 672947412dSManish Pandey #define DEFINE_SIP_SP_PKG(n) DEFINE_SP_PKG(n, sip_sp_content_cert) 682947412dSManish Pandey #define DEFINE_PLAT_SP_PKG(n) DEFINE_SP_PKG(n, plat_sp_content_cert) 692947412dSManish Pandey 702947412dSManish Pandey #define DEFINE_SP_PKG(n, cert) \ 7144f1aa8eSManish Pandey static const auth_img_desc_t sp_pkg##n = { \ 7203a5225cSManish Pandey .img_id = SP_PKG##n##_ID, \ 7344f1aa8eSManish Pandey .img_type = IMG_RAW, \ 742947412dSManish Pandey .parent = &cert, \ 7544f1aa8eSManish Pandey .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { \ 7644f1aa8eSManish Pandey [0] = { \ 7744f1aa8eSManish Pandey .type = AUTH_METHOD_HASH, \ 7844f1aa8eSManish Pandey .param.hash = { \ 7944f1aa8eSManish Pandey .data = &raw_data, \ 8044f1aa8eSManish Pandey .hash = &sp_pkg##n##_hash \ 8144f1aa8eSManish Pandey } \ 8244f1aa8eSManish Pandey } \ 8344f1aa8eSManish Pandey } \ 8444f1aa8eSManish Pandey } 852947412dSManish Pandey 8644f1aa8eSManish Pandey #endif 8744f1aa8eSManish Pandey 8805799ae0SJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 8905799ae0SJuan Castillo 90c3cf06f1SAntonio Nino Diaz #endif /* AUTH_MOD_H */ 91