blob: 399a3f102ca3e399cb3a7252185f1732f55ffbce [file] [log] [blame]
Tamas Ban3ae52c62022-08-31 14:50:27 +02001/*
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 <delegated_attestation.h>
11#include <psa/client.h>
12#include <psa_manifest/sid.h>
13
14#if !PLAT_RSS_NOT_SUPPORTED
15psa_status_t
16rss_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
48psa_status_t
49rss_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
81static 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 Bailleuxb9333cb2022-10-11 14:45:18 +020087};
Tamas Ban3ae52c62022-08-31 14:50:27 +020088
89static const uint8_t platform_token[] = {
90 0xD2, 0x84, 0x43, 0xA1, 0x01, 0x26, 0xA0, 0x59,
91 0x02, 0xBE, 0xAA, 0x3A, 0x00, 0x01, 0x24, 0xFF,
92 0x58, 0x20, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB,
93 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB,
94 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB,
95 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB,
96 0xAB, 0xAB, 0x3A, 0x00, 0x01, 0x24, 0xFB, 0x58,
97 0x20, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
98 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE,
99 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6,
100 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE,
101 0xBF, 0x3A, 0x00, 0x01, 0x25, 0x00, 0x58, 0x21,
102 0x01, 0xFA, 0x58, 0x75, 0x5F, 0x65, 0x86, 0x27,
103 0xCE, 0x54, 0x60, 0xF2, 0x9B, 0x75, 0x29, 0x67,
104 0x13, 0x24, 0x8C, 0xAE, 0x7A, 0xD9, 0xE2, 0x98,
105 0x4B, 0x90, 0x28, 0x0E, 0xFC, 0xBC, 0xB5, 0x02,
106 0x48, 0x3A, 0x00, 0x01, 0x24, 0xFA, 0x58, 0x20,
107 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
108 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
109 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
110 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
111 0x3A, 0x00, 0x01, 0x24, 0xF8, 0x20, 0x3A, 0x00,
112 0x01, 0x24, 0xF9, 0x00, 0x3A, 0x00, 0x01, 0x24,
113 0xFD, 0x85, 0xA5, 0x05, 0x58, 0x20, 0x00, 0x00,
114 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x60,
118 0x01, 0x65, 0x42, 0x4C, 0x31, 0x5F, 0x32, 0x06,
119 0x66, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36, 0x02,
120 0x58, 0x20, 0xF8, 0xB7, 0xCE, 0xAD, 0x9B, 0xE4,
121 0x5A, 0x8F, 0x5C, 0x52, 0x6F, 0x0C, 0x05, 0x25,
122 0x8F, 0xF3, 0xE9, 0x81, 0xDC, 0xBC, 0xF2, 0x05,
123 0x7F, 0x33, 0xF6, 0xBB, 0xDC, 0xD9, 0x4D, 0xA2,
124 0x34, 0x3A, 0xA5, 0x05, 0x58, 0x20, 0x00, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x67,
129 0x31, 0x2E, 0x37, 0x2E, 0x32, 0x2B, 0x30, 0x01,
130 0x63, 0x42, 0x4C, 0x32, 0x06, 0x66, 0x53, 0x48,
131 0x41, 0x32, 0x35, 0x36, 0x02, 0x58, 0x20, 0x3A,
132 0xE5, 0x9E, 0x40, 0xA9, 0x6B, 0xD5, 0x29, 0x1C,
133 0xAB, 0x7A, 0x5F, 0xBD, 0x1F, 0x9A, 0xA6, 0x52,
134 0xFB, 0x77, 0x7D, 0xA3, 0xEC, 0x9C, 0x29, 0xBC,
135 0xE6, 0x5B, 0x3B, 0x43, 0xFC, 0x9D, 0x26, 0xA5,
136 0x05, 0x58, 0x20, 0xBF, 0xE6, 0xD8, 0x6F, 0x88,
137 0x26, 0xF4, 0xFF, 0x97, 0xFB, 0x96, 0xC4, 0xE6,
138 0xFB, 0xC4, 0x99, 0x3E, 0x46, 0x19, 0xFC, 0x56,
139 0x5D, 0xA2, 0x6A, 0xDF, 0x34, 0xC3, 0x29, 0x48,
140 0x9A, 0xDC, 0x38, 0x04, 0x67, 0x31, 0x2E, 0x35,
141 0x2E, 0x30, 0x2B, 0x30, 0x01, 0x64, 0x52, 0x54,
142 0x5F, 0x30, 0x06, 0x66, 0x53, 0x48, 0x41, 0x32,
143 0x35, 0x36, 0x02, 0x58, 0x20, 0x47, 0x94, 0x9D,
144 0x27, 0x33, 0x82, 0x45, 0x1A, 0xDD, 0x25, 0xF4,
145 0x9A, 0x89, 0x6F, 0x5F, 0xD9, 0xB0, 0xE8, 0x14,
146 0xD3, 0xA4, 0x9B, 0x53, 0xB0, 0x44, 0x0B, 0xCF,
147 0x32, 0x1A, 0xC4, 0xD2, 0x65, 0xA5, 0x05, 0x58,
148 0x20, 0xB3, 0x60, 0xCA, 0xF5, 0xC9, 0x8C, 0x6B,
149 0x94, 0x2A, 0x48, 0x82, 0xFA, 0x9D, 0x48, 0x23,
150 0xEF, 0xB1, 0x66, 0xA9, 0xEF, 0x6A, 0x6E, 0x4A,
151 0xA3, 0x7C, 0x19, 0x19, 0xED, 0x1F, 0xCC, 0xC0,
152 0x49, 0x04, 0x67, 0x30, 0x2E, 0x30, 0x2E, 0x37,
153 0x2B, 0x30, 0x01, 0x64, 0x52, 0x54, 0x5F, 0x31,
154 0x06, 0x66, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36,
155 0x02, 0x58, 0x20, 0xCD, 0x38, 0xBE, 0xC8, 0xB7,
156 0xC0, 0x9E, 0xD5, 0x24, 0x30, 0xFE, 0xC8, 0xD0,
157 0x19, 0x12, 0x56, 0xB2, 0x7A, 0xA5, 0x53, 0x6F,
158 0xBC, 0x7D, 0x09, 0xCA, 0x11, 0xDD, 0x90, 0xD7,
159 0xD6, 0x70, 0xFD, 0xA5, 0x05, 0x58, 0x20, 0xAA,
160 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
161 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
162 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
163 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x04,
164 0x60, 0x01, 0x60, 0x06, 0x66, 0x53, 0x48, 0x41,
165 0x32, 0x35, 0x36, 0x02, 0x58, 0x20, 0x28, 0x3D,
166 0x0C, 0x25, 0x22, 0x0C, 0x87, 0x46, 0xA0, 0x58,
167 0x64, 0x6C, 0x0B, 0x14, 0x37, 0x39, 0x40, 0x9D,
168 0x2D, 0x11, 0xD1, 0xCC, 0x54, 0x51, 0xB4, 0x29,
169 0x22, 0xCD, 0x70, 0x92, 0x71, 0xC3, 0x3A, 0x00,
170 0x01, 0x25, 0x01, 0x77, 0x77, 0x77, 0x77, 0x2E,
171 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x66,
172 0x69, 0x72, 0x6D, 0x77, 0x61, 0x72, 0x65, 0x2E,
173 0x6F, 0x72, 0x67, 0x3A, 0x00, 0x01, 0x24, 0xF7,
174 0x71, 0x50, 0x53, 0x41, 0x5F, 0x49, 0x4F, 0x54,
175 0x5F, 0x50, 0x52, 0x4F, 0x46, 0x49, 0x4C, 0x45,
176 0x5F, 0x31, 0x3A, 0x00, 0x01, 0x24, 0xFC, 0x70,
177 0x30, 0x36, 0x30, 0x34, 0x35, 0x36, 0x35, 0x32,
178 0x37, 0x32, 0x38, 0x32, 0x39, 0x31, 0x30, 0x30,
179 0x58, 0x40, 0x1E, 0x0D, 0x2B, 0xD8, 0x7A, 0xC9,
180 0x2D, 0xCB, 0x73, 0xD1, 0x42, 0x2F, 0xBF, 0xDA,
181 0x24, 0x71, 0xE2, 0xAF, 0xEA, 0x48, 0x60, 0x17,
182 0x23, 0x75, 0x64, 0xAC, 0xCC, 0x23, 0xA2, 0x67,
183 0xC4, 0xE7, 0x8F, 0x1C, 0x7C, 0x68, 0x49, 0x42,
184 0x4D, 0xDA, 0xC6, 0xD6, 0x21, 0x1C, 0xAA, 0x00,
185 0xDA, 0x1E, 0x68, 0x56, 0xA3, 0x48, 0xEE, 0xA7,
186 0x92, 0xA9, 0x09, 0x83, 0x42, 0x04, 0x06, 0x9E,
187 0x62, 0xBB
188};
189
190psa_status_t
191rss_delegated_attest_get_delegated_key(uint8_t ecc_curve,
192 uint32_t key_bits,
193 uint8_t *key_buf,
194 size_t key_buf_size,
195 size_t *key_size,
196 uint32_t hash_algo)
197{
198 (void)ecc_curve;
199 (void)key_bits;
200 (void)hash_algo;
201
202 if (key_buf_size < sizeof(delegated_key)) {
203 return PSA_ERROR_BUFFER_TOO_SMALL;
204 }
205
206 (void)memcpy(key_buf, delegated_key, sizeof(delegated_key));
207 *key_size = sizeof(delegated_key);
208
209 return PSA_SUCCESS;
210}
211psa_status_t
212rss_delegated_attest_get_token(const uint8_t *dak_pub_hash,
213 size_t dak_pub_hash_size,
214 uint8_t *token_buf,
215 size_t token_buf_size,
216 size_t *token_size)
217{
218 (void)dak_pub_hash;
219 (void)dak_pub_hash_size;
220
221 if (token_buf_size < sizeof(platform_token)) {
222 return PSA_ERROR_BUFFER_TOO_SMALL;
223 }
224
225 (void)memcpy(token_buf, platform_token, sizeof(platform_token));
226 *token_size = sizeof(platform_token);
227
228 return PSA_SUCCESS;
229}
230#endif /* !PLAT_RSS_NOT_SUPPORTED */