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