Skip to content

CAPABILITIES: Add SupportedAlgorithms #2968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions doc/api/requester_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ returns early with value not equal to `LIBSPDM_STATUS_SUCCESS` then the SPDM con
before attempting establish a new connection.
<br/><br/>

---
### libspdm_get_supported_algorithms
---

### Description
Sends GET_VERSION and GET_CAPABILITIES requests to retrieve the Responder's supported algorithms before algorithm negotiation.

### Parameters

**spdm_context**<br/>
The SPDM context.

**algorithms**<br/>
A pointer to a libspdm_responder_supported_algorithms_t structure to store the Responder's supported algorithms.

### Details
Before calling this function the Integrator must ensure that the SPDM context is initialized
with proper configuration, including the requester's capabilities and supported cryptographic
algorithms. The Requester must support at least one SPDM version >= 1.3 and have CHUNK_CAP
capability enabled in its configuration.

When this function returns with value `LIBSPDM_STATUS_SUCCESS`, the algorithms parameter will contain
the Responder's supported algorithms that can be used for subsequent algorithm negotiation. If this
function returns with value `LIBSPDM_STATUS_UNSUPPORTED_CAP`, either the Requester does not support
version 1.3 or above, or CHUNK_CAP is not enabled.
<br/><br/>

---
### libspdm_get_digest
Expand Down
50 changes: 36 additions & 14 deletions include/industry_standard/spdm.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,41 @@ typedef struct {
uint32_t max_spdm_msg_size;
} spdm_get_capabilities_request_t;

/* SPDM GET_CAPABILITIES response*/
/* SPDM extended algorithm */
typedef struct {
uint8_t registry_id;
uint8_t reserved;
uint16_t algorithm_id;
} spdm_extended_algorithm_t;

typedef struct {
uint8_t alg_type;
uint8_t alg_count;
uint16_t alg_supported;
} spdm_negotiate_algorithms_common_struct_table_t;

/* SPDM supported algorithms block */
typedef struct {
uint8_t param1; /* Number of Algorithms Structure Tables */
uint8_t param2; /* Reserved */
uint16_t length;
uint8_t measurement_specification;
uint8_t other_params_support;
uint32_t base_asym_algo;
uint32_t base_hash_algo;
uint8_t reserved2[12];
uint8_t ext_asym_count;
uint8_t ext_hash_count;
uint8_t reserved3;
uint8_t mel_specification;
/* Followed by dynamic arrays for ext_asym, ext_hash, and struct_tableif needed
* spdm_extended_algorithm_t ext_asym[ext_asym_count];
* spdm_extended_algorithm_t ext_hash[ext_hash_count];
* spdm_negotiate_algorithms_common_struct_table_t struct_table[
* SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG];*/
} spdm_supported_algorithms_block_t;

/* SPDM GET_CAPABILITIES response*/
typedef struct {
spdm_message_header_t header;
/* param1 == RSVD
Expand All @@ -174,6 +207,8 @@ typedef struct {
/* Below field is added in 1.2.*/
uint32_t data_transfer_size;
uint32_t max_spdm_msg_size;
/* Below field is added in 1.3.*/
spdm_supported_algorithms_block_t supported_algorithms;
} spdm_capabilities_response_t;

