Jamie Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 1 | /* |
| 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 Patel | ad2f3db | 2023-05-17 15:41:36 +0100 | [diff] [blame] | 9 | #include "dpe_context_mngr.h" |
Jamie Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 10 | |
| 11 | #if (TFM_PARTITION_LOG_LEVEL >= TFM_PARTITION_LOG_LEVEL_DEBUG) |
| 12 | |
| 13 | static 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 | |
| 33 | static 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 Patel | ad2f3db | 2023-05-17 15:41:36 +0100 | [diff] [blame] | 54 | void 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 Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 60 | void log_derive_child(int context_handle, |
| 61 | bool retain_parent_context, |
| 62 | bool allow_child_to_derive, |
| 63 | bool create_certificate, |
Maulik Patel | ad2f3db | 2023-05-17 15:41:36 +0100 | [diff] [blame] | 64 | const DiceInputValues *dice_inputs, |
| 65 | int32_t client_id) |
Jamie Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 66 | { |
| 67 | LOG_DBGFMT("DPE DeriveChild:\r\n"); |
Maulik Patel | ad2f3db | 2023-05-17 15:41:36 +0100 | [diff] [blame] | 68 | 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 Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 70 | 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 Patel | ad2f3db | 2023-05-17 15:41:36 +0100 | [diff] [blame] | 74 | LOG_DBGFMT(" - client_id = %d\r\n", client_id); |
Jamie Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 75 | } |
| 76 | |
Maulik Patel | 54d65f7 | 2023-06-28 13:04:36 +0100 | [diff] [blame] | 77 | void 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 Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 85 | void 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 Patel | ad2f3db | 2023-05-17 15:41:36 +0100 | [diff] [blame] | 93 | 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 Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 95 | 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 | |
Maulik Patel | 2358bbb | 2023-07-21 10:56:56 +0100 | [diff] [blame^] | 102 | void log_intermediate_certificate(uint16_t layer_idx, |
| 103 | const uint8_t *cert_buf, |
| 104 | size_t cert_buf_size) |
| 105 | { |
| 106 | LOG_DBGFMT("DPE Intermediate Certificate:\r\n"); |
| 107 | LOG_DBGFMT(" - layer index = %d\r\n", layer_idx); |
| 108 | LOG_DBGFMT(" - certificate ="); |
| 109 | print_byte_array(cert_buf, cert_buf_size); |
| 110 | } |
| 111 | |
Jamie Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 112 | #endif /* TFM_PARTITION_LOG_LEVEL */ |