tbbr_cot.c 17.4 KB
Newer Older
Juan Castillo's avatar
Juan Castillo committed
1
/*
2
 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Juan Castillo's avatar
Juan Castillo committed
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo's avatar
Juan Castillo committed
5
6
7
8
 */

#include <auth_mod.h>
#include <platform_def.h>
Isla Mitchell's avatar
Isla Mitchell committed
9
10
#include <stddef.h>

11
12
13
#if USE_TBBR_DEFS
#include <tbbr_oid.h>
#else
Juan Castillo's avatar
Juan Castillo committed
14
#include <platform_oid.h>
15
#endif
Isla Mitchell's avatar
Isla Mitchell committed
16

Juan Castillo's avatar
Juan Castillo committed
17
18
19
20
21

/*
 * Maximum key and hash sizes (in DER format)
 */
#define PK_DER_LEN			294
22
#define HASH_DER_LEN			83
Juan Castillo's avatar
Juan Castillo committed
23
24
25
26
27
28

/*
 * The platform must allocate buffers to store the authentication parameters
 * extracted from the certificates. In this case, because of the way the CoT is
 * established, we can reuse some of the buffers on different stages
 */
29
static unsigned char tb_fw_hash_buf[HASH_DER_LEN];
30
31
static unsigned char tb_fw_config_hash_buf[HASH_DER_LEN];
static unsigned char hw_config_hash_buf[HASH_DER_LEN];
32
33
34
static unsigned char scp_fw_hash_buf[HASH_DER_LEN];
static unsigned char soc_fw_hash_buf[HASH_DER_LEN];
static unsigned char tos_fw_hash_buf[HASH_DER_LEN];
35
36
static unsigned char tos_fw_extra1_hash_buf[HASH_DER_LEN];
static unsigned char tos_fw_extra2_hash_buf[HASH_DER_LEN];
37
38
39
40
static unsigned char nt_world_bl_hash_buf[HASH_DER_LEN];
static unsigned char trusted_world_pk_buf[PK_DER_LEN];
static unsigned char non_trusted_world_pk_buf[PK_DER_LEN];
static unsigned char content_pk_buf[PK_DER_LEN];
41
42
43
static unsigned char soc_fw_config_hash_buf[HASH_DER_LEN];
static unsigned char tos_fw_config_hash_buf[HASH_DER_LEN];
static unsigned char nt_fw_config_hash_buf[HASH_DER_LEN];
Juan Castillo's avatar
Juan Castillo committed
44
45
46
47

/*
 * Parameter type descriptors
 */
48
49
50
51
52
static auth_param_type_desc_t trusted_nv_ctr = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_NV_CTR, TRUSTED_FW_NVCOUNTER_OID);
static auth_param_type_desc_t non_trusted_nv_ctr = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_NV_CTR, NON_TRUSTED_FW_NVCOUNTER_OID);

Juan Castillo's avatar
Juan Castillo committed
53
54
55
56
57
58
59
60
61
static auth_param_type_desc_t subject_pk = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_PUB_KEY, 0);
static auth_param_type_desc_t sig = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_SIG, 0);
static auth_param_type_desc_t sig_alg = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_SIG_ALG, 0);
static auth_param_type_desc_t raw_data = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_RAW_DATA, 0);

62
63
64
65
static auth_param_type_desc_t trusted_world_pk = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_PUB_KEY, TRUSTED_WORLD_PK_OID);
static auth_param_type_desc_t non_trusted_world_pk = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_PUB_KEY, NON_TRUSTED_WORLD_PK_OID);
Juan Castillo's avatar
Juan Castillo committed
66

67
68
69
70
71
72
73
74
static auth_param_type_desc_t scp_fw_content_pk = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_PUB_KEY, SCP_FW_CONTENT_CERT_PK_OID);
static auth_param_type_desc_t soc_fw_content_pk = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_PUB_KEY, SOC_FW_CONTENT_CERT_PK_OID);
static auth_param_type_desc_t tos_fw_content_pk = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_PUB_KEY, TRUSTED_OS_FW_CONTENT_CERT_PK_OID);
static auth_param_type_desc_t nt_fw_content_pk = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_PUB_KEY, NON_TRUSTED_FW_CONTENT_CERT_PK_OID);
Juan Castillo's avatar
Juan Castillo committed
75

