Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2026 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 40 : 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 40 : spdm_request = buffer;
29 40 : message_size = sizeof(spdm_message_header_t);
30 40 : if (buffer_size < message_size) {
31 0 : return buffer_size;
32 : }
33 :
34 40 : if (spdm_request->header.request_response_code != SPDM_KEY_EXCHANGE) {
35 1 : return buffer_size;
36 : }
37 :
38 39 : message_size = sizeof(spdm_key_exchange_request_t);
39 39 : if (buffer_size < message_size) {
40 0 : return buffer_size;
41 : }
42 :
43 39 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
44 39 : message_size += dhe_key_size + sizeof(uint16_t);
45 39 : if (buffer_size < message_size) {
46 0 : return buffer_size;
47 : }
48 :
49 39 : opaque_length =
50 39 : *(uint16_t *)((size_t)buffer +
51 39 : sizeof(spdm_key_exchange_request_t) + dhe_key_size);
52 39 : message_size += opaque_length;
53 39 : if (buffer_size < message_size) {
54 0 : return buffer_size;
55 : }
56 :
57 : /* Good message, return actual size*/
58 39 : return message_size;
59 : }
60 :
61 41 : static libspdm_return_t send_message(
62 : void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
63 : {
64 : libspdm_test_context_t *spdm_test_context;
65 : size_t header_size;
66 : size_t message_size;
67 :
68 41 : spdm_test_context = libspdm_get_test_context();
69 41 : header_size = sizeof(libspdm_test_message_header_t);
70 41 : switch (spdm_test_context->case_id) {
71 1 : case 0x1:
72 1 : return LIBSPDM_STATUS_SEND_FAIL;
73 1 : case 0x2:
74 1 : m_libspdm_local_buffer_size = 0;
75 1 : message_size = libspdm_test_get_key_exchange_request_size(
76 : spdm_context, (const uint8_t *)request + header_size,
77 : request_size - header_size);
78 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
79 : (const uint8_t *)request + header_size, message_size);
80 1 : m_libspdm_local_buffer_size += message_size;
81 1 : return LIBSPDM_STATUS_SUCCESS;
82 0 : case 0x3:
83 0 : m_libspdm_local_buffer_size = 0;
84 0 : message_size = libspdm_test_get_key_exchange_request_size(
85 : spdm_context, (const uint8_t *)request + header_size,
86 : request_size - header_size);
87 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
88 : (const uint8_t *)request + header_size, message_size);
89 0 : m_libspdm_local_buffer_size += message_size;
90 0 : return LIBSPDM_STATUS_SUCCESS;
91 1 : case 0x4:
92 1 : m_libspdm_local_buffer_size = 0;
93 1 : message_size = libspdm_test_get_key_exchange_request_size(
94 : spdm_context, (const uint8_t *)request + header_size,
95 : request_size - header_size);
96 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
97 : (const uint8_t *)request + header_size, message_size);
98 1 : m_libspdm_local_buffer_size += message_size;
99 1 : return LIBSPDM_STATUS_SUCCESS;
100 1 : case 0x5:
101 1 : m_libspdm_local_buffer_size = 0;
102 1 : message_size = libspdm_test_get_key_exchange_request_size(
103 : spdm_context, (const uint8_t *)request + header_size,
104 : request_size - header_size);
105 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
106 : (const uint8_t *)request + header_size, message_size);
107 1 : m_libspdm_local_buffer_size += message_size;
108 1 : return LIBSPDM_STATUS_SUCCESS;
109 0 : case 0x6:
110 0 : m_libspdm_local_buffer_size = 0;
111 0 : message_size = libspdm_test_get_key_exchange_request_size(
112 : spdm_context, (const uint8_t *)request + header_size,
113 : request_size - header_size);
114 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
115 : (const uint8_t *)request + header_size, message_size);
116 0 : m_libspdm_local_buffer_size += message_size;
117 0 : return LIBSPDM_STATUS_SUCCESS;
118 1 : case 0x7:
119 1 : m_libspdm_local_buffer_size = 0;
120 1 : message_size = libspdm_test_get_key_exchange_request_size(
121 : spdm_context, (const uint8_t *)request + header_size,
122 : request_size - header_size);
123 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
124 : (const uint8_t *)request + header_size, message_size);
125 1 : m_libspdm_local_buffer_size += message_size;
126 1 : return LIBSPDM_STATUS_SUCCESS;
127 2 : case 0x8:
128 2 : m_libspdm_local_buffer_size = 0;
129 2 : message_size = libspdm_test_get_key_exchange_request_size(
130 : spdm_context, (const uint8_t *)request + header_size,
131 : request_size - header_size);
132 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
133 : (const uint8_t *)request + header_size, message_size);
134 2 : m_libspdm_local_buffer_size += message_size;
135 2 : return LIBSPDM_STATUS_SUCCESS;
136 0 : case 0x9: {
137 : static size_t sub_index = 0;
138 0 : if (sub_index == 0) {
139 0 : m_libspdm_local_buffer_size = 0;
140 0 : message_size = libspdm_test_get_key_exchange_request_size(
141 : spdm_context, (const uint8_t *)request + header_size,
142 : request_size - header_size);
143 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
144 : (const uint8_t *)request + header_size, message_size);
145 0 : m_libspdm_local_buffer_size += message_size;
146 0 : sub_index++;
147 : }
148 : }
149 0 : return LIBSPDM_STATUS_SUCCESS;
150 18 : case 0xA:
151 18 : m_libspdm_local_buffer_size = 0;
152 18 : message_size = libspdm_test_get_key_exchange_request_size(
153 : spdm_context, (const uint8_t *)request + header_size,
154 : request_size - header_size);
155 18 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
156 : (const uint8_t *)request + header_size, message_size);
157 18 : m_libspdm_local_buffer_size += message_size;
158 18 : return LIBSPDM_STATUS_SUCCESS;
159 1 : case 0xB:
160 1 : m_libspdm_local_buffer_size = 0;
161 1 : message_size = libspdm_test_get_key_exchange_request_size(
162 : spdm_context, (const uint8_t *)request + header_size,
163 : request_size - header_size);
164 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
165 : (const uint8_t *)request + header_size, message_size);
166 1 : m_libspdm_local_buffer_size += message_size;
167 1 : return LIBSPDM_STATUS_SUCCESS;
168 1 : case 0xC:
169 1 : m_libspdm_local_buffer_size = 0;
170 1 : message_size = libspdm_test_get_key_exchange_request_size(
171 : spdm_context, (const uint8_t *)request + header_size,
172 : request_size - header_size);
173 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
174 : (const uint8_t *)request + header_size, message_size);
175 1 : m_libspdm_local_buffer_size += message_size;
176 1 : return LIBSPDM_STATUS_SUCCESS;
177 1 : case 0xD:
178 1 : m_libspdm_local_buffer_size = 0;
179 1 : message_size = libspdm_test_get_key_exchange_request_size(
180 : spdm_context, (const uint8_t *)request + header_size,
181 : request_size - header_size);
182 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
183 : (const uint8_t *)request + header_size, message_size);
184 1 : m_libspdm_local_buffer_size += message_size;
185 1 : return LIBSPDM_STATUS_SUCCESS;
186 1 : case 0xE:
187 1 : m_libspdm_local_buffer_size = 0;
188 1 : message_size = libspdm_test_get_key_exchange_request_size(
189 : spdm_context, (const uint8_t *)request + header_size,
190 : request_size - header_size);
191 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
192 : (const uint8_t *)request + header_size, message_size);
193 1 : m_libspdm_local_buffer_size += message_size;
194 1 : return LIBSPDM_STATUS_SUCCESS;
195 1 : case 0xF:
196 1 : m_libspdm_local_buffer_size = 0;
197 1 : message_size = libspdm_test_get_key_exchange_request_size(
198 : spdm_context, (const uint8_t *)request + header_size,
199 : request_size - header_size);
200 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
201 : (const uint8_t *)request + header_size, message_size);
202 1 : m_libspdm_local_buffer_size += message_size;
203 1 : return LIBSPDM_STATUS_SUCCESS;
204 1 : case 0x10:
205 1 : m_libspdm_local_buffer_size = 0;
206 1 : message_size = libspdm_test_get_key_exchange_request_size(
207 : spdm_context, (const uint8_t *)request + header_size,
208 : request_size - header_size);
209 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
210 : (const uint8_t *)request + header_size, message_size);
211 1 : m_libspdm_local_buffer_size += message_size;
212 1 : return LIBSPDM_STATUS_SUCCESS;
213 1 : case 0x11:
214 1 : m_libspdm_local_buffer_size = 0;
215 1 : message_size = libspdm_test_get_key_exchange_request_size(
216 : spdm_context, (const uint8_t *)request + header_size,
217 : request_size - header_size);
218 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
219 : (const uint8_t *)request + header_size, message_size);
220 1 : m_libspdm_local_buffer_size += message_size;
221 1 : return LIBSPDM_STATUS_SUCCESS;
222 1 : case 0x12:
223 1 : m_libspdm_local_buffer_size = 0;
224 1 : message_size = libspdm_test_get_key_exchange_request_size(
225 : spdm_context, (const uint8_t *)request + header_size,
226 : request_size - header_size);
227 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
228 : (const uint8_t *)request + header_size, message_size);
229 1 : m_libspdm_local_buffer_size += message_size;
230 1 : return LIBSPDM_STATUS_SUCCESS;
231 0 : case 0x13:
232 0 : m_libspdm_local_buffer_size = 0;
233 0 : message_size = libspdm_test_get_key_exchange_request_size(
234 : spdm_context, (const uint8_t *)request + header_size,
235 : request_size - header_size);
236 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
237 : (const uint8_t *)request + header_size, message_size);
238 0 : m_libspdm_local_buffer_size += message_size;
239 0 : return LIBSPDM_STATUS_SUCCESS;
240 1 : case 0x14:
241 1 : m_libspdm_local_buffer_size = 0;
242 1 : message_size = libspdm_test_get_key_exchange_request_size(
243 : spdm_context, (const uint8_t *)request + header_size,
244 : request_size - header_size);
245 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
246 : (const uint8_t *)request + header_size, message_size);
247 1 : m_libspdm_local_buffer_size += message_size;
248 1 : return LIBSPDM_STATUS_SUCCESS;
249 1 : case 0x15:
250 1 : m_libspdm_local_buffer_size = 0;
251 1 : message_size = libspdm_test_get_key_exchange_request_size(
252 : spdm_context, (const uint8_t *)request + header_size,
253 : request_size - header_size);
254 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
255 : (const uint8_t *)request + header_size, message_size);
256 1 : m_libspdm_local_buffer_size += message_size;
257 1 : return LIBSPDM_STATUS_SUCCESS;
258 1 : case 0x16:
259 1 : m_libspdm_local_buffer_size = 0;
260 1 : message_size = libspdm_test_get_key_exchange_request_size(
261 : spdm_context, (const uint8_t *)request + header_size,
262 : request_size - header_size);
263 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
264 : (const uint8_t *)request + header_size, message_size);
265 1 : m_libspdm_local_buffer_size += message_size;
266 1 : return LIBSPDM_STATUS_SUCCESS;
267 1 : case 0x17:
268 1 : m_libspdm_local_buffer_size = 0;
269 1 : message_size = libspdm_test_get_key_exchange_request_size(
270 : spdm_context, (const uint8_t *)request + header_size,
271 : request_size - header_size);
272 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
273 : (const uint8_t *)request + header_size, message_size);
274 1 : m_libspdm_local_buffer_size += message_size;
275 1 : return LIBSPDM_STATUS_SUCCESS;
276 0 : case 0x18:
277 0 : m_libspdm_local_buffer_size = 0;
278 0 : message_size = libspdm_test_get_key_exchange_request_size(
279 : spdm_context, (const uint8_t *)request + header_size,
280 : request_size - header_size);
281 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
282 : (const uint8_t *)request + header_size, message_size);
283 0 : m_libspdm_local_buffer_size += message_size;
284 0 : return LIBSPDM_STATUS_SUCCESS;
285 0 : case 0x19:
286 0 : m_libspdm_local_buffer_size = 0;
287 0 : message_size = libspdm_test_get_key_exchange_request_size(
288 : spdm_context, (const uint8_t *)request + header_size,
289 : request_size - header_size);
290 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
291 : (const uint8_t *)request + header_size, message_size);
292 0 : m_libspdm_local_buffer_size += message_size;
293 0 : return LIBSPDM_STATUS_SUCCESS;
294 1 : case 0x1A:
295 1 : m_libspdm_local_buffer_size = 0;
296 1 : message_size = libspdm_test_get_key_exchange_request_size(
297 : spdm_context, (const uint8_t *)request + header_size,
298 : request_size - header_size);
299 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
300 : (const uint8_t *)request + header_size, message_size);
301 1 : m_libspdm_local_buffer_size += message_size;
302 1 : return LIBSPDM_STATUS_SUCCESS;
303 1 : case 0x1B:
304 1 : m_libspdm_local_buffer_size = 0;
305 1 : message_size = libspdm_test_get_key_exchange_request_size(
306 : spdm_context, (const uint8_t *)request + header_size,
307 : request_size - header_size);
308 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
309 : (const uint8_t *)request + header_size, message_size);
310 1 : m_libspdm_local_buffer_size += message_size;
311 1 : return LIBSPDM_STATUS_SUCCESS;
312 1 : case 0x1C:
313 1 : m_libspdm_local_buffer_size = 0;
314 1 : message_size = libspdm_test_get_key_exchange_request_size(
315 : spdm_context, (const uint8_t *)request + header_size,
316 : request_size - header_size);
317 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
318 : (const uint8_t *)request + header_size, message_size);
319 1 : m_libspdm_local_buffer_size += message_size;
320 1 : return LIBSPDM_STATUS_SUCCESS;
321 0 : case 0x1D:
322 0 : m_libspdm_local_buffer_size = 0;
323 0 : message_size = libspdm_test_get_key_exchange_request_size(
324 : spdm_context, (const uint8_t *)request + header_size,
325 : request_size - header_size);
326 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
327 : (const uint8_t *)request + header_size, message_size);
328 0 : m_libspdm_local_buffer_size += message_size;
329 0 : return LIBSPDM_STATUS_SUCCESS;
330 0 : case 0x1E:
331 0 : m_libspdm_local_buffer_size = 0;
332 0 : message_size = libspdm_test_get_key_exchange_request_size(
333 : spdm_context, (const uint8_t *)request + header_size,
334 : request_size - header_size);
335 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
336 : (const uint8_t *)request + header_size, message_size);
337 0 : m_libspdm_local_buffer_size += message_size;
338 0 : return LIBSPDM_STATUS_SUCCESS;
339 1 : case 0x1F:
340 1 : m_libspdm_local_buffer_size = 0;
341 1 : message_size = libspdm_test_get_key_exchange_request_size(
342 : spdm_context, (const uint8_t *)request + header_size,
343 : request_size - header_size);
344 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
345 : (const uint8_t *)request + header_size, message_size);
346 1 : m_libspdm_local_buffer_size += message_size;
347 1 : return LIBSPDM_STATUS_SUCCESS;
348 0 : default:
349 0 : return LIBSPDM_STATUS_SEND_FAIL;
350 : }
351 : }
352 :
353 39 : static libspdm_return_t receive_message(
354 : void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
355 : {
356 : libspdm_test_context_t *spdm_test_context;
357 :
358 39 : spdm_test_context = libspdm_get_test_context();
359 39 : switch (spdm_test_context->case_id) {
360 0 : case 0x1:
361 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
362 :
363 1 : case 0x2: {
364 : spdm_key_exchange_response_t *spdm_response;
365 : size_t dhe_key_size;
366 : uint32_t hash_size;
367 : size_t signature_size;
368 : uint32_t hmac_size;
369 : uint8_t *ptr;
370 : void *dhe_context;
371 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
372 : size_t final_key_size;
373 : size_t opaque_key_exchange_rsp_size;
374 : void *data;
375 : size_t data_size;
376 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
377 : uint8_t *cert_buffer;
378 : size_t cert_buffer_size;
379 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
380 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
381 : uint8_t bin_str0[128];
382 : size_t bin_str0_size;
383 : uint8_t bin_str2[128];
384 : size_t bin_str2_size;
385 : uint8_t bin_str7[128];
386 : size_t bin_str7_size;
387 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
388 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
389 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
390 : size_t spdm_response_size;
391 : size_t transport_header_size;
392 :
393 :
394 : ((libspdm_context_t *)spdm_context)
395 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
396 : ((libspdm_context_t *)spdm_context)
397 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
398 : ((libspdm_context_t *)spdm_context)
399 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
400 : ((libspdm_context_t *)spdm_context)
401 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
402 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
403 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
404 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
405 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
406 1 : opaque_key_exchange_rsp_size =
407 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
408 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
409 1 : dhe_key_size + 0 + sizeof(uint16_t) +
410 1 : opaque_key_exchange_rsp_size + signature_size +
411 : hmac_size;
412 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
413 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
414 :
415 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
416 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
417 1 : spdm_response->header.param1 = 0;
418 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
419 1 : spdm_response->mut_auth_requested = 0;
420 1 : spdm_response->req_slot_id_param = 0;
421 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
422 1 : ptr = (void *)(spdm_response + 1);
423 1 : dhe_context = libspdm_dhe_new(
424 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
425 : m_libspdm_use_dhe_algo,
426 : true);
427 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
428 1 : final_key_size = sizeof(final_key);
429 1 : libspdm_dhe_compute_key(
430 : m_libspdm_use_dhe_algo, dhe_context,
431 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
432 : sizeof(spdm_key_exchange_request_t),
433 : dhe_key_size, final_key, &final_key_size);
434 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
435 1 : ptr += dhe_key_size;
436 : /* libspdm_zero_mem (ptr, hash_size);
437 : * ptr += hash_size;*/
438 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
439 1 : ptr += sizeof(uint16_t);
440 1 : libspdm_build_opaque_data_version_selection_data(
441 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
442 : &opaque_key_exchange_rsp_size, ptr);
443 1 : ptr += opaque_key_exchange_rsp_size;
444 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
445 : m_libspdm_use_asym_algo, &data,
446 : &data_size, NULL, NULL);
447 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
448 : sizeof(m_libspdm_local_buffer)
449 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
450 : m_libspdm_local_buffer),
451 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
452 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
453 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
454 : m_libspdm_local_buffer_size));
455 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
456 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
457 1 : cert_buffer = (uint8_t *)data;
458 1 : cert_buffer_size = data_size;
459 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
460 : /* transcript.message_a size is 0*/
461 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
462 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
463 : m_libspdm_local_buffer_size);
464 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
465 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
466 1 : free(data);
467 1 : libspdm_responder_data_sign(
468 : spdm_context,
469 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
470 : 0, SPDM_KEY_EXCHANGE_RSP,
471 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
472 1 : false, libspdm_get_managed_buffer(&th_curr),
473 : libspdm_get_managed_buffer_size(&th_curr), ptr,
474 : &signature_size);
475 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
476 : sizeof(m_libspdm_local_buffer)
477 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
478 : m_libspdm_local_buffer),
479 : ptr, signature_size);
480 1 : m_libspdm_local_buffer_size += signature_size;
481 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
482 1 : ptr += signature_size;
483 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
484 : libspdm_get_managed_buffer_size(&th_curr),
485 : th_curr_hash_data);
486 1 : bin_str0_size = sizeof(bin_str0);
487 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
488 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
489 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
490 : &bin_str0_size);
491 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
492 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
493 1 : bin_str2_size = sizeof(bin_str2);
494 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
495 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
496 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
497 : bin_str2, &bin_str2_size);
498 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
499 : bin_str2, bin_str2_size,
500 : response_handshake_secret, hash_size);
501 1 : bin_str7_size = sizeof(bin_str7);
502 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
503 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
504 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
505 : &bin_str7_size);
506 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
507 : hash_size, bin_str7, bin_str7_size,
508 : response_finished_key, hash_size);
509 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
510 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
511 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
512 : response_finished_key, hash_size, ptr);
513 1 : ptr += hmac_size;
514 :
515 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
516 : false, spdm_response_size,
517 : spdm_response, response_size,
518 : response);
519 : }
520 1 : return LIBSPDM_STATUS_SUCCESS;
521 :
522 0 : case 0x3: {
523 : spdm_key_exchange_response_t *spdm_response;
524 : size_t dhe_key_size;
525 : uint32_t hash_size;
526 : size_t signature_size;
527 : uint32_t hmac_size;
528 : uint8_t *ptr;
529 : void *dhe_context;
530 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
531 : size_t final_key_size;
532 : size_t opaque_key_exchange_rsp_size;
533 : void *data;
534 : size_t data_size;
535 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
536 : uint8_t *cert_buffer;
537 : size_t cert_buffer_size;
538 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
539 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
540 : uint8_t bin_str0[128];
541 : size_t bin_str0_size;
542 : uint8_t bin_str2[128];
543 : size_t bin_str2_size;
544 : uint8_t bin_str7[128];
545 : size_t bin_str7_size;
546 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
547 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
548 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
549 : size_t spdm_response_size;
550 : size_t transport_header_size;
551 :
552 : ((libspdm_context_t *)spdm_context)
553 0 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
554 : ((libspdm_context_t *)spdm_context)
555 0 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
556 : ((libspdm_context_t *)spdm_context)
557 0 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
558 : ((libspdm_context_t *)spdm_context)
559 0 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
560 0 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
561 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
562 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
563 0 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
564 0 : opaque_key_exchange_rsp_size =
565 0 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
566 0 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
567 0 : dhe_key_size + 0 + sizeof(uint16_t) +
568 0 : opaque_key_exchange_rsp_size + signature_size +
569 : hmac_size;
570 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
571 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
572 :
573 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
574 0 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
575 0 : spdm_response->header.param1 = 0;
576 0 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
577 0 : spdm_response->mut_auth_requested = 0;
578 0 : spdm_response->req_slot_id_param = 0;
579 0 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
580 0 : ptr = (void *)(spdm_response + 1);
581 0 : dhe_context = libspdm_dhe_new(
582 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
583 : m_libspdm_use_dhe_algo,
584 : true);
585 0 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
586 0 : final_key_size = sizeof(final_key);
587 0 : libspdm_dhe_compute_key(
588 : m_libspdm_use_dhe_algo, dhe_context,
589 0 : (uint8_t *)&m_libspdm_local_buffer[0] +
590 : sizeof(spdm_key_exchange_request_t),
591 : dhe_key_size, final_key, &final_key_size);
592 0 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
593 0 : ptr += dhe_key_size;
594 : /* libspdm_zero_mem (ptr, hash_size);
595 : * ptr += hash_size;*/
596 0 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
597 0 : ptr += sizeof(uint16_t);
598 0 : libspdm_build_opaque_data_version_selection_data(
599 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
600 : &opaque_key_exchange_rsp_size, ptr);
601 0 : ptr += opaque_key_exchange_rsp_size;
602 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
603 : m_libspdm_use_asym_algo, &data,
604 : &data_size, NULL, NULL);
605 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
606 : sizeof(m_libspdm_local_buffer)
607 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
608 : m_libspdm_local_buffer),
609 0 : spdm_response, (size_t)ptr - (size_t)spdm_response);
610 0 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
611 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
612 : m_libspdm_local_buffer_size));
613 0 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
614 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
615 0 : cert_buffer = (uint8_t *)data;
616 0 : cert_buffer_size = data_size;
617 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
618 : /* transcript.message_a size is 0*/
619 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
620 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
621 : m_libspdm_local_buffer_size);
622 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
623 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
624 0 : free(data);
625 0 : libspdm_responder_data_sign(
626 : spdm_context,
627 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
628 : 0, SPDM_KEY_EXCHANGE_RSP,
629 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
630 0 : false, libspdm_get_managed_buffer(&th_curr),
631 : libspdm_get_managed_buffer_size(&th_curr), ptr,
632 : &signature_size);
633 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
634 : sizeof(m_libspdm_local_buffer)
635 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
636 : m_libspdm_local_buffer),
637 : ptr, signature_size);
638 0 : m_libspdm_local_buffer_size += signature_size;
639 0 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
640 0 : ptr += signature_size;
641 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
642 : libspdm_get_managed_buffer_size(&th_curr),
643 : th_curr_hash_data);
644 0 : bin_str0_size = sizeof(bin_str0);
645 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
646 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
647 0 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
648 : &bin_str0_size);
649 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
650 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
651 0 : bin_str2_size = sizeof(bin_str2);
652 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
653 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
654 0 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
655 : bin_str2, &bin_str2_size);
656 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
657 : bin_str2, bin_str2_size,
658 : response_handshake_secret, hash_size);
659 0 : bin_str7_size = sizeof(bin_str7);
660 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
661 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
662 0 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
663 : &bin_str7_size);
664 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
665 : hash_size, bin_str7, bin_str7_size,
666 : response_finished_key, hash_size);
667 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
668 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
669 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
670 : response_finished_key, hash_size, ptr);
671 0 : ptr += hmac_size;
672 :
673 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
674 : false, spdm_response_size,
675 : spdm_response, response_size,
676 : response);
677 : }
678 0 : return LIBSPDM_STATUS_SUCCESS;
679 :
680 1 : case 0x4: {
681 : spdm_error_response_t *spdm_response;
682 : size_t spdm_response_size;
683 : size_t transport_header_size;
684 :
685 1 : spdm_response_size = sizeof(spdm_error_response_t);
686 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
687 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
688 :
689 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
690 1 : spdm_response->header.request_response_code = SPDM_ERROR;
691 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
692 1 : spdm_response->header.param2 = 0;
693 :
694 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
695 : false, spdm_response_size,
696 : spdm_response,
697 : response_size, response);
698 : }
699 1 : return LIBSPDM_STATUS_SUCCESS;
700 :
701 1 : case 0x5: {
702 : spdm_error_response_t *spdm_response;
703 : size_t spdm_response_size;
704 : size_t transport_header_size;
705 :
706 1 : spdm_response_size = sizeof(spdm_error_response_t);
707 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
708 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
709 :
710 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
711 1 : spdm_response->header.request_response_code = SPDM_ERROR;
712 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
713 1 : spdm_response->header.param2 = 0;
714 :
715 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
716 : false, spdm_response_size,
717 : spdm_response,
718 : response_size, response);
719 : }
720 1 : return LIBSPDM_STATUS_SUCCESS;
721 :
722 0 : case 0x6: {
723 : static size_t sub_index1 = 0;
724 0 : if (sub_index1 == 0) {
725 : spdm_error_response_t *spdm_response;
726 : size_t spdm_response_size;
727 : size_t transport_header_size;
728 :
729 0 : spdm_response_size = sizeof(spdm_error_response_t);
730 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
731 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
732 :
733 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
734 0 : spdm_response->header.request_response_code = SPDM_ERROR;
735 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
736 0 : spdm_response->header.param2 = 0;
737 :
738 0 : libspdm_transport_test_encode_message(
739 : spdm_context, NULL, false, false,
740 : spdm_response_size, spdm_response,
741 : response_size, response);
742 0 : sub_index1++;
743 0 : } else if (sub_index1 == 1) {
744 : spdm_key_exchange_response_t *spdm_response;
745 : size_t dhe_key_size;
746 : uint32_t hash_size;
747 : size_t signature_size;
748 : uint32_t hmac_size;
749 : uint8_t *ptr;
750 : void *dhe_context;
751 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
752 : size_t final_key_size;
753 : size_t opaque_key_exchange_rsp_size;
754 : void *data;
755 : size_t data_size;
756 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
757 : uint8_t *cert_buffer;
758 : size_t cert_buffer_size;
759 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
760 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
761 : uint8_t bin_str0[128];
762 : size_t bin_str0_size;
763 : uint8_t bin_str2[128];
764 : size_t bin_str2_size;
765 : uint8_t bin_str7[128];
766 : size_t bin_str7_size;
767 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
768 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
769 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
770 : size_t spdm_response_size;
771 : size_t transport_header_size;
772 :
773 : ((libspdm_context_t *)spdm_context)
774 0 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
775 : ((libspdm_context_t *)spdm_context)
776 0 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
777 : ((libspdm_context_t *)spdm_context)
778 0 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
779 : ((libspdm_context_t *)spdm_context)
780 : ->connection_info.algorithm
781 0 : .measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
782 0 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
783 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
784 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
785 0 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
786 0 : opaque_key_exchange_rsp_size =
787 0 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
788 0 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
789 0 : dhe_key_size + 0 + sizeof(uint16_t) +
790 0 : opaque_key_exchange_rsp_size +
791 0 : signature_size + hmac_size;
792 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
793 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
794 :
795 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
796 0 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
797 0 : spdm_response->header.param1 = 0;
798 0 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
799 0 : spdm_response->mut_auth_requested = 0;
800 0 : spdm_response->req_slot_id_param = 0;
801 0 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
802 0 : ptr = (void *)(spdm_response + 1);
803 0 : dhe_context = libspdm_dhe_new(
804 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
805 : m_libspdm_use_dhe_algo, true);
806 0 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
807 0 : final_key_size = sizeof(final_key);
808 0 : libspdm_dhe_compute_key(
809 : m_libspdm_use_dhe_algo, dhe_context,
810 0 : (uint8_t *)&m_libspdm_local_buffer[0] +
811 : sizeof(spdm_key_exchange_request_t),
812 : dhe_key_size, final_key, &final_key_size);
813 0 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
814 0 : ptr += dhe_key_size;
815 : /* libspdm_zero_mem (ptr, hash_size);
816 : * ptr += hash_size;*/
817 0 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
818 0 : ptr += sizeof(uint16_t);
819 0 : libspdm_build_opaque_data_version_selection_data(
820 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
821 : &opaque_key_exchange_rsp_size, ptr);
822 0 : ptr += opaque_key_exchange_rsp_size;
823 0 : libspdm_read_responder_public_certificate_chain(
824 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
825 : &data_size, NULL, NULL);
826 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
827 : sizeof(m_libspdm_local_buffer)
828 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
829 : m_libspdm_local_buffer),
830 0 : spdm_response, (size_t)ptr - (size_t)spdm_response);
831 0 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
832 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
833 : m_libspdm_local_buffer_size));
834 0 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
835 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
836 0 : cert_buffer = (uint8_t *)data;
837 0 : cert_buffer_size = data_size;
838 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
839 : cert_buffer_size, cert_buffer_hash);
840 : /* transcript.message_a size is 0*/
841 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
842 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
843 : m_libspdm_local_buffer_size);
844 0 : libspdm_hash_all(m_libspdm_use_hash_algo,
845 0 : libspdm_get_managed_buffer(&th_curr),
846 : libspdm_get_managed_buffer_size(&th_curr),
847 : hash_data);
848 0 : free(data);
849 0 : libspdm_responder_data_sign(
850 : spdm_context,
851 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
852 : 0, SPDM_KEY_EXCHANGE_RSP,
853 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
854 0 : false, libspdm_get_managed_buffer(&th_curr),
855 : libspdm_get_managed_buffer_size(&th_curr), ptr,
856 : &signature_size);
857 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
858 : sizeof(m_libspdm_local_buffer)
859 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
860 : m_libspdm_local_buffer),
861 : ptr, signature_size);
862 0 : m_libspdm_local_buffer_size += signature_size;
863 0 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
864 0 : ptr += signature_size;
865 0 : libspdm_hash_all(m_libspdm_use_hash_algo,
866 0 : libspdm_get_managed_buffer(&th_curr),
867 : libspdm_get_managed_buffer_size(&th_curr),
868 : th_curr_hash_data);
869 0 : bin_str0_size = sizeof(bin_str0);
870 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
871 : SPDM_BIN_STR_0_LABEL,
872 : sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
873 0 : (uint16_t)hash_size, hash_size, bin_str0,
874 : &bin_str0_size);
875 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
876 : m_libspdm_zero_filled_buffer, hash_size, handshake_secret);
877 0 : bin_str2_size = sizeof(bin_str2);
878 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
879 : SPDM_BIN_STR_2_LABEL,
880 : sizeof(SPDM_BIN_STR_2_LABEL) - 1,
881 0 : th_curr_hash_data, (uint16_t)hash_size,
882 : hash_size, bin_str2, &bin_str2_size);
883 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret,
884 : hash_size, bin_str2, bin_str2_size,
885 : response_handshake_secret, hash_size);
886 0 : bin_str7_size = sizeof(bin_str7);
887 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
888 : SPDM_BIN_STR_7_LABEL,
889 : sizeof(SPDM_BIN_STR_7_LABEL) - 1, NULL,
890 0 : (uint16_t)hash_size, hash_size, bin_str7,
891 : &bin_str7_size);
892 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo,
893 : response_handshake_secret, hash_size,
894 : bin_str7, bin_str7_size,
895 : response_finished_key, hash_size);
896 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
897 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
898 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
899 : response_finished_key, hash_size, ptr);
900 0 : ptr += hmac_size;
901 :
902 0 : libspdm_transport_test_encode_message(
903 : spdm_context, NULL, false, false, spdm_response_size,
904 : spdm_response, response_size, response);
905 : }
906 : }
907 0 : return LIBSPDM_STATUS_SUCCESS;
908 :
909 1 : case 0x7: {
910 : spdm_error_response_t *spdm_response;
911 : size_t spdm_response_size;
912 : size_t transport_header_size;
913 :
914 1 : spdm_response_size = sizeof(spdm_error_response_t);
915 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
916 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
917 :
918 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
919 1 : spdm_response->header.request_response_code = SPDM_ERROR;
920 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
921 1 : spdm_response->header.param2 = 0;
922 :
923 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
924 : false, spdm_response_size,
925 : spdm_response,
926 : response_size, response);
927 : }
928 1 : return LIBSPDM_STATUS_SUCCESS;
929 :
930 2 : case 0x8: {
931 : spdm_error_response_data_response_not_ready_t *spdm_response;
932 : size_t spdm_response_size;
933 : size_t transport_header_size;
934 :
935 2 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
936 2 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
937 2 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
938 :
939 2 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
940 2 : spdm_response->header.request_response_code = SPDM_ERROR;
941 2 : spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
942 2 : spdm_response->header.param2 = 0;
943 2 : spdm_response->extend_error_data.rd_exponent = 1;
944 2 : spdm_response->extend_error_data.rd_tm = 2;
945 2 : spdm_response->extend_error_data.request_code = SPDM_KEY_EXCHANGE;
946 2 : spdm_response->extend_error_data.token = 0;
947 :
948 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
949 : false, spdm_response_size,
950 : spdm_response,
951 : response_size, response);
952 : }
953 2 : return LIBSPDM_STATUS_SUCCESS;
954 :
955 0 : case 0x9: {
956 : static size_t sub_index2 = 0;
957 0 : if (sub_index2 == 0) {
958 : spdm_error_response_data_response_not_ready_t
959 : *spdm_response;
960 : size_t spdm_response_size;
961 : size_t transport_header_size;
962 :
963 0 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
964 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
965 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
966 :
967 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
968 0 : spdm_response->header.request_response_code = SPDM_ERROR;
969 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
970 0 : spdm_response->header.param2 = 0;
971 0 : spdm_response->extend_error_data.rd_exponent = 1;
972 0 : spdm_response->extend_error_data.rd_tm = 2;
973 0 : spdm_response->extend_error_data.request_code = SPDM_KEY_EXCHANGE;
974 0 : spdm_response->extend_error_data.token = 1;
975 :
976 0 : libspdm_transport_test_encode_message(
977 : spdm_context, NULL, false, false,
978 : spdm_response_size, spdm_response,
979 : response_size, response);
980 0 : sub_index2++;
981 0 : } else if (sub_index2 == 1) {
982 : spdm_key_exchange_response_t *spdm_response;
983 : size_t dhe_key_size;
984 : uint32_t hash_size;
985 : size_t signature_size;
986 : uint32_t hmac_size;
987 : uint8_t *ptr;
988 : void *dhe_context;
989 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
990 : size_t final_key_size;
991 : size_t opaque_key_exchange_rsp_size;
992 : void *data;
993 : size_t data_size;
994 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
995 : uint8_t *cert_buffer;
996 : size_t cert_buffer_size;
997 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
998 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
999 : uint8_t bin_str0[128];
1000 : size_t bin_str0_size;
1001 : uint8_t bin_str2[128];
1002 : size_t bin_str2_size;
1003 : uint8_t bin_str7[128];
1004 : size_t bin_str7_size;
1005 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1006 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1007 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1008 : size_t spdm_response_size;
1009 : size_t transport_header_size;
1010 :
1011 : ((libspdm_context_t *)spdm_context)
1012 0 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1013 : ((libspdm_context_t *)spdm_context)
1014 0 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1015 : ((libspdm_context_t *)spdm_context)
1016 0 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
1017 : ((libspdm_context_t *)spdm_context)
1018 : ->connection_info.algorithm
1019 0 : .measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1020 0 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1021 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1022 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1023 0 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1024 0 : opaque_key_exchange_rsp_size =
1025 0 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
1026 0 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1027 0 : dhe_key_size + 0 + sizeof(uint16_t) +
1028 0 : opaque_key_exchange_rsp_size +
1029 0 : signature_size + hmac_size;
1030 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1031 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1032 :
1033 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1034 0 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
1035 0 : spdm_response->header.param1 = 0;
1036 0 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
1037 0 : spdm_response->mut_auth_requested = 0;
1038 0 : spdm_response->req_slot_id_param = 0;
1039 0 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
1040 0 : ptr = (void *)(spdm_response + 1);
1041 0 : dhe_context = libspdm_dhe_new(
1042 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1043 : m_libspdm_use_dhe_algo, true);
1044 0 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
1045 0 : final_key_size = sizeof(final_key);
1046 0 : libspdm_dhe_compute_key(
1047 : m_libspdm_use_dhe_algo, dhe_context,
1048 0 : (uint8_t *)&m_libspdm_local_buffer[0] +
1049 : sizeof(spdm_key_exchange_request_t),
1050 : dhe_key_size, final_key, &final_key_size);
1051 0 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1052 0 : ptr += dhe_key_size;
1053 : /* libspdm_zero_mem (ptr, hash_size);
1054 : * ptr += hash_size;*/
1055 0 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1056 0 : ptr += sizeof(uint16_t);
1057 0 : libspdm_build_opaque_data_version_selection_data(
1058 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1059 : &opaque_key_exchange_rsp_size, ptr);
1060 0 : ptr += opaque_key_exchange_rsp_size;
1061 0 : libspdm_read_responder_public_certificate_chain(
1062 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
1063 : &data_size, NULL, NULL);
1064 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1065 : sizeof(m_libspdm_local_buffer)
1066 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1067 : m_libspdm_local_buffer),
1068 0 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1069 0 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1070 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1071 : m_libspdm_local_buffer_size));
1072 0 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1073 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1074 0 : cert_buffer = (uint8_t *)data;
1075 0 : cert_buffer_size = data_size;
1076 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
1077 : cert_buffer_size, cert_buffer_hash);
1078 : /* transcript.message_a size is 0*/
1079 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1080 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1081 : m_libspdm_local_buffer_size);
1082 0 : libspdm_hash_all(m_libspdm_use_hash_algo,
1083 0 : libspdm_get_managed_buffer(&th_curr),
1084 : libspdm_get_managed_buffer_size(&th_curr),
1085 : hash_data);
1086 0 : free(data);
1087 0 : libspdm_responder_data_sign(
1088 : spdm_context,
1089 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1090 : 0, SPDM_KEY_EXCHANGE_RSP,
1091 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
1092 0 : false, libspdm_get_managed_buffer(&th_curr),
1093 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1094 : &signature_size);
1095 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1096 : sizeof(m_libspdm_local_buffer)
1097 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1098 : m_libspdm_local_buffer),
1099 : ptr, signature_size);
1100 0 : m_libspdm_local_buffer_size += signature_size;
1101 0 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1102 0 : ptr += signature_size;
1103 0 : libspdm_hash_all(m_libspdm_use_hash_algo,
1104 0 : libspdm_get_managed_buffer(&th_curr),
1105 : libspdm_get_managed_buffer_size(&th_curr),
1106 : th_curr_hash_data);
1107 0 : bin_str0_size = sizeof(bin_str0);
1108 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1109 : SPDM_BIN_STR_0_LABEL,
1110 : sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
1111 0 : (uint16_t)hash_size, hash_size, bin_str0,
1112 : &bin_str0_size);
1113 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1114 : m_libspdm_zero_filled_buffer, hash_size, handshake_secret);
1115 0 : bin_str2_size = sizeof(bin_str2);
1116 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1117 : SPDM_BIN_STR_2_LABEL,
1118 : sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1119 0 : th_curr_hash_data, (uint16_t)hash_size,
1120 : hash_size, bin_str2, &bin_str2_size);
1121 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret,
1122 : hash_size, bin_str2, bin_str2_size,
1123 : response_handshake_secret, hash_size);
1124 0 : bin_str7_size = sizeof(bin_str7);
1125 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1126 : SPDM_BIN_STR_7_LABEL,
1127 : sizeof(SPDM_BIN_STR_7_LABEL) - 1, NULL,
1128 0 : (uint16_t)hash_size, hash_size, bin_str7,
1129 : &bin_str7_size);
1130 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo,
1131 : response_handshake_secret, hash_size,
1132 : bin_str7, bin_str7_size,
1133 : response_finished_key, hash_size);
1134 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1135 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1136 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1137 : response_finished_key, hash_size, ptr);
1138 0 : ptr += hmac_size;
1139 :
1140 0 : libspdm_transport_test_encode_message(
1141 : spdm_context, NULL, false, false, spdm_response_size,
1142 : spdm_response, response_size, response);
1143 : }
1144 : }
1145 0 : return LIBSPDM_STATUS_SUCCESS;
1146 :
1147 18 : case 0xA:
1148 : {
1149 : static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
1150 :
1151 : spdm_error_response_t *spdm_response;
1152 : size_t spdm_response_size;
1153 : size_t transport_header_size;
1154 :
1155 18 : spdm_response_size = sizeof(spdm_error_response_t);
1156 18 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1157 18 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1158 :
1159 18 : if(error_code <= 0xff) {
1160 18 : libspdm_zero_mem (spdm_response, spdm_response_size);
1161 18 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1162 18 : spdm_response->header.request_response_code = SPDM_ERROR;
1163 18 : spdm_response->header.param1 = (uint8_t) error_code;
1164 18 : spdm_response->header.param2 = 0;
1165 :
1166 18 : libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
1167 : spdm_response_size, spdm_response,
1168 : response_size, response);
1169 : }
1170 :
1171 18 : error_code++;
1172 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
1173 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
1174 : }
1175 : /* skip some reserved error codes (0d to 3e) */
1176 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
1177 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
1178 : }
1179 : /* skip response not ready, request resync, and some reserved codes (44 to fc) */
1180 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
1181 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
1182 : }
1183 : }
1184 18 : return LIBSPDM_STATUS_SUCCESS;
1185 0 : case 0xB: {
1186 : spdm_key_exchange_response_t *spdm_response;
1187 : size_t dhe_key_size;
1188 : uint32_t hash_size;
1189 : size_t signature_size;
1190 : uint32_t hmac_size;
1191 : uint8_t *ptr;
1192 : void *dhe_context;
1193 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
1194 : size_t final_key_size;
1195 : size_t opaque_key_exchange_rsp_size;
1196 : void *data;
1197 : size_t data_size;
1198 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1199 : uint8_t *cert_buffer;
1200 : size_t cert_buffer_size;
1201 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1202 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1203 : uint8_t bin_str0[128];
1204 : size_t bin_str0_size;
1205 : uint8_t bin_str2[128];
1206 : size_t bin_str2_size;
1207 : uint8_t bin_str7[128];
1208 : size_t bin_str7_size;
1209 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1210 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1211 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1212 : size_t spdm_response_size;
1213 : size_t transport_header_size;
1214 :
1215 : ((libspdm_context_t *)spdm_context)
1216 0 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1217 : ((libspdm_context_t *)spdm_context)
1218 0 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1219 : ((libspdm_context_t *)spdm_context)
1220 0 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
1221 : ((libspdm_context_t *)spdm_context)
1222 0 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1223 0 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1224 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1225 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1226 0 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1227 0 : opaque_key_exchange_rsp_size =
1228 0 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
1229 0 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1230 0 : dhe_key_size + 0 + sizeof(uint16_t) +
1231 0 : opaque_key_exchange_rsp_size + signature_size +
1232 : hmac_size;
1233 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1234 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1235 :
1236 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1237 0 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
1238 0 : spdm_response->header.param1 = 0;
1239 0 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
1240 0 : spdm_response->mut_auth_requested = 0;
1241 0 : spdm_response->req_slot_id_param = 0;
1242 0 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
1243 0 : ptr = (void *)(spdm_response + 1);
1244 0 : dhe_context = libspdm_dhe_new(
1245 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1246 : m_libspdm_use_dhe_algo,
1247 : true);
1248 0 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
1249 0 : final_key_size = sizeof(final_key);
1250 0 : libspdm_dhe_compute_key(
1251 : m_libspdm_use_dhe_algo, dhe_context,
1252 0 : (uint8_t *)&m_libspdm_local_buffer[0] +
1253 : sizeof(spdm_key_exchange_request_t),
1254 : dhe_key_size, final_key, &final_key_size);
1255 0 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1256 0 : ptr += dhe_key_size;
1257 : /* libspdm_zero_mem (ptr, hash_size);
1258 : * ptr += hash_size;*/
1259 0 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1260 0 : ptr += sizeof(uint16_t);
1261 0 : libspdm_build_opaque_data_version_selection_data(
1262 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1263 : &opaque_key_exchange_rsp_size, ptr);
1264 0 : ptr += opaque_key_exchange_rsp_size;
1265 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1266 : m_libspdm_use_asym_algo, &data,
1267 : &data_size, NULL, NULL);
1268 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1269 : sizeof(m_libspdm_local_buffer)
1270 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1271 : m_libspdm_local_buffer),
1272 0 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1273 0 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1274 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1275 : m_libspdm_local_buffer_size));
1276 0 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1277 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1278 0 : cert_buffer = (uint8_t *)data;
1279 0 : cert_buffer_size = data_size;
1280 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
1281 : /* transcript.message_a size is 0*/
1282 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1283 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1284 : m_libspdm_local_buffer_size);
1285 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1286 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1287 0 : free(data);
1288 0 : libspdm_responder_data_sign(
1289 : spdm_context,
1290 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1291 : 0, SPDM_KEY_EXCHANGE_RSP,
1292 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
1293 0 : false, libspdm_get_managed_buffer(&th_curr),
1294 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1295 : &signature_size);
1296 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1297 : sizeof(m_libspdm_local_buffer)
1298 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1299 : m_libspdm_local_buffer),
1300 : ptr, signature_size);
1301 0 : m_libspdm_local_buffer_size += signature_size;
1302 0 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1303 0 : ptr += signature_size;
1304 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1305 : libspdm_get_managed_buffer_size(&th_curr),
1306 : th_curr_hash_data);
1307 0 : bin_str0_size = sizeof(bin_str0);
1308 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1309 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
1310 0 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
1311 : &bin_str0_size);
1312 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1313 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
1314 0 : bin_str2_size = sizeof(bin_str2);
1315 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1316 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1317 0 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
1318 : bin_str2, &bin_str2_size);
1319 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
1320 : bin_str2, bin_str2_size,
1321 : response_handshake_secret, hash_size);
1322 0 : bin_str7_size = sizeof(bin_str7);
1323 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1324 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1325 0 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1326 : &bin_str7_size);
1327 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1328 : hash_size, bin_str7, bin_str7_size,
1329 : response_finished_key, hash_size);
1330 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1331 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1332 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1333 : response_finished_key, hash_size, ptr);
1334 0 : ptr += hmac_size;
1335 :
1336 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1337 : false, spdm_response_size,
1338 : spdm_response, response_size,
1339 : response);
1340 : }
1341 0 : return LIBSPDM_STATUS_SUCCESS;
1342 1 : case 0xC: {
1343 : spdm_key_exchange_response_t *spdm_response;
1344 : size_t dhe_key_size;
1345 : uint32_t hash_size;
1346 : uint32_t measurement_hash_size;
1347 : size_t signature_size;
1348 : uint32_t hmac_size;
1349 : uint8_t *ptr;
1350 : void *dhe_context;
1351 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
1352 : size_t final_key_size;
1353 : size_t opaque_key_exchange_rsp_size;
1354 : void *data;
1355 : size_t data_size;
1356 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
1357 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1358 : uint8_t *cert_buffer;
1359 : size_t cert_buffer_size;
1360 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1361 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1362 : uint8_t bin_str0[128];
1363 : size_t bin_str0_size;
1364 : uint8_t bin_str2[128];
1365 : size_t bin_str2_size;
1366 : uint8_t bin_str7[128];
1367 : size_t bin_str7_size;
1368 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1369 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1370 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1371 : size_t spdm_response_size;
1372 : size_t transport_header_size;
1373 :
1374 : ((libspdm_context_t *)spdm_context)
1375 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1376 : ((libspdm_context_t *)spdm_context)
1377 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1378 : ((libspdm_context_t *)spdm_context)
1379 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
1380 : ((libspdm_context_t *)spdm_context)
1381 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1382 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1383 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1384 1 : measurement_hash_size = libspdm_get_hash_size( m_libspdm_use_hash_algo);
1385 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1386 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1387 1 : opaque_key_exchange_rsp_size =
1388 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
1389 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1390 1 : dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
1391 1 : opaque_key_exchange_rsp_size + signature_size +
1392 : hmac_size;
1393 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1394 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1395 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1396 :
1397 : /* Incorrect version. Should be 1.1. */
1398 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
1399 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
1400 1 : spdm_response->header.param1 = 0;
1401 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
1402 1 : spdm_response->mut_auth_requested = 0;
1403 1 : spdm_response->req_slot_id_param = 0;
1404 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
1405 1 : ptr = (void *)(spdm_response + 1);
1406 1 : dhe_context = libspdm_dhe_new(
1407 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1408 : m_libspdm_use_dhe_algo,
1409 : true);
1410 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
1411 1 : final_key_size = sizeof(final_key);
1412 1 : libspdm_dhe_compute_key(
1413 : m_libspdm_use_dhe_algo, dhe_context,
1414 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
1415 : sizeof(spdm_key_exchange_request_t),
1416 : dhe_key_size, final_key, &final_key_size);
1417 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1418 1 : ptr += dhe_key_size;
1419 : /*Mock measurement hash as TCB*/
1420 1 : libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
1421 : m_libspdm_use_tcb_hash_value, measurement_hash_size);
1422 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
1423 : measurement_hash_data, measurement_hash_size);
1424 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
1425 1 : ptr += measurement_hash_size;
1426 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1427 1 : ptr += sizeof(uint16_t);
1428 1 : libspdm_build_opaque_data_version_selection_data(
1429 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1430 : &opaque_key_exchange_rsp_size, ptr);
1431 1 : ptr += opaque_key_exchange_rsp_size;
1432 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1433 : m_libspdm_use_asym_algo, &data,
1434 : &data_size, NULL, NULL);
1435 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1436 : sizeof(m_libspdm_local_buffer)
1437 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1438 : m_libspdm_local_buffer),
1439 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1440 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1441 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1442 : m_libspdm_local_buffer_size));
1443 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1444 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1445 1 : cert_buffer = (uint8_t *)data;
1446 1 : cert_buffer_size = data_size;
1447 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
1448 : /* transcript.message_a size is 0*/
1449 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1450 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1451 : m_libspdm_local_buffer_size);
1452 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1453 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1454 1 : free(data);
1455 1 : libspdm_responder_data_sign(
1456 : spdm_context,
1457 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1458 : 0, SPDM_KEY_EXCHANGE_RSP,
1459 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
1460 1 : false, libspdm_get_managed_buffer(&th_curr),
1461 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1462 : &signature_size);
1463 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1464 : sizeof(m_libspdm_local_buffer)
1465 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1466 : m_libspdm_local_buffer),
1467 : ptr, signature_size);
1468 1 : m_libspdm_local_buffer_size += signature_size;
1469 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1470 1 : ptr += signature_size;
1471 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1472 : libspdm_get_managed_buffer_size(&th_curr),
1473 : th_curr_hash_data);
1474 1 : bin_str0_size = sizeof(bin_str0);
1475 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1476 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
1477 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
1478 : &bin_str0_size);
1479 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1480 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
1481 1 : bin_str2_size = sizeof(bin_str2);
1482 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1483 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1484 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
1485 : bin_str2, &bin_str2_size);
1486 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
1487 : bin_str2, bin_str2_size,
1488 : response_handshake_secret, hash_size);
1489 1 : bin_str7_size = sizeof(bin_str7);
1490 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1491 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1492 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1493 : &bin_str7_size);
1494 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1495 : hash_size, bin_str7, bin_str7_size,
1496 : response_finished_key, hash_size);
1497 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1498 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1499 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1500 : response_finished_key, hash_size, ptr);
1501 1 : ptr += hmac_size;
1502 :
1503 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1504 : false, spdm_response_size,
1505 : spdm_response, response_size,
1506 : response);
1507 : }
1508 1 : return LIBSPDM_STATUS_SUCCESS;
1509 :
1510 1 : case 0xD: {
1511 : spdm_key_exchange_response_t *spdm_response;
1512 : size_t dhe_key_size;
1513 : uint32_t hash_size;
1514 : uint32_t measurement_hash_size;
1515 : size_t signature_size;
1516 : uint32_t hmac_size;
1517 : uint8_t *ptr;
1518 : void *dhe_context;
1519 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
1520 : size_t final_key_size;
1521 : size_t opaque_key_exchange_rsp_size;
1522 : void *data;
1523 : size_t data_size;
1524 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
1525 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1526 : uint8_t *cert_buffer;
1527 : size_t cert_buffer_size;
1528 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1529 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1530 : uint8_t bin_str0[128];
1531 : size_t bin_str0_size;
1532 : uint8_t bin_str2[128];
1533 : size_t bin_str2_size;
1534 : uint8_t bin_str7[128];
1535 : size_t bin_str7_size;
1536 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1537 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1538 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1539 : size_t spdm_response_size;
1540 : size_t transport_header_size;
1541 :
1542 : ((libspdm_context_t *)spdm_context)
1543 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1544 : ((libspdm_context_t *)spdm_context)
1545 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1546 : ((libspdm_context_t *)spdm_context)
1547 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
1548 : ((libspdm_context_t *)spdm_context)
1549 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1550 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1551 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1552 1 : measurement_hash_size = libspdm_get_hash_size( m_libspdm_use_hash_algo);
1553 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1554 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1555 1 : opaque_key_exchange_rsp_size =
1556 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
1557 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1558 1 : dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
1559 1 : opaque_key_exchange_rsp_size + signature_size +
1560 : hmac_size;
1561 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1562 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1563 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1564 :
1565 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1566 : /* Incorrect response code. */
1567 1 : spdm_response->header.request_response_code = SPDM_DIGESTS;
1568 1 : spdm_response->header.param1 = 0;
1569 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
1570 1 : spdm_response->mut_auth_requested = 0;
1571 1 : spdm_response->req_slot_id_param = 0;
1572 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
1573 1 : ptr = (void *)(spdm_response + 1);
1574 1 : dhe_context = libspdm_dhe_new(
1575 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1576 : m_libspdm_use_dhe_algo, true);
1577 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
1578 1 : final_key_size = sizeof(final_key);
1579 1 : libspdm_dhe_compute_key(
1580 : m_libspdm_use_dhe_algo, dhe_context,
1581 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
1582 : sizeof(spdm_key_exchange_request_t),
1583 : dhe_key_size, final_key, &final_key_size);
1584 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1585 1 : ptr += dhe_key_size;
1586 : /*Mock measurement hash as 0x00 array*/
1587 1 : libspdm_zero_mem(measurement_hash_data, measurement_hash_size);
1588 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
1589 : measurement_hash_data, measurement_hash_size);
1590 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
1591 1 : ptr += measurement_hash_size;
1592 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1593 1 : ptr += sizeof(uint16_t);
1594 1 : libspdm_build_opaque_data_version_selection_data(
1595 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1596 : &opaque_key_exchange_rsp_size, ptr);
1597 1 : ptr += opaque_key_exchange_rsp_size;
1598 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1599 : m_libspdm_use_asym_algo, &data,
1600 : &data_size, NULL, NULL);
1601 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1602 : sizeof(m_libspdm_local_buffer)
1603 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1604 : m_libspdm_local_buffer),
1605 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1606 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1607 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1608 : m_libspdm_local_buffer_size));
1609 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1610 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1611 1 : cert_buffer = (uint8_t *)data;
1612 1 : cert_buffer_size = data_size;
1613 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
1614 : /* transcript.message_a size is 0*/
1615 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1616 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1617 : m_libspdm_local_buffer_size);
1618 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1619 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1620 1 : free(data);
1621 1 : libspdm_responder_data_sign(
1622 : spdm_context,
1623 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1624 : 0, SPDM_KEY_EXCHANGE_RSP,
1625 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
1626 1 : false, libspdm_get_managed_buffer(&th_curr),
1627 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1628 : &signature_size);
1629 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1630 : sizeof(m_libspdm_local_buffer)
1631 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1632 : m_libspdm_local_buffer),
1633 : ptr, signature_size);
1634 1 : m_libspdm_local_buffer_size += signature_size;
1635 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1636 1 : ptr += signature_size;
1637 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1638 : libspdm_get_managed_buffer_size(&th_curr),
1639 : th_curr_hash_data);
1640 1 : bin_str0_size = sizeof(bin_str0);
1641 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1642 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
1643 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
1644 : &bin_str0_size);
1645 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1646 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
1647 1 : bin_str2_size = sizeof(bin_str2);
1648 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1649 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1650 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
1651 : bin_str2, &bin_str2_size);
1652 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
1653 : bin_str2, bin_str2_size,
1654 : response_handshake_secret, hash_size);
1655 1 : bin_str7_size = sizeof(bin_str7);
1656 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1657 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1658 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1659 : &bin_str7_size);
1660 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1661 : hash_size, bin_str7, bin_str7_size,
1662 : response_finished_key, hash_size);
1663 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1664 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1665 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1666 : response_finished_key, hash_size, ptr);
1667 1 : ptr += hmac_size;
1668 :
1669 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1670 : false, spdm_response_size,
1671 : spdm_response, response_size,
1672 : response);
1673 : }
1674 1 : return LIBSPDM_STATUS_SUCCESS;
1675 :
1676 1 : case 0xE: {
1677 : spdm_key_exchange_response_t *spdm_response;
1678 : size_t dhe_key_size;
1679 : uint32_t hash_size;
1680 : uint32_t measurement_hash_size;
1681 : size_t signature_size;
1682 : uint32_t hmac_size;
1683 : uint8_t *ptr;
1684 : void *dhe_context;
1685 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
1686 : size_t final_key_size;
1687 : size_t opaque_key_exchange_rsp_size;
1688 : void *data;
1689 : size_t data_size;
1690 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
1691 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1692 : uint8_t *cert_buffer;
1693 : size_t cert_buffer_size;
1694 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1695 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1696 : uint8_t bin_str0[128];
1697 : size_t bin_str0_size;
1698 : uint8_t bin_str2[128];
1699 : size_t bin_str2_size;
1700 : uint8_t bin_str7[128];
1701 : size_t bin_str7_size;
1702 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1703 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1704 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1705 : size_t spdm_response_size;
1706 : size_t transport_header_size;
1707 :
1708 : ((libspdm_context_t *)spdm_context)
1709 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1710 : ((libspdm_context_t *)spdm_context)
1711 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1712 : ((libspdm_context_t *)spdm_context)
1713 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
1714 : ((libspdm_context_t *)spdm_context)
1715 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1716 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1717 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1718 1 : measurement_hash_size = libspdm_get_hash_size( m_libspdm_use_hash_algo);
1719 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1720 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1721 1 : opaque_key_exchange_rsp_size =
1722 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
1723 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1724 1 : dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
1725 1 : opaque_key_exchange_rsp_size + signature_size +
1726 : hmac_size;
1727 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1728 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1729 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1730 :
1731 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1732 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
1733 1 : spdm_response->header.param1 = 0;
1734 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
1735 : /* Mutual authentication is requested even though it is not supported. */
1736 1 : spdm_response->mut_auth_requested =
1737 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
1738 1 : spdm_response->req_slot_id_param = 0;
1739 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
1740 1 : ptr = (void *)(spdm_response + 1);
1741 1 : dhe_context = libspdm_dhe_new(
1742 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1743 : m_libspdm_use_dhe_algo,
1744 : true);
1745 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
1746 1 : final_key_size = sizeof(final_key);
1747 1 : libspdm_dhe_compute_key(
1748 : m_libspdm_use_dhe_algo, dhe_context,
1749 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
1750 : sizeof(spdm_key_exchange_request_t),
1751 : dhe_key_size, final_key, &final_key_size);
1752 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1753 1 : ptr += dhe_key_size;
1754 : /*Mock measurement hash*/
1755 1 : libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
1756 : m_libspdm_use_tcb_hash_value, measurement_hash_size);
1757 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
1758 : measurement_hash_data, measurement_hash_size);
1759 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
1760 1 : ptr += measurement_hash_size;
1761 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1762 1 : ptr += sizeof(uint16_t);
1763 1 : libspdm_build_opaque_data_version_selection_data(
1764 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1765 : &opaque_key_exchange_rsp_size, ptr);
1766 1 : ptr += opaque_key_exchange_rsp_size;
1767 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1768 : m_libspdm_use_asym_algo, &data,
1769 : &data_size, NULL, NULL);
1770 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1771 : sizeof(m_libspdm_local_buffer)
1772 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1773 : m_libspdm_local_buffer),
1774 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1775 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1776 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1777 : m_libspdm_local_buffer_size));
1778 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1779 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1780 1 : cert_buffer = (uint8_t *)data;
1781 1 : cert_buffer_size = data_size;
1782 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
1783 : /* transcript.message_a size is 0*/
1784 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1785 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1786 : m_libspdm_local_buffer_size);
1787 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1788 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1789 1 : free(data);
1790 1 : libspdm_responder_data_sign(
1791 : spdm_context,
1792 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1793 : 0, SPDM_KEY_EXCHANGE_RSP,
1794 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
1795 1 : false, libspdm_get_managed_buffer(&th_curr),
1796 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1797 : &signature_size);
1798 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1799 : sizeof(m_libspdm_local_buffer)
1800 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1801 : m_libspdm_local_buffer),
1802 : ptr, signature_size);
1803 1 : m_libspdm_local_buffer_size += signature_size;
1804 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1805 1 : ptr += signature_size;
1806 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1807 : libspdm_get_managed_buffer_size(&th_curr),
1808 : th_curr_hash_data);
1809 1 : bin_str0_size = sizeof(bin_str0);
1810 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1811 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
1812 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
1813 : &bin_str0_size);
1814 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1815 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
1816 1 : bin_str2_size = sizeof(bin_str2);
1817 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1818 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1819 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
1820 : bin_str2, &bin_str2_size);
1821 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
1822 : bin_str2, bin_str2_size,
1823 : response_handshake_secret, hash_size);
1824 1 : bin_str7_size = sizeof(bin_str7);
1825 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1826 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1827 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1828 : &bin_str7_size);
1829 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1830 : hash_size, bin_str7, bin_str7_size,
1831 : response_finished_key, hash_size);
1832 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1833 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1834 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1835 : response_finished_key, hash_size, ptr);
1836 1 : ptr += hmac_size;
1837 :
1838 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1839 : false, spdm_response_size,
1840 : spdm_response, response_size,
1841 : response);
1842 : }
1843 1 : return LIBSPDM_STATUS_SUCCESS;
1844 :
1845 1 : case 0xF: {
1846 : spdm_key_exchange_response_t *spdm_response;
1847 : size_t dhe_key_size;
1848 : uint32_t hash_size;
1849 : size_t signature_size;
1850 : uint32_t hmac_size;
1851 : uint8_t *ptr;
1852 : void *dhe_context;
1853 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
1854 : size_t final_key_size;
1855 : size_t opaque_key_exchange_rsp_size;
1856 : void *data;
1857 : size_t data_size;
1858 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1859 : uint8_t *cert_buffer;
1860 : size_t cert_buffer_size;
1861 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1862 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
1863 : uint8_t bin_str0[128];
1864 : size_t bin_str0_size;
1865 : uint8_t bin_str2[128];
1866 : size_t bin_str2_size;
1867 : uint8_t bin_str7[128];
1868 : size_t bin_str7_size;
1869 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1870 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1871 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1872 : size_t spdm_response_size;
1873 : size_t transport_header_size;
1874 :
1875 : ((libspdm_context_t *)spdm_context)
1876 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1877 : ((libspdm_context_t *)spdm_context)
1878 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1879 : ((libspdm_context_t *)spdm_context)
1880 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
1881 : ((libspdm_context_t *)spdm_context)
1882 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1883 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1884 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1885 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1886 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
1887 1 : opaque_key_exchange_rsp_size =
1888 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
1889 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
1890 1 : dhe_key_size + 0 + sizeof(uint16_t) +
1891 1 : opaque_key_exchange_rsp_size + signature_size +
1892 : hmac_size;
1893 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1894 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1895 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1896 :
1897 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1898 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
1899 1 : spdm_response->header.param1 = 0;
1900 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
1901 1 : spdm_response->mut_auth_requested = 0;
1902 1 : spdm_response->req_slot_id_param = 0;
1903 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
1904 1 : ptr = (void *)(spdm_response + 1);
1905 1 : dhe_context = libspdm_dhe_new(
1906 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1907 : m_libspdm_use_dhe_algo,
1908 : true);
1909 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
1910 1 : final_key_size = sizeof(final_key);
1911 1 : libspdm_dhe_compute_key(
1912 : m_libspdm_use_dhe_algo, dhe_context,
1913 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
1914 : sizeof(spdm_key_exchange_request_t),
1915 : dhe_key_size, final_key, &final_key_size);
1916 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
1917 1 : ptr += dhe_key_size;
1918 : /* libspdm_zero_mem (ptr, hash_size);
1919 : * ptr += hash_size;*/
1920 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
1921 1 : ptr += sizeof(uint16_t);
1922 1 : libspdm_build_opaque_data_version_selection_data(
1923 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1924 : &opaque_key_exchange_rsp_size, ptr);
1925 1 : ptr += opaque_key_exchange_rsp_size;
1926 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1927 : m_libspdm_use_asym_algo, &data,
1928 : &data_size, NULL, NULL);
1929 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1930 : sizeof(m_libspdm_local_buffer)
1931 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1932 : m_libspdm_local_buffer),
1933 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1934 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1935 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1936 : m_libspdm_local_buffer_size));
1937 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1938 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1939 1 : cert_buffer = (uint8_t *)data;
1940 1 : cert_buffer_size = data_size;
1941 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
1942 : /* transcript.message_a size is 0*/
1943 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1944 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1945 : m_libspdm_local_buffer_size);
1946 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1947 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1948 1 : free(data);
1949 1 : libspdm_responder_data_sign(
1950 : spdm_context,
1951 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1952 : 0, SPDM_KEY_EXCHANGE_RSP,
1953 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
1954 1 : false, libspdm_get_managed_buffer(&th_curr),
1955 : libspdm_get_managed_buffer_size(&th_curr), ptr,
1956 : &signature_size);
1957 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1958 : sizeof(m_libspdm_local_buffer)
1959 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1960 : m_libspdm_local_buffer),
1961 : ptr, signature_size);
1962 1 : m_libspdm_local_buffer_size += signature_size;
1963 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
1964 1 : ptr += signature_size;
1965 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1966 : libspdm_get_managed_buffer_size(&th_curr),
1967 : th_curr_hash_data);
1968 1 : bin_str0_size = sizeof(bin_str0);
1969 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1970 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
1971 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
1972 : &bin_str0_size);
1973 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
1974 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
1975 1 : bin_str2_size = sizeof(bin_str2);
1976 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1977 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1978 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
1979 : bin_str2, &bin_str2_size);
1980 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
1981 : bin_str2, bin_str2_size,
1982 : response_handshake_secret, hash_size);
1983 1 : bin_str7_size = sizeof(bin_str7);
1984 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1985 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1986 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1987 : &bin_str7_size);
1988 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1989 : hash_size, bin_str7, bin_str7_size,
1990 : response_finished_key, hash_size);
1991 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1992 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1993 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1994 : response_finished_key, hash_size, ptr);
1995 1 : ptr += hmac_size;
1996 :
1997 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1998 : false, spdm_response_size,
1999 : spdm_response, response_size,
2000 : response);
2001 : }
2002 1 : return LIBSPDM_STATUS_SUCCESS;
2003 :
2004 1 : case 0x10: {
2005 : spdm_key_exchange_response_t *spdm_response;
2006 : size_t dhe_key_size;
2007 : uint32_t hash_size;
2008 : size_t signature_size;
2009 : uint32_t hmac_size;
2010 : uint8_t *ptr;
2011 : void *dhe_context;
2012 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
2013 : size_t final_key_size;
2014 : size_t opaque_key_exchange_rsp_size;
2015 : void *data;
2016 : size_t data_size;
2017 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2018 : uint8_t *cert_buffer;
2019 : size_t cert_buffer_size;
2020 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2021 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2022 : uint8_t bin_str0[128];
2023 : size_t bin_str0_size;
2024 : uint8_t bin_str2[128];
2025 : size_t bin_str2_size;
2026 : uint8_t bin_str7[128];
2027 : size_t bin_str7_size;
2028 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2029 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2030 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2031 : size_t spdm_response_size;
2032 : size_t transport_header_size;
2033 :
2034 : ((libspdm_context_t *)spdm_context)
2035 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2036 : ((libspdm_context_t *)spdm_context)
2037 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2038 : ((libspdm_context_t *)spdm_context)
2039 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
2040 : ((libspdm_context_t *)spdm_context)
2041 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2042 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2043 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2044 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2045 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2046 1 : opaque_key_exchange_rsp_size =
2047 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
2048 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2049 1 : dhe_key_size + 0 + sizeof(uint16_t) +
2050 1 : opaque_key_exchange_rsp_size + signature_size +
2051 : hmac_size;
2052 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2053 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2054 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2055 :
2056 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2057 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
2058 1 : spdm_response->header.param1 = 0;
2059 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
2060 1 : spdm_response->mut_auth_requested = 0;
2061 1 : spdm_response->req_slot_id_param = 0;
2062 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
2063 1 : ptr = (void *)(spdm_response + 1);
2064 1 : dhe_context = libspdm_dhe_new(
2065 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2066 : m_libspdm_use_dhe_algo,
2067 : true);
2068 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
2069 1 : final_key_size = sizeof(final_key);
2070 1 : libspdm_dhe_compute_key(
2071 : m_libspdm_use_dhe_algo, dhe_context,
2072 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2073 : sizeof(spdm_key_exchange_request_t),
2074 : dhe_key_size, final_key, &final_key_size);
2075 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2076 1 : ptr += dhe_key_size;
2077 : /* libspdm_zero_mem (ptr, hash_size);
2078 : * ptr += hash_size;*/
2079 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2080 1 : ptr += sizeof(uint16_t);
2081 1 : libspdm_build_opaque_data_version_selection_data(
2082 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2083 : &opaque_key_exchange_rsp_size, ptr);
2084 1 : ptr += opaque_key_exchange_rsp_size;
2085 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2086 : m_libspdm_use_asym_algo, &data,
2087 : &data_size, NULL, NULL);
2088 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2089 : sizeof(m_libspdm_local_buffer)
2090 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2091 : m_libspdm_local_buffer),
2092 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2093 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2094 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2095 : m_libspdm_local_buffer_size));
2096 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2097 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2098 1 : cert_buffer = (uint8_t *)data;
2099 1 : cert_buffer_size = data_size;
2100 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
2101 : /* transcript.message_a size is 0*/
2102 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2103 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2104 : m_libspdm_local_buffer_size);
2105 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2106 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2107 1 : free(data);
2108 1 : libspdm_responder_data_sign(
2109 : spdm_context,
2110 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2111 : 0, SPDM_KEY_EXCHANGE_RSP,
2112 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2113 1 : false, libspdm_get_managed_buffer(&th_curr),
2114 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2115 : &signature_size);
2116 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2117 : sizeof(m_libspdm_local_buffer)
2118 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2119 : m_libspdm_local_buffer),
2120 : ptr, signature_size);
2121 1 : m_libspdm_local_buffer_size += signature_size;
2122 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2123 1 : ptr += signature_size;
2124 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2125 : libspdm_get_managed_buffer_size(&th_curr),
2126 : th_curr_hash_data);
2127 1 : bin_str0_size = sizeof(bin_str0);
2128 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2129 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2130 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2131 : &bin_str0_size);
2132 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2133 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2134 1 : bin_str2_size = sizeof(bin_str2);
2135 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2136 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2137 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2138 : bin_str2, &bin_str2_size);
2139 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2140 : bin_str2, bin_str2_size,
2141 : response_handshake_secret, hash_size);
2142 1 : bin_str7_size = sizeof(bin_str7);
2143 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2144 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2145 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2146 : &bin_str7_size);
2147 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2148 : hash_size, bin_str7, bin_str7_size,
2149 : response_finished_key, hash_size);
2150 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2151 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2152 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2153 : response_finished_key, hash_size, ptr);
2154 1 : ptr += hmac_size;
2155 :
2156 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2157 : false, spdm_response_size,
2158 : spdm_response, response_size,
2159 : response);
2160 : }
2161 1 : return LIBSPDM_STATUS_SUCCESS;
2162 :
2163 1 : case 0x11: {
2164 : spdm_key_exchange_response_t *spdm_response;
2165 : size_t dhe_key_size;
2166 : uint32_t hash_size;
2167 : uint32_t measurement_hash_size;
2168 : size_t signature_size;
2169 : uint32_t hmac_size;
2170 : uint8_t *ptr;
2171 : void *dhe_context;
2172 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
2173 : size_t final_key_size;
2174 : size_t opaque_key_exchange_rsp_size;
2175 : void *data;
2176 : size_t data_size;
2177 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
2178 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2179 : uint8_t *cert_buffer;
2180 : size_t cert_buffer_size;
2181 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2182 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2183 : uint8_t bin_str0[128];
2184 : size_t bin_str0_size;
2185 : uint8_t bin_str2[128];
2186 : size_t bin_str2_size;
2187 : uint8_t bin_str7[128];
2188 : size_t bin_str7_size;
2189 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2190 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2191 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2192 : size_t spdm_response_size;
2193 : size_t transport_header_size;
2194 :
2195 : ((libspdm_context_t *)spdm_context)
2196 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2197 : ((libspdm_context_t *)spdm_context)
2198 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2199 : ((libspdm_context_t *)spdm_context)
2200 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
2201 : ((libspdm_context_t *)spdm_context)
2202 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2203 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2204 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2205 1 : measurement_hash_size = libspdm_get_hash_size( m_libspdm_use_hash_algo);
2206 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2207 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2208 1 : opaque_key_exchange_rsp_size =
2209 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
2210 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2211 1 : dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
2212 1 : opaque_key_exchange_rsp_size + signature_size +
2213 : hmac_size;
2214 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2215 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2216 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2217 :
2218 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2219 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
2220 1 : spdm_response->header.param1 = 0;
2221 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
2222 1 : spdm_response->mut_auth_requested = 0;
2223 1 : spdm_response->req_slot_id_param = 0;
2224 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
2225 1 : ptr = (void *)(spdm_response + 1);
2226 1 : dhe_context = libspdm_dhe_new(
2227 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2228 : m_libspdm_use_dhe_algo,
2229 : true);
2230 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
2231 1 : final_key_size = sizeof(final_key);
2232 1 : libspdm_dhe_compute_key(
2233 : m_libspdm_use_dhe_algo, dhe_context,
2234 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2235 : sizeof(spdm_key_exchange_request_t),
2236 : dhe_key_size, final_key, &final_key_size);
2237 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2238 1 : ptr += dhe_key_size;
2239 : /*Mock measurement hash as TCB*/
2240 1 : libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
2241 : m_libspdm_use_tcb_hash_value, measurement_hash_size);
2242 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
2243 : measurement_hash_data, measurement_hash_size);
2244 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
2245 1 : ptr += measurement_hash_size;
2246 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2247 1 : ptr += sizeof(uint16_t);
2248 1 : libspdm_build_opaque_data_version_selection_data(
2249 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2250 : &opaque_key_exchange_rsp_size, ptr);
2251 1 : ptr += opaque_key_exchange_rsp_size;
2252 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2253 : m_libspdm_use_asym_algo, &data,
2254 : &data_size, NULL, NULL);
2255 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2256 : sizeof(m_libspdm_local_buffer)
2257 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2258 : m_libspdm_local_buffer),
2259 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2260 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2261 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2262 : m_libspdm_local_buffer_size));
2263 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2264 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2265 1 : cert_buffer = (uint8_t *)data;
2266 1 : cert_buffer_size = data_size;
2267 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
2268 : /* transcript.message_a size is 0*/
2269 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2270 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2271 : m_libspdm_local_buffer_size);
2272 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2273 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2274 1 : free(data);
2275 1 : libspdm_responder_data_sign(
2276 : spdm_context,
2277 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2278 : 0, SPDM_KEY_EXCHANGE_RSP,
2279 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2280 1 : false, libspdm_get_managed_buffer(&th_curr),
2281 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2282 : &signature_size);
2283 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2284 : sizeof(m_libspdm_local_buffer)
2285 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2286 : m_libspdm_local_buffer),
2287 : ptr, signature_size);
2288 1 : m_libspdm_local_buffer_size += signature_size;
2289 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2290 1 : ptr += signature_size;
2291 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2292 : libspdm_get_managed_buffer_size(&th_curr),
2293 : th_curr_hash_data);
2294 1 : bin_str0_size = sizeof(bin_str0);
2295 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2296 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2297 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2298 : &bin_str0_size);
2299 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2300 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2301 1 : bin_str2_size = sizeof(bin_str2);
2302 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2303 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2304 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2305 : bin_str2, &bin_str2_size);
2306 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2307 : bin_str2, bin_str2_size,
2308 : response_handshake_secret, hash_size);
2309 1 : bin_str7_size = sizeof(bin_str7);
2310 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2311 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2312 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2313 : &bin_str7_size);
2314 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2315 : hash_size, bin_str7, bin_str7_size,
2316 : response_finished_key, hash_size);
2317 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2318 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2319 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2320 : response_finished_key, hash_size, ptr);
2321 1 : ptr += hmac_size;
2322 :
2323 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2324 : false, spdm_response_size,
2325 : spdm_response, response_size,
2326 : response);
2327 : }
2328 1 : return LIBSPDM_STATUS_SUCCESS;
2329 :
2330 1 : case 0x12: {
2331 : spdm_key_exchange_response_t *spdm_response;
2332 : size_t dhe_key_size;
2333 : uint32_t hash_size;
2334 : uint32_t measurement_hash_size;
2335 : size_t signature_size;
2336 : uint32_t hmac_size;
2337 : uint8_t *ptr;
2338 : void *dhe_context;
2339 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
2340 : size_t final_key_size;
2341 : size_t opaque_key_exchange_rsp_size;
2342 : void *data;
2343 : size_t data_size;
2344 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2345 : uint8_t *cert_buffer;
2346 : size_t cert_buffer_size;
2347 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2348 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2349 : uint8_t bin_str0[128];
2350 : size_t bin_str0_size;
2351 : uint8_t bin_str2[128];
2352 : size_t bin_str2_size;
2353 : uint8_t bin_str7[128];
2354 : size_t bin_str7_size;
2355 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2356 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2357 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2358 : size_t spdm_response_size;
2359 : size_t transport_header_size;
2360 :
2361 : ((libspdm_context_t *)spdm_context)
2362 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2363 : ((libspdm_context_t *)spdm_context)
2364 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2365 : ((libspdm_context_t *)spdm_context)
2366 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
2367 : ((libspdm_context_t *)spdm_context)
2368 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2369 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2370 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2371 1 : measurement_hash_size = 0;
2372 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2373 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2374 1 : opaque_key_exchange_rsp_size =
2375 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
2376 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2377 1 : dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
2378 1 : opaque_key_exchange_rsp_size + signature_size +
2379 : hmac_size;
2380 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2381 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2382 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2383 :
2384 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2385 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
2386 1 : spdm_response->header.param1 = 0;
2387 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
2388 1 : spdm_response->mut_auth_requested = 0;
2389 1 : spdm_response->req_slot_id_param = 0;
2390 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
2391 1 : ptr = (void *)(spdm_response + 1);
2392 1 : dhe_context = libspdm_dhe_new(
2393 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2394 : m_libspdm_use_dhe_algo,
2395 : true);
2396 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
2397 1 : final_key_size = sizeof(final_key);
2398 1 : libspdm_dhe_compute_key(
2399 : m_libspdm_use_dhe_algo, dhe_context,
2400 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2401 : sizeof(spdm_key_exchange_request_t),
2402 : dhe_key_size, final_key, &final_key_size);
2403 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2404 1 : ptr += dhe_key_size;
2405 :
2406 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2407 1 : ptr += sizeof(uint16_t);
2408 1 : libspdm_build_opaque_data_version_selection_data(
2409 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2410 : &opaque_key_exchange_rsp_size, ptr);
2411 1 : ptr += opaque_key_exchange_rsp_size;
2412 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2413 : m_libspdm_use_asym_algo, &data,
2414 : &data_size, NULL, NULL);
2415 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2416 : sizeof(m_libspdm_local_buffer)
2417 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2418 : m_libspdm_local_buffer),
2419 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2420 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2421 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2422 : m_libspdm_local_buffer_size));
2423 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2424 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2425 1 : cert_buffer = (uint8_t *)data;
2426 1 : cert_buffer_size = data_size;
2427 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
2428 : /* transcript.message_a size is 0*/
2429 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2430 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2431 : m_libspdm_local_buffer_size);
2432 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2433 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2434 1 : free(data);
2435 1 : libspdm_responder_data_sign(
2436 : spdm_context,
2437 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2438 : 0, SPDM_KEY_EXCHANGE_RSP,
2439 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2440 1 : false, libspdm_get_managed_buffer(&th_curr),
2441 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2442 : &signature_size);
2443 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2444 : sizeof(m_libspdm_local_buffer)
2445 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2446 : m_libspdm_local_buffer),
2447 : ptr, signature_size);
2448 1 : m_libspdm_local_buffer_size += signature_size;
2449 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2450 1 : ptr += signature_size-1;
2451 1 : *ptr ^= 0xFF;
2452 1 : ptr++;
2453 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2454 : libspdm_get_managed_buffer_size(&th_curr),
2455 : th_curr_hash_data);
2456 1 : bin_str0_size = sizeof(bin_str0);
2457 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2458 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2459 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2460 : &bin_str0_size);
2461 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2462 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2463 1 : bin_str2_size = sizeof(bin_str2);
2464 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2465 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2466 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2467 : bin_str2, &bin_str2_size);
2468 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2469 : bin_str2, bin_str2_size,
2470 : response_handshake_secret, hash_size);
2471 1 : bin_str7_size = sizeof(bin_str7);
2472 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2473 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2474 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2475 : &bin_str7_size);
2476 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2477 : hash_size, bin_str7, bin_str7_size,
2478 : response_finished_key, hash_size);
2479 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2480 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2481 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2482 : response_finished_key, hash_size, ptr);
2483 1 : ptr += hmac_size;
2484 :
2485 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2486 : false, spdm_response_size,
2487 : spdm_response, response_size,
2488 : response);
2489 : }
2490 1 : return LIBSPDM_STATUS_SUCCESS;
2491 :
2492 0 : case 0x13: {
2493 : }
2494 0 : return LIBSPDM_STATUS_SUCCESS;
2495 :
2496 1 : case 0x14: {
2497 : spdm_key_exchange_response_t *spdm_response;
2498 : size_t dhe_key_size;
2499 : uint32_t hash_size;
2500 : size_t signature_size;
2501 : uint32_t hmac_size;
2502 : uint8_t *ptr;
2503 : void *dhe_context;
2504 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
2505 : size_t final_key_size;
2506 : size_t opaque_key_exchange_rsp_size;
2507 : void *data;
2508 : size_t data_size;
2509 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2510 : uint8_t *cert_buffer;
2511 : size_t cert_buffer_size;
2512 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2513 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2514 : uint8_t bin_str0[128];
2515 : size_t bin_str0_size;
2516 : uint8_t bin_str2[128];
2517 : size_t bin_str2_size;
2518 : uint8_t bin_str7[128];
2519 : size_t bin_str7_size;
2520 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2521 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2522 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2523 : size_t spdm_response_size;
2524 : size_t transport_header_size;
2525 :
2526 : ((libspdm_context_t *)spdm_context)
2527 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2528 : ((libspdm_context_t *)spdm_context)
2529 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2530 : ((libspdm_context_t *)spdm_context)
2531 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
2532 : ((libspdm_context_t *)spdm_context)
2533 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2534 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2535 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2536 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2537 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2538 1 : opaque_key_exchange_rsp_size =
2539 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
2540 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2541 1 : dhe_key_size + 0 + sizeof(uint16_t) +
2542 1 : opaque_key_exchange_rsp_size + signature_size +
2543 : hmac_size;
2544 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2545 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2546 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2547 :
2548 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2549 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
2550 1 : spdm_response->header.param1 = 5;
2551 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
2552 1 : spdm_response->mut_auth_requested = 0;
2553 1 : spdm_response->req_slot_id_param = 0;
2554 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
2555 1 : ptr = (void *)(spdm_response + 1);
2556 1 : dhe_context = libspdm_dhe_new(
2557 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2558 : m_libspdm_use_dhe_algo,
2559 : true);
2560 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
2561 1 : final_key_size = sizeof(final_key);
2562 1 : libspdm_dhe_compute_key(
2563 : m_libspdm_use_dhe_algo, dhe_context,
2564 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2565 : sizeof(spdm_key_exchange_request_t),
2566 : dhe_key_size, final_key, &final_key_size);
2567 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2568 1 : ptr += dhe_key_size;
2569 : /* libspdm_zero_mem (ptr, hash_size);
2570 : * ptr += hash_size;*/
2571 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2572 1 : ptr += sizeof(uint16_t);
2573 1 : libspdm_build_opaque_data_version_selection_data(
2574 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2575 : &opaque_key_exchange_rsp_size, ptr);
2576 1 : ptr += opaque_key_exchange_rsp_size;
2577 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2578 : m_libspdm_use_asym_algo, &data,
2579 : &data_size, NULL, NULL);
2580 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2581 : sizeof(m_libspdm_local_buffer)
2582 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2583 : m_libspdm_local_buffer),
2584 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2585 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2586 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2587 : m_libspdm_local_buffer_size));
2588 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2589 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2590 1 : cert_buffer = (uint8_t *)data;
2591 1 : cert_buffer_size = data_size;
2592 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
2593 : /* transcript.message_a size is 0*/
2594 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2595 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2596 : m_libspdm_local_buffer_size);
2597 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2598 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2599 1 : free(data);
2600 1 : libspdm_responder_data_sign(
2601 : spdm_context,
2602 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2603 : 0, SPDM_KEY_EXCHANGE_RSP,
2604 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2605 1 : false, libspdm_get_managed_buffer(&th_curr),
2606 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2607 : &signature_size);
2608 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2609 : sizeof(m_libspdm_local_buffer)
2610 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2611 : m_libspdm_local_buffer),
2612 : ptr, signature_size);
2613 1 : m_libspdm_local_buffer_size += signature_size;
2614 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2615 1 : ptr += signature_size;
2616 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2617 : libspdm_get_managed_buffer_size(&th_curr),
2618 : th_curr_hash_data);
2619 1 : bin_str0_size = sizeof(bin_str0);
2620 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2621 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2622 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2623 : &bin_str0_size);
2624 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2625 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2626 1 : bin_str2_size = sizeof(bin_str2);
2627 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2628 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2629 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2630 : bin_str2, &bin_str2_size);
2631 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2632 : bin_str2, bin_str2_size,
2633 : response_handshake_secret, hash_size);
2634 1 : bin_str7_size = sizeof(bin_str7);
2635 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2636 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2637 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2638 : &bin_str7_size);
2639 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2640 : hash_size, bin_str7, bin_str7_size,
2641 : response_finished_key, hash_size);
2642 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2643 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2644 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2645 : response_finished_key, hash_size, ptr);
2646 1 : ptr += hmac_size;
2647 :
2648 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2649 : false, spdm_response_size,
2650 : spdm_response, response_size,
2651 : response);
2652 : }
2653 1 : return LIBSPDM_STATUS_SUCCESS;
2654 :
2655 1 : case 0x15: {
2656 : spdm_key_exchange_response_t *spdm_response;
2657 : size_t dhe_key_size;
2658 : uint32_t hash_size;
2659 : size_t signature_size;
2660 : uint32_t hmac_size;
2661 : uint8_t *ptr;
2662 : void *dhe_context;
2663 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
2664 : size_t final_key_size;
2665 : size_t opaque_key_exchange_rsp_size;
2666 : void *data;
2667 : size_t data_size;
2668 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2669 : uint8_t *cert_buffer;
2670 : size_t cert_buffer_size;
2671 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2672 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2673 : uint8_t bin_str0[128];
2674 : size_t bin_str0_size;
2675 : uint8_t bin_str2[128];
2676 : size_t bin_str2_size;
2677 : uint8_t bin_str7[128];
2678 : size_t bin_str7_size;
2679 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2680 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2681 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2682 : size_t spdm_response_size;
2683 : size_t transport_header_size;
2684 :
2685 : ((libspdm_context_t *)spdm_context)
2686 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2687 : ((libspdm_context_t *)spdm_context)
2688 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2689 : ((libspdm_context_t *)spdm_context)
2690 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
2691 : ((libspdm_context_t *)spdm_context)
2692 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2693 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2694 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2695 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2696 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2697 1 : opaque_key_exchange_rsp_size =
2698 1 : libspdm_get_opaque_data_version_selection_data_size(spdm_context);
2699 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2700 1 : dhe_key_size + 0 + sizeof(uint16_t) +
2701 1 : opaque_key_exchange_rsp_size + signature_size + hmac_size;
2702 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2703 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2704 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2705 :
2706 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2707 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
2708 1 : spdm_response->header.param1 = 0;
2709 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
2710 1 : spdm_response->mut_auth_requested = 0;
2711 1 : spdm_response->req_slot_id_param = 0;
2712 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
2713 1 : ptr = (void *)(spdm_response + 1);
2714 1 : dhe_context = libspdm_dhe_new(
2715 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2716 : m_libspdm_use_dhe_algo, true);
2717 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
2718 1 : final_key_size = sizeof(final_key);
2719 1 : libspdm_dhe_compute_key(
2720 : m_libspdm_use_dhe_algo, dhe_context,
2721 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2722 : sizeof(spdm_key_exchange_request_t),
2723 : dhe_key_size, final_key, &final_key_size);
2724 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2725 1 : ptr += dhe_key_size;
2726 :
2727 1 : *(uint16_t *)ptr = SPDM_MAX_OPAQUE_DATA_SIZE + 1;
2728 1 : ptr += sizeof(uint16_t);
2729 1 : libspdm_build_opaque_data_version_selection_data(
2730 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2731 : &opaque_key_exchange_rsp_size, ptr);
2732 1 : ptr += opaque_key_exchange_rsp_size;
2733 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2734 : m_libspdm_use_asym_algo, &data,
2735 : &data_size, NULL, NULL);
2736 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2737 : sizeof(m_libspdm_local_buffer)
2738 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2739 : m_libspdm_local_buffer),
2740 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2741 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2742 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2743 : m_libspdm_local_buffer_size));
2744 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2745 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2746 1 : cert_buffer = (uint8_t *)data;
2747 1 : cert_buffer_size = data_size;
2748 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
2749 : /* transcript.message_a size is 0*/
2750 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2751 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2752 : m_libspdm_local_buffer_size);
2753 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2754 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2755 1 : free(data);
2756 1 : libspdm_responder_data_sign(
2757 : spdm_context,
2758 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2759 : 0, SPDM_KEY_EXCHANGE_RSP,
2760 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2761 1 : false, libspdm_get_managed_buffer(&th_curr),
2762 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2763 : &signature_size);
2764 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2765 : sizeof(m_libspdm_local_buffer)
2766 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2767 : m_libspdm_local_buffer),
2768 : ptr, signature_size);
2769 1 : m_libspdm_local_buffer_size += signature_size;
2770 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2771 1 : ptr += signature_size;
2772 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2773 : libspdm_get_managed_buffer_size(&th_curr),
2774 : th_curr_hash_data);
2775 1 : bin_str0_size = sizeof(bin_str0);
2776 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2777 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2778 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2779 : &bin_str0_size);
2780 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2781 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2782 1 : bin_str2_size = sizeof(bin_str2);
2783 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2784 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2785 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2786 : bin_str2, &bin_str2_size);
2787 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2788 : bin_str2, bin_str2_size,
2789 : response_handshake_secret, hash_size);
2790 1 : bin_str7_size = sizeof(bin_str7);
2791 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2792 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2793 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2794 : &bin_str7_size);
2795 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2796 : hash_size, bin_str7, bin_str7_size,
2797 : response_finished_key, hash_size);
2798 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2799 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2800 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2801 : response_finished_key, hash_size, ptr);
2802 1 : ptr += hmac_size;
2803 :
2804 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2805 : false, spdm_response_size,
2806 : spdm_response, response_size,
2807 : response);
2808 : }
2809 1 : return LIBSPDM_STATUS_SUCCESS;
2810 :
2811 1 : case 0x16: {
2812 : spdm_key_exchange_response_t *spdm_response;
2813 : size_t dhe_key_size;
2814 : uint32_t hash_size;
2815 : size_t signature_size;
2816 : uint32_t hmac_size;
2817 : uint8_t *ptr;
2818 : void *dhe_context;
2819 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
2820 : size_t final_key_size;
2821 : size_t opaque_key_exchange_rsp_size;
2822 : void *data;
2823 : size_t data_size;
2824 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2825 : uint8_t *cert_buffer;
2826 : size_t cert_buffer_size;
2827 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2828 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2829 : uint8_t bin_str0[128];
2830 : size_t bin_str0_size;
2831 : uint8_t bin_str2[128];
2832 : size_t bin_str2_size;
2833 : uint8_t bin_str7[128];
2834 : size_t bin_str7_size;
2835 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2836 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2837 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2838 : size_t spdm_response_size;
2839 : size_t transport_header_size;
2840 :
2841 : ((libspdm_context_t *)spdm_context)
2842 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2843 : ((libspdm_context_t *)spdm_context)
2844 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2845 : ((libspdm_context_t *)spdm_context)
2846 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
2847 : ((libspdm_context_t *)spdm_context)
2848 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2849 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2850 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2851 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2852 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
2853 1 : opaque_key_exchange_rsp_size =
2854 1 : libspdm_get_opaque_data_version_selection_data_size(spdm_context);
2855 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
2856 1 : dhe_key_size + 0 + sizeof(uint16_t) +
2857 1 : opaque_key_exchange_rsp_size + signature_size +
2858 : hmac_size;
2859 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2860 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2861 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2862 :
2863 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2864 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
2865 1 : spdm_response->header.param1 = 0;
2866 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
2867 : /* Requester's PUB_KEY_ID_CAP is set and Responder requests the encapsulated flow. */
2868 1 : spdm_response->mut_auth_requested =
2869 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
2870 1 : spdm_response->req_slot_id_param = 0;
2871 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
2872 1 : ptr = (void *)(spdm_response + 1);
2873 1 : dhe_context = libspdm_dhe_new(
2874 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2875 : m_libspdm_use_dhe_algo,
2876 : true);
2877 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
2878 1 : final_key_size = sizeof(final_key);
2879 1 : libspdm_dhe_compute_key(
2880 : m_libspdm_use_dhe_algo, dhe_context,
2881 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
2882 : sizeof(spdm_key_exchange_request_t),
2883 : dhe_key_size, final_key, &final_key_size);
2884 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
2885 1 : ptr += dhe_key_size;
2886 : /* libspdm_zero_mem (ptr, hash_size);
2887 : * ptr += hash_size;*/
2888 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
2889 1 : ptr += sizeof(uint16_t);
2890 1 : libspdm_build_opaque_data_version_selection_data(
2891 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2892 : &opaque_key_exchange_rsp_size, ptr);
2893 1 : ptr += opaque_key_exchange_rsp_size;
2894 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2895 : m_libspdm_use_asym_algo, &data,
2896 : &data_size, NULL, NULL);
2897 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2898 : sizeof(m_libspdm_local_buffer)
2899 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2900 : m_libspdm_local_buffer),
2901 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2902 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2903 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2904 : m_libspdm_local_buffer_size));
2905 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2906 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2907 1 : cert_buffer = (uint8_t *)data;
2908 1 : cert_buffer_size = data_size;
2909 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
2910 : /* transcript.message_a size is 0*/
2911 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
2912 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2913 : m_libspdm_local_buffer_size);
2914 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2915 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2916 1 : free(data);
2917 1 : libspdm_responder_data_sign(
2918 : spdm_context,
2919 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2920 : 0, SPDM_KEY_EXCHANGE_RSP,
2921 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2922 1 : false, libspdm_get_managed_buffer(&th_curr),
2923 : libspdm_get_managed_buffer_size(&th_curr), ptr,
2924 : &signature_size);
2925 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2926 : sizeof(m_libspdm_local_buffer)
2927 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2928 : m_libspdm_local_buffer),
2929 : ptr, signature_size);
2930 1 : m_libspdm_local_buffer_size += signature_size;
2931 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
2932 1 : ptr += signature_size;
2933 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2934 : libspdm_get_managed_buffer_size(&th_curr),
2935 : th_curr_hash_data);
2936 1 : bin_str0_size = sizeof(bin_str0);
2937 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2938 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
2939 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
2940 : &bin_str0_size);
2941 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
2942 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
2943 1 : bin_str2_size = sizeof(bin_str2);
2944 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2945 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2946 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
2947 : bin_str2, &bin_str2_size);
2948 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
2949 : bin_str2, bin_str2_size,
2950 : response_handshake_secret, hash_size);
2951 1 : bin_str7_size = sizeof(bin_str7);
2952 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2953 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2954 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2955 : &bin_str7_size);
2956 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2957 : hash_size, bin_str7, bin_str7_size,
2958 : response_finished_key, hash_size);
2959 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2960 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2961 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2962 : response_finished_key, hash_size, ptr);
2963 1 : ptr += hmac_size;
2964 :
2965 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2966 : false, spdm_response_size,
2967 : spdm_response, response_size,
2968 : response);
2969 : }
2970 1 : return LIBSPDM_STATUS_SUCCESS;
2971 :
2972 1 : case 0x17: {
2973 : spdm_key_exchange_response_t *spdm_response;
2974 : size_t dhe_key_size;
2975 : uint32_t hash_size;
2976 : size_t signature_size;
2977 : uint32_t hmac_size;
2978 : uint8_t *ptr;
2979 : void *dhe_context;
2980 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
2981 : size_t final_key_size;
2982 : size_t opaque_key_exchange_rsp_size;
2983 : void *data;
2984 : size_t data_size;
2985 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2986 : uint8_t *cert_buffer;
2987 : size_t cert_buffer_size;
2988 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2989 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
2990 : uint8_t bin_str0[128];
2991 : size_t bin_str0_size;
2992 : uint8_t bin_str2[128];
2993 : size_t bin_str2_size;
2994 : uint8_t bin_str7[128];
2995 : size_t bin_str7_size;
2996 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2997 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2998 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2999 : size_t spdm_response_size;
3000 : size_t transport_header_size;
3001 :
3002 : ((libspdm_context_t *)spdm_context)
3003 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3004 : ((libspdm_context_t *)spdm_context)
3005 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3006 : ((libspdm_context_t *)spdm_context)
3007 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3008 : ((libspdm_context_t *)spdm_context)
3009 1 : ->connection_info.algorithm.measurement_hash_algo = 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( spdm_context);
3016 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3017 1 : dhe_key_size + 0 + sizeof(uint16_t) +
3018 1 : opaque_key_exchange_rsp_size + signature_size +
3019 : hmac_size;
3020 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3021 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3022 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
3023 :
3024 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3025 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
3026 1 : spdm_response->header.param1 = 0;
3027 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
3028 1 : spdm_response->mut_auth_requested =
3029 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
3030 1 : spdm_response->req_slot_id_param = 0x0;
3031 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
3032 1 : ptr = (void *)(spdm_response + 1);
3033 1 : dhe_context = libspdm_dhe_new(
3034 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3035 : m_libspdm_use_dhe_algo,
3036 : true);
3037 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
3038 1 : final_key_size = sizeof(final_key);
3039 1 : libspdm_dhe_compute_key(
3040 : m_libspdm_use_dhe_algo, dhe_context,
3041 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
3042 : sizeof(spdm_key_exchange_request_t),
3043 : dhe_key_size, final_key, &final_key_size);
3044 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3045 1 : ptr += dhe_key_size;
3046 : /* libspdm_zero_mem (ptr, hash_size);
3047 : * ptr += hash_size;*/
3048 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3049 1 : ptr += sizeof(uint16_t);
3050 1 : libspdm_build_opaque_data_version_selection_data(
3051 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
3052 : &opaque_key_exchange_rsp_size, ptr);
3053 1 : ptr += opaque_key_exchange_rsp_size;
3054 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3055 : m_libspdm_use_asym_algo, &data,
3056 : &data_size, NULL, NULL);
3057 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3058 : sizeof(m_libspdm_local_buffer)
3059 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3060 : m_libspdm_local_buffer),
3061 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3062 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3063 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3064 : m_libspdm_local_buffer_size));
3065 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3066 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3067 1 : cert_buffer = (uint8_t *)data;
3068 1 : cert_buffer_size = data_size;
3069 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
3070 : /* transcript.message_a size is 0*/
3071 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3072 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3073 : m_libspdm_local_buffer_size);
3074 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3075 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3076 1 : free(data);
3077 1 : libspdm_responder_data_sign(
3078 : spdm_context,
3079 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3080 : 0, SPDM_KEY_EXCHANGE_RSP,
3081 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
3082 1 : false, libspdm_get_managed_buffer(&th_curr),
3083 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3084 : &signature_size);
3085 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3086 : sizeof(m_libspdm_local_buffer)
3087 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3088 : m_libspdm_local_buffer),
3089 : ptr, signature_size);
3090 1 : m_libspdm_local_buffer_size += signature_size;
3091 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3092 1 : ptr += signature_size;
3093 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3094 : libspdm_get_managed_buffer_size(&th_curr),
3095 : th_curr_hash_data);
3096 1 : bin_str0_size = sizeof(bin_str0);
3097 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3098 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3099 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3100 : &bin_str0_size);
3101 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3102 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3103 1 : bin_str2_size = sizeof(bin_str2);
3104 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3105 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3106 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3107 : bin_str2, &bin_str2_size);
3108 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3109 : bin_str2, bin_str2_size,
3110 : response_handshake_secret, hash_size);
3111 1 : bin_str7_size = sizeof(bin_str7);
3112 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3113 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3114 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3115 : &bin_str7_size);
3116 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3117 : hash_size, bin_str7, bin_str7_size,
3118 : response_finished_key, hash_size);
3119 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3120 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3121 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3122 : response_finished_key, hash_size, ptr);
3123 1 : ptr += hmac_size;
3124 :
3125 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3126 : false, spdm_response_size,
3127 : spdm_response, response_size,
3128 : response);
3129 : }
3130 1 : return LIBSPDM_STATUS_SUCCESS;
3131 :
3132 0 : case 0x18: {
3133 : spdm_key_exchange_response_t *spdm_response;
3134 : size_t dhe_key_size;
3135 : uint32_t hash_size;
3136 : size_t signature_size;
3137 : uint32_t hmac_size;
3138 : uint8_t *ptr;
3139 : void *dhe_context;
3140 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
3141 : size_t final_key_size;
3142 : size_t opaque_key_exchange_rsp_size;
3143 : void *data;
3144 : size_t data_size;
3145 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3146 : uint8_t *cert_buffer;
3147 : size_t cert_buffer_size;
3148 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3149 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3150 : uint8_t bin_str0[128];
3151 : size_t bin_str0_size;
3152 : uint8_t bin_str2[128];
3153 : size_t bin_str2_size;
3154 : uint8_t bin_str7[128];
3155 : size_t bin_str7_size;
3156 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3157 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3158 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3159 : size_t spdm_response_size;
3160 : size_t transport_header_size;
3161 :
3162 : ((libspdm_context_t *)spdm_context)
3163 0 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3164 : ((libspdm_context_t *)spdm_context)
3165 0 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3166 : ((libspdm_context_t *)spdm_context)
3167 0 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3168 : ((libspdm_context_t *)spdm_context)
3169 0 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
3170 0 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3171 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3172 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3173 0 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3174 0 : opaque_key_exchange_rsp_size =
3175 0 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
3176 0 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3177 0 : dhe_key_size + 0 + sizeof(uint16_t) +
3178 0 : opaque_key_exchange_rsp_size + signature_size +
3179 : hmac_size;
3180 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3181 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3182 0 : libspdm_zero_mem(spdm_response,spdm_response_size);
3183 :
3184 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3185 0 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
3186 0 : spdm_response->header.param1 = 0;
3187 0 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
3188 0 : spdm_response->mut_auth_requested =
3189 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
3190 0 : spdm_response->req_slot_id_param = 0xF;
3191 0 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
3192 0 : ptr = (void *)(spdm_response + 1);
3193 0 : dhe_context = libspdm_dhe_new(
3194 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3195 : m_libspdm_use_dhe_algo,
3196 : true);
3197 0 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
3198 0 : final_key_size = sizeof(final_key);
3199 0 : libspdm_dhe_compute_key(
3200 : m_libspdm_use_dhe_algo, dhe_context,
3201 0 : (uint8_t *)&m_libspdm_local_buffer[0] +
3202 : sizeof(spdm_key_exchange_request_t),
3203 : dhe_key_size, final_key, &final_key_size);
3204 0 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3205 0 : ptr += dhe_key_size;
3206 : /* libspdm_zero_mem (ptr, hash_size);
3207 : * ptr += hash_size;*/
3208 0 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3209 0 : ptr += sizeof(uint16_t);
3210 0 : libspdm_build_opaque_data_version_selection_data(
3211 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
3212 : &opaque_key_exchange_rsp_size, ptr);
3213 0 : ptr += opaque_key_exchange_rsp_size;
3214 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3215 : m_libspdm_use_asym_algo, &data,
3216 : &data_size, NULL, NULL);
3217 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3218 : sizeof(m_libspdm_local_buffer)
3219 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3220 : m_libspdm_local_buffer),
3221 0 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3222 0 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3223 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3224 : m_libspdm_local_buffer_size));
3225 0 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3226 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3227 0 : cert_buffer = (uint8_t *)data;
3228 0 : cert_buffer_size = data_size;
3229 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
3230 : /* transcript.message_a size is 0*/
3231 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3232 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3233 : m_libspdm_local_buffer_size);
3234 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3235 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3236 0 : free(data);
3237 0 : libspdm_responder_data_sign(
3238 : spdm_context,
3239 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3240 : 0, SPDM_KEY_EXCHANGE_RSP,
3241 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
3242 0 : false, libspdm_get_managed_buffer(&th_curr),
3243 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3244 : &signature_size);
3245 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3246 : sizeof(m_libspdm_local_buffer)
3247 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3248 : m_libspdm_local_buffer),
3249 : ptr, signature_size);
3250 0 : m_libspdm_local_buffer_size += signature_size;
3251 0 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3252 0 : ptr += signature_size;
3253 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3254 : libspdm_get_managed_buffer_size(&th_curr),
3255 : th_curr_hash_data);
3256 0 : bin_str0_size = sizeof(bin_str0);
3257 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3258 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3259 0 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3260 : &bin_str0_size);
3261 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3262 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3263 0 : bin_str2_size = sizeof(bin_str2);
3264 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3265 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3266 0 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3267 : bin_str2, &bin_str2_size);
3268 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3269 : bin_str2, bin_str2_size,
3270 : response_handshake_secret, hash_size);
3271 0 : bin_str7_size = sizeof(bin_str7);
3272 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3273 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3274 0 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3275 : &bin_str7_size);
3276 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3277 : hash_size, bin_str7, bin_str7_size,
3278 : response_finished_key, hash_size);
3279 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3280 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3281 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3282 : response_finished_key, hash_size, ptr);
3283 0 : ptr += hmac_size;
3284 :
3285 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3286 : false, spdm_response_size,
3287 : spdm_response, response_size,
3288 : response);
3289 : }
3290 0 : return LIBSPDM_STATUS_SUCCESS;
3291 :
3292 0 : case 0x19: {
3293 : spdm_key_exchange_response_t *spdm_response;
3294 : size_t dhe_key_size;
3295 : uint32_t hash_size;
3296 : size_t signature_size;
3297 : uint32_t hmac_size;
3298 : uint8_t *ptr;
3299 : void *dhe_context;
3300 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
3301 : size_t final_key_size;
3302 : size_t opaque_key_exchange_rsp_size;
3303 : void *data;
3304 : size_t data_size;
3305 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3306 : uint8_t *cert_buffer;
3307 : size_t cert_buffer_size;
3308 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3309 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3310 : uint8_t bin_str0[128];
3311 : size_t bin_str0_size;
3312 : uint8_t bin_str2[128];
3313 : size_t bin_str2_size;
3314 : uint8_t bin_str7[128];
3315 : size_t bin_str7_size;
3316 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3317 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3318 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3319 : size_t spdm_response_size;
3320 : size_t transport_header_size;
3321 :
3322 : ((libspdm_context_t *)spdm_context)
3323 0 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3324 : ((libspdm_context_t *)spdm_context)
3325 0 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3326 : ((libspdm_context_t *)spdm_context)
3327 0 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3328 : ((libspdm_context_t *)spdm_context)
3329 0 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
3330 0 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3331 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3332 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3333 0 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3334 0 : opaque_key_exchange_rsp_size =
3335 0 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
3336 0 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3337 0 : dhe_key_size + 0 + sizeof(uint16_t) +
3338 0 : opaque_key_exchange_rsp_size + signature_size +
3339 : hmac_size;
3340 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3341 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3342 0 : libspdm_zero_mem(spdm_response,spdm_response_size);
3343 :
3344 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3345 0 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
3346 0 : spdm_response->header.param1 = 0;
3347 0 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
3348 0 : spdm_response->mut_auth_requested =
3349 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
3350 0 : spdm_response->req_slot_id_param = 0xF;
3351 0 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
3352 0 : ptr = (void *)(spdm_response + 1);
3353 0 : dhe_context = libspdm_dhe_new(
3354 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3355 : m_libspdm_use_dhe_algo,
3356 : true);
3357 0 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
3358 0 : final_key_size = sizeof(final_key);
3359 0 : libspdm_dhe_compute_key(
3360 : m_libspdm_use_dhe_algo, dhe_context,
3361 0 : (uint8_t *)&m_libspdm_local_buffer[0] +
3362 : sizeof(spdm_key_exchange_request_t),
3363 : dhe_key_size, final_key, &final_key_size);
3364 0 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3365 0 : ptr += dhe_key_size;
3366 : /* libspdm_zero_mem (ptr, hash_size);
3367 : * ptr += hash_size;*/
3368 0 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3369 0 : ptr += sizeof(uint16_t);
3370 0 : libspdm_build_opaque_data_version_selection_data(
3371 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
3372 : &opaque_key_exchange_rsp_size, ptr);
3373 0 : ptr += opaque_key_exchange_rsp_size;
3374 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3375 : m_libspdm_use_asym_algo, &data,
3376 : &data_size, NULL, NULL);
3377 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3378 : sizeof(m_libspdm_local_buffer)
3379 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3380 : m_libspdm_local_buffer),
3381 0 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3382 0 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3383 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3384 : m_libspdm_local_buffer_size));
3385 0 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3386 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3387 0 : cert_buffer = (uint8_t *)data;
3388 0 : cert_buffer_size = data_size;
3389 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
3390 : /* transcript.message_a size is 0*/
3391 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3392 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3393 : m_libspdm_local_buffer_size);
3394 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3395 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3396 0 : free(data);
3397 0 : libspdm_responder_data_sign(
3398 : spdm_context,
3399 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3400 : 0, SPDM_KEY_EXCHANGE_RSP,
3401 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
3402 0 : false, libspdm_get_managed_buffer(&th_curr),
3403 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3404 : &signature_size);
3405 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3406 : sizeof(m_libspdm_local_buffer)
3407 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3408 : m_libspdm_local_buffer),
3409 : ptr, signature_size);
3410 0 : m_libspdm_local_buffer_size += signature_size;
3411 0 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3412 0 : ptr += signature_size;
3413 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3414 : libspdm_get_managed_buffer_size(&th_curr),
3415 : th_curr_hash_data);
3416 0 : bin_str0_size = sizeof(bin_str0);
3417 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3418 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3419 0 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3420 : &bin_str0_size);
3421 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3422 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3423 0 : bin_str2_size = sizeof(bin_str2);
3424 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3425 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3426 0 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3427 : bin_str2, &bin_str2_size);
3428 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3429 : bin_str2, bin_str2_size,
3430 : response_handshake_secret, hash_size);
3431 0 : bin_str7_size = sizeof(bin_str7);
3432 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3433 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3434 0 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3435 : &bin_str7_size);
3436 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3437 : hash_size, bin_str7, bin_str7_size,
3438 : response_finished_key, hash_size);
3439 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3440 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3441 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3442 : response_finished_key, hash_size, ptr);
3443 0 : ptr += hmac_size;
3444 :
3445 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3446 : false, spdm_response_size,
3447 : spdm_response, response_size,
3448 : response);
3449 : }
3450 0 : return LIBSPDM_STATUS_SUCCESS;
3451 :
3452 1 : case 0x1A: {
3453 : spdm_key_exchange_response_t *spdm_response;
3454 : size_t dhe_key_size;
3455 : uint32_t hash_size;
3456 : size_t signature_size;
3457 : uint32_t hmac_size;
3458 : uint8_t *ptr;
3459 : void *dhe_context;
3460 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
3461 : size_t final_key_size;
3462 : size_t opaque_key_exchange_rsp_size;
3463 : void *data;
3464 : size_t data_size;
3465 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3466 : uint8_t *cert_buffer;
3467 : size_t cert_buffer_size;
3468 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3469 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3470 : uint8_t bin_str0[128];
3471 : size_t bin_str0_size;
3472 : uint8_t bin_str2[128];
3473 : size_t bin_str2_size;
3474 : uint8_t bin_str7[128];
3475 : size_t bin_str7_size;
3476 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3477 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3478 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3479 : size_t spdm_response_size;
3480 : size_t transport_header_size;
3481 :
3482 : ((libspdm_context_t *)spdm_context)
3483 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3484 : ((libspdm_context_t *)spdm_context)
3485 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3486 : ((libspdm_context_t *)spdm_context)
3487 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3488 : ((libspdm_context_t *)spdm_context)
3489 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
3490 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3491 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3492 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3493 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3494 1 : opaque_key_exchange_rsp_size =
3495 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
3496 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3497 1 : dhe_key_size + 0 + sizeof(uint16_t) +
3498 1 : opaque_key_exchange_rsp_size + signature_size +
3499 : hmac_size;
3500 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3501 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3502 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
3503 :
3504 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3505 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
3506 1 : spdm_response->header.param1 = 0;
3507 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
3508 : /* Illegal combination. At most one bit can be set. */
3509 1 : spdm_response->mut_auth_requested =
3510 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED |
3511 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
3512 1 : spdm_response->req_slot_id_param = 0xF;
3513 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
3514 1 : ptr = (void *)(spdm_response + 1);
3515 1 : dhe_context = libspdm_dhe_new(
3516 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3517 : m_libspdm_use_dhe_algo,
3518 : true);
3519 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
3520 1 : final_key_size = sizeof(final_key);
3521 1 : libspdm_dhe_compute_key(
3522 : m_libspdm_use_dhe_algo, dhe_context,
3523 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
3524 : sizeof(spdm_key_exchange_request_t),
3525 : dhe_key_size, final_key, &final_key_size);
3526 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3527 1 : ptr += dhe_key_size;
3528 : /* libspdm_zero_mem (ptr, hash_size);
3529 : * ptr += hash_size;*/
3530 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3531 1 : ptr += sizeof(uint16_t);
3532 1 : libspdm_build_opaque_data_version_selection_data(
3533 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
3534 : &opaque_key_exchange_rsp_size, ptr);
3535 1 : ptr += opaque_key_exchange_rsp_size;
3536 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3537 : m_libspdm_use_asym_algo, &data,
3538 : &data_size, NULL, NULL);
3539 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3540 : sizeof(m_libspdm_local_buffer)
3541 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3542 : m_libspdm_local_buffer),
3543 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3544 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3545 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3546 : m_libspdm_local_buffer_size));
3547 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3548 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3549 1 : cert_buffer = (uint8_t *)data;
3550 1 : cert_buffer_size = data_size;
3551 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
3552 : /* transcript.message_a size is 0*/
3553 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3554 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3555 : m_libspdm_local_buffer_size);
3556 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3557 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3558 1 : free(data);
3559 1 : libspdm_responder_data_sign(
3560 : spdm_context,
3561 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3562 : 0, SPDM_KEY_EXCHANGE_RSP,
3563 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
3564 1 : false, libspdm_get_managed_buffer(&th_curr),
3565 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3566 : &signature_size);
3567 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3568 : sizeof(m_libspdm_local_buffer)
3569 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3570 : m_libspdm_local_buffer),
3571 : ptr, signature_size);
3572 1 : m_libspdm_local_buffer_size += signature_size;
3573 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3574 1 : ptr += signature_size;
3575 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3576 : libspdm_get_managed_buffer_size(&th_curr),
3577 : th_curr_hash_data);
3578 1 : bin_str0_size = sizeof(bin_str0);
3579 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3580 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3581 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3582 : &bin_str0_size);
3583 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3584 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3585 1 : bin_str2_size = sizeof(bin_str2);
3586 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3587 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3588 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3589 : bin_str2, &bin_str2_size);
3590 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3591 : bin_str2, bin_str2_size,
3592 : response_handshake_secret, hash_size);
3593 1 : bin_str7_size = sizeof(bin_str7);
3594 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3595 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3596 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3597 : &bin_str7_size);
3598 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3599 : hash_size, bin_str7, bin_str7_size,
3600 : response_finished_key, hash_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), hash_data);
3603 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3604 : response_finished_key, hash_size, ptr);
3605 1 : ptr += hmac_size;
3606 :
3607 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3608 : false, spdm_response_size,
3609 : spdm_response, response_size,
3610 : response);
3611 : }
3612 1 : return LIBSPDM_STATUS_SUCCESS;
3613 :
3614 1 : case 0x1B: {
3615 : spdm_key_exchange_response_t *spdm_response;
3616 : size_t dhe_key_size;
3617 : uint32_t hash_size;
3618 : size_t signature_size;
3619 : uint32_t hmac_size;
3620 : uint8_t *ptr;
3621 : void *dhe_context;
3622 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
3623 : size_t final_key_size;
3624 : size_t opaque_key_exchange_rsp_size;
3625 : void *data;
3626 : size_t data_size;
3627 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3628 : uint8_t *cert_buffer;
3629 : size_t cert_buffer_size;
3630 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3631 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3632 : uint8_t bin_str0[128];
3633 : size_t bin_str0_size;
3634 : uint8_t bin_str2[128];
3635 : size_t bin_str2_size;
3636 : uint8_t bin_str7[128];
3637 : size_t bin_str7_size;
3638 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3639 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3640 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3641 : size_t spdm_response_size;
3642 : size_t transport_header_size;
3643 :
3644 : ((libspdm_context_t *)spdm_context)
3645 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3646 : ((libspdm_context_t *)spdm_context)
3647 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3648 : ((libspdm_context_t *)spdm_context)
3649 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3650 : ((libspdm_context_t *)spdm_context)
3651 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
3652 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3653 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3654 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3655 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3656 1 : opaque_key_exchange_rsp_size =
3657 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
3658 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3659 1 : dhe_key_size + 0 + sizeof(uint16_t) +
3660 1 : opaque_key_exchange_rsp_size + signature_size +
3661 : hmac_size;
3662 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3663 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3664 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
3665 :
3666 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3667 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
3668 1 : spdm_response->header.param1 = 0;
3669 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
3670 : /* Illegal combination. At most one bit can be set. */
3671 1 : spdm_response->mut_auth_requested =
3672 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED |
3673 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
3674 1 : spdm_response->req_slot_id_param = 0xF;
3675 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
3676 1 : ptr = (void *)(spdm_response + 1);
3677 1 : dhe_context = libspdm_dhe_new(
3678 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3679 : m_libspdm_use_dhe_algo,
3680 : true);
3681 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
3682 1 : final_key_size = sizeof(final_key);
3683 1 : libspdm_dhe_compute_key(
3684 : m_libspdm_use_dhe_algo, dhe_context,
3685 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
3686 : sizeof(spdm_key_exchange_request_t),
3687 : dhe_key_size, final_key, &final_key_size);
3688 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3689 1 : ptr += dhe_key_size;
3690 : /* libspdm_zero_mem (ptr, hash_size);
3691 : * ptr += hash_size;*/
3692 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3693 1 : ptr += sizeof(uint16_t);
3694 1 : libspdm_build_opaque_data_version_selection_data(
3695 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
3696 : &opaque_key_exchange_rsp_size, ptr);
3697 1 : ptr += opaque_key_exchange_rsp_size;
3698 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3699 : m_libspdm_use_asym_algo, &data,
3700 : &data_size, NULL, NULL);
3701 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3702 : sizeof(m_libspdm_local_buffer)
3703 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3704 : m_libspdm_local_buffer),
3705 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3706 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3707 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3708 : m_libspdm_local_buffer_size));
3709 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3710 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3711 1 : cert_buffer = (uint8_t *)data;
3712 1 : cert_buffer_size = data_size;
3713 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
3714 : /* transcript.message_a size is 0*/
3715 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3716 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3717 : m_libspdm_local_buffer_size);
3718 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3719 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3720 1 : free(data);
3721 1 : libspdm_responder_data_sign(
3722 : spdm_context,
3723 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3724 : 0, SPDM_KEY_EXCHANGE_RSP,
3725 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
3726 1 : false, libspdm_get_managed_buffer(&th_curr),
3727 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3728 : &signature_size);
3729 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3730 : sizeof(m_libspdm_local_buffer)
3731 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3732 : m_libspdm_local_buffer),
3733 : ptr, signature_size);
3734 1 : m_libspdm_local_buffer_size += signature_size;
3735 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3736 1 : ptr += signature_size;
3737 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3738 : libspdm_get_managed_buffer_size(&th_curr),
3739 : th_curr_hash_data);
3740 1 : bin_str0_size = sizeof(bin_str0);
3741 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3742 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3743 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3744 : &bin_str0_size);
3745 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3746 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3747 1 : bin_str2_size = sizeof(bin_str2);
3748 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3749 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3750 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3751 : bin_str2, &bin_str2_size);
3752 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3753 : bin_str2, bin_str2_size,
3754 : response_handshake_secret, hash_size);
3755 1 : bin_str7_size = sizeof(bin_str7);
3756 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3757 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3758 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3759 : &bin_str7_size);
3760 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3761 : hash_size, bin_str7, bin_str7_size,
3762 : response_finished_key, hash_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), hash_data);
3765 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3766 : response_finished_key, hash_size, ptr);
3767 1 : ptr += hmac_size;
3768 :
3769 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3770 : false, spdm_response_size,
3771 : spdm_response, response_size,
3772 : response);
3773 : }
3774 1 : return LIBSPDM_STATUS_SUCCESS;
3775 :
3776 1 : case 0x1C: {
3777 : spdm_key_exchange_response_t *spdm_response;
3778 : size_t dhe_key_size;
3779 : uint32_t hash_size;
3780 : size_t signature_size;
3781 : uint32_t hmac_size;
3782 : uint8_t *ptr;
3783 : void *dhe_context;
3784 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
3785 : size_t final_key_size;
3786 : size_t opaque_key_exchange_rsp_size;
3787 : void *data;
3788 : size_t data_size;
3789 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3790 : uint8_t *cert_buffer;
3791 : size_t cert_buffer_size;
3792 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3793 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3794 : uint8_t bin_str0[128];
3795 : size_t bin_str0_size;
3796 : uint8_t bin_str2[128];
3797 : size_t bin_str2_size;
3798 : uint8_t bin_str7[128];
3799 : size_t bin_str7_size;
3800 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3801 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3802 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3803 : size_t spdm_response_size;
3804 : size_t transport_header_size;
3805 :
3806 : ((libspdm_context_t *)spdm_context)
3807 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3808 : ((libspdm_context_t *)spdm_context)
3809 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3810 : ((libspdm_context_t *)spdm_context)
3811 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3812 : ((libspdm_context_t *)spdm_context)
3813 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
3814 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3815 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3816 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3817 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3818 1 : opaque_key_exchange_rsp_size =
3819 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
3820 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3821 1 : dhe_key_size + 0 + sizeof(uint16_t) +
3822 1 : opaque_key_exchange_rsp_size + signature_size +
3823 : hmac_size;
3824 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3825 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3826 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
3827 :
3828 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3829 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
3830 1 : spdm_response->header.param1 = 0;
3831 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
3832 : /* Illegal combination. At most one bit can be set. */
3833 1 : spdm_response->mut_auth_requested =
3834 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST |
3835 : SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
3836 1 : spdm_response->req_slot_id_param = 0xF;
3837 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
3838 1 : ptr = (void *)(spdm_response + 1);
3839 1 : dhe_context = libspdm_dhe_new(
3840 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3841 : m_libspdm_use_dhe_algo,
3842 : true);
3843 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
3844 1 : final_key_size = sizeof(final_key);
3845 1 : libspdm_dhe_compute_key(
3846 : m_libspdm_use_dhe_algo, dhe_context,
3847 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
3848 : sizeof(spdm_key_exchange_request_t),
3849 : dhe_key_size, final_key, &final_key_size);
3850 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
3851 1 : ptr += dhe_key_size;
3852 : /* libspdm_zero_mem (ptr, hash_size);
3853 : * ptr += hash_size;*/
3854 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
3855 1 : ptr += sizeof(uint16_t);
3856 1 : libspdm_build_opaque_data_version_selection_data(
3857 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
3858 : &opaque_key_exchange_rsp_size, ptr);
3859 1 : ptr += opaque_key_exchange_rsp_size;
3860 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3861 : m_libspdm_use_asym_algo, &data,
3862 : &data_size, NULL, NULL);
3863 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3864 : sizeof(m_libspdm_local_buffer)
3865 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3866 : m_libspdm_local_buffer),
3867 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3868 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3869 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3870 : m_libspdm_local_buffer_size));
3871 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3872 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3873 1 : cert_buffer = (uint8_t *)data;
3874 1 : cert_buffer_size = data_size;
3875 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
3876 : /* transcript.message_a size is 0*/
3877 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
3878 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3879 : m_libspdm_local_buffer_size);
3880 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3881 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3882 1 : free(data);
3883 1 : libspdm_responder_data_sign(
3884 : spdm_context,
3885 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3886 : 0, SPDM_KEY_EXCHANGE_RSP,
3887 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
3888 1 : false, libspdm_get_managed_buffer(&th_curr),
3889 : libspdm_get_managed_buffer_size(&th_curr), ptr,
3890 : &signature_size);
3891 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3892 : sizeof(m_libspdm_local_buffer)
3893 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3894 : m_libspdm_local_buffer),
3895 : ptr, signature_size);
3896 1 : m_libspdm_local_buffer_size += signature_size;
3897 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
3898 1 : ptr += signature_size;
3899 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3900 : libspdm_get_managed_buffer_size(&th_curr),
3901 : th_curr_hash_data);
3902 1 : bin_str0_size = sizeof(bin_str0);
3903 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3904 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
3905 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
3906 : &bin_str0_size);
3907 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
3908 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
3909 1 : bin_str2_size = sizeof(bin_str2);
3910 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3911 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
3912 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
3913 : bin_str2, &bin_str2_size);
3914 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
3915 : bin_str2, bin_str2_size,
3916 : response_handshake_secret, hash_size);
3917 1 : bin_str7_size = sizeof(bin_str7);
3918 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3919 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
3920 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3921 : &bin_str7_size);
3922 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3923 : hash_size, bin_str7, bin_str7_size,
3924 : response_finished_key, hash_size);
3925 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3926 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3927 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3928 : response_finished_key, hash_size, ptr);
3929 1 : ptr += hmac_size;
3930 :
3931 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3932 : false, spdm_response_size,
3933 : spdm_response, response_size,
3934 : response);
3935 : }
3936 1 : return LIBSPDM_STATUS_SUCCESS;
3937 :
3938 0 : case 0x1D: {
3939 : spdm_key_exchange_response_t *spdm_response;
3940 : size_t dhe_key_size;
3941 : uint32_t hash_size;
3942 : size_t signature_size;
3943 : uint32_t hmac_size;
3944 : uint8_t *ptr;
3945 : void *dhe_context;
3946 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
3947 : size_t final_key_size;
3948 : size_t opaque_key_exchange_rsp_size;
3949 : void *data;
3950 : size_t data_size;
3951 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
3952 : uint8_t *cert_buffer;
3953 : size_t cert_buffer_size;
3954 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
3955 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
3956 : uint8_t bin_str0[128];
3957 : size_t bin_str0_size;
3958 : uint8_t bin_str2[128];
3959 : size_t bin_str2_size;
3960 : uint8_t bin_str7[128];
3961 : size_t bin_str7_size;
3962 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3963 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3964 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3965 : size_t spdm_response_size;
3966 : size_t transport_header_size;
3967 :
3968 0 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_asym_algo =
3969 : m_libspdm_use_asym_algo;
3970 0 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
3971 : m_libspdm_use_hash_algo;
3972 0 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.dhe_named_group =
3973 : m_libspdm_use_dhe_algo;
3974 0 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
3975 : m_libspdm_use_measurement_hash_algo;
3976 0 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
3977 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3978 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3979 0 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
3980 0 : opaque_key_exchange_rsp_size =
3981 0 : libspdm_get_opaque_data_version_selection_data_size(spdm_context);
3982 0 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
3983 0 : dhe_key_size + 0 + sizeof(uint16_t) +
3984 0 : opaque_key_exchange_rsp_size + signature_size +
3985 : hmac_size;
3986 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3987 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3988 :
3989 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
3990 0 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
3991 0 : spdm_response->header.param1 = 0;
3992 0 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
3993 0 : spdm_response->mut_auth_requested = 0;
3994 0 : spdm_response->req_slot_id_param = 0;
3995 0 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
3996 0 : ptr = (void *)(spdm_response + 1);
3997 0 : dhe_context = libspdm_dhe_new(
3998 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3999 : m_libspdm_use_dhe_algo, true);
4000 0 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
4001 0 : final_key_size = sizeof(final_key);
4002 0 : libspdm_dhe_compute_key(
4003 : m_libspdm_use_dhe_algo, dhe_context,
4004 0 : (uint8_t *)&m_libspdm_local_buffer[0] + sizeof(spdm_key_exchange_request_t),
4005 : dhe_key_size, final_key, &final_key_size);
4006 0 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
4007 0 : ptr += dhe_key_size;
4008 : /* libspdm_zero_mem (ptr, hash_size);
4009 : * ptr += hash_size;*/
4010 0 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
4011 0 : ptr += sizeof(uint16_t);
4012 0 : libspdm_build_opaque_data_version_selection_data(
4013 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
4014 : &opaque_key_exchange_rsp_size, ptr);
4015 0 : ptr += opaque_key_exchange_rsp_size;
4016 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4017 : m_libspdm_use_asym_algo, &data,
4018 : &data_size, NULL, NULL);
4019 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4020 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
4021 0 : spdm_response, (size_t)ptr - (size_t)spdm_response);
4022 0 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
4023 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
4024 : m_libspdm_local_buffer_size));
4025 0 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
4026 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
4027 0 : cert_buffer = (uint8_t *)data;
4028 0 : cert_buffer_size = data_size;
4029 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
4030 : /* transcript.message_a size is 0*/
4031 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
4032 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
4033 : m_libspdm_local_buffer_size);
4034 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4035 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4036 0 : free(data);
4037 0 : libspdm_responder_data_sign(
4038 : spdm_context,
4039 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4040 : 0, SPDM_KEY_EXCHANGE_RSP,
4041 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
4042 0 : false, libspdm_get_managed_buffer(&th_curr),
4043 : libspdm_get_managed_buffer_size(&th_curr), ptr, &signature_size);
4044 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4045 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
4046 : ptr, signature_size);
4047 0 : m_libspdm_local_buffer_size += signature_size;
4048 0 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
4049 0 : ptr += signature_size;
4050 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4051 : libspdm_get_managed_buffer_size(&th_curr), th_curr_hash_data);
4052 0 : bin_str0_size = sizeof(bin_str0);
4053 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4054 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
4055 0 : NULL, (uint16_t)hash_size, hash_size, bin_str0, &bin_str0_size);
4056 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
4057 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
4058 0 : bin_str2_size = sizeof(bin_str2);
4059 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4060 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
4061 0 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
4062 : bin_str2, &bin_str2_size);
4063 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
4064 : bin_str2, bin_str2_size,
4065 : response_handshake_secret, hash_size);
4066 0 : bin_str7_size = sizeof(bin_str7);
4067 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4068 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
4069 0 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
4070 : &bin_str7_size);
4071 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
4072 : hash_size, bin_str7, bin_str7_size,
4073 : response_finished_key, hash_size);
4074 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4075 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4076 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
4077 : response_finished_key, hash_size, ptr);
4078 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4079 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
4080 : ptr, hmac_size);
4081 0 : m_libspdm_local_buffer_size += hmac_size;
4082 0 : ptr += hmac_size;
4083 :
4084 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
4085 : false, spdm_response_size,
4086 : spdm_response, response_size,
4087 : response);
4088 : }
4089 0 : return LIBSPDM_STATUS_SUCCESS;
4090 0 : case 0x1E: {
4091 : spdm_key_exchange_response_t *spdm_response;
4092 : size_t dhe_key_size;
4093 : uint32_t hash_size;
4094 : size_t signature_size;
4095 : uint32_t hmac_size;
4096 : uint8_t *ptr;
4097 : void *dhe_context;
4098 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
4099 : size_t final_key_size;
4100 : size_t opaque_key_exchange_rsp_size;
4101 : void *data;
4102 : size_t data_size;
4103 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
4104 : uint8_t *cert_buffer;
4105 : size_t cert_buffer_size;
4106 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
4107 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
4108 : uint8_t bin_str0[128];
4109 : size_t bin_str0_size;
4110 : uint8_t bin_str2[128];
4111 : size_t bin_str2_size;
4112 : uint8_t bin_str7[128];
4113 : size_t bin_str7_size;
4114 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4115 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4116 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
4117 : size_t spdm_response_size;
4118 : size_t transport_header_size;
4119 :
4120 :
4121 : ((libspdm_context_t *)spdm_context)
4122 0 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4123 : ((libspdm_context_t *)spdm_context)
4124 0 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4125 : ((libspdm_context_t *)spdm_context)
4126 0 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4127 : ((libspdm_context_t *)spdm_context)
4128 0 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
4129 0 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
4130 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4131 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4132 0 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
4133 0 : opaque_key_exchange_rsp_size =
4134 0 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
4135 0 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
4136 0 : dhe_key_size + 0 + sizeof(uint16_t) +
4137 0 : opaque_key_exchange_rsp_size + signature_size +
4138 : hmac_size;
4139 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
4140 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
4141 :
4142 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
4143 0 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
4144 0 : spdm_response->header.param1 = 0;
4145 0 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
4146 0 : spdm_response->mut_auth_requested = 0;
4147 0 : spdm_response->req_slot_id_param = 0;
4148 0 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
4149 0 : ptr = (void *)(spdm_response + 1);
4150 0 : dhe_context = libspdm_dhe_new(
4151 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4152 : m_libspdm_use_dhe_algo,
4153 : true);
4154 0 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
4155 0 : final_key_size = sizeof(final_key);
4156 0 : libspdm_dhe_compute_key(
4157 : m_libspdm_use_dhe_algo, dhe_context,
4158 0 : (uint8_t *)&m_libspdm_local_buffer[0] +
4159 : sizeof(spdm_key_exchange_request_t),
4160 : dhe_key_size, final_key, &final_key_size);
4161 0 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
4162 0 : ptr += dhe_key_size;
4163 : /* libspdm_zero_mem (ptr, hash_size);
4164 : * ptr += hash_size;*/
4165 0 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
4166 0 : ptr += sizeof(uint16_t);
4167 0 : libspdm_build_opaque_data_version_selection_data(
4168 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
4169 : &opaque_key_exchange_rsp_size, ptr);
4170 0 : ptr += opaque_key_exchange_rsp_size;
4171 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4172 : m_libspdm_use_asym_algo, &data,
4173 : &data_size, NULL, NULL);
4174 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4175 : sizeof(m_libspdm_local_buffer)
4176 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4177 : m_libspdm_local_buffer),
4178 0 : spdm_response, (size_t)ptr - (size_t)spdm_response);
4179 0 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
4180 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
4181 : m_libspdm_local_buffer_size));
4182 0 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
4183 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
4184 0 : cert_buffer = (uint8_t *)data;
4185 0 : cert_buffer_size = data_size;
4186 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
4187 : /* transcript.message_a size is 0*/
4188 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
4189 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
4190 : m_libspdm_local_buffer_size);
4191 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4192 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4193 0 : free(data);
4194 0 : libspdm_responder_data_sign(
4195 : spdm_context,
4196 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4197 : 0, SPDM_KEY_EXCHANGE_RSP,
4198 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
4199 0 : false, libspdm_get_managed_buffer(&th_curr),
4200 : libspdm_get_managed_buffer_size(&th_curr), ptr,
4201 : &signature_size);
4202 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4203 : sizeof(m_libspdm_local_buffer)
4204 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4205 : m_libspdm_local_buffer),
4206 : ptr, signature_size);
4207 0 : m_libspdm_local_buffer_size += signature_size;
4208 0 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
4209 0 : ptr += signature_size;
4210 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4211 : libspdm_get_managed_buffer_size(&th_curr),
4212 : th_curr_hash_data);
4213 0 : bin_str0_size = sizeof(bin_str0);
4214 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4215 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
4216 0 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
4217 : &bin_str0_size);
4218 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
4219 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
4220 0 : bin_str2_size = sizeof(bin_str2);
4221 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4222 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
4223 0 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
4224 : bin_str2, &bin_str2_size);
4225 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
4226 : bin_str2, bin_str2_size,
4227 : response_handshake_secret, hash_size);
4228 0 : bin_str7_size = sizeof(bin_str7);
4229 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4230 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
4231 0 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
4232 : &bin_str7_size);
4233 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
4234 : hash_size, bin_str7, bin_str7_size,
4235 : response_finished_key, hash_size);
4236 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4237 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4238 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
4239 : response_finished_key, hash_size, ptr);
4240 0 : ptr += hmac_size;
4241 :
4242 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
4243 : false, spdm_response_size,
4244 : spdm_response, response_size,
4245 : response);
4246 : }
4247 0 : return LIBSPDM_STATUS_SUCCESS;
4248 :
4249 1 : case 0x1F: {
4250 : spdm_key_exchange_response_t *spdm_response;
4251 : size_t dhe_key_size;
4252 : uint32_t hash_size;
4253 : size_t signature_size;
4254 : uint32_t hmac_size;
4255 : uint8_t *ptr;
4256 : void *dhe_context;
4257 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
4258 : size_t final_key_size;
4259 : size_t opaque_key_exchange_rsp_size;
4260 : void *data;
4261 : size_t data_size;
4262 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
4263 : uint8_t *cert_buffer;
4264 : size_t cert_buffer_size;
4265 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
4266 : uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
4267 : uint8_t bin_str0[128];
4268 : size_t bin_str0_size;
4269 : uint8_t bin_str2[128];
4270 : size_t bin_str2_size;
4271 : uint8_t bin_str7[128];
4272 : size_t bin_str7_size;
4273 : uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4274 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
4275 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
4276 : size_t spdm_response_size;
4277 : size_t transport_header_size;
4278 :
4279 : ((libspdm_context_t *)spdm_context)
4280 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4281 : ((libspdm_context_t *)spdm_context)
4282 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4283 : ((libspdm_context_t *)spdm_context)
4284 1 : ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4285 : ((libspdm_context_t *)spdm_context)
4286 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
4287 1 : signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
4288 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4289 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
4290 1 : dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
4291 1 : opaque_key_exchange_rsp_size =
4292 1 : libspdm_get_opaque_data_version_selection_data_size( spdm_context);
4293 1 : spdm_response_size = sizeof(spdm_key_exchange_response_t) +
4294 1 : dhe_key_size + 0 + sizeof(uint16_t) +
4295 1 : opaque_key_exchange_rsp_size + signature_size +
4296 : hmac_size;
4297 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
4298 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
4299 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
4300 :
4301 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
4302 1 : spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
4303 1 : spdm_response->header.param1 = 0;
4304 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
4305 1 : spdm_response->mut_auth_requested = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
4306 1 : spdm_response->req_slot_id_param = 9; /* Invalid SlotID */
4307 1 : libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
4308 1 : ptr = (void *)(spdm_response + 1);
4309 1 : dhe_context = libspdm_dhe_new(
4310 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4311 : m_libspdm_use_dhe_algo,
4312 : true);
4313 1 : libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
4314 1 : final_key_size = sizeof(final_key);
4315 1 : libspdm_dhe_compute_key(
4316 : m_libspdm_use_dhe_algo, dhe_context,
4317 1 : (uint8_t *)&m_libspdm_local_buffer[0] +
4318 : sizeof(spdm_key_exchange_request_t),
4319 : dhe_key_size, final_key, &final_key_size);
4320 1 : libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
4321 1 : ptr += dhe_key_size;
4322 : /* libspdm_zero_mem (ptr, hash_size);
4323 : * ptr += hash_size;*/
4324 1 : *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
4325 1 : ptr += sizeof(uint16_t);
4326 1 : libspdm_build_opaque_data_version_selection_data(
4327 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
4328 : &opaque_key_exchange_rsp_size, ptr);
4329 1 : ptr += opaque_key_exchange_rsp_size;
4330 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4331 : m_libspdm_use_asym_algo, &data,
4332 : &data_size, NULL, NULL);
4333 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4334 : sizeof(m_libspdm_local_buffer)
4335 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4336 : m_libspdm_local_buffer),
4337 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
4338 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
4339 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
4340 : m_libspdm_local_buffer_size));
4341 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
4342 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
4343 1 : cert_buffer = (uint8_t *)data;
4344 1 : cert_buffer_size = data_size;
4345 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
4346 : /* transcript.message_a size is 0*/
4347 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
4348 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
4349 : m_libspdm_local_buffer_size);
4350 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4351 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4352 1 : free(data);
4353 1 : libspdm_responder_data_sign(
4354 : spdm_context,
4355 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
4356 : 0, SPDM_KEY_EXCHANGE_RSP,
4357 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
4358 1 : false, libspdm_get_managed_buffer(&th_curr),
4359 : libspdm_get_managed_buffer_size(&th_curr), ptr,
4360 : &signature_size);
4361 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
4362 : sizeof(m_libspdm_local_buffer)
4363 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
4364 : m_libspdm_local_buffer),
4365 : ptr, signature_size);
4366 1 : m_libspdm_local_buffer_size += signature_size;
4367 1 : libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
4368 1 : ptr += signature_size;
4369 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4370 : libspdm_get_managed_buffer_size(&th_curr),
4371 : th_curr_hash_data);
4372 1 : bin_str0_size = sizeof(bin_str0);
4373 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4374 : SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
4375 1 : NULL, (uint16_t)hash_size, hash_size, bin_str0,
4376 : &bin_str0_size);
4377 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
4378 : m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
4379 1 : bin_str2_size = sizeof(bin_str2);
4380 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4381 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
4382 1 : th_curr_hash_data, (uint16_t)hash_size, hash_size,
4383 : bin_str2, &bin_str2_size);
4384 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
4385 : bin_str2, bin_str2_size,
4386 : response_handshake_secret, hash_size);
4387 1 : bin_str7_size = sizeof(bin_str7);
4388 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
4389 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
4390 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
4391 : &bin_str7_size);
4392 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
4393 : hash_size, bin_str7, bin_str7_size,
4394 : response_finished_key, hash_size);
4395 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
4396 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
4397 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
4398 : response_finished_key, hash_size, ptr);
4399 1 : ptr += hmac_size;
4400 :
4401 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
4402 : false, spdm_response_size,
4403 : spdm_response, response_size,
4404 : response);
4405 : }
4406 1 : return LIBSPDM_STATUS_SUCCESS;
4407 :
4408 0 : default:
4409 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
4410 : }
4411 : }
4412 :
4413 1 : static void libspdm_test_requester_key_exchange_err_case1(void **state)
4414 : {
4415 : libspdm_return_t status;
4416 : libspdm_test_context_t *spdm_test_context;
4417 : libspdm_context_t *spdm_context;
4418 : uint32_t session_id;
4419 : uint8_t heartbeat_period;
4420 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4421 : uint8_t slot_id_param;
4422 : void *data;
4423 : size_t data_size;
4424 : void *hash;
4425 : size_t hash_size;
4426 :
4427 1 : spdm_test_context = *state;
4428 1 : spdm_context = spdm_test_context->spdm_context;
4429 1 : spdm_test_context->case_id = 0x1;
4430 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4431 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4432 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4433 1 : spdm_context->connection_info.capability.flags |=
4434 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
4435 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
4436 1 : spdm_context->local_context.capability.flags |=
4437 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
4438 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
4439 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4440 : m_libspdm_use_asym_algo, &data,
4441 : &data_size, &hash, &hash_size)) {
4442 0 : assert(false);
4443 : }
4444 1 : libspdm_reset_message_a(spdm_context);
4445 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4446 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4447 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4448 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
4449 :
4450 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4451 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4452 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4453 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4454 : data, data_size);
4455 : #else
4456 1 : libspdm_hash_all(
4457 : spdm_context->connection_info.algorithm.base_hash_algo,
4458 : data, data_size,
4459 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4460 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4461 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4462 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4463 : spdm_context->connection_info.algorithm.base_hash_algo,
4464 : spdm_context->connection_info.algorithm.base_asym_algo,
4465 : data, data_size,
4466 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4467 : #endif
4468 :
4469 1 : heartbeat_period = 0;
4470 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4471 1 : status = libspdm_send_receive_key_exchange(
4472 : spdm_context,
4473 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
4474 : &session_id, &heartbeat_period, &slot_id_param,
4475 : measurement_hash);
4476 1 : assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
4477 1 : free(data);
4478 1 : }
4479 :
4480 1 : static void libspdm_test_requester_key_exchange_err_case2(void **state)
4481 : {
4482 : libspdm_return_t status;
4483 : libspdm_test_context_t *spdm_test_context;
4484 : libspdm_context_t *spdm_context;
4485 : uint32_t session_id;
4486 : uint8_t heartbeat_period;
4487 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4488 : uint8_t slot_id_param;
4489 : void *data;
4490 : size_t data_size;
4491 : void *hash;
4492 : size_t hash_size;
4493 :
4494 1 : spdm_test_context = *state;
4495 1 : spdm_context = spdm_test_context->spdm_context;
4496 1 : spdm_test_context->case_id = 0x2;
4497 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4498 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4499 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4500 1 : spdm_context->connection_info.capability.flags |=
4501 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
4502 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
4503 1 : spdm_context->local_context.capability.flags |=
4504 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
4505 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
4506 1 : spdm_context->local_context.secured_message_version.secured_message_version_count = 1;
4507 1 : spdm_context->local_context.secured_message_version.secured_message_version[0] =
4508 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4509 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4510 : m_libspdm_use_asym_algo, &data,
4511 : &data_size, &hash, &hash_size)) {
4512 0 : assert(false);
4513 : }
4514 1 : libspdm_reset_message_a(spdm_context);
4515 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4516 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4517 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4518 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
4519 :
4520 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4521 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4522 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4523 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4524 : data, data_size);
4525 : #else
4526 1 : libspdm_hash_all(
4527 : spdm_context->connection_info.algorithm.base_hash_algo,
4528 : data, data_size,
4529 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4530 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4531 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4532 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4533 : spdm_context->connection_info.algorithm.base_hash_algo,
4534 : spdm_context->connection_info.algorithm.base_asym_algo,
4535 : data, data_size,
4536 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4537 : #endif
4538 :
4539 1 : heartbeat_period = 0;
4540 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4541 1 : status = libspdm_send_receive_key_exchange(
4542 : spdm_context,
4543 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
4544 : &session_id, &heartbeat_period, &slot_id_param,
4545 : measurement_hash);
4546 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4547 1 : assert_int_equal(session_id, 0xFFFFFFFF);
4548 1 : assert_int_equal(
4549 : libspdm_secured_message_get_session_state(
4550 : spdm_context->session_info[0].secured_message_context),
4551 : LIBSPDM_SESSION_STATE_HANDSHAKING);
4552 1 : free(data);
4553 1 : }
4554 :
4555 1 : static void libspdm_test_requester_key_exchange_err_case3(void **state)
4556 : {
4557 : libspdm_return_t status;
4558 : libspdm_test_context_t *spdm_test_context;
4559 : libspdm_context_t *spdm_context;
4560 : uint32_t session_id;
4561 : uint8_t heartbeat_period;
4562 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4563 : uint8_t slot_id_param;
4564 : void *data;
4565 : size_t data_size;
4566 : void *hash;
4567 : size_t hash_size;
4568 :
4569 1 : spdm_test_context = *state;
4570 1 : spdm_context = spdm_test_context->spdm_context;
4571 1 : spdm_test_context->case_id = 0x3;
4572 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4573 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4574 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
4575 1 : spdm_context->connection_info.capability.flags |=
4576 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
4577 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
4578 1 : spdm_context->local_context.capability.flags |=
4579 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
4580 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
4581 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4582 : m_libspdm_use_asym_algo, &data,
4583 : &data_size, &hash, &hash_size)) {
4584 0 : assert(false);
4585 : }
4586 1 : libspdm_reset_message_a(spdm_context);
4587 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4588 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4589 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4590 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
4591 :
4592 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4593 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4594 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4595 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4596 : data, data_size);
4597 : #else
4598 1 : libspdm_hash_all(
4599 : spdm_context->connection_info.algorithm.base_hash_algo,
4600 : data, data_size,
4601 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4602 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4603 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4604 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4605 : spdm_context->connection_info.algorithm.base_hash_algo,
4606 : spdm_context->connection_info.algorithm.base_asym_algo,
4607 : data, data_size,
4608 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4609 : #endif
4610 :
4611 1 : heartbeat_period = 0;
4612 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4613 1 : status = libspdm_send_receive_key_exchange(
4614 : spdm_context,
4615 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
4616 : &session_id, &heartbeat_period, &slot_id_param,
4617 : measurement_hash);
4618 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
4619 1 : free(data);
4620 1 : }
4621 :
4622 1 : static void libspdm_test_requester_key_exchange_err_case4(void **state)
4623 : {
4624 : libspdm_return_t status;
4625 : libspdm_test_context_t *spdm_test_context;
4626 : libspdm_context_t *spdm_context;
4627 : uint32_t session_id;
4628 : uint8_t heartbeat_period;
4629 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4630 : uint8_t slot_id_param;
4631 : void *data;
4632 : size_t data_size;
4633 : void *hash;
4634 : size_t hash_size;
4635 :
4636 1 : spdm_test_context = *state;
4637 1 : spdm_context = spdm_test_context->spdm_context;
4638 1 : spdm_test_context->case_id = 0x4;
4639 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4640 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4641 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4642 1 : spdm_context->connection_info.capability.flags |=
4643 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
4644 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
4645 1 : spdm_context->local_context.capability.flags |=
4646 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
4647 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
4648 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4649 : m_libspdm_use_asym_algo, &data,
4650 : &data_size, &hash, &hash_size)) {
4651 0 : assert(false);
4652 : }
4653 1 : libspdm_reset_message_a(spdm_context);
4654 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4655 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4656 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4657 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
4658 :
4659 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4660 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4661 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4662 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4663 : data, data_size);
4664 : #else
4665 1 : libspdm_hash_all(
4666 : spdm_context->connection_info.algorithm.base_hash_algo,
4667 : data, data_size,
4668 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4669 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4670 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4671 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4672 : spdm_context->connection_info.algorithm.base_hash_algo,
4673 : spdm_context->connection_info.algorithm.base_asym_algo,
4674 : data, data_size,
4675 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4676 : #endif
4677 :
4678 1 : heartbeat_period = 0;
4679 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4680 1 : status = libspdm_send_receive_key_exchange(
4681 : spdm_context,
4682 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
4683 : &session_id, &heartbeat_period, &slot_id_param,
4684 : measurement_hash);
4685 1 : assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
4686 1 : free(data);
4687 1 : }
4688 :
4689 1 : static void libspdm_test_requester_key_exchange_err_case5(void **state)
4690 : {
4691 : libspdm_return_t status;
4692 : libspdm_test_context_t *spdm_test_context;
4693 : libspdm_context_t *spdm_context;
4694 : uint32_t session_id;
4695 : uint8_t heartbeat_period;
4696 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4697 : uint8_t slot_id_param;
4698 : void *data;
4699 : size_t data_size;
4700 : void *hash;
4701 : size_t hash_size;
4702 :
4703 1 : spdm_test_context = *state;
4704 1 : spdm_context = spdm_test_context->spdm_context;
4705 1 : spdm_test_context->case_id = 0x5;
4706 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4707 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4708 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4709 1 : spdm_context->connection_info.capability.flags |=
4710 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
4711 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
4712 1 : spdm_context->local_context.capability.flags |=
4713 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
4714 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
4715 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4716 : m_libspdm_use_asym_algo, &data,
4717 : &data_size, &hash, &hash_size)) {
4718 0 : assert(false);
4719 : }
4720 1 : libspdm_reset_message_a(spdm_context);
4721 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4722 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4723 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4724 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
4725 :
4726 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4727 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4728 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4729 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4730 : data, data_size);
4731 : #else
4732 1 : libspdm_hash_all(
4733 : spdm_context->connection_info.algorithm.base_hash_algo,
4734 : data, data_size,
4735 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4736 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4737 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4738 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4739 : spdm_context->connection_info.algorithm.base_hash_algo,
4740 : spdm_context->connection_info.algorithm.base_asym_algo,
4741 : data, data_size,
4742 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4743 : #endif
4744 :
4745 1 : heartbeat_period = 0;
4746 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4747 1 : status = libspdm_send_receive_key_exchange(
4748 : spdm_context,
4749 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
4750 : &session_id, &heartbeat_period, &slot_id_param,
4751 : measurement_hash);
4752 1 : assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
4753 1 : free(data);
4754 1 : }
4755 :
4756 : /**
4757 : * Test 6: Requester / Responder do not support key exchange.
4758 : * Expected Behavior: returns with error LIBSPDM_STATUS_UNSUPPORTED_CAP.
4759 : **/
4760 1 : static void libspdm_test_requester_key_exchange_err_case6(void **state)
4761 : {
4762 : libspdm_return_t status;
4763 : libspdm_test_context_t *spdm_test_context;
4764 : libspdm_context_t *spdm_context;
4765 : uint32_t session_id;
4766 : uint8_t slot_id_param;
4767 :
4768 1 : spdm_test_context = *state;
4769 1 : spdm_context = spdm_test_context->spdm_context;
4770 1 : spdm_test_context->case_id = 0x6;
4771 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4772 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4773 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4774 1 : spdm_context->connection_info.capability.flags = 0;
4775 1 : spdm_context->local_context.capability.flags = 0;
4776 :
4777 1 : status = libspdm_send_receive_key_exchange(
4778 : spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
4779 : &session_id, NULL, &slot_id_param, NULL);
4780 1 : assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
4781 1 : }
4782 :
4783 1 : static void libspdm_test_requester_key_exchange_err_case7(void **state)
4784 : {
4785 : libspdm_return_t status;
4786 : libspdm_test_context_t *spdm_test_context;
4787 : libspdm_context_t *spdm_context;
4788 : uint32_t session_id;
4789 : uint8_t heartbeat_period;
4790 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4791 : uint8_t slot_id_param;
4792 : void *data;
4793 : size_t data_size;
4794 : void *hash;
4795 : size_t hash_size;
4796 :
4797 1 : spdm_test_context = *state;
4798 1 : spdm_context = spdm_test_context->spdm_context;
4799 1 : spdm_test_context->case_id = 0x7;
4800 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4801 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4802 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4803 1 : spdm_context->connection_info.capability.flags |=
4804 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
4805 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
4806 1 : spdm_context->local_context.capability.flags |=
4807 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
4808 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
4809 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4810 : m_libspdm_use_asym_algo, &data,
4811 : &data_size, &hash, &hash_size)) {
4812 0 : assert(false);
4813 : }
4814 1 : libspdm_reset_message_a(spdm_context);
4815 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4816 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4817 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4818 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
4819 :
4820 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4821 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4822 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4823 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4824 : data, data_size);
4825 : #else
4826 1 : libspdm_hash_all(
4827 : spdm_context->connection_info.algorithm.base_hash_algo,
4828 : data, data_size,
4829 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4830 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4831 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4832 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4833 : spdm_context->connection_info.algorithm.base_hash_algo,
4834 : spdm_context->connection_info.algorithm.base_asym_algo,
4835 : data, data_size,
4836 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4837 : #endif
4838 :
4839 1 : heartbeat_period = 0;
4840 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4841 1 : status = libspdm_send_receive_key_exchange(
4842 : spdm_context,
4843 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
4844 : &session_id, &heartbeat_period, &slot_id_param,
4845 : measurement_hash);
4846 1 : assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
4847 1 : assert_int_equal(spdm_context->connection_info.connection_state,
4848 : LIBSPDM_CONNECTION_STATE_NOT_STARTED);
4849 1 : free(data);
4850 1 : }
4851 :
4852 1 : static void libspdm_test_requester_key_exchange_err_case8(void **state)
4853 : {
4854 : libspdm_return_t status;
4855 : libspdm_test_context_t *spdm_test_context;
4856 : libspdm_context_t *spdm_context;
4857 : uint32_t session_id;
4858 : uint8_t heartbeat_period;
4859 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4860 : uint8_t slot_id_param;
4861 : void *data;
4862 : size_t data_size;
4863 : void *hash;
4864 : size_t hash_size;
4865 :
4866 1 : spdm_test_context = *state;
4867 1 : spdm_context = spdm_test_context->spdm_context;
4868 1 : spdm_test_context->case_id = 0x8;
4869 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4870 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4871 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4872 1 : spdm_context->connection_info.capability.flags |=
4873 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
4874 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
4875 1 : spdm_context->local_context.capability.flags |=
4876 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
4877 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
4878 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4879 : m_libspdm_use_asym_algo, &data,
4880 : &data_size, &hash, &hash_size)) {
4881 0 : assert(false);
4882 : }
4883 1 : libspdm_reset_message_a(spdm_context);
4884 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4885 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4886 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4887 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
4888 :
4889 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4890 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4891 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4892 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4893 : data, data_size);
4894 : #else
4895 1 : libspdm_hash_all(
4896 : spdm_context->connection_info.algorithm.base_hash_algo,
4897 : data, data_size,
4898 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4899 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4900 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4901 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4902 : spdm_context->connection_info.algorithm.base_hash_algo,
4903 : spdm_context->connection_info.algorithm.base_asym_algo,
4904 : data, data_size,
4905 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4906 : #endif
4907 :
4908 1 : heartbeat_period = 0;
4909 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4910 1 : status = libspdm_send_receive_key_exchange(
4911 : spdm_context,
4912 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
4913 : &session_id, &heartbeat_period, &slot_id_param,
4914 : measurement_hash);
4915 1 : assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
4916 1 : free(data);
4917 1 : }
4918 :
4919 : /**
4920 : * Test 9: Unable to acquire the sender buffer.
4921 : * Expected Behavior: returns with error LIBSPDM_STATUS_ACQUIRE_FAIL.
4922 : **/
4923 1 : static void libspdm_test_requester_key_exchange_err_case9(void **state)
4924 : {
4925 : libspdm_return_t status;
4926 : libspdm_test_context_t *spdm_test_context;
4927 : libspdm_context_t *spdm_context;
4928 : uint32_t session_id;
4929 : uint8_t slot_id_param;
4930 :
4931 1 : spdm_test_context = *state;
4932 1 : spdm_context = spdm_test_context->spdm_context;
4933 1 : spdm_test_context->case_id = 0x9;
4934 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4935 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4936 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4937 1 : spdm_context->connection_info.capability.flags |=
4938 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
4939 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
4940 1 : spdm_context->local_context.capability.flags |=
4941 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
4942 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
4943 :
4944 1 : libspdm_force_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
4945 1 : status = libspdm_send_receive_key_exchange(
4946 : spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
4947 : &session_id, NULL, &slot_id_param, NULL);
4948 1 : libspdm_release_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
4949 :
4950 1 : assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
4951 1 : }
4952 :
4953 1 : static void libspdm_test_requester_key_exchange_err_case10(void **state) {
4954 : libspdm_return_t status;
4955 : libspdm_test_context_t *spdm_test_context;
4956 : libspdm_context_t *spdm_context;
4957 : uint32_t session_id;
4958 : uint8_t heartbeat_period;
4959 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4960 : uint8_t slot_id_param;
4961 : void *data;
4962 : size_t data_size;
4963 : void *hash;
4964 : size_t hash_size;
4965 : uint16_t error_code;
4966 :
4967 1 : spdm_test_context = *state;
4968 1 : spdm_context = spdm_test_context->spdm_context;
4969 1 : spdm_test_context->case_id = 0xA;
4970 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4971 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4972 1 : spdm_context->connection_info.capability.flags |=
4973 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
4974 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
4975 1 : libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
4976 : m_libspdm_use_asym_algo,
4977 : &data, &data_size,
4978 : &hash, &hash_size);
4979 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4980 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4981 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
4982 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
4983 :
4984 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4985 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4986 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4987 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4988 : data, data_size);
4989 : #else
4990 1 : libspdm_hash_all(
4991 : spdm_context->connection_info.algorithm.base_hash_algo,
4992 : data, data_size,
4993 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4994 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4995 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4996 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4997 : spdm_context->connection_info.algorithm.base_hash_algo,
4998 : spdm_context->connection_info.algorithm.base_asym_algo,
4999 : data, data_size,
5000 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5001 : #endif
5002 :
5003 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
5004 19 : while(error_code <= 0xff) {
5005 18 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5006 18 : libspdm_reset_message_a(spdm_context);
5007 :
5008 18 : heartbeat_period = 0;
5009 18 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5010 18 : status = libspdm_send_receive_key_exchange (spdm_context,
5011 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
5012 : 0, 0, &session_id, &heartbeat_period,
5013 : &slot_id_param, measurement_hash);
5014 18 : LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
5015 :
5016 18 : error_code++;
5017 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
5018 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
5019 : }
5020 : /* skip some reserved error codes (0d to 3e) */
5021 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
5022 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
5023 : }
5024 : /* skip response not ready, request resync, and some reserved codes (44 to fc) */
5025 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
5026 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
5027 : }
5028 : }
5029 :
5030 1 : free(data);
5031 1 : }
5032 :
5033 : /**
5034 : * Test 11: Unable to acquire the receiver buffer.
5035 : * Expected Behavior: returns with error LIBSPDM_STATUS_ACQUIRE_FAIL.
5036 : **/
5037 1 : static void libspdm_test_requester_key_exchange_err_case11(void **state)
5038 : {
5039 : libspdm_return_t status;
5040 : libspdm_test_context_t *spdm_test_context;
5041 : libspdm_context_t *spdm_context;
5042 : uint32_t session_id;
5043 : uint8_t slot_id_param;
5044 :
5045 1 : spdm_test_context = *state;
5046 1 : spdm_context = spdm_test_context->spdm_context;
5047 1 : spdm_test_context->case_id = 0xb;
5048 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5049 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5050 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5051 1 : spdm_context->connection_info.capability.flags |=
5052 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5053 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5054 1 : spdm_context->local_context.capability.flags |=
5055 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5056 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5057 :
5058 1 : libspdm_force_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
5059 1 : status = libspdm_send_receive_key_exchange(
5060 : spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5061 : &session_id, NULL, &slot_id_param, NULL);
5062 1 : libspdm_release_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
5063 :
5064 1 : assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
5065 1 : }
5066 :
5067 : /**
5068 : * Test 12: Version in response is incorrect.
5069 : * Expected Behavior: returns with error LIBSPDM_STATUS_INVALID_MSG_FIELD.
5070 : **/
5071 1 : static void libspdm_test_requester_key_exchange_err_case12(void **state)
5072 : {
5073 : libspdm_return_t status;
5074 : libspdm_test_context_t *spdm_test_context;
5075 : libspdm_context_t *spdm_context;
5076 : uint32_t session_id;
5077 : uint8_t slot_id_param;
5078 :
5079 1 : spdm_test_context = *state;
5080 1 : spdm_context = spdm_test_context->spdm_context;
5081 1 : spdm_test_context->case_id = 0xc;
5082 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5083 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5084 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5085 1 : spdm_context->connection_info.capability.flags |=
5086 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5087 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5088 1 : spdm_context->local_context.capability.flags |=
5089 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5090 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5091 :
5092 1 : status = libspdm_send_receive_key_exchange(
5093 : spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5094 : &session_id, NULL, &slot_id_param, NULL);
5095 :
5096 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5097 1 : }
5098 :
5099 : /**
5100 : * Test 13: Response code is incorrect.
5101 : * Expected Behavior: returns with error LIBSPDM_STATUS_INVALID_MSG_FIELD.
5102 : **/
5103 1 : static void libspdm_test_requester_key_exchange_err_case13(void **state)
5104 : {
5105 : libspdm_return_t status;
5106 : libspdm_test_context_t *spdm_test_context;
5107 : libspdm_context_t *spdm_context;
5108 : uint32_t session_id;
5109 : uint8_t slot_id_param;
5110 :
5111 1 : spdm_test_context = *state;
5112 1 : spdm_context = spdm_test_context->spdm_context;
5113 1 : spdm_test_context->case_id = 0xd;
5114 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5115 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5116 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5117 1 : spdm_context->connection_info.capability.flags |=
5118 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5119 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5120 1 : spdm_context->local_context.capability.flags |=
5121 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5122 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5123 :
5124 1 : status = libspdm_send_receive_key_exchange(
5125 : spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5126 : &session_id, NULL, &slot_id_param, NULL);
5127 :
5128 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5129 1 : }
5130 :
5131 : /**
5132 : * Test 14: Responder requests mutual authentication when it is not supported.
5133 : * Expected Behavior: returns with error LIBSPDM_STATUS_INVALID_MSG_FIELD.
5134 : **/
5135 1 : static void libspdm_test_requester_key_exchange_err_case14(void **state)
5136 : {
5137 : libspdm_return_t status;
5138 : libspdm_test_context_t *spdm_test_context;
5139 : libspdm_context_t *spdm_context;
5140 : uint32_t session_id;
5141 : uint8_t slot_id_param;
5142 :
5143 1 : spdm_test_context = *state;
5144 1 : spdm_context = spdm_test_context->spdm_context;
5145 1 : spdm_test_context->case_id = 0xe;
5146 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5147 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5148 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5149 1 : spdm_context->connection_info.capability.flags |=
5150 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5151 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5152 1 : spdm_context->local_context.capability.flags |=
5153 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5154 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5155 :
5156 1 : status = libspdm_send_receive_key_exchange(
5157 : spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5158 : &session_id, NULL, &slot_id_param, NULL);
5159 :
5160 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5161 1 : }
5162 :
5163 1 : static void libspdm_test_requester_key_exchange_err_case15(void **state)
5164 : {
5165 : libspdm_return_t status;
5166 : libspdm_test_context_t *spdm_test_context;
5167 : libspdm_context_t *spdm_context;
5168 : uint32_t session_id;
5169 : uint8_t heartbeat_period;
5170 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5171 : uint8_t slot_id_param;
5172 : void *data;
5173 : size_t data_size;
5174 : void *hash;
5175 : size_t hash_size;
5176 :
5177 1 : spdm_test_context = *state;
5178 1 : spdm_context = spdm_test_context->spdm_context;
5179 :
5180 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
5181 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
5182 : }
5183 :
5184 1 : spdm_test_context->case_id = 0xF;
5185 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5186 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5187 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5188 1 : spdm_context->connection_info.capability.flags |=
5189 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
5190 1 : spdm_context->connection_info.capability.flags |=
5191 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5192 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
5193 :
5194 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5195 : m_libspdm_use_asym_algo, &data,
5196 : &data_size, &hash, &hash_size)) {
5197 0 : assert(false);
5198 : }
5199 1 : libspdm_reset_message_a(spdm_context);
5200 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5201 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5202 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5203 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
5204 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5205 : m_libspdm_use_measurement_hash_algo;
5206 :
5207 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5208 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5209 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5210 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5211 : data, data_size);
5212 : #else
5213 1 : libspdm_hash_all(
5214 : spdm_context->connection_info.algorithm.base_hash_algo,
5215 : data, data_size,
5216 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5217 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5218 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5219 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5220 : spdm_context->connection_info.algorithm.base_hash_algo,
5221 : spdm_context->connection_info.algorithm.base_asym_algo,
5222 : data, data_size,
5223 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5224 : #endif
5225 :
5226 1 : heartbeat_period = 0;
5227 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5228 1 : status = libspdm_send_receive_key_exchange(
5229 : spdm_context,
5230 : SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
5231 : &session_id, &heartbeat_period, &slot_id_param,
5232 : measurement_hash);
5233 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
5234 1 : free(data);
5235 1 : }
5236 :
5237 1 : static void libspdm_test_requester_key_exchange_err_case16(void **state)
5238 : {
5239 : libspdm_return_t status;
5240 : libspdm_test_context_t *spdm_test_context;
5241 : libspdm_context_t *spdm_context;
5242 : uint32_t session_id;
5243 : uint8_t heartbeat_period;
5244 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5245 : uint8_t slot_id_param;
5246 : void *data;
5247 : size_t data_size;
5248 : void *hash;
5249 : size_t hash_size;
5250 :
5251 1 : spdm_test_context = *state;
5252 1 : spdm_context = spdm_test_context->spdm_context;
5253 :
5254 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
5255 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
5256 : }
5257 :
5258 1 : spdm_test_context->case_id = 0x10;
5259 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5260 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5261 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5262 1 : spdm_context->connection_info.capability.flags |=
5263 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
5264 1 : spdm_context->connection_info.capability.flags |=
5265 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5266 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
5267 :
5268 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5269 : m_libspdm_use_asym_algo, &data,
5270 : &data_size, &hash, &hash_size)) {
5271 0 : assert(false);
5272 : }
5273 1 : libspdm_reset_message_a(spdm_context);
5274 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5275 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5276 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5277 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
5278 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5279 : m_libspdm_use_measurement_hash_algo;
5280 :
5281 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5282 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5283 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5284 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5285 : data, data_size);
5286 : #else
5287 1 : libspdm_hash_all(
5288 : spdm_context->connection_info.algorithm.base_hash_algo,
5289 : data, data_size,
5290 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5291 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5292 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5293 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5294 : spdm_context->connection_info.algorithm.base_hash_algo,
5295 : spdm_context->connection_info.algorithm.base_asym_algo,
5296 : data, data_size,
5297 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5298 : #endif
5299 :
5300 1 : heartbeat_period = 0;
5301 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5302 1 : status = libspdm_send_receive_key_exchange(
5303 : spdm_context,
5304 : SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, 0,
5305 : &session_id, &heartbeat_period, &slot_id_param,
5306 : measurement_hash);
5307 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
5308 1 : free(data);
5309 1 : }
5310 :
5311 1 : static void libspdm_test_requester_key_exchange_err_case17(void **state)
5312 : {
5313 : libspdm_return_t status;
5314 : libspdm_test_context_t *spdm_test_context;
5315 : libspdm_context_t *spdm_context;
5316 : uint32_t session_id;
5317 : uint8_t heartbeat_period;
5318 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5319 : uint8_t slot_id_param;
5320 : void *data;
5321 : size_t data_size;
5322 : void *hash;
5323 : size_t hash_size;
5324 :
5325 1 : spdm_test_context = *state;
5326 1 : spdm_context = spdm_test_context->spdm_context;
5327 :
5328 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
5329 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
5330 : }
5331 :
5332 1 : spdm_test_context->case_id = 0x11;
5333 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5334 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5335 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5336 1 : spdm_context->connection_info.capability.flags |=
5337 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
5338 1 : spdm_context->connection_info.capability.flags |=
5339 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5340 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
5341 :
5342 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5343 : m_libspdm_use_asym_algo, &data,
5344 : &data_size, &hash, &hash_size)) {
5345 0 : assert(false);
5346 : }
5347 1 : libspdm_reset_message_a(spdm_context);
5348 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5349 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5350 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5351 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
5352 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5353 : m_libspdm_use_measurement_hash_algo;
5354 :
5355 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5356 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5357 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5358 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5359 : data, data_size);
5360 : #else
5361 1 : libspdm_hash_all(
5362 : spdm_context->connection_info.algorithm.base_hash_algo,
5363 : data, data_size,
5364 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5365 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5366 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5367 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5368 : spdm_context->connection_info.algorithm.base_hash_algo,
5369 : spdm_context->connection_info.algorithm.base_asym_algo,
5370 : data, data_size,
5371 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5372 : #endif
5373 :
5374 1 : heartbeat_period = 0;
5375 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5376 1 : status = libspdm_send_receive_key_exchange(
5377 : spdm_context,
5378 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5379 : &session_id, &heartbeat_period, &slot_id_param,
5380 : measurement_hash);
5381 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
5382 1 : free(data);
5383 1 : }
5384 :
5385 1 : static void libspdm_test_requester_key_exchange_err_case18(void **state)
5386 : {
5387 : libspdm_return_t status;
5388 : libspdm_test_context_t *spdm_test_context;
5389 : libspdm_context_t *spdm_context;
5390 : uint32_t session_id;
5391 : uint8_t heartbeat_period;
5392 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5393 : uint8_t slot_id_param;
5394 : void *data;
5395 : size_t data_size;
5396 : void *hash;
5397 : size_t hash_size;
5398 :
5399 1 : spdm_test_context = *state;
5400 1 : spdm_context = spdm_test_context->spdm_context;
5401 :
5402 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
5403 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
5404 : }
5405 :
5406 1 : spdm_test_context->case_id = 0x12;
5407 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5408 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5409 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5410 1 : spdm_context->connection_info.capability.flags |=
5411 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
5412 1 : spdm_context->connection_info.capability.flags |=
5413 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5414 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
5415 :
5416 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5417 : m_libspdm_use_asym_algo, &data,
5418 : &data_size, &hash, &hash_size)) {
5419 0 : assert(false);
5420 : }
5421 1 : libspdm_reset_message_a(spdm_context);
5422 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5423 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5424 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5425 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
5426 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5427 : m_libspdm_use_measurement_hash_algo;
5428 :
5429 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5430 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5431 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5432 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5433 : data, data_size);
5434 : #else
5435 1 : libspdm_hash_all(
5436 : spdm_context->connection_info.algorithm.base_hash_algo,
5437 : data, data_size,
5438 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5439 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5440 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5441 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5442 : spdm_context->connection_info.algorithm.base_hash_algo,
5443 : spdm_context->connection_info.algorithm.base_asym_algo,
5444 : data, data_size,
5445 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5446 : #endif
5447 :
5448 1 : heartbeat_period = 0;
5449 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5450 1 : status = libspdm_send_receive_key_exchange(
5451 : spdm_context,
5452 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5453 : &session_id, &heartbeat_period, &slot_id_param,
5454 : measurement_hash);
5455 1 : assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
5456 1 : free(data);
5457 1 : }
5458 :
5459 : /**
5460 : * Test 19:
5461 : * Expected Behavior:
5462 : **/
5463 1 : static void libspdm_test_requester_key_exchange_err_case19(void **state)
5464 : {
5465 1 : }
5466 :
5467 1 : static void libspdm_test_requester_key_exchange_err_case20(void **state)
5468 : {
5469 : libspdm_return_t status;
5470 : libspdm_test_context_t *spdm_test_context;
5471 : libspdm_context_t *spdm_context;
5472 : uint32_t session_id;
5473 : uint8_t heartbeat_period;
5474 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5475 : uint8_t slot_id_param;
5476 : void *data;
5477 : size_t data_size;
5478 : void *hash;
5479 : size_t hash_size;
5480 :
5481 1 : spdm_test_context = *state;
5482 1 : spdm_context = spdm_test_context->spdm_context;
5483 :
5484 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
5485 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
5486 : }
5487 :
5488 1 : spdm_test_context->case_id = 0x14;
5489 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5490 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5491 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5492 1 : spdm_context->connection_info.capability.flags |=
5493 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
5494 1 : spdm_context->connection_info.capability.flags |=
5495 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5496 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
5497 :
5498 :
5499 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5500 : m_libspdm_use_asym_algo, &data,
5501 : &data_size, &hash, &hash_size)) {
5502 0 : assert(false);
5503 : }
5504 1 : libspdm_reset_message_a(spdm_context);
5505 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5506 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5507 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5508 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
5509 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5510 : m_libspdm_use_measurement_hash_algo;
5511 :
5512 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5513 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5514 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5515 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5516 : data, data_size);
5517 : #else
5518 1 : libspdm_hash_all(
5519 : spdm_context->connection_info.algorithm.base_hash_algo,
5520 : data, data_size,
5521 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5522 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5523 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5524 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5525 : spdm_context->connection_info.algorithm.base_hash_algo,
5526 : spdm_context->connection_info.algorithm.base_asym_algo,
5527 : data, data_size,
5528 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5529 : #endif
5530 :
5531 1 : heartbeat_period = 0;
5532 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5533 1 : status = libspdm_send_receive_key_exchange(
5534 : spdm_context,
5535 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5536 : &session_id, &heartbeat_period, &slot_id_param,
5537 : measurement_hash);
5538 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5539 1 : free(data);
5540 1 : }
5541 :
5542 : /**
5543 : * Test 21: OpaqueLength is larger than the recommended value.
5544 : * Expected Behavior: Returns with LIBSPDM_STATUS_INVALID_MSG_FIELD.
5545 : **/
5546 1 : static void libspdm_test_requester_key_exchange_err_case21(void **state)
5547 : {
5548 : libspdm_return_t status;
5549 : libspdm_test_context_t *spdm_test_context;
5550 : libspdm_context_t *spdm_context;
5551 : uint32_t session_id;
5552 : uint8_t slot_id_param;
5553 :
5554 1 : spdm_test_context = *state;
5555 1 : spdm_context = spdm_test_context->spdm_context;
5556 1 : spdm_test_context->case_id = 0x15;
5557 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5558 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5559 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5560 1 : spdm_context->connection_info.capability.flags |=
5561 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5562 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5563 1 : spdm_context->local_context.capability.flags |=
5564 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5565 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5566 :
5567 1 : status = libspdm_send_receive_key_exchange(
5568 : spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5569 : &session_id, NULL, &slot_id_param, NULL);
5570 :
5571 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5572 1 : }
5573 :
5574 : /**
5575 : * Test 22: Requester's PUB_KEY_ID_CAP is 1 but Responder sets MutAuthRequested to 2 (encapsulated
5576 : * flow).
5577 : * Expected Behavior: Returns with LIBSPDM_STATUS_INVALID_MSG_FIELD.
5578 : **/
5579 1 : static void libspdm_test_requester_key_exchange_err_case22(void **state)
5580 : {
5581 : libspdm_return_t status;
5582 : libspdm_test_context_t *spdm_test_context;
5583 : libspdm_context_t *spdm_context;
5584 : uint32_t session_id;
5585 : uint8_t slot_id_param;
5586 :
5587 1 : spdm_test_context = *state;
5588 1 : spdm_context = spdm_test_context->spdm_context;
5589 1 : spdm_test_context->case_id = 0x16;
5590 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5591 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5592 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5593 1 : spdm_context->connection_info.capability.flags |=
5594 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5595 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
5596 1 : spdm_context->local_context.capability.flags |=
5597 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5598 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
5599 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP;
5600 :
5601 1 : status = libspdm_send_receive_key_exchange(
5602 : spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5603 : &session_id, NULL, &slot_id_param, NULL);
5604 :
5605 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5606 1 : }
5607 :
5608 : /**
5609 : * Test 23: Responder attempts to initiate a mutual authentication encapsulated flow but both
5610 : * endpoints do not support ENCAP_CAP.
5611 : * Expected Behavior: Returns with LIBSPDM_STATUS_INVALID_MSG_FIELD.
5612 : **/
5613 1 : static void libspdm_test_requester_key_exchange_err_case23(void **state)
5614 : {
5615 : libspdm_return_t status;
5616 : libspdm_test_context_t *spdm_test_context;
5617 : libspdm_context_t *spdm_context;
5618 : uint32_t session_id;
5619 : uint8_t slot_id_param;
5620 :
5621 1 : spdm_test_context = *state;
5622 1 : spdm_context = spdm_test_context->spdm_context;
5623 1 : spdm_test_context->case_id = 0x17;
5624 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5625 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5626 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5627 1 : spdm_context->connection_info.capability.flags =
5628 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
5629 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
5630 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
5631 1 : spdm_context->local_context.capability.flags =
5632 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
5633 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP |
5634 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP |
5635 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
5636 :
5637 1 : status = libspdm_send_receive_key_exchange(
5638 : spdm_context, SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5639 : &session_id, NULL, &slot_id_param, NULL);
5640 :
5641 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5642 1 : }
5643 :
5644 1 : static void libspdm_test_requester_key_exchange_err_case24(void **state)
5645 : {
5646 1 : }
5647 :
5648 1 : static void libspdm_test_requester_key_exchange_err_case25(void **state)
5649 : {
5650 1 : }
5651 :
5652 1 : static void libspdm_test_requester_key_exchange_err_case26(void **state)
5653 : {
5654 : libspdm_return_t status;
5655 : libspdm_test_context_t *spdm_test_context;
5656 : libspdm_context_t *spdm_context;
5657 : uint32_t session_id;
5658 : uint8_t heartbeat_period;
5659 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5660 : uint8_t slot_id_param;
5661 : void *data;
5662 : size_t data_size;
5663 : void *hash;
5664 : size_t hash_size;
5665 :
5666 1 : spdm_test_context = *state;
5667 1 : spdm_context = spdm_test_context->spdm_context;
5668 :
5669 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
5670 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
5671 : }
5672 :
5673 1 : spdm_test_context->case_id = 0x1A;
5674 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5675 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5676 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5677 1 : spdm_context->connection_info.capability.flags |=
5678 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
5679 1 : spdm_context->connection_info.capability.flags |=
5680 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5681 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
5682 :
5683 1 : spdm_context->connection_info.capability.flags |=
5684 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
5685 1 : spdm_context->local_context.capability.flags |=
5686 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
5687 :
5688 :
5689 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5690 : m_libspdm_use_asym_algo, &data,
5691 : &data_size, &hash, &hash_size)) {
5692 0 : assert(false);
5693 : }
5694 1 : libspdm_reset_message_a(spdm_context);
5695 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5696 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5697 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5698 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
5699 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5700 : m_libspdm_use_measurement_hash_algo;
5701 :
5702 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5703 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5704 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5705 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5706 : data, data_size);
5707 : #else
5708 1 : libspdm_hash_all(
5709 : spdm_context->connection_info.algorithm.base_hash_algo,
5710 : data, data_size,
5711 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5712 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5713 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5714 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5715 : spdm_context->connection_info.algorithm.base_hash_algo,
5716 : spdm_context->connection_info.algorithm.base_asym_algo,
5717 : data, data_size,
5718 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5719 : #endif
5720 :
5721 1 : heartbeat_period = 0;
5722 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5723 1 : status = libspdm_send_receive_key_exchange(
5724 : spdm_context,
5725 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5726 : &session_id, &heartbeat_period, &slot_id_param,
5727 : measurement_hash);
5728 : /* Clear Mut_auth flags */
5729 1 : spdm_context->connection_info.capability.flags &=
5730 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
5731 1 : spdm_context->local_context.capability.flags &=
5732 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
5733 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5734 1 : free(data);
5735 1 : }
5736 :
5737 1 : static void libspdm_test_requester_key_exchange_err_case27(void **state)
5738 : {
5739 : libspdm_return_t status;
5740 : libspdm_test_context_t *spdm_test_context;
5741 : libspdm_context_t *spdm_context;
5742 : uint32_t session_id;
5743 : uint8_t heartbeat_period;
5744 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5745 : uint8_t slot_id_param;
5746 : void *data;
5747 : size_t data_size;
5748 : void *hash;
5749 : size_t hash_size;
5750 :
5751 1 : spdm_test_context = *state;
5752 1 : spdm_context = spdm_test_context->spdm_context;
5753 :
5754 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
5755 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
5756 : }
5757 :
5758 1 : spdm_test_context->case_id = 0x1B;
5759 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5760 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5761 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5762 1 : spdm_context->connection_info.capability.flags |=
5763 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
5764 1 : spdm_context->connection_info.capability.flags |=
5765 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5766 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
5767 :
5768 1 : spdm_context->connection_info.capability.flags |=
5769 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
5770 1 : spdm_context->local_context.capability.flags |=
5771 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
5772 :
5773 :
5774 1 : if (!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 0 : assert(false);
5778 : }
5779 1 : libspdm_reset_message_a(spdm_context);
5780 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5781 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5782 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5783 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
5784 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5785 : m_libspdm_use_measurement_hash_algo;
5786 :
5787 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5788 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5789 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5790 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5791 : data, data_size);
5792 : #else
5793 1 : libspdm_hash_all(
5794 : spdm_context->connection_info.algorithm.base_hash_algo,
5795 : data, data_size,
5796 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5797 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5798 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5799 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5800 : spdm_context->connection_info.algorithm.base_hash_algo,
5801 : spdm_context->connection_info.algorithm.base_asym_algo,
5802 : data, data_size,
5803 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5804 : #endif
5805 :
5806 1 : heartbeat_period = 0;
5807 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5808 1 : status = libspdm_send_receive_key_exchange(
5809 : spdm_context,
5810 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5811 : &session_id, &heartbeat_period, &slot_id_param,
5812 : measurement_hash);
5813 : /*Clear Mut_auth flags*/
5814 1 : spdm_context->connection_info.capability.flags &=
5815 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
5816 1 : spdm_context->local_context.capability.flags &=
5817 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
5818 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5819 1 : free(data);
5820 1 : }
5821 :
5822 1 : static void libspdm_test_requester_key_exchange_err_case28(void **state)
5823 : {
5824 : libspdm_return_t status;
5825 : libspdm_test_context_t *spdm_test_context;
5826 : libspdm_context_t *spdm_context;
5827 : uint32_t session_id;
5828 : uint8_t heartbeat_period;
5829 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5830 : uint8_t slot_id_param;
5831 : void *data;
5832 : size_t data_size;
5833 : void *hash;
5834 : size_t hash_size;
5835 :
5836 1 : spdm_test_context = *state;
5837 1 : spdm_context = spdm_test_context->spdm_context;
5838 :
5839 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
5840 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
5841 : }
5842 :
5843 1 : spdm_test_context->case_id = 0x1C;
5844 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5845 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5846 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5847 1 : spdm_context->connection_info.capability.flags |=
5848 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
5849 1 : spdm_context->connection_info.capability.flags |=
5850 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5851 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
5852 :
5853 1 : spdm_context->connection_info.capability.flags |=
5854 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
5855 1 : spdm_context->local_context.capability.flags |=
5856 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
5857 :
5858 :
5859 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5860 : m_libspdm_use_asym_algo, &data,
5861 : &data_size, &hash, &hash_size)) {
5862 0 : assert(false);
5863 : }
5864 1 : libspdm_reset_message_a(spdm_context);
5865 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5866 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5867 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5868 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
5869 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5870 : m_libspdm_use_measurement_hash_algo;
5871 :
5872 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5873 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5874 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5875 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5876 : data, data_size);
5877 : #else
5878 1 : libspdm_hash_all(
5879 : spdm_context->connection_info.algorithm.base_hash_algo,
5880 : data, data_size,
5881 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5882 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5883 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5884 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5885 : spdm_context->connection_info.algorithm.base_hash_algo,
5886 : spdm_context->connection_info.algorithm.base_asym_algo,
5887 : data, data_size,
5888 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5889 : #endif
5890 :
5891 1 : heartbeat_period = 0;
5892 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5893 1 : status = libspdm_send_receive_key_exchange(
5894 : spdm_context,
5895 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5896 : &session_id, &heartbeat_period, &slot_id_param,
5897 : measurement_hash);
5898 : /* Clear Mut_auth flags */
5899 1 : spdm_context->connection_info.capability.flags &=
5900 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
5901 1 : spdm_context->local_context.capability.flags &=
5902 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
5903 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5904 1 : free(data);
5905 1 : }
5906 :
5907 1 : static void libspdm_test_requester_key_exchange_err_case29(void **state)
5908 : {
5909 1 : }
5910 :
5911 1 : static void libspdm_test_requester_key_exchange_err_case30(void **state)
5912 : {
5913 1 : }
5914 :
5915 : /**
5916 : * Test 31: Fail case, MutAuthRequested bit 0 set, and SlotID is 9 in KEY_EXCHANGE_RSP response
5917 : * message but SlotID should be between 0 and 7 inclusive.
5918 : * Expected Behavior: returns a status of INVALID_MSG_FIELD.
5919 : **/
5920 1 : static void libspdm_test_requester_key_exchange_err_case31(void **state)
5921 : {
5922 : libspdm_return_t status;
5923 : libspdm_test_context_t *spdm_test_context;
5924 : libspdm_context_t *spdm_context;
5925 : uint32_t session_id;
5926 : uint8_t heartbeat_period;
5927 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5928 : uint8_t slot_id_param;
5929 : void *data;
5930 : size_t data_size;
5931 : void *hash;
5932 : size_t hash_size;
5933 :
5934 1 : spdm_test_context = *state;
5935 1 : spdm_context = spdm_test_context->spdm_context;
5936 :
5937 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
5938 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
5939 : }
5940 :
5941 1 : spdm_test_context->case_id = 0x1F;
5942 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5943 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5944 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5945 1 : spdm_context->connection_info.capability.flags |=
5946 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
5947 1 : spdm_context->connection_info.capability.flags |=
5948 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5949 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
5950 :
5951 1 : spdm_context->connection_info.capability.flags |=
5952 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
5953 1 : spdm_context->local_context.capability.flags |=
5954 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
5955 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
5956 :
5957 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5958 : m_libspdm_use_asym_algo, &data,
5959 : &data_size, &hash, &hash_size)) {
5960 0 : assert(false);
5961 : }
5962 1 : libspdm_reset_message_a(spdm_context);
5963 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5964 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5965 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5966 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
5967 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5968 : m_libspdm_use_measurement_hash_algo;
5969 :
5970 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5971 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5972 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5973 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5974 : data, data_size);
5975 : #else
5976 1 : libspdm_hash_all(
5977 : spdm_context->connection_info.algorithm.base_hash_algo,
5978 : data, data_size,
5979 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5980 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5981 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5982 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5983 : spdm_context->connection_info.algorithm.base_hash_algo,
5984 : spdm_context->connection_info.algorithm.base_asym_algo,
5985 : data, data_size,
5986 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5987 : #endif
5988 :
5989 1 : heartbeat_period = 0;
5990 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5991 1 : status = libspdm_send_receive_key_exchange(
5992 : spdm_context,
5993 : SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
5994 : &session_id, &heartbeat_period, &slot_id_param,
5995 : measurement_hash);
5996 : /* Clear Mut_auth flags */
5997 1 : spdm_context->connection_info.capability.flags &=
5998 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
5999 1 : spdm_context->local_context.capability.flags &=
6000 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
6001 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
6002 1 : free(data);
6003 1 : }
6004 :
6005 1 : int libspdm_req_key_exchange_error_test(void)
6006 : {
6007 1 : const struct CMUnitTest test_cases[] = {
6008 : /* SendRequest failed*/
6009 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case1),
6010 : /* Successful response*/
6011 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case2),
6012 : /* connection_state check failed*/
6013 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case3),
6014 : /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
6015 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case4),
6016 : /* Always SPDM_ERROR_CODE_BUSY*/
6017 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case5),
6018 : /* SPDM_ERROR_CODE_BUSY + Successful response*/
6019 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case6),
6020 : /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
6021 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case7),
6022 : /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
6023 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case8),
6024 : /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
6025 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case9),
6026 : /* Unexpected errors*/
6027 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case10),
6028 : /* Buffer reset*/
6029 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case11),
6030 : /* Measurement hash 1, returns a measurement hash*/
6031 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case12),
6032 : /* Measurement hash 1, returns a 0x00 array (no TCB components)*/
6033 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case13),
6034 : /* Measurement hash FF, returns a measurement_hash*/
6035 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case14),
6036 : /* Measurement hash 1, returns no measurement_hash*/
6037 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case15),
6038 : /* Measurement hash FF, returns no measurement_hash*/
6039 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case16),
6040 : /* Measurement hash not requested, returns a measurement_hash*/
6041 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case17),
6042 : /* Wrong signature*/
6043 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case18),
6044 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case19),
6045 : /* Heartbeat not supported, heartbeat period different from 0 sent*/
6046 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case20),
6047 : /* Heartbeat supported, heartbeat period different from 0 sent*/
6048 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case21),
6049 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case22),
6050 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case23),
6051 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case24),
6052 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case25),
6053 : /* Muth Auth requested with Encapsulated request and bit 0 set*/
6054 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case26),
6055 : /* Muth Auth requested with implicit get digest and bit 0 set*/
6056 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case27),
6057 : /* Muth Auth requested with Encapsulated request and Muth Auth requested with implicit get digest simultaneously*/
6058 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case28),
6059 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case29),
6060 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case30),
6061 : /* Muth Auth requested bit 0 set, but Invalid SlotID in KEY_EXCHANGE_RSP response message*/
6062 : cmocka_unit_test(libspdm_test_requester_key_exchange_err_case31),
6063 : };
6064 :
6065 1 : libspdm_test_context_t test_context = {
6066 : LIBSPDM_TEST_CONTEXT_VERSION,
6067 : true,
6068 : send_message,
6069 : receive_message,
6070 : };
6071 :
6072 1 : libspdm_setup_test_context(&test_context);
6073 :
6074 1 : return cmocka_run_group_tests(test_cases,
6075 : libspdm_unit_test_group_setup,
6076 : libspdm_unit_test_group_teardown);
6077 : }
6078 :
6079 : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
|