tbbr_cot.c 15.5 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];
Juan Castillo's avatar
Juan Castillo committed
41
42
43
44

/*
 * Parameter type descriptors
 */
45
46
47
48
49
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
50
51
52
53
54
55
56
57
58
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);

59
60
61
62
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
63

64
65
66
67
68
69
70
71
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
72

73
74
static auth_param_type_desc_t tb_fw_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, TRUSTED_BOOT_FW_HASH_OID);
75
76
77
78
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);
79
80
81
82
83
84
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);
static auth_param_type_desc_t tos_fw_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, TRUSTED_OS_FW_HASH_OID);
85
86
87
88
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);
89
90
static auth_param_type_desc_t nt_world_bl_hash = AUTH_PARAM_TYPE_DESC(
		AUTH_PARAM_HASH, NON_TRUSTED_WORLD_BOOTLOADER_HASH_OID);
91
static auth_param_type_desc_t scp_bl2u_hash = AUTH_PARAM_TYPE_DESC(
92
		AUTH_PARAM_HASH, SCP_FWU_CFG_HASH_OID);
93
static auth_param_type_desc_t bl2u_hash = AUTH_PARAM_TYPE_DESC(
94
		AUTH_PARAM_HASH, AP_FWU_CFG_HASH_OID);
95
static auth_param_type_desc_t ns_bl2u_hash = AUTH_PARAM_TYPE_DESC(
96
		AUTH_PARAM_HASH, FWU_HASH_OID);
Juan Castillo's avatar
Juan Castillo committed
97
98
99
100
101
102
103
104

/*
 * TBBR Chain of trust definition
 */
static const auth_img_desc_t cot_desc[] = {
	/*
	 * BL2
	 */
105
106
	[TRUSTED_BOOT_FW_CERT_ID] = {
		.img_id = TRUSTED_BOOT_FW_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
107
108
109
110
111
112
113
114
115
116
117
		.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,
				}
118
119
120
121
122
123
124
			},
			[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
125
126
127
128
			}
		},
		.authenticated_data = {
			[0] = {
129
				.type_desc = &tb_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
130
				.data = {
131
					.ptr = (void *)tb_fw_hash_buf,
Juan Castillo's avatar
Juan Castillo committed
132
133
					.len = (unsigned int)HASH_DER_LEN
				}
134
135
136
137
138
139
140
141
142
143
144
145
146
147
			},
			[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
148
149
150
151
152
153
			}
		}
	},
	[BL2_IMAGE_ID] = {
		.img_id = BL2_IMAGE_ID,
		.img_type = IMG_RAW,
154
		.parent = &cot_desc[TRUSTED_BOOT_FW_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
155
156
157
158
159
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
160
					.hash = &tb_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
161
162
163
164
				}
			}
		}
	},
165
166
167
168
169
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
	/* 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
	/*
	 * 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,
				}
211
212
213
214
215
216
217
			},
			[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
218
219
220
221
			}
		},
		.authenticated_data = {
			[0] = {
222
				.type_desc = &trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
223
				.data = {
224
					.ptr = (void *)trusted_world_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
225
226
227
228
					.len = (unsigned int)PK_DER_LEN
				}
			},
			[1] = {
229
				.type_desc = &non_trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
230
				.data = {
231
					.ptr = (void *)non_trusted_world_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
232
233
234
235
236
237
					.len = (unsigned int)PK_DER_LEN
				}
			}
		}
	},
	/*
238
	 * SCP Firmware
Juan Castillo's avatar
Juan Castillo committed
239
	 */
240
241
	[SCP_FW_KEY_CERT_ID] = {
		.img_id = SCP_FW_KEY_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
242
243
244
245
246
247
		.img_type = IMG_CERT,
		.parent = &cot_desc[TRUSTED_KEY_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
248
					.pk = &trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
249
250
251
252
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
253
254
255
256
257
258
259
			},
			[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
260
261
262
263
			}
		},
		.authenticated_data = {
			[0] = {
264
				.type_desc = &scp_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
265
				.data = {
266
					.ptr = (void *)content_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
267
268
269
270
271
					.len = (unsigned int)PK_DER_LEN
				}
			}
		}
	},