76
77
static auth_param_type_desc_t tb_fw_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, TRUSTED_BOOT_FW_HASH_OID);
78
79
80
81
static auth_param_type_desc_t tb_fw_config_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, TRUSTED_BOOT_FW_CONFIG_HASH_OID);
static auth_param_type_desc_t hw_config_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, HW_CONFIG_HASH_OID);
82
83
84
85
static auth_param_type_desc_t scp_fw_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, SCP_FW_HASH_OID);
static auth_param_type_desc_t soc_fw_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, SOC_AP_FW_HASH_OID);
86
87
static auth_param_type_desc_t soc_fw_config_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, SOC_FW_CONFIG_HASH_OID);
88
89
static auth_param_type_desc_t tos_fw_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, TRUSTED_OS_FW_HASH_OID);
90
91
static auth_param_type_desc_t tos_fw_config_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, TRUSTED_OS_FW_CONFIG_HASH_OID);
92
93
94
95
static auth_param_type_desc_t tos_fw_extra1_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, TRUSTED_OS_FW_EXTRA1_HASH_OID);
static auth_param_type_desc_t tos_fw_extra2_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, TRUSTED_OS_FW_EXTRA2_HASH_OID);
96
97
static auth_param_type_desc_t nt_world_bl_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, NON_TRUSTED_WORLD_BOOTLOADER_HASH_OID);
98
99
static auth_param_type_desc_t nt_fw_config_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, NON_TRUSTED_FW_CONFIG_HASH_OID);
100
static auth_param_type_desc_t scp_bl2u_hash = AUTH_PARAM_TYPE_DESC(
101
		AUTH_PARAM_HASH, SCP_FWU_CFG_HASH_OID);
102
static auth_param_type_desc_t bl2u_hash = AUTH_PARAM_TYPE_DESC(
103
		AUTH_PARAM_HASH, AP_FWU_CFG_HASH_OID);
104
static auth_param_type_desc_t ns_bl2u_hash = AUTH_PARAM_TYPE_DESC(
105
		AUTH_PARAM_HASH, FWU_HASH_OID);
Juan Castillo's avatar
Juan Castillo committed
106
107
108
109
110
111
112
113

/*
 * TBBR Chain of trust definition
 */
static const auth_img_desc_t cot_desc[] = {
	/*
	 * BL2
	 */
114
115
	[TRUSTED_BOOT_FW_CERT_ID] = {
		.img_id = TRUSTED_BOOT_FW_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
116
117
118
119
120
121
122
123
124
125
126
		.img_type = IMG_CERT,
		.parent = NULL,
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
					.pk = &subject_pk,
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
127
128
129
130
131
132
133
			},
			[1] = {
				.type = AUTH_METHOD_NV_CTR,
				.param.nv_ctr = {
					.cert_nv_ctr = &trusted_nv_ctr,
					.plat_nv_ctr = &trusted_nv_ctr
				}
Juan Castillo's avatar
Juan Castillo committed
134
135
136
137
			}
		},
		.authenticated_data = {
			[0] = {
138
				.type_desc = &tb_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
139
				.data = {
140
					.ptr = (void *)tb_fw_hash_buf,
Juan Castillo's avatar
Juan Castillo committed
141
142
					.len = (unsigned int)HASH_DER_LEN
				}
143
144
145
146
147
148
149
150
151
152
153
154
155
156
			},
			[1] = {
				.type_desc = &tb_fw_config_hash,
				.data = {
					.ptr = (void *)tb_fw_config_hash_buf,
					.len = (unsigned int)HASH_DER_LEN
				}
			},
			[2] = {
				.type_desc = &hw_config_hash,
				.data = {
					.ptr = (void *)hw_config_hash_buf,
					.len = (unsigned int)HASH_DER_LEN
				}
Juan Castillo's avatar
Juan Castillo committed
157
158
159
160
161
162
			}
		}
	},
	[BL2_IMAGE_ID] = {
		.img_id = BL2_IMAGE_ID,
		.img_type = IMG_RAW,
163
		.parent = &cot_desc[TRUSTED_BOOT_FW_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
164
165
166
167
168
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
169
					.hash = &tb_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
170
171
172
173
				}
			}
		}
	},
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
	/* HW Config */
	[HW_CONFIG_ID] = {
		.img_id = HW_CONFIG_ID,
		.img_type = IMG_RAW,
		.parent = &cot_desc[TRUSTED_BOOT_FW_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
					.hash = &hw_config_hash,
				}
			}
		}
	},
	/* TB FW Config */
	[TB_FW_CONFIG_ID] = {
		.img_id = TB_FW_CONFIG_ID,
		.img_type = IMG_RAW,
		.parent = &cot_desc[TRUSTED_BOOT_FW_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
					.hash = &tb_fw_config_hash,
				}
			}
		}
	},
