Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 1 | /* |
Manish V Badarkhe | 37f9ac2 | 2023-03-12 21:34:44 +0000 | [diff] [blame] | 2 | * Copyright (c) 2022-2023, Arm Limited. All rights reserved. |
Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <string.h> |
| 9 | |
| 10 | #include <delegated_attestation.h> |
| 11 | #include <psa/client.h> |
| 12 | #include <psa_manifest/sid.h> |
| 13 | |
| 14 | #if !PLAT_RSS_NOT_SUPPORTED |
| 15 | psa_status_t |
| 16 | rss_delegated_attest_get_delegated_key(uint8_t ecc_curve, |
| 17 | uint32_t key_bits, |
| 18 | uint8_t *key_buf, |
| 19 | size_t key_buf_size, |
| 20 | size_t *key_size, |
| 21 | uint32_t hash_algo) |
| 22 | { |
| 23 | psa_status_t status; |
| 24 | psa_invec in_vec[] = { |
| 25 | {&ecc_curve, sizeof(ecc_curve)}, |
| 26 | {&key_bits, sizeof(key_bits)}, |
| 27 | {&hash_algo, sizeof(hash_algo)} |
| 28 | }; |
| 29 | psa_outvec out_vec[] = { |
| 30 | {key_buf, key_buf_size} |
| 31 | }; |
| 32 | |
| 33 | if (key_size == NULL) { |
| 34 | return PSA_ERROR_INVALID_ARGUMENT; |
| 35 | } |
| 36 | |
| 37 | status = psa_call(RSS_DELEGATED_SERVICE_HANDLE, |
| 38 | RSS_DELEGATED_ATTEST_GET_DELEGATED_KEY, |
| 39 | in_vec, IOVEC_LEN(in_vec), |
| 40 | out_vec, IOVEC_LEN(out_vec)); |
| 41 | if (status == PSA_SUCCESS) { |
| 42 | *key_size = out_vec[0].len; |
| 43 | } |
| 44 | |
| 45 | return status; |
| 46 | } |
| 47 | |
| 48 | psa_status_t |
| 49 | rss_delegated_attest_get_token(const uint8_t *dak_pub_hash, |
| 50 | size_t dak_pub_hash_size, |
| 51 | uint8_t *token_buf, |
| 52 | size_t token_buf_size, |
| 53 | size_t *token_size) |
| 54 | { |
| 55 | psa_status_t status; |
| 56 | psa_invec in_vec[] = { |
| 57 | {dak_pub_hash, dak_pub_hash_size} |
| 58 | }; |
| 59 | psa_outvec out_vec[] = { |
| 60 | {token_buf, token_buf_size} |
| 61 | }; |
| 62 | |
| 63 | if (token_size == NULL) { |
| 64 | return PSA_ERROR_INVALID_ARGUMENT; |
| 65 | } |
| 66 | |
| 67 | status = psa_call(RSS_DELEGATED_SERVICE_HANDLE, |
| 68 | RSS_DELEGATED_ATTEST_GET_PLATFORM_TOKEN, |
| 69 | in_vec, IOVEC_LEN(in_vec), |
| 70 | out_vec, IOVEC_LEN(out_vec)); |
| 71 | if (status == PSA_SUCCESS) { |
| 72 | *token_size = out_vec[0].len; |
| 73 | } |
| 74 | |
| 75 | return status; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | #else /* !PLAT_RSS_NOT_SUPPORTED */ |
| 80 | |
| 81 | static const uint8_t delegated_key[] = { |
| 82 | 0x20, 0x11, 0xC7, 0xF0, 0x3C, 0xEE, 0x43, 0x25, 0x17, 0x6E, |
| 83 | 0x52, 0x4F, 0x03, 0x3C, 0x0C, 0xE1, 0xE2, 0x1A, 0x76, 0xE6, |
| 84 | 0xC1, 0xA4, 0xF0, 0xB8, 0x39, 0xAA, 0x1D, 0xF6, 0x1E, 0x0E, |
| 85 | 0x8A, 0x5C, 0x8A, 0x05, 0x74, 0x0F, 0x9B, 0x69, 0xEF, 0xA7, |
| 86 | 0xEB, 0x1A, 0x41, 0x85, 0xBD, 0x11, 0x7F, 0x68 |
Sandrine Bailleux | b9333cb | 2022-10-11 14:45:18 +0200 | [diff] [blame] | 87 | }; |
Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 88 | |
| 89 | static const uint8_t platform_token[] = { |
Manish V Badarkhe | 37f9ac2 | 2023-03-12 21:34:44 +0000 | [diff] [blame] | 90 | 0xD2, 0x84, 0x44, 0xA1, 0x01, 0x38, 0x22, 0xA0, |
| 91 | 0x59, 0x02, 0x33, 0xA9, 0x19, 0x01, 0x09, 0x78, |
| 92 | 0x1C, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, |
| 93 | 0x61, 0x72, 0x6D, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, |
| 94 | 0x43, 0x43, 0x41, 0x2D, 0x53, 0x53, 0x44, 0x2F, |
| 95 | 0x31, 0x2E, 0x30, 0x2E, 0x30, 0x0A, 0x58, 0x20, |
| 96 | 0xB5, 0x97, 0x3C, 0xB6, 0x8B, 0xAA, 0x9F, 0xC5, |
| 97 | 0x55, 0x58, 0x78, 0x6B, 0x7E, 0xC6, 0x7F, 0x69, |
| 98 | 0xE4, 0x0D, 0xF5, 0xBA, 0x5A, 0xA9, 0x21, 0xCD, |
| 99 | 0x0C, 0x27, 0xF4, 0x05, 0x87, 0xA0, 0x11, 0xEA, |
| 100 | 0x19, 0x09, 0x5C, 0x58, 0x20, 0x7F, 0x45, 0x4C, |
| 101 | 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 102 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x3E, |
| 103 | 0x00, 0x01, 0x00, 0x00, 0x00, 0x50, 0x58, 0x00, |
| 104 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x01, 0x00, |
| 105 | 0x58, 0x21, 0x01, 0x07, 0x06, 0x05, 0x04, 0x03, |
| 106 | 0x02, 0x01, 0x00, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, |
| 107 | 0x0A, 0x09, 0x08, 0x17, 0x16, 0x15, 0x14, 0x13, |
| 108 | 0x12, 0x11, 0x10, 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, |
| 109 | 0x1A, 0x19, 0x18, 0x19, 0x09, 0x61, 0x58, 0x21, |
| 110 | 0x01, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, |
| 111 | 0x00, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, |
| 112 | 0x08, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, |
| 113 | 0x10, 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, |
| 114 | 0x18, 0x19, 0x09, 0x5B, 0x19, 0x30, 0x03, 0x19, |
| 115 | 0x09, 0x62, 0x67, 0x73, 0x68, 0x61, 0x2D, 0x32, |
| 116 | 0x35, 0x36, 0x19, 0x09, 0x5F, 0x84, 0xA5, 0x01, |
| 117 | 0x62, 0x42, 0x4C, 0x05, 0x58, 0x20, 0x07, 0x06, |
| 118 | 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0F, 0x0E, |
| 119 | 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x17, 0x16, |
| 120 | 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1F, 0x1E, |
| 121 | 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x04, 0x65, |
| 122 | 0x33, 0x2E, 0x34, 0x2E, 0x32, 0x02, 0x58, 0x20, |
| 123 | 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, |
| 124 | 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, |
| 125 | 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, |
| 126 | 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, |
| 127 | 0x06, 0x74, 0x54, 0x46, 0x2D, 0x4D, 0x5F, 0x53, |
| 128 | 0x48, 0x41, 0x32, 0x35, 0x36, 0x4D, 0x65, 0x6D, |
| 129 | 0x50, 0x72, 0x65, 0x58, 0x49, 0x50, 0xA4, 0x01, |
| 130 | 0x62, 0x4D, 0x31, 0x05, 0x58, 0x20, 0x07, 0x06, |
| 131 | 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0F, 0x0E, |
| 132 | 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x17, 0x16, |
| 133 | 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1F, 0x1E, |
| 134 | 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x04, 0x63, |
| 135 | 0x31, 0x2E, 0x32, 0x02, 0x58, 0x20, 0x07, 0x06, |
| 136 | 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0F, 0x0E, |
| 137 | 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x17, 0x16, |
| 138 | 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1F, 0x1E, |
| 139 | 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0xA4, 0x01, |
| 140 | 0x62, 0x4D, 0x32, 0x05, 0x58, 0x20, 0x07, 0x06, |
| 141 | 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0F, 0x0E, |
| 142 | 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x17, 0x16, |
| 143 | 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1F, 0x1E, |
| 144 | 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x04, 0x65, |
| 145 | 0x31, 0x2E, 0x32, 0x2E, 0x33, 0x02, 0x58, 0x20, |
| 146 | 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, |
| 147 | 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, |
| 148 | 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, |
| 149 | 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, |
| 150 | 0xA4, 0x01, 0x62, 0x4D, 0x33, 0x05, 0x58, 0x20, |
| 151 | 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, |
| 152 | 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, |
| 153 | 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, |
| 154 | 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, |
| 155 | 0x04, 0x61, 0x31, 0x02, 0x58, 0x20, 0x07, 0x06, |
| 156 | 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0F, 0x0E, |
| 157 | 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x17, 0x16, |
| 158 | 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1F, 0x1E, |
| 159 | 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x19, 0x09, |
| 160 | 0x60, 0x6C, 0x77, 0x68, 0x61, 0x74, 0x65, 0x76, |
| 161 | 0x65, 0x72, 0x2E, 0x63, 0x6F, 0x6D, 0x58, 0x60, |
| 162 | 0xE6, 0xB6, 0x38, 0x4F, 0xAE, 0x3F, 0x6E, 0x67, |
| 163 | 0xF5, 0xD4, 0x97, 0x4B, 0x3F, 0xFD, 0x0A, 0xFA, |
| 164 | 0x1D, 0xF0, 0x2F, 0x73, 0xB8, 0xFF, 0x5F, 0x02, |
| 165 | 0xC0, 0x0F, 0x40, 0xAC, 0xF3, 0xA2, 0x9D, 0xB5, |
| 166 | 0x31, 0x50, 0x16, 0x4F, 0xFA, 0x34, 0x3D, 0x0E, |
| 167 | 0xAF, 0xE0, 0xD0, 0xD1, 0x6C, 0xF0, 0x9D, 0xC1, |
| 168 | 0x01, 0x42, 0xA2, 0x3C, 0xCE, 0xD4, 0x4A, 0x59, |
| 169 | 0xDC, 0x29, 0x0A, 0x30, 0x93, 0x5F, 0xB4, 0x98, |
| 170 | 0x61, 0xBA, 0xE3, 0x91, 0x22, 0x95, 0x24, 0xF4, |
| 171 | 0xAE, 0x47, 0x93, 0xD3, 0x84, 0xA3, 0x76, 0xD0, |
| 172 | 0xC1, 0x26, 0x96, 0x53, 0xA3, 0x60, 0x3F, 0x6C, |
| 173 | 0x75, 0x96, 0x90, 0x6A, 0xF9, 0x4E, 0xDA, 0x30 |
Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | psa_status_t |
| 177 | rss_delegated_attest_get_delegated_key(uint8_t ecc_curve, |
| 178 | uint32_t key_bits, |
| 179 | uint8_t *key_buf, |
| 180 | size_t key_buf_size, |
| 181 | size_t *key_size, |
| 182 | uint32_t hash_algo) |
| 183 | { |
| 184 | (void)ecc_curve; |
| 185 | (void)key_bits; |
| 186 | (void)hash_algo; |
| 187 | |
| 188 | if (key_buf_size < sizeof(delegated_key)) { |
| 189 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 190 | } |
| 191 | |
| 192 | (void)memcpy(key_buf, delegated_key, sizeof(delegated_key)); |
| 193 | *key_size = sizeof(delegated_key); |
| 194 | |
| 195 | return PSA_SUCCESS; |
| 196 | } |
| 197 | psa_status_t |
| 198 | rss_delegated_attest_get_token(const uint8_t *dak_pub_hash, |
| 199 | size_t dak_pub_hash_size, |
| 200 | uint8_t *token_buf, |
| 201 | size_t token_buf_size, |
| 202 | size_t *token_size) |
| 203 | { |
| 204 | (void)dak_pub_hash; |
| 205 | (void)dak_pub_hash_size; |
| 206 | |
| 207 | if (token_buf_size < sizeof(platform_token)) { |
| 208 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 209 | } |
| 210 | |
| 211 | (void)memcpy(token_buf, platform_token, sizeof(platform_token)); |
| 212 | *token_size = sizeof(platform_token); |
| 213 | |
| 214 | return PSA_SUCCESS; |
| 215 | } |
| 216 | #endif /* !PLAT_RSS_NOT_SUPPORTED */ |