blob: 94537f61a87c912f7207de6edfefaf221a78a0a8 [file] [log] [blame]
Juan Castillo05799ae2015-04-02 09:48:16 +01001/*
Manish V Badarkhe0aa0b3a2021-12-16 10:41:47 +00002 * Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved.
Juan Castillo05799ae2015-04-02 09:48:16 +01003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo05799ae2015-04-02 09:48:16 +01005 */
6
Antonio Nino Diazc3cf06f2018-11-08 10:20:19 +00007#ifndef AUTH_MOD_H
8#define AUTH_MOD_H
Juan Castillo05799ae2015-04-02 09:48:16 +01009
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000010#include <common/tbbr/cot_def.h>
11#include <common/tbbr/tbbr_img_def.h>
12#include <drivers/auth/auth_common.h>
13#include <drivers/auth/img_parser_mod.h>
Juan Castillo05799ae2015-04-02 09:48:16 +010014
Sandrine Bailleux6f8a2562020-03-25 11:22:34 +010015#include <lib/utils_def.h>
16
Juan Castillo05799ae2015-04-02 09:48:16 +010017/*
18 * Image flags
19 */
20#define IMG_FLAG_AUTHENTICATED (1 << 0)
21
Manish V Badarkhe28e9a552020-07-23 10:43:57 +010022#if COT_DESC_IN_DTB && !IMAGE_BL1
23/*
24 * Authentication image descriptor
25 */
26typedef struct auth_img_desc_s {
27 unsigned int img_id;
28 img_type_t img_type;
29 const struct auth_img_desc_s *parent;
30 auth_method_desc_t *img_auth_methods;
31 auth_param_desc_t *authenticated_data;
32} auth_img_desc_t;
33#else
Juan Castillo05799ae2015-04-02 09:48:16 +010034/*
35 * Authentication image descriptor
36 */
37typedef struct auth_img_desc_s {
38 unsigned int img_id;
Juan Castillo05799ae2015-04-02 09:48:16 +010039 img_type_t img_type;
Soby Mathewb313d752016-01-12 10:30:59 +000040 const struct auth_img_desc_s *parent;
Joel Hutton30070422019-03-11 11:37:38 +000041 const auth_method_desc_t *const img_auth_methods;
42 const auth_param_desc_t *const authenticated_data;
Juan Castillo05799ae2015-04-02 09:48:16 +010043} auth_img_desc_t;
Manish V Badarkhe28e9a552020-07-23 10:43:57 +010044#endif /* COT_DESC_IN_DTB && !IMAGE_BL1 */
Juan Castillo05799ae2015-04-02 09:48:16 +010045
46/* Public functions */
Manish V Badarkhe0aa0b3a2021-12-16 10:41:47 +000047#if TRUSTED_BOARD_BOOT
Juan Castillo05799ae2015-04-02 09:48:16 +010048void auth_mod_init(void);
Manish V Badarkhe0aa0b3a2021-12-16 10:41:47 +000049#else
50static inline void auth_mod_init(void)
51{
52}
53#endif /* TRUSTED_BOARD_BOOT */
Juan Castillo05799ae2015-04-02 09:48:16 +010054int auth_mod_get_parent_id(unsigned int img_id, unsigned int *parent_id);
55int auth_mod_verify_img(unsigned int img_id,
56 void *img_ptr,
57 unsigned int img_len);
58
Joel Hutton0b6377d2019-02-20 11:56:46 +000059/* Macro to register a CoT defined as an array of auth_img_desc_t pointers */
Juan Castillo05799ae2015-04-02 09:48:16 +010060#define REGISTER_COT(_cot) \
Sandrine Bailleux2efb7dd2019-06-07 14:33:51 +020061 const auth_img_desc_t *const *const cot_desc_ptr = (_cot); \
Sandrine Bailleux6f8a2562020-03-25 11:22:34 +010062 const size_t cot_desc_size = ARRAY_SIZE(_cot); \
Roberto Vargas735181b2018-02-12 12:36:17 +000063 unsigned int auth_img_flags[MAX_NUMBER_IDS]
Juan Castillo05799ae2015-04-02 09:48:16 +010064
Sandrine Bailleux2efb7dd2019-06-07 14:33:51 +020065extern const auth_img_desc_t *const *const cot_desc_ptr;
Sandrine Bailleux6f8a2562020-03-25 11:22:34 +010066extern const size_t cot_desc_size;
Roberto Vargas3b941892018-02-12 12:36:17 +000067extern unsigned int auth_img_flags[MAX_NUMBER_IDS];
68
Manish Pandey44f1aa82020-05-27 22:40:10 +010069#if defined(SPD_spmd)
Manish Pandey29474122020-07-31 16:25:17 +010070
71#define DEFINE_SIP_SP_PKG(n) DEFINE_SP_PKG(n, sip_sp_content_cert)
72#define DEFINE_PLAT_SP_PKG(n) DEFINE_SP_PKG(n, plat_sp_content_cert)
73
74#define DEFINE_SP_PKG(n, cert) \
Manish Pandey44f1aa82020-05-27 22:40:10 +010075 static const auth_img_desc_t sp_pkg##n = { \
Manish Pandey03a52252020-07-23 16:54:30 +010076 .img_id = SP_PKG##n##_ID, \
Manish Pandey44f1aa82020-05-27 22:40:10 +010077 .img_type = IMG_RAW, \
Manish Pandey29474122020-07-31 16:25:17 +010078 .parent = &cert, \
Manish Pandey44f1aa82020-05-27 22:40:10 +010079 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { \
80 [0] = { \
81 .type = AUTH_METHOD_HASH, \
82 .param.hash = { \
83 .data = &raw_data, \
84 .hash = &sp_pkg##n##_hash \
85 } \
86 } \
87 } \
88 }
Manish Pandey29474122020-07-31 16:25:17 +010089
Manish Pandey44f1aa82020-05-27 22:40:10 +010090#endif
91
Antonio Nino Diazc3cf06f2018-11-08 10:20:19 +000092#endif /* AUTH_MOD_H */