Juan Castillo's avatar
Juan Castillo committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
	/*
	 * Trusted key certificate
	 */
	[TRUSTED_KEY_CERT_ID] = {
		.img_id = TRUSTED_KEY_CERT_ID,
		.img_type = IMG_CERT,
		.parent = NULL,
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
					.pk = &subject_pk,
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
220
221
222
223
224
225
226
			},
			[1] = {
				.type = AUTH_METHOD_NV_CTR,
				.param.nv_ctr = {
					.cert_nv_ctr = &trusted_nv_ctr,
					.plat_nv_ctr = &trusted_nv_ctr
				}
Juan Castillo's avatar
Juan Castillo committed
227
228
229
230
			}
		},
		.authenticated_data = {
			[0] = {
231
				.type_desc = &trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
232
				.data = {
233
					.ptr = (void *)trusted_world_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
234
235
236
237
					.len = (unsigned int)PK_DER_LEN
				}
			},
			[1] = {
238
				.type_desc = &non_trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
239
				.data = {
240
					.ptr = (void *)non_trusted_world_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
241
242
243
244
245
246
					.len = (unsigned int)PK_DER_LEN
				}
			}
		}
	},
	/*
247
	 * SCP Firmware
Juan Castillo's avatar
Juan Castillo committed
248
	 */
249
250
	[SCP_FW_KEY_CERT_ID] = {
		.img_id = SCP_FW_KEY_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
251
252
253
254
255
256
		.img_type = IMG_CERT,
		.parent = &cot_desc[TRUSTED_KEY_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
257
					.pk = &trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
258
259
260
261
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
262
263
264
265
266
267
268
			},
			[1] = {
				.type = AUTH_METHOD_NV_CTR,
				.param.nv_ctr = {
					.cert_nv_ctr = &trusted_nv_ctr,
					.plat_nv_ctr = &trusted_nv_ctr
				}
Juan Castillo's avatar
Juan Castillo committed
269
270
271
272
			}
		},
		.authenticated_data = {
			[0] = {
273
				.type_desc = &scp_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
274
				.data = {
275
					.ptr = (void *)content_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
276
277
278
279
280
					.len = (unsigned int)PK_DER_LEN
				}
			}
		}
	},
281
282
	[SCP_FW_CONTENT_CERT_ID] = {
		.img_id = SCP_FW_CONTENT_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
283
		.img_type = IMG_CERT,
284
		.parent = &cot_desc[SCP_FW_KEY_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
285
286
287
288
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
289
					.pk = &scp_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
290
291
292
293
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
294
295
296
297
298
299
300
			},
			[1] = {
				.type = AUTH_METHOD_NV_CTR,
				.param.nv_ctr = {
					.cert_nv_ctr = &trusted_nv_ctr,
					.plat_nv_ctr = &trusted_nv_ctr
				}
Juan Castillo's avatar
Juan Castillo committed
301
302
303
304
			}
		},
		.authenticated_data = {
			[0] = {
305
				.type_desc = &scp_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
306
				.data = {
307
					.ptr = (void *)scp_fw_hash_buf,
Juan Castillo's avatar
Juan Castillo committed
308
309
310
311
312
					.len = (unsigned int)HASH_DER_LEN
				}
			}
		}
	},
313
314
	[SCP_BL2_IMAGE_ID] = {
		.img_id = SCP_BL2_IMAGE_ID,
Juan Castillo's avatar
Juan Castillo committed
315
		.img_type = IMG_RAW,
316
		.parent = &cot_desc[SCP_FW_CONTENT_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
317
318
319
320
321
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
322
					.hash = &scp_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
323
324
325
326
327
				}
			}
		}
	},
	/*
328
	 * SoC Firmware
Juan Castillo's avatar
Juan Castillo committed
329
	 */
