Skip to content

Commit

Permalink
Add 1.3 MEL algorithm negotiate
Browse files Browse the repository at this point in the history
Signed-off-by: Jiewen Yao <[email protected]>
  • Loading branch information
jyao1 committed Nov 21, 2023
1 parent 3bab714 commit 3710a08
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
8 changes: 6 additions & 2 deletions include/industry_standard/spdm.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ typedef struct {
uint8_t reserved2[12];
uint8_t ext_asym_count;
uint8_t ext_hash_count;
uint16_t reserved3;
uint8_t reserved3;
uint8_t mel_specification;
/*spdm_extended_algorithm_t ext_asym[ext_asym_count];
* spdm_extended_algorithm_t ext_hash[ext_hash_count];
* Below field is added in 1.1.
Expand Down Expand Up @@ -396,7 +397,8 @@ typedef struct {
uint32_t measurement_hash_algo;
uint32_t base_asym_sel;
uint32_t base_hash_sel;
uint8_t reserved2[12];
uint8_t reserved2[11];
uint8_t mel_specification_sel;
uint8_t ext_asym_sel_count;
uint8_t ext_hash_sel_count;
uint16_t reserved3;
Expand Down Expand Up @@ -674,6 +676,8 @@ typedef struct {
#define SPDM_MEASUREMENTS_SIGN_CONTEXT "responder-measurements signing"
#define SPDM_MEASUREMENTS_SIGN_CONTEXT_SIZE (sizeof(SPDM_MEASUREMENTS_SIGN_CONTEXT) - 1)

#define SPDM_MEL_SPECIFICATION_DMTF 0x01

/* SPDM ERROR response */
typedef struct {
spdm_message_header_t header;
Expand Down
1 change: 1 addition & 0 deletions include/internal/libspdm_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef struct {
typedef struct {
uint8_t measurement_spec;
uint8_t other_params_support;
uint8_t mel_spec;
uint32_t measurement_hash_algo;
uint32_t base_asym_algo;
uint32_t base_hash_algo;
Expand Down
1 change: 1 addition & 0 deletions include/library/spdm_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef enum {
LIBSPDM_DATA_REQ_BASE_ASYM_ALG,
LIBSPDM_DATA_KEY_SCHEDULE,
LIBSPDM_DATA_OTHER_PARAMS_SUPPORT,
LIBSPDM_DATA_MEL_SPEC,

/* Connection State */
LIBSPDM_DATA_CONNECTION_STATE,
Expand Down
19 changes: 19 additions & 0 deletions library/spdm_common_lib/libspdm_com_context_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ libspdm_return_t libspdm_set_data(void *spdm_context, libspdm_data_type_t data_t
return LIBSPDM_STATUS_INVALID_PARAMETER;
}
break;
case LIBSPDM_DATA_MEL_SPEC:
if (data_size != sizeof(uint8_t)) {
return LIBSPDM_STATUS_INVALID_PARAMETER;
}
if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
context->connection_info.algorithm.mel_spec = *(uint8_t *)data;
} else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
context->local_context.algorithm.mel_spec = *(uint8_t *)data;
} else {
return LIBSPDM_STATUS_INVALID_PARAMETER;
}
break;
case LIBSPDM_DATA_CONNECTION_STATE:
if (data_size != sizeof(libspdm_connection_state_t)) {
return LIBSPDM_STATUS_INVALID_PARAMETER;
Expand Down Expand Up @@ -900,6 +912,13 @@ libspdm_return_t libspdm_get_data(void *spdm_context, libspdm_data_type_t data_t
target_data_size = sizeof(uint8_t);
target_data = &context->connection_info.algorithm.other_params_support;
break;
case LIBSPDM_DATA_MEL_SPEC:
if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
return LIBSPDM_STATUS_INVALID_PARAMETER;
}
target_data_size = sizeof(uint8_t);
target_data = &context->connection_info.algorithm.mel_spec;
break;
case LIBSPDM_DATA_CONNECTION_STATE:
if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
return LIBSPDM_STATUS_INVALID_PARAMETER;
Expand Down
26 changes: 24 additions & 2 deletions library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ typedef struct {
uint8_t reserved2[12];
uint8_t ext_asym_count;
uint8_t ext_hash_count;
uint16_t reserved3;
uint8_t reserved3;
uint8_t mel_specification;
spdm_negotiate_algorithms_common_struct_table_t struct_table[
SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG];
} libspdm_negotiate_algorithms_request_mine_t;
Expand All @@ -30,7 +31,8 @@ typedef struct {
uint32_t measurement_hash_algo;
uint32_t base_asym_sel;
uint32_t base_hash_sel;
uint8_t reserved2[12];
uint8_t reserved2[11];
uint8_t mel_specification_sel;
uint8_t ext_asym_sel_count;
uint8_t ext_hash_sel_count;
uint16_t reserved3;
Expand Down Expand Up @@ -139,6 +141,10 @@ static libspdm_return_t libspdm_try_negotiate_algorithms(libspdm_context_t *spdm
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
spdm_request->other_params_support =
spdm_context->local_context.algorithm.other_params_support;
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
spdm_request->mel_specification =
spdm_context->local_context.algorithm.mel_spec;
}
}
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
switch (spdm_context->connection_info.capability.flags &
Expand Down Expand Up @@ -373,6 +379,10 @@ static libspdm_return_t libspdm_try_negotiate_algorithms(libspdm_context_t *spdm
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
spdm_context->connection_info.algorithm.other_params_support =
spdm_response->other_params_selection;
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
spdm_context->connection_info.algorithm.mel_spec =
spdm_response->mel_specification_sel;
}
}
spdm_context->connection_info.algorithm.measurement_hash_algo =
spdm_response->measurement_hash_algo;
Expand Down Expand Up @@ -560,6 +570,18 @@ static libspdm_return_t libspdm_try_negotiate_algorithms(libspdm_context_t *spdm
status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
goto receive_done;
}
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
if (libspdm_is_capabilities_flag_supported(
spdm_context, true, 0,
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP) &&
(spdm_request->mel_specification != 0)) {
if (spdm_context->connection_info.algorithm.mel_spec !=
SPDM_MEL_SPECIFICATION_DMTF) {
status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
goto receive_done;
}
}
}
}
}

Expand Down
24 changes: 23 additions & 1 deletion library/spdm_responder_lib/libspdm_rsp_algorithms.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ typedef struct {
uint32_t measurement_hash_algo;
uint32_t base_asym_sel;
uint32_t base_hash_sel;
uint8_t reserved2[12];
uint8_t reserved2[11];
uint8_t mel_specification_sel;
uint8_t ext_asym_sel_count;
uint8_t ext_hash_sel_count;
uint16_t reserved3;
Expand Down Expand Up @@ -257,6 +258,10 @@ libspdm_return_t libspdm_get_response_algorithms(libspdm_context_t *spdm_context
SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE
};

uint32_t mel_spec_priority_table[] = {
SPDM_MEL_SPECIFICATION_DMTF,
};

spdm_request = request;

ext_alg_total_count = 0;
Expand Down Expand Up @@ -550,6 +555,10 @@ libspdm_return_t libspdm_get_response_algorithms(libspdm_context_t *spdm_context
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
spdm_context->connection_info.algorithm.other_params_support =
spdm_request->other_params_support;
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
spdm_context->connection_info.algorithm.mel_spec =
spdm_request->mel_specification;
}
}

spdm_response->measurement_specification_sel = (uint8_t)libspdm_prioritize_algorithm(
Expand Down Expand Up @@ -583,6 +592,13 @@ libspdm_return_t libspdm_get_response_algorithms(libspdm_context_t *spdm_context
SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK,
spdm_context->connection_info.algorithm.other_params_support &
SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK);
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
spdm_response->mel_specification_sel = (uint8_t)libspdm_prioritize_algorithm(
mel_spec_priority_table,
LIBSPDM_ARRAY_SIZE(mel_spec_priority_table),
spdm_context->local_context.algorithm.mel_spec,
spdm_context->connection_info.algorithm.mel_spec);
}
}

if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
Expand Down Expand Up @@ -718,6 +734,12 @@ libspdm_return_t libspdm_get_response_algorithms(libspdm_context_t *spdm_context
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
spdm_context->connection_info.algorithm.other_params_support =
spdm_response->other_params_selection;
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
spdm_context->connection_info.algorithm.mel_spec =
spdm_response->mel_specification_sel;
} else {
spdm_context->connection_info.algorithm.mel_spec = 0;
}
} else {
spdm_context->connection_info.algorithm.other_params_support = 0;
}
Expand Down

0 comments on commit 3710a08

Please sign in to comment.