blob: 28aa40784a16a7a94208bb4a69fbe1b14e350d73 [file] [log] [blame]
Juan Castillo8e55d932015-04-02 09:48:16 +01001/*
Govindraj Raja9c7dfb02023-01-11 18:34:58 +00002 * Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved.
Juan Castillo8e55d932015-04-02 09:48:16 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo8e55d932015-04-02 09:48:16 +01005 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef AUTH_MOD_H
8#define AUTH_MOD_H
Juan Castillo8e55d932015-04-02 09:48:16 +01009
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <common/tbbr/tbbr_img_def.h>
11#include <drivers/auth/auth_common.h>
12#include <drivers/auth/img_parser_mod.h>
Juan Castillo8e55d932015-04-02 09:48:16 +010013
Sandrine Bailleux4bca1402020-03-25 11:22:34 +010014#include <lib/utils_def.h>
15
Juan Castillo8e55d932015-04-02 09:48:16 +010016/*
17 * Image flags
18 */
19#define IMG_FLAG_AUTHENTICATED (1 << 0)
20
Manish V Badarkhe39317ab2020-07-23 10:43:57 +010021#if COT_DESC_IN_DTB && !IMAGE_BL1
Juan Castillo8e55d932015-04-02 09:48:16 +010022/*
23 * Authentication image descriptor
24 */
25typedef struct auth_img_desc_s {
26 unsigned int img_id;
Juan Castillo8e55d932015-04-02 09:48:16 +010027 img_type_t img_type;
Soby Mathew6d4f2622016-01-12 10:30:59 +000028 const struct auth_img_desc_s *parent;
Manish V Badarkhe39317ab2020-07-23 10:43:57 +010029 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 */
36typedef 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 Hutton69931af2019-03-11 11:37:38 +000040 const auth_method_desc_t *const img_auth_methods;
41 const auth_param_desc_t *const authenticated_data;
Juan Castillo8e55d932015-04-02 09:48:16 +010042} auth_img_desc_t;
Manish V Badarkhe39317ab2020-07-23 10:43:57 +010043#endif /* COT_DESC_IN_DTB && !IMAGE_BL1 */
Juan Castillo8e55d932015-04-02 09:48:16 +010044
45/* Public functions */
Manish V Badarkhe92de80a2021-12-16 10:41:47 +000046#if TRUSTED_BOARD_BOOT
Juan Castillo8e55d932015-04-02 09:48:16 +010047void auth_mod_init(void);
Manish V Badarkhe92de80a2021-12-16 10:41:47 +000048#else
49static inline void auth_mod_init(void)
50{
51}
52#endif /* TRUSTED_BOARD_BOOT */
Juan Castillo8e55d932015-04-02 09:48:16 +010053int auth_mod_get_parent_id(unsigned int img_id, unsigned int *parent_id);
54int auth_mod_verify_img(unsigned int img_id,
55 void *img_ptr,
56 unsigned int img_len);
57
Joel Huttone9919bb2019-02-20 11:56:46 +000058/* Macro to register a CoT defined as an array of auth_img_desc_t pointers */
Juan Castillo8e55d932015-04-02 09:48:16 +010059#define REGISTER_COT(_cot) \
Sandrine Bailleux25532c72019-06-07 14:33:51 +020060 const auth_img_desc_t *const *const cot_desc_ptr = (_cot); \
Sandrine Bailleux4bca1402020-03-25 11:22:34 +010061 const size_t cot_desc_size = ARRAY_SIZE(_cot); \
Roberto Vargasbe126ed2018-02-12 12:36:17 +000062 unsigned int auth_img_flags[MAX_NUMBER_IDS]
Juan Castillo8e55d932015-04-02 09:48:16 +010063
Sandrine Bailleux25532c72019-06-07 14:33:51 +020064extern const auth_img_desc_t *const *const cot_desc_ptr;
Sandrine Bailleux4bca1402020-03-25 11:22:34 +010065extern const size_t cot_desc_size;
Roberto Vargas52f707f2018-02-12 12:36:17 +000066extern unsigned int auth_img_flags[MAX_NUMBER_IDS];
67
Manish Pandey5f8e1a02020-05-27 22:40:10 +010068#if defined(SPD_spmd)
Manish Pandey6aef2cc2020-07-31 16:25:17 +010069
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 Pandey5f8e1a02020-05-27 22:40:10 +010074 static const auth_img_desc_t sp_pkg##n = { \
Manish Pandeyd07d0172020-07-23 16:54:30 +010075 .img_id = SP_PKG##n##_ID, \
Manish Pandey5f8e1a02020-05-27 22:40:10 +010076 .img_type = IMG_RAW, \
Manish Pandey6aef2cc2020-07-31 16:25:17 +010077 .parent = &cert, \
Manish Pandey5f8e1a02020-05-27 22:40:10 +010078 .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 Pandey6aef2cc2020-07-31 16:25:17 +010088
Manish Pandey5f8e1a02020-05-27 22:40:10 +010089#endif
90
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000091#endif /* AUTH_MOD_H */