330
331
	[SOC_FW_KEY_CERT_ID] = {
		.img_id = SOC_FW_KEY_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
332
333
334
335
336
337
		.img_type = IMG_CERT,
		.parent = &cot_desc[TRUSTED_KEY_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
338
					.pk = &trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
339
340
341
342
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
343
344
345
346
347
348
349
			},
			[1] = {
				.type = AUTH_METHOD_NV_CTR,
				.param.nv_ctr = {
					.cert_nv_ctr = &trusted_nv_ctr,
					.plat_nv_ctr = &trusted_nv_ctr
				}
Juan Castillo's avatar
Juan Castillo committed
350
351
352
353
			}
		},
		.authenticated_data = {
			[0] = {
354
				.type_desc = &soc_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
355
				.data = {
356
					.ptr = (void *)content_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
357
358
359
360
361
					.len = (unsigned int)PK_DER_LEN
				}
			}
		}
	},
362
363
	[SOC_FW_CONTENT_CERT_ID] = {
		.img_id = SOC_FW_CONTENT_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
364
		.img_type = IMG_CERT,
365
		.parent = &cot_desc[SOC_FW_KEY_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
366
367
368
369
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
370
					.pk = &soc_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
371
372
373
374
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
375
376
377
378
379
380
381
			},
			[1] = {
				.type = AUTH_METHOD_NV_CTR,
				.param.nv_ctr = {
					.cert_nv_ctr = &trusted_nv_ctr,
					.plat_nv_ctr = &trusted_nv_ctr
				}
Juan Castillo's avatar
Juan Castillo committed
382
383
384
385
			}
		},
		.authenticated_data = {
			[0] = {
386
				.type_desc = &soc_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
387
				.data = {
388
					.ptr = (void *)soc_fw_hash_buf,
Juan Castillo's avatar
Juan Castillo committed
389
390
					.len = (unsigned int)HASH_DER_LEN
				}
391
392
393
394
395
396
397
			},
			[1] = {
				.type_desc = &soc_fw_config_hash,
				.data = {
					.ptr = (void *)soc_fw_config_hash_buf,
					.len = (unsigned int)HASH_DER_LEN
				}
Juan Castillo's avatar
Juan Castillo committed
398
399
400
401
402
403
			}
		}
	},
	[BL31_IMAGE_ID] = {
		.img_id = BL31_IMAGE_ID,
		.img_type = IMG_RAW,
404
		.parent = &cot_desc[SOC_FW_CONTENT_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
405
406
407
408
409
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
410
					.hash = &soc_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
411
412
413
414
				}
			}
		}
	},
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
	/* SOC FW Config */
	[SOC_FW_CONFIG_ID] = {
		.img_id = SOC_FW_CONFIG_ID,
		.img_type = IMG_RAW,
		.parent = &cot_desc[SOC_FW_CONTENT_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
					.hash = &soc_fw_config_hash,
				}
			}
		}
	},
Juan Castillo's avatar
Juan Castillo committed
430
	/*
431
	 * Trusted OS Firmware
Juan Castillo's avatar
Juan Castillo committed
432
	 */
433
434
	[TRUSTED_OS_FW_KEY_CERT_ID] = {
		.img_id = TRUSTED_OS_FW_KEY_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
435
436
437
438
439
440
		.img_type = IMG_CERT,
		.parent = &cot_desc[TRUSTED_KEY_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
441
					.pk = &trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
442
443
444
445
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
446
447
448
449
450
451
452
			},
			[1] = {
				.type = AUTH_METHOD_NV_CTR,
				.param.nv_ctr = {
					.cert_nv_ctr = &trusted_nv_ctr,
					.plat_nv_ctr = &trusted_nv_ctr
				}
Juan Castillo's avatar
Juan Castillo committed
453
454
455
456
			}
		},
		.authenticated_data = {
			[0] = {
457
				.type_desc = &tos_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
458
				.data = {
459
					.ptr = (void *)content_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
460
461
462
463
464
					.len = (unsigned int)PK_DER_LEN
				}
			}
		}
	},
