From 3710a08c8a26c15c2290095b30e041ff4b87366c Mon Sep 17 00:00:00 2001 From: Jiewen Yao Date: Mon, 20 Nov 2023 17:54:11 +0800 Subject: [PATCH] Add 1.3 MEL algorithm negotiate Signed-off-by: Jiewen Yao --- include/industry_standard/spdm.h | 8 ++++-- include/internal/libspdm_common_lib.h | 1 + include/library/spdm_common_lib.h | 1 + .../libspdm_com_context_data.c | 19 ++++++++++++++ .../libspdm_req_negotiate_algorithms.c | 26 +++++++++++++++++-- .../libspdm_rsp_algorithms.c | 24 ++++++++++++++++- 6 files changed, 74 insertions(+), 5 deletions(-) diff --git a/include/industry_standard/spdm.h b/include/industry_standard/spdm.h index b323270d8a7..88af7f6ca13 100644 --- a/include/industry_standard/spdm.h +++ b/include/industry_standard/spdm.h @@ -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. @@ -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; @@ -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; diff --git a/include/internal/libspdm_common_lib.h b/include/internal/libspdm_common_lib.h index ff550476abd..4e6f8112a9b 100644 --- a/include/internal/libspdm_common_lib.h +++ b/include/internal/libspdm_common_lib.h @@ -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; diff --git a/include/library/spdm_common_lib.h b/include/library/spdm_common_lib.h index 11d1b5b9b9a..04663600d4f 100644 --- a/include/library/spdm_common_lib.h +++ b/include/library/spdm_common_lib.h @@ -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, diff --git a/library/spdm_common_lib/libspdm_com_context_data.c b/library/spdm_common_lib/libspdm_com_context_data.c index 00accb8cfae..1167aa55f73 100644 --- a/library/spdm_common_lib/libspdm_com_context_data.c +++ b/library/spdm_common_lib/libspdm_com_context_data.c @@ -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; @@ -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; diff --git a/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c b/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c index e10550fb75d..cf46793b5d2 100644 --- a/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c +++ b/library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c @@ -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; @@ -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; @@ -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 & @@ -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; @@ -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; + } + } + } } } diff --git a/library/spdm_responder_lib/libspdm_rsp_algorithms.c b/library/spdm_responder_lib/libspdm_rsp_algorithms.c index 2b56324f704..3dbb4e1e874 100644 --- a/library/spdm_responder_lib/libspdm_rsp_algorithms.c +++ b/library/spdm_responder_lib/libspdm_rsp_algorithms.c @@ -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; @@ -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; @@ -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( @@ -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) { @@ -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; }