blob: 3c9bfab52f2fd2d1048edcbb080459f69d705c9d [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)
Maulik Patel780943f2024-03-14 11:40:14 +000012#define LOG_BOOL_VAL(arg) ((arg) ? "true" : "false")
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010013
14static void print_byte_array(const uint8_t *array, size_t len)
15{
16 size_t i;
17
18 if (array != NULL) {
19 for (i = 0; i < len; ++i) {
20 if ((i & 0xF) == 0) {
21 LOG_DBGFMT("\r\n ");
22 }
23 if (array[i] < 0x10) {
24 LOG_DBGFMT(" 0%x", array[i]);
25 } else {
26 LOG_DBGFMT(" %x", array[i]);
27 }
28 }
29 }
30
31 LOG_DBGFMT("\r\n");
32}
33
34static void log_dice_inputs(const DiceInputValues *input)
35{
36 LOG_DBGFMT(" - DICE code_hash =");
37 print_byte_array(input->code_hash, sizeof(input->code_hash));
38 LOG_DBGFMT(" - DICE code_descriptor =");
39 print_byte_array(input->code_descriptor, input->code_descriptor_size);
40 LOG_DBGFMT(" - DICE config_type = %d\r\n", input->config_type);
41 LOG_DBGFMT(" - DICE config_value =");
42 print_byte_array(input->config_value, sizeof(input->config_value));
43 LOG_DBGFMT(" - DICE config_descriptor =");
44 print_byte_array(input->config_descriptor, input->config_descriptor_size);
45 LOG_DBGFMT(" - DICE authority_hash =");
46 print_byte_array(input->authority_hash, sizeof(input->authority_hash));
47 LOG_DBGFMT(" - DICE authority_descriptor =");
48 print_byte_array(input->authority_descriptor,
49 input->authority_descriptor_size);
50 LOG_DBGFMT(" - DICE mode = %d\r\n", input->mode);
51 LOG_DBGFMT(" - DICE hidden =");
52 print_byte_array(input->hidden, sizeof(input->hidden));
53}
54
Maulik Patelad2f3db2023-05-17 15:41:36 +010055void log_derive_rot_context(const DiceInputValues *dice_inputs)
56{
57 LOG_DBGFMT("DPE DeriveRoTContext:\r\n");
58 log_dice_inputs(dice_inputs);
59}
60
Maulik Patela81605b2023-10-24 12:17:03 +010061void log_derive_context(int context_handle,
Maulik Patelcb14cde2024-01-23 12:39:53 +000062 uint32_t cert_id,
Maulik Patela81605b2023-10-24 12:17:03 +010063 bool retain_parent_context,
64 bool allow_new_context_to_derive,
65 bool create_certificate,
66 const DiceInputValues *dice_inputs,
67 int32_t client_id)
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010068{
Maulik Patela81605b2023-10-24 12:17:03 +010069 LOG_DBGFMT("DPE DeriveContext:\r\n");
Maulik Patelad2f3db2023-05-17 15:41:36 +010070 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
Maulik Patel780943f2024-03-14 11:40:14 +000071 LOG_DBGFMT(" - context_handle nonce = 0x%x\r\n", GET_NONCE(context_handle));
Maulik Patelcb14cde2024-01-23 12:39:53 +000072 LOG_DBGFMT(" - cert_id = 0x%x\r\n", cert_id);
Maulik Patel780943f2024-03-14 11:40:14 +000073 LOG_DBGFMT(" - retain_parent_context = %s\r\n", LOG_BOOL_VAL(retain_parent_context));
74 LOG_DBGFMT(" - allow_new_context_to_derive = %s\r\n", LOG_BOOL_VAL(allow_new_context_to_derive));
75 LOG_DBGFMT(" - create_certificate = %s\r\n", LOG_BOOL_VAL(create_certificate));
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010076 log_dice_inputs(dice_inputs);
Maulik Patelad2f3db2023-05-17 15:41:36 +010077 LOG_DBGFMT(" - client_id = %d\r\n", client_id);
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010078}
79
Maulik Patel54d65f72023-06-28 13:04:36 +010080void log_destroy_context(int context_handle, bool destroy_recursively)
81{
82 LOG_DBGFMT("DPE DestroyContext:\r\n");
83 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
Maulik Patel780943f2024-03-14 11:40:14 +000084 LOG_DBGFMT(" - context_handle nonce = 0x%x\r\n", GET_NONCE(context_handle));
85 LOG_DBGFMT(" - destroy_recursively = %s\r\n", LOG_BOOL_VAL(destroy_recursively));
Maulik Patel54d65f72023-06-28 13:04:36 +010086}
87
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010088void log_certify_key(int context_handle,
89 bool retain_context,
90 const uint8_t *public_key,
91 size_t public_key_size,
92 const uint8_t *label,
93 size_t label_size)
94{
95 LOG_DBGFMT("DPE CertifyKey:\r\n");
Maulik Patelad2f3db2023-05-17 15:41:36 +010096 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
Maulik Patel780943f2024-03-14 11:40:14 +000097 LOG_DBGFMT(" - context_handle nonce = 0x%x\r\n", GET_NONCE(context_handle));
98 LOG_DBGFMT(" - retain_context = %s\r\n", LOG_BOOL_VAL(retain_context));
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010099 LOG_DBGFMT(" - public_key =");
100 print_byte_array(public_key, public_key_size);
101 LOG_DBGFMT(" - label =");
102 print_byte_array(label, label_size);
103}
104
Maulik Patel83a6b592023-12-05 15:20:30 +0000105void log_get_certificate_chain(int context_handle,
106 bool retain_context,
Tamas Bana5e2f582024-01-25 16:59:26 +0100107 bool clear_from_context,
108 size_t cert_chain_buf_size)
Maulik Patel83a6b592023-12-05 15:20:30 +0000109{
110 LOG_DBGFMT("DPE GetCertificateChain:\r\n");
111 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
Maulik Patel780943f2024-03-14 11:40:14 +0000112 LOG_DBGFMT(" - context_handle nonce = 0x%x\r\n", GET_NONCE(context_handle));
113 LOG_DBGFMT(" - retain_context = %s\r\n", LOG_BOOL_VAL(retain_context));
114 LOG_DBGFMT(" - clear_from_context = %s\r\n", LOG_BOOL_VAL(clear_from_context));
Tamas Bana5e2f582024-01-25 16:59:26 +0100115 LOG_DBGFMT(" - cert_chain_buf_size = %d\r\n", cert_chain_buf_size);
Maulik Patel83a6b592023-12-05 15:20:30 +0000116}
117
Maulik Patel2358bbb2023-07-21 10:56:56 +0100118void log_intermediate_certificate(uint16_t layer_idx,
119 const uint8_t *cert_buf,
120 size_t cert_buf_size)
121{
122 LOG_DBGFMT("DPE Intermediate Certificate:\r\n");
123 LOG_DBGFMT(" - layer index = %d\r\n", layer_idx);
124 LOG_DBGFMT(" - certificate =");
125 print_byte_array(cert_buf, cert_buf_size);
126}
127
Maulik Patele6adc112023-08-18 14:21:51 +0100128void log_certificate_chain(const uint8_t *certificate_chain_buf,
129 size_t certificate_chain_size)
130{
131 LOG_DBGFMT("DPE Certificate Chain:\r\n");
132 LOG_DBGFMT(" - size = %d\r\n", certificate_chain_size);
133 print_byte_array(certificate_chain_buf, certificate_chain_size);
134}
135
Jamie Foxe7f8b4e2023-05-30 18:03:20 +0100136#endif /* TFM_PARTITION_LOG_LEVEL */