blob: 6e9ff78f260c10c228ae38c859932453706ed77f [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 */
Tamas Ban4ebcd582022-10-05 13:22:23 +020042 size_t version_size,
Tamas Banf5492752022-01-18 16:19:17 +010043 const uint8_t *sw_type, /* string */
Tamas Ban4ebcd582022-10-05 13:22:23 +020044 size_t sw_type_size,
45 uint32_t measurement_algo,
Tamas Banf5492752022-01-18 16:19:17 +010046 const uint8_t *measurement_value,
47 size_t measurement_value_size,
48 bool lock_measurement)
49{
50 INFO("Measured boot extend measurement:\n");
51 INFO(" - slot : %u\n", index);
52 INFO(" - signer_id :");
53 print_byte_array(signer_id, signer_id_size);
Tamas Ban4ebcd582022-10-05 13:22:23 +020054 INFO(" - version : %s\n", version);
55 INFO(" - version_size: %zu\n", version_size);
56 INFO(" - sw_type : %s\n", sw_type);
57 INFO(" - sw_type_size: %zu\n", sw_type_size);
Tamas Banf5492752022-01-18 16:19:17 +010058 INFO(" - algorithm : %x\n", measurement_algo);
Tamas Banf5492752022-01-18 16:19:17 +010059 INFO(" - measurement :");
60 print_byte_array(measurement_value, measurement_value_size);
61 INFO(" - locking : %s\n", lock_measurement ? "true" : "false");
62}
63
Tamas Banc9ccc272022-01-18 16:20:47 +010064#if !PLAT_RSS_NOT_SUPPORTED
Tamas Banf5492752022-01-18 16:19:17 +010065psa_status_t
66rss_measured_boot_extend_measurement(uint8_t index,
67 const uint8_t *signer_id,
68 size_t signer_id_size,
69 const uint8_t *version,
70 size_t version_size,
71 uint32_t measurement_algo,
72 const uint8_t *sw_type,
73 size_t sw_type_size,
74 const uint8_t *measurement_value,
75 size_t measurement_value_size,
76 bool lock_measurement)
77{
78 struct measured_boot_extend_iovec_t extend_iov = {
79 .index = index,
80 .lock_measurement = lock_measurement,
81 .measurement_algo = measurement_algo,
82 .sw_type = {0},
83 .sw_type_size = sw_type_size,
84 };
85
86 psa_invec in_vec[] = {
87 {.base = &extend_iov,
88 .len = sizeof(struct measured_boot_extend_iovec_t)},
89 {.base = signer_id, .len = signer_id_size},
90 {.base = version, .len = version_size},
91 {.base = measurement_value, .len = measurement_value_size}
92 };
93
Tamas Banf5492752022-01-18 16:19:17 +010094 if (sw_type != NULL) {
Tamas Banfc6ba272022-10-03 13:06:53 +020095 if (sw_type_size > SW_TYPE_MAX_SIZE) {
96 return PSA_ERROR_INVALID_ARGUMENT;
97 }
98 memcpy(extend_iov.sw_type, sw_type, sw_type_size);
Tamas Banf5492752022-01-18 16:19:17 +010099 }
100
101 log_measurement(index, signer_id, signer_id_size,
Tamas Ban4ebcd582022-10-05 13:22:23 +0200102 version, version_size, sw_type, sw_type_size,
103 measurement_algo, measurement_value,
104 measurement_value_size, lock_measurement);
Tamas Banf5492752022-01-18 16:19:17 +0100105
106 return psa_call(RSS_MEASURED_BOOT_HANDLE,
107 RSS_MEASURED_BOOT_EXTEND,
108 in_vec, IOVEC_LEN(in_vec),
109 NULL, 0);
110}
Tamas Banc9ccc272022-01-18 16:20:47 +0100111
112#else /* !PLAT_RSS_NOT_SUPPORTED */
113
114psa_status_t
115rss_measured_boot_extend_measurement(uint8_t index,
116 const uint8_t *signer_id,
117 size_t signer_id_size,
118 const uint8_t *version,
119 size_t version_size,
120 uint32_t measurement_algo,
121 const uint8_t *sw_type,
122 size_t sw_type_size,
123 const uint8_t *measurement_value,
124 size_t measurement_value_size,
125 bool lock_measurement)
126{
127 log_measurement(index, signer_id, signer_id_size,
Tamas Ban4ebcd582022-10-05 13:22:23 +0200128 version, version_size, sw_type, sw_type_size,
129 measurement_algo, measurement_value,
130 measurement_value_size, lock_measurement);
Tamas Banc9ccc272022-01-18 16:20:47 +0100131
132 return PSA_SUCCESS;
133}
134#endif /* !PLAT_RSS_NOT_SUPPORTED */