#define SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12 42
Expand Down Expand Up @@ -357,12 +392,6 @@ typedef struct {
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_AEAD_12_MASK 0x000f
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_REQ_BASE_ASYM_ALG_12_MASK 0x0fff

typedef struct {
uint8_t alg_type;
uint8_t alg_count;
uint16_t alg_supported;
} spdm_negotiate_algorithms_common_struct_table_t;


/* SPDM NEGOTIATE_ALGORITHMS request base_asym_algo/REQ_BASE_ASYM_ALG */
#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
Expand Down Expand Up @@ -481,13 +510,6 @@ typedef struct {
/*opaque_element_table_t opaque_list[];*/
} spdm_general_opaque_data_table_header_t;

/* SPDM extended algorithm */
typedef struct {
uint8_t registry_id;
uint8_t reserved;
uint16_t algorithm_id;
} spdm_extended_algorithm_t;

/* SPDM registry_id */
#define SPDM_REGISTRY_ID_DMTF 0x0
#define SPDM_REGISTRY_ID_TCG 0x1
Expand Down
24 changes: 24 additions & 0 deletions include/internal/libspdm_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ typedef struct {
uint16_t key_schedule;
} libspdm_device_algorithm_t;

#define LIBSPDM_MAX_EXT_ALG_COUNT 5

#pragma pack(1)
typedef struct {
spdm_negotiate_algorithms_common_struct_table_t alg_struct;
spdm_extended_algorithm_t alg_external[LIBSPDM_MAX_EXT_ALG_COUNT];
} libspdm_supported_algorithms_alg_struct_t;
#pragma pack()

typedef struct {
uint8_t measurement_specification;
Comment on lines +79 to +80
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add version of the structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please help me understand the motivation for this and adding version to the name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint8_t other_params_support;
uint32_t base_asym_algo;
uint32_t base_hash_algo;
uint8_t mel_specification;
uint8_t ext_asym_count;
spdm_extended_algorithm_t ext_asym[LIBSPDM_MAX_EXT_ALG_COUNT];
uint8_t ext_hash_count;
spdm_extended_algorithm_t ext_hash[LIBSPDM_MAX_EXT_ALG_COUNT];
uint8_t struct_table_count;
libspdm_supported_algorithms_alg_struct_t
struct_table[SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG];
} libspdm_responder_supported_algorithms_t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add version to the name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be in spdm_requester_lib.h.


typedef struct {
#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
uint8_t buffer[LIBSPDM_MAX_CERT_CHAIN_SIZE];
Expand Down
7 changes: 5 additions & 2 deletions include/internal/libspdm_requester_lib.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2024 DMTF. All rights reserved.
* Copyright 2021-2025 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand Down Expand Up @@ -133,6 +133,7 @@ libspdm_return_t libspdm_get_version(libspdm_context_t *spdm_context,
* This function sends GET_CAPABILITIES and receives CAPABILITIES.
*
* @param spdm_context A pointer to the SPDM context.
* @param get_supported_algorithms If true, indicates that the requester wants the responder to include its supported algorithms in the CAPABILITIES response.
* @param RequesterCTExponent RequesterCTExponent to the GET_CAPABILITIES request.
* @param RequesterFlags RequesterFlags to the GET_CAPABILITIES request.
* @param ResponderCTExponent ResponderCTExponent from the CAPABILITIES response.
Expand All @@ -141,7 +142,9 @@ libspdm_return_t libspdm_get_version(libspdm_context_t *spdm_context,
* @retval RETURN_SUCCESS The GET_CAPABILITIES is sent and the CAPABILITIES is received.
* @retval RETURN_DEVICE_ERROR A device error occurs when communicates with the device.
**/
libspdm_return_t libspdm_get_capabilities(libspdm_context_t *spdm_context);
libspdm_return_t libspdm_get_capabilities(libspdm_context_t *spdm_context,
bool get_supported_algorithms,
libspdm_responder_supported_algorithms_t *supported_algs);
Copy link
Member

@jyao1 jyao1 Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to use void * for supported_algs, because the structure may be changed in the future version.
Also add length for the function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/**
* This function sends NEGOTIATE_ALGORITHMS and receives ALGORITHMS.
Expand Down
16 changes: 15 additions & 1 deletion include/library/spdm_requester_lib.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2024 DMTF. All rights reserved.
* Copyright 2021-2025 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand All @@ -12,6 +12,7 @@ extern "C" {
#endif

#include "library/spdm_common_lib.h"
#include "internal/libspdm_common_lib.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be removed.


/**
* This function sends GET_VERSION, GET_CAPABILITIES, NEGOTIATE_ALGORITHMS
Expand Down Expand Up @@ -491,6 +492,19 @@ libspdm_return_t libspdm_start_session(void *spdm_context, bool use_psk,
uint8_t *heartbeat_period,
void *measurement_hash);

/**
* Sends the `GET_VERSION` and `GET_CAPABILITIES` requests, where GET_CAPABILITIES.Param1[0] is set
* If the Responder supports this extended capability, the Responder will include the Supported
* Algorithms Block in its CAPABILITIES response.
*
* @param spdm_context The SPDM context.
* @param responder_supported_algorithms The responder supported algorithms.
* @retval RETURN_SUCCESS The connection is initialized successfully.
* @retval RETURN_DEVICE_ERROR A device error occurs when communicates with the device.
**/
libspdm_return_t libspdm_get_supported_algorithms(
void *spdm_context, libspdm_responder_supported_algorithms_t *responder_supported_algorithms);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to use void * for responder_supported_algorithms, because the structure may be changed in the future version.
Also add length for the function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/**
* This function sends KEY_EXCHANGE/FINISH or PSK_EXCHANGE/PSK_FINISH to start an SPDM Session.
*
Expand Down
50 changes: 48 additions & 2 deletions library/spdm_requester_lib/libspdm_req_communication.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2024 DMTF. All rights reserved.
* Copyright 2021-2025 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand All @@ -19,7 +19,7 @@ libspdm_return_t libspdm_init_connection(void *spdm_context, bool get_version_on
}

if (!get_version_only) {
status = libspdm_get_capabilities(context);
status = libspdm_get_capabilities(context, false, NULL);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
Expand All @@ -31,6 +31,52 @@ libspdm_return_t libspdm_init_connection(void *spdm_context, bool get_version_on
return LIBSPDM_STATUS_SUCCESS;
}

libspdm_return_t libspdm_get_supported_algorithms(void *spdm_context,
libspdm_responder_supported_algorithms_t *algorithms)
{
libspdm_return_t status;
libspdm_context_t *context;
bool has_version_1_3_or_above;
size_t index;

context = spdm_context;
has_version_1_3_or_above = false;

/* Verify algorithms is not NULL */
LIBSPDM_ASSERT(algorithms != NULL);

/* Pre-check: Verify requester supports at least one version >= 1.3 */
for (index = 0; index < context->local_context.version.spdm_version_count; index++) {
if (context->local_context.version.spdm_version[index] >= SPDM_MESSAGE_VERSION_13) {
has_version_1_3_or_above = true;
break;
}
}
LIBSPDM_ASSERT(has_version_1_3_or_above);
if (!has_version_1_3_or_above) {
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
}

LIBSPDM_ASSERT((context->local_context.capability.flags &
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP) != 0);

status = libspdm_get_version(context, NULL, NULL);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

if (context->connection_info.version < SPDM_MESSAGE_VERSION_13) {
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
}

status = libspdm_get_capabilities(context, true, algorithms);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

return LIBSPDM_STATUS_SUCCESS;
}

#if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
libspdm_return_t libspdm_start_session(void *spdm_context, bool use_psk,
const void *psk_hint,
Expand Down
Loading
Loading