Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 1 | /* |
Govindraj Raja | 9c7dfb0 | 2023-01-11 18:34:58 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved. |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef AUTH_MOD_H |
| 8 | #define AUTH_MOD_H |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 9 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <common/tbbr/tbbr_img_def.h> |
| 11 | #include <drivers/auth/auth_common.h> |
| 12 | #include <drivers/auth/img_parser_mod.h> |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 13 | |
Sandrine Bailleux | 4bca140 | 2020-03-25 11:22:34 +0100 | [diff] [blame] | 14 | #include <lib/utils_def.h> |
| 15 | |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 16 | /* |
| 17 | * Image flags |
| 18 | */ |
| 19 | #define IMG_FLAG_AUTHENTICATED (1 << 0) |
| 20 | |
Manish V Badarkhe | 39317ab | 2020-07-23 10:43:57 +0100 | [diff] [blame] | 21 | #if COT_DESC_IN_DTB && !IMAGE_BL1 |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 22 | /* |
| 23 | * Authentication image descriptor |
| 24 | */ |
| 25 | typedef struct auth_img_desc_s { |
| 26 | unsigned int img_id; |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 27 | img_type_t img_type; |
Soby Mathew | 6d4f262 | 2016-01-12 10:30:59 +0000 | [diff] [blame] | 28 | const struct auth_img_desc_s *parent; |
Manish V Badarkhe | 39317ab | 2020-07-23 10:43:57 +0100 | [diff] [blame] | 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; |
Joel Hutton | 69931af | 2019-03-11 11:37:38 +0000 | [diff] [blame] | 40 | const auth_method_desc_t *const img_auth_methods; |
| 41 | const auth_param_desc_t *const authenticated_data; |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 42 | } auth_img_desc_t; |
Manish V Badarkhe | 39317ab | 2020-07-23 10:43:57 +0100 | [diff] [blame] | 43 | #endif /* COT_DESC_IN_DTB && !IMAGE_BL1 */ |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 44 | |
| 45 | /* Public functions */ |
Manish V Badarkhe | 92de80a | 2021-12-16 10:41:47 +0000 | [diff] [blame] | 46 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 47 | void auth_mod_init(void); |
Manish V Badarkhe | 92de80a | 2021-12-16 10:41:47 +0000 | [diff] [blame] | 48 | #else |
| 49 | static inline void auth_mod_init(void) |
| 50 | { |
| 51 | } |
| 52 | #endif /* TRUSTED_BOARD_BOOT */ |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 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 | |
Joel Hutton | e9919bb | 2019-02-20 11:56:46 +0000 | [diff] [blame] | 58 | /* Macro to register a CoT defined as an array of auth_img_desc_t pointers */ |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 59 | #define REGISTER_COT(_cot) \ |
Sandrine Bailleux | 25532c7 | 2019-06-07 14:33:51 +0200 | [diff] [blame] | 60 | const auth_img_desc_t *const *const cot_desc_ptr = (_cot); \ |
Sandrine Bailleux | 4bca140 | 2020-03-25 11:22:34 +0100 | [diff] [blame] | 61 | const size_t cot_desc_size = ARRAY_SIZE(_cot); \ |
Roberto Vargas | be126ed | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 62 | unsigned int auth_img_flags[MAX_NUMBER_IDS] |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 63 | |
Sandrine Bailleux | 25532c7 | 2019-06-07 14:33:51 +0200 | [diff] [blame] | 64 | extern const auth_img_desc_t *const *const cot_desc_ptr; |
Sandrine Bailleux | 4bca140 | 2020-03-25 11:22:34 +0100 | [diff] [blame] | 65 | extern const size_t cot_desc_size; |
Roberto Vargas | 52f707f | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 66 | extern unsigned int auth_img_flags[MAX_NUMBER_IDS]; |
| 67 | |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 68 | #if defined(SPD_spmd) |
Manish Pandey | 6aef2cc | 2020-07-31 16:25:17 +0100 | [diff] [blame] | 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) \ |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 74 | static const auth_img_desc_t sp_pkg##n = { \ |
Manish Pandey | d07d017 | 2020-07-23 16:54:30 +0100 | [diff] [blame] | 75 | .img_id = SP_PKG##n##_ID, \ |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 76 | .img_type = IMG_RAW, \ |
Manish Pandey | 6aef2cc | 2020-07-31 16:25:17 +0100 | [diff] [blame] | 77 | .parent = &cert, \ |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 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 | } |
Manish Pandey | 6aef2cc | 2020-07-31 16:25:17 +0100 | [diff] [blame] | 88 | |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 89 | #endif |
| 90 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 91 | #endif /* AUTH_MOD_H */ |