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