Jamie Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 1 | /* |
Tamas Ban | a5e2f58 | 2024-01-25 16:59:26 +0100 | [diff] [blame] | 2 | * Copyright (c) 2023-2024, Arm Limited. All rights reserved. |
Jamie Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 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 | |
Maulik Patel | a81605b | 2023-10-24 12:17:03 +0100 | [diff] [blame] | 60 | void log_derive_context(int context_handle, |
Maulik Patel | cb14cde | 2024-01-23 12:39:53 +0000 | [diff] [blame^] | 61 | uint32_t cert_id, |
Maulik Patel | a81605b | 2023-10-24 12:17:03 +0100 | [diff] [blame] | 62 | 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 Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 67 | { |
Maulik Patel | a81605b | 2023-10-24 12:17:03 +0100 | [diff] [blame] | 68 | LOG_DBGFMT("DPE DeriveContext:\r\n"); |
Maulik Patel | ad2f3db | 2023-05-17 15:41:36 +0100 | [diff] [blame] | 69 | 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 Patel | cb14cde | 2024-01-23 12:39:53 +0000 | [diff] [blame^] | 71 | LOG_DBGFMT(" - cert_id = 0x%x\r\n", cert_id); |
Jamie Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 72 | LOG_DBGFMT(" - retain_parent_context = %d\r\n", retain_parent_context); |
Maulik Patel | a81605b | 2023-10-24 12:17:03 +0100 | [diff] [blame] | 73 | LOG_DBGFMT(" - allow_new_context_to_derive = %d\r\n", allow_new_context_to_derive); |
Jamie Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 74 | LOG_DBGFMT(" - create_certificate = %d\r\n", create_certificate); |
| 75 | log_dice_inputs(dice_inputs); |
Maulik Patel | ad2f3db | 2023-05-17 15:41:36 +0100 | [diff] [blame] | 76 | LOG_DBGFMT(" - client_id = %d\r\n", client_id); |
Jamie Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Maulik Patel | 54d65f7 | 2023-06-28 13:04:36 +0100 | [diff] [blame] | 79 | void 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 Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 87 | void 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 Patel | ad2f3db | 2023-05-17 15:41:36 +0100 | [diff] [blame] | 95 | 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 Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 97 | 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 Patel | 83a6b59 | 2023-12-05 15:20:30 +0000 | [diff] [blame] | 104 | void log_get_certificate_chain(int context_handle, |
| 105 | bool retain_context, |
Tamas Ban | a5e2f58 | 2024-01-25 16:59:26 +0100 | [diff] [blame] | 106 | bool clear_from_context, |
| 107 | size_t cert_chain_buf_size) |
Maulik Patel | 83a6b59 | 2023-12-05 15:20:30 +0000 | [diff] [blame] | 108 | { |
| 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 Ban | a5e2f58 | 2024-01-25 16:59:26 +0100 | [diff] [blame] | 114 | LOG_DBGFMT(" - cert_chain_buf_size = %d\r\n", cert_chain_buf_size); |
Maulik Patel | 83a6b59 | 2023-12-05 15:20:30 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Maulik Patel | 2358bbb | 2023-07-21 10:56:56 +0100 | [diff] [blame] | 117 | void 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 Patel | e6adc11 | 2023-08-18 14:21:51 +0100 | [diff] [blame] | 127 | void 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 Fox | e7f8b4e | 2023-05-30 18:03:20 +0100 | [diff] [blame] | 135 | #endif /* TFM_PARTITION_LOG_LEVEL */ |