465
466
	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {
		.img_id = TRUSTED_OS_FW_CONTENT_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
467
		.img_type = IMG_CERT,
468
		.parent = &cot_desc[TRUSTED_OS_FW_KEY_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
469
470
471
472
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
473
					.pk = &tos_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
474
475
476
477
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
478
479
480
481
482
483
484
			},
			[1] = {
				.type = AUTH_METHOD_NV_CTR,
				.param.nv_ctr = {
					.cert_nv_ctr = &trusted_nv_ctr,
					.plat_nv_ctr = &trusted_nv_ctr
				}
Juan Castillo's avatar
Juan Castillo committed
485
486
487
488
			}
		},
		.authenticated_data = {
			[0] = {
489
				.type_desc = &tos_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
490
				.data = {
491
					.ptr = (void *)tos_fw_hash_buf,
Juan Castillo's avatar
Juan Castillo committed
492
493
					.len = (unsigned int)HASH_DER_LEN
				}
494
495
496
497
498
499
500
501
502
503
504
505
506
507
			},
			[1] = {
				.type_desc = &tos_fw_extra1_hash,
				.data = {
					.ptr = (void *)tos_fw_extra1_hash_buf,
					.len = (unsigned int)HASH_DER_LEN
				}
			},
			[2] = {
				.type_desc = &tos_fw_extra2_hash,
				.data = {
					.ptr = (void *)tos_fw_extra2_hash_buf,
					.len = (unsigned int)HASH_DER_LEN
				}
508
509
510
511
512
513
514
			},
			[3] = {
				.type_desc = &tos_fw_config_hash,
				.data = {
					.ptr = (void *)tos_fw_config_hash_buf,
					.len = (unsigned int)HASH_DER_LEN
				}
Juan Castillo's avatar
Juan Castillo committed
515
516
517
518
519
520
			}
		}
	},
	[BL32_IMAGE_ID] = {
		.img_id = BL32_IMAGE_ID,
		.img_type = IMG_RAW,
521
		.parent = &cot_desc[TRUSTED_OS_FW_CONTENT_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
522
523
524
525
526
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
527
					.hash = &tos_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
528
529
530
531
				}
			}
		}
	},
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
	[BL32_EXTRA1_IMAGE_ID] = {
		.img_id = BL32_EXTRA1_IMAGE_ID,
		.img_type = IMG_RAW,
		.parent = &cot_desc[TRUSTED_OS_FW_CONTENT_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
					.hash = &tos_fw_extra1_hash,
				}
			}
		}
	},
	[BL32_EXTRA2_IMAGE_ID] = {
		.img_id = BL32_EXTRA2_IMAGE_ID,
		.img_type = IMG_RAW,
		.parent = &cot_desc[TRUSTED_OS_FW_CONTENT_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
					.hash = &tos_fw_extra2_hash,
				}
			}
		}
	},
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
	/* TOS FW Config */
	[TOS_FW_CONFIG_ID] = {
		.img_id = TOS_FW_CONFIG_ID,
		.img_type = IMG_RAW,
		.parent = &cot_desc[TRUSTED_OS_FW_CONTENT_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
					.hash = &tos_fw_config_hash,
				}
			}
		}
	},
Juan Castillo's avatar
Juan Castillo committed
575
	/*
576
	 * Non-Trusted Firmware
Juan Castillo's avatar
Juan Castillo committed
577
	 */
578
579
	[NON_TRUSTED_FW_KEY_CERT_ID] = {
		.img_id = NON_TRUSTED_FW_KEY_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
580
581
582
583
584
585
		.img_type = IMG_CERT,
		.parent = &cot_desc[TRUSTED_KEY_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
586
					.pk = &non_trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
587
588
589
590
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
591
592
593
594
595
596
597
			},
			[1] = {
				.type = AUTH_METHOD_NV_CTR,
				.param.nv_ctr = {
					.cert_nv_ctr = &non_trusted_nv_ctr,
					.plat_nv_ctr = &non_trusted_nv_ctr
				}
Juan Castillo's avatar
Juan Castillo committed
598
599
600
601
			}
		},
		.authenticated_data = {
			[0] = {
602
				.type_desc = &nt_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
603
				.data = {
604
					.ptr = (void *)content_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
605
606
607
608
609
					.len = (unsigned int)PK_DER_LEN
				}
			}
		}
	},
