blob: 82e86cd98e122272fba027cc98aaa1c8b539c655 [file] [log] [blame]
Jamie Foxe7f8b4e2023-05-30 18:03:20 +01001/*
Tamas Bana5e2f582024-01-25 16:59:26 +01002 * Copyright (c) 2023-2024, Arm Limited. All rights reserved.
Jamie Foxe7f8b4e2023-05-30 18:03:20 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include "dpe_log.h"
Maulik Patelad2f3db2023-05-17 15:41:36 +01009#include "dpe_context_mngr.h"
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010010
11#if (TFM_PARTITION_LOG_LEVEL >= TFM_PARTITION_LOG_LEVEL_DEBUG)
12
13static void print_byte_array(const uint8_t *array, size_t len)
14{
15 size_t i;
16
17 if (array != NULL) {
18 for (i = 0; i < len; ++i) {
19 if ((i & 0xF) == 0) {
20 LOG_DBGFMT("\r\n ");
21 }
22 if (array[i] < 0x10) {
23 LOG_DBGFMT(" 0%x", array[i]);
24 } else {
25 LOG_DBGFMT(" %x", array[i]);
26 }
27 }
28 }
29
30 LOG_DBGFMT("\r\n");
31}
32
33static void log_dice_inputs(const DiceInputValues *input)
34{
35 LOG_DBGFMT(" - DICE code_hash =");
36 print_byte_array(input->code_hash, sizeof(input->code_hash));
37 LOG_DBGFMT(" - DICE code_descriptor =");
38 print_byte_array(input->code_descriptor, input->code_descriptor_size);
39 LOG_DBGFMT(" - DICE config_type = %d\r\n", input->config_type);
40 LOG_DBGFMT(" - DICE config_value =");
41 print_byte_array(input->config_value, sizeof(input->config_value));
42 LOG_DBGFMT(" - DICE config_descriptor =");
43 print_byte_array(input->config_descriptor, input->config_descriptor_size);
44 LOG_DBGFMT(" - DICE authority_hash =");
45 print_byte_array(input->authority_hash, sizeof(input->authority_hash));
46 LOG_DBGFMT(" - DICE authority_descriptor =");
47 print_byte_array(input->authority_descriptor,
48 input->authority_descriptor_size);
49 LOG_DBGFMT(" - DICE mode = %d\r\n", input->mode);
50 LOG_DBGFMT(" - DICE hidden =");
51 print_byte_array(input->hidden, sizeof(input->hidden));
52}
53
Maulik Patelad2f3db2023-05-17 15:41:36 +010054void log_derive_rot_context(const DiceInputValues *dice_inputs)
55{
56 LOG_DBGFMT("DPE DeriveRoTContext:\r\n");
57 log_dice_inputs(dice_inputs);
58}
59
Maulik Patela81605b2023-10-24 12:17:03 +010060void log_derive_context(int context_handle,
Maulik Patelcb14cde2024-01-23 12:39:53 +000061 uint32_t cert_id,
Maulik Patela81605b2023-10-24 12:17:03 +010062 bool retain_parent_context,
63 bool allow_new_context_to_derive,
64 bool create_certificate,
65 const DiceInputValues *dice_inputs,
66 int32_t client_id)
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010067{
Maulik Patela81605b2023-10-24 12:17:03 +010068 LOG_DBGFMT("DPE DeriveContext:\r\n");
Maulik Patelad2f3db2023-05-17 15:41:36 +010069 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
70 LOG_DBGFMT(" - context_handle nonce = %d\r\n", GET_NONCE(context_handle));
Maulik Patelcb14cde2024-01-23 12:39:53 +000071 LOG_DBGFMT(" - cert_id = 0x%x\r\n", cert_id);
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010072 LOG_DBGFMT(" - retain_parent_context = %d\r\n", retain_parent_context);
Maulik Patela81605b2023-10-24 12:17:03 +010073 LOG_DBGFMT(" - allow_new_context_to_derive = %d\r\n", allow_new_context_to_derive);
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010074 LOG_DBGFMT(" - create_certificate = %d\r\n", create_certificate);
75 log_dice_inputs(dice_inputs);
Maulik Patelad2f3db2023-05-17 15:41:36 +010076 LOG_DBGFMT(" - client_id = %d\r\n", client_id);
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010077}
78
Maulik Patel54d65f72023-06-28 13:04:36 +010079void log_destroy_context(int context_handle, bool destroy_recursively)
80{
81 LOG_DBGFMT("DPE DestroyContext:\r\n");
82 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
83 LOG_DBGFMT(" - context_handle nonce = %d\r\n", GET_NONCE(context_handle));
84 LOG_DBGFMT(" - destroy_recursively = %d\r\n", destroy_recursively);
85}
86
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010087void log_certify_key(int context_handle,
88 bool retain_context,
89 const uint8_t *public_key,
90 size_t public_key_size,
91 const uint8_t *label,
92 size_t label_size)
93{
94 LOG_DBGFMT("DPE CertifyKey:\r\n");
Maulik Patelad2f3db2023-05-17 15:41:36 +010095 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
96 LOG_DBGFMT(" - context_handle nonce = %d\r\n", GET_NONCE(context_handle));
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010097 LOG_DBGFMT(" - retain_context = %d\r\n", retain_context);
98 LOG_DBGFMT(" - public_key =");
99 print_byte_array(public_key, public_key_size);
100 LOG_DBGFMT(" - label =");
101 print_byte_array(label, label_size);
102}
103
Maulik Patel83a6b592023-12-05 15:20:30 +0000104void log_get_certificate_chain(int context_handle,
105 bool retain_context,
Tamas Bana5e2f582024-01-25 16:59:26 +0100106 bool clear_from_context,
107 size_t cert_chain_buf_size)
Maulik Patel83a6b592023-12-05 15:20:30 +0000108{
109 LOG_DBGFMT("DPE GetCertificateChain:\r\n");
110 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
111 LOG_DBGFMT(" - context_handle nonce = %d\r\n", GET_NONCE(context_handle));
112 LOG_DBGFMT(" - retain_context = %d\r\n", retain_context);
113 LOG_DBGFMT(" - clear_from_context = %d\r\n", clear_from_context);
Tamas Bana5e2f582024-01-25 16:59:26 +0100114 LOG_DBGFMT(" - cert_chain_buf_size = %d\r\n", cert_chain_buf_size);
Maulik Patel83a6b592023-12-05 15:20:30 +0000115}
116
Maulik Patel2358bbb2023-07-21 10:56:56 +0100117void log_intermediate_certificate(uint16_t layer_idx,
118 const uint8_t *cert_buf,
119 size_t cert_buf_size)
120{
121 LOG_DBGFMT("DPE Intermediate Certificate:\r\n");
122 LOG_DBGFMT(" - layer index = %d\r\n", layer_idx);
123 LOG_DBGFMT(" - certificate =");
124 print_byte_array(cert_buf, cert_buf_size);
125}
126
Maulik Patele6adc112023-08-18 14:21:51 +0100127void log_certificate_chain(const uint8_t *certificate_chain_buf,
128 size_t certificate_chain_size)
129{
130 LOG_DBGFMT("DPE Certificate Chain:\r\n");
131 LOG_DBGFMT(" - size = %d\r\n", certificate_chain_size);
132 print_byte_array(certificate_chain_buf, certificate_chain_size);
133}
134
Jamie Foxe7f8b4e2023-05-30 18:03:20 +0100135#endif /* TFM_PARTITION_LOG_LEVEL */