blob: 6f00b180ca29c86b0c82529a8fc16505f127939c [file] [log] [blame]
Juan Castillo9b265a82015-05-07 14:52:44 +01001/*
Sandrine Bailleux41477e72020-02-17 13:41:59 +01002 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
Juan Castillo9b265a82015-05-07 14:52:44 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo9b265a82015-05-07 14:52:44 +01005 */
6
Isla Mitchell99305012017-07-11 14:54:08 +01007#include <stddef.h>
8
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <platform_def.h>
Justin Chadwellf9b32c12019-07-29 17:13:10 +010010#include <drivers/auth/mbedtls/mbedtls_config.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011
12#include <drivers/auth/auth_mod.h>
Masahiro Yamadaa27c1662017-05-22 12:11:24 +090013#if USE_TBBR_DEFS
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <tools_share/tbbr_oid.h>
Masahiro Yamadaa27c1662017-05-22 12:11:24 +090015#else
Juan Castillo9b265a82015-05-07 14:52:44 +010016#include <platform_oid.h>
Masahiro Yamadaa27c1662017-05-22 12:11:24 +090017#endif
Isla Mitchell99305012017-07-11 14:54:08 +010018
Juan Castillo9b265a82015-05-07 14:52:44 +010019
20/*
Sandrine Bailleux41477e72020-02-17 13:41:59 +010021 * Maximum key and hash sizes (in DER format).
22 *
23 * Both RSA and ECDSA keys may be used at the same time. In this case, the key
24 * buffers must be big enough to hold either. As RSA keys are bigger than ECDSA
25 * ones for all key sizes we support, they impose the minimum size of these
26 * buffers.
Juan Castillo9b265a82015-05-07 14:52:44 +010027 */
Justin Chadwellf9b32c12019-07-29 17:13:10 +010028#if TF_MBEDTLS_USE_RSA
29#if TF_MBEDTLS_KEY_SIZE == 1024
30#define PK_DER_LEN 162
31#elif TF_MBEDTLS_KEY_SIZE == 2048
Juan Castillo9b265a82015-05-07 14:52:44 +010032#define PK_DER_LEN 294
Justin Chadwellf9b32c12019-07-29 17:13:10 +010033#elif TF_MBEDTLS_KEY_SIZE == 3072
34#define PK_DER_LEN 422
35#elif TF_MBEDTLS_KEY_SIZE == 4096
36#define PK_DER_LEN 550
37#else
38#error "Invalid value for TF_MBEDTLS_KEY_SIZE"
39#endif
Sandrine Bailleux41477e72020-02-17 13:41:59 +010040#else /* Only using ECDSA keys. */
41#define PK_DER_LEN 91
Justin Chadwellf9b32c12019-07-29 17:13:10 +010042#endif
43
Sandrine Bailleuxfd754ce2020-02-17 16:26:05 +010044#if TF_MBEDTLS_HASH_ALG_ID == TF_MBEDTLS_SHA256
45#define HASH_DER_LEN 51
46#elif TF_MBEDTLS_HASH_ALG_ID == TF_MBEDTLS_SHA384
47#define HASH_DER_LEN 67
48#elif TF_MBEDTLS_HASH_ALG_ID == TF_MBEDTLS_SHA512
Qixiang Xu1a1f2912017-11-09 13:56:29 +080049#define HASH_DER_LEN 83
Sandrine Bailleuxfd754ce2020-02-17 16:26:05 +010050#else
51#error "Invalid value for TF_MBEDTLS_HASH_ALG_ID"
52#endif
Juan Castillo9b265a82015-05-07 14:52:44 +010053
54/*
55 * The platform must allocate buffers to store the authentication parameters
56 * extracted from the certificates. In this case, because of the way the CoT is
57 * established, we can reuse some of the buffers on different stages
58 */
Joel Huttone9919bb2019-02-20 11:56:46 +000059
Juan Castillobe801202015-12-03 10:19:21 +000060static unsigned char tb_fw_hash_buf[HASH_DER_LEN];
Soby Mathew0bdfef02017-11-07 17:03:57 +000061static unsigned char tb_fw_config_hash_buf[HASH_DER_LEN];
62static unsigned char hw_config_hash_buf[HASH_DER_LEN];
Juan Castillobe801202015-12-03 10:19:21 +000063static unsigned char scp_fw_hash_buf[HASH_DER_LEN];
Joel Huttone9919bb2019-02-20 11:56:46 +000064static unsigned char nt_world_bl_hash_buf[HASH_DER_LEN];
65
66#ifdef IMAGE_BL2
Juan Castillobe801202015-12-03 10:19:21 +000067static unsigned char soc_fw_hash_buf[HASH_DER_LEN];
68static unsigned char tos_fw_hash_buf[HASH_DER_LEN];
Summer Qin80726782017-04-20 16:28:39 +010069static unsigned char tos_fw_extra1_hash_buf[HASH_DER_LEN];
70static unsigned char tos_fw_extra2_hash_buf[HASH_DER_LEN];
Juan Castillobe801202015-12-03 10:19:21 +000071static unsigned char trusted_world_pk_buf[PK_DER_LEN];
72static unsigned char non_trusted_world_pk_buf[PK_DER_LEN];
73static unsigned char content_pk_buf[PK_DER_LEN];
Soby Mathew2bb78d32018-03-29 14:29:55 +010074static unsigned char soc_fw_config_hash_buf[HASH_DER_LEN];
75static unsigned char tos_fw_config_hash_buf[HASH_DER_LEN];
76static unsigned char nt_fw_config_hash_buf[HASH_DER_LEN];
Joel Huttone9919bb2019-02-20 11:56:46 +000077#endif
Juan Castillo9b265a82015-05-07 14:52:44 +010078
79/*
80 * Parameter type descriptors
81 */
Juan Castillobfb7fa62016-01-22 11:05:57 +000082static auth_param_type_desc_t trusted_nv_ctr = AUTH_PARAM_TYPE_DESC(
83 AUTH_PARAM_NV_CTR, TRUSTED_FW_NVCOUNTER_OID);
Juan Castillobfb7fa62016-01-22 11:05:57 +000084
Juan Castillo9b265a82015-05-07 14:52:44 +010085static auth_param_type_desc_t subject_pk = AUTH_PARAM_TYPE_DESC(
86 AUTH_PARAM_PUB_KEY, 0);
87static auth_param_type_desc_t sig = AUTH_PARAM_TYPE_DESC(
88 AUTH_PARAM_SIG, 0);
89static auth_param_type_desc_t sig_alg = AUTH_PARAM_TYPE_DESC(
90 AUTH_PARAM_SIG_ALG, 0);
91static auth_param_type_desc_t raw_data = AUTH_PARAM_TYPE_DESC(
92 AUTH_PARAM_RAW_DATA, 0);
93
Joel Huttone9919bb2019-02-20 11:56:46 +000094
95static auth_param_type_desc_t tb_fw_hash = AUTH_PARAM_TYPE_DESC(
96 AUTH_PARAM_HASH, TRUSTED_BOOT_FW_HASH_OID);
97static auth_param_type_desc_t tb_fw_config_hash = AUTH_PARAM_TYPE_DESC(
98 AUTH_PARAM_HASH, TRUSTED_BOOT_FW_CONFIG_HASH_OID);
99static auth_param_type_desc_t hw_config_hash = AUTH_PARAM_TYPE_DESC(
100 AUTH_PARAM_HASH, HW_CONFIG_HASH_OID);
101#ifdef IMAGE_BL1
102static auth_param_type_desc_t scp_bl2u_hash = AUTH_PARAM_TYPE_DESC(
103 AUTH_PARAM_HASH, SCP_FWU_CFG_HASH_OID);
104static auth_param_type_desc_t bl2u_hash = AUTH_PARAM_TYPE_DESC(
105 AUTH_PARAM_HASH, AP_FWU_CFG_HASH_OID);
106static auth_param_type_desc_t ns_bl2u_hash = AUTH_PARAM_TYPE_DESC(
107 AUTH_PARAM_HASH, FWU_HASH_OID);
108#endif /* IMAGE_BL1 */
109
110#ifdef IMAGE_BL2
111static auth_param_type_desc_t non_trusted_nv_ctr = AUTH_PARAM_TYPE_DESC(
112 AUTH_PARAM_NV_CTR, NON_TRUSTED_FW_NVCOUNTER_OID);
Juan Castillobe801202015-12-03 10:19:21 +0000113static auth_param_type_desc_t trusted_world_pk = AUTH_PARAM_TYPE_DESC(
114 AUTH_PARAM_PUB_KEY, TRUSTED_WORLD_PK_OID);
115static auth_param_type_desc_t non_trusted_world_pk = AUTH_PARAM_TYPE_DESC(
116 AUTH_PARAM_PUB_KEY, NON_TRUSTED_WORLD_PK_OID);
Juan Castillobe801202015-12-03 10:19:21 +0000117static auth_param_type_desc_t scp_fw_content_pk = AUTH_PARAM_TYPE_DESC(
118 AUTH_PARAM_PUB_KEY, SCP_FW_CONTENT_CERT_PK_OID);
119static auth_param_type_desc_t soc_fw_content_pk = AUTH_PARAM_TYPE_DESC(
120 AUTH_PARAM_PUB_KEY, SOC_FW_CONTENT_CERT_PK_OID);
121static auth_param_type_desc_t tos_fw_content_pk = AUTH_PARAM_TYPE_DESC(
122 AUTH_PARAM_PUB_KEY, TRUSTED_OS_FW_CONTENT_CERT_PK_OID);
123static auth_param_type_desc_t nt_fw_content_pk = AUTH_PARAM_TYPE_DESC(
124 AUTH_PARAM_PUB_KEY, NON_TRUSTED_FW_CONTENT_CERT_PK_OID);
Juan Castillobe801202015-12-03 10:19:21 +0000125static auth_param_type_desc_t scp_fw_hash = AUTH_PARAM_TYPE_DESC(
126 AUTH_PARAM_HASH, SCP_FW_HASH_OID);
127static auth_param_type_desc_t soc_fw_hash = AUTH_PARAM_TYPE_DESC(
128 AUTH_PARAM_HASH, SOC_AP_FW_HASH_OID);
Soby Mathew2bb78d32018-03-29 14:29:55 +0100129static auth_param_type_desc_t soc_fw_config_hash = AUTH_PARAM_TYPE_DESC(
130 AUTH_PARAM_HASH, SOC_FW_CONFIG_HASH_OID);
Juan Castillobe801202015-12-03 10:19:21 +0000131static auth_param_type_desc_t tos_fw_hash = AUTH_PARAM_TYPE_DESC(
132 AUTH_PARAM_HASH, TRUSTED_OS_FW_HASH_OID);
Soby Mathew2bb78d32018-03-29 14:29:55 +0100133static auth_param_type_desc_t tos_fw_config_hash = AUTH_PARAM_TYPE_DESC(
134 AUTH_PARAM_HASH, TRUSTED_OS_FW_CONFIG_HASH_OID);
Summer Qin80726782017-04-20 16:28:39 +0100135static auth_param_type_desc_t tos_fw_extra1_hash = AUTH_PARAM_TYPE_DESC(
136 AUTH_PARAM_HASH, TRUSTED_OS_FW_EXTRA1_HASH_OID);
137static auth_param_type_desc_t tos_fw_extra2_hash = AUTH_PARAM_TYPE_DESC(
138 AUTH_PARAM_HASH, TRUSTED_OS_FW_EXTRA2_HASH_OID);
Juan Castillobe801202015-12-03 10:19:21 +0000139static auth_param_type_desc_t nt_world_bl_hash = AUTH_PARAM_TYPE_DESC(
140 AUTH_PARAM_HASH, NON_TRUSTED_WORLD_BOOTLOADER_HASH_OID);
Soby Mathew2bb78d32018-03-29 14:29:55 +0100141static auth_param_type_desc_t nt_fw_config_hash = AUTH_PARAM_TYPE_DESC(
142 AUTH_PARAM_HASH, NON_TRUSTED_FW_CONFIG_HASH_OID);
Juan Castillo9b265a82015-05-07 14:52:44 +0100143
Joel Huttone9919bb2019-02-20 11:56:46 +0000144#endif /* IMAGE_BL2 */
145
146
Juan Castillo9b265a82015-05-07 14:52:44 +0100147 /*
148 * BL2
149 */
Joel Huttone9919bb2019-02-20 11:56:46 +0000150static const auth_img_desc_t trusted_boot_fw_cert = {
151 .img_id = TRUSTED_BOOT_FW_CERT_ID,
152 .img_type = IMG_CERT,
153 .parent = NULL,
Joel Hutton69931af2019-03-11 11:37:38 +0000154 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000155 [0] = {
156 .type = AUTH_METHOD_SIG,
157 .param.sig = {
158 .pk = &subject_pk,
159 .sig = &sig,
160 .alg = &sig_alg,
161 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100162 }
163 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000164 [1] = {
165 .type = AUTH_METHOD_NV_CTR,
166 .param.nv_ctr = {
167 .cert_nv_ctr = &trusted_nv_ctr,
168 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100169 }
170 }
171 },
Joel Hutton69931af2019-03-11 11:37:38 +0000172 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000173 [0] = {
174 .type_desc = &tb_fw_hash,
175 .data = {
176 .ptr = (void *)tb_fw_hash_buf,
177 .len = (unsigned int)HASH_DER_LEN
178 }
179 },
180 [1] = {
181 .type_desc = &tb_fw_config_hash,
182 .data = {
183 .ptr = (void *)tb_fw_config_hash_buf,
184 .len = (unsigned int)HASH_DER_LEN
185 }
186 },
187 [2] = {
188 .type_desc = &hw_config_hash,
189 .data = {
190 .ptr = (void *)hw_config_hash_buf,
191 .len = (unsigned int)HASH_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100192 }
193 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000194 }
195 };
196#ifdef IMAGE_BL1
197static const auth_img_desc_t bl2_image = {
198 .img_id = BL2_IMAGE_ID,
199 .img_type = IMG_RAW,
200 .parent = &trusted_boot_fw_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000201 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000202 [0] = {
203 .type = AUTH_METHOD_HASH,
204 .param.hash = {
205 .data = &raw_data,
206 .hash = &tb_fw_hash
Soby Mathew0bdfef02017-11-07 17:03:57 +0000207 }
208 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000209 }
210};
211#endif /* IMAGE_BL1 */
212/* HW Config */
213static const auth_img_desc_t hw_config = {
214 .img_id = HW_CONFIG_ID,
215 .img_type = IMG_RAW,
216 .parent = &trusted_boot_fw_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000217 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000218 [0] = {
219 .type = AUTH_METHOD_HASH,
220 .param.hash = {
221 .data = &raw_data,
222 .hash = &hw_config_hash
Soby Mathew0bdfef02017-11-07 17:03:57 +0000223 }
224 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000225 }
226};
227/* TB FW Config */
228#ifdef IMAGE_BL1
229static const auth_img_desc_t tb_fw_config = {
230 .img_id = TB_FW_CONFIG_ID,
231 .img_type = IMG_RAW,
232 .parent = &trusted_boot_fw_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000233 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000234 [0] = {
235 .type = AUTH_METHOD_HASH,
236 .param.hash = {
237 .data = &raw_data,
238 .hash = &tb_fw_config_hash
239 }
240 }
241 }
242};
243#endif /* IMAGE_BL1 */
244#ifdef IMAGE_BL2
245/*
246 * Trusted key certificate
247 */
248static const auth_img_desc_t trusted_key_cert = {
249 .img_id = TRUSTED_KEY_CERT_ID,
250 .img_type = IMG_CERT,
251 .parent = NULL,
Joel Hutton69931af2019-03-11 11:37:38 +0000252 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000253 [0] = {
254 .type = AUTH_METHOD_SIG,
255 .param.sig = {
256 .pk = &subject_pk,
257 .sig = &sig,
258 .alg = &sig_alg,
259 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100260 }
261 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000262 [1] = {
263 .type = AUTH_METHOD_NV_CTR,
264 .param.nv_ctr = {
265 .cert_nv_ctr = &trusted_nv_ctr,
266 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100267 }
268 }
269 },
Joel Hutton69931af2019-03-11 11:37:38 +0000270 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000271 [0] = {
272 .type_desc = &trusted_world_pk,
273 .data = {
274 .ptr = (void *)trusted_world_pk_buf,
275 .len = (unsigned int)PK_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100276 }
277 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000278 [1] = {
279 .type_desc = &non_trusted_world_pk,
280 .data = {
281 .ptr = (void *)non_trusted_world_pk_buf,
282 .len = (unsigned int)PK_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100283 }
284 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000285 }
286};
287/*
288 * SCP Firmware
289 */
290static const auth_img_desc_t scp_fw_key_cert = {
291 .img_id = SCP_FW_KEY_CERT_ID,
292 .img_type = IMG_CERT,
293 .parent = &trusted_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000294 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000295 [0] = {
296 .type = AUTH_METHOD_SIG,
297 .param.sig = {
298 .pk = &trusted_world_pk,
299 .sig = &sig,
300 .alg = &sig_alg,
301 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100302 }
303 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000304 [1] = {
305 .type = AUTH_METHOD_NV_CTR,
306 .param.nv_ctr = {
307 .cert_nv_ctr = &trusted_nv_ctr,
308 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100309 }
310 }
311 },
Joel Hutton69931af2019-03-11 11:37:38 +0000312 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000313 [0] = {
314 .type_desc = &scp_fw_content_pk,
315 .data = {
316 .ptr = (void *)content_pk_buf,
317 .len = (unsigned int)PK_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100318 }
319 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000320 }
321};
322static const auth_img_desc_t scp_fw_content_cert = {
323 .img_id = SCP_FW_CONTENT_CERT_ID,
324 .img_type = IMG_CERT,
325 .parent = &scp_fw_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000326 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000327 [0] = {
328 .type = AUTH_METHOD_SIG,
329 .param.sig = {
330 .pk = &scp_fw_content_pk,
331 .sig = &sig,
332 .alg = &sig_alg,
333 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100334 }
335 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000336 [1] = {
337 .type = AUTH_METHOD_NV_CTR,
338 .param.nv_ctr = {
339 .cert_nv_ctr = &trusted_nv_ctr,
340 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100341 }
342 }
343 },
Joel Hutton69931af2019-03-11 11:37:38 +0000344 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000345 [0] = {
346 .type_desc = &scp_fw_hash,
347 .data = {
348 .ptr = (void *)scp_fw_hash_buf,
349 .len = (unsigned int)HASH_DER_LEN
350 }
351 }
352 }
353};
354static const auth_img_desc_t scp_bl2_image = {
355 .img_id = SCP_BL2_IMAGE_ID,
356 .img_type = IMG_RAW,
357 .parent = &scp_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000358 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000359 [0] = {
360 .type = AUTH_METHOD_HASH,
361 .param.hash = {
362 .data = &raw_data,
363 .hash = &scp_fw_hash
364 }
365 }
366 }
367};
368/*
369 * SoC Firmware
370 */
371static const auth_img_desc_t soc_fw_key_cert = {
372 .img_id = SOC_FW_KEY_CERT_ID,
373 .img_type = IMG_CERT,
374 .parent = &trusted_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000375 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000376 [0] = {
377 .type = AUTH_METHOD_SIG,
378 .param.sig = {
379 .pk = &trusted_world_pk,
380 .sig = &sig,
381 .alg = &sig_alg,
382 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100383 }
384 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000385 [1] = {
386 .type = AUTH_METHOD_NV_CTR,
387 .param.nv_ctr = {
388 .cert_nv_ctr = &trusted_nv_ctr,
389 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100390 }
391 }
392 },
Joel Hutton69931af2019-03-11 11:37:38 +0000393 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000394 [0] = {
395 .type_desc = &soc_fw_content_pk,
396 .data = {
397 .ptr = (void *)content_pk_buf,
398 .len = (unsigned int)PK_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100399 }
400 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000401 }
402};
403static const auth_img_desc_t soc_fw_content_cert = {
404 .img_id = SOC_FW_CONTENT_CERT_ID,
405 .img_type = IMG_CERT,
406 .parent = &soc_fw_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000407 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000408 [0] = {
409 .type = AUTH_METHOD_SIG,
410 .param.sig = {
411 .pk = &soc_fw_content_pk,
412 .sig = &sig,
413 .alg = &sig_alg,
414 .data = &raw_data
415 }
416 },
417 [1] = {
418 .type = AUTH_METHOD_NV_CTR,
419 .param.nv_ctr = {
420 .cert_nv_ctr = &trusted_nv_ctr,
421 .plat_nv_ctr = &trusted_nv_ctr
Soby Mathew2bb78d32018-03-29 14:29:55 +0100422 }
423 }
424 },
Joel Hutton69931af2019-03-11 11:37:38 +0000425 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000426 [0] = {
427 .type_desc = &soc_fw_hash,
428 .data = {
429 .ptr = (void *)soc_fw_hash_buf,
430 .len = (unsigned int)HASH_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100431 }
432 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000433 [1] = {
434 .type_desc = &soc_fw_config_hash,
435 .data = {
436 .ptr = (void *)soc_fw_config_hash_buf,
437 .len = (unsigned int)HASH_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100438 }
439 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000440 }
441};
442static const auth_img_desc_t bl31_image = {
443 .img_id = BL31_IMAGE_ID,
444 .img_type = IMG_RAW,
445 .parent = &soc_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000446 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000447 [0] = {
448 .type = AUTH_METHOD_HASH,
449 .param.hash = {
450 .data = &raw_data,
451 .hash = &soc_fw_hash
452 }
453 }
454 }
455};
456/* SOC FW Config */
457static const auth_img_desc_t soc_fw_config = {
458 .img_id = SOC_FW_CONFIG_ID,
459 .img_type = IMG_RAW,
460 .parent = &soc_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000461 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000462 [0] = {
463 .type = AUTH_METHOD_HASH,
464 .param.hash = {
465 .data = &raw_data,
466 .hash = &soc_fw_config_hash
467 }
468 }
469 }
470};
471/*
472 * Trusted OS Firmware
473 */
474static const auth_img_desc_t trusted_os_fw_key_cert = {
475 .img_id = TRUSTED_OS_FW_KEY_CERT_ID,
476 .img_type = IMG_CERT,
477 .parent = &trusted_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000478 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000479 [0] = {
480 .type = AUTH_METHOD_SIG,
481 .param.sig = {
482 .pk = &trusted_world_pk,
483 .sig = &sig,
484 .alg = &sig_alg,
485 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100486 }
487 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000488 [1] = {
489 .type = AUTH_METHOD_NV_CTR,
490 .param.nv_ctr = {
491 .cert_nv_ctr = &trusted_nv_ctr,
492 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100493 }
494 }
495 },
Joel Hutton69931af2019-03-11 11:37:38 +0000496 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000497 [0] = {
498 .type_desc = &tos_fw_content_pk,
499 .data = {
500 .ptr = (void *)content_pk_buf,
501 .len = (unsigned int)PK_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100502 }
503 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000504 }
505};
506static const auth_img_desc_t trusted_os_fw_content_cert = {
507 .img_id = TRUSTED_OS_FW_CONTENT_CERT_ID,
508 .img_type = IMG_CERT,
509 .parent = &trusted_os_fw_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000510 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000511 [0] = {
512 .type = AUTH_METHOD_SIG,
513 .param.sig = {
514 .pk = &tos_fw_content_pk,
515 .sig = &sig,
516 .alg = &sig_alg,
517 .data = &raw_data
518 }
519 },
520 [1] = {
521 .type = AUTH_METHOD_NV_CTR,
522 .param.nv_ctr = {
523 .cert_nv_ctr = &trusted_nv_ctr,
524 .plat_nv_ctr = &trusted_nv_ctr
Summer Qin80726782017-04-20 16:28:39 +0100525 }
526 }
527 },
Joel Hutton69931af2019-03-11 11:37:38 +0000528 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000529 [0] = {
530 .type_desc = &tos_fw_hash,
531 .data = {
532 .ptr = (void *)tos_fw_hash_buf,
533 .len = (unsigned int)HASH_DER_LEN
534 }
535 },
536 [1] = {
537 .type_desc = &tos_fw_extra1_hash,
538 .data = {
539 .ptr = (void *)tos_fw_extra1_hash_buf,
540 .len = (unsigned int)HASH_DER_LEN
541 }
542 },
543 [2] = {
544 .type_desc = &tos_fw_extra2_hash,
545 .data = {
546 .ptr = (void *)tos_fw_extra2_hash_buf,
547 .len = (unsigned int)HASH_DER_LEN
548 }
549 },
550 [3] = {
551 .type_desc = &tos_fw_config_hash,
552 .data = {
553 .ptr = (void *)tos_fw_config_hash_buf,
554 .len = (unsigned int)HASH_DER_LEN
Summer Qin80726782017-04-20 16:28:39 +0100555 }
556 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000557 }
558};
559static const auth_img_desc_t bl32_image = {
560 .img_id = BL32_IMAGE_ID,
561 .img_type = IMG_RAW,
562 .parent = &trusted_os_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000563 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000564 [0] = {
565 .type = AUTH_METHOD_HASH,
566 .param.hash = {
567 .data = &raw_data,
568 .hash = &tos_fw_hash
Soby Mathew2bb78d32018-03-29 14:29:55 +0100569 }
570 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000571 }
572};
573static const auth_img_desc_t bl32_extra1_image = {
574 .img_id = BL32_EXTRA1_IMAGE_ID,
575 .img_type = IMG_RAW,
576 .parent = &trusted_os_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000577 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000578 [0] = {
579 .type = AUTH_METHOD_HASH,
580 .param.hash = {
581 .data = &raw_data,
582 .hash = &tos_fw_extra1_hash
583 }
584 }
585 }
586};
587static const auth_img_desc_t bl32_extra2_image = {
588 .img_id = BL32_EXTRA2_IMAGE_ID,
589 .img_type = IMG_RAW,
590 .parent = &trusted_os_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000591 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000592 [0] = {
593 .type = AUTH_METHOD_HASH,
594 .param.hash = {
595 .data = &raw_data,
596 .hash = &tos_fw_extra2_hash
597 }
598 }
599 }
600};
601/* TOS FW Config */
602static const auth_img_desc_t tos_fw_config = {
603 .img_id = TOS_FW_CONFIG_ID,
604 .img_type = IMG_RAW,
605 .parent = &trusted_os_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000606 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000607 [0] = {
608 .type = AUTH_METHOD_HASH,
609 .param.hash = {
610 .data = &raw_data,
611 .hash = &tos_fw_config_hash
612 }
613 }
614 }
615};
616/*
617 * Non-Trusted Firmware
618 */
619static const auth_img_desc_t non_trusted_fw_key_cert = {
620 .img_id = NON_TRUSTED_FW_KEY_CERT_ID,
621 .img_type = IMG_CERT,
622 .parent = &trusted_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000623 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000624 [0] = {
625 .type = AUTH_METHOD_SIG,
626 .param.sig = {
627 .pk = &non_trusted_world_pk,
628 .sig = &sig,
629 .alg = &sig_alg,
630 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100631 }
632 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000633 [1] = {
634 .type = AUTH_METHOD_NV_CTR,
635 .param.nv_ctr = {
636 .cert_nv_ctr = &non_trusted_nv_ctr,
637 .plat_nv_ctr = &non_trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100638 }
639 }
640 },
Joel Hutton69931af2019-03-11 11:37:38 +0000641 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000642 [0] = {
643 .type_desc = &nt_fw_content_pk,
644 .data = {
645 .ptr = (void *)content_pk_buf,
646 .len = (unsigned int)PK_DER_LEN
647 }
648 }
649 }
650};
651static const auth_img_desc_t non_trusted_fw_content_cert = {
652 .img_id = NON_TRUSTED_FW_CONTENT_CERT_ID,
653 .img_type = IMG_CERT,
654 .parent = &non_trusted_fw_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000655 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000656 [0] = {
657 .type = AUTH_METHOD_SIG,
658 .param.sig = {
659 .pk = &nt_fw_content_pk,
660 .sig = &sig,
661 .alg = &sig_alg,
662 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100663 }
664 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000665 [1] = {
666 .type = AUTH_METHOD_NV_CTR,
667 .param.nv_ctr = {
668 .cert_nv_ctr = &non_trusted_nv_ctr,
669 .plat_nv_ctr = &non_trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100670 }
671 }
672 },
Joel Hutton69931af2019-03-11 11:37:38 +0000673 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000674 [0] = {
675 .type_desc = &nt_world_bl_hash,
676 .data = {
677 .ptr = (void *)nt_world_bl_hash_buf,
678 .len = (unsigned int)HASH_DER_LEN
679 }
680 },
681 [1] = {
682 .type_desc = &nt_fw_config_hash,
683 .data = {
684 .ptr = (void *)nt_fw_config_hash_buf,
685 .len = (unsigned int)HASH_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100686 }
687 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000688 }
689};
690static const auth_img_desc_t bl33_image = {
691 .img_id = BL33_IMAGE_ID,
692 .img_type = IMG_RAW,
693 .parent = &non_trusted_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000694 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000695 [0] = {
696 .type = AUTH_METHOD_HASH,
697 .param.hash = {
698 .data = &raw_data,
699 .hash = &nt_world_bl_hash
Soby Mathew2bb78d32018-03-29 14:29:55 +0100700 }
701 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000702 }
703};
704/* NT FW Config */
705static const auth_img_desc_t nt_fw_config = {
706 .img_id = NT_FW_CONFIG_ID,
707 .img_type = IMG_RAW,
708 .parent = &non_trusted_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000709 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000710 [0] = {
711 .type = AUTH_METHOD_HASH,
712 .param.hash = {
713 .data = &raw_data,
714 .hash = &nt_fw_config_hash
715 }
716 }
717 }
718};
719#else /* IMAGE_BL2 */
720/*
721 * FWU auth descriptor.
722 */
723static const auth_img_desc_t fwu_cert = {
724 .img_id = FWU_CERT_ID,
725 .img_type = IMG_CERT,
726 .parent = NULL,
Joel Hutton69931af2019-03-11 11:37:38 +0000727 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000728 [0] = {
729 .type = AUTH_METHOD_SIG,
730 .param.sig = {
731 .pk = &subject_pk,
732 .sig = &sig,
733 .alg = &sig_alg,
734 .data = &raw_data
735 }
736 }
Soby Mathew2bb78d32018-03-29 14:29:55 +0100737 },
Joel Hutton69931af2019-03-11 11:37:38 +0000738 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000739 [0] = {
740 .type_desc = &scp_bl2u_hash,
741 .data = {
742 .ptr = (void *)scp_fw_hash_buf,
743 .len = (unsigned int)HASH_DER_LEN
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +0100744 }
745 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000746 [1] = {
747 .type_desc = &bl2u_hash,
748 .data = {
749 .ptr = (void *)tb_fw_hash_buf,
750 .len = (unsigned int)HASH_DER_LEN
751 }
752 },
753 [2] = {
754 .type_desc = &ns_bl2u_hash,
755 .data = {
756 .ptr = (void *)nt_world_bl_hash_buf,
757 .len = (unsigned int)HASH_DER_LEN
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +0100758 }
759 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000760 }
761};
762/*
763 * SCP_BL2U
764 */
765static const auth_img_desc_t scp_bl2u_image = {
766 .img_id = SCP_BL2U_IMAGE_ID,
767 .img_type = IMG_RAW,
768 .parent = &fwu_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000769 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000770 [0] = {
771 .type = AUTH_METHOD_HASH,
772 .param.hash = {
773 .data = &raw_data,
774 .hash = &scp_bl2u_hash
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +0100775 }
776 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000777 }
778};
779/*
780 * BL2U
781 */
782static const auth_img_desc_t bl2u_image = {
783 .img_id = BL2U_IMAGE_ID,
784 .img_type = IMG_RAW,
785 .parent = &fwu_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000786 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000787 [0] = {
788 .type = AUTH_METHOD_HASH,
789 .param.hash = {
790 .data = &raw_data,
791 .hash = &bl2u_hash
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +0100792 }
793 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000794 }
795};
796/*
797 * NS_BL2U
798 */
799static const auth_img_desc_t ns_bl2u_image = {
800 .img_id = NS_BL2U_IMAGE_ID,
801 .img_type = IMG_RAW,
802 .parent = &fwu_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000803 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000804 [0] = {
805 .type = AUTH_METHOD_HASH,
806 .param.hash = {
807 .data = &raw_data,
808 .hash = &ns_bl2u_hash
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +0100809 }
810 }
811 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000812 };
813#endif /* IMAGE_BL2 */
814/*
815 * TBBR Chain of trust definition
816 */
817
818#ifdef IMAGE_BL1
819static const auth_img_desc_t * const cot_desc[] = {
820 [TRUSTED_BOOT_FW_CERT_ID] = &trusted_boot_fw_cert,
821 [BL2_IMAGE_ID] = &bl2_image,
822 [HW_CONFIG_ID] = &hw_config,
823 [TB_FW_CONFIG_ID] = &tb_fw_config,
824 [FWU_CERT_ID] = &fwu_cert,
825 [SCP_BL2U_IMAGE_ID] = &scp_bl2u_image,
826 [BL2U_IMAGE_ID] = &bl2u_image,
827 [NS_BL2U_IMAGE_ID] = &ns_bl2u_image
828};
829#else /* IMAGE_BL2 */
830static const auth_img_desc_t * const cot_desc[] = {
831 [TRUSTED_BOOT_FW_CERT_ID] = &trusted_boot_fw_cert,
832 [HW_CONFIG_ID] = &hw_config,
833 [TRUSTED_KEY_CERT_ID] = &trusted_key_cert,
834 [SCP_FW_KEY_CERT_ID] = &scp_fw_key_cert,
835 [SCP_FW_CONTENT_CERT_ID] = &scp_fw_content_cert,
836 [SCP_BL2_IMAGE_ID] = &scp_bl2_image,
837 [SOC_FW_KEY_CERT_ID] = &soc_fw_key_cert,
838 [SOC_FW_CONTENT_CERT_ID] = &soc_fw_content_cert,
839 [BL31_IMAGE_ID] = &bl31_image,
840 [SOC_FW_CONFIG_ID] = &soc_fw_config,
841 [TRUSTED_OS_FW_KEY_CERT_ID] = &trusted_os_fw_key_cert,
842 [TRUSTED_OS_FW_CONTENT_CERT_ID] = &trusted_os_fw_content_cert,
843 [BL32_IMAGE_ID] = &bl32_image,
844 [BL32_EXTRA1_IMAGE_ID] = &bl32_extra1_image,
845 [BL32_EXTRA2_IMAGE_ID] = &bl32_extra2_image,
846 [TOS_FW_CONFIG_ID] = &tos_fw_config,
847 [NON_TRUSTED_FW_KEY_CERT_ID] = &non_trusted_fw_key_cert,
848 [NON_TRUSTED_FW_CONTENT_CERT_ID] = &non_trusted_fw_content_cert,
849 [BL33_IMAGE_ID] = &bl33_image,
850 [NT_FW_CONFIG_ID] = &nt_fw_config,
Juan Castillo9b265a82015-05-07 14:52:44 +0100851};
Joel Huttone9919bb2019-02-20 11:56:46 +0000852#endif
Juan Castillo9b265a82015-05-07 14:52:44 +0100853
854/* Register the CoT in the authentication module */
855REGISTER_COT(cot_desc);