610
611
	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {
		.img_id = NON_TRUSTED_FW_CONTENT_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
612
		.img_type = IMG_CERT,
613
		.parent = &cot_desc[NON_TRUSTED_FW_KEY_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
614
615
616
617
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
618
					.pk = &nt_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
619
620
621
622
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
623
624
625
626
627
628
629
			},
			[1] = {
				.type = AUTH_METHOD_NV_CTR,
				.param.nv_ctr = {
					.cert_nv_ctr = &non_trusted_nv_ctr,
					.plat_nv_ctr = &non_trusted_nv_ctr
				}
Juan Castillo's avatar
Juan Castillo committed
630
631
632
633
			}
		},
		.authenticated_data = {
			[0] = {
634
				.type_desc = &nt_world_bl_hash,
Juan Castillo's avatar
Juan Castillo committed
635
				.data = {
636
					.ptr = (void *)nt_world_bl_hash_buf,
Juan Castillo's avatar
Juan Castillo committed
637
638
					.len = (unsigned int)HASH_DER_LEN
				}
639
640
641
642
643
644
645
			},
			[1] = {
				.type_desc = &nt_fw_config_hash,
				.data = {
					.ptr = (void *)nt_fw_config_hash_buf,
					.len = (unsigned int)HASH_DER_LEN
				}
Juan Castillo's avatar
Juan Castillo committed
646
647
648
649
650
651
			}
		}
	},
	[BL33_IMAGE_ID] = {
		.img_id = BL33_IMAGE_ID,
		.img_type = IMG_RAW,
652
		.parent = &cot_desc[NON_TRUSTED_FW_CONTENT_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
653
654
655
656
657
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
658
					.hash = &nt_world_bl_hash,
Juan Castillo's avatar
Juan Castillo committed
659
660
661
				}
			}
		}
662
	},
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
	/* NT FW Config */
	[NT_FW_CONFIG_ID] = {
		.img_id = NT_FW_CONFIG_ID,
		.img_type = IMG_RAW,
		.parent = &cot_desc[NON_TRUSTED_FW_CONTENT_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
					.hash = &nt_fw_config_hash,
				}
			}
		}
	},
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
	/*
	 * FWU auth descriptor.
	 */
	[FWU_CERT_ID] = {
		.img_id = FWU_CERT_ID,
		.img_type = IMG_CERT,
		.parent = NULL,
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
					.pk = &subject_pk,
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
			}
		},
		.authenticated_data = {
			[0] = {
				.type_desc = &scp_bl2u_hash,
				.data = {
700
					.ptr = (void *)scp_fw_hash_buf,
701
702
703
704
705
706
					.len = (unsigned int)HASH_DER_LEN
				}
			},
			[1] = {
				.type_desc = &bl2u_hash,
				.data = {
707
					.ptr = (void *)tb_fw_hash_buf,
708
709
710
711
712
713
					.len = (unsigned int)HASH_DER_LEN
				}
			},
			[2] = {
				.type_desc = &ns_bl2u_hash,
				.data = {
714
					.ptr = (void *)nt_world_bl_hash_buf,
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
					.len = (unsigned int)HASH_DER_LEN
				}
			}
		}
	},
	/*
	 * SCP_BL2U
	 */
	[SCP_BL2U_IMAGE_ID] = {
		.img_id = SCP_BL2U_IMAGE_ID,
		.img_type = IMG_RAW,
		.parent = &cot_desc[FWU_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
					.hash = &scp_bl2u_hash,
				}
			}
		}
	},
	/*
	 * BL2U
	 */
	[BL2U_IMAGE_ID] = {
		.img_id = BL2U_IMAGE_ID,
		.img_type = IMG_RAW,
		.parent = &cot_desc[FWU_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
					.hash = &bl2u_hash,
				}
			}
		}
	},
	/*
	 * NS_BL2U
	 */
	[NS_BL2U_IMAGE_ID] = {
		.img_id = NS_BL2U_IMAGE_ID,
		.img_type = IMG_RAW,
		.parent = &cot_desc[FWU_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
					.hash = &ns_bl2u_hash,
				}
			}
		}
Juan Castillo's avatar
Juan Castillo committed
770
771
772
773
774
	}
};

/* Register the CoT in the authentication module */
REGISTER_COT(cot_desc);