blob: 5e4da40af4df1964c10db7d58ca782eba228fea9 [file] [log] [blame]
Jamie Foxe7f8b4e2023-05-30 18:03:20 +01001/*
2 * Copyright (c) 2023, Arm Limited. All rights reserved.
3 *
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
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010060void log_derive_child(int context_handle,
61 bool retain_parent_context,
62 bool allow_child_to_derive,
63 bool create_certificate,
Maulik Patelad2f3db2023-05-17 15:41:36 +010064 const DiceInputValues *dice_inputs,
65 int32_t client_id)
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010066{
67 LOG_DBGFMT("DPE DeriveChild:\r\n");
Maulik Patelad2f3db2023-05-17 15:41:36 +010068 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
69 LOG_DBGFMT(" - context_handle nonce = %d\r\n", GET_NONCE(context_handle));
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010070 LOG_DBGFMT(" - retain_parent_context = %d\r\n", retain_parent_context);
71 LOG_DBGFMT(" - allow_child_to_derive = %d\r\n", allow_child_to_derive);
72 LOG_DBGFMT(" - create_certificate = %d\r\n", create_certificate);
73 log_dice_inputs(dice_inputs);
Maulik Patelad2f3db2023-05-17 15:41:36 +010074 LOG_DBGFMT(" - client_id = %d\r\n", client_id);
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010075}
76
Maulik Patel54d65f72023-06-28 13:04:36 +010077void log_destroy_context(int context_handle, bool destroy_recursively)
78{
79 LOG_DBGFMT("DPE DestroyContext:\r\n");
80 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
81 LOG_DBGFMT(" - context_handle nonce = %d\r\n", GET_NONCE(context_handle));
82 LOG_DBGFMT(" - destroy_recursively = %d\r\n", destroy_recursively);
83}
84
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010085void log_certify_key(int context_handle,
86 bool retain_context,
87 const uint8_t *public_key,
88 size_t public_key_size,
89 const uint8_t *label,
90 size_t label_size)
91{
92 LOG_DBGFMT("DPE CertifyKey:\r\n");
Maulik Patelad2f3db2023-05-17 15:41:36 +010093 LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
94 LOG_DBGFMT(" - context_handle nonce = %d\r\n", GET_NONCE(context_handle));
Jamie Foxe7f8b4e2023-05-30 18:03:20 +010095 LOG_DBGFMT(" - retain_context = %d\r\n", retain_context);
96 LOG_DBGFMT(" - public_key =");
97 print_byte_array(public_key, public_key_size);
98 LOG_DBGFMT(" - label =");
99 print_byte_array(label, label_size);
100}
101
102#endif /* TFM_PARTITION_LOG_LEVEL */