Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2024 DMTF. All rights reserved.
4 : * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5 : **/
6 :
7 : #include "spdm_unit_test.h"
8 : #include "internal/libspdm_requester_lib.h"
9 : #include "internal/libspdm_responder_lib.h"
10 :
11 : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
12 :
13 : static size_t m_libspdm_local_buffer_size;
14 : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
15 : static uint8_t m_libspdm_zero_filled_buffer[LIBSPDM_MAX_HASH_SIZE];
16 :
17 : static libspdm_th_managed_buffer_t th_curr;
18 :
19 51 : static size_t libspdm_test_get_key_exchange_request_size(const void *spdm_context,
20 : const void *buffer,
21 : size_t buffer_size)
22 : {
23 : const spdm_key_exchange_request_t *spdm_request;
24 : size_t message_size;
25 : size_t dhe_key_size;
26 : uint16_t opaque_length;
27 :
28 51 : spdm_request = buffer;
29 51 : message_size = sizeof(spdm_message_header_t);
30 51 : if (buffer_size < message_size) {
31 0 : return buffer_size;
32 : }
33 :
34 51 : if (spdm_request->header.request_response_code != SPDM_KEY_EXCHANGE) {
35 1 : return buffer_size;
36 : }
37 :
38 50 : message_size = sizeof(spdm_key_exchange_request_t);
39 50 : if (buffer_size < message_size) {
40 0 : return buffer_size;
41 : }
42 :
43 50 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
44 50 : message_size += dhe_key_size + sizeof(uint16_t);
45 50 : if (buffer_size < message_size) {
46 0 : return buffer_size;
47 : }
48 :
49 50 : opaque_length =
50 50 : *(uint16_t *)((size_t)buffer +
51 50 : sizeof(spdm_key_exchange_request_t) + dhe_key_size);
52 50 : message_size += opaque_length;
53 50 : if (buffer_size < message_size) {
54 0 : return buffer_size;
55 : }
56 :
57 : /* Good message, return actual size*/
58 50 : return message_size;
59 : }
60 :
61 53 : static libspdm_return_t libspdm_requester_key_exchange_test_send_message(
62 : void *spdm_context, size_t request_size, const void *request,
63 : uint64_t timeout)
64 : {
65 : libspdm_test_context_t *spdm_test_context;
66 : size_t header_size;
67 : size_t message_size;
68 :
69 53 : spdm_test_context = libspdm_get_test_context();
70 53 : header_size = sizeof(libspdm_test_message_header_t);
71 53 : switch (spdm_test_context->case_id) {
72 1 : case 0x1:
73 1 : return LIBSPDM_STATUS_SEND_FAIL;
74 1 : case 0x2:
75 1 : m_libspdm_local_buffer_size = 0;
76 1 : message_size = libspdm_test_get_key_exchange_request_size(
77 : spdm_context, (const uint8_t *)request + header_size,
78 : request_size - header_size);
79 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
80 : (const uint8_t *)request + header_size, message_size);
81 1 : m_libspdm_local_buffer_size += message_size;
82 1 : return LIBSPDM_STATUS_SUCCESS;
83 0 : case 0x3:
84 0 : m_libspdm_local_buffer_size = 0;
85 0 : message_size = libspdm_test_get_key_exchange_request_size(
86 : spdm_context, (const uint8_t *)request + header_size,
87 : request_size - header_size);
88 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
89 : (const uint8_t *)request + header_size, message_size);
90 0 : m_libspdm_local_buffer_size += message_size;
91 0 : return LIBSPDM_STATUS_SUCCESS;
92 1 : case 0x4:
93 1 : m_libspdm_local_buffer_size = 0;
94 1 : message_size = libspdm_test_get_key_exchange_request_size(
95 : spdm_context, (const uint8_t *)request + header_size,
96 : request_size - header_size);
97 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
98 : (const uint8_t *)request + header_size, message_size);
99 1 : m_libspdm_local_buffer_size += message_size;
100 1 : return LIBSPDM_STATUS_SUCCESS;
101 1 : case 0x5:
102 1 : m_libspdm_local_buffer_size = 0;
103 1 : message_size = libspdm_test_get_key_exchange_request_size(
104 : spdm_context, (const uint8_t *)request + header_size,
105 : request_size - header_size);
106 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
107 : (const uint8_t *)request + header_size, message_size);
108 1 : m_libspdm_local_buffer_size += message_size;
109 1 : return LIBSPDM_STATUS_SUCCESS;
110 2 : case 0x6:
111 2 : m_libspdm_local_buffer_size = 0;
112 2 : message_size = libspdm_test_get_key_exchange_request_size(
113 : spdm_context, (const uint8_t *)request + header_size,
114 : request_size - header_size);
115 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
116 : (const uint8_t *)request + header_size, message_size);
117 2 : m_libspdm_local_buffer_size += message_size;
118 2 : return LIBSPDM_STATUS_SUCCESS;
119 1 : case 0x7:
120 1 : m_libspdm_local_buffer_size = 0;
121 1 : message_size = libspdm_test_get_key_exchange_request_size(
122 : spdm_context, (const uint8_t *)request + header_size,
123 : request_size - header_size);
124 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
125 : (const uint8_t *)request + header_size, message_size);
126 1 : m_libspdm_local_buffer_size += message_size;
127 1 : return LIBSPDM_STATUS_SUCCESS;
128 2 : case 0x8:
129 2 : m_libspdm_local_buffer_size = 0;
130 2 : message_size = libspdm_test_get_key_exchange_request_size(
131 : spdm_context, (const uint8_t *)request + header_size,
132 : request_size - header_size);
133 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
134 : (const uint8_t *)request + header_size, message_size);
135 2 : m_libspdm_local_buffer_size += message_size;
136 2 : return LIBSPDM_STATUS_SUCCESS;
137 2 : case 0x9: {
138 : static size_t sub_index = 0;
139 2 : if (sub_index == 0) {
140 1 : m_libspdm_local_buffer_size = 0;
141 1 : message_size = libspdm_test_get_key_exchange_request_size(
142 : spdm_context, (const uint8_t *)request + header_size,
143 : request_size - header_size);
144 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
145 : (const uint8_t *)request + header_size, message_size);
146 1 : m_libspdm_local_buffer_size += message_size;
147 1 : sub_index++;
148 : }
149 : }
150 2 : return LIBSPDM_STATUS_SUCCESS;
151 18 : case 0xA:
152 18 : m_libspdm_local_buffer_size = 0;
153 18 : message_size = libspdm_test_get_key_exchange_request_size(
154 : spdm_context, (const uint8_t *)request + header_size,
155 : request_size - header_size);
156 18 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
157 : (const uint8_t *)request + header_size, message_size);
158 18 : m_libspdm_local_buffer_size += message_size;
159 18 : return LIBSPDM_STATUS_SUCCESS;
160 1 : case 0xB:
161 1 : m_libspdm_local_buffer_size = 0;
162 1 : message_size = libspdm_test_get_key_exchange_request_size(
163 : spdm_context, (const uint8_t *)request + header_size,
164 : request_size - header_size);
165 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
166 : (const uint8_t *)request + header_size, message_size);
167 1 : m_libspdm_local_buffer_size += message_size;
168 1 : return LIBSPDM_STATUS_SUCCESS;
169 1 : case 0xC:
170 1 : m_libspdm_local_buffer_size = 0;
171 1 : message_size = libspdm_test_get_key_exchange_request_size(
172 : spdm_context, (const uint8_t *)request + header_size,
173 : request_size - header_size);
174 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
175 : (const uint8_t *)request + header_size, message_size);
176 1 : m_libspdm_local_buffer_size += message_size;
177 1 : return LIBSPDM_STATUS_SUCCESS;
178 1 : case 0xD:
179 1 : m_libspdm_local_buffer_size = 0;
180 1 : message_size = libspdm_test_get_key_exchange_request_size(
181 : spdm_context, (const uint8_t *)request + header_size,
182 : request_size - header_size);
183 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
184 : (const uint8_t *)request + header_size, message_size);
185 1 : m_libspdm_local_buffer_size += message_size;
186 1 : return LIBSPDM_STATUS_SUCCESS;
187 1 : case 0xE:
188 1 : m_libspdm_local_buffer_size = 0;
189 1 : message_size = libspdm_test_get_key_exchange_request_size(
190 : spdm_context, (const uint8_t *)request + header_size,
191 : request_size - header_size);
192 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
193 : (const uint8_t *)request + header_size, message_size);
194 1 : m_libspdm_local_buffer_size += message_size;
195 1 : return LIBSPDM_STATUS_SUCCESS;
196 1 : case 0xF:
197 1 : m_libspdm_local_buffer_size = 0;
198 1 : message_size = libspdm_test_get_key_exchange_request_size(
199 : spdm_context, (const uint8_t *)request + header_size,
200 : request_size - header_size);
201 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
202 : (const uint8_t *)request + header_size, message_size);
203 1 : m_libspdm_local_buffer_size += message_size;
204 1 : return LIBSPDM_STATUS_SUCCESS;
205 1 : case 0x10:
206 1 : m_libspdm_local_buffer_size = 0;
207 1 : message_size = libspdm_test_get_key_exchange_request_size(
208 : spdm_context, (const uint8_t *)request + header_size,
209 : request_size - header_size);
210 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
211 : (const uint8_t *)request + header_size, message_size);
212 1 : m_libspdm_local_buffer_size += message_size;
213 1 : return LIBSPDM_STATUS_SUCCESS;
214 1 : case 0x11:
215 1 : m_libspdm_local_buffer_size = 0;
216 1 : message_size = libspdm_test_get_key_exchange_request_size(
217 : spdm_context, (const uint8_t *)request + header_size,
218 : request_size - header_size);
219 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
220 : (const uint8_t *)request + header_size, message_size);
221 1 : m_libspdm_local_buffer_size += message_size;
222 1 : return LIBSPDM_STATUS_SUCCESS;
223 1 : case 0x12:
224 1 : m_libspdm_local_buffer_size = 0;
225 1 : message_size = libspdm_test_get_key_exchange_request_size(
226 : spdm_context, (const uint8_t *)request + header_size,
227 : request_size - header_size);
228 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
229 : (const uint8_t *)request + header_size, message_size);
230 1 : m_libspdm_local_buffer_size += message_size;
231 1 : return LIBSPDM_STATUS_SUCCESS;
232 1 : case 0x13:
233 1 : m_libspdm_local_buffer_size = 0;
234 1 : message_size = libspdm_test_get_key_exchange_request_size(
235 : spdm_context, (const uint8_t *)request + header_size,
236 : request_size - header_size);
237 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
238 : (const uint8_t *)request + header_size, message_size);
239 1 : m_libspdm_local_buffer_size += message_size;
240 1 : return LIBSPDM_STATUS_SUCCESS;
241 1 : case 0x14:
242 1 : m_libspdm_local_buffer_size = 0;
243 1 : message_size = libspdm_test_get_key_exchange_request_size(
244 : spdm_context, (const uint8_t *)request + header_size,
245 : request_size - header_size);
246 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
247 : (const uint8_t *)request + header_size, message_size);
248 1 : m_libspdm_local_buffer_size += message_size;
249 1 : return LIBSPDM_STATUS_SUCCESS;
250 1 : case 0x15:
251 1 : m_libspdm_local_buffer_size = 0;
252 1 : message_size = libspdm_test_get_key_exchange_request_size(
253 : spdm_context, (const uint8_t *)request + header_size,
254 : request_size - header_size);
255 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
256 : (const uint8_t *)request + header_size, message_size);
257 1 : m_libspdm_local_buffer_size += message_size;
258 1 : return LIBSPDM_STATUS_SUCCESS;
259 1 : case 0x16:
260 1 : m_libspdm_local_buffer_size = 0;
261 1 : message_size = libspdm_test_get_key_exchange_request_size(
262 : spdm_context, (const uint8_t *)request + header_size,
263 : request_size - header_size);
264 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
265 : (const uint8_t *)request + header_size, message_size);
266 1 : m_libspdm_local_buffer_size += message_size;
267 1 : return LIBSPDM_STATUS_SUCCESS;
268 1 : case 0x17:
269 1 : m_libspdm_local_buffer_size = 0;
270 1 : message_size = libspdm_test_get_key_exchange_request_size(
271 : spdm_context, (const uint8_t *)request + header_size,
272 : request_size - header_size);
273 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
274 : (const uint8_t *)request + header_size, message_size);
275 1 : m_libspdm_local_buffer_size += message_size;
276 1 : return LIBSPDM_STATUS_SUCCESS;
277 1 : case 0x18:
278 1 : m_libspdm_local_buffer_size = 0;
279 1 : message_size = libspdm_test_get_key_exchange_request_size(
280 : spdm_context, (const uint8_t *)request + header_size,
281 : request_size - header_size);
282 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
283 : (const uint8_t *)request + header_size, message_size);
284 1 : m_libspdm_local_buffer_size += message_size;
285 1 : return LIBSPDM_STATUS_SUCCESS;
286 1 : case 0x19:
287 1 : m_libspdm_local_buffer_size = 0;
288 1 : message_size = libspdm_test_get_key_exchange_request_size(
289 : spdm_context, (const uint8_t *)request + header_size,
290 : request_size - header_size);
291 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
292 : (const uint8_t *)request + header_size, message_size);
293 1 : m_libspdm_local_buffer_size += message_size;
294 1 : return LIBSPDM_STATUS_SUCCESS;
295 1 : case 0x1A:
296 1 : m_libspdm_local_buffer_size = 0;
297 1 : message_size = libspdm_test_get_key_exchange_request_size(
298 : spdm_context, (const uint8_t *)request + header_size,
299 : request_size - header_size);
300 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
301 : (const uint8_t *)request + header_size, message_size);
302 1 : m_libspdm_local_buffer_size += message_size;
303 1 : return LIBSPDM_STATUS_SUCCESS;
304 1 : case 0x1B:
305 1 : m_libspdm_local_buffer_size = 0;
306 1 : message_size = libspdm_test_get_key_exchange_request_size(
307 : spdm_context, (const uint8_t *)request + header_size,
308 : request_size - header_size);
309 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
310 : (const uint8_t *)request + header_size, message_size);
311 1 : m_libspdm_local_buffer_size += message_size;
312 1 : return LIBSPDM_STATUS_SUCCESS;
313 1 : case 0x1C:
314 1 : m_libspdm_local_buffer_size = 0;
315 1 : message_size = libspdm_test_get_key_exchange_request_size(
316 : spdm_context, (const uint8_t *)request + header_size,
317 : request_size - header_size);
318 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
319 : (const uint8_t *)request + header_size, message_size);
320 1 : m_libspdm_local_buffer_size += message_size;
321 1 : return LIBSPDM_STATUS_SUCCESS;
322 1 : case 0x1D:
323 1 : m_libspdm_local_buffer_size = 0;
324 1 : message_size = libspdm_test_get_key_exchange_request_size(
325 : spdm_context, (const uint8_t *)request + header_size,
326 : request_size - header_size);
327 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
328 : (const uint8_t *)request + header_size, message_size);
329 1 : m_libspdm_local_buffer_size += message_size;
330 1 : return LIBSPDM_STATUS_SUCCESS;
331 1 : case 0x1E:
332 1 : m_libspdm_local_buffer_size = 0;
333 1 : message_size = libspdm_test_get_key_exchange_request_size(
334 : spdm_context, (const uint8_t *)request + header_size,
335 : request_size - header_size);
336 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
337 : (const uint8_t *)request + header_size, message_size);
338 1 : m_libspdm_local_buffer_size += message_size;
339 1 : return LIBSPDM_STATUS_SUCCESS;
340 1 : case 0x1F:
341 1 : m_libspdm_local_buffer_size = 0;
342 1 : message_size = libspdm_test_get_key_exchange_request_size(
343 : spdm_context, (const uint8_t *)request + header_size,
344 : request_size - header_size);
345 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
346 : (const uint8_t *)request + header_size, message_size);
347 1 : m_libspdm_local_buffer_size += message_size;
348 1 : return LIBSPDM_STATUS_SUCCESS;
349 1 : case 0x20:
350 1 : m_libspdm_local_buffer_size = 0;
351 1 : message_size = libspdm_test_get_key_exchange_request_size(
352 : spdm_context, (const uint8_t *)request + header_size,
353 : request_size - header_size);
354 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
355 : (const uint8_t *)request + header_size, message_size);
356 1 : m_libspdm_local_buffer_size += message_size;
357 1 : return LIBSPDM_STATUS_SUCCESS;
358 1 : case 0x21:
359 1 : m_libspdm_local_buffer_size = 0;
360 1 : message_size = libspdm_test_get_key_exchange_request_size(
361 : spdm_context, (const uint8_t *)request + header_size,
362 : request_size - header_size);
363 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
364 : (const uint8_t *)request + header_size, message_size);
365 1 : m_libspdm_local_buffer_size += message_size;
366 1 : return LIBSPDM_STATUS_SUCCESS;
367 1 : case 0x22:
368 1 : m_libspdm_local_buffer_size = 0;
369 1 : message_size = libspdm_test_get_key_exchange_request_size(
370 : spdm_context, (const uint8_t *)request + header_size,
371 : request_size - header_size);
372 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
373 : (const uint8_t *)request + header_size, message_size);
374 1 : m_libspdm_local_buffer_size += message_size;
375 1 : return LIBSPDM_STATUS_SUCCESS;
376 0 : default:
377 0 : return LIBSPDM_STATUS_SEND_FAIL;
378 : }
379 : }
380 :
381 52 : static libspdm_return_t libspdm_requester_key_exchange_test_receive_message(
382 : void *spdm_context, size_t *response_size,
383 : void **response, uint64_t timeout)
384 : {
385 : libspdm_test_context_t *spdm_test_context;
386 :
387 52 : spdm_test_context = libspdm_get_test_context();
388 52 : switch (spdm_test_context->case_id) {
389 0 : case 0x1:
390 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
391 :
392 1 : case 0x2: {
393 : spdm_key_exchange_response_t *spdm_response;
394 : size_t dhe_key_size;
395 : uint32_t hash_size;
396 : size_t signature_size;
397 : uint32_t hmac_size;
398 : uint8_t *ptr;
399 : void *dhe_context;
400 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
401 : size_t final_key_size;
402 : size_t opaque_key_exchange_rsp_size;
403 : void *data;
404 : size_t data_size;
405 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
406 : uint8_t *cert_buffer;
407 : size_t cert_buffer_size;
408 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
409 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
410 : uint8_t bin_str0[128];
411 : size_t bin_str0_size;
412 : uint8_t bin_str2[128];
413 : size_t bin_str2_size;
414 : uint8_t bin_str7[128];
415 : size_t bin_str7_size;
416 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
417 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
418 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
419 : size_t spdm_response_size;
420 : size_t transport_header_size;
421 :
422 1 : ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
423 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
424 : ((libspdm_context_t *)spdm_context)
425 1 : ->connection_info.algorithm.base_asym_algo =
426 : m_libspdm_use_asym_algo;
427 : ((libspdm_context_t *)spdm_context)
428 1 : ->connection_info.algorithm.base_hash_algo =
429 : m_libspdm_use_hash_algo;
430 : ((libspdm_context_t *)spdm_context)
431 1 : ->connection_info.algorithm.dhe_named_group =
432 : m_libspdm_use_dhe_algo;
433 : ((libspdm_context_t *)spdm_context)
434 1 : ->connection_info.algorithm.measurement_hash_algo =
435 : m_libspdm_use_measurement_hash_algo;
436 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
437 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
438 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
439 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
440 1 : opaque_key_exchange_rsp_size =
441 1 : libspdm_get_opaque_data_version_selection_data_size(
442 : spdm_context);
443 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
444 1 : dhe_key_size + 0 + sizeof(uint16_t) +
445 1 : opaque_key_exchange_rsp_size + signature_size +
446 : hmac_size;
447 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
448 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
449 :
450 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
451 1 : spdm_response->header.request_response_code =
452 : SPDM_KEY_EXCHANGE_RSP;
453 1 : spdm_response->header.param1 = 0;
454 1 : spdm_response->rsp_session_id =
455 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
456 1 : spdm_response->mut_auth_requested = 0;
457 1 : spdm_response->req_slot_id_param = 0;
458 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
459 1 : spdm_response->random_data);
460 1 : ptr = (void *)(spdm_response + 1);
461 1 : dhe_context = libspdm_dhe_new(
462 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
463 : m_libspdm_use_dhe_algo,
464 : true);
465 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
466 : &dhe_key_size);
467 1 : final_key_size = sizeof(final_key);
468 1 : libspdm_dhe_compute_key(
469 : m_libspdm_use_dhe_algo, dhe_context,
470 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
471 : sizeof(spdm_key_exchange_request_t),
472 : dhe_key_size, final_key, &final_key_size);
473 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
474 1 : ptr += dhe_key_size;
475 : /* libspdm_zero_mem (ptr, hash_size);
476 : * ptr += hash_size;*/
477 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
478 1 : ptr += sizeof(uint16_t);
479 1 : libspdm_build_opaque_data_version_selection_data(
480 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
481 1 : ptr += opaque_key_exchange_rsp_size;
482 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
483 : m_libspdm_use_asym_algo, &data,
484 : &data_size, NULL, NULL);
485 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
486 : sizeof(m_libspdm_local_buffer)
487 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
488 : m_libspdm_local_buffer),
489 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
490 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
491 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
492 : m_libspdm_local_buffer_size));
493 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
494 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
495 1 : cert_buffer = (uint8_t *)data;
496 1 : cert_buffer_size = data_size;
497 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
498 : cert_buffer_hash);
499 : /* transcript.message_a size is 0*/
500 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
501 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
502 : m_libspdm_local_buffer_size);
503 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
504 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
505 1 : free(data);
506 1 : libspdm_responder_data_sign(
507 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
508 : spdm_context,
509 : #endif
510 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
511 : SPDM_KEY_EXCHANGE_RSP,
512 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
513 1 : false, libspdm_get_managed_buffer(&th_curr),
514 : libspdm_get_managed_buffer_size(&th_curr), ptr,
515 : &signature_size);
516 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
517 : sizeof(m_libspdm_local_buffer)
518 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
519 : m_libspdm_local_buffer),
520 : ptr, signature_size);
521 1 : m_libspdm_local_buffer_size += signature_size;
522 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
523 1 : ptr += signature_size;
524 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
525 : libspdm_get_managed_buffer_size(&th_curr),
526 : th_curr_hash_data);
527 1 : bin_str0_size = sizeof(bin_str0);
528 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
529 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
530 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
531 : &bin_str0_size);
532 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
533 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
534 1 : bin_str2_size = sizeof(bin_str2);
535 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
536 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
537 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
538 : bin_str2, &bin_str2_size);
539 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
540 : bin_str2, bin_str2_size,
541 : response_handshake_secret, hash_size);
542 1 : bin_str7_size = sizeof(bin_str7);
543 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
544 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
545 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
546 : &bin_str7_size);
547 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
548 : hash_size, bin_str7, bin_str7_size,
549 : response_finished_key, hash_size);
550 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
551 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
552 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
553 : response_finished_key, hash_size, ptr);
554 1 : ptr += hmac_size;
555 :
556 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
557 : false, spdm_response_size,
558 : spdm_response, response_size,
559 : response);
560 : }
561 1 : return LIBSPDM_STATUS_SUCCESS;
562 :
563 0 : case 0x3: {
564 : spdm_key_exchange_response_t *spdm_response;
565 : size_t dhe_key_size;
566 : uint32_t hash_size;
567 : size_t signature_size;
568 : uint32_t hmac_size;
569 : uint8_t *ptr;
570 : void *dhe_context;
571 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
572 : size_t final_key_size;
573 : size_t opaque_key_exchange_rsp_size;
574 : void *data;
575 : size_t data_size;
576 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
577 : uint8_t *cert_buffer;
578 : size_t cert_buffer_size;
579 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
580 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
581 : uint8_t bin_str0[128];
582 : size_t bin_str0_size;
583 : uint8_t bin_str2[128];
584 : size_t bin_str2_size;
585 : uint8_t bin_str7[128];
586 : size_t bin_str7_size;
587 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
588 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
589 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
590 : size_t spdm_response_size;
591 : size_t transport_header_size;
592 :
593 : ((libspdm_context_t *)spdm_context)
594 0 : ->connection_info.algorithm.base_asym_algo =
595 : m_libspdm_use_asym_algo;
596 : ((libspdm_context_t *)spdm_context)
597 0 : ->connection_info.algorithm.base_hash_algo =
598 : m_libspdm_use_hash_algo;
599 : ((libspdm_context_t *)spdm_context)
600 0 : ->connection_info.algorithm.dhe_named_group =
601 : m_libspdm_use_dhe_algo;
602 : ((libspdm_context_t *)spdm_context)
603 0 : ->connection_info.algorithm.measurement_hash_algo =
604 : m_libspdm_use_measurement_hash_algo;
605 0 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
606 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
607 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
608 0 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
609 0 : opaque_key_exchange_rsp_size =
610 0 : libspdm_get_opaque_data_version_selection_data_size(
611 : spdm_context);
612 0 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
613 0 : dhe_key_size + 0 + sizeof(uint16_t) +
614 0 : opaque_key_exchange_rsp_size + signature_size +
615 : hmac_size;
616 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
617 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
618 :
619 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
620 0 : spdm_response->header.request_response_code =
621 : SPDM_KEY_EXCHANGE_RSP;
622 0 : spdm_response->header.param1 = 0;
623 0 : spdm_response->rsp_session_id =
624 0 : libspdm_allocate_rsp_session_id(spdm_context, false);
625 0 : spdm_response->mut_auth_requested = 0;
626 0 : spdm_response->req_slot_id_param = 0;
627 0 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
628 0 : spdm_response->random_data);
629 0 : ptr = (void *)(spdm_response + 1);
630 0 : dhe_context = libspdm_dhe_new(
631 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
632 : m_libspdm_use_dhe_algo,
633 : true);
634 0 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
635 : &dhe_key_size);
636 0 : final_key_size = sizeof(final_key);
637 0 : libspdm_dhe_compute_key(
638 : m_libspdm_use_dhe_algo, dhe_context,
639 0 : (uint8_t *)&m_libspdm_local_buffer[0] +
640 : sizeof(spdm_key_exchange_request_t),
641 : dhe_key_size, final_key, &final_key_size);
642 0 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
643 0 : ptr += dhe_key_size;
644 : /* libspdm_zero_mem (ptr, hash_size);
645 : * ptr += hash_size;*/
646 0 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
647 0 : ptr += sizeof(uint16_t);
648 0 : libspdm_build_opaque_data_version_selection_data(
649 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
650 0 : ptr += opaque_key_exchange_rsp_size;
651 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
652 : m_libspdm_use_asym_algo, &data,
653 : &data_size, NULL, NULL);
654 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
655 : sizeof(m_libspdm_local_buffer)
656 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
657 : m_libspdm_local_buffer),
658 0 : spdm_response, (size_t)ptr - (size_t)spdm_response);
659 0 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
660 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
661 : m_libspdm_local_buffer_size));
662 0 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
663 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
664 0 : cert_buffer = (uint8_t *)data;
665 0 : cert_buffer_size = data_size;
666 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
667 : cert_buffer_hash);
668 : /* transcript.message_a size is 0*/
669 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
670 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
671 : m_libspdm_local_buffer_size);
672 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
673 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
674 0 : free(data);
675 0 : libspdm_responder_data_sign(
676 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
677 : spdm_context,
678 : #endif
679 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
680 : SPDM_KEY_EXCHANGE_RSP,
681 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
682 0 : false, libspdm_get_managed_buffer(&th_curr),
683 : libspdm_get_managed_buffer_size(&th_curr), ptr,
684 : &signature_size);
685 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
686 : sizeof(m_libspdm_local_buffer)
687 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
688 : m_libspdm_local_buffer),
689 : ptr, signature_size);
690 0 : m_libspdm_local_buffer_size += signature_size;
691 0 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
692 0 : ptr += signature_size;
693 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
694 : libspdm_get_managed_buffer_size(&th_curr),
695 : th_curr_hash_data);
696 0 : bin_str0_size = sizeof(bin_str0);
697 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
698 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
699 0 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
700 : &bin_str0_size);
701 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
702 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
703 0 : bin_str2_size = sizeof(bin_str2);
704 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
705 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
706 0 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
707 : bin_str2, &bin_str2_size);
708 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
709 : bin_str2, bin_str2_size,
710 : response_handshake_secret, hash_size);
711 0 : bin_str7_size = sizeof(bin_str7);
712 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
713 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
714 0 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
715 : &bin_str7_size);
716 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
717 : hash_size, bin_str7, bin_str7_size,
718 : response_finished_key, hash_size);
719 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
720 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
721 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
722 : response_finished_key, hash_size, ptr);
723 0 : ptr += hmac_size;
724 :
725 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
726 : false, spdm_response_size,
727 : spdm_response, response_size,
728 : response);
729 : }
730 0 : return LIBSPDM_STATUS_SUCCESS;
731 :
732 1 : case 0x4: {
733 : spdm_error_response_t *spdm_response;
734 : size_t spdm_response_size;
735 : size_t transport_header_size;
736 :
737 1 : spdm_response_size = sizeof(spdm_error_response_t);
738 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
739 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
740 :
741 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
742 1 : spdm_response->header.request_response_code = SPDM_ERROR;
743 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
744 1 : spdm_response->header.param2 = 0;
745 :
746 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
747 : false, spdm_response_size,
748 : spdm_response,
749 : response_size, response);
750 : }
751 1 : return LIBSPDM_STATUS_SUCCESS;
752 :
753 1 : case 0x5: {
754 : spdm_error_response_t *spdm_response;
755 : size_t spdm_response_size;
756 : size_t transport_header_size;
757 :
758 1 : spdm_response_size = sizeof(spdm_error_response_t);
759 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
760 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
761 :
762 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
763 1 : spdm_response->header.request_response_code = SPDM_ERROR;
764 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
765 1 : spdm_response->header.param2 = 0;
766 :
767 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
768 : false, spdm_response_size,
769 : spdm_response,
770 : response_size, response);
771 : }
772 1 : return LIBSPDM_STATUS_SUCCESS;
773 :
774 2 : case 0x6: {
775 : static size_t sub_index1 = 0;
776 2 : if (sub_index1 == 0) {
777 : spdm_error_response_t *spdm_response;
778 : size_t spdm_response_size;
779 : size_t transport_header_size;
780 :
781 1 : spdm_response_size = sizeof(spdm_error_response_t);
782 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
783 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
784 :
785 1 : spdm_response->header.spdm_version =
786 : SPDM_MESSAGE_VERSION_11;
787 1 : spdm_response->header.request_response_code = SPDM_ERROR;
788 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
789 1 : spdm_response->header.param2 = 0;
790 :
791 1 : libspdm_transport_test_encode_message(
792 : spdm_context, NULL, false, false,
793 : spdm_response_size, spdm_response,
794 : response_size, response);
795 1 : sub_index1++;
796 1 : } else if (sub_index1 == 1) {
797 : spdm_key_exchange_response_t *spdm_response;
798 : size_t dhe_key_size;
799 : uint32_t hash_size;
800 : size_t signature_size;
801 : uint32_t hmac_size;
802 : uint8_t *ptr;
803 : void *dhe_context;
804 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
805 : size_t final_key_size;
806 : size_t opaque_key_exchange_rsp_size;
807 : void *data;
808 : size_t data_size;
809 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
810 : uint8_t *cert_buffer;
811 : size_t cert_buffer_size;
812 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
813 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
814 : uint8_t bin_str0[128];
815 : size_t bin_str0_size;
816 : uint8_t bin_str2[128];
817 : size_t bin_str2_size;
818 : uint8_t bin_str7[128];
819 : size_t bin_str7_size;
820 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
821 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
822 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
823 : size_t spdm_response_size;
824 : size_t transport_header_size;
825 :
826 : ((libspdm_context_t *)spdm_context)
827 1 : ->connection_info.algorithm.base_asym_algo =
828 : m_libspdm_use_asym_algo;
829 : ((libspdm_context_t *)spdm_context)
830 1 : ->connection_info.algorithm.base_hash_algo =
831 : m_libspdm_use_hash_algo;
832 : ((libspdm_context_t *)spdm_context)
833 1 : ->connection_info.algorithm.dhe_named_group =
834 : m_libspdm_use_dhe_algo;
835 : ((libspdm_context_t *)spdm_context)
836 : ->connection_info.algorithm
837 1 : .measurement_hash_algo =
838 : m_libspdm_use_measurement_hash_algo;
839 1 : signature_size =
840 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
841 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
842 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
843 1 : dhe_key_size =
844 1 : libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
845 1 : opaque_key_exchange_rsp_size =
846 1 : libspdm_get_opaque_data_version_selection_data_size(
847 : spdm_context);
848 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
849 1 : dhe_key_size + 0 + sizeof(uint16_t) +
850 1 : opaque_key_exchange_rsp_size +
851 1 : signature_size + hmac_size;
852 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
853 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
854 :
855 1 : spdm_response->header.spdm_version =
856 : SPDM_MESSAGE_VERSION_11;
857 1 : spdm_response->header.request_response_code =
858 : SPDM_KEY_EXCHANGE_RSP;
859 1 : spdm_response->header.param1 = 0;
860 1 : spdm_response->rsp_session_id =
861 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
862 1 : spdm_response->mut_auth_requested = 0;
863 1 : spdm_response->req_slot_id_param = 0;
864 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
865 1 : spdm_response->random_data);
866 1 : ptr = (void *)(spdm_response + 1);
867 1 : dhe_context = libspdm_dhe_new(
868 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
869 : m_libspdm_use_dhe_algo, true);
870 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
871 : &dhe_key_size);
872 1 : final_key_size = sizeof(final_key);
873 1 : libspdm_dhe_compute_key(
874 : m_libspdm_use_dhe_algo, dhe_context,
875 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
876 : sizeof(spdm_key_exchange_request_t),
877 : dhe_key_size, final_key, &final_key_size);
878 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
879 1 : ptr += dhe_key_size;
880 : /* libspdm_zero_mem (ptr, hash_size);
881 : * ptr += hash_size;*/
882 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
883 1 : ptr += sizeof(uint16_t);
884 1 : libspdm_build_opaque_data_version_selection_data(
885 : spdm_context, &opaque_key_exchange_rsp_size,
886 : ptr);
887 1 : ptr += opaque_key_exchange_rsp_size;
888 1 : libspdm_read_responder_public_certificate_chain(
889 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
890 : &data_size, NULL, NULL);
891 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
892 : sizeof(m_libspdm_local_buffer)
893 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
894 : m_libspdm_local_buffer),
895 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
896 1 : m_libspdm_local_buffer_size +=
897 1 : ((size_t)ptr - (size_t)spdm_response);
898 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
899 : m_libspdm_local_buffer_size));
900 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
901 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
902 1 : cert_buffer = (uint8_t *)data;
903 1 : cert_buffer_size = data_size;
904 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
905 : cert_buffer_size, cert_buffer_hash);
906 : /* transcript.message_a size is 0*/
907 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash,
908 : hash_size);
909 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
910 : m_libspdm_local_buffer_size);
911 2 : libspdm_hash_all(m_libspdm_use_hash_algo,
912 1 : libspdm_get_managed_buffer(&th_curr),
913 : libspdm_get_managed_buffer_size(&th_curr),
914 : hash_data);
915 1 : free(data);
916 1 : libspdm_responder_data_sign(
917 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
918 : spdm_context,
919 : #endif
920 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
921 : SPDM_KEY_EXCHANGE_RSP,
922 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
923 1 : false, libspdm_get_managed_buffer(&th_curr),
924 : libspdm_get_managed_buffer_size(&th_curr), ptr,
925 : &signature_size);
926 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
927 : sizeof(m_libspdm_local_buffer)
928 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
929 : m_libspdm_local_buffer),
930 : ptr, signature_size);
931 1 : m_libspdm_local_buffer_size += signature_size;
932 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
933 1 : ptr += signature_size;
934 2 : libspdm_hash_all(m_libspdm_use_hash_algo,
935 1 : libspdm_get_managed_buffer(&th_curr),
936 : libspdm_get_managed_buffer_size(&th_curr),
937 : th_curr_hash_data);
938 1 : bin_str0_size = sizeof(bin_str0);
939 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
940 : SPDM_BIN_STR_0_LABEL,
941 : sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
942 1 : (uint16_t)hash_size, hash_size, bin_str0,
943 : &bin_str0_size);
944 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
945 : m_libspdm_zero_filled_buffer, hash_size, handshake_secret);
946 1 : bin_str2_size = sizeof(bin_str2);
947 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
948 : SPDM_BIN_STR_2_LABEL,
949 : sizeof(SPDM_BIN_STR_2_LABEL) - 1,
950 1 : th_curr_hash_data, (uint16_t)hash_size,
951 : hash_size, bin_str2, &bin_str2_size);
952 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret,
953 : hash_size, bin_str2, bin_str2_size,
954 : response_handshake_secret, hash_size);
955 1 : bin_str7_size = sizeof(bin_str7);
956 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
957 : SPDM_BIN_STR_7_LABEL,
958 : sizeof(SPDM_BIN_STR_7_LABEL) - 1, NULL,
959 1 : (uint16_t)hash_size, hash_size, bin_str7,
960 : &bin_str7_size);
961 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo,
962 : response_handshake_secret, hash_size,
963 : bin_str7, bin_str7_size,
964 : response_finished_key, hash_size);
965 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
966 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
967 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
968 : response_finished_key, hash_size, ptr);
969 1 : ptr += hmac_size;
970 :
971 1 : libspdm_transport_test_encode_message(
972 : spdm_context, NULL, false, false, spdm_response_size,
973 : spdm_response, response_size, response);
974 : }
975 : }
976 2 : return LIBSPDM_STATUS_SUCCESS;
977 :
978 1 : case 0x7: {
979 : spdm_error_response_t *spdm_response;
980 : size_t spdm_response_size;
981 : size_t transport_header_size;
982 :
983 1 : spdm_response_size = sizeof(spdm_error_response_t);
984 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
985 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
986 :
987 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
988 1 : spdm_response->header.request_response_code = SPDM_ERROR;
989 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
990 1 : spdm_response->header.param2 = 0;
991 :
992 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
993 : false, spdm_response_size,
994 : spdm_response,
995 : response_size, response);
996 : }
997 1 : return LIBSPDM_STATUS_SUCCESS;
998 :
999 2 : case 0x8: {
1000 : spdm_error_response_data_response_not_ready_t *spdm_response;
1001 : size_t spdm_response_size;
1002 : size_t transport_header_size;
1003 :
1004 2 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
1005 2 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1006 2 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1007 :
1008 2 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1009 2 : spdm_response->header.request_response_code = SPDM_ERROR;
1010 2 : spdm_response->header.param1 =
1011 : SPDM_ERROR_CODE_RESPONSE_NOT_READY;
1012 2 : spdm_response->header.param2 = 0;
1013 2 : spdm_response->extend_error_data.rd_exponent = 1;
1014 2 : spdm_response->extend_error_data.rd_tm = 2;
1015 2 : spdm_response->extend_error_data.request_code =
1016 : SPDM_KEY_EXCHANGE;
1017 2 : spdm_response->extend_error_data.token = 0;
1018 :
1019 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1020 : false, spdm_response_size,
1021 : spdm_response,
1022 : response_size, response);
1023 : }
1024 2 : return LIBSPDM_STATUS_SUCCESS;
1025 :
1026 2 : case 0x9: {
1027 : static size_t sub_index2 = 0;
1028 2 : if (sub_index2 == 0) {
1029 : spdm_error_response_data_response_not_ready_t
1030 : *spdm_response;
1031 : size_t spdm_response_size;
1032 : size_t transport_header_size;
1033 :
1034 1 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
1035 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1036 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1037 :
1038 1 : spdm_response->header.spdm_version =
1039 : SPDM_MESSAGE_VERSION_11;
1040 1 : spdm_response->header.request_response_code = SPDM_ERROR;
1041 1 : spdm_response->header.param1 =
1042 : SPDM_ERROR_CODE_RESPONSE_NOT_READY;
1043 1 : spdm_response->header.param2 = 0;
1044 1 : spdm_response->extend_error_data.rd_exponent = 1;
1045 1 : spdm_response->extend_error_data.rd_tm = 2;
1046 1 : spdm_response->extend_error_data.request_code =
1047 : SPDM_KEY_EXCHANGE;
1048 1 : spdm_response->extend_error_data.token = 1;
1049 :
1050 1 : libspdm_transport_test_encode_message(
1051 : spdm_context, NULL, false, false,
1052 : spdm_response_size, spdm_response,
1053 : response_size, response);
1054 1 : sub_index2++;
1055 1 : } else if (sub_index2 == 1) {
1056 : spdm_key_exchange_response_t *spdm_response;
1057 : size_t dhe_key_size;
1058 : uint32_t hash_size;
1059 : size_t signature_size;
1060 : uint32_t hmac_size;
1061 : uint8_t *ptr;
1062 : void *dhe_context;
1063 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
1064 : size_t final_key_size;
1065 : size_t opaque_key_exchange_rsp_size;
1066 : void *data;
1067 : size_t data_size;
1068 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1069 : uint8_t *cert_buffer;
1070 : size_t cert_buffer_size;
1071 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1072 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1073 : uint8_t bin_str0[128];
1074 : size_t bin_str0_size;
1075 : uint8_t bin_str2[128];
1076 : size_t bin_str2_size;
1077 : uint8_t bin_str7[128];
1078 : size_t bin_str7_size;
1079 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1080 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1081 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1082 : size_t spdm_response_size;
1083 : size_t transport_header_size;
1084 :
1085 : ((libspdm_context_t *)spdm_context)
1086 1 : ->connection_info.algorithm.base_asym_algo =
1087 : m_libspdm_use_asym_algo;
1088 : ((libspdm_context_t *)spdm_context)
1089 1 : ->connection_info.algorithm.base_hash_algo =
1090 : m_libspdm_use_hash_algo;
1091 : ((libspdm_context_t *)spdm_context)
1092 1 : ->connection_info.algorithm.dhe_named_group =
1093 : m_libspdm_use_dhe_algo;
1094 : ((libspdm_context_t *)spdm_context)
1095 : ->connection_info.algorithm
1096 1 : .measurement_hash_algo =
1097 : m_libspdm_use_measurement_hash_algo;
1098 1 : signature_size =
1099 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1100 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1101 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1102 1 : dhe_key_size =
1103 1 : libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1104 1 : opaque_key_exchange_rsp_size =
1105 1 : libspdm_get_opaque_data_version_selection_data_size(
1106 : spdm_context);
1107 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1108 1 : dhe_key_size + 0 + sizeof(uint16_t) +
1109 1 : opaque_key_exchange_rsp_size +
1110 1 : signature_size + hmac_size;
1111 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1112 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1113 :
1114 1 : spdm_response->header.spdm_version =
1115 : SPDM_MESSAGE_VERSION_11;
1116 1 : spdm_response->header.request_response_code =
1117 : SPDM_KEY_EXCHANGE_RSP;
1118 1 : spdm_response->header.param1 = 0;
1119 1 : spdm_response->rsp_session_id =
1120 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
1121 1 : spdm_response->mut_auth_requested = 0;
1122 1 : spdm_response->req_slot_id_param = 0;
1123 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
1124 1 : spdm_response->random_data);
1125 1 : ptr = (void *)(spdm_response + 1);
1126 1 : dhe_context = libspdm_dhe_new(
1127 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1128 : m_libspdm_use_dhe_algo, true);
1129 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
1130 : &dhe_key_size);
1131 1 : final_key_size = sizeof(final_key);
1132 1 : libspdm_dhe_compute_key(
1133 : m_libspdm_use_dhe_algo, dhe_context,
1134 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
1135 : sizeof(spdm_key_exchange_request_t),
1136 : dhe_key_size, final_key, &final_key_size);
1137 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1138 1 : ptr += dhe_key_size;
1139 : /* libspdm_zero_mem (ptr, hash_size);
1140 : * ptr += hash_size;*/
1141 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1142 1 : ptr += sizeof(uint16_t);
1143 1 : libspdm_build_opaque_data_version_selection_data(
1144 : spdm_context, &opaque_key_exchange_rsp_size,
1145 : ptr);
1146 1 : ptr += opaque_key_exchange_rsp_size;
1147 1 : libspdm_read_responder_public_certificate_chain(
1148 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
1149 : &data_size, NULL, NULL);
1150 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1151 : sizeof(m_libspdm_local_buffer)
1152 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1153 : m_libspdm_local_buffer),
1154 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1155 1 : m_libspdm_local_buffer_size +=
1156 1 : ((size_t)ptr - (size_t)spdm_response);
1157 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1158 : m_libspdm_local_buffer_size));
1159 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1160 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1161 1 : cert_buffer = (uint8_t *)data;
1162 1 : cert_buffer_size = data_size;
1163 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
1164 : cert_buffer_size, cert_buffer_hash);
1165 : /* transcript.message_a size is 0*/
1166 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash,
1167 : hash_size);
1168 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1169 : m_libspdm_local_buffer_size);
1170 2 : libspdm_hash_all(m_libspdm_use_hash_algo,
1171 1 : libspdm_get_managed_buffer(&th_curr),
1172 : libspdm_get_managed_buffer_size(&th_curr),
1173 : hash_data);
1174 1 : free(data);
1175 1 : libspdm_responder_data_sign(
1176 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
1177 : spdm_context,
1178 : #endif
1179 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1180 : SPDM_KEY_EXCHANGE_RSP,
1181 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
1182 1 : false, libspdm_get_managed_buffer(&th_curr),
1183 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1184 : &signature_size);
1185 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1186 : sizeof(m_libspdm_local_buffer)
1187 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1188 : m_libspdm_local_buffer),
1189 : ptr, signature_size);
1190 1 : m_libspdm_local_buffer_size += signature_size;
1191 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1192 1 : ptr += signature_size;
1193 2 : libspdm_hash_all(m_libspdm_use_hash_algo,
1194 1 : libspdm_get_managed_buffer(&th_curr),
1195 : libspdm_get_managed_buffer_size(&th_curr),
1196 : th_curr_hash_data);
1197 1 : bin_str0_size = sizeof(bin_str0);
1198 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1199 : SPDM_BIN_STR_0_LABEL,
1200 : sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
1201 1 : (uint16_t)hash_size, hash_size, bin_str0,
1202 : &bin_str0_size);
1203 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1204 : m_libspdm_zero_filled_buffer, hash_size, handshake_secret);
1205 1 : bin_str2_size = sizeof(bin_str2);
1206 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1207 : SPDM_BIN_STR_2_LABEL,
1208 : sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1209 1 : th_curr_hash_data, (uint16_t)hash_size,
1210 : hash_size, bin_str2, &bin_str2_size);
1211 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret,
1212 : hash_size, bin_str2, bin_str2_size,
1213 : response_handshake_secret, hash_size);
1214 1 : bin_str7_size = sizeof(bin_str7);
1215 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1216 : SPDM_BIN_STR_7_LABEL,
1217 : sizeof(SPDM_BIN_STR_7_LABEL) - 1, NULL,
1218 1 : (uint16_t)hash_size, hash_size, bin_str7,
1219 : &bin_str7_size);
1220 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo,
1221 : response_handshake_secret, hash_size,
1222 : bin_str7, bin_str7_size,
1223 : response_finished_key, hash_size);
1224 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1225 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1226 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1227 : response_finished_key, hash_size, ptr);
1228 1 : ptr += hmac_size;
1229 :
1230 1 : libspdm_transport_test_encode_message(
1231 : spdm_context, NULL, false, false, spdm_response_size,
1232 : spdm_response, response_size, response);
1233 : }
1234 : }
1235 2 : return LIBSPDM_STATUS_SUCCESS;
1236 :
1237 18 : case 0xA:
1238 : {
1239 : static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
1240 :
1241 : spdm_error_response_t *spdm_response;
1242 : size_t spdm_response_size;
1243 : size_t transport_header_size;
1244 :
1245 18 : spdm_response_size = sizeof(spdm_error_response_t);
1246 18 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1247 18 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1248 :
1249 18 : if(error_code <= 0xff) {
1250 18 : libspdm_zero_mem (spdm_response, spdm_response_size);
1251 18 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1252 18 : spdm_response->header.request_response_code = SPDM_ERROR;
1253 18 : spdm_response->header.param1 = (uint8_t) error_code;
1254 18 : spdm_response->header.param2 = 0;
1255 :
1256 18 : libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
1257 : spdm_response_size, spdm_response,
1258 : response_size, response);
1259 : }
1260 :
1261 18 : error_code++;
1262 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
1263 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
1264 : }
1265 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
1266 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
1267 : }
1268 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
1269 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
1270 : }
1271 : }
1272 18 : return LIBSPDM_STATUS_SUCCESS;
1273 1 : case 0xB: {
1274 : spdm_key_exchange_response_t *spdm_response;
1275 : size_t dhe_key_size;
1276 : uint32_t hash_size;
1277 : size_t signature_size;
1278 : uint32_t hmac_size;
1279 : uint8_t *ptr;
1280 : void *dhe_context;
1281 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
1282 : size_t final_key_size;
1283 : size_t opaque_key_exchange_rsp_size;
1284 : void *data;
1285 : size_t data_size;
1286 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1287 : uint8_t *cert_buffer;
1288 : size_t cert_buffer_size;
1289 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1290 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1291 : uint8_t bin_str0[128];
1292 : size_t bin_str0_size;
1293 : uint8_t bin_str2[128];
1294 : size_t bin_str2_size;
1295 : uint8_t bin_str7[128];
1296 : size_t bin_str7_size;
1297 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1298 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1299 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1300 : size_t spdm_response_size;
1301 : size_t transport_header_size;
1302 :
1303 : ((libspdm_context_t *)spdm_context)
1304 1 : ->connection_info.algorithm.base_asym_algo =
1305 : m_libspdm_use_asym_algo;
1306 : ((libspdm_context_t *)spdm_context)
1307 1 : ->connection_info.algorithm.base_hash_algo =
1308 : m_libspdm_use_hash_algo;
1309 : ((libspdm_context_t *)spdm_context)
1310 1 : ->connection_info.algorithm.dhe_named_group =
1311 : m_libspdm_use_dhe_algo;
1312 : ((libspdm_context_t *)spdm_context)
1313 1 : ->connection_info.algorithm.measurement_hash_algo =
1314 : m_libspdm_use_measurement_hash_algo;
1315 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1316 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1317 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1318 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1319 1 : opaque_key_exchange_rsp_size =
1320 1 : libspdm_get_opaque_data_version_selection_data_size(
1321 : spdm_context);
1322 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1323 1 : dhe_key_size + 0 + sizeof(uint16_t) +
1324 1 : opaque_key_exchange_rsp_size + signature_size +
1325 : hmac_size;
1326 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1327 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1328 :
1329 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1330 1 : spdm_response->header.request_response_code =
1331 : SPDM_KEY_EXCHANGE_RSP;
1332 1 : spdm_response->header.param1 = 0;
1333 1 : spdm_response->rsp_session_id =
1334 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
1335 1 : spdm_response->mut_auth_requested = 0;
1336 1 : spdm_response->req_slot_id_param = 0;
1337 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
1338 1 : spdm_response->random_data);
1339 1 : ptr = (void *)(spdm_response + 1);
1340 1 : dhe_context = libspdm_dhe_new(
1341 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1342 : m_libspdm_use_dhe_algo,
1343 : true);
1344 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
1345 : &dhe_key_size);
1346 1 : final_key_size = sizeof(final_key);
1347 1 : libspdm_dhe_compute_key(
1348 : m_libspdm_use_dhe_algo, dhe_context,
1349 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
1350 : sizeof(spdm_key_exchange_request_t),
1351 : dhe_key_size, final_key, &final_key_size);
1352 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1353 1 : ptr += dhe_key_size;
1354 : /* libspdm_zero_mem (ptr, hash_size);
1355 : * ptr += hash_size;*/
1356 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1357 1 : ptr += sizeof(uint16_t);
1358 1 : libspdm_build_opaque_data_version_selection_data(
1359 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
1360 1 : ptr += opaque_key_exchange_rsp_size;
1361 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1362 : m_libspdm_use_asym_algo, &data,
1363 : &data_size, NULL, NULL);
1364 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1365 : sizeof(m_libspdm_local_buffer)
1366 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1367 : m_libspdm_local_buffer),
1368 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1369 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1370 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1371 : m_libspdm_local_buffer_size));
1372 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1373 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1374 1 : cert_buffer = (uint8_t *)data;
1375 1 : cert_buffer_size = data_size;
1376 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1377 : cert_buffer_hash);
1378 : /* transcript.message_a size is 0*/
1379 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1380 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1381 : m_libspdm_local_buffer_size);
1382 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1383 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1384 1 : free(data);
1385 1 : libspdm_responder_data_sign(
1386 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
1387 : spdm_context,
1388 : #endif
1389 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1390 : SPDM_KEY_EXCHANGE_RSP,
1391 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
1392 1 : false, libspdm_get_managed_buffer(&th_curr),
1393 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1394 : &signature_size);
1395 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1396 : sizeof(m_libspdm_local_buffer)
1397 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1398 : m_libspdm_local_buffer),
1399 : ptr, signature_size);
1400 1 : m_libspdm_local_buffer_size += signature_size;
1401 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1402 1 : ptr += signature_size;
1403 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1404 : libspdm_get_managed_buffer_size(&th_curr),
1405 : th_curr_hash_data);
1406 1 : bin_str0_size = sizeof(bin_str0);
1407 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1408 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
1409 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
1410 : &bin_str0_size);
1411 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1412 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
1413 1 : bin_str2_size = sizeof(bin_str2);
1414 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1415 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1416 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
1417 : bin_str2, &bin_str2_size);
1418 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
1419 : bin_str2, bin_str2_size,
1420 : response_handshake_secret, hash_size);
1421 1 : bin_str7_size = sizeof(bin_str7);
1422 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1423 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1424 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1425 : &bin_str7_size);
1426 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1427 : hash_size, bin_str7, bin_str7_size,
1428 : response_finished_key, hash_size);
1429 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1430 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1431 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1432 : response_finished_key, hash_size, ptr);
1433 1 : ptr += hmac_size;
1434 :
1435 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1436 : false, spdm_response_size,
1437 : spdm_response, response_size,
1438 : response);
1439 : }
1440 1 : return LIBSPDM_STATUS_SUCCESS;
1441 1 : case 0xC: {
1442 : spdm_key_exchange_response_t *spdm_response;
1443 : size_t dhe_key_size;
1444 : uint32_t hash_size;
1445 : uint32_t measurement_hash_size;
1446 : size_t signature_size;
1447 : uint32_t hmac_size;
1448 : uint8_t *ptr;
1449 : void *dhe_context;
1450 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
1451 : size_t final_key_size;
1452 : size_t opaque_key_exchange_rsp_size;
1453 : void *data;
1454 : size_t data_size;
1455 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
1456 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1457 : uint8_t *cert_buffer;
1458 : size_t cert_buffer_size;
1459 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1460 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1461 : uint8_t bin_str0[128];
1462 : size_t bin_str0_size;
1463 : uint8_t bin_str2[128];
1464 : size_t bin_str2_size;
1465 : uint8_t bin_str7[128];
1466 : size_t bin_str7_size;
1467 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1468 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1469 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1470 : size_t spdm_response_size;
1471 : size_t transport_header_size;
1472 :
1473 : ((libspdm_context_t *)spdm_context)
1474 1 : ->connection_info.algorithm.base_asym_algo =
1475 : m_libspdm_use_asym_algo;
1476 : ((libspdm_context_t *)spdm_context)
1477 1 : ->connection_info.algorithm.base_hash_algo =
1478 : m_libspdm_use_hash_algo;
1479 : ((libspdm_context_t *)spdm_context)
1480 1 : ->connection_info.algorithm.dhe_named_group =
1481 : m_libspdm_use_dhe_algo;
1482 : ((libspdm_context_t *)spdm_context)
1483 1 : ->connection_info.algorithm.measurement_hash_algo =
1484 : m_libspdm_use_measurement_hash_algo;
1485 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1486 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1487 1 : measurement_hash_size = libspdm_get_hash_size(
1488 : m_libspdm_use_hash_algo);
1489 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1490 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1491 1 : opaque_key_exchange_rsp_size =
1492 1 : libspdm_get_opaque_data_version_selection_data_size(
1493 : spdm_context);
1494 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1495 1 : dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
1496 1 : opaque_key_exchange_rsp_size + signature_size +
1497 : hmac_size;
1498 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1499 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1500 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1501 :
1502 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1503 1 : spdm_response->header.request_response_code =
1504 : SPDM_KEY_EXCHANGE_RSP;
1505 1 : spdm_response->header.param1 = 0;
1506 1 : spdm_response->rsp_session_id =
1507 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
1508 1 : spdm_response->mut_auth_requested = 0;
1509 1 : spdm_response->req_slot_id_param = 0;
1510 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
1511 1 : spdm_response->random_data);
1512 1 : ptr = (void *)(spdm_response + 1);
1513 1 : dhe_context = libspdm_dhe_new(
1514 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1515 : m_libspdm_use_dhe_algo,
1516 : true);
1517 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
1518 : &dhe_key_size);
1519 1 : final_key_size = sizeof(final_key);
1520 1 : libspdm_dhe_compute_key(
1521 : m_libspdm_use_dhe_algo, dhe_context,
1522 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
1523 : sizeof(spdm_key_exchange_request_t),
1524 : dhe_key_size, final_key, &final_key_size);
1525 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1526 1 : ptr += dhe_key_size;
1527 : /*Mock measurement hash as TCB*/
1528 1 : libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
1529 : m_libspdm_use_tcb_hash_value, measurement_hash_size);
1530 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
1531 : measurement_hash_data, measurement_hash_size);
1532 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
1533 1 : ptr += measurement_hash_size;
1534 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1535 1 : ptr += sizeof(uint16_t);
1536 1 : libspdm_build_opaque_data_version_selection_data(
1537 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
1538 1 : ptr += opaque_key_exchange_rsp_size;
1539 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1540 : m_libspdm_use_asym_algo, &data,
1541 : &data_size, NULL, NULL);
1542 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1543 : sizeof(m_libspdm_local_buffer)
1544 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1545 : m_libspdm_local_buffer),
1546 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1547 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1548 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1549 : m_libspdm_local_buffer_size));
1550 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1551 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1552 1 : cert_buffer = (uint8_t *)data;
1553 1 : cert_buffer_size = data_size;
1554 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1555 : cert_buffer_hash);
1556 : /* transcript.message_a size is 0*/
1557 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1558 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1559 : m_libspdm_local_buffer_size);
1560 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1561 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1562 1 : free(data);
1563 1 : libspdm_responder_data_sign(
1564 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
1565 : spdm_context,
1566 : #endif
1567 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1568 : SPDM_KEY_EXCHANGE_RSP,
1569 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
1570 1 : false, libspdm_get_managed_buffer(&th_curr),
1571 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1572 : &signature_size);
1573 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1574 : sizeof(m_libspdm_local_buffer)
1575 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1576 : m_libspdm_local_buffer),
1577 : ptr, signature_size);
1578 1 : m_libspdm_local_buffer_size += signature_size;
1579 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1580 1 : ptr += signature_size;
1581 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1582 : libspdm_get_managed_buffer_size(&th_curr),
1583 : th_curr_hash_data);
1584 1 : bin_str0_size = sizeof(bin_str0);
1585 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1586 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
1587 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
1588 : &bin_str0_size);
1589 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1590 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
1591 1 : bin_str2_size = sizeof(bin_str2);
1592 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1593 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1594 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
1595 : bin_str2, &bin_str2_size);
1596 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
1597 : bin_str2, bin_str2_size,
1598 : response_handshake_secret, hash_size);
1599 1 : bin_str7_size = sizeof(bin_str7);
1600 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1601 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1602 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1603 : &bin_str7_size);
1604 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1605 : hash_size, bin_str7, bin_str7_size,
1606 : response_finished_key, hash_size);
1607 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1608 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1609 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1610 : response_finished_key, hash_size, ptr);
1611 1 : ptr += hmac_size;
1612 :
1613 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1614 : false, spdm_response_size,
1615 : spdm_response, response_size,
1616 : response);
1617 : }
1618 1 : return LIBSPDM_STATUS_SUCCESS;
1619 :
1620 1 : case 0xD: {
1621 : spdm_key_exchange_response_t *spdm_response;
1622 : size_t dhe_key_size;
1623 : uint32_t hash_size;
1624 : uint32_t measurement_hash_size;
1625 : size_t signature_size;
1626 : uint32_t hmac_size;
1627 : uint8_t *ptr;
1628 : void *dhe_context;
1629 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
1630 : size_t final_key_size;
1631 : size_t opaque_key_exchange_rsp_size;
1632 : void *data;
1633 : size_t data_size;
1634 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
1635 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1636 : uint8_t *cert_buffer;
1637 : size_t cert_buffer_size;
1638 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1639 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1640 : uint8_t bin_str0[128];
1641 : size_t bin_str0_size;
1642 : uint8_t bin_str2[128];
1643 : size_t bin_str2_size;
1644 : uint8_t bin_str7[128];
1645 : size_t bin_str7_size;
1646 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1647 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1648 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1649 : size_t spdm_response_size;
1650 : size_t transport_header_size;
1651 :
1652 : ((libspdm_context_t *)spdm_context)
1653 1 : ->connection_info.algorithm.base_asym_algo =
1654 : m_libspdm_use_asym_algo;
1655 : ((libspdm_context_t *)spdm_context)
1656 1 : ->connection_info.algorithm.base_hash_algo =
1657 : m_libspdm_use_hash_algo;
1658 : ((libspdm_context_t *)spdm_context)
1659 1 : ->connection_info.algorithm.dhe_named_group =
1660 : m_libspdm_use_dhe_algo;
1661 : ((libspdm_context_t *)spdm_context)
1662 1 : ->connection_info.algorithm.measurement_hash_algo =
1663 : m_libspdm_use_measurement_hash_algo;
1664 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1665 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1666 1 : measurement_hash_size = libspdm_get_hash_size(
1667 : m_libspdm_use_hash_algo);
1668 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1669 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1670 1 : opaque_key_exchange_rsp_size =
1671 1 : libspdm_get_opaque_data_version_selection_data_size(
1672 : spdm_context);
1673 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1674 1 : dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
1675 1 : opaque_key_exchange_rsp_size + signature_size +
1676 : hmac_size;
1677 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1678 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1679 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1680 :
1681 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1682 1 : spdm_response->header.request_response_code =
1683 : SPDM_KEY_EXCHANGE_RSP;
1684 1 : spdm_response->header.param1 = 0;
1685 1 : spdm_response->rsp_session_id =
1686 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
1687 1 : spdm_response->mut_auth_requested = 0;
1688 1 : spdm_response->req_slot_id_param = 0;
1689 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
1690 1 : spdm_response->random_data);
1691 1 : ptr = (void *)(spdm_response + 1);
1692 1 : dhe_context = libspdm_dhe_new(
1693 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1694 : m_libspdm_use_dhe_algo,
1695 : true);
1696 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
1697 : &dhe_key_size);
1698 1 : final_key_size = sizeof(final_key);
1699 1 : libspdm_dhe_compute_key(
1700 : m_libspdm_use_dhe_algo, dhe_context,
1701 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
1702 : sizeof(spdm_key_exchange_request_t),
1703 : dhe_key_size, final_key, &final_key_size);
1704 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1705 1 : ptr += dhe_key_size;
1706 : /*Mock measurement hash as 0x00 array*/
1707 1 : libspdm_zero_mem(measurement_hash_data, measurement_hash_size);
1708 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
1709 : measurement_hash_data, measurement_hash_size);
1710 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
1711 1 : ptr += measurement_hash_size;
1712 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1713 1 : ptr += sizeof(uint16_t);
1714 1 : libspdm_build_opaque_data_version_selection_data(
1715 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
1716 1 : ptr += opaque_key_exchange_rsp_size;
1717 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1718 : m_libspdm_use_asym_algo, &data,
1719 : &data_size, NULL, NULL);
1720 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1721 : sizeof(m_libspdm_local_buffer)
1722 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1723 : m_libspdm_local_buffer),
1724 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1725 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1726 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1727 : m_libspdm_local_buffer_size));
1728 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1729 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1730 1 : cert_buffer = (uint8_t *)data;
1731 1 : cert_buffer_size = data_size;
1732 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1733 : cert_buffer_hash);
1734 : /* transcript.message_a size is 0*/
1735 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1736 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1737 : m_libspdm_local_buffer_size);
1738 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1739 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1740 1 : free(data);
1741 1 : libspdm_responder_data_sign(
1742 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
1743 : spdm_context,
1744 : #endif
1745 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1746 : SPDM_KEY_EXCHANGE_RSP,
1747 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
1748 1 : false, libspdm_get_managed_buffer(&th_curr),
1749 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1750 : &signature_size);
1751 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1752 : sizeof(m_libspdm_local_buffer)
1753 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1754 : m_libspdm_local_buffer),
1755 : ptr, signature_size);
1756 1 : m_libspdm_local_buffer_size += signature_size;
1757 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1758 1 : ptr += signature_size;
1759 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1760 : libspdm_get_managed_buffer_size(&th_curr),
1761 : th_curr_hash_data);
1762 1 : bin_str0_size = sizeof(bin_str0);
1763 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1764 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
1765 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
1766 : &bin_str0_size);
1767 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1768 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
1769 1 : bin_str2_size = sizeof(bin_str2);
1770 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1771 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1772 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
1773 : bin_str2, &bin_str2_size);
1774 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
1775 : bin_str2, bin_str2_size,
1776 : response_handshake_secret, hash_size);
1777 1 : bin_str7_size = sizeof(bin_str7);
1778 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1779 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1780 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1781 : &bin_str7_size);
1782 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1783 : hash_size, bin_str7, bin_str7_size,
1784 : response_finished_key, hash_size);
1785 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1786 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1787 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1788 : response_finished_key, hash_size, ptr);
1789 1 : ptr += hmac_size;
1790 :
1791 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1792 : false, spdm_response_size,
1793 : spdm_response, response_size,
1794 : response);
1795 : }
1796 1 : return LIBSPDM_STATUS_SUCCESS;
1797 :
1798 1 : case 0xE: {
1799 : spdm_key_exchange_response_t *spdm_response;
1800 : size_t dhe_key_size;
1801 : uint32_t hash_size;
1802 : uint32_t measurement_hash_size;
1803 : size_t signature_size;
1804 : uint32_t hmac_size;
1805 : uint8_t *ptr;
1806 : void *dhe_context;
1807 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
1808 : size_t final_key_size;
1809 : size_t opaque_key_exchange_rsp_size;
1810 : void *data;
1811 : size_t data_size;
1812 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
1813 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1814 : uint8_t *cert_buffer;
1815 : size_t cert_buffer_size;
1816 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1817 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1818 : uint8_t bin_str0[128];
1819 : size_t bin_str0_size;
1820 : uint8_t bin_str2[128];
1821 : size_t bin_str2_size;
1822 : uint8_t bin_str7[128];
1823 : size_t bin_str7_size;
1824 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1825 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1826 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1827 : size_t spdm_response_size;
1828 : size_t transport_header_size;
1829 :
1830 : ((libspdm_context_t *)spdm_context)
1831 1 : ->connection_info.algorithm.base_asym_algo =
1832 : m_libspdm_use_asym_algo;
1833 : ((libspdm_context_t *)spdm_context)
1834 1 : ->connection_info.algorithm.base_hash_algo =
1835 : m_libspdm_use_hash_algo;
1836 : ((libspdm_context_t *)spdm_context)
1837 1 : ->connection_info.algorithm.dhe_named_group =
1838 : m_libspdm_use_dhe_algo;
1839 : ((libspdm_context_t *)spdm_context)
1840 1 : ->connection_info.algorithm.measurement_hash_algo =
1841 : m_libspdm_use_measurement_hash_algo;
1842 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1843 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1844 1 : measurement_hash_size = libspdm_get_hash_size(
1845 : m_libspdm_use_hash_algo);
1846 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1847 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1848 1 : opaque_key_exchange_rsp_size =
1849 1 : libspdm_get_opaque_data_version_selection_data_size(
1850 : spdm_context);
1851 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1852 1 : dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
1853 1 : opaque_key_exchange_rsp_size + signature_size +
1854 : hmac_size;
1855 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1856 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1857 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1858 :
1859 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1860 1 : spdm_response->header.request_response_code =
1861 : SPDM_KEY_EXCHANGE_RSP;
1862 1 : spdm_response->header.param1 = 0;
1863 1 : spdm_response->rsp_session_id =
1864 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
1865 1 : spdm_response->mut_auth_requested = 0;
1866 1 : spdm_response->req_slot_id_param = 0;
1867 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
1868 1 : spdm_response->random_data);
1869 1 : ptr = (void *)(spdm_response + 1);
1870 1 : dhe_context = libspdm_dhe_new(
1871 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1872 : m_libspdm_use_dhe_algo,
1873 : true);
1874 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
1875 : &dhe_key_size);
1876 1 : final_key_size = sizeof(final_key);
1877 1 : libspdm_dhe_compute_key(
1878 : m_libspdm_use_dhe_algo, dhe_context,
1879 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
1880 : sizeof(spdm_key_exchange_request_t),
1881 : dhe_key_size, final_key, &final_key_size);
1882 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1883 1 : ptr += dhe_key_size;
1884 : /*Mock measurement hash*/
1885 1 : libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
1886 : m_libspdm_use_tcb_hash_value, measurement_hash_size);
1887 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
1888 : measurement_hash_data, measurement_hash_size);
1889 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
1890 1 : ptr += measurement_hash_size;
1891 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1892 1 : ptr += sizeof(uint16_t);
1893 1 : libspdm_build_opaque_data_version_selection_data(
1894 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
1895 1 : ptr += opaque_key_exchange_rsp_size;
1896 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1897 : m_libspdm_use_asym_algo, &data,
1898 : &data_size, NULL, NULL);
1899 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1900 : sizeof(m_libspdm_local_buffer)
1901 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1902 : m_libspdm_local_buffer),
1903 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1904 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1905 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1906 : m_libspdm_local_buffer_size));
1907 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1908 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1909 1 : cert_buffer = (uint8_t *)data;
1910 1 : cert_buffer_size = data_size;
1911 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1912 : cert_buffer_hash);
1913 : /* transcript.message_a size is 0*/
1914 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1915 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1916 : m_libspdm_local_buffer_size);
1917 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1918 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1919 1 : free(data);
1920 1 : libspdm_responder_data_sign(
1921 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
1922 : spdm_context,
1923 : #endif
1924 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1925 : SPDM_KEY_EXCHANGE_RSP,
1926 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
1927 1 : false, libspdm_get_managed_buffer(&th_curr),
1928 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1929 : &signature_size);
1930 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1931 : sizeof(m_libspdm_local_buffer)
1932 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1933 : m_libspdm_local_buffer),
1934 : ptr, signature_size);
1935 1 : m_libspdm_local_buffer_size += signature_size;
1936 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1937 1 : ptr += signature_size;
1938 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1939 : libspdm_get_managed_buffer_size(&th_curr),
1940 : th_curr_hash_data);
1941 1 : bin_str0_size = sizeof(bin_str0);
1942 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1943 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
1944 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
1945 : &bin_str0_size);
1946 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1947 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
1948 1 : bin_str2_size = sizeof(bin_str2);
1949 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1950 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1951 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
1952 : bin_str2, &bin_str2_size);
1953 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
1954 : bin_str2, bin_str2_size,
1955 : response_handshake_secret, hash_size);
1956 1 : bin_str7_size = sizeof(bin_str7);
1957 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1958 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1959 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1960 : &bin_str7_size);
1961 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1962 : hash_size, bin_str7, bin_str7_size,
1963 : response_finished_key, hash_size);
1964 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1965 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1966 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1967 : response_finished_key, hash_size, ptr);
1968 1 : ptr += hmac_size;
1969 :
1970 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1971 : false, spdm_response_size,
1972 : spdm_response, response_size,
1973 : response);
1974 : }
1975 1 : return LIBSPDM_STATUS_SUCCESS;
1976 :
1977 1 : case 0xF: {
1978 : spdm_key_exchange_response_t *spdm_response;
1979 : size_t dhe_key_size;
1980 : uint32_t hash_size;
1981 : size_t signature_size;
1982 : uint32_t hmac_size;
1983 : uint8_t *ptr;
1984 : void *dhe_context;
1985 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
1986 : size_t final_key_size;
1987 : size_t opaque_key_exchange_rsp_size;
1988 : void *data;
1989 : size_t data_size;
1990 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1991 : uint8_t *cert_buffer;
1992 : size_t cert_buffer_size;
1993 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1994 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1995 : uint8_t bin_str0[128];
1996 : size_t bin_str0_size;
1997 : uint8_t bin_str2[128];
1998 : size_t bin_str2_size;
1999 : uint8_t bin_str7[128];
2000 : size_t bin_str7_size;
2001 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2002 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2003 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2004 : size_t spdm_response_size;
2005 : size_t transport_header_size;
2006 :
2007 : ((libspdm_context_t *)spdm_context)
2008 1 : ->connection_info.algorithm.base_asym_algo =
2009 : m_libspdm_use_asym_algo;
2010 : ((libspdm_context_t *)spdm_context)
2011 1 : ->connection_info.algorithm.base_hash_algo =
2012 : m_libspdm_use_hash_algo;
2013 : ((libspdm_context_t *)spdm_context)
2014 1 : ->connection_info.algorithm.dhe_named_group =
2015 : m_libspdm_use_dhe_algo;
2016 : ((libspdm_context_t *)spdm_context)
2017 1 : ->connection_info.algorithm.measurement_hash_algo =
2018 : m_libspdm_use_measurement_hash_algo;
2019 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2020 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2021 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2022 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2023 1 : opaque_key_exchange_rsp_size =
2024 1 : libspdm_get_opaque_data_version_selection_data_size(
2025 : spdm_context);
2026 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2027 1 : dhe_key_size + 0 + sizeof(uint16_t) +
2028 1 : opaque_key_exchange_rsp_size + signature_size +
2029 : hmac_size;
2030 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2031 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2032 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2033 :
2034 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2035 1 : spdm_response->header.request_response_code =
2036 : SPDM_KEY_EXCHANGE_RSP;
2037 1 : spdm_response->header.param1 = 0;
2038 1 : spdm_response->rsp_session_id =
2039 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
2040 1 : spdm_response->mut_auth_requested = 0;
2041 1 : spdm_response->req_slot_id_param = 0;
2042 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
2043 1 : spdm_response->random_data);
2044 1 : ptr = (void *)(spdm_response + 1);
2045 1 : dhe_context = libspdm_dhe_new(
2046 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2047 : m_libspdm_use_dhe_algo,
2048 : true);
2049 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
2050 : &dhe_key_size);
2051 1 : final_key_size = sizeof(final_key);
2052 1 : libspdm_dhe_compute_key(
2053 : m_libspdm_use_dhe_algo, dhe_context,
2054 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2055 : sizeof(spdm_key_exchange_request_t),
2056 : dhe_key_size, final_key, &final_key_size);
2057 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2058 1 : ptr += dhe_key_size;
2059 : /* libspdm_zero_mem (ptr, hash_size);
2060 : * ptr += hash_size;*/
2061 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2062 1 : ptr += sizeof(uint16_t);
2063 1 : libspdm_build_opaque_data_version_selection_data(
2064 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
2065 1 : ptr += opaque_key_exchange_rsp_size;
2066 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2067 : m_libspdm_use_asym_algo, &data,
2068 : &data_size, NULL, NULL);
2069 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2070 : sizeof(m_libspdm_local_buffer)
2071 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2072 : m_libspdm_local_buffer),
2073 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2074 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2075 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2076 : m_libspdm_local_buffer_size));
2077 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2078 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2079 1 : cert_buffer = (uint8_t *)data;
2080 1 : cert_buffer_size = data_size;
2081 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2082 : cert_buffer_hash);
2083 : /* transcript.message_a size is 0*/
2084 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2085 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2086 : m_libspdm_local_buffer_size);
2087 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2088 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2089 1 : free(data);
2090 1 : libspdm_responder_data_sign(
2091 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
2092 : spdm_context,
2093 : #endif
2094 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2095 : SPDM_KEY_EXCHANGE_RSP,
2096 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
2097 1 : false, libspdm_get_managed_buffer(&th_curr),
2098 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2099 : &signature_size);
2100 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2101 : sizeof(m_libspdm_local_buffer)
2102 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2103 : m_libspdm_local_buffer),
2104 : ptr, signature_size);
2105 1 : m_libspdm_local_buffer_size += signature_size;
2106 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2107 1 : ptr += signature_size;
2108 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2109 : libspdm_get_managed_buffer_size(&th_curr),
2110 : th_curr_hash_data);
2111 1 : bin_str0_size = sizeof(bin_str0);
2112 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2113 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2114 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2115 : &bin_str0_size);
2116 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2117 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2118 1 : bin_str2_size = sizeof(bin_str2);
2119 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2120 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2121 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2122 : bin_str2, &bin_str2_size);
2123 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2124 : bin_str2, bin_str2_size,
2125 : response_handshake_secret, hash_size);
2126 1 : bin_str7_size = sizeof(bin_str7);
2127 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2128 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2129 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2130 : &bin_str7_size);
2131 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2132 : hash_size, bin_str7, bin_str7_size,
2133 : response_finished_key, hash_size);
2134 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2135 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2136 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2137 : response_finished_key, hash_size, ptr);
2138 1 : ptr += hmac_size;
2139 :
2140 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2141 : false, spdm_response_size,
2142 : spdm_response, response_size,
2143 : response);
2144 : }
2145 1 : return LIBSPDM_STATUS_SUCCESS;
2146 :
2147 1 : case 0x10: {
2148 : spdm_key_exchange_response_t *spdm_response;
2149 : size_t dhe_key_size;
2150 : uint32_t hash_size;
2151 : size_t signature_size;
2152 : uint32_t hmac_size;
2153 : uint8_t *ptr;
2154 : void *dhe_context;
2155 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
2156 : size_t final_key_size;
2157 : size_t opaque_key_exchange_rsp_size;
2158 : void *data;
2159 : size_t data_size;
2160 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2161 : uint8_t *cert_buffer;
2162 : size_t cert_buffer_size;
2163 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2164 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2165 : uint8_t bin_str0[128];
2166 : size_t bin_str0_size;
2167 : uint8_t bin_str2[128];
2168 : size_t bin_str2_size;
2169 : uint8_t bin_str7[128];
2170 : size_t bin_str7_size;
2171 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2172 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2173 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2174 : size_t spdm_response_size;
2175 : size_t transport_header_size;
2176 :
2177 : ((libspdm_context_t *)spdm_context)
2178 1 : ->connection_info.algorithm.base_asym_algo =
2179 : m_libspdm_use_asym_algo;
2180 : ((libspdm_context_t *)spdm_context)
2181 1 : ->connection_info.algorithm.base_hash_algo =
2182 : m_libspdm_use_hash_algo;
2183 : ((libspdm_context_t *)spdm_context)
2184 1 : ->connection_info.algorithm.dhe_named_group =
2185 : m_libspdm_use_dhe_algo;
2186 : ((libspdm_context_t *)spdm_context)
2187 1 : ->connection_info.algorithm.measurement_hash_algo =
2188 : m_libspdm_use_measurement_hash_algo;
2189 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2190 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2191 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2192 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2193 1 : opaque_key_exchange_rsp_size =
2194 1 : libspdm_get_opaque_data_version_selection_data_size(
2195 : spdm_context);
2196 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2197 1 : dhe_key_size + 0 + sizeof(uint16_t) +
2198 1 : opaque_key_exchange_rsp_size + signature_size +
2199 : hmac_size;
2200 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2201 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2202 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2203 :
2204 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2205 1 : spdm_response->header.request_response_code =
2206 : SPDM_KEY_EXCHANGE_RSP;
2207 1 : spdm_response->header.param1 = 0;
2208 1 : spdm_response->rsp_session_id =
2209 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
2210 1 : spdm_response->mut_auth_requested = 0;
2211 1 : spdm_response->req_slot_id_param = 0;
2212 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
2213 1 : spdm_response->random_data);
2214 1 : ptr = (void *)(spdm_response + 1);
2215 1 : dhe_context = libspdm_dhe_new(
2216 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2217 : m_libspdm_use_dhe_algo,
2218 : true);
2219 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
2220 : &dhe_key_size);
2221 1 : final_key_size = sizeof(final_key);
2222 1 : libspdm_dhe_compute_key(
2223 : m_libspdm_use_dhe_algo, dhe_context,
2224 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2225 : sizeof(spdm_key_exchange_request_t),
2226 : dhe_key_size, final_key, &final_key_size);
2227 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2228 1 : ptr += dhe_key_size;
2229 : /* libspdm_zero_mem (ptr, hash_size);
2230 : * ptr += hash_size;*/
2231 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2232 1 : ptr += sizeof(uint16_t);
2233 1 : libspdm_build_opaque_data_version_selection_data(
2234 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
2235 1 : ptr += opaque_key_exchange_rsp_size;
2236 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2237 : m_libspdm_use_asym_algo, &data,
2238 : &data_size, NULL, NULL);
2239 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2240 : sizeof(m_libspdm_local_buffer)
2241 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2242 : m_libspdm_local_buffer),
2243 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2244 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2245 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2246 : m_libspdm_local_buffer_size));
2247 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2248 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2249 1 : cert_buffer = (uint8_t *)data;
2250 1 : cert_buffer_size = data_size;
2251 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2252 : cert_buffer_hash);
2253 : /* transcript.message_a size is 0*/
2254 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2255 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2256 : m_libspdm_local_buffer_size);
2257 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2258 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2259 1 : free(data);
2260 1 : libspdm_responder_data_sign(
2261 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
2262 : spdm_context,
2263 : #endif
2264 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2265 : SPDM_KEY_EXCHANGE_RSP,
2266 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
2267 1 : false, libspdm_get_managed_buffer(&th_curr),
2268 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2269 : &signature_size);
2270 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2271 : sizeof(m_libspdm_local_buffer)
2272 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2273 : m_libspdm_local_buffer),
2274 : ptr, signature_size);
2275 1 : m_libspdm_local_buffer_size += signature_size;
2276 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2277 1 : ptr += signature_size;
2278 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2279 : libspdm_get_managed_buffer_size(&th_curr),
2280 : th_curr_hash_data);
2281 1 : bin_str0_size = sizeof(bin_str0);
2282 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2283 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2284 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2285 : &bin_str0_size);
2286 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2287 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2288 1 : bin_str2_size = sizeof(bin_str2);
2289 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2290 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2291 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2292 : bin_str2, &bin_str2_size);
2293 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2294 : bin_str2, bin_str2_size,
2295 : response_handshake_secret, hash_size);
2296 1 : bin_str7_size = sizeof(bin_str7);
2297 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2298 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2299 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2300 : &bin_str7_size);
2301 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2302 : hash_size, bin_str7, bin_str7_size,
2303 : response_finished_key, hash_size);
2304 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2305 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2306 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2307 : response_finished_key, hash_size, ptr);
2308 1 : ptr += hmac_size;
2309 :
2310 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2311 : false, spdm_response_size,
2312 : spdm_response, response_size,
2313 : response);
2314 : }
2315 1 : return LIBSPDM_STATUS_SUCCESS;
2316 :
2317 1 : case 0x11: {
2318 : spdm_key_exchange_response_t *spdm_response;
2319 : size_t dhe_key_size;
2320 : uint32_t hash_size;
2321 : uint32_t measurement_hash_size;
2322 : size_t signature_size;
2323 : uint32_t hmac_size;
2324 : uint8_t *ptr;
2325 : void *dhe_context;
2326 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
2327 : size_t final_key_size;
2328 : size_t opaque_key_exchange_rsp_size;
2329 : void *data;
2330 : size_t data_size;
2331 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
2332 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2333 : uint8_t *cert_buffer;
2334 : size_t cert_buffer_size;
2335 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2336 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2337 : uint8_t bin_str0[128];
2338 : size_t bin_str0_size;
2339 : uint8_t bin_str2[128];
2340 : size_t bin_str2_size;
2341 : uint8_t bin_str7[128];
2342 : size_t bin_str7_size;
2343 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2344 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2345 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2346 : size_t spdm_response_size;
2347 : size_t transport_header_size;
2348 :
2349 : ((libspdm_context_t *)spdm_context)
2350 1 : ->connection_info.algorithm.base_asym_algo =
2351 : m_libspdm_use_asym_algo;
2352 : ((libspdm_context_t *)spdm_context)
2353 1 : ->connection_info.algorithm.base_hash_algo =
2354 : m_libspdm_use_hash_algo;
2355 : ((libspdm_context_t *)spdm_context)
2356 1 : ->connection_info.algorithm.dhe_named_group =
2357 : m_libspdm_use_dhe_algo;
2358 : ((libspdm_context_t *)spdm_context)
2359 1 : ->connection_info.algorithm.measurement_hash_algo =
2360 : m_libspdm_use_measurement_hash_algo;
2361 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2362 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2363 1 : measurement_hash_size = libspdm_get_hash_size(
2364 : m_libspdm_use_hash_algo);
2365 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2366 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2367 1 : opaque_key_exchange_rsp_size =
2368 1 : libspdm_get_opaque_data_version_selection_data_size(
2369 : spdm_context);
2370 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2371 1 : dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
2372 1 : opaque_key_exchange_rsp_size + signature_size +
2373 : hmac_size;
2374 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2375 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2376 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2377 :
2378 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2379 1 : spdm_response->header.request_response_code =
2380 : SPDM_KEY_EXCHANGE_RSP;
2381 1 : spdm_response->header.param1 = 0;
2382 1 : spdm_response->rsp_session_id =
2383 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
2384 1 : spdm_response->mut_auth_requested = 0;
2385 1 : spdm_response->req_slot_id_param = 0;
2386 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
2387 1 : spdm_response->random_data);
2388 1 : ptr = (void *)(spdm_response + 1);
2389 1 : dhe_context = libspdm_dhe_new(
2390 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2391 : m_libspdm_use_dhe_algo,
2392 : true);
2393 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
2394 : &dhe_key_size);
2395 1 : final_key_size = sizeof(final_key);
2396 1 : libspdm_dhe_compute_key(
2397 : m_libspdm_use_dhe_algo, dhe_context,
2398 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2399 : sizeof(spdm_key_exchange_request_t),
2400 : dhe_key_size, final_key, &final_key_size);
2401 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2402 1 : ptr += dhe_key_size;
2403 : /*Mock measurement hash as TCB*/
2404 1 : libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
2405 : m_libspdm_use_tcb_hash_value, measurement_hash_size);
2406 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
2407 : measurement_hash_data, measurement_hash_size);
2408 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
2409 1 : ptr += measurement_hash_size;
2410 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2411 1 : ptr += sizeof(uint16_t);
2412 1 : libspdm_build_opaque_data_version_selection_data(
2413 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
2414 1 : ptr += opaque_key_exchange_rsp_size;
2415 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2416 : m_libspdm_use_asym_algo, &data,
2417 : &data_size, NULL, NULL);
2418 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2419 : sizeof(m_libspdm_local_buffer)
2420 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2421 : m_libspdm_local_buffer),
2422 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2423 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2424 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2425 : m_libspdm_local_buffer_size));
2426 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2427 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2428 1 : cert_buffer = (uint8_t *)data;
2429 1 : cert_buffer_size = data_size;
2430 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2431 : cert_buffer_hash);
2432 : /* transcript.message_a size is 0*/
2433 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2434 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2435 : m_libspdm_local_buffer_size);
2436 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2437 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2438 1 : free(data);
2439 1 : libspdm_responder_data_sign(
2440 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
2441 : spdm_context,
2442 : #endif
2443 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2444 : SPDM_KEY_EXCHANGE_RSP,
2445 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
2446 1 : false, libspdm_get_managed_buffer(&th_curr),
2447 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2448 : &signature_size);
2449 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2450 : sizeof(m_libspdm_local_buffer)
2451 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2452 : m_libspdm_local_buffer),
2453 : ptr, signature_size);
2454 1 : m_libspdm_local_buffer_size += signature_size;
2455 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2456 1 : ptr += signature_size;
2457 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2458 : libspdm_get_managed_buffer_size(&th_curr),
2459 : th_curr_hash_data);
2460 1 : bin_str0_size = sizeof(bin_str0);
2461 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2462 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2463 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2464 : &bin_str0_size);
2465 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2466 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2467 1 : bin_str2_size = sizeof(bin_str2);
2468 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2469 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2470 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2471 : bin_str2, &bin_str2_size);
2472 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2473 : bin_str2, bin_str2_size,
2474 : response_handshake_secret, hash_size);
2475 1 : bin_str7_size = sizeof(bin_str7);
2476 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2477 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2478 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2479 : &bin_str7_size);
2480 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2481 : hash_size, bin_str7, bin_str7_size,
2482 : response_finished_key, hash_size);
2483 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2484 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2485 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2486 : response_finished_key, hash_size, ptr);
2487 1 : ptr += hmac_size;
2488 :
2489 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2490 : false, spdm_response_size,
2491 : spdm_response, response_size,
2492 : response);
2493 : }
2494 1 : return LIBSPDM_STATUS_SUCCESS;
2495 :
2496 1 : case 0x12: {
2497 : spdm_key_exchange_response_t *spdm_response;
2498 : size_t dhe_key_size;
2499 : uint32_t hash_size;
2500 : uint32_t measurement_hash_size;
2501 : size_t signature_size;
2502 : uint32_t hmac_size;
2503 : uint8_t *ptr;
2504 : void *dhe_context;
2505 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
2506 : size_t final_key_size;
2507 : size_t opaque_key_exchange_rsp_size;
2508 : void *data;
2509 : size_t data_size;
2510 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2511 : uint8_t *cert_buffer;
2512 : size_t cert_buffer_size;
2513 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2514 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2515 : uint8_t bin_str0[128];
2516 : size_t bin_str0_size;
2517 : uint8_t bin_str2[128];
2518 : size_t bin_str2_size;
2519 : uint8_t bin_str7[128];
2520 : size_t bin_str7_size;
2521 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2522 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2523 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2524 : size_t spdm_response_size;
2525 : size_t transport_header_size;
2526 :
2527 : ((libspdm_context_t *)spdm_context)
2528 1 : ->connection_info.algorithm.base_asym_algo =
2529 : m_libspdm_use_asym_algo;
2530 : ((libspdm_context_t *)spdm_context)
2531 1 : ->connection_info.algorithm.base_hash_algo =
2532 : m_libspdm_use_hash_algo;
2533 : ((libspdm_context_t *)spdm_context)
2534 1 : ->connection_info.algorithm.dhe_named_group =
2535 : m_libspdm_use_dhe_algo;
2536 : ((libspdm_context_t *)spdm_context)
2537 1 : ->connection_info.algorithm.measurement_hash_algo =
2538 : m_libspdm_use_measurement_hash_algo;
2539 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2540 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2541 1 : measurement_hash_size = 0;
2542 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2543 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2544 1 : opaque_key_exchange_rsp_size =
2545 1 : libspdm_get_opaque_data_version_selection_data_size(
2546 : spdm_context);
2547 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2548 1 : dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
2549 1 : opaque_key_exchange_rsp_size + signature_size +
2550 : hmac_size;
2551 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2552 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2553 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2554 :
2555 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2556 1 : spdm_response->header.request_response_code =
2557 : SPDM_KEY_EXCHANGE_RSP;
2558 1 : spdm_response->header.param1 = 0;
2559 1 : spdm_response->rsp_session_id =
2560 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
2561 1 : spdm_response->mut_auth_requested = 0;
2562 1 : spdm_response->req_slot_id_param = 0;
2563 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
2564 1 : spdm_response->random_data);
2565 1 : ptr = (void *)(spdm_response + 1);
2566 1 : dhe_context = libspdm_dhe_new(
2567 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2568 : m_libspdm_use_dhe_algo,
2569 : true);
2570 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
2571 : &dhe_key_size);
2572 1 : final_key_size = sizeof(final_key);
2573 1 : libspdm_dhe_compute_key(
2574 : m_libspdm_use_dhe_algo, dhe_context,
2575 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2576 : sizeof(spdm_key_exchange_request_t),
2577 : dhe_key_size, final_key, &final_key_size);
2578 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2579 1 : ptr += dhe_key_size;
2580 :
2581 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2582 1 : ptr += sizeof(uint16_t);
2583 1 : libspdm_build_opaque_data_version_selection_data(
2584 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
2585 1 : ptr += opaque_key_exchange_rsp_size;
2586 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2587 : m_libspdm_use_asym_algo, &data,
2588 : &data_size, NULL, NULL);
2589 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2590 : sizeof(m_libspdm_local_buffer)
2591 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2592 : m_libspdm_local_buffer),
2593 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2594 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2595 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2596 : m_libspdm_local_buffer_size));
2597 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2598 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2599 1 : cert_buffer = (uint8_t *)data;
2600 1 : cert_buffer_size = data_size;
2601 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2602 : cert_buffer_hash);
2603 : /* transcript.message_a size is 0*/
2604 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2605 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2606 : m_libspdm_local_buffer_size);
2607 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2608 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2609 1 : free(data);
2610 1 : libspdm_responder_data_sign(
2611 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
2612 : spdm_context,
2613 : #endif
2614 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2615 : SPDM_KEY_EXCHANGE_RSP,
2616 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
2617 1 : false, libspdm_get_managed_buffer(&th_curr),
2618 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2619 : &signature_size);
2620 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2621 : sizeof(m_libspdm_local_buffer)
2622 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2623 : m_libspdm_local_buffer),
2624 : ptr, signature_size);
2625 1 : m_libspdm_local_buffer_size += signature_size;
2626 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2627 1 : ptr += signature_size-1;
2628 1 : *ptr ^= 0xFF;
2629 1 : ptr++;
2630 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2631 : libspdm_get_managed_buffer_size(&th_curr),
2632 : th_curr_hash_data);
2633 1 : bin_str0_size = sizeof(bin_str0);
2634 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2635 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2636 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2637 : &bin_str0_size);
2638 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2639 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2640 1 : bin_str2_size = sizeof(bin_str2);
2641 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2642 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2643 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2644 : bin_str2, &bin_str2_size);
2645 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2646 : bin_str2, bin_str2_size,
2647 : response_handshake_secret, hash_size);
2648 1 : bin_str7_size = sizeof(bin_str7);
2649 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2650 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2651 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2652 : &bin_str7_size);
2653 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2654 : hash_size, bin_str7, bin_str7_size,
2655 : response_finished_key, hash_size);
2656 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2657 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2658 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2659 : response_finished_key, hash_size, ptr);
2660 1 : ptr += hmac_size;
2661 :
2662 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2663 : false, spdm_response_size,
2664 : spdm_response, response_size,
2665 : response);
2666 : }
2667 1 : return LIBSPDM_STATUS_SUCCESS;
2668 :
2669 1 : case 0x13: {
2670 : spdm_key_exchange_response_t *spdm_response;
2671 : size_t dhe_key_size;
2672 : uint32_t hash_size;
2673 : size_t signature_size;
2674 : uint32_t hmac_size;
2675 : uint8_t *ptr;
2676 : void *dhe_context;
2677 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
2678 : size_t final_key_size;
2679 : size_t opaque_key_exchange_rsp_size;
2680 : void *data;
2681 : size_t data_size;
2682 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2683 : uint8_t *cert_buffer;
2684 : size_t cert_buffer_size;
2685 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2686 : size_t spdm_response_size;
2687 : size_t transport_header_size;
2688 :
2689 : ((libspdm_context_t *)spdm_context)
2690 1 : ->connection_info.algorithm.base_asym_algo =
2691 : m_libspdm_use_asym_algo;
2692 : ((libspdm_context_t *)spdm_context)
2693 1 : ->connection_info.algorithm.base_hash_algo =
2694 : m_libspdm_use_hash_algo;
2695 : ((libspdm_context_t *)spdm_context)
2696 1 : ->connection_info.algorithm.dhe_named_group =
2697 : m_libspdm_use_dhe_algo;
2698 : ((libspdm_context_t *)spdm_context)
2699 1 : ->connection_info.algorithm.measurement_hash_algo =
2700 : m_libspdm_use_measurement_hash_algo;
2701 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2702 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2703 1 : hmac_size = 0;
2704 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2705 1 : opaque_key_exchange_rsp_size =
2706 1 : libspdm_get_opaque_data_version_selection_data_size(
2707 : spdm_context);
2708 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2709 1 : dhe_key_size + 0 + sizeof(uint16_t) +
2710 1 : opaque_key_exchange_rsp_size + signature_size +
2711 : hmac_size;
2712 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2713 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2714 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2715 :
2716 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2717 1 : spdm_response->header.request_response_code =
2718 : SPDM_KEY_EXCHANGE_RSP;
2719 1 : spdm_response->header.param1 = 0;
2720 1 : spdm_response->rsp_session_id =
2721 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
2722 1 : spdm_response->mut_auth_requested = 0;
2723 1 : spdm_response->req_slot_id_param = 0;
2724 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
2725 1 : spdm_response->random_data);
2726 1 : ptr = (void *)(spdm_response + 1);
2727 1 : dhe_context = libspdm_dhe_new(
2728 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2729 : m_libspdm_use_dhe_algo,
2730 : true);
2731 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
2732 : &dhe_key_size);
2733 1 : final_key_size = sizeof(final_key);
2734 1 : libspdm_dhe_compute_key(
2735 : m_libspdm_use_dhe_algo, dhe_context,
2736 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2737 : sizeof(spdm_key_exchange_request_t),
2738 : dhe_key_size, final_key, &final_key_size);
2739 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2740 1 : ptr += dhe_key_size;
2741 : /* libspdm_zero_mem (ptr, hash_size);
2742 : * ptr += hash_size;*/
2743 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2744 1 : ptr += sizeof(uint16_t);
2745 1 : libspdm_build_opaque_data_version_selection_data(
2746 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
2747 1 : ptr += opaque_key_exchange_rsp_size;
2748 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2749 : m_libspdm_use_asym_algo, &data,
2750 : &data_size, NULL, NULL);
2751 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2752 : sizeof(m_libspdm_local_buffer)
2753 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2754 : m_libspdm_local_buffer),
2755 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2756 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2757 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2758 : m_libspdm_local_buffer_size));
2759 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2760 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2761 1 : cert_buffer = (uint8_t *)data;
2762 1 : cert_buffer_size = data_size;
2763 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2764 : cert_buffer_hash);
2765 : /* transcript.message_a size is 0*/
2766 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2767 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2768 : m_libspdm_local_buffer_size);
2769 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2770 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2771 1 : free(data);
2772 1 : libspdm_responder_data_sign(
2773 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
2774 : spdm_context,
2775 : #endif
2776 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2777 : SPDM_KEY_EXCHANGE_RSP,
2778 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
2779 1 : false, libspdm_get_managed_buffer(&th_curr),
2780 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2781 : &signature_size);
2782 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2783 : sizeof(m_libspdm_local_buffer)
2784 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2785 : m_libspdm_local_buffer),
2786 : ptr, signature_size);
2787 1 : m_libspdm_local_buffer_size += signature_size;
2788 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2789 1 : ptr += signature_size;
2790 :
2791 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2792 : false, spdm_response_size,
2793 : spdm_response, response_size,
2794 : response);
2795 : }
2796 1 : return LIBSPDM_STATUS_SUCCESS;
2797 :
2798 1 : case 0x14: {
2799 : spdm_key_exchange_response_t *spdm_response;
2800 : size_t dhe_key_size;
2801 : uint32_t hash_size;
2802 : size_t signature_size;
2803 : uint32_t hmac_size;
2804 : uint8_t *ptr;
2805 : void *dhe_context;
2806 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
2807 : size_t final_key_size;
2808 : size_t opaque_key_exchange_rsp_size;
2809 : void *data;
2810 : size_t data_size;
2811 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2812 : uint8_t *cert_buffer;
2813 : size_t cert_buffer_size;
2814 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2815 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2816 : uint8_t bin_str0[128];
2817 : size_t bin_str0_size;
2818 : uint8_t bin_str2[128];
2819 : size_t bin_str2_size;
2820 : uint8_t bin_str7[128];
2821 : size_t bin_str7_size;
2822 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2823 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2824 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2825 : size_t spdm_response_size;
2826 : size_t transport_header_size;
2827 :
2828 : ((libspdm_context_t *)spdm_context)
2829 1 : ->connection_info.algorithm.base_asym_algo =
2830 : m_libspdm_use_asym_algo;
2831 : ((libspdm_context_t *)spdm_context)
2832 1 : ->connection_info.algorithm.base_hash_algo =
2833 : m_libspdm_use_hash_algo;
2834 : ((libspdm_context_t *)spdm_context)
2835 1 : ->connection_info.algorithm.dhe_named_group =
2836 : m_libspdm_use_dhe_algo;
2837 : ((libspdm_context_t *)spdm_context)
2838 1 : ->connection_info.algorithm.measurement_hash_algo =
2839 : m_libspdm_use_measurement_hash_algo;
2840 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2841 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2842 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2843 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2844 1 : opaque_key_exchange_rsp_size =
2845 1 : libspdm_get_opaque_data_version_selection_data_size(
2846 : spdm_context);
2847 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2848 1 : dhe_key_size + 0 + sizeof(uint16_t) +
2849 1 : opaque_key_exchange_rsp_size + signature_size +
2850 : hmac_size;
2851 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2852 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2853 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2854 :
2855 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2856 1 : spdm_response->header.request_response_code =
2857 : SPDM_KEY_EXCHANGE_RSP;
2858 1 : spdm_response->header.param1 = 5;
2859 1 : spdm_response->rsp_session_id =
2860 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
2861 1 : spdm_response->mut_auth_requested = 0;
2862 1 : spdm_response->req_slot_id_param = 0;
2863 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
2864 1 : spdm_response->random_data);
2865 1 : ptr = (void *)(spdm_response + 1);
2866 1 : dhe_context = libspdm_dhe_new(
2867 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2868 : m_libspdm_use_dhe_algo,
2869 : true);
2870 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
2871 : &dhe_key_size);
2872 1 : final_key_size = sizeof(final_key);
2873 1 : libspdm_dhe_compute_key(
2874 : m_libspdm_use_dhe_algo, dhe_context,
2875 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2876 : sizeof(spdm_key_exchange_request_t),
2877 : dhe_key_size, final_key, &final_key_size);
2878 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2879 1 : ptr += dhe_key_size;
2880 : /* libspdm_zero_mem (ptr, hash_size);
2881 : * ptr += hash_size;*/
2882 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2883 1 : ptr += sizeof(uint16_t);
2884 1 : libspdm_build_opaque_data_version_selection_data(
2885 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
2886 1 : ptr += opaque_key_exchange_rsp_size;
2887 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2888 : m_libspdm_use_asym_algo, &data,
2889 : &data_size, NULL, NULL);
2890 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2891 : sizeof(m_libspdm_local_buffer)
2892 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2893 : m_libspdm_local_buffer),
2894 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2895 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2896 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2897 : m_libspdm_local_buffer_size));
2898 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2899 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2900 1 : cert_buffer = (uint8_t *)data;
2901 1 : cert_buffer_size = data_size;
2902 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2903 : cert_buffer_hash);
2904 : /* transcript.message_a size is 0*/
2905 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2906 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2907 : m_libspdm_local_buffer_size);
2908 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2909 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2910 1 : free(data);
2911 1 : libspdm_responder_data_sign(
2912 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
2913 : spdm_context,
2914 : #endif
2915 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2916 : SPDM_KEY_EXCHANGE_RSP,
2917 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
2918 1 : false, libspdm_get_managed_buffer(&th_curr),
2919 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2920 : &signature_size);
2921 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2922 : sizeof(m_libspdm_local_buffer)
2923 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2924 : m_libspdm_local_buffer),
2925 : ptr, signature_size);
2926 1 : m_libspdm_local_buffer_size += signature_size;
2927 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2928 1 : ptr += signature_size;
2929 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2930 : libspdm_get_managed_buffer_size(&th_curr),
2931 : th_curr_hash_data);
2932 1 : bin_str0_size = sizeof(bin_str0);
2933 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2934 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2935 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2936 : &bin_str0_size);
2937 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2938 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2939 1 : bin_str2_size = sizeof(bin_str2);
2940 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2941 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2942 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2943 : bin_str2, &bin_str2_size);
2944 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2945 : bin_str2, bin_str2_size,
2946 : response_handshake_secret, hash_size);
2947 1 : bin_str7_size = sizeof(bin_str7);
2948 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2949 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2950 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2951 : &bin_str7_size);
2952 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2953 : hash_size, bin_str7, bin_str7_size,
2954 : response_finished_key, hash_size);
2955 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2956 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2957 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2958 : response_finished_key, hash_size, ptr);
2959 1 : ptr += hmac_size;
2960 :
2961 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2962 : false, spdm_response_size,
2963 : spdm_response, response_size,
2964 : response);
2965 : }
2966 1 : return LIBSPDM_STATUS_SUCCESS;
2967 :
2968 1 : case 0x15: {
2969 : spdm_key_exchange_response_t *spdm_response;
2970 : size_t dhe_key_size;
2971 : uint32_t hash_size;
2972 : size_t signature_size;
2973 : uint32_t hmac_size;
2974 : uint8_t *ptr;
2975 : void *dhe_context;
2976 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
2977 : size_t final_key_size;
2978 : size_t opaque_key_exchange_rsp_size;
2979 : void *data;
2980 : size_t data_size;
2981 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2982 : uint8_t *cert_buffer;
2983 : size_t cert_buffer_size;
2984 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2985 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2986 : uint8_t bin_str0[128];
2987 : size_t bin_str0_size;
2988 : uint8_t bin_str2[128];
2989 : size_t bin_str2_size;
2990 : uint8_t bin_str7[128];
2991 : size_t bin_str7_size;
2992 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2993 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2994 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2995 : size_t spdm_response_size;
2996 : size_t transport_header_size;
2997 :
2998 : ((libspdm_context_t *)spdm_context)
2999 1 : ->connection_info.algorithm.base_asym_algo =
3000 : m_libspdm_use_asym_algo;
3001 : ((libspdm_context_t *)spdm_context)
3002 1 : ->connection_info.algorithm.base_hash_algo =
3003 : m_libspdm_use_hash_algo;
3004 : ((libspdm_context_t *)spdm_context)
3005 1 : ->connection_info.algorithm.dhe_named_group =
3006 : m_libspdm_use_dhe_algo;
3007 : ((libspdm_context_t *)spdm_context)
3008 1 : ->connection_info.algorithm.measurement_hash_algo =
3009 : m_libspdm_use_measurement_hash_algo;
3010 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3011 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3012 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3013 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3014 1 : opaque_key_exchange_rsp_size =
3015 1 : libspdm_get_opaque_data_version_selection_data_size(
3016 : spdm_context);
3017 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3018 1 : dhe_key_size + 0 + sizeof(uint16_t) +
3019 1 : opaque_key_exchange_rsp_size + signature_size +
3020 : hmac_size;
3021 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3022 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3023 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
3024 :
3025 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3026 1 : spdm_response->header.request_response_code =
3027 : SPDM_KEY_EXCHANGE_RSP;
3028 1 : spdm_response->header.param1 = 5;
3029 1 : spdm_response->rsp_session_id =
3030 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
3031 1 : spdm_response->mut_auth_requested = 0;
3032 1 : spdm_response->req_slot_id_param = 0;
3033 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
3034 1 : spdm_response->random_data);
3035 1 : ptr = (void *)(spdm_response + 1);
3036 1 : dhe_context = libspdm_dhe_new(
3037 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3038 : m_libspdm_use_dhe_algo,
3039 : true);
3040 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
3041 : &dhe_key_size);
3042 1 : final_key_size = sizeof(final_key);
3043 1 : libspdm_dhe_compute_key(
3044 : m_libspdm_use_dhe_algo, dhe_context,
3045 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
3046 : sizeof(spdm_key_exchange_request_t),
3047 : dhe_key_size, final_key, &final_key_size);
3048 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3049 1 : ptr += dhe_key_size;
3050 : /* libspdm_zero_mem (ptr, hash_size);
3051 : * ptr += hash_size;*/
3052 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3053 1 : ptr += sizeof(uint16_t);
3054 1 : libspdm_build_opaque_data_version_selection_data(
3055 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
3056 1 : ptr += opaque_key_exchange_rsp_size;
3057 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3058 : m_libspdm_use_asym_algo, &data,
3059 : &data_size, NULL, NULL);
3060 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3061 : sizeof(m_libspdm_local_buffer)
3062 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3063 : m_libspdm_local_buffer),
3064 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3065 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3066 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3067 : m_libspdm_local_buffer_size));
3068 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3069 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3070 1 : cert_buffer = (uint8_t *)data;
3071 1 : cert_buffer_size = data_size;
3072 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
3073 : cert_buffer_hash);
3074 : /* transcript.message_a size is 0*/
3075 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3076 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3077 : m_libspdm_local_buffer_size);
3078 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3079 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3080 1 : free(data);
3081 1 : libspdm_responder_data_sign(
3082 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
3083 : spdm_context,
3084 : #endif
3085 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3086 : SPDM_KEY_EXCHANGE_RSP,
3087 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
3088 1 : false, libspdm_get_managed_buffer(&th_curr),
3089 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3090 : &signature_size);
3091 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3092 : sizeof(m_libspdm_local_buffer)
3093 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3094 : m_libspdm_local_buffer),
3095 : ptr, signature_size);
3096 1 : m_libspdm_local_buffer_size += signature_size;
3097 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3098 1 : ptr += signature_size;
3099 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3100 : libspdm_get_managed_buffer_size(&th_curr),
3101 : th_curr_hash_data);
3102 1 : bin_str0_size = sizeof(bin_str0);
3103 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3104 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3105 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3106 : &bin_str0_size);
3107 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3108 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3109 1 : bin_str2_size = sizeof(bin_str2);
3110 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3111 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3112 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3113 : bin_str2, &bin_str2_size);
3114 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3115 : bin_str2, bin_str2_size,
3116 : response_handshake_secret, hash_size);
3117 1 : bin_str7_size = sizeof(bin_str7);
3118 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3119 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3120 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3121 : &bin_str7_size);
3122 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3123 : hash_size, bin_str7, bin_str7_size,
3124 : response_finished_key, hash_size);
3125 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3126 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3127 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3128 : response_finished_key, hash_size, ptr);
3129 1 : ptr += hmac_size;
3130 :
3131 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3132 : false, spdm_response_size,
3133 : spdm_response, response_size,
3134 : response);
3135 : }
3136 1 : return LIBSPDM_STATUS_SUCCESS;
3137 :
3138 1 : case 0x16: {
3139 : spdm_key_exchange_response_t *spdm_response;
3140 : size_t dhe_key_size;
3141 : uint32_t hash_size;
3142 : size_t signature_size;
3143 : uint32_t hmac_size;
3144 : uint8_t *ptr;
3145 : void *dhe_context;
3146 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
3147 : size_t final_key_size;
3148 : size_t opaque_key_exchange_rsp_size;
3149 : void *data;
3150 : size_t data_size;
3151 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3152 : uint8_t *cert_buffer;
3153 : size_t cert_buffer_size;
3154 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3155 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3156 : uint8_t bin_str0[128];
3157 : size_t bin_str0_size;
3158 : uint8_t bin_str2[128];
3159 : size_t bin_str2_size;
3160 : uint8_t bin_str7[128];
3161 : size_t bin_str7_size;
3162 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3163 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3164 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3165 : size_t spdm_response_size;
3166 : size_t transport_header_size;
3167 :
3168 : ((libspdm_context_t *)spdm_context)
3169 1 : ->connection_info.algorithm.base_asym_algo =
3170 : m_libspdm_use_asym_algo;
3171 : ((libspdm_context_t *)spdm_context)
3172 1 : ->connection_info.algorithm.base_hash_algo =
3173 : m_libspdm_use_hash_algo;
3174 : ((libspdm_context_t *)spdm_context)
3175 1 : ->connection_info.algorithm.dhe_named_group =
3176 : m_libspdm_use_dhe_algo;
3177 : ((libspdm_context_t *)spdm_context)
3178 1 : ->connection_info.algorithm.measurement_hash_algo =
3179 : m_libspdm_use_measurement_hash_algo;
3180 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3181 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3182 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3183 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3184 1 : opaque_key_exchange_rsp_size =
3185 1 : libspdm_get_opaque_data_version_selection_data_size(
3186 : spdm_context);
3187 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3188 1 : dhe_key_size + 0 + sizeof(uint16_t) +
3189 1 : opaque_key_exchange_rsp_size + signature_size +
3190 : hmac_size;
3191 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3192 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3193 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
3194 :
3195 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3196 1 : spdm_response->header.request_response_code =
3197 : SPDM_KEY_EXCHANGE_RSP;
3198 1 : spdm_response->header.param1 = 0;
3199 1 : spdm_response->rsp_session_id =
3200 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
3201 1 : spdm_response->mut_auth_requested = 0;
3202 1 : spdm_response->req_slot_id_param = 0;
3203 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
3204 1 : spdm_response->random_data);
3205 1 : ptr = (void *)(spdm_response + 1);
3206 1 : dhe_context = libspdm_dhe_new(
3207 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3208 : m_libspdm_use_dhe_algo,
3209 : true);
3210 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
3211 : &dhe_key_size);
3212 1 : final_key_size = sizeof(final_key);
3213 1 : libspdm_dhe_compute_key(
3214 : m_libspdm_use_dhe_algo, dhe_context,
3215 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
3216 : sizeof(spdm_key_exchange_request_t),
3217 : dhe_key_size, final_key, &final_key_size);
3218 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3219 1 : ptr += dhe_key_size;
3220 : /* libspdm_zero_mem (ptr, hash_size);
3221 : * ptr += hash_size;*/
3222 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3223 1 : ptr += sizeof(uint16_t);
3224 1 : libspdm_build_opaque_data_version_selection_data(
3225 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
3226 1 : ptr += opaque_key_exchange_rsp_size;
3227 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3228 : m_libspdm_use_asym_algo, &data,
3229 : &data_size, NULL, NULL);
3230 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3231 : sizeof(m_libspdm_local_buffer)
3232 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3233 : m_libspdm_local_buffer),
3234 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3235 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3236 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3237 : m_libspdm_local_buffer_size));
3238 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3239 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3240 1 : cert_buffer = (uint8_t *)data;
3241 1 : cert_buffer_size = data_size;
3242 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
3243 : cert_buffer_hash);
3244 : /* transcript.message_a size is 0*/
3245 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3246 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3247 : m_libspdm_local_buffer_size);
3248 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3249 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3250 1 : free(data);
3251 1 : libspdm_responder_data_sign(
3252 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
3253 : spdm_context,
3254 : #endif
3255 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3256 : SPDM_KEY_EXCHANGE_RSP,
3257 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
3258 1 : false, libspdm_get_managed_buffer(&th_curr),
3259 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3260 : &signature_size);
3261 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3262 : sizeof(m_libspdm_local_buffer)
3263 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3264 : m_libspdm_local_buffer),
3265 : ptr, signature_size);
3266 1 : m_libspdm_local_buffer_size += signature_size;
3267 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3268 1 : ptr += signature_size;
3269 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3270 : libspdm_get_managed_buffer_size(&th_curr),
3271 : th_curr_hash_data);
3272 1 : bin_str0_size = sizeof(bin_str0);
3273 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3274 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3275 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3276 : &bin_str0_size);
3277 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3278 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3279 1 : bin_str2_size = sizeof(bin_str2);
3280 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3281 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3282 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3283 : bin_str2, &bin_str2_size);
3284 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3285 : bin_str2, bin_str2_size,
3286 : response_handshake_secret, hash_size);
3287 1 : bin_str7_size = sizeof(bin_str7);
3288 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3289 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3290 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3291 : &bin_str7_size);
3292 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3293 : hash_size, bin_str7, bin_str7_size,
3294 : response_finished_key, hash_size);
3295 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3296 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3297 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3298 : response_finished_key, hash_size, ptr);
3299 1 : ptr += hmac_size;
3300 :
3301 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3302 : false, spdm_response_size,
3303 : spdm_response, response_size,
3304 : response);
3305 : }
3306 1 : return LIBSPDM_STATUS_SUCCESS;
3307 :
3308 1 : case 0x17: {
3309 : spdm_key_exchange_response_t *spdm_response;
3310 : size_t dhe_key_size;
3311 : uint32_t hash_size;
3312 : size_t signature_size;
3313 : uint32_t hmac_size;
3314 : uint8_t *ptr;
3315 : void *dhe_context;
3316 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
3317 : size_t final_key_size;
3318 : size_t opaque_key_exchange_rsp_size;
3319 : void *data;
3320 : size_t data_size;
3321 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3322 : uint8_t *cert_buffer;
3323 : size_t cert_buffer_size;
3324 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3325 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3326 : uint8_t bin_str0[128];
3327 : size_t bin_str0_size;
3328 : uint8_t bin_str2[128];
3329 : size_t bin_str2_size;
3330 : uint8_t bin_str7[128];
3331 : size_t bin_str7_size;
3332 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3333 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3334 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3335 : size_t spdm_response_size;
3336 : size_t transport_header_size;
3337 :
3338 : ((libspdm_context_t *)spdm_context)
3339 1 : ->connection_info.algorithm.base_asym_algo =
3340 : m_libspdm_use_asym_algo;
3341 : ((libspdm_context_t *)spdm_context)
3342 1 : ->connection_info.algorithm.base_hash_algo =
3343 : m_libspdm_use_hash_algo;
3344 : ((libspdm_context_t *)spdm_context)
3345 1 : ->connection_info.algorithm.dhe_named_group =
3346 : m_libspdm_use_dhe_algo;
3347 : ((libspdm_context_t *)spdm_context)
3348 1 : ->connection_info.algorithm.measurement_hash_algo =
3349 : m_libspdm_use_measurement_hash_algo;
3350 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3351 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3352 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3353 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3354 1 : opaque_key_exchange_rsp_size =
3355 1 : libspdm_get_opaque_data_version_selection_data_size(
3356 : spdm_context);
3357 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3358 1 : dhe_key_size + 0 + sizeof(uint16_t) +
3359 1 : opaque_key_exchange_rsp_size + signature_size +
3360 : hmac_size;
3361 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3362 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3363 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
3364 :
3365 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3366 1 : spdm_response->header.request_response_code =
3367 : SPDM_KEY_EXCHANGE_RSP;
3368 1 : spdm_response->header.param1 = 0;
3369 1 : spdm_response->rsp_session_id =
3370 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
3371 1 : spdm_response->mut_auth_requested =
3372 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
3373 1 : spdm_response->req_slot_id_param = 0xF;
3374 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
3375 1 : spdm_response->random_data);
3376 1 : ptr = (void *)(spdm_response + 1);
3377 1 : dhe_context = libspdm_dhe_new(
3378 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3379 : m_libspdm_use_dhe_algo,
3380 : true);
3381 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
3382 : &dhe_key_size);
3383 1 : final_key_size = sizeof(final_key);
3384 1 : libspdm_dhe_compute_key(
3385 : m_libspdm_use_dhe_algo, dhe_context,
3386 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
3387 : sizeof(spdm_key_exchange_request_t),
3388 : dhe_key_size, final_key, &final_key_size);
3389 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3390 1 : ptr += dhe_key_size;
3391 : /* libspdm_zero_mem (ptr, hash_size);
3392 : * ptr += hash_size;*/
3393 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3394 1 : ptr += sizeof(uint16_t);
3395 1 : libspdm_build_opaque_data_version_selection_data(
3396 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
3397 1 : ptr += opaque_key_exchange_rsp_size;
3398 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3399 : m_libspdm_use_asym_algo, &data,
3400 : &data_size, NULL, NULL);
3401 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3402 : sizeof(m_libspdm_local_buffer)
3403 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3404 : m_libspdm_local_buffer),
3405 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3406 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3407 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3408 : m_libspdm_local_buffer_size));
3409 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3410 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3411 1 : cert_buffer = (uint8_t *)data;
3412 1 : cert_buffer_size = data_size;
3413 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
3414 : cert_buffer_hash);
3415 : /* transcript.message_a size is 0*/
3416 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3417 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3418 : m_libspdm_local_buffer_size);
3419 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3420 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3421 1 : free(data);
3422 1 : libspdm_responder_data_sign(
3423 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
3424 : spdm_context,
3425 : #endif
3426 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3427 : SPDM_KEY_EXCHANGE_RSP,
3428 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
3429 1 : false, libspdm_get_managed_buffer(&th_curr),
3430 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3431 : &signature_size);
3432 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3433 : sizeof(m_libspdm_local_buffer)
3434 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3435 : m_libspdm_local_buffer),
3436 : ptr, signature_size);
3437 1 : m_libspdm_local_buffer_size += signature_size;
3438 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3439 1 : ptr += signature_size;
3440 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3441 : libspdm_get_managed_buffer_size(&th_curr),
3442 : th_curr_hash_data);
3443 1 : bin_str0_size = sizeof(bin_str0);
3444 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3445 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3446 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3447 : &bin_str0_size);
3448 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3449 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3450 1 : bin_str2_size = sizeof(bin_str2);
3451 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3452 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3453 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3454 : bin_str2, &bin_str2_size);
3455 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3456 : bin_str2, bin_str2_size,
3457 : response_handshake_secret, hash_size);
3458 1 : bin_str7_size = sizeof(bin_str7);
3459 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3460 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3461 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3462 : &bin_str7_size);
3463 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3464 : hash_size, bin_str7, bin_str7_size,
3465 : response_finished_key, hash_size);
3466 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3467 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3468 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3469 : response_finished_key, hash_size, ptr);
3470 1 : ptr += hmac_size;
3471 :
3472 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3473 : false, spdm_response_size,
3474 : spdm_response, response_size,
3475 : response);
3476 : }
3477 1 : return LIBSPDM_STATUS_SUCCESS;
3478 :
3479 1 : case 0x18: {
3480 : spdm_key_exchange_response_t *spdm_response;
3481 : size_t dhe_key_size;
3482 : uint32_t hash_size;
3483 : size_t signature_size;
3484 : uint32_t hmac_size;
3485 : uint8_t *ptr;
3486 : void *dhe_context;
3487 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
3488 : size_t final_key_size;
3489 : size_t opaque_key_exchange_rsp_size;
3490 : void *data;
3491 : size_t data_size;
3492 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3493 : uint8_t *cert_buffer;
3494 : size_t cert_buffer_size;
3495 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3496 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3497 : uint8_t bin_str0[128];
3498 : size_t bin_str0_size;
3499 : uint8_t bin_str2[128];
3500 : size_t bin_str2_size;
3501 : uint8_t bin_str7[128];
3502 : size_t bin_str7_size;
3503 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3504 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3505 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3506 : size_t spdm_response_size;
3507 : size_t transport_header_size;
3508 :
3509 : ((libspdm_context_t *)spdm_context)
3510 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3511 : ((libspdm_context_t *)spdm_context)
3512 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3513 : ((libspdm_context_t *)spdm_context)
3514 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3515 : ((libspdm_context_t *)spdm_context)
3516 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
3517 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3518 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3519 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3520 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3521 1 : opaque_key_exchange_rsp_size =
3522 1 : libspdm_get_opaque_data_version_selection_data_size(spdm_context);
3523 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3524 1 : dhe_key_size + 0 + sizeof(uint16_t) +
3525 1 : opaque_key_exchange_rsp_size + signature_size +
3526 : hmac_size;
3527 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3528 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3529 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
3530 :
3531 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3532 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
3533 1 : spdm_response->header.param1 = 0x0;
3534 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
3535 1 : spdm_response->mut_auth_requested =
3536 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
3537 1 : spdm_response->req_slot_id_param = 0x0;
3538 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
3539 1 : ptr = (void *)(spdm_response + 1);
3540 1 : dhe_context = libspdm_dhe_new(
3541 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3542 : m_libspdm_use_dhe_algo, true);
3543 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
3544 1 : final_key_size = sizeof(final_key);
3545 1 : libspdm_dhe_compute_key(
3546 : m_libspdm_use_dhe_algo, dhe_context,
3547 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
3548 : sizeof(spdm_key_exchange_request_t),
3549 : dhe_key_size, final_key, &final_key_size);
3550 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3551 1 : ptr += dhe_key_size;
3552 : /* libspdm_zero_mem (ptr, hash_size);
3553 : * ptr += hash_size;*/
3554 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3555 1 : ptr += sizeof(uint16_t);
3556 1 : libspdm_build_opaque_data_version_selection_data(
3557 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
3558 1 : ptr += opaque_key_exchange_rsp_size;
3559 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3560 : m_libspdm_use_asym_algo, &data,
3561 : &data_size, NULL, NULL);
3562 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3563 : sizeof(m_libspdm_local_buffer)
3564 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3565 : m_libspdm_local_buffer),
3566 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3567 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3568 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3569 : m_libspdm_local_buffer_size));
3570 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3571 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3572 1 : cert_buffer = (uint8_t *)data;
3573 1 : cert_buffer_size = data_size;
3574 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
3575 : cert_buffer_hash);
3576 : /* transcript.message_a size is 0*/
3577 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3578 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3579 : m_libspdm_local_buffer_size);
3580 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3581 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3582 1 : free(data);
3583 1 : libspdm_responder_data_sign(
3584 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
3585 : spdm_context,
3586 : #endif
3587 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3588 : SPDM_KEY_EXCHANGE_RSP,
3589 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
3590 1 : false, libspdm_get_managed_buffer(&th_curr),
3591 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3592 : &signature_size);
3593 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3594 : sizeof(m_libspdm_local_buffer)
3595 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3596 : m_libspdm_local_buffer),
3597 : ptr, signature_size);
3598 1 : m_libspdm_local_buffer_size += signature_size;
3599 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3600 1 : ptr += signature_size;
3601 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3602 : libspdm_get_managed_buffer_size(&th_curr),
3603 : th_curr_hash_data);
3604 1 : bin_str0_size = sizeof(bin_str0);
3605 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3606 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3607 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3608 : &bin_str0_size);
3609 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3610 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3611 1 : bin_str2_size = sizeof(bin_str2);
3612 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3613 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3614 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3615 : bin_str2, &bin_str2_size);
3616 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3617 : bin_str2, bin_str2_size,
3618 : response_handshake_secret, hash_size);
3619 1 : bin_str7_size = sizeof(bin_str7);
3620 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3621 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3622 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3623 : &bin_str7_size);
3624 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3625 : hash_size, bin_str7, bin_str7_size,
3626 : response_finished_key, hash_size);
3627 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3628 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3629 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3630 : response_finished_key, hash_size, ptr);
3631 1 : ptr += hmac_size;
3632 :
3633 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3634 : false, spdm_response_size,
3635 : spdm_response, response_size,
3636 : response);
3637 : }
3638 1 : return LIBSPDM_STATUS_SUCCESS;
3639 :
3640 1 : case 0x19: {
3641 : spdm_key_exchange_response_t *spdm_response;
3642 : size_t dhe_key_size;
3643 : uint32_t hash_size;
3644 : size_t signature_size;
3645 : uint32_t hmac_size;
3646 : uint8_t *ptr;
3647 : void *dhe_context;
3648 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
3649 : size_t final_key_size;
3650 : size_t opaque_key_exchange_rsp_size;
3651 : void *data;
3652 : size_t data_size;
3653 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3654 : uint8_t *cert_buffer;
3655 : size_t cert_buffer_size;
3656 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3657 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3658 : uint8_t bin_str0[128];
3659 : size_t bin_str0_size;
3660 : uint8_t bin_str2[128];
3661 : size_t bin_str2_size;
3662 : uint8_t bin_str7[128];
3663 : size_t bin_str7_size;
3664 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3665 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3666 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3667 : size_t spdm_response_size;
3668 : size_t transport_header_size;
3669 :
3670 : ((libspdm_context_t *)spdm_context)
3671 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3672 : ((libspdm_context_t *)spdm_context)
3673 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3674 : ((libspdm_context_t *)spdm_context)
3675 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3676 : ((libspdm_context_t *)spdm_context)
3677 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
3678 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3679 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3680 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3681 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3682 1 : opaque_key_exchange_rsp_size =
3683 1 : libspdm_get_opaque_data_version_selection_data_size(spdm_context);
3684 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3685 1 : dhe_key_size + 0 + sizeof(uint16_t) +
3686 1 : opaque_key_exchange_rsp_size + signature_size +
3687 : hmac_size;
3688 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3689 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3690 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
3691 :
3692 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3693 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
3694 1 : spdm_response->header.param1 = 0;
3695 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
3696 1 : spdm_response->mut_auth_requested =
3697 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
3698 1 : spdm_response->req_slot_id_param = 0;
3699 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
3700 1 : spdm_response->random_data);
3701 1 : ptr = (void *)(spdm_response + 1);
3702 1 : dhe_context = libspdm_dhe_new(
3703 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3704 : m_libspdm_use_dhe_algo, true);
3705 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
3706 1 : final_key_size = sizeof(final_key);
3707 1 : libspdm_dhe_compute_key(
3708 : m_libspdm_use_dhe_algo, dhe_context,
3709 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
3710 : sizeof(spdm_key_exchange_request_t),
3711 : dhe_key_size, final_key, &final_key_size);
3712 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3713 1 : ptr += dhe_key_size;
3714 : /* libspdm_zero_mem (ptr, hash_size);
3715 : * ptr += hash_size;*/
3716 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3717 1 : ptr += sizeof(uint16_t);
3718 1 : libspdm_build_opaque_data_version_selection_data(
3719 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
3720 1 : ptr += opaque_key_exchange_rsp_size;
3721 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3722 : m_libspdm_use_asym_algo, &data,
3723 : &data_size, NULL, NULL);
3724 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3725 : sizeof(m_libspdm_local_buffer)
3726 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3727 : m_libspdm_local_buffer),
3728 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3729 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3730 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3731 : m_libspdm_local_buffer_size));
3732 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3733 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3734 1 : cert_buffer = (uint8_t *)data;
3735 1 : cert_buffer_size = data_size;
3736 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
3737 : cert_buffer_hash);
3738 : /* transcript.message_a size is 0*/
3739 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3740 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3741 : m_libspdm_local_buffer_size);
3742 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3743 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3744 1 : free(data);
3745 1 : libspdm_responder_data_sign(
3746 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
3747 : spdm_context,
3748 : #endif
3749 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3750 : SPDM_KEY_EXCHANGE_RSP,
3751 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
3752 1 : false, libspdm_get_managed_buffer(&th_curr),
3753 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3754 : &signature_size);
3755 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3756 : sizeof(m_libspdm_local_buffer)
3757 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3758 : m_libspdm_local_buffer),
3759 : ptr, signature_size);
3760 1 : m_libspdm_local_buffer_size += signature_size;
3761 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3762 1 : ptr += signature_size;
3763 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3764 : libspdm_get_managed_buffer_size(&th_curr),
3765 : th_curr_hash_data);
3766 1 : bin_str0_size = sizeof(bin_str0);
3767 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3768 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3769 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3770 : &bin_str0_size);
3771 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3772 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3773 1 : bin_str2_size = sizeof(bin_str2);
3774 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3775 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3776 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3777 : bin_str2, &bin_str2_size);
3778 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3779 : bin_str2, bin_str2_size,
3780 : response_handshake_secret, hash_size);
3781 1 : bin_str7_size = sizeof(bin_str7);
3782 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3783 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3784 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3785 : &bin_str7_size);
3786 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3787 : hash_size, bin_str7, bin_str7_size,
3788 : response_finished_key, hash_size);
3789 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3790 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3791 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3792 : response_finished_key, hash_size, ptr);
3793 1 : ptr += hmac_size;
3794 :
3795 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3796 : false, spdm_response_size,
3797 : spdm_response, response_size,
3798 : response);
3799 : }
3800 1 : return LIBSPDM_STATUS_SUCCESS;
3801 :
3802 1 : case 0x1A: {
3803 : spdm_key_exchange_response_t *spdm_response;
3804 : size_t dhe_key_size;
3805 : uint32_t hash_size;
3806 : size_t signature_size;
3807 : uint32_t hmac_size;
3808 : uint8_t *ptr;
3809 : void *dhe_context;
3810 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
3811 : size_t final_key_size;
3812 : size_t opaque_key_exchange_rsp_size;
3813 : void *data;
3814 : size_t data_size;
3815 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3816 : uint8_t *cert_buffer;
3817 : size_t cert_buffer_size;
3818 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3819 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3820 : uint8_t bin_str0[128];
3821 : size_t bin_str0_size;
3822 : uint8_t bin_str2[128];
3823 : size_t bin_str2_size;
3824 : uint8_t bin_str7[128];
3825 : size_t bin_str7_size;
3826 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3827 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3828 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3829 : size_t spdm_response_size;
3830 : size_t transport_header_size;
3831 :
3832 : ((libspdm_context_t *)spdm_context)
3833 1 : ->connection_info.algorithm.base_asym_algo =
3834 : m_libspdm_use_asym_algo;
3835 : ((libspdm_context_t *)spdm_context)
3836 1 : ->connection_info.algorithm.base_hash_algo =
3837 : m_libspdm_use_hash_algo;
3838 : ((libspdm_context_t *)spdm_context)
3839 1 : ->connection_info.algorithm.dhe_named_group =
3840 : m_libspdm_use_dhe_algo;
3841 : ((libspdm_context_t *)spdm_context)
3842 1 : ->connection_info.algorithm.measurement_hash_algo =
3843 : m_libspdm_use_measurement_hash_algo;
3844 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3845 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3846 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3847 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3848 1 : opaque_key_exchange_rsp_size =
3849 1 : libspdm_get_opaque_data_version_selection_data_size(
3850 : spdm_context);
3851 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3852 1 : dhe_key_size + 0 + sizeof(uint16_t) +
3853 1 : opaque_key_exchange_rsp_size + signature_size +
3854 : hmac_size;
3855 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3856 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3857 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
3858 :
3859 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3860 1 : spdm_response->header.request_response_code =
3861 : SPDM_KEY_EXCHANGE_RSP;
3862 1 : spdm_response->header.param1 = 0;
3863 1 : spdm_response->rsp_session_id =
3864 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
3865 1 : spdm_response->mut_auth_requested =
3866 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED |
3867 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
3868 1 : spdm_response->req_slot_id_param = 0xF;
3869 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
3870 1 : spdm_response->random_data);
3871 1 : ptr = (void *)(spdm_response + 1);
3872 1 : dhe_context = libspdm_dhe_new(
3873 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3874 : m_libspdm_use_dhe_algo,
3875 : true);
3876 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
3877 : &dhe_key_size);
3878 1 : final_key_size = sizeof(final_key);
3879 1 : libspdm_dhe_compute_key(
3880 : m_libspdm_use_dhe_algo, dhe_context,
3881 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
3882 : sizeof(spdm_key_exchange_request_t),
3883 : dhe_key_size, final_key, &final_key_size);
3884 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3885 1 : ptr += dhe_key_size;
3886 : /* libspdm_zero_mem (ptr, hash_size);
3887 : * ptr += hash_size;*/
3888 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3889 1 : ptr += sizeof(uint16_t);
3890 1 : libspdm_build_opaque_data_version_selection_data(
3891 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
3892 1 : ptr += opaque_key_exchange_rsp_size;
3893 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3894 : m_libspdm_use_asym_algo, &data,
3895 : &data_size, NULL, NULL);
3896 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3897 : sizeof(m_libspdm_local_buffer)
3898 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3899 : m_libspdm_local_buffer),
3900 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3901 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3902 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3903 : m_libspdm_local_buffer_size));
3904 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3905 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3906 1 : cert_buffer = (uint8_t *)data;
3907 1 : cert_buffer_size = data_size;
3908 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
3909 : cert_buffer_hash);
3910 : /* transcript.message_a size is 0*/
3911 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3912 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3913 : m_libspdm_local_buffer_size);
3914 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3915 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3916 1 : free(data);
3917 1 : libspdm_responder_data_sign(
3918 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
3919 : spdm_context,
3920 : #endif
3921 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3922 : SPDM_KEY_EXCHANGE_RSP,
3923 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
3924 1 : false, libspdm_get_managed_buffer(&th_curr),
3925 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3926 : &signature_size);
3927 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3928 : sizeof(m_libspdm_local_buffer)
3929 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3930 : m_libspdm_local_buffer),
3931 : ptr, signature_size);
3932 1 : m_libspdm_local_buffer_size += signature_size;
3933 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3934 1 : ptr += signature_size;
3935 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3936 : libspdm_get_managed_buffer_size(&th_curr),
3937 : th_curr_hash_data);
3938 1 : bin_str0_size = sizeof(bin_str0);
3939 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3940 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3941 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3942 : &bin_str0_size);
3943 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3944 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3945 1 : bin_str2_size = sizeof(bin_str2);
3946 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3947 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3948 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3949 : bin_str2, &bin_str2_size);
3950 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3951 : bin_str2, bin_str2_size,
3952 : response_handshake_secret, hash_size);
3953 1 : bin_str7_size = sizeof(bin_str7);
3954 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3955 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3956 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3957 : &bin_str7_size);
3958 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3959 : hash_size, bin_str7, bin_str7_size,
3960 : response_finished_key, hash_size);
3961 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3962 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3963 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3964 : response_finished_key, hash_size, ptr);
3965 1 : ptr += hmac_size;
3966 :
3967 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3968 : false, spdm_response_size,
3969 : spdm_response, response_size,
3970 : response);
3971 : }
3972 1 : return LIBSPDM_STATUS_SUCCESS;
3973 :
3974 1 : case 0x1B: {
3975 : spdm_key_exchange_response_t *spdm_response;
3976 : size_t dhe_key_size;
3977 : uint32_t hash_size;
3978 : size_t signature_size;
3979 : uint32_t hmac_size;
3980 : uint8_t *ptr;
3981 : void *dhe_context;
3982 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
3983 : size_t final_key_size;
3984 : size_t opaque_key_exchange_rsp_size;
3985 : void *data;
3986 : size_t data_size;
3987 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3988 : uint8_t *cert_buffer;
3989 : size_t cert_buffer_size;
3990 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3991 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3992 : uint8_t bin_str0[128];
3993 : size_t bin_str0_size;
3994 : uint8_t bin_str2[128];
3995 : size_t bin_str2_size;
3996 : uint8_t bin_str7[128];
3997 : size_t bin_str7_size;
3998 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3999 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4000 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
4001 : size_t spdm_response_size;
4002 : size_t transport_header_size;
4003 :
4004 : ((libspdm_context_t *)spdm_context)
4005 1 : ->connection_info.algorithm.base_asym_algo =
4006 : m_libspdm_use_asym_algo;
4007 : ((libspdm_context_t *)spdm_context)
4008 1 : ->connection_info.algorithm.base_hash_algo =
4009 : m_libspdm_use_hash_algo;
4010 : ((libspdm_context_t *)spdm_context)
4011 1 : ->connection_info.algorithm.dhe_named_group =
4012 : m_libspdm_use_dhe_algo;
4013 : ((libspdm_context_t *)spdm_context)
4014 1 : ->connection_info.algorithm.measurement_hash_algo =
4015 : m_libspdm_use_measurement_hash_algo;
4016 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
4017 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4018 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4019 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
4020 1 : opaque_key_exchange_rsp_size =
4021 1 : libspdm_get_opaque_data_version_selection_data_size(
4022 : spdm_context);
4023 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
4024 1 : dhe_key_size + 0 + sizeof(uint16_t) +
4025 1 : opaque_key_exchange_rsp_size + signature_size +
4026 : hmac_size;
4027 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
4028 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
4029 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
4030 :
4031 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
4032 1 : spdm_response->header.request_response_code =
4033 : SPDM_KEY_EXCHANGE_RSP;
4034 1 : spdm_response->header.param1 = 0;
4035 1 : spdm_response->rsp_session_id =
4036 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
4037 1 : spdm_response->mut_auth_requested =
4038 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED |
4039 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
4040 1 : spdm_response->req_slot_id_param = 0xF;
4041 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
4042 1 : spdm_response->random_data);
4043 1 : ptr = (void *)(spdm_response + 1);
4044 1 : dhe_context = libspdm_dhe_new(
4045 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4046 : m_libspdm_use_dhe_algo,
4047 : true);
4048 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
4049 : &dhe_key_size);
4050 1 : final_key_size = sizeof(final_key);
4051 1 : libspdm_dhe_compute_key(
4052 : m_libspdm_use_dhe_algo, dhe_context,
4053 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
4054 : sizeof(spdm_key_exchange_request_t),
4055 : dhe_key_size, final_key, &final_key_size);
4056 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
4057 1 : ptr += dhe_key_size;
4058 : /* libspdm_zero_mem (ptr, hash_size);
4059 : * ptr += hash_size;*/
4060 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
4061 1 : ptr += sizeof(uint16_t);
4062 1 : libspdm_build_opaque_data_version_selection_data(
4063 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
4064 1 : ptr += opaque_key_exchange_rsp_size;
4065 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4066 : m_libspdm_use_asym_algo, &data,
4067 : &data_size, NULL, NULL);
4068 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4069 : sizeof(m_libspdm_local_buffer)
4070 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4071 : m_libspdm_local_buffer),
4072 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
4073 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
4074 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
4075 : m_libspdm_local_buffer_size));
4076 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
4077 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
4078 1 : cert_buffer = (uint8_t *)data;
4079 1 : cert_buffer_size = data_size;
4080 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
4081 : cert_buffer_hash);
4082 : /* transcript.message_a size is 0*/
4083 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
4084 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
4085 : m_libspdm_local_buffer_size);
4086 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4087 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4088 1 : free(data);
4089 1 : libspdm_responder_data_sign(
4090 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
4091 : spdm_context,
4092 : #endif
4093 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4094 : SPDM_KEY_EXCHANGE_RSP,
4095 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
4096 1 : false, libspdm_get_managed_buffer(&th_curr),
4097 : libspdm_get_managed_buffer_size(&th_curr), ptr,
4098 : &signature_size);
4099 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4100 : sizeof(m_libspdm_local_buffer)
4101 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4102 : m_libspdm_local_buffer),
4103 : ptr, signature_size);
4104 1 : m_libspdm_local_buffer_size += signature_size;
4105 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
4106 1 : ptr += signature_size;
4107 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4108 : libspdm_get_managed_buffer_size(&th_curr),
4109 : th_curr_hash_data);
4110 1 : bin_str0_size = sizeof(bin_str0);
4111 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4112 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
4113 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
4114 : &bin_str0_size);
4115 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
4116 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
4117 1 : bin_str2_size = sizeof(bin_str2);
4118 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4119 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
4120 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
4121 : bin_str2, &bin_str2_size);
4122 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
4123 : bin_str2, bin_str2_size,
4124 : response_handshake_secret, hash_size);
4125 1 : bin_str7_size = sizeof(bin_str7);
4126 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4127 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
4128 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
4129 : &bin_str7_size);
4130 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
4131 : hash_size, bin_str7, bin_str7_size,
4132 : response_finished_key, hash_size);
4133 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4134 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4135 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
4136 : response_finished_key, hash_size, ptr);
4137 1 : ptr += hmac_size;
4138 :
4139 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
4140 : false, spdm_response_size,
4141 : spdm_response, response_size,
4142 : response);
4143 : }
4144 1 : return LIBSPDM_STATUS_SUCCESS;
4145 :
4146 1 : case 0x1C: {
4147 : spdm_key_exchange_response_t *spdm_response;
4148 : size_t dhe_key_size;
4149 : uint32_t hash_size;
4150 : size_t signature_size;
4151 : uint32_t hmac_size;
4152 : uint8_t *ptr;
4153 : void *dhe_context;
4154 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
4155 : size_t final_key_size;
4156 : size_t opaque_key_exchange_rsp_size;
4157 : void *data;
4158 : size_t data_size;
4159 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
4160 : uint8_t *cert_buffer;
4161 : size_t cert_buffer_size;
4162 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
4163 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
4164 : uint8_t bin_str0[128];
4165 : size_t bin_str0_size;
4166 : uint8_t bin_str2[128];
4167 : size_t bin_str2_size;
4168 : uint8_t bin_str7[128];
4169 : size_t bin_str7_size;
4170 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4171 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4172 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
4173 : size_t spdm_response_size;
4174 : size_t transport_header_size;
4175 :
4176 : ((libspdm_context_t *)spdm_context)
4177 1 : ->connection_info.algorithm.base_asym_algo =
4178 : m_libspdm_use_asym_algo;
4179 : ((libspdm_context_t *)spdm_context)
4180 1 : ->connection_info.algorithm.base_hash_algo =
4181 : m_libspdm_use_hash_algo;
4182 : ((libspdm_context_t *)spdm_context)
4183 1 : ->connection_info.algorithm.dhe_named_group =
4184 : m_libspdm_use_dhe_algo;
4185 : ((libspdm_context_t *)spdm_context)
4186 1 : ->connection_info.algorithm.measurement_hash_algo =
4187 : m_libspdm_use_measurement_hash_algo;
4188 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
4189 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4190 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4191 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
4192 1 : opaque_key_exchange_rsp_size =
4193 1 : libspdm_get_opaque_data_version_selection_data_size(
4194 : spdm_context);
4195 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
4196 1 : dhe_key_size + 0 + sizeof(uint16_t) +
4197 1 : opaque_key_exchange_rsp_size + signature_size +
4198 : hmac_size;
4199 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
4200 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
4201 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
4202 :
4203 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
4204 1 : spdm_response->header.request_response_code =
4205 : SPDM_KEY_EXCHANGE_RSP;
4206 1 : spdm_response->header.param1 = 0;
4207 1 : spdm_response->rsp_session_id =
4208 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
4209 1 : spdm_response->mut_auth_requested =
4210 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST |
4211 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
4212 1 : spdm_response->req_slot_id_param = 0xF;
4213 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
4214 1 : spdm_response->random_data);
4215 1 : ptr = (void *)(spdm_response + 1);
4216 1 : dhe_context = libspdm_dhe_new(
4217 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4218 : m_libspdm_use_dhe_algo,
4219 : true);
4220 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
4221 : &dhe_key_size);
4222 1 : final_key_size = sizeof(final_key);
4223 1 : libspdm_dhe_compute_key(
4224 : m_libspdm_use_dhe_algo, dhe_context,
4225 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
4226 : sizeof(spdm_key_exchange_request_t),
4227 : dhe_key_size, final_key, &final_key_size);
4228 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
4229 1 : ptr += dhe_key_size;
4230 : /* libspdm_zero_mem (ptr, hash_size);
4231 : * ptr += hash_size;*/
4232 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
4233 1 : ptr += sizeof(uint16_t);
4234 1 : libspdm_build_opaque_data_version_selection_data(
4235 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
4236 1 : ptr += opaque_key_exchange_rsp_size;
4237 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4238 : m_libspdm_use_asym_algo, &data,
4239 : &data_size, NULL, NULL);
4240 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4241 : sizeof(m_libspdm_local_buffer)
4242 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4243 : m_libspdm_local_buffer),
4244 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
4245 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
4246 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
4247 : m_libspdm_local_buffer_size));
4248 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
4249 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
4250 1 : cert_buffer = (uint8_t *)data;
4251 1 : cert_buffer_size = data_size;
4252 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
4253 : cert_buffer_hash);
4254 : /* transcript.message_a size is 0*/
4255 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
4256 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
4257 : m_libspdm_local_buffer_size);
4258 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4259 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4260 1 : free(data);
4261 1 : libspdm_responder_data_sign(
4262 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
4263 : spdm_context,
4264 : #endif
4265 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4266 : SPDM_KEY_EXCHANGE_RSP,
4267 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
4268 1 : false, libspdm_get_managed_buffer(&th_curr),
4269 : libspdm_get_managed_buffer_size(&th_curr), ptr,
4270 : &signature_size);
4271 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4272 : sizeof(m_libspdm_local_buffer)
4273 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4274 : m_libspdm_local_buffer),
4275 : ptr, signature_size);
4276 1 : m_libspdm_local_buffer_size += signature_size;
4277 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
4278 1 : ptr += signature_size;
4279 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4280 : libspdm_get_managed_buffer_size(&th_curr),
4281 : th_curr_hash_data);
4282 1 : bin_str0_size = sizeof(bin_str0);
4283 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4284 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
4285 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
4286 : &bin_str0_size);
4287 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
4288 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
4289 1 : bin_str2_size = sizeof(bin_str2);
4290 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4291 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
4292 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
4293 : bin_str2, &bin_str2_size);
4294 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
4295 : bin_str2, bin_str2_size,
4296 : response_handshake_secret, hash_size);
4297 1 : bin_str7_size = sizeof(bin_str7);
4298 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4299 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
4300 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
4301 : &bin_str7_size);
4302 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
4303 : hash_size, bin_str7, bin_str7_size,
4304 : response_finished_key, hash_size);
4305 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4306 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4307 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
4308 : response_finished_key, hash_size, ptr);
4309 1 : ptr += hmac_size;
4310 :
4311 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
4312 : false, spdm_response_size,
4313 : spdm_response, response_size,
4314 : response);
4315 : }
4316 1 : return LIBSPDM_STATUS_SUCCESS;
4317 :
4318 1 : case 0x1D: {
4319 : spdm_key_exchange_response_t *spdm_response;
4320 : size_t dhe_key_size;
4321 : uint32_t hash_size;
4322 : size_t signature_size;
4323 : uint32_t hmac_size;
4324 : uint8_t *ptr;
4325 : void *dhe_context;
4326 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
4327 : size_t final_key_size;
4328 : size_t opaque_key_exchange_rsp_size;
4329 : void *data;
4330 : size_t data_size;
4331 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
4332 : uint8_t *cert_buffer;
4333 : size_t cert_buffer_size;
4334 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
4335 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
4336 : uint8_t bin_str0[128];
4337 : size_t bin_str0_size;
4338 : uint8_t bin_str2[128];
4339 : size_t bin_str2_size;
4340 : uint8_t bin_str7[128];
4341 : size_t bin_str7_size;
4342 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4343 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4344 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
4345 : size_t spdm_response_size;
4346 : size_t transport_header_size;
4347 :
4348 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_asym_algo =
4349 : m_libspdm_use_asym_algo;
4350 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
4351 : m_libspdm_use_hash_algo;
4352 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.dhe_named_group =
4353 : m_libspdm_use_dhe_algo;
4354 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
4355 : m_libspdm_use_measurement_hash_algo;
4356 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
4357 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4358 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4359 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
4360 1 : opaque_key_exchange_rsp_size =
4361 1 : libspdm_get_opaque_data_version_selection_data_size(spdm_context);
4362 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
4363 1 : dhe_key_size + 0 + sizeof(uint16_t) +
4364 1 : opaque_key_exchange_rsp_size + signature_size +
4365 : hmac_size;
4366 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
4367 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
4368 :
4369 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
4370 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
4371 1 : spdm_response->header.param1 = 0;
4372 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
4373 1 : spdm_response->mut_auth_requested = 0;
4374 1 : spdm_response->req_slot_id_param = 0;
4375 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
4376 1 : ptr = (void *)(spdm_response + 1);
4377 1 : dhe_context = libspdm_dhe_new(
4378 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4379 : m_libspdm_use_dhe_algo, true);
4380 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
4381 1 : final_key_size = sizeof(final_key);
4382 1 : libspdm_dhe_compute_key(
4383 : m_libspdm_use_dhe_algo, dhe_context,
4384 1 : (uint8_t *)&m_libspdm_local_buffer[0] + sizeof(spdm_key_exchange_request_t),
4385 : dhe_key_size, final_key, &final_key_size);
4386 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
4387 1 : ptr += dhe_key_size;
4388 : /* libspdm_zero_mem (ptr, hash_size);
4389 : * ptr += hash_size;*/
4390 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
4391 1 : ptr += sizeof(uint16_t);
4392 1 : libspdm_build_opaque_data_version_selection_data(
4393 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
4394 1 : ptr += opaque_key_exchange_rsp_size;
4395 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4396 : m_libspdm_use_asym_algo, &data,
4397 : &data_size, NULL, NULL);
4398 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4399 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
4400 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
4401 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
4402 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
4403 : m_libspdm_local_buffer_size));
4404 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
4405 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
4406 1 : cert_buffer = (uint8_t *)data;
4407 1 : cert_buffer_size = data_size;
4408 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
4409 : cert_buffer_hash);
4410 : /* transcript.message_a size is 0*/
4411 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
4412 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
4413 : m_libspdm_local_buffer_size);
4414 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4415 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4416 1 : free(data);
4417 1 : libspdm_responder_data_sign(
4418 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
4419 : spdm_context,
4420 : #endif
4421 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4422 : SPDM_KEY_EXCHANGE_RSP, m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
4423 1 : false, libspdm_get_managed_buffer(&th_curr),
4424 : libspdm_get_managed_buffer_size(&th_curr), ptr, &signature_size);
4425 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4426 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
4427 : ptr, signature_size);
4428 1 : m_libspdm_local_buffer_size += signature_size;
4429 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
4430 1 : ptr += signature_size;
4431 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4432 : libspdm_get_managed_buffer_size(&th_curr), th_curr_hash_data);
4433 1 : bin_str0_size = sizeof(bin_str0);
4434 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4435 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
4436 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0, &bin_str0_size);
4437 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
4438 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
4439 1 : bin_str2_size = sizeof(bin_str2);
4440 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4441 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
4442 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
4443 : bin_str2, &bin_str2_size);
4444 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
4445 : bin_str2, bin_str2_size,
4446 : response_handshake_secret, hash_size);
4447 1 : bin_str7_size = sizeof(bin_str7);
4448 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4449 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
4450 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
4451 : &bin_str7_size);
4452 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
4453 : hash_size, bin_str7, bin_str7_size,
4454 : response_finished_key, hash_size);
4455 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4456 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4457 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
4458 : response_finished_key, hash_size, ptr);
4459 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4460 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
4461 : ptr, hmac_size);
4462 1 : m_libspdm_local_buffer_size += hmac_size;
4463 1 : ptr += hmac_size;
4464 :
4465 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
4466 : false, spdm_response_size,
4467 : spdm_response, response_size,
4468 : response);
4469 : }
4470 1 : return LIBSPDM_STATUS_SUCCESS;
4471 1 : case 0x1E: {
4472 : spdm_key_exchange_response_t *spdm_response;
4473 : size_t dhe_key_size;
4474 : uint32_t hash_size;
4475 : size_t signature_size;
4476 : uint32_t hmac_size;
4477 : uint8_t *ptr;
4478 : void *dhe_context;
4479 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
4480 : size_t final_key_size;
4481 : size_t opaque_key_exchange_rsp_size;
4482 : void *data;
4483 : size_t data_size;
4484 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
4485 : uint8_t *cert_buffer;
4486 : size_t cert_buffer_size;
4487 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
4488 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
4489 : uint8_t bin_str0[128];
4490 : size_t bin_str0_size;
4491 : uint8_t bin_str2[128];
4492 : size_t bin_str2_size;
4493 : uint8_t bin_str7[128];
4494 : size_t bin_str7_size;
4495 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4496 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4497 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
4498 : size_t spdm_response_size;
4499 : size_t transport_header_size;
4500 :
4501 1 : ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
4502 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4503 : ((libspdm_context_t *)spdm_context)
4504 1 : ->connection_info.algorithm.base_asym_algo =
4505 : m_libspdm_use_asym_algo;
4506 : ((libspdm_context_t *)spdm_context)
4507 1 : ->connection_info.algorithm.base_hash_algo =
4508 : m_libspdm_use_hash_algo;
4509 : ((libspdm_context_t *)spdm_context)
4510 1 : ->connection_info.algorithm.dhe_named_group =
4511 : m_libspdm_use_dhe_algo;
4512 : ((libspdm_context_t *)spdm_context)
4513 1 : ->connection_info.algorithm.measurement_hash_algo =
4514 : m_libspdm_use_measurement_hash_algo;
4515 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
4516 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4517 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4518 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
4519 1 : opaque_key_exchange_rsp_size =
4520 1 : libspdm_get_opaque_data_version_selection_data_size(
4521 : spdm_context);
4522 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
4523 1 : dhe_key_size + 0 + sizeof(uint16_t) +
4524 1 : opaque_key_exchange_rsp_size + signature_size +
4525 : hmac_size;
4526 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
4527 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
4528 :
4529 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
4530 1 : spdm_response->header.request_response_code =
4531 : SPDM_KEY_EXCHANGE_RSP;
4532 1 : spdm_response->header.param1 = 0;
4533 1 : spdm_response->rsp_session_id =
4534 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
4535 1 : spdm_response->mut_auth_requested = 0;
4536 1 : spdm_response->req_slot_id_param = 0;
4537 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
4538 1 : spdm_response->random_data);
4539 1 : ptr = (void *)(spdm_response + 1);
4540 1 : dhe_context = libspdm_dhe_new(
4541 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4542 : m_libspdm_use_dhe_algo,
4543 : true);
4544 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
4545 : &dhe_key_size);
4546 1 : final_key_size = sizeof(final_key);
4547 1 : libspdm_dhe_compute_key(
4548 : m_libspdm_use_dhe_algo, dhe_context,
4549 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
4550 : sizeof(spdm_key_exchange_request_t),
4551 : dhe_key_size, final_key, &final_key_size);
4552 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
4553 1 : ptr += dhe_key_size;
4554 : /* libspdm_zero_mem (ptr, hash_size);
4555 : * ptr += hash_size;*/
4556 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
4557 1 : ptr += sizeof(uint16_t);
4558 1 : libspdm_build_opaque_data_version_selection_data(
4559 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
4560 1 : ptr += opaque_key_exchange_rsp_size;
4561 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4562 : m_libspdm_use_asym_algo, &data,
4563 : &data_size, NULL, NULL);
4564 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4565 : sizeof(m_libspdm_local_buffer)
4566 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4567 : m_libspdm_local_buffer),
4568 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
4569 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
4570 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
4571 : m_libspdm_local_buffer_size));
4572 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
4573 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
4574 1 : cert_buffer = (uint8_t *)data;
4575 1 : cert_buffer_size = data_size;
4576 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
4577 : cert_buffer_hash);
4578 : /* transcript.message_a size is 0*/
4579 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
4580 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
4581 : m_libspdm_local_buffer_size);
4582 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4583 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4584 1 : free(data);
4585 1 : libspdm_responder_data_sign(
4586 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
4587 : spdm_context,
4588 : #endif
4589 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4590 : SPDM_KEY_EXCHANGE_RSP,
4591 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
4592 1 : false, libspdm_get_managed_buffer(&th_curr),
4593 : libspdm_get_managed_buffer_size(&th_curr), ptr,
4594 : &signature_size);
4595 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4596 : sizeof(m_libspdm_local_buffer)
4597 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4598 : m_libspdm_local_buffer),
4599 : ptr, signature_size);
4600 1 : m_libspdm_local_buffer_size += signature_size;
4601 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
4602 1 : ptr += signature_size;
4603 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4604 : libspdm_get_managed_buffer_size(&th_curr),
4605 : th_curr_hash_data);
4606 1 : bin_str0_size = sizeof(bin_str0);
4607 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4608 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
4609 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
4610 : &bin_str0_size);
4611 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
4612 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
4613 1 : bin_str2_size = sizeof(bin_str2);
4614 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4615 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
4616 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
4617 : bin_str2, &bin_str2_size);
4618 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
4619 : bin_str2, bin_str2_size,
4620 : response_handshake_secret, hash_size);
4621 1 : bin_str7_size = sizeof(bin_str7);
4622 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4623 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
4624 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
4625 : &bin_str7_size);
4626 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
4627 : hash_size, bin_str7, bin_str7_size,
4628 : response_finished_key, hash_size);
4629 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4630 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4631 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
4632 : response_finished_key, hash_size, ptr);
4633 1 : ptr += hmac_size;
4634 :
4635 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
4636 : false, spdm_response_size,
4637 : spdm_response, response_size,
4638 : response);
4639 : }
4640 1 : return LIBSPDM_STATUS_SUCCESS;
4641 :
4642 1 : case 0x1F: {
4643 : spdm_key_exchange_response_t *spdm_response;
4644 : size_t dhe_key_size;
4645 : uint32_t hash_size;
4646 : size_t signature_size;
4647 : uint32_t hmac_size;
4648 : uint8_t *ptr;
4649 : void *dhe_context;
4650 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
4651 : size_t final_key_size;
4652 : size_t opaque_key_exchange_rsp_size;
4653 : void *data;
4654 : size_t data_size;
4655 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
4656 : uint8_t *cert_buffer;
4657 : size_t cert_buffer_size;
4658 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
4659 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
4660 : uint8_t bin_str0[128];
4661 : size_t bin_str0_size;
4662 : uint8_t bin_str2[128];
4663 : size_t bin_str2_size;
4664 : uint8_t bin_str7[128];
4665 : size_t bin_str7_size;
4666 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4667 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4668 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
4669 : size_t spdm_response_size;
4670 : size_t transport_header_size;
4671 :
4672 1 : ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
4673 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4674 : ((libspdm_context_t *)spdm_context)
4675 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4676 : ((libspdm_context_t *)spdm_context)
4677 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4678 : ((libspdm_context_t *)spdm_context)
4679 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4680 : ((libspdm_context_t *)spdm_context)
4681 1 : ->connection_info.algorithm.measurement_hash_algo =
4682 : m_libspdm_use_measurement_hash_algo;
4683 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
4684 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4685 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4686 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
4687 1 : opaque_key_exchange_rsp_size =
4688 1 : libspdm_get_opaque_data_version_selection_data_size(spdm_context);
4689 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
4690 1 : dhe_key_size + 0 + sizeof(uint16_t) +
4691 1 : opaque_key_exchange_rsp_size + signature_size +
4692 : hmac_size;
4693 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
4694 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
4695 :
4696 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
4697 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
4698 1 : spdm_response->header.param1 = 0;
4699 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
4700 1 : spdm_response->mut_auth_requested = 0;
4701 1 : spdm_response->req_slot_id_param = 0;
4702 1 : memset(spdm_response->random_data, 0x5c, SPDM_RANDOM_DATA_SIZE);
4703 1 : ptr = (void *)(spdm_response + 1);
4704 1 : dhe_context = libspdm_dhe_new(
4705 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4706 : m_libspdm_use_dhe_algo, true);
4707 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
4708 1 : final_key_size = sizeof(final_key);
4709 1 : libspdm_dhe_compute_key(
4710 : m_libspdm_use_dhe_algo, dhe_context,
4711 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
4712 : sizeof(spdm_key_exchange_request_t),
4713 : dhe_key_size, final_key, &final_key_size);
4714 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
4715 1 : ptr += dhe_key_size;
4716 : /* libspdm_zero_mem (ptr, hash_size);
4717 : * ptr += hash_size;*/
4718 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
4719 1 : ptr += sizeof(uint16_t);
4720 1 : libspdm_build_opaque_data_version_selection_data(
4721 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
4722 1 : ptr += opaque_key_exchange_rsp_size;
4723 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4724 : m_libspdm_use_asym_algo, &data,
4725 : &data_size, NULL, NULL);
4726 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4727 : sizeof(m_libspdm_local_buffer)
4728 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4729 : m_libspdm_local_buffer),
4730 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
4731 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
4732 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
4733 : m_libspdm_local_buffer_size));
4734 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
4735 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
4736 1 : cert_buffer = (uint8_t *)data;
4737 1 : cert_buffer_size = data_size;
4738 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
4739 : /* transcript.message_a size is 0*/
4740 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
4741 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
4742 : m_libspdm_local_buffer_size);
4743 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4744 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4745 1 : free(data);
4746 1 : libspdm_responder_data_sign(
4747 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
4748 : spdm_context,
4749 : #endif
4750 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4751 : SPDM_KEY_EXCHANGE_RSP,
4752 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
4753 1 : false, libspdm_get_managed_buffer(&th_curr),
4754 : libspdm_get_managed_buffer_size(&th_curr), ptr,
4755 : &signature_size);
4756 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4757 : sizeof(m_libspdm_local_buffer)
4758 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4759 : m_libspdm_local_buffer),
4760 : ptr, signature_size);
4761 1 : m_libspdm_local_buffer_size += signature_size;
4762 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
4763 1 : ptr += signature_size;
4764 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4765 : libspdm_get_managed_buffer_size(&th_curr),
4766 : th_curr_hash_data);
4767 1 : bin_str0_size = sizeof(bin_str0);
4768 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4769 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
4770 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
4771 : &bin_str0_size);
4772 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
4773 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
4774 1 : bin_str2_size = sizeof(bin_str2);
4775 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4776 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
4777 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
4778 : bin_str2, &bin_str2_size);
4779 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
4780 : bin_str2, bin_str2_size,
4781 : response_handshake_secret, hash_size);
4782 1 : bin_str7_size = sizeof(bin_str7);
4783 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4784 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
4785 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
4786 : &bin_str7_size);
4787 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
4788 : hash_size, bin_str7, bin_str7_size,
4789 : response_finished_key, hash_size);
4790 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4791 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4792 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
4793 : response_finished_key, hash_size, ptr);
4794 1 : ptr += hmac_size;
4795 :
4796 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
4797 : false, spdm_response_size,
4798 : spdm_response, response_size,
4799 : response);
4800 : }
4801 1 : return LIBSPDM_STATUS_SUCCESS;
4802 :
4803 1 : case 0x20: {
4804 : spdm_key_exchange_response_t *spdm_response;
4805 : size_t dhe_key_size;
4806 : uint32_t hash_size;
4807 : size_t signature_size;
4808 : uint32_t hmac_size;
4809 : uint8_t *ptr;
4810 : void *dhe_context;
4811 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
4812 : size_t final_key_size;
4813 : size_t opaque_key_exchange_rsp_size;
4814 : void *data;
4815 : size_t data_size;
4816 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
4817 : uint8_t *cert_buffer;
4818 : size_t cert_buffer_size;
4819 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
4820 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
4821 : uint8_t bin_str0[128];
4822 : size_t bin_str0_size;
4823 : uint8_t bin_str2[128];
4824 : size_t bin_str2_size;
4825 : uint8_t bin_str7[128];
4826 : size_t bin_str7_size;
4827 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4828 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4829 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
4830 : size_t spdm_response_size;
4831 : size_t transport_header_size;
4832 :
4833 1 : ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
4834 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4835 : ((libspdm_context_t *)spdm_context)
4836 1 : ->connection_info.algorithm.base_asym_algo =
4837 : m_libspdm_use_asym_algo;
4838 : ((libspdm_context_t *)spdm_context)
4839 1 : ->connection_info.algorithm.base_hash_algo =
4840 : m_libspdm_use_hash_algo;
4841 : ((libspdm_context_t *)spdm_context)
4842 1 : ->connection_info.algorithm.dhe_named_group =
4843 : m_libspdm_use_dhe_algo;
4844 : ((libspdm_context_t *)spdm_context)
4845 1 : ->connection_info.algorithm.measurement_hash_algo =
4846 : m_libspdm_use_measurement_hash_algo;
4847 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
4848 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4849 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4850 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
4851 1 : opaque_key_exchange_rsp_size =
4852 1 : libspdm_get_opaque_data_version_selection_data_size(
4853 : spdm_context);
4854 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
4855 1 : dhe_key_size + 0 + sizeof(uint16_t) +
4856 1 : opaque_key_exchange_rsp_size + signature_size +
4857 : hmac_size;
4858 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
4859 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
4860 :
4861 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
4862 1 : spdm_response->header.request_response_code =
4863 : SPDM_KEY_EXCHANGE_RSP;
4864 1 : spdm_response->header.param1 = 0;
4865 1 : spdm_response->rsp_session_id =
4866 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
4867 1 : spdm_response->mut_auth_requested = 0;
4868 1 : spdm_response->req_slot_id_param = 0;
4869 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
4870 1 : spdm_response->random_data);
4871 1 : ptr = (void *)(spdm_response + 1);
4872 1 : dhe_context = libspdm_dhe_new(
4873 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4874 : m_libspdm_use_dhe_algo,
4875 : true);
4876 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
4877 : &dhe_key_size);
4878 1 : final_key_size = sizeof(final_key);
4879 1 : libspdm_dhe_compute_key(
4880 : m_libspdm_use_dhe_algo, dhe_context,
4881 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
4882 : sizeof(spdm_key_exchange_request_t),
4883 : dhe_key_size, final_key, &final_key_size);
4884 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
4885 1 : ptr += dhe_key_size;
4886 : /* libspdm_zero_mem (ptr, hash_size);
4887 : * ptr += hash_size;*/
4888 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
4889 1 : ptr += sizeof(uint16_t);
4890 1 : libspdm_build_opaque_data_version_selection_data(
4891 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
4892 1 : ptr += opaque_key_exchange_rsp_size;
4893 1 : libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
4894 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4895 : sizeof(m_libspdm_local_buffer)
4896 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4897 : m_libspdm_local_buffer),
4898 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
4899 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
4900 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
4901 : m_libspdm_local_buffer_size));
4902 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
4903 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
4904 1 : cert_buffer = (uint8_t *)data;
4905 1 : cert_buffer_size = data_size;
4906 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
4907 : cert_buffer_hash);
4908 : /* transcript.message_a size is 0*/
4909 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
4910 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
4911 : m_libspdm_local_buffer_size);
4912 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4913 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4914 1 : free(data);
4915 1 : libspdm_responder_data_sign(
4916 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
4917 : spdm_context,
4918 : #endif
4919 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4920 : SPDM_KEY_EXCHANGE_RSP,
4921 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
4922 1 : false, libspdm_get_managed_buffer(&th_curr),
4923 : libspdm_get_managed_buffer_size(&th_curr), ptr,
4924 : &signature_size);
4925 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4926 : sizeof(m_libspdm_local_buffer)
4927 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4928 : m_libspdm_local_buffer),
4929 : ptr, signature_size);
4930 1 : m_libspdm_local_buffer_size += signature_size;
4931 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
4932 1 : ptr += signature_size;
4933 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4934 : libspdm_get_managed_buffer_size(&th_curr),
4935 : th_curr_hash_data);
4936 1 : bin_str0_size = sizeof(bin_str0);
4937 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4938 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
4939 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
4940 : &bin_str0_size);
4941 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
4942 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
4943 1 : bin_str2_size = sizeof(bin_str2);
4944 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4945 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
4946 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
4947 : bin_str2, &bin_str2_size);
4948 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
4949 : bin_str2, bin_str2_size,
4950 : response_handshake_secret, hash_size);
4951 1 : bin_str7_size = sizeof(bin_str7);
4952 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4953 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
4954 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
4955 : &bin_str7_size);
4956 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
4957 : hash_size, bin_str7, bin_str7_size,
4958 : response_finished_key, hash_size);
4959 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4960 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4961 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
4962 : response_finished_key, hash_size, ptr);
4963 1 : ptr += hmac_size;
4964 :
4965 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
4966 : false, spdm_response_size,
4967 : spdm_response, response_size,
4968 : response);
4969 : }
4970 1 : return LIBSPDM_STATUS_SUCCESS;
4971 1 : case 0x21: {
4972 : spdm_key_exchange_response_t *spdm_response;
4973 : size_t dhe_key_size;
4974 : uint32_t hash_size;
4975 : size_t signature_size;
4976 : uint32_t hmac_size;
4977 : uint8_t *ptr;
4978 : void *dhe_context;
4979 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
4980 : size_t final_key_size;
4981 : size_t opaque_key_exchange_rsp_size;
4982 : void *data;
4983 : size_t data_size;
4984 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
4985 : uint8_t *cert_buffer;
4986 : size_t cert_buffer_size;
4987 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
4988 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
4989 : uint8_t bin_str0[128];
4990 : size_t bin_str0_size;
4991 : uint8_t bin_str2[128];
4992 : size_t bin_str2_size;
4993 : uint8_t bin_str7[128];
4994 : size_t bin_str7_size;
4995 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4996 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4997 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
4998 : size_t spdm_response_size;
4999 : size_t transport_header_size;
5000 :
5001 1 : ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
5002 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
5003 : ((libspdm_context_t *)spdm_context)
5004 1 : ->connection_info.algorithm.base_asym_algo =
5005 : m_libspdm_use_asym_algo;
5006 : ((libspdm_context_t *)spdm_context)
5007 1 : ->connection_info.algorithm.base_hash_algo =
5008 : m_libspdm_use_hash_algo;
5009 : ((libspdm_context_t *)spdm_context)
5010 1 : ->connection_info.algorithm.dhe_named_group =
5011 : m_libspdm_use_dhe_algo;
5012 : ((libspdm_context_t *)spdm_context)
5013 1 : ->connection_info.algorithm.measurement_hash_algo =
5014 : m_libspdm_use_measurement_hash_algo;
5015 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
5016 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
5017 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
5018 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
5019 1 : opaque_key_exchange_rsp_size =
5020 1 : libspdm_get_opaque_data_version_selection_data_size(
5021 : spdm_context);
5022 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
5023 1 : dhe_key_size + 0 + sizeof(uint16_t) +
5024 1 : opaque_key_exchange_rsp_size + signature_size +
5025 : hmac_size;
5026 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
5027 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
5028 :
5029 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
5030 1 : spdm_response->header.request_response_code =
5031 : SPDM_KEY_EXCHANGE_RSP;
5032 1 : spdm_response->header.param1 = 0;
5033 1 : spdm_response->rsp_session_id =
5034 1 : libspdm_allocate_rsp_session_id(spdm_context, false);
5035 1 : spdm_response->mut_auth_requested = 0;
5036 1 : spdm_response->req_slot_id_param = 0;
5037 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
5038 1 : spdm_response->random_data);
5039 1 : ptr = (void *)(spdm_response + 1);
5040 1 : dhe_context = libspdm_dhe_new(
5041 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
5042 : m_libspdm_use_dhe_algo,
5043 : true);
5044 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
5045 : &dhe_key_size);
5046 1 : final_key_size = sizeof(final_key);
5047 1 : libspdm_dhe_compute_key(
5048 : m_libspdm_use_dhe_algo, dhe_context,
5049 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
5050 : sizeof(spdm_key_exchange_request_t),
5051 : dhe_key_size, final_key, &final_key_size);
5052 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
5053 1 : ptr += dhe_key_size;
5054 : /* libspdm_zero_mem (ptr, hash_size);
5055 : * ptr += hash_size;*/
5056 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
5057 1 : ptr += sizeof(uint16_t);
5058 1 : libspdm_build_opaque_data_version_selection_data(
5059 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
5060 1 : ptr += opaque_key_exchange_rsp_size;
5061 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5062 : m_libspdm_use_asym_algo, &data,
5063 : &data_size, NULL, NULL);
5064 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
5065 : sizeof(m_libspdm_local_buffer)
5066 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
5067 : m_libspdm_local_buffer),
5068 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
5069 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
5070 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
5071 : m_libspdm_local_buffer_size));
5072 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
5073 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
5074 1 : cert_buffer = (uint8_t *)data;
5075 1 : cert_buffer_size = data_size;
5076 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
5077 : cert_buffer_hash);
5078 : /* transcript.message_a size is 0*/
5079 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
5080 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
5081 : m_libspdm_local_buffer_size);
5082 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
5083 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
5084 1 : free(data);
5085 1 : libspdm_responder_data_sign(
5086 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
5087 : spdm_context,
5088 : #endif
5089 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
5090 : SPDM_KEY_EXCHANGE_RSP,
5091 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
5092 1 : false, libspdm_get_managed_buffer(&th_curr),
5093 : libspdm_get_managed_buffer_size(&th_curr), ptr,
5094 : &signature_size);
5095 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
5096 : sizeof(m_libspdm_local_buffer)
5097 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
5098 : m_libspdm_local_buffer),
5099 : ptr, signature_size);
5100 1 : m_libspdm_local_buffer_size += signature_size;
5101 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
5102 1 : ptr += signature_size;
5103 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
5104 : libspdm_get_managed_buffer_size(&th_curr),
5105 : th_curr_hash_data);
5106 1 : bin_str0_size = sizeof(bin_str0);
5107 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
5108 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
5109 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
5110 : &bin_str0_size);
5111 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
5112 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
5113 1 : bin_str2_size = sizeof(bin_str2);
5114 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
5115 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
5116 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
5117 : bin_str2, &bin_str2_size);
5118 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
5119 : bin_str2, bin_str2_size,
5120 : response_handshake_secret, hash_size);
5121 1 : bin_str7_size = sizeof(bin_str7);
5122 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
5123 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
5124 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
5125 : &bin_str7_size);
5126 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
5127 : hash_size, bin_str7, bin_str7_size,
5128 : response_finished_key, hash_size);
5129 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
5130 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
5131 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
5132 : response_finished_key, hash_size, ptr);
5133 1 : ptr += hmac_size;
5134 :
5135 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
5136 : false, spdm_response_size,
5137 : spdm_response, response_size,
5138 : response);
5139 : }
5140 1 : return LIBSPDM_STATUS_SUCCESS;
5141 1 : case 0x22: {
5142 : spdm_key_exchange_response_t *spdm_response;
5143 : size_t dhe_key_size;
5144 : uint32_t hash_size;
5145 : size_t signature_size;
5146 : uint32_t hmac_size;
5147 : uint8_t *ptr;
5148 : void *dhe_context;
5149 : uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
5150 : size_t final_key_size;
5151 : size_t opaque_key_exchange_rsp_size;
5152 : void *data;
5153 : size_t data_size;
5154 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
5155 : uint8_t *cert_buffer;
5156 : size_t cert_buffer_size;
5157 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
5158 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
5159 : uint8_t bin_str0[128];
5160 : size_t bin_str0_size;
5161 : uint8_t bin_str2[128];
5162 : size_t bin_str2_size;
5163 : uint8_t bin_str7[128];
5164 : size_t bin_str7_size;
5165 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
5166 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
5167 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
5168 : size_t spdm_response_size;
5169 : size_t transport_header_size;
5170 :
5171 1 : ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
5172 : SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
5173 : ((libspdm_context_t *)spdm_context)
5174 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5175 : ((libspdm_context_t *)spdm_context)
5176 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5177 : ((libspdm_context_t *)spdm_context)
5178 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5179 : ((libspdm_context_t *)spdm_context)
5180 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
5181 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
5182 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
5183 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
5184 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
5185 1 : opaque_key_exchange_rsp_size =
5186 1 : libspdm_get_opaque_data_version_selection_data_size(spdm_context);
5187 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
5188 1 : dhe_key_size + 0 + sizeof(uint16_t) +
5189 1 : opaque_key_exchange_rsp_size + signature_size +
5190 : hmac_size;
5191 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
5192 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
5193 :
5194 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
5195 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
5196 1 : spdm_response->header.param1 = 0;
5197 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
5198 1 : spdm_response->mut_auth_requested = 0;
5199 1 : spdm_response->req_slot_id_param = 0;
5200 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
5201 1 : ptr = (void *)(spdm_response + 1);
5202 1 : dhe_context = libspdm_dhe_new(
5203 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
5204 : m_libspdm_use_dhe_algo, true);
5205 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
5206 1 : final_key_size = sizeof(final_key);
5207 1 : libspdm_dhe_compute_key(
5208 : m_libspdm_use_dhe_algo, dhe_context,
5209 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
5210 : sizeof(spdm_key_exchange_request_t),
5211 : dhe_key_size, final_key, &final_key_size);
5212 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
5213 1 : ptr += dhe_key_size;
5214 : /* libspdm_zero_mem (ptr, hash_size);
5215 : * ptr += hash_size;*/
5216 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
5217 1 : ptr += sizeof(uint16_t);
5218 1 : libspdm_build_opaque_data_version_selection_data(
5219 : spdm_context, &opaque_key_exchange_rsp_size, ptr);
5220 1 : ptr += opaque_key_exchange_rsp_size;
5221 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5222 : m_libspdm_use_asym_algo, &data,
5223 : &data_size, NULL, NULL);
5224 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
5225 : sizeof(m_libspdm_local_buffer)
5226 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
5227 : m_libspdm_local_buffer),
5228 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
5229 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
5230 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
5231 : m_libspdm_local_buffer_size));
5232 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
5233 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
5234 1 : cert_buffer = (uint8_t *)data;
5235 1 : cert_buffer_size = data_size;
5236 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
5237 : cert_buffer_hash);
5238 : /* transcript.message_a size is 0*/
5239 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
5240 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
5241 : m_libspdm_local_buffer_size);
5242 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
5243 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
5244 1 : free(data);
5245 1 : libspdm_responder_data_sign(
5246 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
5247 : spdm_context,
5248 : #endif
5249 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
5250 : SPDM_KEY_EXCHANGE_RSP,
5251 : m_libspdm_use_asym_algo, m_libspdm_use_hash_algo,
5252 1 : false, libspdm_get_managed_buffer(&th_curr),
5253 : libspdm_get_managed_buffer_size(&th_curr), ptr,
5254 : &signature_size);
5255 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
5256 : sizeof(m_libspdm_local_buffer)
5257 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
5258 : m_libspdm_local_buffer),
5259 : ptr, signature_size);
5260 1 : m_libspdm_local_buffer_size += signature_size;
5261 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
5262 1 : ptr += signature_size;
5263 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
5264 : libspdm_get_managed_buffer_size(&th_curr),
5265 : th_curr_hash_data);
5266 1 : bin_str0_size = sizeof(bin_str0);
5267 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
5268 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
5269 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
5270 : &bin_str0_size);
5271 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
5272 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
5273 1 : bin_str2_size = sizeof(bin_str2);
5274 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
5275 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
5276 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
5277 : bin_str2, &bin_str2_size);
5278 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
5279 : bin_str2, bin_str2_size,
5280 : response_handshake_secret, hash_size);
5281 1 : bin_str7_size = sizeof(bin_str7);
5282 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
5283 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
5284 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
5285 : &bin_str7_size);
5286 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
5287 : hash_size, bin_str7, bin_str7_size,
5288 : response_finished_key, hash_size);
5289 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
5290 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
5291 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
5292 : response_finished_key, hash_size, ptr);
5293 1 : ptr += hmac_size;
5294 :
5295 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
5296 : false, spdm_response_size,
5297 : spdm_response, response_size,
5298 : response);
5299 : }
5300 1 : return LIBSPDM_STATUS_SUCCESS;
5301 :
5302 0 : default:
5303 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
5304 : }
5305 : }
5306 :
5307 1 : static void libspdm_test_requester_key_exchange_case1(void **state)
5308 : {
5309 : libspdm_return_t status;
5310 : libspdm_test_context_t *spdm_test_context;
5311 : libspdm_context_t *spdm_context;
5312 : uint32_t session_id;
5313 : uint8_t heartbeat_period;
5314 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5315 : uint8_t slot_id_param;
5316 : void *data;
5317 : size_t data_size;
5318 : void *hash;
5319 : size_t hash_size;
5320 :
5321 1 : spdm_test_context = *state;
5322 1 : spdm_context = spdm_test_context->spdm_context;
5323 1 : spdm_test_context->case_id = 0x1;
5324 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5325 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5326 1 : spdm_context->connection_info.connection_state =
5327 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5328 1 : spdm_context->connection_info.capability.flags |=
5329 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5330 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5331 1 : spdm_context->local_context.capability.flags |=
5332 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5333 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5334 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5335 : m_libspdm_use_asym_algo, &data,
5336 : &data_size, &hash, &hash_size);
5337 1 : libspdm_reset_message_a(spdm_context);
5338 1 : spdm_context->connection_info.algorithm.base_hash_algo =
5339 : m_libspdm_use_hash_algo;
5340 1 : spdm_context->connection_info.algorithm.base_asym_algo =
5341 : m_libspdm_use_asym_algo;
5342 1 : spdm_context->connection_info.algorithm.dhe_named_group =
5343 : m_libspdm_use_dhe_algo;
5344 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
5345 : m_libspdm_use_aead_algo;
5346 :
5347 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5348 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
5349 : data_size;
5350 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5351 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5352 : data, data_size);
5353 : #else
5354 1 : libspdm_hash_all(
5355 : spdm_context->connection_info.algorithm.base_hash_algo,
5356 : data, data_size,
5357 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5358 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5359 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5360 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5361 : spdm_context->connection_info.algorithm.base_hash_algo,
5362 : spdm_context->connection_info.algorithm.base_asym_algo,
5363 : data, data_size,
5364 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5365 : #endif
5366 :
5367 1 : heartbeat_period = 0;
5368 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5369 1 : status = libspdm_send_receive_key_exchange(
5370 : spdm_context,
5371 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5372 : &session_id, &heartbeat_period, &slot_id_param,
5373 : measurement_hash);
5374 1 : assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
5375 1 : free(data);
5376 1 : }
5377 :
5378 1 : static void libspdm_test_requester_key_exchange_case2(void **state)
5379 : {
5380 : libspdm_return_t status;
5381 : libspdm_test_context_t *spdm_test_context;
5382 : libspdm_context_t *spdm_context;
5383 : uint32_t session_id;
5384 : uint8_t heartbeat_period;
5385 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5386 : uint8_t slot_id_param;
5387 : void *data;
5388 : size_t data_size;
5389 : void *hash;
5390 : size_t hash_size;
5391 :
5392 1 : spdm_test_context = *state;
5393 1 : spdm_context = spdm_test_context->spdm_context;
5394 1 : spdm_test_context->case_id = 0x2;
5395 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5396 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5397 1 : spdm_context->connection_info.connection_state =
5398 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5399 1 : spdm_context->connection_info.capability.flags |=
5400 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5401 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5402 1 : spdm_context->local_context.capability.flags |=
5403 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5404 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5405 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
5406 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
5407 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
5408 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5409 : m_libspdm_use_asym_algo, &data,
5410 : &data_size, &hash, &hash_size);
5411 1 : libspdm_reset_message_a(spdm_context);
5412 1 : spdm_context->connection_info.algorithm.base_hash_algo =
5413 : m_libspdm_use_hash_algo;
5414 1 : spdm_context->connection_info.algorithm.base_asym_algo =
5415 : m_libspdm_use_asym_algo;
5416 1 : spdm_context->connection_info.algorithm.dhe_named_group =
5417 : m_libspdm_use_dhe_algo;
5418 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
5419 : m_libspdm_use_aead_algo;
5420 :
5421 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5422 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
5423 : data_size;
5424 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5425 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5426 : data, data_size);
5427 : #else
5428 1 : libspdm_hash_all(
5429 : spdm_context->connection_info.algorithm.base_hash_algo,
5430 : data, data_size,
5431 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5432 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5433 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5434 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5435 : spdm_context->connection_info.algorithm.base_hash_algo,
5436 : spdm_context->connection_info.algorithm.base_asym_algo,
5437 : data, data_size,
5438 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5439 : #endif
5440 :
5441 1 : heartbeat_period = 0;
5442 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5443 1 : status = libspdm_send_receive_key_exchange(
5444 : spdm_context,
5445 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5446 : &session_id, &heartbeat_period, &slot_id_param,
5447 : measurement_hash);
5448 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5449 1 : assert_int_equal(session_id, 0xFFFFFFFF);
5450 1 : assert_int_equal(
5451 : libspdm_secured_message_get_session_state(
5452 : spdm_context->session_info[0].secured_message_context),
5453 : LIBSPDM_SESSION_STATE_HANDSHAKING);
5454 1 : free(data);
5455 1 : }
5456 :
5457 1 : static void libspdm_test_requester_key_exchange_case3(void **state)
5458 : {
5459 : libspdm_return_t status;
5460 : libspdm_test_context_t *spdm_test_context;
5461 : libspdm_context_t *spdm_context;
5462 : uint32_t session_id;
5463 : uint8_t heartbeat_period;
5464 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5465 : uint8_t slot_id_param;
5466 : void *data;
5467 : size_t data_size;
5468 : void *hash;
5469 : size_t hash_size;
5470 :
5471 1 : spdm_test_context = *state;
5472 1 : spdm_context = spdm_test_context->spdm_context;
5473 1 : spdm_test_context->case_id = 0x3;
5474 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5475 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5476 1 : spdm_context->connection_info.connection_state =
5477 : LIBSPDM_CONNECTION_STATE_NOT_STARTED;
5478 1 : spdm_context->connection_info.capability.flags |=
5479 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5480 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5481 1 : spdm_context->local_context.capability.flags |=
5482 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5483 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5484 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5485 : m_libspdm_use_asym_algo, &data,
5486 : &data_size, &hash, &hash_size);
5487 1 : libspdm_reset_message_a(spdm_context);
5488 1 : spdm_context->connection_info.algorithm.base_hash_algo =
5489 : m_libspdm_use_hash_algo;
5490 1 : spdm_context->connection_info.algorithm.base_asym_algo =
5491 : m_libspdm_use_asym_algo;
5492 1 : spdm_context->connection_info.algorithm.dhe_named_group =
5493 : m_libspdm_use_dhe_algo;
5494 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
5495 : m_libspdm_use_aead_algo;
5496 :
5497 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5498 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
5499 : data_size;
5500 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5501 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5502 : data, data_size);
5503 : #else
5504 1 : libspdm_hash_all(
5505 : spdm_context->connection_info.algorithm.base_hash_algo,
5506 : data, data_size,
5507 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5508 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5509 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5510 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5511 : spdm_context->connection_info.algorithm.base_hash_algo,
5512 : spdm_context->connection_info.algorithm.base_asym_algo,
5513 : data, data_size,
5514 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5515 : #endif
5516 :
5517 1 : heartbeat_period = 0;
5518 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5519 1 : status = libspdm_send_receive_key_exchange(
5520 : spdm_context,
5521 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5522 : &session_id, &heartbeat_period, &slot_id_param,
5523 : measurement_hash);
5524 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
5525 1 : free(data);
5526 1 : }
5527 :
5528 1 : static void libspdm_test_requester_key_exchange_case4(void **state)
5529 : {
5530 : libspdm_return_t status;
5531 : libspdm_test_context_t *spdm_test_context;
5532 : libspdm_context_t *spdm_context;
5533 : uint32_t session_id;
5534 : uint8_t heartbeat_period;
5535 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5536 : uint8_t slot_id_param;
5537 : void *data;
5538 : size_t data_size;
5539 : void *hash;
5540 : size_t hash_size;
5541 :
5542 1 : spdm_test_context = *state;
5543 1 : spdm_context = spdm_test_context->spdm_context;
5544 1 : spdm_test_context->case_id = 0x4;
5545 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5546 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5547 1 : spdm_context->connection_info.connection_state =
5548 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5549 1 : spdm_context->connection_info.capability.flags |=
5550 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5551 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5552 1 : spdm_context->local_context.capability.flags |=
5553 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5554 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5555 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5556 : m_libspdm_use_asym_algo, &data,
5557 : &data_size, &hash, &hash_size);
5558 1 : libspdm_reset_message_a(spdm_context);
5559 1 : spdm_context->connection_info.algorithm.base_hash_algo =
5560 : m_libspdm_use_hash_algo;
5561 1 : spdm_context->connection_info.algorithm.base_asym_algo =
5562 : m_libspdm_use_asym_algo;
5563 1 : spdm_context->connection_info.algorithm.dhe_named_group =
5564 : m_libspdm_use_dhe_algo;
5565 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
5566 : m_libspdm_use_aead_algo;
5567 :
5568 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5569 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
5570 : data_size;
5571 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5572 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5573 : data, data_size);
5574 : #else
5575 1 : libspdm_hash_all(
5576 : spdm_context->connection_info.algorithm.base_hash_algo,
5577 : data, data_size,
5578 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5579 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5580 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5581 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5582 : spdm_context->connection_info.algorithm.base_hash_algo,
5583 : spdm_context->connection_info.algorithm.base_asym_algo,
5584 : data, data_size,
5585 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5586 : #endif
5587 :
5588 1 : heartbeat_period = 0;
5589 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5590 1 : status = libspdm_send_receive_key_exchange(
5591 : spdm_context,
5592 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5593 : &session_id, &heartbeat_period, &slot_id_param,
5594 : measurement_hash);
5595 1 : assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
5596 1 : free(data);
5597 1 : }
5598 :
5599 1 : static void libspdm_test_requester_key_exchange_case5(void **state)
5600 : {
5601 : libspdm_return_t status;
5602 : libspdm_test_context_t *spdm_test_context;
5603 : libspdm_context_t *spdm_context;
5604 : uint32_t session_id;
5605 : uint8_t heartbeat_period;
5606 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5607 : uint8_t slot_id_param;
5608 : void *data;
5609 : size_t data_size;
5610 : void *hash;
5611 : size_t hash_size;
5612 :
5613 1 : spdm_test_context = *state;
5614 1 : spdm_context = spdm_test_context->spdm_context;
5615 1 : spdm_test_context->case_id = 0x5;
5616 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5617 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5618 1 : spdm_context->connection_info.connection_state =
5619 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5620 1 : spdm_context->connection_info.capability.flags |=
5621 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5622 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5623 1 : spdm_context->local_context.capability.flags |=
5624 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5625 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5626 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5627 : m_libspdm_use_asym_algo, &data,
5628 : &data_size, &hash, &hash_size);
5629 1 : libspdm_reset_message_a(spdm_context);
5630 1 : spdm_context->connection_info.algorithm.base_hash_algo =
5631 : m_libspdm_use_hash_algo;
5632 1 : spdm_context->connection_info.algorithm.base_asym_algo =
5633 : m_libspdm_use_asym_algo;
5634 1 : spdm_context->connection_info.algorithm.dhe_named_group =
5635 : m_libspdm_use_dhe_algo;
5636 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
5637 : m_libspdm_use_aead_algo;
5638 :
5639 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5640 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
5641 : data_size;
5642 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5643 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5644 : data, data_size);
5645 : #else
5646 1 : libspdm_hash_all(
5647 : spdm_context->connection_info.algorithm.base_hash_algo,
5648 : data, data_size,
5649 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5650 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5651 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5652 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5653 : spdm_context->connection_info.algorithm.base_hash_algo,
5654 : spdm_context->connection_info.algorithm.base_asym_algo,
5655 : data, data_size,
5656 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5657 : #endif
5658 :
5659 1 : heartbeat_period = 0;
5660 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5661 1 : status = libspdm_send_receive_key_exchange(
5662 : spdm_context,
5663 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5664 : &session_id, &heartbeat_period, &slot_id_param,
5665 : measurement_hash);
5666 1 : assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
5667 1 : free(data);
5668 1 : }
5669 :
5670 1 : static void libspdm_test_requester_key_exchange_case6(void **state)
5671 : {
5672 : libspdm_return_t status;
5673 : libspdm_test_context_t *spdm_test_context;
5674 : libspdm_context_t *spdm_context;
5675 : uint32_t session_id;
5676 : uint8_t heartbeat_period;
5677 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5678 : uint8_t slot_id_param;
5679 : void *data;
5680 : size_t data_size;
5681 : void *hash;
5682 : size_t hash_size;
5683 :
5684 1 : spdm_test_context = *state;
5685 1 : spdm_context = spdm_test_context->spdm_context;
5686 1 : spdm_test_context->case_id = 0x6;
5687 1 : spdm_context->retry_times = 3;
5688 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5689 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5690 1 : spdm_context->connection_info.connection_state =
5691 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5692 1 : spdm_context->connection_info.capability.flags |=
5693 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5694 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5695 1 : spdm_context->local_context.capability.flags |=
5696 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5697 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5698 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5699 : m_libspdm_use_asym_algo, &data,
5700 : &data_size, &hash, &hash_size);
5701 1 : libspdm_reset_message_a(spdm_context);
5702 1 : spdm_context->connection_info.algorithm.base_hash_algo =
5703 : m_libspdm_use_hash_algo;
5704 1 : spdm_context->connection_info.algorithm.base_asym_algo =
5705 : m_libspdm_use_asym_algo;
5706 1 : spdm_context->connection_info.algorithm.dhe_named_group =
5707 : m_libspdm_use_dhe_algo;
5708 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
5709 : m_libspdm_use_aead_algo;
5710 :
5711 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5712 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
5713 : data_size;
5714 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5715 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5716 : data, data_size);
5717 : #else
5718 1 : libspdm_hash_all(
5719 : spdm_context->connection_info.algorithm.base_hash_algo,
5720 : data, data_size,
5721 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5722 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5723 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5724 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5725 : spdm_context->connection_info.algorithm.base_hash_algo,
5726 : spdm_context->connection_info.algorithm.base_asym_algo,
5727 : data, data_size,
5728 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5729 : #endif
5730 :
5731 1 : heartbeat_period = 0;
5732 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5733 1 : status = libspdm_send_receive_key_exchange(
5734 : spdm_context,
5735 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5736 : &session_id, &heartbeat_period, &slot_id_param,
5737 : measurement_hash);
5738 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5739 1 : assert_int_equal(session_id, 0xFFFEFFFE);
5740 1 : assert_int_equal(
5741 : libspdm_secured_message_get_session_state(
5742 : spdm_context->session_info[0].secured_message_context),
5743 : LIBSPDM_SESSION_STATE_HANDSHAKING);
5744 1 : free(data);
5745 1 : }
5746 :
5747 1 : static void libspdm_test_requester_key_exchange_case7(void **state)
5748 : {
5749 : libspdm_return_t status;
5750 : libspdm_test_context_t *spdm_test_context;
5751 : libspdm_context_t *spdm_context;
5752 : uint32_t session_id;
5753 : uint8_t heartbeat_period;
5754 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5755 : uint8_t slot_id_param;
5756 : void *data;
5757 : size_t data_size;
5758 : void *hash;
5759 : size_t hash_size;
5760 :
5761 1 : spdm_test_context = *state;
5762 1 : spdm_context = spdm_test_context->spdm_context;
5763 1 : spdm_test_context->case_id = 0x7;
5764 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5765 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5766 1 : spdm_context->connection_info.connection_state =
5767 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5768 1 : spdm_context->connection_info.capability.flags |=
5769 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5770 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5771 1 : spdm_context->local_context.capability.flags |=
5772 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5773 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5774 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5775 : m_libspdm_use_asym_algo, &data,
5776 : &data_size, &hash, &hash_size);
5777 1 : libspdm_reset_message_a(spdm_context);
5778 1 : spdm_context->connection_info.algorithm.base_hash_algo =
5779 : m_libspdm_use_hash_algo;
5780 1 : spdm_context->connection_info.algorithm.base_asym_algo =
5781 : m_libspdm_use_asym_algo;
5782 1 : spdm_context->connection_info.algorithm.dhe_named_group =
5783 : m_libspdm_use_dhe_algo;
5784 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
5785 : m_libspdm_use_aead_algo;
5786 :
5787 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5788 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
5789 : data_size;
5790 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5791 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5792 : data, data_size);
5793 : #else
5794 1 : libspdm_hash_all(
5795 : spdm_context->connection_info.algorithm.base_hash_algo,
5796 : data, data_size,
5797 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5798 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5799 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5800 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5801 : spdm_context->connection_info.algorithm.base_hash_algo,
5802 : spdm_context->connection_info.algorithm.base_asym_algo,
5803 : data, data_size,
5804 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5805 : #endif
5806 :
5807 1 : heartbeat_period = 0;
5808 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5809 1 : status = libspdm_send_receive_key_exchange(
5810 : spdm_context,
5811 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5812 : &session_id, &heartbeat_period, &slot_id_param,
5813 : measurement_hash);
5814 1 : assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
5815 1 : assert_int_equal(spdm_context->connection_info.connection_state,
5816 : LIBSPDM_CONNECTION_STATE_NOT_STARTED);
5817 1 : free(data);
5818 1 : }
5819 :
5820 1 : static void libspdm_test_requester_key_exchange_case8(void **state)
5821 : {
5822 : libspdm_return_t status;
5823 : libspdm_test_context_t *spdm_test_context;
5824 : libspdm_context_t *spdm_context;
5825 : uint32_t session_id;
5826 : uint8_t heartbeat_period;
5827 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5828 : uint8_t slot_id_param;
5829 : void *data;
5830 : size_t data_size;
5831 : void *hash;
5832 : size_t hash_size;
5833 :
5834 1 : spdm_test_context = *state;
5835 1 : spdm_context = spdm_test_context->spdm_context;
5836 1 : spdm_test_context->case_id = 0x8;
5837 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5838 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5839 1 : spdm_context->connection_info.connection_state =
5840 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5841 1 : spdm_context->connection_info.capability.flags |=
5842 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5843 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5844 1 : spdm_context->local_context.capability.flags |=
5845 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5846 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5847 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5848 : m_libspdm_use_asym_algo, &data,
5849 : &data_size, &hash, &hash_size);
5850 1 : libspdm_reset_message_a(spdm_context);
5851 1 : spdm_context->connection_info.algorithm.base_hash_algo =
5852 : m_libspdm_use_hash_algo;
5853 1 : spdm_context->connection_info.algorithm.base_asym_algo =
5854 : m_libspdm_use_asym_algo;
5855 1 : spdm_context->connection_info.algorithm.dhe_named_group =
5856 : m_libspdm_use_dhe_algo;
5857 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
5858 : m_libspdm_use_aead_algo;
5859 :
5860 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5861 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
5862 : data_size;
5863 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5864 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5865 : data, data_size);
5866 : #else
5867 1 : libspdm_hash_all(
5868 : spdm_context->connection_info.algorithm.base_hash_algo,
5869 : data, data_size,
5870 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5871 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5872 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5873 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5874 : spdm_context->connection_info.algorithm.base_hash_algo,
5875 : spdm_context->connection_info.algorithm.base_asym_algo,
5876 : data, data_size,
5877 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5878 : #endif
5879 :
5880 1 : heartbeat_period = 0;
5881 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5882 1 : status = libspdm_send_receive_key_exchange(
5883 : spdm_context,
5884 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5885 : &session_id, &heartbeat_period, &slot_id_param,
5886 : measurement_hash);
5887 1 : assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
5888 1 : free(data);
5889 1 : }
5890 :
5891 1 : static void libspdm_test_requester_key_exchange_case9(void **state)
5892 : {
5893 : libspdm_return_t status;
5894 : libspdm_test_context_t *spdm_test_context;
5895 : libspdm_context_t *spdm_context;
5896 : uint32_t session_id;
5897 : uint8_t heartbeat_period;
5898 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5899 : uint8_t slot_id_param;
5900 : void *data;
5901 : size_t data_size;
5902 : void *hash;
5903 : size_t hash_size;
5904 :
5905 1 : spdm_test_context = *state;
5906 1 : spdm_context = spdm_test_context->spdm_context;
5907 1 : spdm_test_context->case_id = 0x9;
5908 1 : spdm_context->retry_times = 3;
5909 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5910 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5911 1 : spdm_context->connection_info.connection_state =
5912 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5913 1 : spdm_context->connection_info.capability.flags |=
5914 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5915 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5916 1 : spdm_context->local_context.capability.flags |=
5917 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5918 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5919 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5920 : m_libspdm_use_asym_algo, &data,
5921 : &data_size, &hash, &hash_size);
5922 1 : libspdm_reset_message_a(spdm_context);
5923 1 : spdm_context->connection_info.algorithm.base_hash_algo =
5924 : m_libspdm_use_hash_algo;
5925 1 : spdm_context->connection_info.algorithm.base_asym_algo =
5926 : m_libspdm_use_asym_algo;
5927 1 : spdm_context->connection_info.algorithm.dhe_named_group =
5928 : m_libspdm_use_dhe_algo;
5929 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
5930 : m_libspdm_use_aead_algo;
5931 :
5932 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5933 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
5934 : data_size;
5935 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5936 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5937 : data, data_size);
5938 : #else
5939 1 : libspdm_hash_all(
5940 : spdm_context->connection_info.algorithm.base_hash_algo,
5941 : data, data_size,
5942 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5943 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5944 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5945 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5946 : spdm_context->connection_info.algorithm.base_hash_algo,
5947 : spdm_context->connection_info.algorithm.base_asym_algo,
5948 : data, data_size,
5949 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5950 : #endif
5951 :
5952 1 : heartbeat_period = 0;
5953 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5954 1 : status = libspdm_send_receive_key_exchange(
5955 : spdm_context,
5956 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5957 : &session_id, &heartbeat_period, &slot_id_param,
5958 : measurement_hash);
5959 : if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
5960 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5961 1 : assert_int_equal(session_id, 0xFFFDFFFD);
5962 1 : assert_int_equal(
5963 : libspdm_secured_message_get_session_state(
5964 : spdm_context->session_info[0].secured_message_context),
5965 : LIBSPDM_SESSION_STATE_HANDSHAKING);
5966 : } else {
5967 : assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
5968 : }
5969 1 : free(data);
5970 1 : }
5971 :
5972 1 : static void libspdm_test_requester_key_exchange_case10(void **state) {
5973 : libspdm_return_t status;
5974 : libspdm_test_context_t *spdm_test_context;
5975 : libspdm_context_t *spdm_context;
5976 : uint32_t session_id;
5977 : uint8_t heartbeat_period;
5978 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5979 : uint8_t slot_id_param;
5980 : void *data;
5981 : size_t data_size;
5982 : void *hash;
5983 : size_t hash_size;
5984 : uint16_t error_code;
5985 :
5986 1 : spdm_test_context = *state;
5987 1 : spdm_context = spdm_test_context->spdm_context;
5988 1 : spdm_test_context->case_id = 0xA;
5989 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5990 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5991 1 : spdm_context->connection_info.capability.flags |=
5992 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
5993 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
5994 1 : libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
5995 : m_libspdm_use_asym_algo,
5996 : &data, &data_size,
5997 : &hash, &hash_size);
5998 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5999 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
6000 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
6001 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
6002 :
6003 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6004 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6005 : data_size;
6006 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6007 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6008 : data, data_size);
6009 : #else
6010 1 : libspdm_hash_all(
6011 : spdm_context->connection_info.algorithm.base_hash_algo,
6012 : data, data_size,
6013 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6014 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6015 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6016 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6017 : spdm_context->connection_info.algorithm.base_hash_algo,
6018 : spdm_context->connection_info.algorithm.base_asym_algo,
6019 : data, data_size,
6020 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6021 : #endif
6022 :
6023 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
6024 19 : while(error_code <= 0xff) {
6025 18 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6026 18 : libspdm_reset_message_a(spdm_context);
6027 :
6028 18 : heartbeat_period = 0;
6029 18 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6030 18 : status = libspdm_send_receive_key_exchange (spdm_context,
6031 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
6032 : 0, 0, &session_id, &heartbeat_period,
6033 : &slot_id_param, measurement_hash);
6034 18 : LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
6035 :
6036 18 : error_code++;
6037 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
6038 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
6039 : }
6040 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
6041 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
6042 : }
6043 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
6044 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
6045 : }
6046 : }
6047 :
6048 1 : free(data);
6049 1 : }
6050 :
6051 1 : static void libspdm_test_requester_key_exchange_case11(void **state)
6052 : {
6053 : libspdm_return_t status;
6054 : libspdm_test_context_t *spdm_test_context;
6055 : libspdm_context_t *spdm_context;
6056 : uint32_t session_id;
6057 : uint8_t heartbeat_period;
6058 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6059 : uint8_t slot_id_param;
6060 : void *data;
6061 : size_t data_size;
6062 : void *hash;
6063 : size_t hash_size;
6064 :
6065 1 : spdm_test_context = *state;
6066 1 : spdm_context = spdm_test_context->spdm_context;
6067 1 : spdm_test_context->case_id = 0xB;
6068 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6069 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6070 1 : spdm_context->connection_info.connection_state =
6071 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6072 1 : spdm_context->connection_info.capability.flags |=
6073 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
6074 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
6075 1 : spdm_context->local_context.capability.flags |=
6076 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
6077 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
6078 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6079 : m_libspdm_use_asym_algo, &data,
6080 : &data_size, &hash, &hash_size);
6081 1 : libspdm_reset_message_a(spdm_context);
6082 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6083 : m_libspdm_use_hash_algo;
6084 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6085 : m_libspdm_use_asym_algo;
6086 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6087 : m_libspdm_use_dhe_algo;
6088 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6089 : m_libspdm_use_aead_algo;
6090 :
6091 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6092 : spdm_context->transcript.message_m.buffer_size =
6093 : spdm_context->transcript.message_m.max_buffer_size;
6094 : spdm_context->transcript.message_b.buffer_size =
6095 : spdm_context->transcript.message_b.max_buffer_size;
6096 : spdm_context->transcript.message_c.buffer_size =
6097 : spdm_context->transcript.message_c.max_buffer_size;
6098 : spdm_context->transcript.message_mut_b.buffer_size =
6099 : spdm_context->transcript.message_mut_b.max_buffer_size;
6100 : spdm_context->transcript.message_mut_c.buffer_size =
6101 : spdm_context->transcript.message_mut_c.max_buffer_size;
6102 : #endif
6103 :
6104 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6105 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6106 : data_size;
6107 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6108 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6109 : data, data_size);
6110 : #else
6111 1 : libspdm_hash_all(
6112 : spdm_context->connection_info.algorithm.base_hash_algo,
6113 : data, data_size,
6114 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6115 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6116 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6117 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6118 : spdm_context->connection_info.algorithm.base_hash_algo,
6119 : spdm_context->connection_info.algorithm.base_asym_algo,
6120 : data, data_size,
6121 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6122 : #endif
6123 :
6124 1 : heartbeat_period = 0;
6125 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6126 1 : status = libspdm_send_receive_key_exchange(
6127 : spdm_context,
6128 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
6129 : &session_id, &heartbeat_period, &slot_id_param,
6130 : measurement_hash);
6131 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
6132 1 : assert_int_equal(
6133 : libspdm_secured_message_get_session_state(
6134 : spdm_context->session_info[0].secured_message_context),
6135 : LIBSPDM_SESSION_STATE_HANDSHAKING);
6136 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6137 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
6138 : assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
6139 : assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
6140 : assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
6141 : assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
6142 : #endif
6143 1 : free(data);
6144 1 : }
6145 :
6146 1 : static void libspdm_test_requester_key_exchange_case12(void **state)
6147 : {
6148 : libspdm_return_t status;
6149 : libspdm_test_context_t *spdm_test_context;
6150 : libspdm_context_t *spdm_context;
6151 : uint32_t session_id;
6152 : uint8_t heartbeat_period;
6153 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6154 : uint8_t slot_id_param;
6155 : void *data;
6156 : size_t data_size;
6157 : void *hash;
6158 : size_t hash_size;
6159 :
6160 1 : spdm_test_context = *state;
6161 1 : spdm_context = spdm_test_context->spdm_context;
6162 :
6163 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
6164 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
6165 : }
6166 :
6167 1 : spdm_test_context->case_id = 0xC;
6168 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6169 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6170 1 : spdm_context->connection_info.connection_state =
6171 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6172 1 : spdm_context->connection_info.capability.flags |=
6173 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
6174 1 : spdm_context->connection_info.capability.flags |=
6175 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
6176 1 : spdm_context->local_context.capability.flags |=
6177 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
6178 :
6179 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6180 : m_libspdm_use_asym_algo, &data,
6181 : &data_size, &hash, &hash_size);
6182 1 : libspdm_reset_message_a(spdm_context);
6183 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6184 : m_libspdm_use_hash_algo;
6185 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6186 : m_libspdm_use_asym_algo;
6187 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6188 : m_libspdm_use_dhe_algo;
6189 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6190 : m_libspdm_use_aead_algo;
6191 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
6192 : m_libspdm_use_measurement_hash_algo;
6193 :
6194 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6195 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6196 : data_size;
6197 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6198 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6199 : data, data_size);
6200 : #else
6201 1 : libspdm_hash_all(
6202 : spdm_context->connection_info.algorithm.base_hash_algo,
6203 : data, data_size,
6204 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6205 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6206 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6207 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6208 : spdm_context->connection_info.algorithm.base_hash_algo,
6209 : spdm_context->connection_info.algorithm.base_asym_algo,
6210 : data, data_size,
6211 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6212 : #endif
6213 :
6214 1 : heartbeat_period = 0;
6215 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6216 1 : status = libspdm_send_receive_key_exchange(
6217 : spdm_context,
6218 : SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
6219 : &session_id, &heartbeat_period, &slot_id_param,
6220 : measurement_hash);
6221 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
6222 1 : assert_int_equal(session_id, 0xFFFFFFFF);
6223 1 : assert_memory_equal(
6224 : measurement_hash,
6225 : m_libspdm_use_tcb_hash_value,
6226 : libspdm_get_hash_size(m_libspdm_use_hash_algo));
6227 1 : assert_int_equal(
6228 : libspdm_secured_message_get_session_state(
6229 : spdm_context->session_info[0].secured_message_context),
6230 : LIBSPDM_SESSION_STATE_HANDSHAKING);
6231 1 : free(data);
6232 1 : }
6233 :
6234 1 : static void libspdm_test_requester_key_exchange_case13(void **state)
6235 : {
6236 : libspdm_return_t status;
6237 : libspdm_test_context_t *spdm_test_context;
6238 : libspdm_context_t *spdm_context;
6239 : uint32_t session_id;
6240 : uint8_t heartbeat_period;
6241 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6242 : uint8_t slot_id_param;
6243 : void *data;
6244 : size_t data_size;
6245 : void *hash;
6246 : size_t hash_size;
6247 :
6248 1 : spdm_test_context = *state;
6249 1 : spdm_context = spdm_test_context->spdm_context;
6250 :
6251 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
6252 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
6253 : }
6254 :
6255 1 : spdm_test_context->case_id = 0xD;
6256 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6257 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6258 1 : spdm_context->connection_info.connection_state =
6259 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6260 1 : spdm_context->connection_info.capability.flags |=
6261 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
6262 1 : spdm_context->connection_info.capability.flags |=
6263 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
6264 1 : spdm_context->local_context.capability.flags |=
6265 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
6266 :
6267 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6268 : m_libspdm_use_asym_algo, &data,
6269 : &data_size, &hash, &hash_size);
6270 1 : libspdm_reset_message_a(spdm_context);
6271 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6272 : m_libspdm_use_hash_algo;
6273 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6274 : m_libspdm_use_asym_algo;
6275 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6276 : m_libspdm_use_dhe_algo;
6277 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6278 : m_libspdm_use_aead_algo;
6279 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
6280 : m_libspdm_use_measurement_hash_algo;
6281 :
6282 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6283 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6284 : data_size;
6285 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6286 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6287 : data, data_size);
6288 : #else
6289 1 : libspdm_hash_all(
6290 : spdm_context->connection_info.algorithm.base_hash_algo,
6291 : data, data_size,
6292 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6293 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6294 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6295 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6296 : spdm_context->connection_info.algorithm.base_hash_algo,
6297 : spdm_context->connection_info.algorithm.base_asym_algo,
6298 : data, data_size,
6299 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6300 : #endif
6301 :
6302 1 : heartbeat_period = 0;
6303 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6304 1 : status = libspdm_send_receive_key_exchange(
6305 : spdm_context,
6306 : SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
6307 : &session_id, &heartbeat_period, &slot_id_param,
6308 : measurement_hash);
6309 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
6310 1 : assert_int_equal(session_id, 0xFFFFFFFF);
6311 1 : assert_memory_equal(
6312 : measurement_hash,
6313 : m_libspdm_zero_filled_buffer,
6314 : libspdm_get_hash_size(m_libspdm_use_hash_algo));
6315 1 : assert_int_equal(
6316 : libspdm_secured_message_get_session_state(
6317 : spdm_context->session_info[0].secured_message_context),
6318 : LIBSPDM_SESSION_STATE_HANDSHAKING);
6319 1 : free(data);
6320 1 : }
6321 :
6322 1 : static void libspdm_test_requester_key_exchange_case14(void **state)
6323 : {
6324 : libspdm_return_t status;
6325 : libspdm_test_context_t *spdm_test_context;
6326 : libspdm_context_t *spdm_context;
6327 : uint32_t session_id;
6328 : uint8_t heartbeat_period;
6329 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6330 : uint8_t slot_id_param;
6331 : void *data;
6332 : size_t data_size;
6333 : void *hash;
6334 : size_t hash_size;
6335 :
6336 1 : spdm_test_context = *state;
6337 1 : spdm_context = spdm_test_context->spdm_context;
6338 :
6339 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
6340 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
6341 : }
6342 :
6343 1 : spdm_test_context->case_id = 0xE;
6344 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6345 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6346 1 : spdm_context->connection_info.connection_state =
6347 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6348 1 : spdm_context->connection_info.capability.flags |=
6349 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
6350 1 : spdm_context->connection_info.capability.flags |=
6351 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
6352 1 : spdm_context->local_context.capability.flags |=
6353 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
6354 :
6355 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6356 : m_libspdm_use_asym_algo, &data,
6357 : &data_size, &hash, &hash_size);
6358 1 : libspdm_reset_message_a(spdm_context);
6359 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6360 : m_libspdm_use_hash_algo;
6361 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6362 : m_libspdm_use_asym_algo;
6363 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6364 : m_libspdm_use_dhe_algo;
6365 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6366 : m_libspdm_use_aead_algo;
6367 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
6368 : m_libspdm_use_measurement_hash_algo;
6369 :
6370 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6371 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6372 : data_size;
6373 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6374 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6375 : data, data_size);
6376 : #else
6377 1 : libspdm_hash_all(
6378 : spdm_context->connection_info.algorithm.base_hash_algo,
6379 : data, data_size,
6380 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6381 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6382 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6383 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6384 : spdm_context->connection_info.algorithm.base_hash_algo,
6385 : spdm_context->connection_info.algorithm.base_asym_algo,
6386 : data, data_size,
6387 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6388 : #endif
6389 :
6390 1 : heartbeat_period = 0;
6391 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6392 1 : status = libspdm_send_receive_key_exchange(
6393 : spdm_context,
6394 : SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, 0,
6395 : &session_id, &heartbeat_period, &slot_id_param,
6396 : measurement_hash);
6397 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
6398 1 : assert_int_equal(session_id, 0xFFFFFFFF);
6399 1 : assert_memory_equal(
6400 : measurement_hash,
6401 : m_libspdm_use_tcb_hash_value,
6402 : libspdm_get_hash_size(m_libspdm_use_hash_algo));
6403 1 : assert_int_equal(
6404 : libspdm_secured_message_get_session_state(
6405 : spdm_context->session_info[0].secured_message_context),
6406 : LIBSPDM_SESSION_STATE_HANDSHAKING);
6407 1 : free(data);
6408 1 : }
6409 :
6410 1 : static void libspdm_test_requester_key_exchange_case15(void **state)
6411 : {
6412 : libspdm_return_t status;
6413 : libspdm_test_context_t *spdm_test_context;
6414 : libspdm_context_t *spdm_context;
6415 : uint32_t session_id;
6416 : uint8_t heartbeat_period;
6417 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6418 : uint8_t slot_id_param;
6419 : void *data;
6420 : size_t data_size;
6421 : void *hash;
6422 : size_t hash_size;
6423 :
6424 1 : spdm_test_context = *state;
6425 1 : spdm_context = spdm_test_context->spdm_context;
6426 :
6427 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
6428 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
6429 : }
6430 :
6431 1 : spdm_test_context->case_id = 0xF;
6432 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6433 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6434 1 : spdm_context->connection_info.connection_state =
6435 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6436 1 : spdm_context->connection_info.capability.flags |=
6437 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
6438 1 : spdm_context->connection_info.capability.flags |=
6439 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
6440 1 : spdm_context->local_context.capability.flags |=
6441 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
6442 :
6443 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6444 : m_libspdm_use_asym_algo, &data,
6445 : &data_size, &hash, &hash_size);
6446 1 : libspdm_reset_message_a(spdm_context);
6447 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6448 : m_libspdm_use_hash_algo;
6449 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6450 : m_libspdm_use_asym_algo;
6451 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6452 : m_libspdm_use_dhe_algo;
6453 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6454 : m_libspdm_use_aead_algo;
6455 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
6456 : m_libspdm_use_measurement_hash_algo;
6457 :
6458 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6459 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6460 : data_size;
6461 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6462 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6463 : data, data_size);
6464 : #else
6465 1 : libspdm_hash_all(
6466 : spdm_context->connection_info.algorithm.base_hash_algo,
6467 : data, data_size,
6468 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6469 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6470 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6471 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6472 : spdm_context->connection_info.algorithm.base_hash_algo,
6473 : spdm_context->connection_info.algorithm.base_asym_algo,
6474 : data, data_size,
6475 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6476 : #endif
6477 :
6478 1 : heartbeat_period = 0;
6479 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6480 1 : status = libspdm_send_receive_key_exchange(
6481 : spdm_context,
6482 : SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
6483 : &session_id, &heartbeat_period, &slot_id_param,
6484 : measurement_hash);
6485 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
6486 1 : free(data);
6487 1 : }
6488 :
6489 1 : static void libspdm_test_requester_key_exchange_case16(void **state)
6490 : {
6491 : libspdm_return_t status;
6492 : libspdm_test_context_t *spdm_test_context;
6493 : libspdm_context_t *spdm_context;
6494 : uint32_t session_id;
6495 : uint8_t heartbeat_period;
6496 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6497 : uint8_t slot_id_param;
6498 : void *data;
6499 : size_t data_size;
6500 : void *hash;
6501 : size_t hash_size;
6502 :
6503 1 : spdm_test_context = *state;
6504 1 : spdm_context = spdm_test_context->spdm_context;
6505 :
6506 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
6507 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
6508 : }
6509 :
6510 1 : spdm_test_context->case_id = 0x10;
6511 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6512 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6513 1 : spdm_context->connection_info.connection_state =
6514 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6515 1 : spdm_context->connection_info.capability.flags |=
6516 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
6517 1 : spdm_context->connection_info.capability.flags |=
6518 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
6519 1 : spdm_context->local_context.capability.flags |=
6520 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
6521 :
6522 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6523 : m_libspdm_use_asym_algo, &data,
6524 : &data_size, &hash, &hash_size);
6525 1 : libspdm_reset_message_a(spdm_context);
6526 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6527 : m_libspdm_use_hash_algo;
6528 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6529 : m_libspdm_use_asym_algo;
6530 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6531 : m_libspdm_use_dhe_algo;
6532 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6533 : m_libspdm_use_aead_algo;
6534 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
6535 : m_libspdm_use_measurement_hash_algo;
6536 :
6537 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6538 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6539 : data_size;
6540 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6541 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6542 : data, data_size);
6543 : #else
6544 1 : libspdm_hash_all(
6545 : spdm_context->connection_info.algorithm.base_hash_algo,
6546 : data, data_size,
6547 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6548 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6549 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6550 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6551 : spdm_context->connection_info.algorithm.base_hash_algo,
6552 : spdm_context->connection_info.algorithm.base_asym_algo,
6553 : data, data_size,
6554 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6555 : #endif
6556 :
6557 1 : heartbeat_period = 0;
6558 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6559 1 : status = libspdm_send_receive_key_exchange(
6560 : spdm_context,
6561 : SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, 0,
6562 : &session_id, &heartbeat_period, &slot_id_param,
6563 : measurement_hash);
6564 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
6565 1 : free(data);
6566 1 : }
6567 :
6568 1 : static void libspdm_test_requester_key_exchange_case17(void **state)
6569 : {
6570 : libspdm_return_t status;
6571 : libspdm_test_context_t *spdm_test_context;
6572 : libspdm_context_t *spdm_context;
6573 : uint32_t session_id;
6574 : uint8_t heartbeat_period;
6575 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6576 : uint8_t slot_id_param;
6577 : void *data;
6578 : size_t data_size;
6579 : void *hash;
6580 : size_t hash_size;
6581 :
6582 1 : spdm_test_context = *state;
6583 1 : spdm_context = spdm_test_context->spdm_context;
6584 :
6585 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
6586 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
6587 : }
6588 :
6589 1 : spdm_test_context->case_id = 0x11;
6590 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6591 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6592 1 : spdm_context->connection_info.connection_state =
6593 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6594 1 : spdm_context->connection_info.capability.flags |=
6595 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
6596 1 : spdm_context->connection_info.capability.flags |=
6597 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
6598 1 : spdm_context->local_context.capability.flags |=
6599 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
6600 :
6601 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6602 : m_libspdm_use_asym_algo, &data,
6603 : &data_size, &hash, &hash_size);
6604 1 : libspdm_reset_message_a(spdm_context);
6605 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6606 : m_libspdm_use_hash_algo;
6607 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6608 : m_libspdm_use_asym_algo;
6609 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6610 : m_libspdm_use_dhe_algo;
6611 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6612 : m_libspdm_use_aead_algo;
6613 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
6614 : m_libspdm_use_measurement_hash_algo;
6615 :
6616 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6617 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6618 : data_size;
6619 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6620 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6621 : data, data_size);
6622 : #else
6623 1 : libspdm_hash_all(
6624 : spdm_context->connection_info.algorithm.base_hash_algo,
6625 : data, data_size,
6626 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6627 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6628 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6629 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6630 : spdm_context->connection_info.algorithm.base_hash_algo,
6631 : spdm_context->connection_info.algorithm.base_asym_algo,
6632 : data, data_size,
6633 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6634 : #endif
6635 :
6636 1 : heartbeat_period = 0;
6637 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6638 1 : status = libspdm_send_receive_key_exchange(
6639 : spdm_context,
6640 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
6641 : &session_id, &heartbeat_period, &slot_id_param,
6642 : measurement_hash);
6643 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
6644 1 : free(data);
6645 1 : }
6646 :
6647 1 : static void libspdm_test_requester_key_exchange_case18(void **state)
6648 : {
6649 : libspdm_return_t status;
6650 : libspdm_test_context_t *spdm_test_context;
6651 : libspdm_context_t *spdm_context;
6652 : uint32_t session_id;
6653 : uint8_t heartbeat_period;
6654 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6655 : uint8_t slot_id_param;
6656 : void *data;
6657 : size_t data_size;
6658 : void *hash;
6659 : size_t hash_size;
6660 :
6661 1 : spdm_test_context = *state;
6662 1 : spdm_context = spdm_test_context->spdm_context;
6663 :
6664 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
6665 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
6666 : }
6667 :
6668 1 : spdm_test_context->case_id = 0x12;
6669 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6670 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6671 1 : spdm_context->connection_info.connection_state =
6672 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6673 1 : spdm_context->connection_info.capability.flags |=
6674 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
6675 1 : spdm_context->connection_info.capability.flags |=
6676 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
6677 1 : spdm_context->local_context.capability.flags |=
6678 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
6679 :
6680 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6681 : m_libspdm_use_asym_algo, &data,
6682 : &data_size, &hash, &hash_size);
6683 1 : libspdm_reset_message_a(spdm_context);
6684 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6685 : m_libspdm_use_hash_algo;
6686 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6687 : m_libspdm_use_asym_algo;
6688 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6689 : m_libspdm_use_dhe_algo;
6690 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6691 : m_libspdm_use_aead_algo;
6692 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
6693 : m_libspdm_use_measurement_hash_algo;
6694 :
6695 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6696 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6697 : data_size;
6698 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6699 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6700 : data, data_size);
6701 : #else
6702 1 : libspdm_hash_all(
6703 : spdm_context->connection_info.algorithm.base_hash_algo,
6704 : data, data_size,
6705 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6706 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6707 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6708 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6709 : spdm_context->connection_info.algorithm.base_hash_algo,
6710 : spdm_context->connection_info.algorithm.base_asym_algo,
6711 : data, data_size,
6712 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6713 : #endif
6714 :
6715 1 : heartbeat_period = 0;
6716 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6717 1 : status = libspdm_send_receive_key_exchange(
6718 : spdm_context,
6719 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
6720 : &session_id, &heartbeat_period, &slot_id_param,
6721 : measurement_hash);
6722 1 : assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
6723 1 : free(data);
6724 1 : }
6725 :
6726 1 : static void libspdm_test_requester_key_exchange_case19(void **state)
6727 : {
6728 : libspdm_return_t status;
6729 : libspdm_test_context_t *spdm_test_context;
6730 : libspdm_context_t *spdm_context;
6731 : uint32_t session_id;
6732 : uint8_t heartbeat_period;
6733 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6734 : uint8_t slot_id_param;
6735 : void *data;
6736 : size_t data_size;
6737 : void *hash;
6738 : size_t hash_size;
6739 :
6740 1 : spdm_test_context = *state;
6741 1 : spdm_context = spdm_test_context->spdm_context;
6742 1 : spdm_test_context->case_id = 0x13;
6743 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6744 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6745 1 : spdm_context->connection_info.connection_state =
6746 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6747 1 : spdm_context->connection_info.capability.flags |=
6748 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
6749 1 : spdm_context->connection_info.capability.flags |=
6750 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
6751 1 : spdm_context->local_context.capability.flags |=
6752 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
6753 :
6754 1 : spdm_context->connection_info.capability.flags |=
6755 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
6756 1 : spdm_context->local_context.capability.flags |=
6757 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
6758 :
6759 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6760 : m_libspdm_use_asym_algo, &data,
6761 : &data_size, &hash, &hash_size);
6762 1 : libspdm_reset_message_a(spdm_context);
6763 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6764 : m_libspdm_use_hash_algo;
6765 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6766 : m_libspdm_use_asym_algo;
6767 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6768 : m_libspdm_use_dhe_algo;
6769 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6770 : m_libspdm_use_aead_algo;
6771 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
6772 : m_libspdm_use_measurement_hash_algo;
6773 :
6774 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6775 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6776 : data_size;
6777 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6778 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6779 : data, data_size);
6780 : #else
6781 1 : libspdm_hash_all(
6782 : spdm_context->connection_info.algorithm.base_hash_algo,
6783 : data, data_size,
6784 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6785 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6786 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6787 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6788 : spdm_context->connection_info.algorithm.base_hash_algo,
6789 : spdm_context->connection_info.algorithm.base_asym_algo,
6790 : data, data_size,
6791 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6792 : #endif
6793 :
6794 1 : heartbeat_period = 0;
6795 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6796 1 : status = libspdm_send_receive_key_exchange(
6797 : spdm_context,
6798 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
6799 : &session_id, &heartbeat_period, &slot_id_param,
6800 : measurement_hash);
6801 : /* Clear Handshake in the clear flags */
6802 1 : spdm_context->connection_info.capability.flags &=
6803 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
6804 1 : spdm_context->local_context.capability.flags &=
6805 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
6806 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
6807 1 : assert_int_equal(session_id, 0xFFFFFFFF);
6808 1 : assert_int_equal(
6809 : libspdm_secured_message_get_session_state(
6810 : spdm_context->session_info[0].secured_message_context),
6811 : LIBSPDM_SESSION_STATE_HANDSHAKING);
6812 1 : free(data);
6813 1 : }
6814 :
6815 1 : static void libspdm_test_requester_key_exchange_case20(void **state)
6816 : {
6817 : libspdm_return_t status;
6818 : libspdm_test_context_t *spdm_test_context;
6819 : libspdm_context_t *spdm_context;
6820 : uint32_t session_id;
6821 : uint8_t heartbeat_period;
6822 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6823 : uint8_t slot_id_param;
6824 : void *data;
6825 : size_t data_size;
6826 : void *hash;
6827 : size_t hash_size;
6828 :
6829 1 : spdm_test_context = *state;
6830 1 : spdm_context = spdm_test_context->spdm_context;
6831 :
6832 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
6833 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
6834 : }
6835 :
6836 1 : spdm_test_context->case_id = 0x14;
6837 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6838 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6839 1 : spdm_context->connection_info.connection_state =
6840 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6841 1 : spdm_context->connection_info.capability.flags |=
6842 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
6843 1 : spdm_context->connection_info.capability.flags |=
6844 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
6845 1 : spdm_context->local_context.capability.flags |=
6846 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
6847 :
6848 :
6849 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6850 : m_libspdm_use_asym_algo, &data,
6851 : &data_size, &hash, &hash_size);
6852 1 : libspdm_reset_message_a(spdm_context);
6853 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6854 : m_libspdm_use_hash_algo;
6855 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6856 : m_libspdm_use_asym_algo;
6857 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6858 : m_libspdm_use_dhe_algo;
6859 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6860 : m_libspdm_use_aead_algo;
6861 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
6862 : m_libspdm_use_measurement_hash_algo;
6863 :
6864 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6865 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6866 : data_size;
6867 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6868 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6869 : data, data_size);
6870 : #else
6871 1 : libspdm_hash_all(
6872 : spdm_context->connection_info.algorithm.base_hash_algo,
6873 : data, data_size,
6874 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6875 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6876 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6877 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6878 : spdm_context->connection_info.algorithm.base_hash_algo,
6879 : spdm_context->connection_info.algorithm.base_asym_algo,
6880 : data, data_size,
6881 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6882 : #endif
6883 :
6884 1 : heartbeat_period = 0;
6885 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6886 1 : status = libspdm_send_receive_key_exchange(
6887 : spdm_context,
6888 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
6889 : &session_id, &heartbeat_period, &slot_id_param,
6890 : measurement_hash);
6891 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
6892 1 : free(data);
6893 1 : }
6894 :
6895 1 : static void libspdm_test_requester_key_exchange_case21(void **state)
6896 : {
6897 : libspdm_return_t status;
6898 : libspdm_test_context_t *spdm_test_context;
6899 : libspdm_context_t *spdm_context;
6900 : uint32_t session_id;
6901 : uint8_t heartbeat_period;
6902 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6903 : uint8_t slot_id_param;
6904 : void *data;
6905 : size_t data_size;
6906 : void *hash;
6907 : size_t hash_size;
6908 :
6909 1 : spdm_test_context = *state;
6910 1 : spdm_context = spdm_test_context->spdm_context;
6911 :
6912 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
6913 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
6914 : }
6915 :
6916 1 : spdm_test_context->case_id = 0x15;
6917 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
6918 : SPDM_VERSION_NUMBER_SHIFT_BIT;
6919 1 : spdm_context->connection_info.connection_state =
6920 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6921 1 : spdm_context->connection_info.capability.flags |=
6922 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
6923 1 : spdm_context->connection_info.capability.flags |=
6924 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
6925 1 : spdm_context->local_context.capability.flags |=
6926 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
6927 :
6928 1 : spdm_context->connection_info.capability.flags |=
6929 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
6930 1 : spdm_context->local_context.capability.flags |=
6931 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
6932 :
6933 :
6934 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
6935 : m_libspdm_use_asym_algo, &data,
6936 : &data_size, &hash, &hash_size);
6937 1 : libspdm_reset_message_a(spdm_context);
6938 1 : spdm_context->connection_info.algorithm.base_hash_algo =
6939 : m_libspdm_use_hash_algo;
6940 1 : spdm_context->connection_info.algorithm.base_asym_algo =
6941 : m_libspdm_use_asym_algo;
6942 1 : spdm_context->connection_info.algorithm.dhe_named_group =
6943 : m_libspdm_use_dhe_algo;
6944 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
6945 : m_libspdm_use_aead_algo;
6946 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
6947 : m_libspdm_use_measurement_hash_algo;
6948 :
6949 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
6950 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
6951 : data_size;
6952 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
6953 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
6954 : data, data_size);
6955 : #else
6956 1 : libspdm_hash_all(
6957 : spdm_context->connection_info.algorithm.base_hash_algo,
6958 : data, data_size,
6959 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
6960 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
6961 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
6962 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
6963 : spdm_context->connection_info.algorithm.base_hash_algo,
6964 : spdm_context->connection_info.algorithm.base_asym_algo,
6965 : data, data_size,
6966 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
6967 : #endif
6968 :
6969 1 : heartbeat_period = 0;
6970 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
6971 1 : status = libspdm_send_receive_key_exchange(
6972 : spdm_context,
6973 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
6974 : &session_id, &heartbeat_period, &slot_id_param,
6975 : measurement_hash);
6976 : /* clear Heartbeat flags */
6977 1 : spdm_context->connection_info.capability.flags &=
6978 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
6979 1 : spdm_context->local_context.capability.flags &=
6980 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
6981 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
6982 1 : assert_int_equal(session_id, 0xFFFFFFFF);
6983 1 : assert_int_equal(
6984 : libspdm_secured_message_get_session_state(
6985 : spdm_context->session_info[0].secured_message_context),
6986 : LIBSPDM_SESSION_STATE_HANDSHAKING);
6987 1 : assert_int_equal(heartbeat_period,5);
6988 1 : free(data);
6989 1 : }
6990 :
6991 1 : static void libspdm_test_requester_key_exchange_case22(void **state)
6992 : {
6993 : libspdm_return_t status;
6994 : libspdm_test_context_t *spdm_test_context;
6995 : libspdm_context_t *spdm_context;
6996 : uint32_t session_id;
6997 : uint8_t heartbeat_period;
6998 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
6999 : uint8_t slot_id_param;
7000 : void *data;
7001 : size_t data_size;
7002 : void *hash;
7003 : size_t hash_size;
7004 :
7005 1 : spdm_test_context = *state;
7006 1 : spdm_context = spdm_test_context->spdm_context;
7007 :
7008 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
7009 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
7010 : }
7011 :
7012 1 : spdm_test_context->case_id = 0x16;
7013 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
7014 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7015 1 : spdm_context->connection_info.connection_state =
7016 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7017 1 : spdm_context->connection_info.capability.flags |=
7018 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
7019 1 : spdm_context->connection_info.capability.flags |=
7020 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
7021 1 : spdm_context->local_context.capability.flags |=
7022 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
7023 :
7024 1 : spdm_context->connection_info.capability.flags |=
7025 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
7026 1 : spdm_context->local_context.capability.flags |=
7027 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
7028 :
7029 :
7030 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
7031 : m_libspdm_use_asym_algo, &data,
7032 : &data_size, &hash, &hash_size);
7033 1 : libspdm_reset_message_a(spdm_context);
7034 1 : spdm_context->connection_info.algorithm.base_hash_algo =
7035 : m_libspdm_use_hash_algo;
7036 1 : spdm_context->connection_info.algorithm.base_asym_algo =
7037 : m_libspdm_use_asym_algo;
7038 1 : spdm_context->connection_info.algorithm.dhe_named_group =
7039 : m_libspdm_use_dhe_algo;
7040 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
7041 : m_libspdm_use_aead_algo;
7042 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
7043 : m_libspdm_use_measurement_hash_algo;
7044 :
7045 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7046 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
7047 : data_size;
7048 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
7049 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
7050 : data, data_size);
7051 : #else
7052 1 : libspdm_hash_all(
7053 : spdm_context->connection_info.algorithm.base_hash_algo,
7054 : data, data_size,
7055 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
7056 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
7057 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
7058 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
7059 : spdm_context->connection_info.algorithm.base_hash_algo,
7060 : spdm_context->connection_info.algorithm.base_asym_algo,
7061 : data, data_size,
7062 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
7063 : #endif
7064 :
7065 1 : heartbeat_period = 0;
7066 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7067 1 : status = libspdm_send_receive_key_exchange(
7068 : spdm_context,
7069 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
7070 : &session_id, &heartbeat_period, &slot_id_param,
7071 : measurement_hash);
7072 :
7073 : /*clear Heartbeat flags*/
7074 1 : spdm_context->connection_info.capability.flags &=
7075 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
7076 1 : spdm_context->local_context.capability.flags &=
7077 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
7078 :
7079 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
7080 1 : assert_int_equal(session_id, 0xFFFFFFFF);
7081 1 : assert_int_equal(
7082 : libspdm_secured_message_get_session_state(
7083 : spdm_context->session_info[0].secured_message_context),
7084 : LIBSPDM_SESSION_STATE_HANDSHAKING);
7085 1 : assert_int_equal(heartbeat_period,0);
7086 1 : free(data);
7087 1 : }
7088 :
7089 1 : static void libspdm_test_requester_key_exchange_case23(void **state)
7090 : {
7091 : libspdm_return_t status;
7092 : libspdm_test_context_t *spdm_test_context;
7093 : libspdm_context_t *spdm_context;
7094 : uint32_t session_id;
7095 : uint8_t heartbeat_period;
7096 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
7097 : uint8_t slot_id_param;
7098 : void *data;
7099 : size_t data_size;
7100 : void *hash;
7101 : size_t hash_size;
7102 :
7103 1 : spdm_test_context = *state;
7104 1 : spdm_context = spdm_test_context->spdm_context;
7105 :
7106 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
7107 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
7108 : }
7109 :
7110 1 : spdm_test_context->case_id = 0x17;
7111 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
7112 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7113 1 : spdm_context->connection_info.connection_state =
7114 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7115 1 : spdm_context->connection_info.capability.flags |=
7116 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
7117 1 : spdm_context->connection_info.capability.flags |=
7118 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
7119 1 : spdm_context->local_context.capability.flags |=
7120 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
7121 :
7122 1 : spdm_context->connection_info.capability.flags |=
7123 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7124 1 : spdm_context->local_context.capability.flags |=
7125 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7126 :
7127 :
7128 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
7129 : m_libspdm_use_asym_algo, &data,
7130 : &data_size, &hash, &hash_size);
7131 1 : libspdm_reset_message_a(spdm_context);
7132 1 : spdm_context->connection_info.algorithm.base_hash_algo =
7133 : m_libspdm_use_hash_algo;
7134 1 : spdm_context->connection_info.algorithm.base_asym_algo =
7135 : m_libspdm_use_asym_algo;
7136 1 : spdm_context->connection_info.algorithm.dhe_named_group =
7137 : m_libspdm_use_dhe_algo;
7138 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
7139 : m_libspdm_use_aead_algo;
7140 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
7141 : m_libspdm_use_measurement_hash_algo;
7142 :
7143 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7144 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
7145 : data_size;
7146 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
7147 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
7148 : data, data_size);
7149 : #else
7150 1 : libspdm_hash_all(
7151 : spdm_context->connection_info.algorithm.base_hash_algo,
7152 : data, data_size,
7153 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
7154 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
7155 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
7156 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
7157 : spdm_context->connection_info.algorithm.base_hash_algo,
7158 : spdm_context->connection_info.algorithm.base_asym_algo,
7159 : data, data_size,
7160 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
7161 : #endif
7162 :
7163 1 : heartbeat_period = 0;
7164 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7165 1 : status = libspdm_send_receive_key_exchange(
7166 : spdm_context,
7167 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
7168 : &session_id, &heartbeat_period, &slot_id_param,
7169 : measurement_hash);
7170 : /* Clear Mut_auth flags */
7171 1 : spdm_context->connection_info.capability.flags &=
7172 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7173 1 : spdm_context->local_context.capability.flags &=
7174 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7175 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
7176 1 : assert_int_equal(session_id, 0xFFFFFFFF);
7177 1 : assert_int_equal(
7178 : libspdm_secured_message_get_session_state(
7179 : spdm_context->session_info[0].secured_message_context),
7180 : LIBSPDM_SESSION_STATE_HANDSHAKING);
7181 1 : assert_int_equal(
7182 : spdm_context->session_info[0].mut_auth_requested,
7183 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED);
7184 1 : free(data);
7185 1 : }
7186 :
7187 1 : static void libspdm_test_requester_key_exchange_case24(void **state)
7188 : {
7189 : libspdm_return_t status;
7190 : libspdm_test_context_t *spdm_test_context;
7191 : libspdm_context_t *spdm_context;
7192 : uint32_t session_id;
7193 : uint8_t heartbeat_period;
7194 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
7195 : uint8_t slot_id_param;
7196 : void *data;
7197 : size_t data_size;
7198 : void *hash;
7199 : size_t hash_size;
7200 :
7201 1 : spdm_test_context = *state;
7202 1 : spdm_context = spdm_test_context->spdm_context;
7203 :
7204 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
7205 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
7206 : }
7207 :
7208 1 : spdm_test_context->case_id = 0x18;
7209 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
7210 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7211 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7212 1 : spdm_context->connection_info.capability.flags |=
7213 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
7214 1 : spdm_context->connection_info.capability.flags |=
7215 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
7216 1 : spdm_context->local_context.capability.flags |=
7217 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
7218 :
7219 1 : spdm_context->connection_info.capability.flags |=
7220 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7221 1 : spdm_context->local_context.capability.flags |=
7222 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7223 :
7224 1 : spdm_context->connection_info.capability.flags |=
7225 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
7226 1 : spdm_context->local_context.capability.flags |=
7227 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
7228 :
7229 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
7230 : m_libspdm_use_asym_algo, &data,
7231 : &data_size, &hash, &hash_size);
7232 1 : libspdm_reset_message_a(spdm_context);
7233 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
7234 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
7235 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
7236 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
7237 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
7238 : m_libspdm_use_measurement_hash_algo;
7239 :
7240 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7241 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
7242 : data_size;
7243 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
7244 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
7245 : data, data_size);
7246 : #else
7247 1 : libspdm_hash_all(
7248 : spdm_context->connection_info.algorithm.base_hash_algo,
7249 : data, data_size,
7250 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
7251 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
7252 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
7253 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
7254 : spdm_context->connection_info.algorithm.base_hash_algo,
7255 : spdm_context->connection_info.algorithm.base_asym_algo,
7256 : data, data_size,
7257 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
7258 : #endif
7259 :
7260 1 : heartbeat_period = 0;
7261 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7262 1 : status = libspdm_send_receive_key_exchange(
7263 : spdm_context,
7264 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
7265 : &session_id, &heartbeat_period, &slot_id_param,
7266 : measurement_hash);
7267 : /* Clear Mut_auth flags */
7268 1 : spdm_context->connection_info.capability.flags &=
7269 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7270 1 : spdm_context->local_context.capability.flags &=
7271 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7272 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
7273 1 : assert_int_equal(session_id, 0xFFFFFFFF);
7274 1 : assert_int_equal(
7275 : libspdm_secured_message_get_session_state(
7276 : spdm_context->session_info[0].secured_message_context),
7277 : LIBSPDM_SESSION_STATE_HANDSHAKING);
7278 1 : assert_int_equal(
7279 : spdm_context->session_info[0].mut_auth_requested,
7280 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST);
7281 1 : free(data);
7282 1 : }
7283 :
7284 1 : static void libspdm_test_requester_key_exchange_case25(void **state)
7285 : {
7286 : libspdm_return_t status;
7287 : libspdm_test_context_t *spdm_test_context;
7288 : libspdm_context_t *spdm_context;
7289 : uint32_t session_id;
7290 : uint8_t heartbeat_period;
7291 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
7292 : uint8_t slot_id_param;
7293 : void *data;
7294 : size_t data_size;
7295 : void *hash;
7296 : size_t hash_size;
7297 :
7298 1 : spdm_test_context = *state;
7299 1 : spdm_context = spdm_test_context->spdm_context;
7300 :
7301 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
7302 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
7303 : }
7304 :
7305 1 : spdm_test_context->case_id = 0x19;
7306 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
7307 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7308 1 : spdm_context->connection_info.connection_state =
7309 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7310 1 : spdm_context->connection_info.capability.flags |=
7311 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
7312 1 : spdm_context->connection_info.capability.flags |=
7313 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
7314 1 : spdm_context->local_context.capability.flags |=
7315 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
7316 :
7317 1 : spdm_context->connection_info.capability.flags |=
7318 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7319 1 : spdm_context->local_context.capability.flags |=
7320 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7321 :
7322 1 : spdm_context->connection_info.capability.flags |=
7323 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
7324 1 : spdm_context->local_context.capability.flags |=
7325 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
7326 :
7327 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
7328 : m_libspdm_use_asym_algo, &data,
7329 : &data_size, &hash, &hash_size);
7330 1 : libspdm_reset_message_a(spdm_context);
7331 1 : spdm_context->connection_info.algorithm.base_hash_algo =
7332 : m_libspdm_use_hash_algo;
7333 1 : spdm_context->connection_info.algorithm.base_asym_algo =
7334 : m_libspdm_use_asym_algo;
7335 1 : spdm_context->connection_info.algorithm.dhe_named_group =
7336 : m_libspdm_use_dhe_algo;
7337 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
7338 : m_libspdm_use_aead_algo;
7339 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
7340 : m_libspdm_use_measurement_hash_algo;
7341 :
7342 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7343 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
7344 : data_size;
7345 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
7346 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
7347 : data, data_size);
7348 : #else
7349 1 : libspdm_hash_all(
7350 : spdm_context->connection_info.algorithm.base_hash_algo,
7351 : data, data_size,
7352 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
7353 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
7354 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
7355 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
7356 : spdm_context->connection_info.algorithm.base_hash_algo,
7357 : spdm_context->connection_info.algorithm.base_asym_algo,
7358 : data, data_size,
7359 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
7360 : #endif
7361 :
7362 1 : heartbeat_period = 0;
7363 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7364 1 : status = libspdm_send_receive_key_exchange(
7365 : spdm_context,
7366 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
7367 : &session_id, &heartbeat_period, &slot_id_param,
7368 : measurement_hash);
7369 : /* Clear Mut_auth flags */
7370 1 : spdm_context->connection_info.capability.flags &=
7371 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7372 1 : spdm_context->local_context.capability.flags &=
7373 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7374 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
7375 1 : assert_int_equal(session_id, 0xFFFFFFFF);
7376 1 : assert_int_equal(
7377 : libspdm_secured_message_get_session_state(
7378 : spdm_context->session_info[0].secured_message_context),
7379 : LIBSPDM_SESSION_STATE_HANDSHAKING);
7380 1 : assert_int_equal(
7381 : spdm_context->session_info[0].mut_auth_requested,
7382 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS);
7383 1 : free(data);
7384 1 : }
7385 :
7386 1 : static void libspdm_test_requester_key_exchange_case26(void **state)
7387 : {
7388 : libspdm_return_t status;
7389 : libspdm_test_context_t *spdm_test_context;
7390 : libspdm_context_t *spdm_context;
7391 : uint32_t session_id;
7392 : uint8_t heartbeat_period;
7393 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
7394 : uint8_t slot_id_param;
7395 : void *data;
7396 : size_t data_size;
7397 : void *hash;
7398 : size_t hash_size;
7399 :
7400 1 : spdm_test_context = *state;
7401 1 : spdm_context = spdm_test_context->spdm_context;
7402 :
7403 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
7404 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
7405 : }
7406 :
7407 1 : spdm_test_context->case_id = 0x1A;
7408 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
7409 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7410 1 : spdm_context->connection_info.connection_state =
7411 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7412 1 : spdm_context->connection_info.capability.flags |=
7413 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
7414 1 : spdm_context->connection_info.capability.flags |=
7415 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
7416 1 : spdm_context->local_context.capability.flags |=
7417 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
7418 :
7419 1 : spdm_context->connection_info.capability.flags |=
7420 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7421 1 : spdm_context->local_context.capability.flags |=
7422 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7423 :
7424 :
7425 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
7426 : m_libspdm_use_asym_algo, &data,
7427 : &data_size, &hash, &hash_size);
7428 1 : libspdm_reset_message_a(spdm_context);
7429 1 : spdm_context->connection_info.algorithm.base_hash_algo =
7430 : m_libspdm_use_hash_algo;
7431 1 : spdm_context->connection_info.algorithm.base_asym_algo =
7432 : m_libspdm_use_asym_algo;
7433 1 : spdm_context->connection_info.algorithm.dhe_named_group =
7434 : m_libspdm_use_dhe_algo;
7435 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
7436 : m_libspdm_use_aead_algo;
7437 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
7438 : m_libspdm_use_measurement_hash_algo;
7439 :
7440 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7441 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
7442 : data_size;
7443 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
7444 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
7445 : data, data_size);
7446 : #else
7447 1 : libspdm_hash_all(
7448 : spdm_context->connection_info.algorithm.base_hash_algo,
7449 : data, data_size,
7450 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
7451 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
7452 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
7453 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
7454 : spdm_context->connection_info.algorithm.base_hash_algo,
7455 : spdm_context->connection_info.algorithm.base_asym_algo,
7456 : data, data_size,
7457 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
7458 : #endif
7459 :
7460 1 : heartbeat_period = 0;
7461 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7462 1 : status = libspdm_send_receive_key_exchange(
7463 : spdm_context,
7464 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
7465 : &session_id, &heartbeat_period, &slot_id_param,
7466 : measurement_hash);
7467 : /* Clear Mut_auth flags */
7468 1 : spdm_context->connection_info.capability.flags &=
7469 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7470 1 : spdm_context->local_context.capability.flags &=
7471 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7472 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
7473 1 : free(data);
7474 1 : }
7475 :
7476 1 : static void libspdm_test_requester_key_exchange_case27(void **state)
7477 : {
7478 : libspdm_return_t status;
7479 : libspdm_test_context_t *spdm_test_context;
7480 : libspdm_context_t *spdm_context;
7481 : uint32_t session_id;
7482 : uint8_t heartbeat_period;
7483 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
7484 : uint8_t slot_id_param;
7485 : void *data;
7486 : size_t data_size;
7487 : void *hash;
7488 : size_t hash_size;
7489 :
7490 1 : spdm_test_context = *state;
7491 1 : spdm_context = spdm_test_context->spdm_context;
7492 :
7493 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
7494 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
7495 : }
7496 :
7497 1 : spdm_test_context->case_id = 0x1B;
7498 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
7499 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7500 1 : spdm_context->connection_info.connection_state =
7501 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7502 1 : spdm_context->connection_info.capability.flags |=
7503 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
7504 1 : spdm_context->connection_info.capability.flags |=
7505 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
7506 1 : spdm_context->local_context.capability.flags |=
7507 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
7508 :
7509 1 : spdm_context->connection_info.capability.flags |=
7510 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7511 1 : spdm_context->local_context.capability.flags |=
7512 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7513 :
7514 :
7515 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
7516 : m_libspdm_use_asym_algo, &data,
7517 : &data_size, &hash, &hash_size);
7518 1 : libspdm_reset_message_a(spdm_context);
7519 1 : spdm_context->connection_info.algorithm.base_hash_algo =
7520 : m_libspdm_use_hash_algo;
7521 1 : spdm_context->connection_info.algorithm.base_asym_algo =
7522 : m_libspdm_use_asym_algo;
7523 1 : spdm_context->connection_info.algorithm.dhe_named_group =
7524 : m_libspdm_use_dhe_algo;
7525 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
7526 : m_libspdm_use_aead_algo;
7527 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
7528 : m_libspdm_use_measurement_hash_algo;
7529 :
7530 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7531 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
7532 : data_size;
7533 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
7534 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
7535 : data, data_size);
7536 : #else
7537 1 : libspdm_hash_all(
7538 : spdm_context->connection_info.algorithm.base_hash_algo,
7539 : data, data_size,
7540 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
7541 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
7542 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
7543 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
7544 : spdm_context->connection_info.algorithm.base_hash_algo,
7545 : spdm_context->connection_info.algorithm.base_asym_algo,
7546 : data, data_size,
7547 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
7548 : #endif
7549 :
7550 1 : heartbeat_period = 0;
7551 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7552 1 : status = libspdm_send_receive_key_exchange(
7553 : spdm_context,
7554 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
7555 : &session_id, &heartbeat_period, &slot_id_param,
7556 : measurement_hash);
7557 : /*Clear Mut_auth flags*/
7558 1 : spdm_context->connection_info.capability.flags &=
7559 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7560 1 : spdm_context->local_context.capability.flags &=
7561 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7562 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
7563 1 : free(data);
7564 1 : }
7565 :
7566 1 : static void libspdm_test_requester_key_exchange_case28(void **state)
7567 : {
7568 : libspdm_return_t status;
7569 : libspdm_test_context_t *spdm_test_context;
7570 : libspdm_context_t *spdm_context;
7571 : uint32_t session_id;
7572 : uint8_t heartbeat_period;
7573 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
7574 : uint8_t slot_id_param;
7575 : void *data;
7576 : size_t data_size;
7577 : void *hash;
7578 : size_t hash_size;
7579 :
7580 1 : spdm_test_context = *state;
7581 1 : spdm_context = spdm_test_context->spdm_context;
7582 :
7583 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
7584 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
7585 : }
7586 :
7587 1 : spdm_test_context->case_id = 0x1C;
7588 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
7589 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7590 1 : spdm_context->connection_info.connection_state =
7591 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7592 1 : spdm_context->connection_info.capability.flags |=
7593 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
7594 1 : spdm_context->connection_info.capability.flags |=
7595 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
7596 1 : spdm_context->local_context.capability.flags |=
7597 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
7598 :
7599 1 : spdm_context->connection_info.capability.flags |=
7600 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7601 1 : spdm_context->local_context.capability.flags |=
7602 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7603 :
7604 :
7605 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
7606 : m_libspdm_use_asym_algo, &data,
7607 : &data_size, &hash, &hash_size);
7608 1 : libspdm_reset_message_a(spdm_context);
7609 1 : spdm_context->connection_info.algorithm.base_hash_algo =
7610 : m_libspdm_use_hash_algo;
7611 1 : spdm_context->connection_info.algorithm.base_asym_algo =
7612 : m_libspdm_use_asym_algo;
7613 1 : spdm_context->connection_info.algorithm.dhe_named_group =
7614 : m_libspdm_use_dhe_algo;
7615 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
7616 : m_libspdm_use_aead_algo;
7617 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
7618 : m_libspdm_use_measurement_hash_algo;
7619 :
7620 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7621 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
7622 : data_size;
7623 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
7624 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
7625 : data, data_size);
7626 : #else
7627 1 : libspdm_hash_all(
7628 : spdm_context->connection_info.algorithm.base_hash_algo,
7629 : data, data_size,
7630 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
7631 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
7632 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
7633 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
7634 : spdm_context->connection_info.algorithm.base_hash_algo,
7635 : spdm_context->connection_info.algorithm.base_asym_algo,
7636 : data, data_size,
7637 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
7638 : #endif
7639 :
7640 1 : heartbeat_period = 0;
7641 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7642 1 : status = libspdm_send_receive_key_exchange(
7643 : spdm_context,
7644 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
7645 : &session_id, &heartbeat_period, &slot_id_param,
7646 : measurement_hash);
7647 : /* Clear Mut_auth flags */
7648 1 : spdm_context->connection_info.capability.flags &=
7649 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
7650 1 : spdm_context->local_context.capability.flags &=
7651 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
7652 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
7653 1 : free(data);
7654 1 : }
7655 :
7656 1 : static void libspdm_test_requester_key_exchange_case29(void **state)
7657 : {
7658 : libspdm_return_t status;
7659 : libspdm_test_context_t *spdm_test_context;
7660 : libspdm_context_t *spdm_context;
7661 : uint32_t session_id;
7662 : uint8_t heartbeat_period;
7663 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
7664 : uint8_t slot_id_param;
7665 : void *data;
7666 : size_t data_size;
7667 : void *hash;
7668 : size_t hash_size;
7669 :
7670 1 : spdm_test_context = *state;
7671 1 : spdm_context = spdm_test_context->spdm_context;
7672 :
7673 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
7674 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
7675 : }
7676 :
7677 1 : spdm_test_context->case_id = 0x1D;
7678 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
7679 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7680 1 : spdm_context->connection_info.connection_state =
7681 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7682 1 : spdm_context->connection_info.capability.flags |=
7683 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
7684 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
7685 1 : spdm_context->local_context.capability.flags |=
7686 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
7687 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
7688 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
7689 : m_libspdm_use_asym_algo, &data,
7690 : &data_size, &hash, &hash_size);
7691 1 : libspdm_reset_message_a(spdm_context);
7692 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
7693 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
7694 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
7695 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
7696 :
7697 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7698 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
7699 : data_size;
7700 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
7701 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
7702 : data, data_size);
7703 : #else
7704 1 : libspdm_hash_all(
7705 : spdm_context->connection_info.algorithm.base_hash_algo,
7706 : data, data_size,
7707 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
7708 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
7709 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
7710 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
7711 : spdm_context->connection_info.algorithm.base_hash_algo,
7712 : spdm_context->connection_info.algorithm.base_asym_algo,
7713 : data, data_size,
7714 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
7715 : #endif
7716 :
7717 1 : heartbeat_period = 0;
7718 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7719 1 : status = libspdm_send_receive_key_exchange(
7720 : spdm_context,
7721 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
7722 : &session_id, &heartbeat_period, &slot_id_param,
7723 : measurement_hash);
7724 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
7725 1 : assert_int_equal(session_id, 0xFFFFFFFF);
7726 1 : assert_int_equal(
7727 : libspdm_secured_message_get_session_state(
7728 : spdm_context->session_info[0].secured_message_context),
7729 : LIBSPDM_SESSION_STATE_HANDSHAKING);
7730 :
7731 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7732 : assert_int_equal(spdm_context->session_info[0].session_transcript.message_k.buffer_size,
7733 : m_libspdm_local_buffer_size);
7734 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
7735 : m_libspdm_local_buffer_size));
7736 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
7737 : assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer,
7738 : m_libspdm_local_buffer, m_libspdm_local_buffer_size);
7739 : #endif
7740 :
7741 1 : free(data);
7742 1 : }
7743 :
7744 1 : static void libspdm_test_requester_key_exchange_case30(void **state)
7745 : {
7746 : libspdm_return_t status;
7747 : libspdm_test_context_t *spdm_test_context;
7748 : libspdm_context_t *spdm_context;
7749 : uint32_t session_id;
7750 : uint8_t heartbeat_period;
7751 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
7752 : uint8_t slot_id_param;
7753 : void *data;
7754 : size_t data_size;
7755 : void *hash;
7756 : size_t hash_size;
7757 :
7758 1 : spdm_test_context = *state;
7759 1 : spdm_context = spdm_test_context->spdm_context;
7760 1 : spdm_test_context->case_id = 0x1e;
7761 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
7762 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7763 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7764 1 : spdm_context->connection_info.capability.flags |=
7765 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
7766 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
7767 1 : spdm_context->local_context.capability.flags |=
7768 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
7769 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
7770 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
7771 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
7772 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
7773 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
7774 : m_libspdm_use_asym_algo, &data,
7775 : &data_size, &hash, &hash_size);
7776 1 : libspdm_reset_message_a(spdm_context);
7777 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
7778 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
7779 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
7780 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
7781 1 : spdm_context->connection_info.algorithm.other_params_support =
7782 : SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
7783 1 : libspdm_session_info_init(spdm_context,
7784 1 : spdm_context->session_info,
7785 : INVALID_SESSION_ID, false);
7786 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7787 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
7788 : data_size;
7789 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
7790 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
7791 : data, data_size);
7792 : #else
7793 1 : libspdm_hash_all(
7794 : spdm_context->connection_info.algorithm.base_hash_algo,
7795 : data, data_size,
7796 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
7797 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
7798 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
7799 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
7800 : spdm_context->connection_info.algorithm.base_hash_algo,
7801 : spdm_context->connection_info.algorithm.base_asym_algo,
7802 : data, data_size,
7803 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
7804 : #endif
7805 :
7806 1 : heartbeat_period = 0;
7807 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7808 1 : status = libspdm_send_receive_key_exchange(
7809 : spdm_context,
7810 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0,
7811 : SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE,
7812 : &session_id, &heartbeat_period, &slot_id_param,
7813 : measurement_hash);
7814 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
7815 1 : assert_int_equal(session_id, 0xFFFFFFFF);
7816 1 : assert_int_equal(
7817 : libspdm_secured_message_get_session_state(
7818 : spdm_context->session_info[0].secured_message_context),
7819 : LIBSPDM_SESSION_STATE_HANDSHAKING);
7820 1 : assert_int_equal(spdm_context->session_info[0].session_policy,
7821 : SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE);
7822 1 : free(data);
7823 1 : }
7824 :
7825 : /**
7826 : * Test 31: Exercise the libspdm_send_receive_key_exchange_ex path
7827 : * Expected Behavior: requester_random_in is sent to Responder and correct responder_random is
7828 : * returned to Requester.
7829 : **/
7830 1 : static void libspdm_test_requester_key_exchange_case31(void **state)
7831 : {
7832 : libspdm_return_t status;
7833 : libspdm_test_context_t *spdm_test_context;
7834 : libspdm_context_t *spdm_context;
7835 : uint32_t session_id;
7836 : uint8_t heartbeat_period;
7837 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
7838 : uint8_t slot_id_param;
7839 : void *data;
7840 : size_t data_size;
7841 : void *hash;
7842 : size_t hash_size;
7843 : uint8_t requester_random_in[SPDM_RANDOM_DATA_SIZE];
7844 : uint8_t requester_random[SPDM_RANDOM_DATA_SIZE];
7845 : uint8_t responder_random[SPDM_RANDOM_DATA_SIZE];
7846 : uint8_t responder_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
7847 : size_t responder_opaque_data_size;
7848 : uint8_t requester_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
7849 : size_t requester_opaque_data_size;
7850 :
7851 1 : spdm_test_context = *state;
7852 1 : spdm_context = spdm_test_context->spdm_context;
7853 1 : spdm_test_context->case_id = 0x1f;
7854 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
7855 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7856 1 : spdm_context->connection_info.connection_state =
7857 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7858 1 : spdm_context->connection_info.capability.flags |=
7859 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
7860 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
7861 1 : spdm_context->local_context.capability.flags |=
7862 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
7863 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
7864 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
7865 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
7866 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
7867 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
7868 : m_libspdm_use_asym_algo, &data,
7869 : &data_size, &hash, &hash_size);
7870 1 : libspdm_reset_message_a(spdm_context);
7871 1 : spdm_context->connection_info.algorithm.base_hash_algo =
7872 : m_libspdm_use_hash_algo;
7873 1 : spdm_context->connection_info.algorithm.base_asym_algo =
7874 : m_libspdm_use_asym_algo;
7875 1 : spdm_context->connection_info.algorithm.dhe_named_group =
7876 : m_libspdm_use_dhe_algo;
7877 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
7878 : m_libspdm_use_aead_algo;
7879 :
7880 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
7881 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
7882 : }
7883 :
7884 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
7885 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
7886 : data_size;
7887 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
7888 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
7889 : data, data_size);
7890 : #else
7891 1 : libspdm_hash_all(
7892 : spdm_context->connection_info.algorithm.base_hash_algo,
7893 : data, data_size,
7894 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
7895 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
7896 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
7897 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
7898 : spdm_context->connection_info.algorithm.base_hash_algo,
7899 : spdm_context->connection_info.algorithm.base_asym_algo,
7900 : data, data_size,
7901 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
7902 : #endif
7903 :
7904 33 : for (int index = 0; index < SPDM_RANDOM_DATA_SIZE; index++) {
7905 32 : requester_random_in[index] = 0x12;
7906 : }
7907 :
7908 1 : heartbeat_period = 0;
7909 1 : responder_opaque_data_size = sizeof(responder_opaque_data);
7910 1 : requester_opaque_data_size = sizeof(requester_opaque_data);
7911 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7912 1 : status = libspdm_send_receive_key_exchange_ex(
7913 : spdm_context,
7914 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
7915 : &session_id, &heartbeat_period, &slot_id_param,
7916 : measurement_hash, requester_random_in, requester_random, responder_random,
7917 : requester_opaque_data, requester_opaque_data_size,
7918 : responder_opaque_data, &responder_opaque_data_size);
7919 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
7920 1 : assert_int_equal(session_id, 0xFFFFFFFF);
7921 1 : assert_int_equal(
7922 : libspdm_secured_message_get_session_state(
7923 : spdm_context->session_info[0].secured_message_context),
7924 : LIBSPDM_SESSION_STATE_HANDSHAKING);
7925 :
7926 33 : for (int index = 0; index < SPDM_RANDOM_DATA_SIZE; index++) {
7927 32 : assert_int_equal(requester_random[index], requester_random_in[index]);
7928 32 : assert_int_equal(requester_random[index], 0x12);
7929 32 : assert_int_equal(responder_random[index], 0x5c);
7930 : }
7931 :
7932 1 : free(data);
7933 1 : }
7934 :
7935 1 : void libspdm_test_requester_key_exchange_case32(void **state)
7936 : {
7937 : libspdm_return_t status;
7938 : libspdm_test_context_t *spdm_test_context;
7939 : libspdm_context_t *spdm_context;
7940 : uint32_t session_id;
7941 : uint8_t heartbeat_period;
7942 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
7943 : uint8_t slot_id_param;
7944 : void *data;
7945 : size_t data_size;
7946 :
7947 1 : spdm_test_context = *state;
7948 1 : spdm_context = spdm_test_context->spdm_context;
7949 1 : spdm_test_context->case_id = 0x20;
7950 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
7951 : SPDM_VERSION_NUMBER_SHIFT_BIT;
7952 1 : spdm_context->connection_info.connection_state =
7953 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
7954 1 : spdm_context->connection_info.capability.flags |=
7955 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
7956 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
7957 1 : spdm_context->local_context.capability.flags |=
7958 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
7959 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
7960 1 : spdm_context->connection_info.capability.flags |=
7961 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
7962 1 : spdm_context->local_context.capability.flags |=
7963 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP;
7964 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
7965 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
7966 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
7967 1 : libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
7968 1 : spdm_context->local_context.peer_public_key_provision = data;
7969 1 : spdm_context->local_context.peer_public_key_provision_size = data_size;
7970 :
7971 1 : libspdm_reset_message_a(spdm_context);
7972 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
7973 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
7974 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
7975 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
7976 1 : spdm_context->connection_info.algorithm.other_params_support =
7977 : SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
7978 1 : libspdm_session_info_init(spdm_context,
7979 1 : spdm_context->session_info,
7980 : INVALID_SESSION_ID, false);
7981 :
7982 1 : heartbeat_period = 0;
7983 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
7984 1 : status = libspdm_send_receive_key_exchange(
7985 : spdm_context,
7986 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0xFF,
7987 : SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE,
7988 : &session_id, &heartbeat_period, &slot_id_param,
7989 : measurement_hash);
7990 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
7991 1 : assert_int_equal(session_id, 0xFFFFFFFF);
7992 1 : assert_int_equal(
7993 : libspdm_secured_message_get_session_state(
7994 : spdm_context->session_info[0].secured_message_context),
7995 : LIBSPDM_SESSION_STATE_HANDSHAKING);
7996 1 : assert_int_equal(spdm_context->session_info[0].session_policy,
7997 : SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE);
7998 1 : free(data);
7999 1 : }
8000 :
8001 1 : static void libspdm_test_requester_key_exchange_case33(void **state)
8002 : {
8003 : libspdm_return_t status;
8004 : libspdm_test_context_t *spdm_test_context;
8005 : libspdm_context_t *spdm_context;
8006 : uint32_t session_id;
8007 : uint8_t heartbeat_period;
8008 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
8009 : uint8_t slot_id_param;
8010 : void *data;
8011 : size_t data_size;
8012 : void *hash;
8013 : size_t hash_size;
8014 :
8015 1 : spdm_test_context = *state;
8016 1 : spdm_context = spdm_test_context->spdm_context;
8017 1 : spdm_test_context->case_id = 0x21;
8018 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
8019 : SPDM_VERSION_NUMBER_SHIFT_BIT;
8020 1 : spdm_context->connection_info.connection_state =
8021 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
8022 1 : spdm_context->connection_info.capability.flags |=
8023 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
8024 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
8025 1 : spdm_context->local_context.capability.flags |=
8026 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
8027 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
8028 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
8029 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
8030 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
8031 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
8032 : m_libspdm_use_asym_algo, &data,
8033 : &data_size, &hash, &hash_size);
8034 1 : libspdm_reset_message_a(spdm_context);
8035 1 : spdm_context->connection_info.algorithm.base_hash_algo =
8036 : m_libspdm_use_hash_algo;
8037 1 : spdm_context->connection_info.algorithm.base_asym_algo =
8038 : m_libspdm_use_asym_algo;
8039 1 : spdm_context->connection_info.algorithm.dhe_named_group =
8040 : m_libspdm_use_dhe_algo;
8041 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
8042 : m_libspdm_use_aead_algo;
8043 1 : spdm_context->connection_info.algorithm.other_params_support =
8044 : SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
8045 1 : libspdm_session_info_init(spdm_context,
8046 1 : spdm_context->session_info,
8047 : INVALID_SESSION_ID, false);
8048 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
8049 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
8050 : data_size;
8051 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
8052 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
8053 : data, data_size);
8054 : #else
8055 1 : libspdm_hash_all(
8056 : spdm_context->connection_info.algorithm.base_hash_algo,
8057 : data, data_size,
8058 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
8059 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
8060 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
8061 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
8062 : spdm_context->connection_info.algorithm.base_hash_algo,
8063 : spdm_context->connection_info.algorithm.base_asym_algo,
8064 : data, data_size,
8065 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
8066 : #endif
8067 :
8068 1 : heartbeat_period = 0;
8069 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
8070 1 : status = libspdm_send_receive_key_exchange(
8071 : spdm_context,
8072 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0,
8073 : SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE,
8074 : &session_id, &heartbeat_period, &slot_id_param,
8075 : measurement_hash);
8076 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
8077 1 : assert_int_equal(session_id, 0xFFFFFFFF);
8078 1 : assert_int_equal(
8079 : libspdm_secured_message_get_session_state(
8080 : spdm_context->session_info[0].secured_message_context),
8081 : LIBSPDM_SESSION_STATE_HANDSHAKING);
8082 1 : assert_int_equal(spdm_context->session_info[0].session_policy,
8083 : SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE);
8084 1 : free(data);
8085 1 : }
8086 :
8087 : /**
8088 : * Test 34: The secured message version is 1.2 and the Integrator has set the sequence number
8089 : * endianness to big-endian. After key exchange the session's endianness will be
8090 : * little-endian as 277 1.2 only supports little-endian.
8091 : * Expected Behavior: A successful key exchange with the session's endianness set to little-endian.
8092 : **/
8093 1 : static void libspdm_test_requester_key_exchange_case34(void **state)
8094 : {
8095 : libspdm_return_t status;
8096 : libspdm_test_context_t *spdm_test_context;
8097 : libspdm_context_t *spdm_context;
8098 : uint32_t session_id;
8099 : uint8_t heartbeat_period;
8100 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
8101 : uint8_t slot_id_param;
8102 : void *data;
8103 : size_t data_size;
8104 : void *hash;
8105 : size_t hash_size;
8106 :
8107 1 : spdm_test_context = *state;
8108 1 : spdm_context = spdm_test_context->spdm_context;
8109 :
8110 1 : if (spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
8111 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
8112 : }
8113 :
8114 1 : spdm_test_context->case_id = 0x22;
8115 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
8116 : SPDM_VERSION_NUMBER_SHIFT_BIT;
8117 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
8118 1 : spdm_context->connection_info.capability.flags |=
8119 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
8120 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
8121 1 : spdm_context->local_context.capability.flags |=
8122 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
8123 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
8124 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
8125 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
8126 : SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
8127 :
8128 : /* Set 277 sequence number endianness to big-endian. */
8129 1 : spdm_context->sequence_number_endian = LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BIG;
8130 :
8131 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
8132 : m_libspdm_use_asym_algo, &data,
8133 : &data_size, &hash, &hash_size);
8134 1 : libspdm_reset_message_a(spdm_context);
8135 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
8136 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
8137 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
8138 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
8139 :
8140 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
8141 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
8142 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
8143 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
8144 : data, data_size);
8145 : #else
8146 1 : libspdm_hash_all(
8147 : spdm_context->connection_info.algorithm.base_hash_algo,
8148 : data, data_size,
8149 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
8150 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
8151 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
8152 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
8153 : spdm_context->connection_info.algorithm.base_hash_algo,
8154 : spdm_context->connection_info.algorithm.base_asym_algo,
8155 : data, data_size,
8156 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
8157 : #endif
8158 :
8159 1 : heartbeat_period = 0;
8160 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
8161 1 : status = libspdm_send_receive_key_exchange(
8162 : spdm_context,
8163 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
8164 : &session_id, &heartbeat_period, &slot_id_param,
8165 : measurement_hash);
8166 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
8167 1 : assert_int_equal(session_id, 0xFFFFFFFF);
8168 1 : assert_int_equal(
8169 : libspdm_secured_message_get_session_state(
8170 : spdm_context->session_info[0].secured_message_context),
8171 : LIBSPDM_SESSION_STATE_HANDSHAKING);
8172 1 : assert_int_equal(((libspdm_secured_message_context_t *)spdm_context->session_info->
8173 : secured_message_context)->sequence_number_endian,
8174 : LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE);
8175 1 : free(data);
8176 1 : }
8177 :
8178 1 : int libspdm_requester_key_exchange_test_main(void)
8179 : {
8180 1 : const struct CMUnitTest spdm_requester_key_exchange_tests[] = {
8181 : /* SendRequest failed*/
8182 : cmocka_unit_test(libspdm_test_requester_key_exchange_case1),
8183 : /* Successful response*/
8184 : cmocka_unit_test(libspdm_test_requester_key_exchange_case2),
8185 : /* connection_state check failed*/
8186 : cmocka_unit_test(libspdm_test_requester_key_exchange_case3),
8187 : /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
8188 : cmocka_unit_test(libspdm_test_requester_key_exchange_case4),
8189 : /* Always SPDM_ERROR_CODE_BUSY*/
8190 : cmocka_unit_test(libspdm_test_requester_key_exchange_case5),
8191 : /* SPDM_ERROR_CODE_BUSY + Successful response*/
8192 : cmocka_unit_test(libspdm_test_requester_key_exchange_case6),
8193 : /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
8194 : cmocka_unit_test(libspdm_test_requester_key_exchange_case7),
8195 : /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
8196 : cmocka_unit_test(libspdm_test_requester_key_exchange_case8),
8197 : /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
8198 : cmocka_unit_test(libspdm_test_requester_key_exchange_case9),
8199 : /* Unexpected errors*/
8200 : cmocka_unit_test(libspdm_test_requester_key_exchange_case10),
8201 : /* Buffer reset*/
8202 : cmocka_unit_test(libspdm_test_requester_key_exchange_case11),
8203 : /* Measurement hash 1, returns a measurement hash*/
8204 : cmocka_unit_test(libspdm_test_requester_key_exchange_case12),
8205 : /* Measurement hash 1, returns a 0x00 array (no TCB components)*/
8206 : cmocka_unit_test(libspdm_test_requester_key_exchange_case13),
8207 : /* Measurement hash FF, returns a measurement_hash*/
8208 : cmocka_unit_test(libspdm_test_requester_key_exchange_case14),
8209 : /* Measurement hash 1, returns no measurement_hash*/
8210 : cmocka_unit_test(libspdm_test_requester_key_exchange_case15),
8211 : /* Measurement hash FF, returns no measurement_hash*/
8212 : cmocka_unit_test(libspdm_test_requester_key_exchange_case16),
8213 : /* Measurement hash not requested, returns a measurement_hash*/
8214 : cmocka_unit_test(libspdm_test_requester_key_exchange_case17),
8215 : /* Wrong signature*/
8216 : cmocka_unit_test(libspdm_test_requester_key_exchange_case18),
8217 : /* Requester and Responder Handshake in the clear set, no ResponderVerifyData*/
8218 : cmocka_unit_test(libspdm_test_requester_key_exchange_case19),
8219 : /* Heartbeat not supported, heartbeat period different from 0 sent*/
8220 : cmocka_unit_test(libspdm_test_requester_key_exchange_case20),
8221 : /* Heartbeat supported, heartbeat period different from 0 sent*/
8222 : cmocka_unit_test(libspdm_test_requester_key_exchange_case21),
8223 : /* Heartbeat supported, heartbeat period 0 sent NOTE: This should disable heartbeat*/
8224 : cmocka_unit_test(libspdm_test_requester_key_exchange_case22),
8225 : /* Muth Auth requested*/
8226 : cmocka_unit_test(libspdm_test_requester_key_exchange_case23),
8227 : /* Muth Auth requested with Encapsulated request*/
8228 : cmocka_unit_test(libspdm_test_requester_key_exchange_case24),
8229 : /* Muth Auth requested with implicit get digest*/
8230 : cmocka_unit_test(libspdm_test_requester_key_exchange_case25),
8231 : /* Muth Auth requested with Encapsulated request and bit 0 set*/
8232 : cmocka_unit_test(libspdm_test_requester_key_exchange_case26),
8233 : /* Muth Auth requested with implicit get digest and bit 0 set*/
8234 : cmocka_unit_test(libspdm_test_requester_key_exchange_case27),
8235 : /* Muth Auth requested with Encapsulated request and Muth Auth requested with implicit get digest simultaneously*/
8236 : cmocka_unit_test(libspdm_test_requester_key_exchange_case28),
8237 : /* Buffer verification*/
8238 : cmocka_unit_test(libspdm_test_requester_key_exchange_case29),
8239 : /* Successful response V1.2*/
8240 : cmocka_unit_test(libspdm_test_requester_key_exchange_case30),
8241 : cmocka_unit_test(libspdm_test_requester_key_exchange_case31),
8242 : /* Successful response using provisioned public key (slot_id 0xFF) */
8243 : cmocka_unit_test(libspdm_test_requester_key_exchange_case32),
8244 : /* OpaqueData only supports OpaqueDataFmt1, Success Case */
8245 : cmocka_unit_test(libspdm_test_requester_key_exchange_case33),
8246 : cmocka_unit_test(libspdm_test_requester_key_exchange_case34),
8247 : };
8248 :
8249 1 : libspdm_test_context_t test_context = {
8250 : LIBSPDM_TEST_CONTEXT_VERSION,
8251 : true,
8252 : libspdm_requester_key_exchange_test_send_message,
8253 : libspdm_requester_key_exchange_test_receive_message,
8254 : };
8255 :
8256 1 : libspdm_setup_test_context(&test_context);
8257 :
8258 1 : return cmocka_run_group_tests(spdm_requester_key_exchange_tests,
8259 : libspdm_unit_test_group_setup,
8260 : libspdm_unit_test_group_teardown);
8261 : }
8262 :
8263 : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
|