Skip to content

Commit b1dc2d7

Browse files
committed
CAPABILITIES: Add SupportedAlgorithms
fix DMTF#2279 Signed-off-by: Shital Jumbad <[email protected]>
1 parent 18a2654 commit b1dc2d7

File tree

11 files changed

+604
-83
lines changed

11 files changed

+604
-83
lines changed

doc/api/requester_api.md

+23
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,29 @@ returns early with value not equal to `LIBSPDM_STATUS_SUCCESS` then the SPDM con
3131
before attempting establish a new connection.
3232
<br/><br/>
3333

34+
---
35+
### libspdm_get_supported_algorithms
36+
---
37+
38+
### Description
39+
Sends the `GET_VERSION` and `GET_CAPABILITIES` requests, where GET_CAPABILITIES.Param1[0] is set.
40+
If the Responder supports this extended capability, the Responder will include the Supported
41+
Algorithms Block in its CAPABILITIES response. If the requester wishes to continue with the
42+
connection, they can call `libspdm_init_connection` to restart the connection process.
43+
44+
### Parameters
45+
46+
**spdm_context**<br/>
47+
The SPDM context.
48+
49+
### Details
50+
Before calling this function, the integrator must ensure that the SPDM context is initialized
51+
with the necessary configuration, including the requester's capabilities and supported
52+
cryptographic algorithms. When this function returns with the value `RETURN_SUCCESS`,
53+
the SPDM context can be queried to determine the capabilities and algorithms supported
54+
by the responder. If this function returns with a value not equal to `RETURN_SUCCESS`,
55+
the SPDM context should be reset before attempting to establish a new connection.
56+
<br/><br/>
3457

3558
---
3659
### libspdm_get_digest

include/industry_standard/spdm.h

+56-14
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,61 @@ typedef struct {
161161
uint32_t max_spdm_msg_size;
162162
} spdm_get_capabilities_request_t;
163163

164-
/* SPDM GET_CAPABILITIES response*/
164+
/* SPDM extended algorithm */
165+
typedef struct {
166+
uint8_t registry_id;
167+
uint8_t reserved;
168+
uint16_t algorithm_id;
169+
} spdm_extended_algorithm_t;
170+
171+
typedef struct {
172+
uint8_t alg_type;
173+
uint8_t alg_count;
174+
uint16_t alg_supported;
175+
} spdm_negotiate_algorithms_common_struct_table_t;
165176

177+
/* SPDM supported algorithms block */
178+
typedef struct {
179+
uint8_t param1; /* Number of Algorithms Structure Tables */
180+
uint8_t param2; /* Reserved */
181+
uint16_t length;
182+
uint8_t measurement_specification;
183+
uint8_t other_params_support;
184+
uint32_t base_asym_algo;
185+
uint32_t base_hash_algo;
186+
uint8_t reserved2[12];
187+
uint8_t ext_asym_count;
188+
uint8_t ext_hash_count;
189+
uint8_t reserved3;
190+
uint8_t mel_specification;
191+
/* Followed by dynamic arrays for ext_asym, ext_hash, and struct_tableif needed
192+
* spdm_extended_algorithm_t ext_asym[ext_asym_count];
193+
* spdm_extended_algorithm_t ext_hash[ext_hash_count];
194+
* spdm_negotiate_algorithms_common_struct_table_t struct_table[
195+
* SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG];*/
196+
} spdm_supported_algorithms_block_t;
197+
198+
/* Specification states that total Extended algorithms count is less than or equal to 20*/
199+
#define SPDM_ALGORITHMS_MAX_NUM_EXT_ASYM_COUNT 20
200+
#define SPDM_ALGORITHMS_MAX_NUM_EXT_HASH_COUNT 20
201+
#define SPDM_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG 4
202+
203+
/* SPDM supported algorithms by responder */
204+
typedef struct {
205+
uint8_t measurement_specification;
206+
uint8_t other_params_support;
207+
uint32_t base_asym_algo;
208+
uint32_t base_hash_algo;
209+
uint8_t ext_asym_count;
210+
uint8_t ext_hash_count;
211+
uint8_t mel_specification;
212+
spdm_extended_algorithm_t ext_asym[SPDM_ALGORITHMS_MAX_NUM_EXT_ASYM_COUNT];
213+
spdm_extended_algorithm_t ext_hash[SPDM_ALGORITHMS_MAX_NUM_EXT_HASH_COUNT];
214+
spdm_negotiate_algorithms_common_struct_table_t struct_table[
215+
SPDM_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG];
216+
} spdm_responder_supported_algorithms_t;
217+
218+
/* SPDM GET_CAPABILITIES response*/
166219
typedef struct {
167220
spdm_message_header_t header;
168221
/* param1 == RSVD
@@ -174,6 +227,8 @@ typedef struct {
174227
/* Below field is added in 1.2.*/
175228
uint32_t data_transfer_size;
176229
uint32_t max_spdm_msg_size;
230+
/* Below field is added in 1.3.*/
231+
spdm_supported_algorithms_block_t supported_algorithms;
177232
} spdm_capabilities_response_t;
178233

