@@ -211,7 +211,7 @@ 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 , bool get_supported_algorithms )
215
215
{
216
216
libspdm_return_t status ;
217
217
spdm_get_capabilities_request_t * spdm_request ;
@@ -241,6 +241,11 @@ static libspdm_return_t libspdm_try_get_capabilities(libspdm_context_t *spdm_con
241
241
spdm_context -> local_context .capability .transport_tail_size ;
242
242
243
243
LIBSPDM_ASSERT (spdm_request_size >= sizeof (spdm_request -> header ));
244
+
245
+ LIBSPDM_ASSERT (!((spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) &&
246
+ get_supported_algorithms &&
247
+ ((spdm_request -> flags & SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP ) == 0 )));
248
+
244
249
libspdm_zero_mem (spdm_request , spdm_request_size );
245
250
spdm_request -> header .spdm_version = libspdm_get_connection_version (spdm_context );
246
251
if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
@@ -258,6 +263,10 @@ static libspdm_return_t libspdm_try_get_capabilities(libspdm_context_t *spdm_con
258
263
}
259
264
spdm_request -> header .request_response_code = SPDM_GET_CAPABILITIES ;
260
265
spdm_request -> header .param1 = 0 ;
266
+ if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 &&
267
+ get_supported_algorithms ) {
268
+ spdm_request -> header .param1 |= 0x01 ;
269
+ }
261
270
spdm_request -> header .param2 = 0 ;
262
271
if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_11 ) {
263
272
spdm_request -> ct_exponent = spdm_context -> local_context .capability .ct_exponent ;
@@ -315,22 +324,54 @@ static libspdm_return_t libspdm_try_get_capabilities(libspdm_context_t *spdm_con
315
324
status = LIBSPDM_STATUS_INVALID_MSG_FIELD ;
316
325
goto receive_done ;
317
326
}
318
- if (spdm_response -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
327
+ if (spdm_response -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) {
319
328
if (spdm_response_size < sizeof (spdm_capabilities_response_t )) {
320
329
status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
321
330
goto receive_done ;
322
331
}
332
+ } else if (spdm_response -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
333
+ if (spdm_response_size < (sizeof (spdm_capabilities_response_t ) -
334
+ sizeof (spdm_supported_algorithms_block_t ))) {
335
+ status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
336
+ goto receive_done ;
337
+ }
323
338
} 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 )) {
339
+ if (spdm_response_size < (sizeof (spdm_capabilities_response_t ) -
340
+ sizeof (spdm_supported_algorithms_block_t ) -
341
+ sizeof (spdm_response -> data_transfer_size ) -
342
+ sizeof (spdm_response -> max_spdm_msg_size ))) {
326
343
status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
327
344
goto receive_done ;
328
345
}
329
346
}
330
- if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
331
- spdm_response_size = sizeof (spdm_capabilities_response_t );
347
+
348
+ if (spdm_response -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 &&
349
+ (spdm_request -> header .param1 & 0x01 )) {
350
+
351
+ uint8_t index = 0 ;
352
+ if (spdm_context -> connection_info .capability .flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP ) {
353
+ index ++ ;
354
+ }
355
+ if ((spdm_context -> connection_info .capability .flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP ) ||
356
+ (spdm_context -> connection_info .capability .flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP )) {
357
+ index ++ ;
358
+ }
359
+ if (spdm_context -> connection_info .capability .flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP ) {
360
+ index ++ ;
361
+ }
362
+ if ((spdm_context -> connection_info .capability .flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP ) ||
363
+ (spdm_context -> connection_info .capability .flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP )) {
364
+ index ++ ;
365
+ }
366
+ spdm_response_size = sizeof (spdm_capabilities_response_t )+ index *
367
+ sizeof (spdm_negotiate_algorithms_common_struct_table_t );
368
+
369
+ } else if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
370
+ spdm_response_size = sizeof (spdm_capabilities_response_t )-
371
+ sizeof (spdm_supported_algorithms_block_t );
332
372
} else {
333
373
spdm_response_size = sizeof (spdm_capabilities_response_t ) -
374
+ sizeof (spdm_supported_algorithms_block_t ) -
334
375
sizeof (spdm_response -> data_transfer_size ) -
335
376
sizeof (spdm_response -> max_spdm_msg_size );
336
377
}
@@ -397,7 +438,7 @@ static libspdm_return_t libspdm_try_get_capabilities(libspdm_context_t *spdm_con
397
438
return status ;
398
439
}
399
440
400
- libspdm_return_t libspdm_get_capabilities (libspdm_context_t * spdm_context )
441
+ libspdm_return_t libspdm_get_capabilities (libspdm_context_t * spdm_context , bool get_supported_algorithms )
401
442
{
402
443
size_t retry ;
403
444
uint64_t retry_delay_time ;
@@ -407,7 +448,7 @@ libspdm_return_t libspdm_get_capabilities(libspdm_context_t *spdm_context)
407
448
retry = spdm_context -> retry_times ;
408
449
retry_delay_time = spdm_context -> retry_delay_time ;
409
450
do {
410
- status = libspdm_try_get_capabilities (spdm_context );
451
+ status = libspdm_try_get_capabilities (spdm_context , get_supported_algorithms );
411
452
if (status != LIBSPDM_STATUS_BUSY_PEER ) {
412
453
return status ;
413
454
}
@@ -417,3 +458,23 @@ libspdm_return_t libspdm_get_capabilities(libspdm_context_t *spdm_context)
417
458
418
459
return status ;
419
460
}
461
+
462
+ libspdm_return_t libspdm_get_supported_algorithms (void * spdm_context )
463
+ {
464
+ libspdm_return_t status ;
465
+ libspdm_context_t * context ;
466
+
467
+ context = spdm_context ;
468
+
469
+ status = libspdm_get_version (context , NULL , NULL );
470
+ if (LIBSPDM_STATUS_IS_ERROR (status )) {
471
+ return status ;
472
+ }
473
+
474
+ status = libspdm_get_capabilities (context , true);
475
+ if (LIBSPDM_STATUS_IS_ERROR (status )) {
476
+ return status ;
477
+ }
478
+
479
+ return LIBSPDM_STATUS_SUCCESS ;
480
+ }
0 commit comments