Skip to content

Commit a9c0332

Browse files
committed
Add 1.3 MEL algorithm negotiate
Signed-off-by: Jiewen Yao <[email protected]>
1 parent 4a010ad commit a9c0332

File tree

6 files changed

+74
-5
lines changed

6 files changed

+74
-5
lines changed

include/industry_standard/spdm.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ typedef struct {
298298
uint8_t reserved2[12];
299299
uint8_t ext_asym_count;
300300
uint8_t ext_hash_count;
301-
uint16_t reserved3;
301+
uint8_t reserved3;
302+
uint8_t mel_specification;
302303
/*spdm_extended_algorithm_t ext_asym[ext_asym_count];
303304
* spdm_extended_algorithm_t ext_hash[ext_hash_count];
304305
* Below field is added in 1.1.
@@ -396,7 +397,8 @@ typedef struct {
396397
uint32_t measurement_hash_algo;
397398
uint32_t base_asym_sel;
398399
uint32_t base_hash_sel;
399-
uint8_t reserved2[12];
400+
uint8_t reserved2[11];
401+
uint8_t mel_specification_sel;
400402
uint8_t ext_asym_sel_count;
401403
uint8_t ext_hash_sel_count;
402404
uint16_t reserved3;
@@ -674,6 +676,8 @@ typedef struct {
674676
#define SPDM_MEASUREMENTS_SIGN_CONTEXT "responder-measurements signing"
675677
#define SPDM_MEASUREMENTS_SIGN_CONTEXT_SIZE (sizeof(SPDM_MEASUREMENTS_SIGN_CONTEXT) - 1)
676678

679+
#define SPDM_MEL_SPECIFICATION_DMTF 0x01
680+
677681
/* SPDM ERROR response */
678682
typedef struct {
679683
spdm_message_header_t header;

include/internal/libspdm_common_lib.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef struct {
4848
typedef struct {
4949
uint8_t measurement_spec;
5050
uint8_t other_params_support;
51+
uint8_t mel_spec;
5152
uint32_t measurement_hash_algo;
5253
uint32_t base_asym_algo;
5354
uint32_t base_hash_algo;

include/library/spdm_common_lib.h

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ typedef enum {
5151
LIBSPDM_DATA_REQ_BASE_ASYM_ALG,
5252
LIBSPDM_DATA_KEY_SCHEDULE,
5353
LIBSPDM_DATA_OTHER_PARAMS_SUPPORT,
54+
LIBSPDM_DATA_MEL_SPEC,
5455

5556
/* Connection State */
5657
LIBSPDM_DATA_CONNECTION_STATE,

library/spdm_common_lib/libspdm_com_context_data.c

+19
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,18 @@ libspdm_return_t libspdm_set_data(void *spdm_context, libspdm_data_type_t data_t
425425
return LIBSPDM_STATUS_INVALID_PARAMETER;
426426
}
427427
break;
428+
case LIBSPDM_DATA_MEL_SPEC:
429+
if (data_size != sizeof(uint8_t)) {
430+
return LIBSPDM_STATUS_INVALID_PARAMETER;
431+
}
432+
if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
433+
context->connection_info.algorithm.mel_spec = *(uint8_t *)data;
434+
} else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
435+
context->local_context.algorithm.mel_spec = *(uint8_t *)data;
436+
} else {
437+
return LIBSPDM_STATUS_INVALID_PARAMETER;
438+
}
439+
break;
428440
case LIBSPDM_DATA_CONNECTION_STATE:
429441
if (data_size != sizeof(libspdm_connection_state_t)) {
430442
return LIBSPDM_STATUS_INVALID_PARAMETER;
@@ -919,6 +931,13 @@ libspdm_return_t libspdm_get_data(void *spdm_context, libspdm_data_type_t data_t
919931
target_data_size = sizeof(uint8_t);
920932
target_data = &context->connection_info.algorithm.other_params_support;
921933
break;
934+
case LIBSPDM_DATA_MEL_SPEC:
935+
if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
936+
return LIBSPDM_STATUS_INVALID_PARAMETER;
937+
}
938+
target_data_size = sizeof(uint8_t);
939+
target_data = &context->connection_info.algorithm.mel_spec;
940+
break;
922941
case LIBSPDM_DATA_CONNECTION_STATE:
923942
if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
924943
return LIBSPDM_STATUS_INVALID_PARAMETER;

library/spdm_requester_lib/libspdm_req_negotiate_algorithms.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ typedef struct {
1717
uint8_t reserved2[12];
1818
uint8_t ext_asym_count;
1919
uint8_t ext_hash_count;
20-
uint16_t reserved3;
20+
uint8_t reserved3;
21+
uint8_t mel_specification;
2122
spdm_negotiate_algorithms_common_struct_table_t struct_table[
2223
SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG];
2324
} libspdm_negotiate_algorithms_request_mine_t;
@@ -30,7 +31,8 @@ typedef struct {
3031
uint32_t measurement_hash_algo;
3132
uint32_t base_asym_sel;
3233
uint32_t base_hash_sel;
33-
uint8_t reserved2[12];
34+
uint8_t reserved2[11];
35+
uint8_t mel_specification_sel;
3436
uint8_t ext_asym_sel_count;
3537
uint8_t ext_hash_sel_count;
3638
uint16_t reserved3;
@@ -139,6 +141,10 @@ static libspdm_return_t libspdm_try_negotiate_algorithms(libspdm_context_t *spdm
139141
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
140142
spdm_request->other_params_support =
141143
spdm_context->local_context.algorithm.other_params_support;
144+
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
145+
spdm_request->mel_specification =
146+
spdm_context->local_context.algorithm.mel_spec;
147+
}
142148
}
143149
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
144150
switch (spdm_context->connection_info.capability.flags &
@@ -373,6 +379,10 @@ static libspdm_return_t libspdm_try_negotiate_algorithms(libspdm_context_t *spdm
373379
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
374380
spdm_context->connection_info.algorithm.other_params_support =
375381
spdm_response->other_params_selection;
382+
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
383+
spdm_context->connection_info.algorithm.mel_spec =
384+
spdm_response->mel_specification_sel;
385+
}
376386
}
377387
spdm_context->connection_info.algorithm.measurement_hash_algo =
378388
spdm_response->measurement_hash_algo;
@@ -560,6 +570,18 @@ static libspdm_return_t libspdm_try_negotiate_algorithms(libspdm_context_t *spdm
560570
status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
561571
goto receive_done;
562572
}
573+
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
574+
if (libspdm_is_capabilities_flag_supported(
575+
spdm_context, true, 0,
576+
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP) &&
577+
(spdm_request->mel_specification != 0)) {
578+
if (spdm_context->connection_info.algorithm.mel_spec !=
579+
SPDM_MEL_SPECIFICATION_DMTF) {
580+
status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
581+
goto receive_done;
582+
}
583+
}
584+
}
563585
}
564586
}
565587

library/spdm_responder_lib/libspdm_rsp_algorithms.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ typedef struct {
1818
uint32_t measurement_hash_algo;
1919
uint32_t base_asym_sel;
2020
uint32_t base_hash_sel;
21-
uint8_t reserved2[12];
21+
uint8_t reserved2[11];
22+
uint8_t mel_specification_sel;
2223
uint8_t ext_asym_sel_count;
2324
uint8_t ext_hash_sel_count;
2425
uint16_t reserved3;
@@ -257,6 +258,10 @@ libspdm_return_t libspdm_get_response_algorithms(libspdm_context_t *spdm_context
257258
SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE
258259
};
259260

261+
uint32_t mel_spec_priority_table[] = {
262+
SPDM_MEL_SPECIFICATION_DMTF,
263+
};
264+
260265
spdm_request = request;
261266

262267
ext_alg_total_count = 0;
@@ -550,6 +555,10 @@ libspdm_return_t libspdm_get_response_algorithms(libspdm_context_t *spdm_context
550555
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
551556
spdm_context->connection_info.algorithm.other_params_support =
552557
spdm_request->other_params_support;
558+
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
559+
spdm_context->connection_info.algorithm.mel_spec =
560+
spdm_request->mel_specification;
561+
}
553562
}
554563

555564
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
583592
SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK,
584593
spdm_context->connection_info.algorithm.other_params_support &
585594
SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK);
595+
if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
596+
spdm_response->mel_specification_sel = (uint8_t)libspdm_prioritize_algorithm(
597+
mel_spec_priority_table,
598+
LIBSPDM_ARRAY_SIZE(mel_spec_priority_table),
599+
spdm_context->local_context.algorithm.mel_spec,
600+
spdm_context->connection_info.algorithm.mel_spec);
601+
}
586602
}
587603

588604
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
718734
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
719735
spdm_context->connection_info.algorithm.other_params_support =
720736
spdm_response->other_params_selection;
737+
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
738+
spdm_context->connection_info.algorithm.mel_spec =
739+
spdm_response->mel_specification_sel;
740+
} else {
741+
spdm_context->connection_info.algorithm.mel_spec = 0;
742+
}
721743
} else {
722744
spdm_context->connection_info.algorithm.other_params_support = 0;
723745
}

0 commit comments

Comments
 (0)