272
273
	[SCP_FW_CONTENT_CERT_ID] = {
		.img_id = SCP_FW_CONTENT_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
274
		.img_type = IMG_CERT,
275
		.parent = &cot_desc[SCP_FW_KEY_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
276
277
278
279
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
280
					.pk = &scp_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
281
282
283
284
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
285
286
287
288
289
290
291
			},
			[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
292
293
294
295
			}
		},
		.authenticated_data = {
			[0] = {
296
				.type_desc = &scp_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
297
				.data = {
298
					.ptr = (void *)scp_fw_hash_buf,
Juan Castillo's avatar
Juan Castillo committed
299
300
301
302
303
					.len = (unsigned int)HASH_DER_LEN
				}
			}
		}
	},
304
305
	[SCP_BL2_IMAGE_ID] = {
		.img_id = SCP_BL2_IMAGE_ID,
Juan Castillo's avatar
Juan Castillo committed
306
		.img_type = IMG_RAW,
307
		.parent = &cot_desc[SCP_FW_CONTENT_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
308
309
310
311
312
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
313
					.hash = &scp_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
314
315
316
317
318
				}
			}
		}
	},
	/*
319
	 * SoC Firmware
Juan Castillo's avatar
Juan Castillo committed
320
	 */
321
322
	[SOC_FW_KEY_CERT_ID] = {
		.img_id = SOC_FW_KEY_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
323
324
325
326
327
328
		.img_type = IMG_CERT,
		.parent = &cot_desc[TRUSTED_KEY_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
329
					.pk = &trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
330
331
332
333
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
334
335
336
337
338
339
340
			},
			[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
341
342
343
344
			}
		},
		.authenticated_data = {
			[0] = {
345
				.type_desc = &soc_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
346
				.data = {
347
					.ptr = (void *)content_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
348
349
350
351
352
					.len = (unsigned int)PK_DER_LEN
				}
			}
		}
	},
353
354
	[SOC_FW_CONTENT_CERT_ID] = {
		.img_id = SOC_FW_CONTENT_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
355
		.img_type = IMG_CERT,
356
		.parent = &cot_desc[SOC_FW_KEY_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
357
358
359
360
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
361
					.pk = &soc_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
362
363
364
365
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
366
367
368
369
370
371
372
			},
			[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
373
374
375
376
			}
		},
		.authenticated_data = {
			[0] = {
377
				.type_desc = &soc_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
378
				.data = {
379
					.ptr = (void *)soc_fw_hash_buf,
Juan Castillo's avatar
Juan Castillo committed
380
381
382
383
384
385
386
387
					.len = (unsigned int)HASH_DER_LEN
				}
			}
		}
	},
	[BL31_IMAGE_ID] = {
		.img_id = BL31_IMAGE_ID,
		.img_type = IMG_RAW,
388
		.parent = &cot_desc[SOC_FW_CONTENT_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
389
390
391
392
393
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
394
					.hash = &soc_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
395
396
397
398
399
				}
			}
		}
	},
	/*
400
	 * Trusted OS Firmware
Juan Castillo's avatar
Juan Castillo committed
401
	 */
402
403
	[TRUSTED_OS_FW_KEY_CERT_ID] = {
		.img_id = TRUSTED_OS_FW_KEY_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
404
405
406
407
408
409
		.img_type = IMG_CERT,
		.parent = &cot_desc[TRUSTED_KEY_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
410
					.pk = &trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
411
412
413
414
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
415
416
417
418
419
420
421
			},
			[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
422
423
424
425
			}
		},
		.authenticated_data = {
			[0] = {
426
				.type_desc = &tos_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
427
				.data = {
428
					.ptr = (void *)content_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
429
430
431
432
433
					.len = (unsigned int)PK_DER_LEN
				}
			}
		}
	},
