blob: 4f13c3177b398b9c1ddea672df745d88da874f8e [file] [log] [blame]
Maulik Pateld3142702022-06-22 10:09:13 +01001/*
2 * Copyright (c) 2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include "measured_boot_utils.h"
9#include "measured_boot_api.h"
10#include "tfm_sp_log.h"
11#include <stddef.h>
12#include <stdint.h>
13#include <string.h>
14
15static void print_byte_array(const uint8_t *array, size_t len)
16{
17 size_t i;
18
19 if (array == NULL || len == 0) {
20 LOG_DBGFMT("\r\n");
21 } else {
22 for (i = 0; i < len; ++i) {
23 if (array[i] < 0x10) {
24 LOG_DBGFMT(" 0%x", array[i]);
25 } else {
26 LOG_DBGFMT(" %x", array[i]);
27 }
28 if ((i & 0xFu) == 0xFu) {
29 LOG_DBGFMT("\r\n");
30 if (i < (len - 1)) {
31 LOG_DBGFMT(" :");
32 }
33 }
34 }
35 }
36}
37
38static inline void add_null_terminator(uint8_t *dest,
39 const uint8_t *src,
40 size_t src_len)
41{
42 memcpy(dest, src, src_len);
43 *(dest + src_len) = '\0';
44}
45
46void log_extend_measurement(uint8_t index,
47 const uint8_t *signer_id,
48 size_t signer_id_size,
49 const uint8_t *version,
50 uint8_t version_size,
51 uint32_t measurement_algo,
52 const uint8_t *sw_type,
53 uint8_t sw_type_size,
54 const uint8_t *measurement_value,
55 size_t measurement_value_size,
56 uint8_t lock_measurement)
57{
58 uint8_t string_buf[((SW_TYPE_MAX_SIZE > VERSION_MAX_SIZE) ?
59 SW_TYPE_MAX_SIZE : VERSION_MAX_SIZE) + 1];
60
61 LOG_DBGFMT("Measured Boot : store and extend measurement:\r\n");
62 LOG_DBGFMT(" - slot : %u\r\n", index);
63 LOG_DBGFMT(" - signer_id :");
64 print_byte_array(signer_id, signer_id_size);
65 add_null_terminator(string_buf, version, version_size);
66 LOG_DBGFMT(" - version : %s\r\n", string_buf);
67 LOG_DBGFMT(" - algorithm : %x\r\n", measurement_algo);
68 add_null_terminator(string_buf, sw_type, sw_type_size);
69 LOG_DBGFMT(" - sw_type : %s\r\n", string_buf);
70 LOG_DBGFMT(" - measurement :");
71 print_byte_array(measurement_value, measurement_value_size);
72 LOG_DBGFMT(" - locking : %s\r\n", lock_measurement ? "true" : "false");
73}