blob: 2f1f451b15ab8df63ff5452b9bff98aebe2ed425 [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
Qixiang Xu1a1f2912017-11-09 13:56:29 +080044#define HASH_DER_LEN 83
Juan Castillo9b265a82015-05-07 14:52:44 +010045
46/*
47 * The platform must allocate buffers to store the authentication parameters
48 * extracted from the certificates. In this case, because of the way the CoT is
49 * established, we can reuse some of the buffers on different stages
50 */
Joel Huttone9919bb2019-02-20 11:56:46 +000051
Juan Castillobe801202015-12-03 10:19:21 +000052static unsigned char tb_fw_hash_buf[HASH_DER_LEN];
Soby Mathew0bdfef02017-11-07 17:03:57 +000053static unsigned char tb_fw_config_hash_buf[HASH_DER_LEN];
54static unsigned char hw_config_hash_buf[HASH_DER_LEN];
Juan Castillobe801202015-12-03 10:19:21 +000055static unsigned char scp_fw_hash_buf[HASH_DER_LEN];
Joel Huttone9919bb2019-02-20 11:56:46 +000056static unsigned char nt_world_bl_hash_buf[HASH_DER_LEN];
57
58#ifdef IMAGE_BL2
Juan Castillobe801202015-12-03 10:19:21 +000059static unsigned char soc_fw_hash_buf[HASH_DER_LEN];
60static unsigned char tos_fw_hash_buf[HASH_DER_LEN];
Summer Qin80726782017-04-20 16:28:39 +010061static unsigned char tos_fw_extra1_hash_buf[HASH_DER_LEN];
62static unsigned char tos_fw_extra2_hash_buf[HASH_DER_LEN];
Juan Castillobe801202015-12-03 10:19:21 +000063static unsigned char trusted_world_pk_buf[PK_DER_LEN];
64static unsigned char non_trusted_world_pk_buf[PK_DER_LEN];
65static unsigned char content_pk_buf[PK_DER_LEN];
Soby Mathew2bb78d32018-03-29 14:29:55 +010066static unsigned char soc_fw_config_hash_buf[HASH_DER_LEN];
67static unsigned char tos_fw_config_hash_buf[HASH_DER_LEN];
68static unsigned char nt_fw_config_hash_buf[HASH_DER_LEN];
Joel Huttone9919bb2019-02-20 11:56:46 +000069#endif
Juan Castillo9b265a82015-05-07 14:52:44 +010070
71/*
72 * Parameter type descriptors
73 */
Juan Castillobfb7fa62016-01-22 11:05:57 +000074static auth_param_type_desc_t trusted_nv_ctr = AUTH_PARAM_TYPE_DESC(
75 AUTH_PARAM_NV_CTR, TRUSTED_FW_NVCOUNTER_OID);
Juan Castillobfb7fa62016-01-22 11:05:57 +000076
Juan Castillo9b265a82015-05-07 14:52:44 +010077static auth_param_type_desc_t subject_pk = AUTH_PARAM_TYPE_DESC(
78 AUTH_PARAM_PUB_KEY, 0);
79static auth_param_type_desc_t sig = AUTH_PARAM_TYPE_DESC(
80 AUTH_PARAM_SIG, 0);
81static auth_param_type_desc_t sig_alg = AUTH_PARAM_TYPE_DESC(
82 AUTH_PARAM_SIG_ALG, 0);
83static auth_param_type_desc_t raw_data = AUTH_PARAM_TYPE_DESC(
84 AUTH_PARAM_RAW_DATA, 0);
85
Joel Huttone9919bb2019-02-20 11:56:46 +000086
87static auth_param_type_desc_t tb_fw_hash = AUTH_PARAM_TYPE_DESC(
88 AUTH_PARAM_HASH, TRUSTED_BOOT_FW_HASH_OID);
89static auth_param_type_desc_t tb_fw_config_hash = AUTH_PARAM_TYPE_DESC(
90 AUTH_PARAM_HASH, TRUSTED_BOOT_FW_CONFIG_HASH_OID);
91static auth_param_type_desc_t hw_config_hash = AUTH_PARAM_TYPE_DESC(
92 AUTH_PARAM_HASH, HW_CONFIG_HASH_OID);
93#ifdef IMAGE_BL1
94static auth_param_type_desc_t scp_bl2u_hash = AUTH_PARAM_TYPE_DESC(
95 AUTH_PARAM_HASH, SCP_FWU_CFG_HASH_OID);
96static auth_param_type_desc_t bl2u_hash = AUTH_PARAM_TYPE_DESC(
97 AUTH_PARAM_HASH, AP_FWU_CFG_HASH_OID);
98static auth_param_type_desc_t ns_bl2u_hash = AUTH_PARAM_TYPE_DESC(
99 AUTH_PARAM_HASH, FWU_HASH_OID);
100#endif /* IMAGE_BL1 */
101
102#ifdef IMAGE_BL2
103static auth_param_type_desc_t non_trusted_nv_ctr = AUTH_PARAM_TYPE_DESC(
104 AUTH_PARAM_NV_CTR, NON_TRUSTED_FW_NVCOUNTER_OID);
Juan Castillobe801202015-12-03 10:19:21 +0000105static auth_param_type_desc_t trusted_world_pk = AUTH_PARAM_TYPE_DESC(
106 AUTH_PARAM_PUB_KEY, TRUSTED_WORLD_PK_OID);
107static auth_param_type_desc_t non_trusted_world_pk = AUTH_PARAM_TYPE_DESC(
108 AUTH_PARAM_PUB_KEY, NON_TRUSTED_WORLD_PK_OID);
Juan Castillobe801202015-12-03 10:19:21 +0000109static auth_param_type_desc_t scp_fw_content_pk = AUTH_PARAM_TYPE_DESC(
110 AUTH_PARAM_PUB_KEY, SCP_FW_CONTENT_CERT_PK_OID);
111static auth_param_type_desc_t soc_fw_content_pk = AUTH_PARAM_TYPE_DESC(
112 AUTH_PARAM_PUB_KEY, SOC_FW_CONTENT_CERT_PK_OID);
113static auth_param_type_desc_t tos_fw_content_pk = AUTH_PARAM_TYPE_DESC(
114 AUTH_PARAM_PUB_KEY, TRUSTED_OS_FW_CONTENT_CERT_PK_OID);
115static auth_param_type_desc_t nt_fw_content_pk = AUTH_PARAM_TYPE_DESC(
116 AUTH_PARAM_PUB_KEY, NON_TRUSTED_FW_CONTENT_CERT_PK_OID);
Juan Castillobe801202015-12-03 10:19:21 +0000117static auth_param_type_desc_t scp_fw_hash = AUTH_PARAM_TYPE_DESC(
118 AUTH_PARAM_HASH, SCP_FW_HASH_OID);
119static auth_param_type_desc_t soc_fw_hash = AUTH_PARAM_TYPE_DESC(
120 AUTH_PARAM_HASH, SOC_AP_FW_HASH_OID);
Soby Mathew2bb78d32018-03-29 14:29:55 +0100121static auth_param_type_desc_t soc_fw_config_hash = AUTH_PARAM_TYPE_DESC(
122 AUTH_PARAM_HASH, SOC_FW_CONFIG_HASH_OID);
Juan Castillobe801202015-12-03 10:19:21 +0000123static auth_param_type_desc_t tos_fw_hash = AUTH_PARAM_TYPE_DESC(
124 AUTH_PARAM_HASH, TRUSTED_OS_FW_HASH_OID);
Soby Mathew2bb78d32018-03-29 14:29:55 +0100125static auth_param_type_desc_t tos_fw_config_hash = AUTH_PARAM_TYPE_DESC(
126 AUTH_PARAM_HASH, TRUSTED_OS_FW_CONFIG_HASH_OID);
Summer Qin80726782017-04-20 16:28:39 +0100127static auth_param_type_desc_t tos_fw_extra1_hash = AUTH_PARAM_TYPE_DESC(
128 AUTH_PARAM_HASH, TRUSTED_OS_FW_EXTRA1_HASH_OID);
129static auth_param_type_desc_t tos_fw_extra2_hash = AUTH_PARAM_TYPE_DESC(
130 AUTH_PARAM_HASH, TRUSTED_OS_FW_EXTRA2_HASH_OID);
Juan Castillobe801202015-12-03 10:19:21 +0000131static auth_param_type_desc_t nt_world_bl_hash = AUTH_PARAM_TYPE_DESC(
132 AUTH_PARAM_HASH, NON_TRUSTED_WORLD_BOOTLOADER_HASH_OID);
Soby Mathew2bb78d32018-03-29 14:29:55 +0100133static auth_param_type_desc_t nt_fw_config_hash = AUTH_PARAM_TYPE_DESC(
134 AUTH_PARAM_HASH, NON_TRUSTED_FW_CONFIG_HASH_OID);
Juan Castillo9b265a82015-05-07 14:52:44 +0100135
Joel Huttone9919bb2019-02-20 11:56:46 +0000136#endif /* IMAGE_BL2 */
137
138
Juan Castillo9b265a82015-05-07 14:52:44 +0100139 /*
140 * BL2
141 */
Joel Huttone9919bb2019-02-20 11:56:46 +0000142static const auth_img_desc_t trusted_boot_fw_cert = {
143 .img_id = TRUSTED_BOOT_FW_CERT_ID,
144 .img_type = IMG_CERT,
145 .parent = NULL,
Joel Hutton69931af2019-03-11 11:37:38 +0000146 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000147 [0] = {
148 .type = AUTH_METHOD_SIG,
149 .param.sig = {
150 .pk = &subject_pk,
151 .sig = &sig,
152 .alg = &sig_alg,
153 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100154 }
155 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000156 [1] = {
157 .type = AUTH_METHOD_NV_CTR,
158 .param.nv_ctr = {
159 .cert_nv_ctr = &trusted_nv_ctr,
160 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100161 }
162 }
163 },
Joel Hutton69931af2019-03-11 11:37:38 +0000164 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000165 [0] = {
166 .type_desc = &tb_fw_hash,
167 .data = {
168 .ptr = (void *)tb_fw_hash_buf,
169 .len = (unsigned int)HASH_DER_LEN
170 }
171 },
172 [1] = {
173 .type_desc = &tb_fw_config_hash,
174 .data = {
175 .ptr = (void *)tb_fw_config_hash_buf,
176 .len = (unsigned int)HASH_DER_LEN
177 }
178 },
179 [2] = {
180 .type_desc = &hw_config_hash,
181 .data = {
182 .ptr = (void *)hw_config_hash_buf,
183 .len = (unsigned int)HASH_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100184 }
185 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000186 }
187 };
188#ifdef IMAGE_BL1
189static const auth_img_desc_t bl2_image = {
190 .img_id = BL2_IMAGE_ID,
191 .img_type = IMG_RAW,
192 .parent = &trusted_boot_fw_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000193 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000194 [0] = {
195 .type = AUTH_METHOD_HASH,
196 .param.hash = {
197 .data = &raw_data,
198 .hash = &tb_fw_hash
Soby Mathew0bdfef02017-11-07 17:03:57 +0000199 }
200 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000201 }
202};
203#endif /* IMAGE_BL1 */
204/* HW Config */
205static const auth_img_desc_t hw_config = {
206 .img_id = HW_CONFIG_ID,
207 .img_type = IMG_RAW,
208 .parent = &trusted_boot_fw_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000209 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000210 [0] = {
211 .type = AUTH_METHOD_HASH,
212 .param.hash = {
213 .data = &raw_data,
214 .hash = &hw_config_hash
Soby Mathew0bdfef02017-11-07 17:03:57 +0000215 }
216 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000217 }
218};
219/* TB FW Config */
220#ifdef IMAGE_BL1
221static const auth_img_desc_t tb_fw_config = {
222 .img_id = TB_FW_CONFIG_ID,
223 .img_type = IMG_RAW,
224 .parent = &trusted_boot_fw_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000225 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000226 [0] = {
227 .type = AUTH_METHOD_HASH,
228 .param.hash = {
229 .data = &raw_data,
230 .hash = &tb_fw_config_hash
231 }
232 }
233 }
234};
235#endif /* IMAGE_BL1 */
236#ifdef IMAGE_BL2
237/*
238 * Trusted key certificate
239 */
240static const auth_img_desc_t trusted_key_cert = {
241 .img_id = TRUSTED_KEY_CERT_ID,
242 .img_type = IMG_CERT,
243 .parent = NULL,
Joel Hutton69931af2019-03-11 11:37:38 +0000244 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000245 [0] = {
246 .type = AUTH_METHOD_SIG,
247 .param.sig = {
248 .pk = &subject_pk,
249 .sig = &sig,
250 .alg = &sig_alg,
251 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100252 }
253 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000254 [1] = {
255 .type = AUTH_METHOD_NV_CTR,
256 .param.nv_ctr = {
257 .cert_nv_ctr = &trusted_nv_ctr,
258 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100259 }
260 }
261 },
Joel Hutton69931af2019-03-11 11:37:38 +0000262 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000263 [0] = {
264 .type_desc = &trusted_world_pk,
265 .data = {
266 .ptr = (void *)trusted_world_pk_buf,
267 .len = (unsigned int)PK_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100268 }
269 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000270 [1] = {
271 .type_desc = &non_trusted_world_pk,
272 .data = {
273 .ptr = (void *)non_trusted_world_pk_buf,
274 .len = (unsigned int)PK_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100275 }
276 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000277 }
278};
279/*
280 * SCP Firmware
281 */
282static const auth_img_desc_t scp_fw_key_cert = {
283 .img_id = SCP_FW_KEY_CERT_ID,
284 .img_type = IMG_CERT,
285 .parent = &trusted_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000286 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000287 [0] = {
288 .type = AUTH_METHOD_SIG,
289 .param.sig = {
290 .pk = &trusted_world_pk,
291 .sig = &sig,
292 .alg = &sig_alg,
293 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100294 }
295 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000296 [1] = {
297 .type = AUTH_METHOD_NV_CTR,
298 .param.nv_ctr = {
299 .cert_nv_ctr = &trusted_nv_ctr,
300 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100301 }
302 }
303 },
Joel Hutton69931af2019-03-11 11:37:38 +0000304 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000305 [0] = {
306 .type_desc = &scp_fw_content_pk,
307 .data = {
308 .ptr = (void *)content_pk_buf,
309 .len = (unsigned int)PK_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100310 }
311 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000312 }
313};
314static const auth_img_desc_t scp_fw_content_cert = {
315 .img_id = SCP_FW_CONTENT_CERT_ID,
316 .img_type = IMG_CERT,
317 .parent = &scp_fw_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000318 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000319 [0] = {
320 .type = AUTH_METHOD_SIG,
321 .param.sig = {
322 .pk = &scp_fw_content_pk,
323 .sig = &sig,
324 .alg = &sig_alg,
325 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100326 }
327 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000328 [1] = {
329 .type = AUTH_METHOD_NV_CTR,
330 .param.nv_ctr = {
331 .cert_nv_ctr = &trusted_nv_ctr,
332 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100333 }
334 }
335 },
Joel Hutton69931af2019-03-11 11:37:38 +0000336 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000337 [0] = {
338 .type_desc = &scp_fw_hash,
339 .data = {
340 .ptr = (void *)scp_fw_hash_buf,
341 .len = (unsigned int)HASH_DER_LEN
342 }
343 }
344 }
345};
346static const auth_img_desc_t scp_bl2_image = {
347 .img_id = SCP_BL2_IMAGE_ID,
348 .img_type = IMG_RAW,
349 .parent = &scp_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000350 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000351 [0] = {
352 .type = AUTH_METHOD_HASH,
353 .param.hash = {
354 .data = &raw_data,
355 .hash = &scp_fw_hash
356 }
357 }
358 }
359};
360/*
361 * SoC Firmware
362 */
363static const auth_img_desc_t soc_fw_key_cert = {
364 .img_id = SOC_FW_KEY_CERT_ID,
365 .img_type = IMG_CERT,
366 .parent = &trusted_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000367 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000368 [0] = {
369 .type = AUTH_METHOD_SIG,
370 .param.sig = {
371 .pk = &trusted_world_pk,
372 .sig = &sig,
373 .alg = &sig_alg,
374 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100375 }
376 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000377 [1] = {
378 .type = AUTH_METHOD_NV_CTR,
379 .param.nv_ctr = {
380 .cert_nv_ctr = &trusted_nv_ctr,
381 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100382 }
383 }
384 },
Joel Hutton69931af2019-03-11 11:37:38 +0000385 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000386 [0] = {
387 .type_desc = &soc_fw_content_pk,
388 .data = {
389 .ptr = (void *)content_pk_buf,
390 .len = (unsigned int)PK_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100391 }
392 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000393 }
394};
395static const auth_img_desc_t soc_fw_content_cert = {
396 .img_id = SOC_FW_CONTENT_CERT_ID,
397 .img_type = IMG_CERT,
398 .parent = &soc_fw_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000399 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000400 [0] = {
401 .type = AUTH_METHOD_SIG,
402 .param.sig = {
403 .pk = &soc_fw_content_pk,
404 .sig = &sig,
405 .alg = &sig_alg,
406 .data = &raw_data
407 }
408 },
409 [1] = {
410 .type = AUTH_METHOD_NV_CTR,
411 .param.nv_ctr = {
412 .cert_nv_ctr = &trusted_nv_ctr,
413 .plat_nv_ctr = &trusted_nv_ctr
Soby Mathew2bb78d32018-03-29 14:29:55 +0100414 }
415 }
416 },
Joel Hutton69931af2019-03-11 11:37:38 +0000417 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000418 [0] = {
419 .type_desc = &soc_fw_hash,
420 .data = {
421 .ptr = (void *)soc_fw_hash_buf,
422 .len = (unsigned int)HASH_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100423 }
424 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000425 [1] = {
426 .type_desc = &soc_fw_config_hash,
427 .data = {
428 .ptr = (void *)soc_fw_config_hash_buf,
429 .len = (unsigned int)HASH_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100430 }
431 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000432 }
433};
434static const auth_img_desc_t bl31_image = {
435 .img_id = BL31_IMAGE_ID,
436 .img_type = IMG_RAW,
437 .parent = &soc_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000438 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000439 [0] = {
440 .type = AUTH_METHOD_HASH,
441 .param.hash = {
442 .data = &raw_data,
443 .hash = &soc_fw_hash
444 }
445 }
446 }
447};
448/* SOC FW Config */
449static const auth_img_desc_t soc_fw_config = {
450 .img_id = SOC_FW_CONFIG_ID,
451 .img_type = IMG_RAW,
452 .parent = &soc_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000453 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000454 [0] = {
455 .type = AUTH_METHOD_HASH,
456 .param.hash = {
457 .data = &raw_data,
458 .hash = &soc_fw_config_hash
459 }
460 }
461 }
462};
463/*
464 * Trusted OS Firmware
465 */
466static const auth_img_desc_t trusted_os_fw_key_cert = {
467 .img_id = TRUSTED_OS_FW_KEY_CERT_ID,
468 .img_type = IMG_CERT,
469 .parent = &trusted_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000470 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000471 [0] = {
472 .type = AUTH_METHOD_SIG,
473 .param.sig = {
474 .pk = &trusted_world_pk,
475 .sig = &sig,
476 .alg = &sig_alg,
477 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100478 }
479 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000480 [1] = {
481 .type = AUTH_METHOD_NV_CTR,
482 .param.nv_ctr = {
483 .cert_nv_ctr = &trusted_nv_ctr,
484 .plat_nv_ctr = &trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100485 }
486 }
487 },
Joel Hutton69931af2019-03-11 11:37:38 +0000488 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000489 [0] = {
490 .type_desc = &tos_fw_content_pk,
491 .data = {
492 .ptr = (void *)content_pk_buf,
493 .len = (unsigned int)PK_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100494 }
495 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000496 }
497};
498static const auth_img_desc_t trusted_os_fw_content_cert = {
499 .img_id = TRUSTED_OS_FW_CONTENT_CERT_ID,
500 .img_type = IMG_CERT,
501 .parent = &trusted_os_fw_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000502 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000503 [0] = {
504 .type = AUTH_METHOD_SIG,
505 .param.sig = {
506 .pk = &tos_fw_content_pk,
507 .sig = &sig,
508 .alg = &sig_alg,
509 .data = &raw_data
510 }
511 },
512 [1] = {
513 .type = AUTH_METHOD_NV_CTR,
514 .param.nv_ctr = {
515 .cert_nv_ctr = &trusted_nv_ctr,
516 .plat_nv_ctr = &trusted_nv_ctr
Summer Qin80726782017-04-20 16:28:39 +0100517 }
518 }
519 },
Joel Hutton69931af2019-03-11 11:37:38 +0000520 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000521 [0] = {
522 .type_desc = &tos_fw_hash,
523 .data = {
524 .ptr = (void *)tos_fw_hash_buf,
525 .len = (unsigned int)HASH_DER_LEN
526 }
527 },
528 [1] = {
529 .type_desc = &tos_fw_extra1_hash,
530 .data = {
531 .ptr = (void *)tos_fw_extra1_hash_buf,
532 .len = (unsigned int)HASH_DER_LEN
533 }
534 },
535 [2] = {
536 .type_desc = &tos_fw_extra2_hash,
537 .data = {
538 .ptr = (void *)tos_fw_extra2_hash_buf,
539 .len = (unsigned int)HASH_DER_LEN
540 }
541 },
542 [3] = {
543 .type_desc = &tos_fw_config_hash,
544 .data = {
545 .ptr = (void *)tos_fw_config_hash_buf,
546 .len = (unsigned int)HASH_DER_LEN
Summer Qin80726782017-04-20 16:28:39 +0100547 }
548 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000549 }
550};
551static const auth_img_desc_t bl32_image = {
552 .img_id = BL32_IMAGE_ID,
553 .img_type = IMG_RAW,
554 .parent = &trusted_os_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000555 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000556 [0] = {
557 .type = AUTH_METHOD_HASH,
558 .param.hash = {
559 .data = &raw_data,
560 .hash = &tos_fw_hash
Soby Mathew2bb78d32018-03-29 14:29:55 +0100561 }
562 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000563 }
564};
565static const auth_img_desc_t bl32_extra1_image = {
566 .img_id = BL32_EXTRA1_IMAGE_ID,
567 .img_type = IMG_RAW,
568 .parent = &trusted_os_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000569 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000570 [0] = {
571 .type = AUTH_METHOD_HASH,
572 .param.hash = {
573 .data = &raw_data,
574 .hash = &tos_fw_extra1_hash
575 }
576 }
577 }
578};
579static const auth_img_desc_t bl32_extra2_image = {
580 .img_id = BL32_EXTRA2_IMAGE_ID,
581 .img_type = IMG_RAW,
582 .parent = &trusted_os_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000583 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000584 [0] = {
585 .type = AUTH_METHOD_HASH,
586 .param.hash = {
587 .data = &raw_data,
588 .hash = &tos_fw_extra2_hash
589 }
590 }
591 }
592};
593/* TOS FW Config */
594static const auth_img_desc_t tos_fw_config = {
595 .img_id = TOS_FW_CONFIG_ID,
596 .img_type = IMG_RAW,
597 .parent = &trusted_os_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000598 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000599 [0] = {
600 .type = AUTH_METHOD_HASH,
601 .param.hash = {
602 .data = &raw_data,
603 .hash = &tos_fw_config_hash
604 }
605 }
606 }
607};
608/*
609 * Non-Trusted Firmware
610 */
611static const auth_img_desc_t non_trusted_fw_key_cert = {
612 .img_id = NON_TRUSTED_FW_KEY_CERT_ID,
613 .img_type = IMG_CERT,
614 .parent = &trusted_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000615 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000616 [0] = {
617 .type = AUTH_METHOD_SIG,
618 .param.sig = {
619 .pk = &non_trusted_world_pk,
620 .sig = &sig,
621 .alg = &sig_alg,
622 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100623 }
624 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000625 [1] = {
626 .type = AUTH_METHOD_NV_CTR,
627 .param.nv_ctr = {
628 .cert_nv_ctr = &non_trusted_nv_ctr,
629 .plat_nv_ctr = &non_trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100630 }
631 }
632 },
Joel Hutton69931af2019-03-11 11:37:38 +0000633 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000634 [0] = {
635 .type_desc = &nt_fw_content_pk,
636 .data = {
637 .ptr = (void *)content_pk_buf,
638 .len = (unsigned int)PK_DER_LEN
639 }
640 }
641 }
642};
643static const auth_img_desc_t non_trusted_fw_content_cert = {
644 .img_id = NON_TRUSTED_FW_CONTENT_CERT_ID,
645 .img_type = IMG_CERT,
646 .parent = &non_trusted_fw_key_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000647 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000648 [0] = {
649 .type = AUTH_METHOD_SIG,
650 .param.sig = {
651 .pk = &nt_fw_content_pk,
652 .sig = &sig,
653 .alg = &sig_alg,
654 .data = &raw_data
Juan Castillo9b265a82015-05-07 14:52:44 +0100655 }
656 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000657 [1] = {
658 .type = AUTH_METHOD_NV_CTR,
659 .param.nv_ctr = {
660 .cert_nv_ctr = &non_trusted_nv_ctr,
661 .plat_nv_ctr = &non_trusted_nv_ctr
Juan Castillo9b265a82015-05-07 14:52:44 +0100662 }
663 }
664 },
Joel Hutton69931af2019-03-11 11:37:38 +0000665 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000666 [0] = {
667 .type_desc = &nt_world_bl_hash,
668 .data = {
669 .ptr = (void *)nt_world_bl_hash_buf,
670 .len = (unsigned int)HASH_DER_LEN
671 }
672 },
673 [1] = {
674 .type_desc = &nt_fw_config_hash,
675 .data = {
676 .ptr = (void *)nt_fw_config_hash_buf,
677 .len = (unsigned int)HASH_DER_LEN
Juan Castillo9b265a82015-05-07 14:52:44 +0100678 }
679 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000680 }
681};
682static const auth_img_desc_t bl33_image = {
683 .img_id = BL33_IMAGE_ID,
684 .img_type = IMG_RAW,
685 .parent = &non_trusted_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000686 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000687 [0] = {
688 .type = AUTH_METHOD_HASH,
689 .param.hash = {
690 .data = &raw_data,
691 .hash = &nt_world_bl_hash
Soby Mathew2bb78d32018-03-29 14:29:55 +0100692 }
693 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000694 }
695};
696/* NT FW Config */
697static const auth_img_desc_t nt_fw_config = {
698 .img_id = NT_FW_CONFIG_ID,
699 .img_type = IMG_RAW,
700 .parent = &non_trusted_fw_content_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000701 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000702 [0] = {
703 .type = AUTH_METHOD_HASH,
704 .param.hash = {
705 .data = &raw_data,
706 .hash = &nt_fw_config_hash
707 }
708 }
709 }
710};
711#else /* IMAGE_BL2 */
712/*
713 * FWU auth descriptor.
714 */
715static const auth_img_desc_t fwu_cert = {
716 .img_id = FWU_CERT_ID,
717 .img_type = IMG_CERT,
718 .parent = NULL,
Joel Hutton69931af2019-03-11 11:37:38 +0000719 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000720 [0] = {
721 .type = AUTH_METHOD_SIG,
722 .param.sig = {
723 .pk = &subject_pk,
724 .sig = &sig,
725 .alg = &sig_alg,
726 .data = &raw_data
727 }
728 }
Soby Mathew2bb78d32018-03-29 14:29:55 +0100729 },
Joel Hutton69931af2019-03-11 11:37:38 +0000730 .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000731 [0] = {
732 .type_desc = &scp_bl2u_hash,
733 .data = {
734 .ptr = (void *)scp_fw_hash_buf,
735 .len = (unsigned int)HASH_DER_LEN
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +0100736 }
737 },
Joel Huttone9919bb2019-02-20 11:56:46 +0000738 [1] = {
739 .type_desc = &bl2u_hash,
740 .data = {
741 .ptr = (void *)tb_fw_hash_buf,
742 .len = (unsigned int)HASH_DER_LEN
743 }
744 },
745 [2] = {
746 .type_desc = &ns_bl2u_hash,
747 .data = {
748 .ptr = (void *)nt_world_bl_hash_buf,
749 .len = (unsigned int)HASH_DER_LEN
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +0100750 }
751 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000752 }
753};
754/*
755 * SCP_BL2U
756 */
757static const auth_img_desc_t scp_bl2u_image = {
758 .img_id = SCP_BL2U_IMAGE_ID,
759 .img_type = IMG_RAW,
760 .parent = &fwu_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000761 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000762 [0] = {
763 .type = AUTH_METHOD_HASH,
764 .param.hash = {
765 .data = &raw_data,
766 .hash = &scp_bl2u_hash
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +0100767 }
768 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000769 }
770};
771/*
772 * BL2U
773 */
774static const auth_img_desc_t bl2u_image = {
775 .img_id = BL2U_IMAGE_ID,
776 .img_type = IMG_RAW,
777 .parent = &fwu_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000778 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000779 [0] = {
780 .type = AUTH_METHOD_HASH,
781 .param.hash = {
782 .data = &raw_data,
783 .hash = &bl2u_hash
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +0100784 }
785 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000786 }
787};
788/*
789 * NS_BL2U
790 */
791static const auth_img_desc_t ns_bl2u_image = {
792 .img_id = NS_BL2U_IMAGE_ID,
793 .img_type = IMG_RAW,
794 .parent = &fwu_cert,
Joel Hutton69931af2019-03-11 11:37:38 +0000795 .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) {
Joel Huttone9919bb2019-02-20 11:56:46 +0000796 [0] = {
797 .type = AUTH_METHOD_HASH,
798 .param.hash = {
799 .data = &raw_data,
800 .hash = &ns_bl2u_hash
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +0100801 }
802 }
803 }
Joel Huttone9919bb2019-02-20 11:56:46 +0000804 };
805#endif /* IMAGE_BL2 */
806/*
807 * TBBR Chain of trust definition
808 */
809
810#ifdef IMAGE_BL1
811static const auth_img_desc_t * const cot_desc[] = {
812 [TRUSTED_BOOT_FW_CERT_ID] = &trusted_boot_fw_cert,
813 [BL2_IMAGE_ID] = &bl2_image,
814 [HW_CONFIG_ID] = &hw_config,
815 [TB_FW_CONFIG_ID] = &tb_fw_config,
816 [FWU_CERT_ID] = &fwu_cert,
817 [SCP_BL2U_IMAGE_ID] = &scp_bl2u_image,
818 [BL2U_IMAGE_ID] = &bl2u_image,
819 [NS_BL2U_IMAGE_ID] = &ns_bl2u_image
820};
821#else /* IMAGE_BL2 */
822static const auth_img_desc_t * const cot_desc[] = {
823 [TRUSTED_BOOT_FW_CERT_ID] = &trusted_boot_fw_cert,
824 [HW_CONFIG_ID] = &hw_config,
825 [TRUSTED_KEY_CERT_ID] = &trusted_key_cert,
826 [SCP_FW_KEY_CERT_ID] = &scp_fw_key_cert,
827 [SCP_FW_CONTENT_CERT_ID] = &scp_fw_content_cert,
828 [SCP_BL2_IMAGE_ID] = &scp_bl2_image,
829 [SOC_FW_KEY_CERT_ID] = &soc_fw_key_cert,
830 [SOC_FW_CONTENT_CERT_ID] = &soc_fw_content_cert,
831 [BL31_IMAGE_ID] = &bl31_image,
832 [SOC_FW_CONFIG_ID] = &soc_fw_config,
833 [TRUSTED_OS_FW_KEY_CERT_ID] = &trusted_os_fw_key_cert,
834 [TRUSTED_OS_FW_CONTENT_CERT_ID] = &trusted_os_fw_content_cert,
835 [BL32_IMAGE_ID] = &bl32_image,
836 [BL32_EXTRA1_IMAGE_ID] = &bl32_extra1_image,
837 [BL32_EXTRA2_IMAGE_ID] = &bl32_extra2_image,
838 [TOS_FW_CONFIG_ID] = &tos_fw_config,
839 [NON_TRUSTED_FW_KEY_CERT_ID] = &non_trusted_fw_key_cert,
840 [NON_TRUSTED_FW_CONTENT_CERT_ID] = &non_trusted_fw_content_cert,
841 [BL33_IMAGE_ID] = &bl33_image,
842 [NT_FW_CONFIG_ID] = &nt_fw_config,
Juan Castillo9b265a82015-05-07 14:52:44 +0100843};
Joel Huttone9919bb2019-02-20 11:56:46 +0000844#endif
Juan Castillo9b265a82015-05-07 14:52:44 +0100845
846/* Register the CoT in the authentication module */
847REGISTER_COT(cot_desc);