434
435
	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {
		.img_id = TRUSTED_OS_FW_CONTENT_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
436
		.img_type = IMG_CERT,
437
		.parent = &cot_desc[TRUSTED_OS_FW_KEY_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
438
439
440
441
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
442
					.pk = &tos_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
443
444
445
446
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
447
448
449
450
451
452
453
			},
			[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
454
455
456
457
			}
		},
		.authenticated_data = {
			[0] = {
458
				.type_desc = &tos_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
459
				.data = {
460
					.ptr = (void *)tos_fw_hash_buf,
Juan Castillo's avatar
Juan Castillo committed
461
462
					.len = (unsigned int)HASH_DER_LEN
				}
463
464
465
466
467
468
469
470
471
472
473
474
475
476
			},
			[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
				}
Juan Castillo's avatar
Juan Castillo committed
477
478
479
480
481
482
			}
		}
	},
	[BL32_IMAGE_ID] = {
		.img_id = BL32_IMAGE_ID,
		.img_type = IMG_RAW,
483
		.parent = &cot_desc[TRUSTED_OS_FW_CONTENT_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
484
485
486
487
488
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
489
					.hash = &tos_fw_hash,
Juan Castillo's avatar
Juan Castillo committed
490
491
492
493
				}
			}
		}
	},
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
	[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,
				}
			}
		}
	},
Juan Castillo's avatar
Juan Castillo committed
522
	/*
523
	 * Non-Trusted Firmware
Juan Castillo's avatar
Juan Castillo committed
524
	 */
525
526
	[NON_TRUSTED_FW_KEY_CERT_ID] = {
		.img_id = NON_TRUSTED_FW_KEY_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
527
528
529
530
531
532
		.img_type = IMG_CERT,
		.parent = &cot_desc[TRUSTED_KEY_CERT_ID],
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
533
					.pk = &non_trusted_world_pk,
Juan Castillo's avatar
Juan Castillo committed
534
535
536
537
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
538
539
540
541
542
543
544
			},
			[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
545
546
547
548
			}
		},
		.authenticated_data = {
			[0] = {
549
				.type_desc = &nt_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
550
				.data = {
551
					.ptr = (void *)content_pk_buf,
Juan Castillo's avatar
Juan Castillo committed
552
553
554
555
556
					.len = (unsigned int)PK_DER_LEN
				}
			}
		}
	},
557
558
	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {
		.img_id = NON_TRUSTED_FW_CONTENT_CERT_ID,
Juan Castillo's avatar
Juan Castillo committed
559
		.img_type = IMG_CERT,
560
		.parent = &cot_desc[NON_TRUSTED_FW_KEY_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
561
562
563
564
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_SIG,
				.param.sig = {
565
					.pk = &nt_fw_content_pk,
Juan Castillo's avatar
Juan Castillo committed
566
567
568
569
					.sig = &sig,
					.alg = &sig_alg,
					.data = &raw_data,
				}
570
571
572
573
574
575
576
			},
			[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
577
578
579
580
			}
		},
		.authenticated_data = {
			[0] = {
581
				.type_desc = &nt_world_bl_hash,
Juan Castillo's avatar
Juan Castillo committed
582
				.data = {
583
					.ptr = (void *)nt_world_bl_hash_buf,
Juan Castillo's avatar
Juan Castillo committed
584
585
586
587
588
589
590
591
					.len = (unsigned int)HASH_DER_LEN
				}
			}
		}
	},
	[BL33_IMAGE_ID] = {
		.img_id = BL33_IMAGE_ID,
		.img_type = IMG_RAW,
592
		.parent = &cot_desc[NON_TRUSTED_FW_CONTENT_CERT_ID],
Juan Castillo's avatar
Juan Castillo committed
593
594
595
596
597
		.img_auth_methods = {
			[0] = {
				.type = AUTH_METHOD_HASH,
				.param.hash = {
					.data = &raw_data,
598
					.hash = &nt_world_bl_hash,
Juan Castillo's avatar
Juan Castillo committed
599
600
601
				}
			}
		}
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
	},
	/*
	 * 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 = {
625
					.ptr = (void *)scp_fw_hash_buf,
626
627
628
629
630
631
					.len = (unsigned int)HASH_DER_LEN
				}
			},
			[1] = {
				.type_desc = &bl2u_hash,
				.data = {
632
					.ptr = (void *)tb_fw_hash_buf,
633
634
635
636
637
638
					.len = (unsigned int)HASH_DER_LEN
				}
			},
			[2] = {
				.type_desc = &ns_bl2u_hash,
				.data = {
639
					.ptr = (void *)nt_world_bl_hash_buf,
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
					.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
695
696
697
698
699
	}
};

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