blob: 90e4ef39dca06f6d9f6d7a73e4240eff2b2b0f9a [file] [log] [blame]
Tamas Banf5492752022-01-18 16:19:17 +01001/*
2 * Copyright (c) 2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <string.h>
9
10#include <common/debug.h>
11#include <measured_boot.h>
12#include <psa/client.h>
13#include <psa_manifest/sid.h>
14
15#include "measured_boot_private.h"
16
Sandrine Bailleux03d0ad32022-06-15 14:21:17 +020017static void print_byte_array(const uint8_t *array __unused, size_t len __unused)
Tamas Banf5492752022-01-18 16:19:17 +010018{
Sandrine Bailleux03d0ad32022-06-15 14:21:17 +020019#if LOG_LEVEL >= LOG_LEVEL_INFO
David Vinczeffaf5582022-05-18 16:02:37 +020020 size_t i;
Tamas Banf5492752022-01-18 16:19:17 +010021
22 if (array == NULL || len == 0U) {
23 (void)printf("\n");
David Vinczeffaf5582022-05-18 16:02:37 +020024 } else {
25 for (i = 0U; i < len; ++i) {
26 (void)printf(" %02x", array[i]);
27 if ((i & U(0xF)) == U(0xF)) {
28 (void)printf("\n");
29 if (i < (len - 1U)) {
30 INFO("\t\t:");
31 }
Tamas Banf5492752022-01-18 16:19:17 +010032 }
33 }
34 }
Sandrine Bailleux03d0ad32022-06-15 14:21:17 +020035#endif
Tamas Banf5492752022-01-18 16:19:17 +010036}
37
38static void log_measurement(uint8_t index,
39 const uint8_t *signer_id,
40 size_t signer_id_size,
41 const uint8_t *version, /* string */
42 uint32_t measurement_algo,
43 const uint8_t *sw_type, /* string */
44 const uint8_t *measurement_value,
45 size_t measurement_value_size,
46 bool lock_measurement)
47{
48 INFO("Measured boot extend measurement:\n");
49 INFO(" - slot : %u\n", index);
50 INFO(" - signer_id :");
51 print_byte_array(signer_id, signer_id_size);
52 INFO(" - version : %s\n", version);
53 INFO(" - algorithm : %x\n", measurement_algo);
54 INFO(" - sw_type : %s\n", sw_type);
55 INFO(" - measurement :");
56 print_byte_array(measurement_value, measurement_value_size);
57 INFO(" - locking : %s\n", lock_measurement ? "true" : "false");
58}
59
Tamas Banc9ccc272022-01-18 16:20:47 +010060#if !PLAT_RSS_NOT_SUPPORTED
Tamas Banf5492752022-01-18 16:19:17 +010061psa_status_t
62rss_measured_boot_extend_measurement(uint8_t index,
63 const uint8_t *signer_id,
64 size_t signer_id_size,
65 const uint8_t *version,
66 size_t version_size,
67 uint32_t measurement_algo,
68 const uint8_t *sw_type,
69 size_t sw_type_size,
70 const uint8_t *measurement_value,
71 size_t measurement_value_size,
72 bool lock_measurement)
73{
74 struct measured_boot_extend_iovec_t extend_iov = {
75 .index = index,
76 .lock_measurement = lock_measurement,
77 .measurement_algo = measurement_algo,
78 .sw_type = {0},
79 .sw_type_size = sw_type_size,
80 };
81
82 psa_invec in_vec[] = {
83 {.base = &extend_iov,
84 .len = sizeof(struct measured_boot_extend_iovec_t)},
85 {.base = signer_id, .len = signer_id_size},
86 {.base = version, .len = version_size},
87 {.base = measurement_value, .len = measurement_value_size}
88 };
89
90 uint32_t sw_type_size_limited;
91
92 if (sw_type != NULL) {
93 sw_type_size_limited = (sw_type_size < SW_TYPE_MAX_SIZE) ?
94 sw_type_size : SW_TYPE_MAX_SIZE;
95 memcpy(extend_iov.sw_type, sw_type, sw_type_size_limited);
96 }
97
98 log_measurement(index, signer_id, signer_id_size,
99 version, measurement_algo, sw_type,
100 measurement_value, measurement_value_size,
101 lock_measurement);
102
103 return psa_call(RSS_MEASURED_BOOT_HANDLE,
104 RSS_MEASURED_BOOT_EXTEND,
105 in_vec, IOVEC_LEN(in_vec),
106 NULL, 0);
107}
Tamas Banc9ccc272022-01-18 16:20:47 +0100108
109#else /* !PLAT_RSS_NOT_SUPPORTED */
110
111psa_status_t
112rss_measured_boot_extend_measurement(uint8_t index,
113 const uint8_t *signer_id,
114 size_t signer_id_size,
115 const uint8_t *version,
116 size_t version_size,
117 uint32_t measurement_algo,
118 const uint8_t *sw_type,
119 size_t sw_type_size,
120 const uint8_t *measurement_value,
121 size_t measurement_value_size,
122 bool lock_measurement)
123{
124 log_measurement(index, signer_id, signer_id_size,
125 version, measurement_algo, sw_type,
126 measurement_value, measurement_value_size,
127 lock_measurement);
128
129 return PSA_SUCCESS;
130}
131#endif /* !PLAT_RSS_NOT_SUPPORTED */