Tamas Ban | f549275 | 2022-01-18 16:19:17 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | static void print_byte_array(const uint8_t *array, size_t len) |
| 18 | { |
| 19 | unsigned int i; |
| 20 | |
| 21 | if (array == NULL || len == 0U) { |
| 22 | (void)printf("\n"); |
| 23 | } |
| 24 | |
| 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 | } |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | static void log_measurement(uint8_t index, |
| 37 | const uint8_t *signer_id, |
| 38 | size_t signer_id_size, |
| 39 | const uint8_t *version, /* string */ |
| 40 | uint32_t measurement_algo, |
| 41 | const uint8_t *sw_type, /* string */ |
| 42 | const uint8_t *measurement_value, |
| 43 | size_t measurement_value_size, |
| 44 | bool lock_measurement) |
| 45 | { |
| 46 | INFO("Measured boot extend measurement:\n"); |
| 47 | INFO(" - slot : %u\n", index); |
| 48 | INFO(" - signer_id :"); |
| 49 | print_byte_array(signer_id, signer_id_size); |
| 50 | INFO(" - version : %s\n", version); |
| 51 | INFO(" - algorithm : %x\n", measurement_algo); |
| 52 | INFO(" - sw_type : %s\n", sw_type); |
| 53 | INFO(" - measurement :"); |
| 54 | print_byte_array(measurement_value, measurement_value_size); |
| 55 | INFO(" - locking : %s\n", lock_measurement ? "true" : "false"); |
| 56 | } |
| 57 | |
Tamas Ban | c9ccc27 | 2022-01-18 16:20:47 +0100 | [diff] [blame] | 58 | #if !PLAT_RSS_NOT_SUPPORTED |
Tamas Ban | f549275 | 2022-01-18 16:19:17 +0100 | [diff] [blame] | 59 | psa_status_t |
| 60 | rss_measured_boot_extend_measurement(uint8_t index, |
| 61 | const uint8_t *signer_id, |
| 62 | size_t signer_id_size, |
| 63 | const uint8_t *version, |
| 64 | size_t version_size, |
| 65 | uint32_t measurement_algo, |
| 66 | const uint8_t *sw_type, |
| 67 | size_t sw_type_size, |
| 68 | const uint8_t *measurement_value, |
| 69 | size_t measurement_value_size, |
| 70 | bool lock_measurement) |
| 71 | { |
| 72 | struct measured_boot_extend_iovec_t extend_iov = { |
| 73 | .index = index, |
| 74 | .lock_measurement = lock_measurement, |
| 75 | .measurement_algo = measurement_algo, |
| 76 | .sw_type = {0}, |
| 77 | .sw_type_size = sw_type_size, |
| 78 | }; |
| 79 | |
| 80 | psa_invec in_vec[] = { |
| 81 | {.base = &extend_iov, |
| 82 | .len = sizeof(struct measured_boot_extend_iovec_t)}, |
| 83 | {.base = signer_id, .len = signer_id_size}, |
| 84 | {.base = version, .len = version_size}, |
| 85 | {.base = measurement_value, .len = measurement_value_size} |
| 86 | }; |
| 87 | |
| 88 | uint32_t sw_type_size_limited; |
| 89 | |
| 90 | if (sw_type != NULL) { |
| 91 | sw_type_size_limited = (sw_type_size < SW_TYPE_MAX_SIZE) ? |
| 92 | sw_type_size : SW_TYPE_MAX_SIZE; |
| 93 | memcpy(extend_iov.sw_type, sw_type, sw_type_size_limited); |
| 94 | } |
| 95 | |
| 96 | log_measurement(index, signer_id, signer_id_size, |
| 97 | version, measurement_algo, sw_type, |
| 98 | measurement_value, measurement_value_size, |
| 99 | lock_measurement); |
| 100 | |
| 101 | return psa_call(RSS_MEASURED_BOOT_HANDLE, |
| 102 | RSS_MEASURED_BOOT_EXTEND, |
| 103 | in_vec, IOVEC_LEN(in_vec), |
| 104 | NULL, 0); |
| 105 | } |
Tamas Ban | c9ccc27 | 2022-01-18 16:20:47 +0100 | [diff] [blame] | 106 | |
| 107 | #else /* !PLAT_RSS_NOT_SUPPORTED */ |
| 108 | |
| 109 | psa_status_t |
| 110 | rss_measured_boot_extend_measurement(uint8_t index, |
| 111 | const uint8_t *signer_id, |
| 112 | size_t signer_id_size, |
| 113 | const uint8_t *version, |
| 114 | size_t version_size, |
| 115 | uint32_t measurement_algo, |
| 116 | const uint8_t *sw_type, |
| 117 | size_t sw_type_size, |
| 118 | const uint8_t *measurement_value, |
| 119 | size_t measurement_value_size, |
| 120 | bool lock_measurement) |
| 121 | { |
| 122 | log_measurement(index, signer_id, signer_id_size, |
| 123 | version, measurement_algo, sw_type, |
| 124 | measurement_value, measurement_value_size, |
| 125 | lock_measurement); |
| 126 | |
| 127 | return PSA_SUCCESS; |
| 128 | } |
| 129 | #endif /* !PLAT_RSS_NOT_SUPPORTED */ |