Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2025 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 "internal/libspdm_requester_lib.h"
8 :
9 : #if LIBSPDM_SEND_CHALLENGE_SUPPORT
10 :
11 : #pragma pack(1)
12 : typedef struct {
13 : spdm_message_header_t header;
14 : uint8_t cert_chain_hash[LIBSPDM_MAX_HASH_SIZE];
15 : uint8_t nonce[SPDM_NONCE_SIZE];
16 : uint8_t measurement_summary_hash[LIBSPDM_MAX_HASH_SIZE];
17 : uint16_t opaque_length;
18 : uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
19 : uint8_t requester_context[SPDM_REQ_CONTEXT_SIZE];
20 : uint8_t signature[LIBSPDM_RSP_SIGNATURE_DATA_MAX_SIZE];
21 : } libspdm_challenge_auth_response_max_t;
22 : #pragma pack()
23 :
24 : /**
25 : * This function sends CHALLENGE to authenticate the device based upon the key in one slot.
26 : *
27 : * This function verifies the signature in the challenge auth.
28 : *
29 : * If basic mutual authentication is requested from the responder,
30 : * this function also perform the basic mutual authentication.
31 : *
32 : * @param spdm_context A pointer to the SPDM context.
33 : * @param slot_id The number of slot for the challenge.
34 : * @param requester_context If not NULL, a buffer to hold the requester context (8 bytes).
35 : * It is used only if the negotiated version >= 1.3.
36 : * @param measurement_hash_type The type of the measurement hash.
37 : * @param measurement_hash A pointer to a destination buffer to store the measurement hash.
38 : * @param slot_mask A pointer to a destination to store the slot mask.
39 : * @param requester_nonce_in If not NULL, a buffer that holds the requester nonce (32 bytes)
40 : * @param requester_nonce If not NULL, a buffer to hold the requester nonce (32 bytes).
41 : * @param responder_nonce If not NULL, a buffer to hold the responder nonce (32 bytes).
42 : **/
43 49 : static libspdm_return_t libspdm_try_challenge(libspdm_context_t *spdm_context,
44 : uint8_t slot_id,
45 : const void *requester_context,
46 : uint8_t measurement_hash_type,
47 : void *measurement_hash,
48 : uint8_t *slot_mask,
49 : const void *requester_nonce_in,
50 : void *requester_nonce,
51 : void *responder_nonce,
52 : void *opaque_data,
53 : size_t *opaque_data_size)
54 : {
55 : libspdm_return_t status;
56 : bool result;
57 : spdm_challenge_request_t *spdm_request;
58 : size_t spdm_request_size;
59 : libspdm_challenge_auth_response_max_t *spdm_response;
60 : size_t spdm_response_size;
61 : uint8_t *ptr;
62 : void *cert_chain_hash;
63 : size_t hash_size;
64 : uint32_t measurement_summary_hash_size;
65 : void *nonce;
66 : void *measurement_summary_hash;
67 : uint16_t opaque_length;
68 : void *signature;
69 : size_t signature_size;
70 : uint8_t auth_attribute;
71 : uint8_t *message;
72 : size_t message_size;
73 : size_t transport_header_size;
74 :
75 : /* -=[Check Parameters Phase]=- */
76 49 : LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xff));
77 49 : LIBSPDM_ASSERT((slot_id != 0xff) ||
78 : (spdm_context->local_context.peer_public_key_provision_size != 0));
79 49 : LIBSPDM_ASSERT(measurement_hash_type == SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH ||
80 : measurement_hash_type == SPDM_CHALLENGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH ||
81 : measurement_hash_type == SPDM_CHALLENGE_REQUEST_ALL_MEASUREMENTS_HASH);
82 :
83 : /* -=[Verify State Phase]=- */
84 49 : if (!libspdm_is_capabilities_flag_supported(
85 : spdm_context, true, 0,
86 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP)) {
87 1 : return LIBSPDM_STATUS_UNSUPPORTED_CAP;
88 : }
89 48 : if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
90 1 : return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
91 : }
92 :
93 47 : libspdm_reset_message_buffer_via_request_code(spdm_context, NULL, SPDM_CHALLENGE);
94 :
95 : /* -=[Construct Request Phase]=- */
96 47 : transport_header_size = spdm_context->local_context.capability.transport_header_size;
97 47 : status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
98 47 : if (LIBSPDM_STATUS_IS_ERROR(status)) {
99 0 : return status;
100 : }
101 47 : LIBSPDM_ASSERT (message_size >= transport_header_size +
102 : spdm_context->local_context.capability.transport_tail_size);
103 47 : spdm_request = (void *)(message + transport_header_size);
104 47 : spdm_request_size = message_size - transport_header_size -
105 47 : spdm_context->local_context.capability.transport_tail_size;
106 :
107 47 : LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_challenge_request_t));
108 47 : spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
109 47 : spdm_request->header.request_response_code = SPDM_CHALLENGE;
110 47 : spdm_request->header.param1 = slot_id;
111 47 : spdm_request->header.param2 = measurement_hash_type;
112 47 : if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
113 2 : LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_challenge_request_t) +
114 : SPDM_REQ_CONTEXT_SIZE);
115 2 : spdm_request_size = sizeof(spdm_challenge_request_t) + SPDM_REQ_CONTEXT_SIZE;
116 : } else {
117 45 : spdm_request_size = sizeof(spdm_challenge_request_t);
118 : }
119 47 : if (requester_nonce_in == NULL) {
120 47 : if (!libspdm_get_random_number(SPDM_NONCE_SIZE, spdm_request->nonce)) {
121 0 : libspdm_release_sender_buffer (spdm_context);
122 0 : return LIBSPDM_STATUS_LOW_ENTROPY;
123 : }
124 : } else {
125 0 : libspdm_copy_mem(spdm_request->nonce, sizeof(spdm_request->nonce),
126 : requester_nonce_in, SPDM_NONCE_SIZE);
127 : }
128 47 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterNonce - "));
129 47 : LIBSPDM_INTERNAL_DUMP_DATA(spdm_request->nonce, SPDM_NONCE_SIZE);
130 47 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
131 47 : if (requester_nonce != NULL) {
132 0 : libspdm_copy_mem(requester_nonce, SPDM_NONCE_SIZE, spdm_request->nonce, SPDM_NONCE_SIZE);
133 : }
134 47 : if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
135 2 : if (requester_context == NULL) {
136 0 : libspdm_zero_mem(spdm_request + 1, SPDM_REQ_CONTEXT_SIZE);
137 : } else {
138 2 : libspdm_copy_mem(spdm_request + 1, SPDM_REQ_CONTEXT_SIZE,
139 : requester_context, SPDM_REQ_CONTEXT_SIZE);
140 : }
141 2 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterContext - "));
142 2 : LIBSPDM_INTERNAL_DUMP_DATA((uint8_t *)(spdm_request + 1), SPDM_REQ_CONTEXT_SIZE);
143 2 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
144 : }
145 :
146 : /* -=[Send Request Phase]=- */
147 47 : status = libspdm_send_spdm_request(spdm_context, NULL, spdm_request_size, spdm_request);
148 47 : if (LIBSPDM_STATUS_IS_ERROR(status)) {
149 1 : libspdm_release_sender_buffer (spdm_context);
150 1 : return status;
151 : }
152 46 : libspdm_release_sender_buffer (spdm_context);
153 46 : spdm_request = (void *)spdm_context->last_spdm_request;
154 :
155 : /* -=[Receive Response Phase]=- */
156 46 : status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
157 46 : if (LIBSPDM_STATUS_IS_ERROR(status)) {
158 0 : return status;
159 : }
160 46 : LIBSPDM_ASSERT (message_size >= transport_header_size);
161 46 : spdm_response = (void *)(message);
162 46 : spdm_response_size = message_size;
163 :
164 46 : status = libspdm_receive_spdm_response(
165 : spdm_context, NULL, &spdm_response_size, (void **)&spdm_response);
166 46 : if (LIBSPDM_STATUS_IS_ERROR(status)) {
167 0 : goto receive_done;
168 : }
169 :
170 : /* -=[Validate Response Phase]=- */
171 46 : if (spdm_response_size < sizeof(spdm_message_header_t)) {
172 0 : status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
173 0 : goto receive_done;
174 : }
175 46 : if (spdm_response->header.request_response_code == SPDM_ERROR) {
176 24 : status = libspdm_handle_error_response_main(
177 : spdm_context, NULL,
178 : &spdm_response_size,
179 : (void **)&spdm_response, SPDM_CHALLENGE, SPDM_CHALLENGE_AUTH);
180 24 : if (LIBSPDM_STATUS_IS_ERROR(status)) {
181 23 : goto receive_done;
182 : }
183 22 : } else if (spdm_response->header.request_response_code != SPDM_CHALLENGE_AUTH) {
184 1 : status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
185 1 : goto receive_done;
186 : }
187 22 : if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
188 1 : status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
189 1 : goto receive_done;
190 : }
191 21 : if (spdm_response_size < sizeof(spdm_challenge_auth_response_t)) {
192 0 : status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
193 0 : goto receive_done;
194 : }
195 21 : auth_attribute = spdm_response->header.param1;
196 21 : if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_11 && slot_id == 0xFF) {
197 1 : if ((auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_SLOT_ID_MASK) != 0xF) {
198 0 : status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
199 0 : goto receive_done;
200 : }
201 : } else {
202 20 : if ((spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_11 &&
203 20 : (auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_SLOT_ID_MASK) != slot_id) ||
204 19 : (spdm_response->header.spdm_version == SPDM_MESSAGE_VERSION_10 &&
205 : auth_attribute != slot_id)) {
206 1 : status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
207 1 : goto receive_done;
208 : }
209 19 : if ((spdm_response->header.param2 & (1 << slot_id)) == 0) {
210 1 : status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
211 1 : goto receive_done;
212 : }
213 : }
214 19 : if ((auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_BASIC_MUT_AUTH_REQ) != 0) {
215 0 : if (!libspdm_is_capabilities_flag_supported(
216 : spdm_context, true,
217 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP,
218 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP)) {
219 0 : status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
220 0 : goto receive_done;
221 : }
222 : }
223 :
224 : /* -=[Process Response Phase]=- */
225 19 : hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
226 19 : if (spdm_context->connection_info.algorithm.pqc_asym_algo != 0) {
227 0 : signature_size = libspdm_get_pqc_asym_signature_size(
228 : spdm_context->connection_info.algorithm.pqc_asym_algo);
229 : } else {
230 19 : signature_size = libspdm_get_asym_signature_size(
231 : spdm_context->connection_info.algorithm.base_asym_algo);
232 : }
233 19 : measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
234 : spdm_context, true, measurement_hash_type);
235 :
236 19 : if (spdm_response_size <= sizeof(spdm_challenge_auth_response_t) +
237 19 : hash_size + SPDM_NONCE_SIZE + measurement_summary_hash_size + sizeof(uint16_t)) {
238 0 : status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
239 0 : goto receive_done;
240 : }
241 :
242 19 : ptr = spdm_response->cert_chain_hash;
243 :
244 19 : cert_chain_hash = ptr;
245 19 : ptr += hash_size;
246 19 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cert_chain_hash (0x%zx) - ", hash_size));
247 19 : LIBSPDM_INTERNAL_DUMP_DATA(cert_chain_hash, hash_size);
248 19 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
249 19 : if (slot_id == 0xFF) {
250 1 : result = libspdm_verify_public_key_hash(spdm_context, cert_chain_hash, hash_size);
251 : } else {
252 18 : result = libspdm_verify_certificate_chain_hash(spdm_context, slot_id, cert_chain_hash,
253 : hash_size);
254 : }
255 19 : if (!result) {
256 0 : status = LIBSPDM_STATUS_VERIF_FAIL;
257 0 : goto receive_done;
258 : }
259 :
260 19 : nonce = ptr;
261 19 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "nonce (0x%x) - ", SPDM_NONCE_SIZE));
262 19 : LIBSPDM_INTERNAL_DUMP_DATA(nonce, SPDM_NONCE_SIZE);
263 19 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
264 19 : ptr += SPDM_NONCE_SIZE;
265 19 : if (responder_nonce != NULL) {
266 0 : libspdm_copy_mem(responder_nonce, SPDM_NONCE_SIZE, nonce, SPDM_NONCE_SIZE);
267 : }
268 :
269 19 : measurement_summary_hash = ptr;
270 19 : ptr += measurement_summary_hash_size;
271 19 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "measurement_summary_hash (0x%x) - ",
272 : measurement_summary_hash_size));
273 19 : LIBSPDM_INTERNAL_DUMP_DATA(measurement_summary_hash, measurement_summary_hash_size);
274 19 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
275 :
276 19 : opaque_length = libspdm_read_uint16((const uint8_t *)ptr);
277 19 : if (opaque_length > SPDM_MAX_OPAQUE_DATA_SIZE) {
278 1 : status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
279 1 : goto receive_done;
280 : }
281 18 : if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
282 4 : if (((spdm_context->connection_info.algorithm.other_params_support &
283 : SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) ==
284 1 : SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE) &&
285 : (opaque_length != 0)) {
286 0 : status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
287 0 : goto receive_done;
288 : }
289 : }
290 18 : ptr += sizeof(uint16_t);
291 18 : if (opaque_length != 0) {
292 2 : result = libspdm_process_general_opaque_data_check(spdm_context, opaque_length, ptr);
293 2 : if (!result) {
294 0 : status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
295 0 : goto receive_done;
296 : }
297 : }
298 :
299 18 : if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
300 2 : if (spdm_response_size <
301 : sizeof(spdm_challenge_auth_response_t) + hash_size +
302 2 : SPDM_NONCE_SIZE + measurement_summary_hash_size +
303 2 : sizeof(uint16_t) + opaque_length + SPDM_REQ_CONTEXT_SIZE +
304 : signature_size) {
305 0 : status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
306 0 : goto receive_done;
307 : }
308 2 : spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
309 2 : hash_size + SPDM_NONCE_SIZE +
310 2 : measurement_summary_hash_size + sizeof(uint16_t) +
311 2 : opaque_length + SPDM_REQ_CONTEXT_SIZE + signature_size;
312 : } else {
313 16 : if (spdm_response_size <
314 : sizeof(spdm_challenge_auth_response_t) + hash_size +
315 16 : SPDM_NONCE_SIZE + measurement_summary_hash_size +
316 16 : sizeof(uint16_t) + opaque_length + signature_size) {
317 0 : status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
318 0 : goto receive_done;
319 : }
320 16 : spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
321 16 : hash_size + SPDM_NONCE_SIZE +
322 16 : measurement_summary_hash_size + sizeof(uint16_t) +
323 16 : opaque_length + signature_size;
324 : }
325 :
326 18 : if ((opaque_data != NULL) && (opaque_data_size != NULL)) {
327 2 : if (opaque_length >= *opaque_data_size) {
328 0 : status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
329 0 : goto receive_done;
330 : }
331 2 : libspdm_copy_mem(opaque_data, *opaque_data_size, ptr, opaque_length);
332 2 : *opaque_data_size = opaque_length;
333 : }
334 :
335 18 : ptr += opaque_length;
336 18 : if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
337 2 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterContext - "));
338 2 : LIBSPDM_INTERNAL_DUMP_DATA(ptr, SPDM_REQ_CONTEXT_SIZE);
339 2 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
340 2 : if (!libspdm_consttime_is_mem_equal(spdm_request + 1, ptr, SPDM_REQ_CONTEXT_SIZE)) {
341 1 : libspdm_reset_message_c(spdm_context);
342 1 : status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
343 1 : goto receive_done;
344 : }
345 1 : ptr += SPDM_REQ_CONTEXT_SIZE;
346 : }
347 :
348 17 : status = libspdm_append_message_c(spdm_context, spdm_request, spdm_request_size);
349 17 : if (LIBSPDM_STATUS_IS_ERROR(status)) {
350 0 : goto receive_done;
351 : }
352 17 : status = libspdm_append_message_c(spdm_context, spdm_response,
353 : spdm_response_size - signature_size);
354 17 : if (LIBSPDM_STATUS_IS_ERROR(status)) {
355 0 : libspdm_reset_message_c(spdm_context);
356 0 : goto receive_done;
357 : }
358 :
359 17 : signature = ptr;
360 17 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "signature (0x%zx):\n", signature_size));
361 17 : LIBSPDM_INTERNAL_DUMP_HEX(signature, signature_size);
362 17 : result = libspdm_verify_challenge_auth_signature(spdm_context, true, slot_id,
363 : signature, signature_size);
364 17 : if (!result) {
365 1 : libspdm_reset_message_c(spdm_context);
366 1 : status = LIBSPDM_STATUS_VERIF_FAIL;
367 1 : goto receive_done;
368 : }
369 :
370 16 : if (measurement_hash != NULL) {
371 16 : libspdm_copy_mem(measurement_hash, measurement_summary_hash_size,
372 : measurement_summary_hash, measurement_summary_hash_size);
373 : }
374 16 : if (slot_mask != NULL) {
375 1 : *slot_mask = spdm_response->header.param2;
376 : }
377 :
378 : /* At this point the Requester has successfully authenticated the Responder, even if the
379 : * the Responder intends to authenticate the Requester. */
380 16 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
381 :
382 : /* -=[Update State Phase]=- */
383 : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP)
384 16 : if ((auth_attribute & SPDM_CHALLENGE_AUTH_RESPONSE_ATTRIBUTE_BASIC_MUT_AUTH_REQ) != 0) {
385 : /* we must release it here, because libspdm_encapsulated_request() will acquire again. */
386 0 : libspdm_release_receiver_buffer (spdm_context);
387 :
388 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "BasicMutAuth :\n"));
389 0 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
390 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
391 : "libspdm_challenge - libspdm_encapsulated_request - %xu\n", status));
392 0 : if (LIBSPDM_STATUS_IS_ERROR(status)) {
393 0 : libspdm_reset_message_c(spdm_context);
394 0 : return status;
395 : }
396 0 : return LIBSPDM_STATUS_SUCCESS;
397 : }
398 : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) */
399 :
400 16 : status = LIBSPDM_STATUS_SUCCESS;
401 :
402 46 : receive_done:
403 46 : libspdm_release_receiver_buffer (spdm_context);
404 46 : return status;
405 : }
406 :
407 44 : libspdm_return_t libspdm_challenge(void *spdm_context, void *reserved,
408 : uint8_t slot_id,
409 : uint8_t measurement_hash_type,
410 : void *measurement_hash,
411 : uint8_t *slot_mask)
412 : {
413 : libspdm_context_t *context;
414 : size_t retry;
415 : uint64_t retry_delay_time;
416 : libspdm_return_t status;
417 :
418 44 : context = spdm_context;
419 44 : context->crypto_request = true;
420 44 : retry = context->retry_times;
421 44 : retry_delay_time = context->retry_delay_time;
422 : do {
423 45 : status = libspdm_try_challenge(context, slot_id, NULL,
424 : measurement_hash_type,
425 : measurement_hash, slot_mask,
426 : NULL, NULL, NULL, NULL, NULL);
427 45 : if (status != LIBSPDM_STATUS_BUSY_PEER) {
428 43 : return status;
429 : }
430 :
431 2 : libspdm_sleep(retry_delay_time);
432 2 : } while (retry-- != 0);
433 :
434 1 : return status;
435 : }
436 :
437 2 : libspdm_return_t libspdm_challenge_ex(void *spdm_context, void *reserved,
438 : uint8_t slot_id,
439 : uint8_t measurement_hash_type,
440 : void *measurement_hash,
441 : uint8_t *slot_mask,
442 : const void *requester_nonce_in,
443 : void *requester_nonce,
444 : void *responder_nonce,
445 : void *opaque_data,
446 : size_t *opaque_data_size)
447 : {
448 : libspdm_context_t *context;
449 : size_t retry;
450 : uint64_t retry_delay_time;
451 : libspdm_return_t status;
452 :
453 2 : context = spdm_context;
454 2 : context->crypto_request = true;
455 2 : retry = context->retry_times;
456 2 : retry_delay_time = context->retry_delay_time;
457 : do {
458 2 : status = libspdm_try_challenge(context, slot_id, NULL,
459 : measurement_hash_type,
460 : measurement_hash,
461 : slot_mask,
462 : requester_nonce_in,
463 : requester_nonce, responder_nonce,
464 : opaque_data,
465 : opaque_data_size);
466 2 : if (status != LIBSPDM_STATUS_BUSY_PEER) {
467 2 : return status;
468 : }
469 :
470 0 : libspdm_sleep(retry_delay_time);
471 0 : } while (retry-- != 0);
472 :
473 0 : return status;
474 : }
475 :
476 2 : libspdm_return_t libspdm_challenge_ex2(void *spdm_context, void *reserved,
477 : uint8_t slot_id,
478 : const void *requester_context,
479 : uint8_t measurement_hash_type,
480 : void *measurement_hash,
481 : uint8_t *slot_mask,
482 : const void *requester_nonce_in,
483 : void *requester_nonce,
484 : void *responder_nonce,
485 : void *opaque_data,
486 : size_t *opaque_data_size)
487 : {
488 : libspdm_context_t *context;
489 : size_t retry;
490 : uint64_t retry_delay_time;
491 : libspdm_return_t status;
492 :
493 2 : context = spdm_context;
494 2 : context->crypto_request = true;
495 2 : retry = context->retry_times;
496 2 : retry_delay_time = context->retry_delay_time;
497 : do {
498 2 : status = libspdm_try_challenge(context, slot_id, requester_context,
499 : measurement_hash_type,
500 : measurement_hash,
501 : slot_mask,
502 : requester_nonce_in,
503 : requester_nonce, responder_nonce,
504 : opaque_data,
505 : opaque_data_size);
506 2 : if (status != LIBSPDM_STATUS_BUSY_PEER) {
507 2 : return status;
508 : }
509 :
510 0 : libspdm_sleep(retry_delay_time);
511 0 : } while (retry-- != 0);
512 :
513 0 : return status;
514 : }
515 :
516 : #endif /* LIBSPDM_SEND_CHALLENGE_SUPPORT */
|