@@ -211,7 +211,8 @@ static bool validate_responder_capability(uint32_t capabilities_flag, uint8_t ve
211
211
* @retval LIBSPDM_STATUS_BUFFER_FULL
212
212
* The buffer used to store transcripts is exhausted.
213
213
**/
214
- static libspdm_return_t libspdm_try_get_capabilities (libspdm_context_t * spdm_context )
214
+ static libspdm_return_t libspdm_try_get_capabilities (libspdm_context_t * spdm_context ,
215
+ bool get_supported_algorithms )
215
216
{
216
217
libspdm_return_t status ;
217
218
spdm_get_capabilities_request_t * spdm_request ;
@@ -241,6 +242,11 @@ static libspdm_return_t libspdm_try_get_capabilities(libspdm_context_t *spdm_con
241
242
spdm_context -> local_context .capability .transport_tail_size ;
242
243
243
244
LIBSPDM_ASSERT (spdm_request_size >= sizeof (spdm_request -> header ));
245
+
246
+ LIBSPDM_ASSERT (!((spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) &&
247
+ get_supported_algorithms &&
248
+ ((spdm_request -> flags & SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP ) == 0 )));
249
+
244
250
libspdm_zero_mem (spdm_request , spdm_request_size );
245
251
spdm_request -> header .spdm_version = libspdm_get_connection_version (spdm_context );
246
252
if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
@@ -258,6 +264,10 @@ static libspdm_return_t libspdm_try_get_capabilities(libspdm_context_t *spdm_con
258
264
}
259
265
spdm_request -> header .request_response_code = SPDM_GET_CAPABILITIES ;
260
266
spdm_request -> header .param1 = 0 ;
267
+ if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 &&
268
+ get_supported_algorithms ) {
269
+ spdm_request -> header .param1 |= 0x01 ;
270
+ }
261
271
spdm_request -> header .param2 = 0 ;
262
272
if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_11 ) {
263
273
spdm_request -> ct_exponent = spdm_context -> local_context .capability .ct_exponent ;
@@ -315,22 +325,60 @@ static libspdm_return_t libspdm_try_get_capabilities(libspdm_context_t *spdm_con
315
325
status = LIBSPDM_STATUS_INVALID_MSG_FIELD ;
316
326
goto receive_done ;
317
327
}
318
- if (spdm_response -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
328
+ if (spdm_response -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) {
319
329
if (spdm_response_size < sizeof (spdm_capabilities_response_t )) {
320
330
status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
321
331
goto receive_done ;
322
332
}
333
+ } else if (spdm_response -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
334
+ if (spdm_response_size < (sizeof (spdm_capabilities_response_t ) -
335
+ sizeof (spdm_supported_algorithms_block_t ))) {
336
+ status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
337
+ goto receive_done ;
338
+ }
323
339
} else {
324
- if (spdm_response_size < sizeof (spdm_capabilities_response_t ) -
325
- sizeof (spdm_response -> data_transfer_size ) - sizeof (spdm_response -> max_spdm_msg_size )) {
340
+ if (spdm_response_size < (sizeof (spdm_capabilities_response_t ) -
341
+ sizeof (spdm_supported_algorithms_block_t ) -
342
+ sizeof (spdm_response -> data_transfer_size ) -
343
+ sizeof (spdm_response -> max_spdm_msg_size ))) {
326
344
status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
327
345
goto receive_done ;
328
346
}
329
347
}
330
- if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
331
- spdm_response_size = sizeof (spdm_capabilities_response_t );
348
+
349
+ if (spdm_response -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 &&
350
+ (spdm_request -> header .param1 & 0x01 )) {
351
+
352
+ uint8_t index = 0 ;
353
+ if (spdm_context -> connection_info .capability .flags &
354
+ SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP ) {
355
+ index ++ ;
356
+ }
357
+ if ((spdm_context -> connection_info .capability .flags &
358
+ SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP ) ||
359
+ (spdm_context -> connection_info .capability .flags &
360
+ SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP )) {
361
+ index ++ ;
362
+ }
363
+ if (spdm_context -> connection_info .capability .flags &
364
+ SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP ) {
365
+ index ++ ;
366
+ }
367
+ if ((spdm_context -> connection_info .capability .flags &
368
+ SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP ) ||
369
+ (spdm_context -> connection_info .capability .flags &
370
+ SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP )) {
371
+ index ++ ;
372
+ }
373
+ spdm_response_size = sizeof (spdm_capabilities_response_t )+
374
+ index * sizeof (spdm_negotiate_algorithms_common_struct_table_t );
375
+
376
+ } else if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
377
+ spdm_response_size = sizeof (spdm_capabilities_response_t )-
378
+ sizeof (spdm_supported_algorithms_block_t );
332
379
} else {
333
380
spdm_response_size = sizeof (spdm_capabilities_response_t ) -
381
+ sizeof (spdm_supported_algorithms_block_t ) -
334
382
sizeof (spdm_response -> data_transfer_size ) -
335
383
sizeof (spdm_response -> max_spdm_msg_size );
336
384
}
@@ -397,7 +445,8 @@ static libspdm_return_t libspdm_try_get_capabilities(libspdm_context_t *spdm_con
397
445
return status ;
398
446
}
399
447
400
- libspdm_return_t libspdm_get_capabilities (libspdm_context_t * spdm_context )
448
+ libspdm_return_t libspdm_get_capabilities (libspdm_context_t * spdm_context ,
449
+ bool get_supported_algorithms )
401
450
{
402
451
size_t retry ;
403
452
uint64_t retry_delay_time ;
@@ -407,7 +456,7 @@ libspdm_return_t libspdm_get_capabilities(libspdm_context_t *spdm_context)
407
456
retry = spdm_context -> retry_times ;
408
457
retry_delay_time = spdm_context -> retry_delay_time ;
409
458
do {
410
- status = libspdm_try_get_capabilities (spdm_context );
459
+ status = libspdm_try_get_capabilities (spdm_context , get_supported_algorithms );
411
460
if (status != LIBSPDM_STATUS_BUSY_PEER ) {
412
461
return status ;
413
462
}
@@ -417,3 +466,23 @@ libspdm_return_t libspdm_get_capabilities(libspdm_context_t *spdm_context)
417
466
418
467
return status ;
419
468
}
469
+
470
+ libspdm_return_t libspdm_get_supported_algorithms (void * spdm_context )
471
+ {
472
+ libspdm_return_t status ;
473
+ libspdm_context_t * context ;
474
+
475
+ context = spdm_context ;
476
+
477
+ status = libspdm_get_version (context , NULL , NULL );
478
+ if (LIBSPDM_STATUS_IS_ERROR (status )) {
479
+ return status ;
480
+ }
481
+
482
+ status = libspdm_get_capabilities (context , true);
483
+ if (LIBSPDM_STATUS_IS_ERROR (status )) {
484
+ return status ;
485
+ }
486
+
487
+ return LIBSPDM_STATUS_SUCCESS ;
488
+ }
0 commit comments