179234
#define SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12 42
@@ -357,12 +412,6 @@ typedef struct {
357412
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_AEAD_12_MASK 0x000f
358413
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_REQ_BASE_ASYM_ALG_12_MASK 0x0fff
359414

360-
typedef struct {
361-
uint8_t alg_type;
362-
uint8_t alg_count;
363-
uint16_t alg_supported;
364-
} spdm_negotiate_algorithms_common_struct_table_t;
365-
366415

367416
/* SPDM NEGOTIATE_ALGORITHMS request base_asym_algo/REQ_BASE_ASYM_ALG */
368417
#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
@@ -481,13 +530,6 @@ typedef struct {
481530
/*opaque_element_table_t opaque_list[];*/
482531
} spdm_general_opaque_data_table_header_t;
483532

484-
/* SPDM extended algorithm */
485-
typedef struct {
486-
uint8_t registry_id;
487-
uint8_t reserved;
488-
uint16_t algorithm_id;
489-
} spdm_extended_algorithm_t;
490-
491533
/* SPDM registry_id */
492534
#define SPDM_REGISTRY_ID_DMTF 0x0
493535
#define SPDM_REGISTRY_ID_TCG 0x1

include/internal/libspdm_requester_lib.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2024 DMTF. All rights reserved.
3+
* Copyright 2021-2025 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -133,6 +133,7 @@ libspdm_return_t libspdm_get_version(libspdm_context_t *spdm_context,
133133
* This function sends GET_CAPABILITIES and receives CAPABILITIES.
134134
*
135135
* @param spdm_context A pointer to the SPDM context.
136+
* @param get_supported_algorithms If true, indicates that the requester wants the responder to include its supported algorithms in the CAPABILITIES response.
136137
* @param RequesterCTExponent RequesterCTExponent to the GET_CAPABILITIES request.
137138
* @param RequesterFlags RequesterFlags to the GET_CAPABILITIES request.
138139
* @param ResponderCTExponent ResponderCTExponent from the CAPABILITIES response.
@@ -141,7 +142,9 @@ libspdm_return_t libspdm_get_version(libspdm_context_t *spdm_context,
141142
* @retval RETURN_SUCCESS The GET_CAPABILITIES is sent and the CAPABILITIES is received.
142143
* @retval RETURN_DEVICE_ERROR A device error occurs when communicates with the device.
143144
**/
144-
libspdm_return_t libspdm_get_capabilities(libspdm_context_t *spdm_context);
145+
libspdm_return_t libspdm_get_capabilities(libspdm_context_t *spdm_context,
146+
bool get_supported_algorithms,
147+
spdm_responder_supported_algorithms_t *supported_algs);
145148

146149
/**
147150
* This function sends NEGOTIATE_ALGORITHMS and receives ALGORITHMS.

include/library/spdm_requester_lib.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2024 DMTF. All rights reserved.
3+
* Copyright 2021-2025 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -491,6 +491,19 @@ libspdm_return_t libspdm_start_session(void *spdm_context, bool use_psk,
491491
uint8_t *heartbeat_period,
492492
void *measurement_hash);
493493

494+
/**
495+
* Sends the `GET_VERSION` and `GET_CAPABILITIES` requests, where GET_CAPABILITIES.Param1[0] is set
496+
* If the Responder supports this extended capability, the Responder will include the Supported
497+
* Algorithms Block in its CAPABILITIES response.
498+
*
499+
* @param spdm_context The SPDM context.
500+
*
501+
* @retval RETURN_SUCCESS The connection is initialized successfully.
502+
* @retval RETURN_DEVICE_ERROR A device error occurs when communicates with the device.
503+
**/
504+
libspdm_return_t libspdm_get_supported_algorithms(
505+
void *spdm_context, void *responder_supported_algorithms);
506+
494507
/**
495508
* This function sends KEY_EXCHANGE/FINISH or PSK_EXCHANGE/PSK_FINISH to start an SPDM Session.
496509
*

library/spdm_requester_lib/libspdm_req_communication.c

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2024 DMTF. All rights reserved.
3+
* Copyright 2021-2025 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -19,7 +19,7 @@ libspdm_return_t libspdm_init_connection(void *spdm_context, bool get_version_on
1919
}
2020

2121
if (!get_version_only) {
22-
status = libspdm_get_capabilities(context);
22+
status = libspdm_get_capabilities(context, false, NULL);
2323
if (LIBSPDM_STATUS_IS_ERROR(status)) {
2424
return status;
2525
}
@@ -31,6 +31,51 @@ libspdm_return_t libspdm_init_connection(void *spdm_context, bool get_version_on
3131
return LIBSPDM_STATUS_SUCCESS;
3232
}
3333

34+
libspdm_return_t libspdm_get_supported_algorithms(void *spdm_context,
35+
void *responder_supported_algorithms)
36+
{
37+
libspdm_return_t status;
38+
libspdm_context_t *context;
39+
spdm_responder_supported_algorithms_t *algorithms;
40+
bool has_version_1_3_or_above;
41+
size_t index;
42+
43+
context = spdm_context;
44+
algorithms = responder_supported_algorithms;
45+
has_version_1_3_or_above = false;
46+
47+
/* Pre-check: Verify requester supports at least one version >= 1.3 */
48+
for (index = 0; index < context->local_context.version.spdm_version_count; index++) {
49+
if (context->local_context.version.spdm_version[index] >= SPDM_MESSAGE_VERSION_13) {
50+
has_version_1_3_or_above = true;
51+
break;
52+
}
53+
}
54+
LIBSPDM_ASSERT(has_version_1_3_or_above);
55+
if (!has_version_1_3_or_above) {
56+
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
57+
}
58+
59+
LIBSPDM_ASSERT((context->local_context.capability.flags &
60+
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP) != 0);
61+
62+
status = libspdm_get_version(context, NULL, NULL);
63+
if (LIBSPDM_STATUS_IS_ERROR(status)) {
64+
return status;
65+
}
66+
67+
if (context->connection_info.version < SPDM_MESSAGE_VERSION_13) {
68+
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
69+
}
70+
71+
status = libspdm_get_capabilities(context, true, algorithms);
72+
if (LIBSPDM_STATUS_IS_ERROR(status)) {
73+
return status;
74+
}
75+
76+
return LIBSPDM_STATUS_SUCCESS;
77+
}
78+
3479
#if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
3580
libspdm_return_t libspdm_start_session(void *spdm_context, bool use_psk,
3681
const void *psk_hint,

0 commit comments

Comments
 (0)