LCOV - code coverage report
Current view: top level - unit_test/test_spdm_responder - key_exchange_rsp.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 99.7 % 1061 1058
Test Date: 2026-02-22 08:11:49 Functions: 100.0 % 23 23

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2021-2026 DMTF. All rights reserved.
       4              :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
       5              :  **/
       6              : 
       7              : #include "spdm_unit_test.h"
       8              : #include "internal/libspdm_responder_lib.h"
       9              : #include "internal/libspdm_requester_lib.h"
      10              : 
      11              : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
      12              : 
      13              : #pragma pack(1)
      14              : typedef struct {
      15              :     spdm_message_header_t header;
      16              :     uint16_t req_session_id;
      17              :     uint8_t session_policy;
      18              :     uint8_t reserved;
      19              :     uint8_t random_data[SPDM_RANDOM_DATA_SIZE];
      20              :     uint8_t exchange_data[LIBSPDM_MAX_DHE_KEY_SIZE];
      21              :     uint16_t opaque_length;
      22              :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
      23              : } libspdm_key_exchange_request_mine_t;
      24              : #pragma pack()
      25              : 
      26              : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request1 = {
      27              :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
      28              :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
      29              : };
      30              : size_t m_libspdm_key_exchange_request1_size = sizeof(m_libspdm_key_exchange_request1);
      31              : 
      32              : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request2 = {
      33              :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
      34              :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
      35              : };
      36              : size_t m_libspdm_key_exchange_request2_size = sizeof(spdm_key_exchange_request_t);
      37              : 
      38              : /* Request TCB measurement hash */
      39              : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request3 = {
      40              :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
      41              :       SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0 },
      42              : };
      43              : size_t m_libspdm_key_exchange_request3_size = sizeof(m_libspdm_key_exchange_request3);
      44              : 
      45              : /* Request all measurement hash */
      46              : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request4 = {
      47              :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
      48              :       SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0 },
      49              : };
      50              : size_t m_libspdm_key_exchange_request4_size = sizeof(m_libspdm_key_exchange_request4);
      51              : 
      52              : /* Uses a reserved value in measurement hash */
      53              : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request5 = {
      54              :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
      55              :       0x50, 0 },
      56              : };
      57              : size_t m_libspdm_key_exchange_request5_size = sizeof(m_libspdm_key_exchange_request5);
      58              : 
      59              : /* Asks for certificate in slot 1 */
      60              : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request6 = {
      61              :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
      62              :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 1 },
      63              : };
      64              : size_t m_libspdm_key_exchange_request6_size = sizeof(m_libspdm_key_exchange_request6);
      65              : 
      66              : /* Asks for previously provisioned raw public key */
      67              : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request7 = {
      68              :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
      69              :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0xFF },
      70              : };
      71              : size_t m_libspdm_key_exchange_request7_size = sizeof(m_libspdm_key_exchange_request7);
      72              : 
      73              : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request8 = {
      74              :     { SPDM_MESSAGE_VERSION_12, SPDM_KEY_EXCHANGE,
      75              :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
      76              : };
      77              : size_t m_libspdm_key_exchange_request8_size = sizeof(m_libspdm_key_exchange_request8);
      78              : 
      79              : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request9 = {
      80              :     { SPDM_MESSAGE_VERSION_11, SPDM_KEY_EXCHANGE,
      81              :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 9 },
      82              : };
      83              : size_t m_libspdm_key_exchange_request9_size = sizeof(m_libspdm_key_exchange_request9);
      84              : 
      85              : libspdm_key_exchange_request_mine_t m_libspdm_key_exchange_request10 = {
      86              :     { SPDM_MESSAGE_VERSION_13, SPDM_KEY_EXCHANGE,
      87              :       SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0 },
      88              : };
      89              : size_t m_libspdm_key_exchange_request10_size = sizeof(m_libspdm_key_exchange_request10);
      90              : 
      91              : extern uint8_t g_key_exchange_start_mut_auth;
      92              : extern bool g_mandatory_mut_auth;
      93              : 
      94              : extern bool g_event_all_subscribe;
      95              : extern bool g_event_all_unsubscribe;
      96              : 
      97            1 : static void rsp_key_exchange_rsp_case1(void **state)
      98              : {
      99              :     libspdm_return_t status;
     100              :     libspdm_test_context_t *spdm_test_context;
     101              :     libspdm_context_t *spdm_context;
     102              :     size_t response_size;
     103              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     104              :     spdm_key_exchange_response_t *spdm_response;
     105              :     void *data1;
     106              :     size_t data_size1;
     107              :     uint8_t *ptr;
     108              :     size_t dhe_key_size;
     109              :     void *dhe_context;
     110              :     size_t opaque_key_exchange_req_size;
     111              :     uint32_t session_id;
     112              : 
     113            1 :     spdm_test_context = *state;
     114            1 :     spdm_context = spdm_test_context->spdm_context;
     115            1 :     spdm_test_context->case_id = 0x1;
     116            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     117            1 :     spdm_context->connection_info.capability.flags |=
     118              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     119              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     120            1 :     spdm_context->local_context.capability.flags |=
     121              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     122              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
     123              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
     124            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     125            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     126            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     127            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     128              :         m_libspdm_use_measurement_hash_algo;
     129            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     130            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     131            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     132              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     133            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     134              :                                                     m_libspdm_use_asym_algo, &data1,
     135              :                                                     &data_size1, NULL, NULL);
     136            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     137            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     138              : 
     139            1 :     libspdm_reset_message_a(spdm_context);
     140              : 
     141            1 :     spdm_context->local_context.secured_message_version.secured_message_version_count = 1;
     142              : 
     143            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request1.random_data);
     144            1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
     145            1 :     m_libspdm_key_exchange_request1.reserved = 0;
     146            1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
     147            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     148            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
     149              :                                   false);
     150            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
     151            1 :     ptr += dhe_key_size;
     152            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     153            1 :     opaque_key_exchange_req_size =
     154            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
     155            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
     156            1 :     ptr += sizeof(uint16_t);
     157            1 :     libspdm_build_opaque_data_supported_version_data(
     158              :         spdm_context, &opaque_key_exchange_req_size, ptr);
     159            1 :     ptr += opaque_key_exchange_req_size;
     160            1 :     response_size = sizeof(response);
     161            1 :     status = libspdm_get_response_key_exchange(
     162              :         spdm_context, m_libspdm_key_exchange_request1_size,
     163              :         &m_libspdm_key_exchange_request1, &response_size, response);
     164            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     165            1 :     assert_int_equal(
     166              :         libspdm_secured_message_get_session_state(
     167              :             spdm_context->session_info[0].secured_message_context),
     168              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
     169            1 :     spdm_response = (void *)response;
     170            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
     171            1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
     172              : 
     173            1 :     session_id = (m_libspdm_key_exchange_request1.req_session_id << 16) |
     174            1 :                  spdm_response->rsp_session_id;
     175            1 :     libspdm_free_session_id(spdm_context, session_id);
     176            1 :     free(data1);
     177            1 : }
     178              : 
     179            1 : static void rsp_key_exchange_rsp_case2(void **state)
     180              : {
     181              :     libspdm_return_t status;
     182              :     libspdm_test_context_t *spdm_test_context;
     183              :     libspdm_context_t *spdm_context;
     184              :     size_t response_size;
     185              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     186              :     spdm_key_exchange_response_t *spdm_response;
     187              :     void *data1;
     188              :     size_t data_size1;
     189              :     uint8_t *ptr;
     190              :     size_t dhe_key_size;
     191              :     void *dhe_context;
     192              :     size_t opaque_key_exchange_req_size;
     193              : 
     194            1 :     spdm_test_context = *state;
     195            1 :     spdm_context = spdm_test_context->spdm_context;
     196            1 :     spdm_test_context->case_id = 0x2;
     197            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     198            1 :     spdm_context->connection_info.capability.flags |=
     199              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     200              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     201            1 :     spdm_context->local_context.capability.flags |=
     202              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     203              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     204            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     205            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     206            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     207            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     208              :         m_libspdm_use_measurement_hash_algo;
     209            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     210            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     211            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     212              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     213            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     214              :                                                     m_libspdm_use_asym_algo, &data1,
     215              :                                                     &data_size1, NULL, NULL);
     216            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     217            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     218              : 
     219            1 :     libspdm_reset_message_a(spdm_context);
     220              : 
     221            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request2.random_data);
     222            1 :     m_libspdm_key_exchange_request2.req_session_id = 0xFFFF;
     223            1 :     m_libspdm_key_exchange_request2.reserved = 0;
     224            1 :     ptr = m_libspdm_key_exchange_request2.exchange_data;
     225            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     226            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
     227              :                                   false);
     228            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
     229            1 :     ptr += dhe_key_size;
     230            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     231            1 :     opaque_key_exchange_req_size =
     232            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
     233            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
     234            1 :     ptr += sizeof(uint16_t);
     235            1 :     libspdm_build_opaque_data_supported_version_data(
     236              :         spdm_context, &opaque_key_exchange_req_size, ptr);
     237            1 :     ptr += opaque_key_exchange_req_size;
     238            1 :     response_size = sizeof(response);
     239            1 :     status = libspdm_get_response_key_exchange(
     240              :         spdm_context, m_libspdm_key_exchange_request2_size,
     241              :         &m_libspdm_key_exchange_request2, &response_size, response);
     242            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     243            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     244            1 :     spdm_response = (void *)response;
     245            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     246            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
     247            1 :     assert_int_equal(spdm_response->header.param2, 0);
     248            1 :     free(data1);
     249            1 : }
     250              : 
     251            1 : static void rsp_key_exchange_rsp_case3(void **state)
     252              : {
     253              :     libspdm_return_t status;
     254              :     libspdm_test_context_t *spdm_test_context;
     255              :     libspdm_context_t *spdm_context;
     256              :     size_t response_size;
     257              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     258              :     spdm_key_exchange_response_t *spdm_response;
     259              :     void *data1;
     260              :     size_t data_size1;
     261              :     uint8_t *ptr;
     262              :     size_t dhe_key_size;
     263              :     void *dhe_context;
     264              :     size_t opaque_key_exchange_req_size;
     265              : 
     266            1 :     spdm_test_context = *state;
     267            1 :     spdm_context = spdm_test_context->spdm_context;
     268            1 :     spdm_test_context->case_id = 0x3;
     269            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
     270            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     271            1 :     spdm_context->connection_info.capability.flags |=
     272              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     273              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     274            1 :     spdm_context->local_context.capability.flags |=
     275              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     276              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     277            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     278            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     279            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     280            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     281              :         m_libspdm_use_measurement_hash_algo;
     282            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     283            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     284            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     285              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     286            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     287              :                                                     m_libspdm_use_asym_algo, &data1,
     288              :                                                     &data_size1, NULL, NULL);
     289            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     290            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     291              : 
     292            1 :     libspdm_reset_message_a(spdm_context);
     293              : 
     294            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request1.random_data);
     295            1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
     296            1 :     m_libspdm_key_exchange_request1.reserved = 0;
     297            1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
     298            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     299            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
     300              :                                   false);
     301            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
     302            1 :     ptr += dhe_key_size;
     303            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     304            1 :     opaque_key_exchange_req_size =
     305            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
     306            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
     307            1 :     ptr += sizeof(uint16_t);
     308            1 :     libspdm_build_opaque_data_supported_version_data(
     309              :         spdm_context, &opaque_key_exchange_req_size, ptr);
     310            1 :     ptr += opaque_key_exchange_req_size;
     311            1 :     response_size = sizeof(response);
     312            1 :     status = libspdm_get_response_key_exchange(
     313              :         spdm_context, m_libspdm_key_exchange_request1_size,
     314              :         &m_libspdm_key_exchange_request1, &response_size, response);
     315            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     316            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     317            1 :     spdm_response = (void *)response;
     318            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     319            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
     320            1 :     assert_int_equal(spdm_response->header.param2, 0);
     321            1 :     assert_int_equal(spdm_context->response_state, LIBSPDM_RESPONSE_STATE_BUSY);
     322            1 :     free(data1);
     323            1 : }
     324              : 
     325            1 : static void rsp_key_exchange_rsp_case4(void **state)
     326              : {
     327              :     libspdm_return_t status;
     328              :     libspdm_test_context_t *spdm_test_context;
     329              :     libspdm_context_t *spdm_context;
     330              :     size_t response_size;
     331              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     332              :     spdm_key_exchange_response_t *spdm_response;
     333              :     void *data1;
     334              :     size_t data_size1;
     335              :     uint8_t *ptr;
     336              :     size_t dhe_key_size;
     337              :     void *dhe_context;
     338              :     size_t opaque_key_exchange_req_size;
     339              : 
     340            1 :     spdm_test_context = *state;
     341            1 :     spdm_context = spdm_test_context->spdm_context;
     342            1 :     spdm_test_context->case_id = 0x4;
     343            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC;
     344            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     345            1 :     spdm_context->connection_info.capability.flags |=
     346              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     347              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     348            1 :     spdm_context->local_context.capability.flags |=
     349              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     350              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     351            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     352            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     353            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     354            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     355              :         m_libspdm_use_measurement_hash_algo;
     356            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     357            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     358            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     359              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     360            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     361              :                                                     m_libspdm_use_asym_algo, &data1,
     362              :                                                     &data_size1, NULL, NULL);
     363            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     364            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     365              : 
     366            1 :     libspdm_reset_message_a(spdm_context);
     367              : 
     368            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request1.random_data);
     369            1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
     370            1 :     m_libspdm_key_exchange_request1.reserved = 0;
     371            1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
     372            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     373            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
     374              :                                   false);
     375            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
     376            1 :     ptr += dhe_key_size;
     377            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     378            1 :     opaque_key_exchange_req_size =
     379            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
     380            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
     381            1 :     ptr += sizeof(uint16_t);
     382            1 :     libspdm_build_opaque_data_supported_version_data(
     383              :         spdm_context, &opaque_key_exchange_req_size, ptr);
     384            1 :     ptr += opaque_key_exchange_req_size;
     385            1 :     response_size = sizeof(response);
     386            1 :     status = libspdm_get_response_key_exchange(
     387              :         spdm_context, m_libspdm_key_exchange_request1_size,
     388              :         &m_libspdm_key_exchange_request1, &response_size, response);
     389            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     390            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     391            1 :     spdm_response = (void *)response;
     392            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     393            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_REQUEST_RESYNCH);
     394            1 :     assert_int_equal(spdm_response->header.param2, 0);
     395            1 :     assert_int_equal(spdm_context->response_state, LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
     396            1 :     free(data1);
     397            1 : }
     398              : 
     399              : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
     400            1 : static void rsp_key_exchange_rsp_case5(void **state)
     401              : {
     402              :     libspdm_return_t status;
     403              :     libspdm_test_context_t *spdm_test_context;
     404              :     libspdm_context_t *spdm_context;
     405              :     size_t response_size;
     406              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     407              :     spdm_key_exchange_response_t *spdm_response;
     408              :     void *data1;
     409              :     size_t data_size1;
     410              :     spdm_error_data_response_not_ready_t *error_data;
     411              :     uint8_t *ptr;
     412              :     size_t dhe_key_size;
     413              :     void *dhe_context;
     414              :     size_t opaque_key_exchange_req_size;
     415              : 
     416            1 :     spdm_test_context = *state;
     417            1 :     spdm_context = spdm_test_context->spdm_context;
     418            1 :     spdm_test_context->case_id = 0x5;
     419            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY;
     420            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     421            1 :     spdm_context->connection_info.capability.flags |=
     422              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     423              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     424            1 :     spdm_context->local_context.capability.flags |=
     425              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     426              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     427            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     428            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     429            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     430            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     431              :         m_libspdm_use_measurement_hash_algo;
     432            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     433            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     434            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     435              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     436            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     437              :                                                     m_libspdm_use_asym_algo, &data1,
     438              :                                                     &data_size1, NULL, NULL);
     439            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     440            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     441              : 
     442            1 :     libspdm_reset_message_a(spdm_context);
     443              : 
     444            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request1.random_data);
     445            1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
     446            1 :     m_libspdm_key_exchange_request1.reserved = 0;
     447            1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
     448            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     449            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
     450              :                                   false);
     451            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
     452            1 :     ptr += dhe_key_size;
     453            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     454            1 :     opaque_key_exchange_req_size =
     455            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
     456            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
     457            1 :     ptr += sizeof(uint16_t);
     458            1 :     libspdm_build_opaque_data_supported_version_data(
     459              :         spdm_context, &opaque_key_exchange_req_size, ptr);
     460            1 :     ptr += opaque_key_exchange_req_size;
     461            1 :     response_size = sizeof(response);
     462            1 :     status = libspdm_get_response_key_exchange(
     463              :         spdm_context, m_libspdm_key_exchange_request1_size,
     464              :         &m_libspdm_key_exchange_request1, &response_size, response);
     465            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     466            1 :     assert_int_equal(response_size,
     467              :                      sizeof(spdm_error_response_t) +
     468              :                      sizeof(spdm_error_data_response_not_ready_t));
     469            1 :     spdm_response = (void *)response;
     470            1 :     error_data = (spdm_error_data_response_not_ready_t
     471              :                   *)(&spdm_response->rsp_session_id);
     472            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     473            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_RESPONSE_NOT_READY);
     474            1 :     assert_int_equal(spdm_response->header.param2, 0);
     475            1 :     assert_int_equal(spdm_context->response_state, LIBSPDM_RESPONSE_STATE_NOT_READY);
     476            1 :     assert_int_equal(error_data->request_code, SPDM_KEY_EXCHANGE);
     477            1 :     free(data1);
     478            1 : }
     479              : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
     480              : 
     481            1 : static void rsp_key_exchange_rsp_case6(void **state)
     482              : {
     483              :     libspdm_return_t status;
     484              :     libspdm_test_context_t *spdm_test_context;
     485              :     libspdm_context_t *spdm_context;
     486              :     size_t response_size;
     487              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     488              :     spdm_key_exchange_response_t *spdm_response;
     489              :     void *data1;
     490              :     size_t data_size1;
     491              :     uint8_t *ptr;
     492              :     size_t dhe_key_size;
     493              :     void *dhe_context;
     494              :     size_t opaque_key_exchange_req_size;
     495              : 
     496            1 :     spdm_test_context = *state;
     497            1 :     spdm_context = spdm_test_context->spdm_context;
     498            1 :     spdm_test_context->case_id = 0x6;
     499            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     500            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
     501            1 :     spdm_context->connection_info.capability.flags |=
     502              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     503              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     504            1 :     spdm_context->local_context.capability.flags |=
     505              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     506              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     507            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     508            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     509            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     510            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     511              :         m_libspdm_use_measurement_hash_algo;
     512            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     513            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     514            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     515              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     516            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     517              :                                                     m_libspdm_use_asym_algo, &data1,
     518              :                                                     &data_size1, NULL, NULL);
     519            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     520            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     521              : 
     522            1 :     libspdm_reset_message_a(spdm_context);
     523              : 
     524            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request1.random_data);
     525            1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
     526            1 :     m_libspdm_key_exchange_request1.reserved = 0;
     527            1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
     528            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     529            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
     530              :                                   false);
     531            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
     532            1 :     ptr += dhe_key_size;
     533            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     534            1 :     opaque_key_exchange_req_size =
     535            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
     536            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
     537            1 :     ptr += sizeof(uint16_t);
     538            1 :     libspdm_build_opaque_data_supported_version_data(
     539              :         spdm_context, &opaque_key_exchange_req_size, ptr);
     540            1 :     ptr += opaque_key_exchange_req_size;
     541            1 :     response_size = sizeof(response);
     542            1 :     status = libspdm_get_response_key_exchange(
     543              :         spdm_context, m_libspdm_key_exchange_request1_size,
     544              :         &m_libspdm_key_exchange_request1, &response_size, response);
     545            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     546            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     547            1 :     spdm_response = (void *)response;
     548            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     549            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
     550            1 :     assert_int_equal(spdm_response->header.param2, 0);
     551            1 :     free(data1);
     552            1 : }
     553              : 
     554            1 : static void rsp_key_exchange_rsp_case7(void **state)
     555              : {
     556              :     libspdm_return_t status;
     557              :     libspdm_test_context_t *spdm_test_context;
     558              :     libspdm_context_t *spdm_context;
     559              :     size_t response_size;
     560              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     561              :     spdm_key_exchange_response_t *spdm_response;
     562              :     void *data1;
     563              :     size_t data_size1;
     564              :     uint8_t *ptr;
     565              :     size_t dhe_key_size;
     566              :     void *dhe_context;
     567              :     size_t opaque_key_exchange_req_size;
     568              : 
     569            1 :     spdm_test_context = *state;
     570            1 :     spdm_context = spdm_test_context->spdm_context;
     571            1 :     spdm_test_context->case_id = 0x1;
     572            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     573            1 :     spdm_context->connection_info.capability.flags |=
     574              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     575              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     576            1 :     spdm_context->local_context.capability.flags |=
     577              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     578              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     579            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     580            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     581            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     582            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     583              :         m_libspdm_use_measurement_hash_algo;
     584            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     585            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     586            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     587              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     588            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     589              :                                                     m_libspdm_use_asym_algo, &data1,
     590              :                                                     &data_size1, NULL, NULL);
     591            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     592            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     593              : 
     594            1 :     libspdm_reset_message_a(spdm_context);
     595              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     596              :     spdm_context->transcript.message_m.buffer_size =
     597              :         spdm_context->transcript.message_m.max_buffer_size;
     598              :     spdm_context->transcript.message_b.buffer_size =
     599              :         spdm_context->transcript.message_b.max_buffer_size;
     600              :     spdm_context->transcript.message_c.buffer_size =
     601              :         spdm_context->transcript.message_c.max_buffer_size;
     602              :     spdm_context->transcript.message_mut_b.buffer_size =
     603              :         spdm_context->transcript.message_mut_b.max_buffer_size;
     604              :     spdm_context->transcript.message_mut_c.buffer_size =
     605              :         spdm_context->transcript.message_mut_c.max_buffer_size;
     606              : #endif
     607              : 
     608            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request1.random_data);
     609            1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
     610            1 :     m_libspdm_key_exchange_request1.reserved = 0;
     611            1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
     612            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     613            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
     614              :                                   false);
     615            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
     616            1 :     ptr += dhe_key_size;
     617            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     618            1 :     opaque_key_exchange_req_size =
     619            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
     620            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
     621            1 :     ptr += sizeof(uint16_t);
     622            1 :     libspdm_build_opaque_data_supported_version_data(
     623              :         spdm_context, &opaque_key_exchange_req_size, ptr);
     624            1 :     ptr += opaque_key_exchange_req_size;
     625            1 :     response_size = sizeof(response);
     626            1 :     status = libspdm_get_response_key_exchange(
     627              :         spdm_context, m_libspdm_key_exchange_request1_size,
     628              :         &m_libspdm_key_exchange_request1, &response_size, response);
     629            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     630            1 :     assert_int_equal(
     631              :         libspdm_secured_message_get_session_state(
     632              :             spdm_context->session_info[0].secured_message_context),
     633              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
     634            1 :     spdm_response = (void *)response;
     635            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
     636              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     637              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
     638              :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
     639              :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
     640              :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
     641              :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
     642              : #endif
     643              : 
     644            1 :     free(data1);
     645            1 : }
     646              : 
     647            1 : static void rsp_key_exchange_rsp_case8(void **state)
     648              : {
     649              :     libspdm_return_t status;
     650              :     libspdm_test_context_t *spdm_test_context;
     651              :     libspdm_context_t *spdm_context;
     652              :     size_t response_size;
     653              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     654              : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
     655              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
     656              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
     657              :     uint32_t measurement_summary_hash_size;
     658              :     spdm_key_exchange_response_t *spdm_response;
     659              :     void *data1;
     660              :     size_t data_size1;
     661              :     uint8_t *ptr;
     662              :     size_t dhe_key_size;
     663              :     void *dhe_context;
     664              :     size_t opaque_key_exchange_req_size;
     665              :     bool result;
     666              : 
     667            1 :     spdm_test_context = *state;
     668            1 :     spdm_context = spdm_test_context->spdm_context;
     669            1 :     spdm_test_context->case_id = 0x8;
     670              : 
     671              :     /* Clear previous sessions */
     672            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
     673            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
     674              :     }
     675              : 
     676            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     677            1 :     spdm_context->connection_info.capability.flags |=
     678              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     679              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     680            1 :     spdm_context->local_context.capability.flags |=
     681              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     682              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     683            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
     684            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     685            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     686            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     687            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     688              :         m_libspdm_use_measurement_hash_algo;
     689            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     690            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     691            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     692              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     693            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     694              :                                                     m_libspdm_use_asym_algo, &data1,
     695              :                                                     &data_size1, NULL, NULL);
     696            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     697            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     698              : 
     699            1 :     libspdm_reset_message_a(spdm_context);
     700              : 
     701            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request3.random_data);
     702            1 :     m_libspdm_key_exchange_request3.req_session_id = 0xFFFF;
     703            1 :     m_libspdm_key_exchange_request3.reserved = 0;
     704            1 :     ptr = m_libspdm_key_exchange_request3.exchange_data;
     705            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     706            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
     707              :                                   false);
     708            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
     709            1 :     ptr += dhe_key_size;
     710            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     711            1 :     opaque_key_exchange_req_size =
     712            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
     713            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
     714            1 :     ptr += sizeof(uint16_t);
     715            1 :     libspdm_build_opaque_data_supported_version_data(
     716              :         spdm_context, &opaque_key_exchange_req_size, ptr);
     717            1 :     ptr += opaque_key_exchange_req_size;
     718            1 :     response_size = sizeof(response);
     719            1 :     status = libspdm_get_response_key_exchange(
     720              :         spdm_context, m_libspdm_key_exchange_request3_size,
     721              :         &m_libspdm_key_exchange_request3, &response_size, response);
     722            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     723            1 :     assert_int_equal(
     724              :         libspdm_secured_message_get_session_state(
     725              :             spdm_context->session_info[0].secured_message_context),
     726              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
     727            1 :     spdm_response = (void *)response;
     728            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
     729            1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
     730              : 
     731            1 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
     732            1 :         spdm_context, false, m_libspdm_key_exchange_request3.header.param1);
     733              : 
     734              : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
     735            1 :     result = libspdm_generate_measurement_summary_hash(
     736              :         spdm_context,
     737            1 :         spdm_context->connection_info.version,
     738              :         spdm_context->connection_info.algorithm.base_hash_algo,
     739            1 :         spdm_context->connection_info.algorithm.measurement_spec,
     740              :         spdm_context->connection_info.algorithm.measurement_hash_algo,
     741            1 :         m_libspdm_key_exchange_request3.header.param1,
     742              :         measurement_hash,
     743              :         measurement_summary_hash_size);
     744              : 
     745            1 :     assert_true(result);
     746              : 
     747            1 :     assert_memory_equal((uint8_t *)response + sizeof(spdm_key_exchange_response_t) + dhe_key_size,
     748              :                         measurement_hash, measurement_summary_hash_size);
     749              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
     750            1 :     free(data1);
     751            1 : }
     752              : 
     753            1 : static void rsp_key_exchange_rsp_case9(void **state)
     754              : {
     755              :     libspdm_return_t status;
     756              :     libspdm_test_context_t *spdm_test_context;
     757              :     libspdm_context_t *spdm_context;
     758              :     size_t response_size;
     759              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     760              : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
     761              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
     762              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
     763              :     uint32_t measurement_summary_hash_size;
     764              :     spdm_key_exchange_response_t *spdm_response;
     765              :     void *data1;
     766              :     size_t data_size1;
     767              :     uint8_t *ptr;
     768              :     size_t dhe_key_size;
     769              :     void *dhe_context;
     770              :     size_t opaque_key_exchange_req_size;
     771              :     uint32_t session_id;
     772              :     bool result;
     773              : 
     774            1 :     spdm_test_context = *state;
     775            1 :     spdm_context = spdm_test_context->spdm_context;
     776            1 :     spdm_test_context->case_id = 0x9;
     777              : 
     778              :     /* Clear previous sessions */
     779            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
     780            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
     781              :     }
     782              : 
     783            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     784            1 :     spdm_context->connection_info.capability.flags |=
     785              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     786              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     787            1 :     spdm_context->local_context.capability.flags |=
     788              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     789              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     790            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
     791            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     792            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     793            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     794            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     795              :         m_libspdm_use_measurement_hash_algo;
     796            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     797            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     798            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     799              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     800            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     801              :                                                     m_libspdm_use_asym_algo, &data1,
     802              :                                                     &data_size1, NULL, NULL);
     803            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     804            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     805              : 
     806            1 :     libspdm_reset_message_a(spdm_context);
     807              : 
     808            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request4.random_data);
     809            1 :     m_libspdm_key_exchange_request4.req_session_id = 0xFFFF;
     810            1 :     m_libspdm_key_exchange_request4.reserved = 0;
     811            1 :     ptr = m_libspdm_key_exchange_request4.exchange_data;
     812            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     813            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
     814              :                                   false);
     815            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
     816            1 :     ptr += dhe_key_size;
     817            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     818            1 :     opaque_key_exchange_req_size =
     819            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
     820            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
     821            1 :     ptr += sizeof(uint16_t);
     822            1 :     libspdm_build_opaque_data_supported_version_data(
     823              :         spdm_context, &opaque_key_exchange_req_size, ptr);
     824            1 :     ptr += opaque_key_exchange_req_size;
     825            1 :     response_size = sizeof(response);
     826            1 :     status = libspdm_get_response_key_exchange(
     827              :         spdm_context, m_libspdm_key_exchange_request4_size,
     828              :         &m_libspdm_key_exchange_request4, &response_size, response);
     829            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     830            1 :     assert_int_equal(
     831              :         libspdm_secured_message_get_session_state(
     832              :             spdm_context->session_info[0].secured_message_context),
     833              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
     834            1 :     spdm_response = (void *)response;
     835            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
     836            1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
     837              : 
     838            1 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
     839            1 :         spdm_context, false, m_libspdm_key_exchange_request4.header.param1);
     840              : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
     841            1 :     result = libspdm_generate_measurement_summary_hash(
     842              :         spdm_context,
     843            1 :         spdm_context->connection_info.version,
     844              :         spdm_context->connection_info.algorithm.base_hash_algo,
     845            1 :         spdm_context->connection_info.algorithm.measurement_spec,
     846              :         spdm_context->connection_info.algorithm.measurement_hash_algo,
     847            1 :         m_libspdm_key_exchange_request4.header.param1,
     848              :         measurement_hash,
     849              :         measurement_summary_hash_size);
     850              : 
     851            1 :     assert_true(result);
     852              : 
     853            1 :     assert_memory_equal((uint8_t *)response + sizeof(spdm_key_exchange_response_t) + dhe_key_size,
     854              :                         measurement_hash, measurement_summary_hash_size);
     855              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
     856              : 
     857            1 :     session_id = (m_libspdm_key_exchange_request4.req_session_id << 16) |
     858            1 :                  spdm_response->rsp_session_id;
     859            1 :     libspdm_free_session_id(spdm_context, session_id);
     860              : 
     861            1 :     free(data1);
     862            1 : }
     863              : 
     864            1 : static void rsp_key_exchange_rsp_case10(void **state)
     865              : {
     866              :     libspdm_return_t status;
     867              :     libspdm_test_context_t *spdm_test_context;
     868              :     libspdm_context_t *spdm_context;
     869              :     size_t response_size;
     870              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     871              :     spdm_key_exchange_response_t *spdm_response;
     872              :     void *data1;
     873              :     size_t data_size1;
     874              :     uint8_t *ptr;
     875              :     size_t dhe_key_size;
     876              :     void *dhe_context;
     877              :     size_t opaque_key_exchange_req_size;
     878              : 
     879            1 :     spdm_test_context = *state;
     880            1 :     spdm_context = spdm_test_context->spdm_context;
     881            1 :     spdm_test_context->case_id = 0xA;
     882              : 
     883              :     /* Clear previous sessions */
     884            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
     885            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
     886              :     }
     887              : 
     888            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     889            1 :     spdm_context->connection_info.capability.flags |=
     890              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     891              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     892            1 :     spdm_context->local_context.capability.flags |=
     893              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     894              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     895            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
     896            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     897            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     898            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     899            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     900              :         m_libspdm_use_measurement_hash_algo;
     901            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     902            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     903            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     904              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     905            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     906              :                                                     m_libspdm_use_asym_algo, &data1,
     907              :                                                     &data_size1, NULL, NULL);
     908            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     909            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     910              : 
     911            1 :     libspdm_reset_message_a(spdm_context);
     912              : 
     913            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request5.random_data);
     914            1 :     m_libspdm_key_exchange_request5.req_session_id = 0xFFFF;
     915            1 :     m_libspdm_key_exchange_request5.reserved = 0;
     916            1 :     ptr = m_libspdm_key_exchange_request5.exchange_data;
     917            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     918            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
     919              :                                   false);
     920            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
     921            1 :     ptr += dhe_key_size;
     922            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     923            1 :     opaque_key_exchange_req_size =
     924            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
     925            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
     926            1 :     ptr += sizeof(uint16_t);
     927            1 :     libspdm_build_opaque_data_supported_version_data(
     928              :         spdm_context, &opaque_key_exchange_req_size, ptr);
     929            1 :     ptr += opaque_key_exchange_req_size;
     930            1 :     response_size = sizeof(response);
     931            1 :     status = libspdm_get_response_key_exchange(
     932              :         spdm_context, m_libspdm_key_exchange_request5_size,
     933              :         &m_libspdm_key_exchange_request5, &response_size, response);
     934            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     935              : 
     936            1 :     spdm_response = (void *)response;
     937            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     938            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
     939              : 
     940            1 :     free(data1);
     941            1 : }
     942              : 
     943            1 : static void rsp_key_exchange_rsp_case11(void **state)
     944              : {
     945              :     libspdm_return_t status;
     946              :     libspdm_test_context_t *spdm_test_context;
     947              :     libspdm_context_t *spdm_context;
     948              :     size_t response_size;
     949              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     950              :     spdm_key_exchange_response_t *spdm_response;
     951              :     void *data1;
     952              :     size_t data_size1;
     953              :     uint8_t *ptr;
     954              :     size_t dhe_key_size;
     955              :     void *dhe_context;
     956              :     size_t opaque_key_exchange_req_size;
     957              : 
     958            1 :     spdm_test_context = *state;
     959            1 :     spdm_context = spdm_test_context->spdm_context;
     960            1 :     spdm_test_context->case_id = 0xB;
     961              : 
     962              :     /* Clear previous sessions */
     963            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
     964            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
     965              :     }
     966              : 
     967            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     968              : 
     969              :     /* Clear capabilities flag */
     970            1 :     spdm_context->local_context.capability.flags &= ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
     971              : 
     972              :     /*set capabilities flags */
     973            1 :     spdm_context->connection_info.capability.flags |=
     974              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
     975              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     976            1 :     spdm_context->local_context.capability.flags |=
     977              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
     978              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     979            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     980            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     981            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
     982            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     983              :         m_libspdm_use_measurement_hash_algo;
     984            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     985            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     986            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     987              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     988            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     989              :                                                     m_libspdm_use_asym_algo, &data1,
     990              :                                                     &data_size1, NULL, NULL);
     991            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
     992            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
     993              : 
     994            1 :     libspdm_reset_message_a(spdm_context);
     995              : 
     996            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request3.random_data);
     997            1 :     m_libspdm_key_exchange_request3.req_session_id = 0xFFFF;
     998            1 :     m_libspdm_key_exchange_request3.reserved = 0;
     999            1 :     ptr = m_libspdm_key_exchange_request3.exchange_data;
    1000            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1001            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1002              :                                   false);
    1003            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1004            1 :     ptr += dhe_key_size;
    1005            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1006            1 :     opaque_key_exchange_req_size =
    1007            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    1008            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    1009            1 :     ptr += sizeof(uint16_t);
    1010            1 :     libspdm_build_opaque_data_supported_version_data(
    1011              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    1012            1 :     ptr += opaque_key_exchange_req_size;
    1013            1 :     response_size = sizeof(response);
    1014            1 :     status = libspdm_get_response_key_exchange(
    1015              :         spdm_context, m_libspdm_key_exchange_request3_size,
    1016              :         &m_libspdm_key_exchange_request3, &response_size, response);
    1017            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1018              : 
    1019            1 :     spdm_response = (void *)response;
    1020            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
    1021            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
    1022              : 
    1023            1 :     free(data1);
    1024            1 : }
    1025              : 
    1026            1 : static void rsp_key_exchange_rsp_case14(void **state)
    1027              : {
    1028              :     libspdm_return_t status;
    1029              :     libspdm_test_context_t *spdm_test_context;
    1030              :     libspdm_context_t *spdm_context;
    1031              :     size_t response_size;
    1032              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1033              :     spdm_key_exchange_response_t *spdm_response;
    1034              :     void *data1;
    1035              :     size_t data_size1;
    1036              :     void *data2;
    1037              :     size_t data_size2;
    1038              :     uint8_t *ptr;
    1039              :     size_t dhe_key_size;
    1040              :     void *dhe_context;
    1041              :     size_t opaque_key_exchange_req_size;
    1042              : 
    1043            1 :     spdm_test_context = *state;
    1044            1 :     spdm_context = spdm_test_context->spdm_context;
    1045            1 :     spdm_test_context->case_id = 0xE;
    1046              : 
    1047              :     /* Clear previous sessions */
    1048            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    1049            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    1050              :     }
    1051              : 
    1052            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1053            1 :     spdm_context->connection_info.capability.flags =
    1054              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    1055              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1056            1 :     spdm_context->local_context.capability.flags =
    1057              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1058              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1059            1 :     spdm_context->connection_info.capability.flags |=
    1060              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP;
    1061            1 :     spdm_context->local_context.capability.flags |=
    1062              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
    1063            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1064            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1065            1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
    1066            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1067            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1068              :         m_libspdm_use_measurement_hash_algo;
    1069            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1070            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1071            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1072              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1073            1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data1, &data_size1);
    1074            1 :     spdm_context->local_context.local_public_key_provision = data1;
    1075            1 :     spdm_context->local_context.local_public_key_provision_size = data_size1;
    1076            1 :     libspdm_read_requester_public_key(m_libspdm_use_req_asym_algo, &data2, &data_size2);
    1077            1 :     spdm_context->local_context.peer_public_key_provision = data2;
    1078            1 :     spdm_context->local_context.peer_public_key_provision_size = data_size2;
    1079              : 
    1080            1 :     libspdm_reset_message_a(spdm_context);
    1081              : 
    1082            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request7.random_data);
    1083            1 :     m_libspdm_key_exchange_request7.req_session_id = 0xFFFF;
    1084            1 :     m_libspdm_key_exchange_request7.reserved = 0;
    1085            1 :     ptr = m_libspdm_key_exchange_request7.exchange_data;
    1086            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1087            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1088              :                                   false);
    1089            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1090            1 :     ptr += dhe_key_size;
    1091            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1092            1 :     opaque_key_exchange_req_size =
    1093            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    1094            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    1095            1 :     ptr += sizeof(uint16_t);
    1096            1 :     libspdm_build_opaque_data_supported_version_data(
    1097              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    1098            1 :     ptr += opaque_key_exchange_req_size;
    1099            1 :     response_size = sizeof(response);
    1100            1 :     status = libspdm_get_response_key_exchange(
    1101              :         spdm_context, m_libspdm_key_exchange_request7_size,
    1102              :         &m_libspdm_key_exchange_request7, &response_size, response);
    1103            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1104            1 :     assert_int_equal(
    1105              :         libspdm_secured_message_get_session_state(
    1106              :             spdm_context->session_info[0].secured_message_context),
    1107              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    1108            1 :     spdm_response = (void *)response;
    1109            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
    1110            1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
    1111            1 :     free(data1);
    1112            1 :     free(data2);
    1113            1 : }
    1114              : 
    1115            1 : static void rsp_key_exchange_rsp_case15(void **state)
    1116              : {
    1117              :     libspdm_return_t status;
    1118              :     libspdm_test_context_t *spdm_test_context;
    1119              :     libspdm_context_t *spdm_context;
    1120              :     size_t response_size;
    1121              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1122              :     spdm_key_exchange_response_t *spdm_response;
    1123              :     void *data1;
    1124              :     size_t data_size1;
    1125              :     uint8_t *ptr;
    1126              :     size_t dhe_key_size;
    1127              :     void *dhe_context;
    1128              :     size_t opaque_key_exchange_req_size;
    1129              :     size_t opaque_key_exchange_rsp_size;
    1130              : 
    1131            1 :     spdm_test_context = *state;
    1132            1 :     spdm_context = spdm_test_context->spdm_context;
    1133            1 :     spdm_test_context->case_id = 0xF;
    1134              : 
    1135              :     /* Clear previous sessions */
    1136            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    1137            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    1138              :     }
    1139              : 
    1140            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1141            1 :     spdm_context->connection_info.capability.flags =
    1142              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    1143              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1144            1 :     spdm_context->local_context.capability.flags =
    1145              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1146              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1147            1 :     spdm_context->connection_info.capability.flags |=
    1148              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
    1149            1 :     spdm_context->local_context.capability.flags |=
    1150              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP |
    1151              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1152              : 
    1153            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1154            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1155            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1156            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1157              :         m_libspdm_use_measurement_hash_algo;
    1158            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1159            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1160            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1161              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1162            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1163              :                                                     m_libspdm_use_asym_algo, &data1,
    1164              :                                                     &data_size1, NULL, NULL);
    1165            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
    1166            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
    1167              : 
    1168            1 :     libspdm_reset_message_a(spdm_context);
    1169              : 
    1170            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request1.random_data);
    1171            1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
    1172            1 :     m_libspdm_key_exchange_request1.reserved = 0;
    1173            1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
    1174            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1175            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1176              :                                   false);
    1177            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1178            1 :     ptr += dhe_key_size;
    1179            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1180            1 :     opaque_key_exchange_req_size =
    1181            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    1182            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    1183            1 :     ptr += sizeof(uint16_t);
    1184            1 :     libspdm_build_opaque_data_supported_version_data(
    1185              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    1186            1 :     ptr += opaque_key_exchange_req_size;
    1187            1 :     response_size = sizeof(response);
    1188              : 
    1189              :     /* Required to compute response size independently */
    1190              :     opaque_key_exchange_rsp_size =
    1191            1 :         libspdm_get_opaque_data_version_selection_data_size(spdm_context);
    1192              : 
    1193            1 :     status = libspdm_get_response_key_exchange(
    1194              :         spdm_context, m_libspdm_key_exchange_request1_size,
    1195              :         &m_libspdm_key_exchange_request1, &response_size, response);
    1196            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1197            1 :     assert_int_equal(
    1198              :         libspdm_secured_message_get_session_state(
    1199              :             spdm_context->session_info[0].secured_message_context),
    1200              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    1201            1 :     spdm_response = (void *)response;
    1202            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
    1203            1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
    1204            1 :     assert_int_equal(response_size,
    1205              :                      sizeof(spdm_key_exchange_response_t) +
    1206              :                      dhe_key_size +
    1207              :                      sizeof(uint16_t) +
    1208              :                      opaque_key_exchange_rsp_size +
    1209              :                      libspdm_get_asym_signature_size(
    1210              :                          spdm_context->connection_info.algorithm.base_asym_algo)
    1211              :                      );
    1212              : 
    1213            1 :     free(data1);
    1214            1 : }
    1215              : 
    1216            1 : static void rsp_key_exchange_rsp_case16(void **state)
    1217              : {
    1218              :     libspdm_return_t status;
    1219              :     libspdm_test_context_t *spdm_test_context;
    1220              :     libspdm_context_t *spdm_context;
    1221              :     size_t current_request_size;
    1222              :     size_t response_size;
    1223              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1224              :     spdm_key_exchange_response_t *spdm_response;
    1225              :     void *data1;
    1226              :     size_t data_size1;
    1227              :     uint8_t *ptr;
    1228              :     size_t dhe_key_size;
    1229              :     void *dhe_context;
    1230              :     size_t opaque_key_exchange_req_size;
    1231              : 
    1232            1 :     spdm_test_context = *state;
    1233            1 :     spdm_context = spdm_test_context->spdm_context;
    1234            1 :     spdm_test_context->case_id = 0x10;
    1235              : 
    1236            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    1237            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    1238              :     }
    1239              : 
    1240            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1241            1 :     spdm_context->connection_info.capability.flags |=
    1242              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    1243              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1244            1 :     spdm_context->local_context.capability.flags |=
    1245              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1246              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1247              : 
    1248            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1249            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1250            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1251            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1252              :         m_libspdm_use_measurement_hash_algo;
    1253            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1254            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1255              : 
    1256            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1257              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1258            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1259              :                                                     m_libspdm_use_asym_algo, &data1,
    1260              :                                                     &data_size1, NULL, NULL);
    1261            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
    1262            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
    1263              : 
    1264            1 :     libspdm_reset_message_a(spdm_context);
    1265              : 
    1266            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request1.random_data);
    1267            1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
    1268            1 :     m_libspdm_key_exchange_request1.reserved = 0;
    1269            1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
    1270            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1271            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1272              :                                   false);
    1273            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1274            1 :     ptr += dhe_key_size;
    1275            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1276            1 :     opaque_key_exchange_req_size =
    1277            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    1278            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    1279            1 :     ptr += sizeof(uint16_t);
    1280            1 :     libspdm_build_opaque_data_supported_version_data(
    1281              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    1282            1 :     ptr += opaque_key_exchange_req_size;
    1283              : 
    1284            1 :     current_request_size = sizeof(spdm_key_exchange_request_t) + dhe_key_size +
    1285            1 :                            sizeof(uint16_t) + opaque_key_exchange_req_size;
    1286            1 :     response_size = sizeof(response);
    1287            1 :     status = libspdm_get_response_key_exchange(
    1288              :         spdm_context, current_request_size, &m_libspdm_key_exchange_request1,
    1289              :         &response_size, response);
    1290              : 
    1291            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1292            1 :     assert_int_equal(
    1293              :         libspdm_secured_message_get_session_state(
    1294              :             spdm_context->session_info[0].secured_message_context),
    1295              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    1296            1 :     spdm_response = (void *)response;
    1297            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
    1298            1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
    1299              : 
    1300              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1301              :     assert_int_equal(spdm_context->session_info[0].session_transcript.message_k.buffer_size,
    1302              :                      current_request_size + response_size);
    1303              :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer,
    1304              :                         &m_libspdm_key_exchange_request1, current_request_size);
    1305              :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer +
    1306              :                         current_request_size,
    1307              :                         response, response_size);
    1308              : #endif
    1309            1 :     free(data1);
    1310            1 : }
    1311              : 
    1312            1 : static void rsp_key_exchange_rsp_case17(void **state)
    1313              : {
    1314              :     libspdm_return_t status;
    1315              :     libspdm_test_context_t *spdm_test_context;
    1316              :     libspdm_context_t *spdm_context;
    1317              :     size_t response_size;
    1318              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1319              :     spdm_key_exchange_response_t *spdm_response;
    1320              :     void *data1;
    1321              :     size_t data_size1;
    1322              :     uint8_t *ptr;
    1323              :     size_t dhe_key_size;
    1324              :     void *dhe_context;
    1325              :     size_t opaque_key_exchange_req_size;
    1326              : 
    1327            1 :     spdm_test_context = *state;
    1328            1 :     spdm_context = spdm_test_context->spdm_context;
    1329            1 :     spdm_test_context->case_id = 0x11;
    1330            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1331            1 :     spdm_context->connection_info.capability.flags |=
    1332              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    1333              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1334            1 :     spdm_context->local_context.capability.flags |=
    1335              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1336              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1337            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1338            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1339            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1340            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1341              :         m_libspdm_use_measurement_hash_algo;
    1342            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1343            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1344            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    1345              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1346            1 :     spdm_context->connection_info.algorithm.other_params_support =
    1347              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    1348            1 :     spdm_context->local_context.secured_message_version.secured_message_version_count = 1;
    1349              : 
    1350            1 :     libspdm_session_info_init(spdm_context,
    1351            1 :                               spdm_context->session_info,
    1352              :                               0,
    1353              :                               INVALID_SESSION_ID, false);
    1354            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1355              :                                                     m_libspdm_use_asym_algo, &data1,
    1356              :                                                     &data_size1, NULL, NULL);
    1357            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
    1358            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
    1359              : 
    1360            1 :     libspdm_reset_message_a(spdm_context);
    1361              : 
    1362            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request8.random_data);
    1363            1 :     m_libspdm_key_exchange_request8.req_session_id = 0xFFFF;
    1364            1 :     m_libspdm_key_exchange_request8.reserved = 0;
    1365            1 :     m_libspdm_key_exchange_request8.session_policy = 0xFF;
    1366            1 :     ptr = m_libspdm_key_exchange_request8.exchange_data;
    1367            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1368            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1369              :                                   false);
    1370            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1371            1 :     ptr += dhe_key_size;
    1372            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1373            1 :     opaque_key_exchange_req_size =
    1374            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    1375            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    1376            1 :     ptr += sizeof(uint16_t);
    1377            1 :     libspdm_build_opaque_data_supported_version_data(
    1378              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    1379            1 :     ptr += opaque_key_exchange_req_size;
    1380            1 :     response_size = sizeof(response);
    1381            1 :     status = libspdm_get_response_key_exchange(
    1382              :         spdm_context, m_libspdm_key_exchange_request8_size,
    1383              :         &m_libspdm_key_exchange_request8, &response_size, response);
    1384            1 :     assert_int_equal(spdm_context->session_info[0].session_policy,
    1385              :                      m_libspdm_key_exchange_request8.session_policy);
    1386            1 :     spdm_response = (void *)response;
    1387            1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
    1388            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1389            1 :     assert_int_equal(
    1390              :         libspdm_secured_message_get_session_state(
    1391              :             spdm_context->session_info[0].secured_message_context),
    1392              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    1393            1 :     spdm_response = (void *)response;
    1394            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
    1395            1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
    1396            1 :     free(data1);
    1397            1 : }
    1398              : 
    1399              : /**
    1400              :  * Test 18: SlotID in KEY_EXCHANGE request message is 9, but it should be 0xFF or between 0 and 7 inclusive.
    1401              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST.
    1402              :  **/
    1403            1 : static void rsp_key_exchange_rsp_case18(void **state)
    1404              : {
    1405              :     libspdm_return_t status;
    1406              :     libspdm_test_context_t *spdm_test_context;
    1407              :     libspdm_context_t *spdm_context;
    1408              :     size_t response_size;
    1409              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1410              :     spdm_key_exchange_response_t *spdm_response;
    1411              :     void *data1;
    1412              :     size_t data_size1;
    1413              :     uint8_t *ptr;
    1414              :     size_t dhe_key_size;
    1415              :     void *dhe_context;
    1416              :     size_t opaque_key_exchange_req_size;
    1417              : 
    1418            1 :     spdm_test_context = *state;
    1419            1 :     spdm_context = spdm_test_context->spdm_context;
    1420            1 :     spdm_test_context->case_id = 0x12;
    1421            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1422            1 :     spdm_context->connection_info.capability.flags |=
    1423              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    1424              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1425            1 :     spdm_context->local_context.capability.flags |=
    1426              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1427              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1428            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1429            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1430            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1431            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1432              :         m_libspdm_use_measurement_hash_algo;
    1433            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1434            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1435            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1436              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1437            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1438              :                                                     m_libspdm_use_asym_algo, &data1,
    1439              :                                                     &data_size1, NULL, NULL);
    1440            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
    1441            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
    1442              : 
    1443            1 :     libspdm_reset_message_a(spdm_context);
    1444              : 
    1445            1 :     spdm_context->local_context.secured_message_version.secured_message_version_count = 1;
    1446              : 
    1447            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request9.random_data);
    1448            1 :     m_libspdm_key_exchange_request9.req_session_id = 0xFFFF;
    1449            1 :     m_libspdm_key_exchange_request9.reserved = 0;
    1450            1 :     ptr = m_libspdm_key_exchange_request9.exchange_data;
    1451            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1452            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1453              :                                   false);
    1454            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1455            1 :     ptr += dhe_key_size;
    1456            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1457            1 :     opaque_key_exchange_req_size =
    1458            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    1459            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    1460            1 :     ptr += sizeof(uint16_t);
    1461            1 :     libspdm_build_opaque_data_supported_version_data(
    1462              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    1463            1 :     ptr += opaque_key_exchange_req_size;
    1464            1 :     response_size = sizeof(response);
    1465            1 :     status = libspdm_get_response_key_exchange(
    1466              :         spdm_context, m_libspdm_key_exchange_request9_size,
    1467              :         &m_libspdm_key_exchange_request9, &response_size, response);
    1468            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1469            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
    1470            1 :     spdm_response = (void *)response;
    1471            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
    1472            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
    1473            1 :     assert_int_equal(spdm_response->header.param2, 0);
    1474            1 :     free(data1);
    1475            1 : }
    1476              : 
    1477            1 : static void rsp_key_exchange_rsp_case19(void **state)
    1478              : {
    1479              :     libspdm_return_t status;
    1480              :     libspdm_test_context_t *spdm_test_context;
    1481              :     libspdm_context_t *spdm_context;
    1482              :     size_t response_size;
    1483              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1484              :     spdm_key_exchange_response_t *spdm_response;
    1485              :     void *data1;
    1486              :     size_t data_size1;
    1487              :     uint8_t *ptr;
    1488              :     size_t dhe_key_size;
    1489              :     void *dhe_context;
    1490              : 
    1491            1 :     spdm_test_context = *state;
    1492            1 :     spdm_context = spdm_test_context->spdm_context;
    1493            1 :     spdm_test_context->case_id = 0x13;
    1494            1 :     spdm_context->response_state = 0;
    1495            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1496            1 :     spdm_context->connection_info.capability.flags = 0;
    1497            1 :     spdm_context->connection_info.capability.flags |=
    1498              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    1499              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1500            1 :     spdm_context->local_context.capability.flags = 0;
    1501            1 :     spdm_context->local_context.capability.flags |=
    1502              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1503              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1504            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1505            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1506            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1507            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1508              :         m_libspdm_use_measurement_hash_algo;
    1509            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1510            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1511            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    1512              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1513            1 :     spdm_context->connection_info.algorithm.other_params_support =
    1514              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    1515              : 
    1516            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1517              :                                                     m_libspdm_use_asym_algo, &data1,
    1518              :                                                     &data_size1, NULL, NULL);
    1519            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
    1520            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
    1521              : 
    1522            1 :     libspdm_reset_message_a(spdm_context);
    1523              : 
    1524            1 :     spdm_context->local_context.secured_message_version.secured_message_version_count = 1;
    1525              : 
    1526            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request8.random_data);
    1527            1 :     m_libspdm_key_exchange_request8.req_session_id = 0xFFFF;
    1528            1 :     m_libspdm_key_exchange_request8.reserved = 0;
    1529            1 :     ptr = m_libspdm_key_exchange_request8.exchange_data;
    1530            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1531            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1532              :                                   false);
    1533            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1534            1 :     ptr += dhe_key_size;
    1535            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1536              : 
    1537              :     size_t opaque_data_size;
    1538              :     spdm_general_opaque_data_table_header_t
    1539              :     *spdm_general_opaque_data_table_header;
    1540              :     secured_message_opaque_element_table_header_t
    1541              :     *opaque_element_table_header;
    1542              :     secured_message_opaque_element_header_t
    1543              :     * secured_message_element_header;
    1544              :     uint8_t element_num;
    1545              :     uint8_t element_index;
    1546              :     size_t current_element_len;
    1547              : 
    1548            1 :     spdm_general_opaque_data_table_header =
    1549              :         (spdm_general_opaque_data_table_header_t *)(ptr + sizeof(uint16_t));
    1550            1 :     spdm_general_opaque_data_table_header->total_elements = 2;
    1551            1 :     opaque_element_table_header = (void *)(spdm_general_opaque_data_table_header + 1);
    1552              : 
    1553            1 :     element_num = spdm_general_opaque_data_table_header->total_elements;
    1554            1 :     opaque_data_size = sizeof(spdm_general_opaque_data_table_header_t);
    1555              : 
    1556            3 :     for (element_index = 0; element_index < element_num; element_index++) {
    1557            2 :         opaque_element_table_header->id = SPDM_REGISTRY_ID_DMTF;
    1558            2 :         opaque_element_table_header->vendor_len = 0;
    1559              :         /* When opaque_element_data_len is not four byte aligned*/
    1560            2 :         opaque_element_table_header->opaque_element_data_len = 0xF;
    1561              : 
    1562            2 :         secured_message_element_header = (void *)(opaque_element_table_header + 1);
    1563            2 :         secured_message_element_header->sm_data_id =
    1564              :             SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_ID_SUPPORTED_VERSION;
    1565            2 :         secured_message_element_header->sm_data_version =
    1566              :             SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_DATA_VERSION;
    1567              : 
    1568            2 :         current_element_len = sizeof(secured_message_opaque_element_table_header_t) +
    1569            2 :                               opaque_element_table_header->vendor_len +
    1570            2 :                               sizeof(opaque_element_table_header->opaque_element_data_len) +
    1571            2 :                               opaque_element_table_header->opaque_element_data_len;
    1572              : 
    1573              :         /*move to next element*/
    1574            2 :         opaque_element_table_header =
    1575              :             (secured_message_opaque_element_table_header_t *)
    1576              :             ((uint8_t *)opaque_element_table_header + current_element_len);
    1577              : 
    1578            2 :         opaque_data_size += current_element_len;
    1579              :     }
    1580              : 
    1581            1 :     *(uint16_t *)ptr = (uint16_t)opaque_data_size;
    1582              : 
    1583            1 :     response_size = sizeof(response);
    1584            1 :     status = libspdm_get_response_key_exchange(
    1585              :         spdm_context, m_libspdm_key_exchange_request8_size,
    1586              :         &m_libspdm_key_exchange_request8, &response_size, response);
    1587            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1588            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
    1589            1 :     spdm_response = (void *)response;
    1590            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
    1591            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
    1592            1 :     assert_int_equal(spdm_response->header.param2, 0);
    1593            1 :     free(data1);
    1594            1 : }
    1595              : 
    1596            1 : static void rsp_key_exchange_rsp_case20(void **state)
    1597              : {
    1598              :     libspdm_return_t status;
    1599              :     libspdm_test_context_t *spdm_test_context;
    1600              :     libspdm_context_t *spdm_context;
    1601              :     size_t response_size;
    1602              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1603              :     spdm_key_exchange_response_t *spdm_response;
    1604              :     void *data1;
    1605              :     size_t data_size1;
    1606              :     uint8_t *ptr;
    1607              :     size_t dhe_key_size;
    1608              :     void *dhe_context;
    1609              :     size_t opaque_key_exchange_req_size;
    1610              : 
    1611            1 :     spdm_test_context = *state;
    1612            1 :     spdm_context = spdm_test_context->spdm_context;
    1613            1 :     spdm_test_context->case_id = 0x14;
    1614            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1615            1 :     spdm_context->connection_info.capability.flags =
    1616              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    1617              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1618            1 :     spdm_context->local_context.capability.flags =
    1619              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1620              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
    1621              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1622            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1623            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1624            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1625            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1626              :         m_libspdm_use_measurement_hash_algo;
    1627            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1628            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1629            1 :     spdm_context->connection_info.algorithm.other_params_support =
    1630              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    1631            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    1632              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1633              : 
    1634            1 :     spdm_context->local_context.secured_message_version.secured_message_version_count = 1;
    1635              : 
    1636            1 :     libspdm_session_info_init(spdm_context,
    1637            1 :                               spdm_context->session_info,
    1638              :                               0,
    1639              :                               INVALID_SESSION_ID, false);
    1640            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1641              :                                                     m_libspdm_use_asym_algo, &data1,
    1642              :                                                     &data_size1, NULL, NULL);
    1643            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
    1644            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
    1645              : 
    1646            1 :     libspdm_reset_message_a(spdm_context);
    1647              : 
    1648            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request8.random_data);
    1649            1 :     m_libspdm_key_exchange_request8.req_session_id = 0xFFFF;
    1650            1 :     m_libspdm_key_exchange_request8.reserved = 0;
    1651            1 :     m_libspdm_key_exchange_request8.session_policy = 0xFF;
    1652            1 :     ptr = m_libspdm_key_exchange_request8.exchange_data;
    1653            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1654            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1655              :                                   false);
    1656            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1657            1 :     ptr += dhe_key_size;
    1658            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1659            1 :     opaque_key_exchange_req_size =
    1660            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    1661            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    1662            1 :     ptr += sizeof(uint16_t);
    1663            1 :     libspdm_build_opaque_data_supported_version_data(
    1664              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    1665            1 :     ptr += opaque_key_exchange_req_size;
    1666            1 :     response_size = sizeof(response);
    1667            1 :     status = libspdm_get_response_key_exchange(
    1668              :         spdm_context, m_libspdm_key_exchange_request8_size,
    1669              :         &m_libspdm_key_exchange_request8, &response_size, response);
    1670            1 :     assert_int_equal(spdm_context->session_info[0].session_policy,
    1671              :                      m_libspdm_key_exchange_request8.session_policy);
    1672            1 :     spdm_response = (void *)response;
    1673            1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
    1674            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1675            1 :     assert_int_equal(
    1676              :         libspdm_secured_message_get_session_state(
    1677              :             spdm_context->session_info[0].secured_message_context),
    1678              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    1679            1 :     spdm_response = (void *)response;
    1680            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
    1681            1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
    1682            1 :     free(data1);
    1683            1 : }
    1684              : 
    1685              : /**
    1686              :  * Test 21: The key usage bit mask is not set, the SlotID fields in KEY_EXCHANGE and KEY_EXCHANGE_RSP shall not specify this certificate slot
    1687              :  * Expected Behavior: get a SPDM_ERROR_CODE_INVALID_REQUEST return code
    1688              :  **/
    1689            1 : static void rsp_key_exchange_rsp_case21(void **state)
    1690              : {
    1691              :     libspdm_return_t status;
    1692              :     libspdm_test_context_t *spdm_test_context;
    1693              :     libspdm_context_t *spdm_context;
    1694              :     size_t response_size;
    1695              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1696              :     spdm_key_exchange_response_t *spdm_response;
    1697              :     void *data1;
    1698              :     size_t data_size1;
    1699              :     uint8_t *ptr;
    1700              :     size_t dhe_key_size;
    1701              :     void *dhe_context;
    1702              :     size_t opaque_key_exchange_req_size;
    1703              :     uint8_t slot_id;
    1704              : 
    1705            1 :     spdm_test_context = *state;
    1706            1 :     spdm_context = spdm_test_context->spdm_context;
    1707            1 :     spdm_test_context->case_id = 0x15;
    1708            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1709            1 :     spdm_context->connection_info.capability.flags |=
    1710              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    1711              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1712            1 :     spdm_context->local_context.capability.flags |=
    1713              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1714              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1715            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1716            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1717            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1718            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1719              :         m_libspdm_use_measurement_hash_algo;
    1720            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1721            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1722            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    1723              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1724            1 :     spdm_context->connection_info.algorithm.other_params_support =
    1725              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    1726            1 :     spdm_context->local_context.secured_message_version.secured_message_version_count = 1;
    1727            1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
    1728              : 
    1729            1 :     libspdm_session_info_init(spdm_context,
    1730            1 :                               spdm_context->session_info,
    1731              :                               0,
    1732              :                               INVALID_SESSION_ID, false);
    1733            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1734              :                                                     m_libspdm_use_asym_algo, &data1,
    1735              :                                                     &data_size1, NULL, NULL);
    1736            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
    1737            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
    1738              : 
    1739            1 :     libspdm_reset_message_a(spdm_context);
    1740              : 
    1741              :     /* If set, the SlotID fields in KEY_EXCHANGE and KEY_EXCHANGE_RSP can specify this certificate slot. If not set,
    1742              :      * the SlotID fields in KEY_EXCHANGE and KEY_EXCHANGE_RSP shall not specify this certificate slot */
    1743            1 :     slot_id = 0;
    1744            1 :     m_libspdm_key_exchange_request10.header.param2 = slot_id;
    1745            1 :     spdm_context->local_context.local_key_usage_bit_mask[slot_id] =
    1746              :         SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
    1747              :         SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE;
    1748              : 
    1749            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request10.random_data);
    1750            1 :     m_libspdm_key_exchange_request10.req_session_id = 0xFFFF;
    1751            1 :     m_libspdm_key_exchange_request10.reserved = 0;
    1752            1 :     m_libspdm_key_exchange_request10.session_policy = 0xFF;
    1753            1 :     ptr = m_libspdm_key_exchange_request10.exchange_data;
    1754            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1755            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1756              :                                   false);
    1757            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1758            1 :     ptr += dhe_key_size;
    1759            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1760            1 :     opaque_key_exchange_req_size =
    1761            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    1762            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    1763            1 :     ptr += sizeof(uint16_t);
    1764            1 :     libspdm_build_opaque_data_supported_version_data(
    1765              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    1766            1 :     ptr += opaque_key_exchange_req_size;
    1767            1 :     response_size = sizeof(response);
    1768            1 :     status = libspdm_get_response_key_exchange(
    1769              :         spdm_context, m_libspdm_key_exchange_request10_size,
    1770              :         &m_libspdm_key_exchange_request10, &response_size, response);
    1771              : 
    1772            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1773            1 :     assert_int_equal (response_size, sizeof(spdm_error_response_t));
    1774            1 :     spdm_response = (void *)response;
    1775            1 :     assert_int_equal (spdm_response->header.request_response_code, SPDM_ERROR);
    1776            1 :     assert_int_equal (spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_REQUEST);
    1777            1 :     assert_int_equal (spdm_response->header.param2, 0);
    1778              : 
    1779            1 :     free(data1);
    1780            1 : }
    1781              : 
    1782              : /**
    1783              :  * Test 21: The Requester subscribes to all events supported by the Responder.
    1784              :  * Expected Behavior: Responder successfully subscribes the Requester to all events.
    1785              :  **/
    1786            1 : static void rsp_key_exchange_rsp_case22(void **state)
    1787              : {
    1788              : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
    1789              :     libspdm_return_t status;
    1790              :     libspdm_test_context_t *spdm_test_context;
    1791              :     libspdm_context_t *spdm_context;
    1792              :     size_t response_size;
    1793              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1794              :     spdm_key_exchange_response_t *spdm_response;
    1795              :     void *data1;
    1796              :     size_t data_size1;
    1797              :     uint8_t *ptr;
    1798              :     size_t dhe_key_size;
    1799              :     void *dhe_context;
    1800              :     size_t opaque_key_exchange_req_size;
    1801              : 
    1802            1 :     spdm_test_context = *state;
    1803            1 :     spdm_context = spdm_test_context->spdm_context;
    1804            1 :     spdm_test_context->case_id = 0x16;
    1805            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1806            1 :     spdm_context->connection_info.capability.flags |=
    1807              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    1808            1 :     spdm_context->local_context.capability.flags |=
    1809              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1810              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP;
    1811            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1812            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1813            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1814            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1815              :         m_libspdm_use_measurement_hash_algo;
    1816            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1817            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1818            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    1819              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1820            1 :     spdm_context->connection_info.algorithm.other_params_support =
    1821              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    1822            1 :     spdm_context->local_context.secured_message_version.secured_message_version_count = 1;
    1823            1 :     spdm_context->connection_info.multi_key_conn_rsp = false;
    1824              : 
    1825            1 :     libspdm_session_info_init(spdm_context, spdm_context->session_info, INVALID_SESSION_ID,
    1826              :                               0, false);
    1827            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1828              :                                                     m_libspdm_use_asym_algo, &data1,
    1829              :                                                     &data_size1, NULL, NULL);
    1830            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
    1831            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
    1832              : 
    1833            1 :     libspdm_reset_message_a(spdm_context);
    1834              : 
    1835            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request10.random_data);
    1836            1 :     m_libspdm_key_exchange_request10.req_session_id = 0xFFFF;
    1837            1 :     m_libspdm_key_exchange_request10.reserved = 0;
    1838            1 :     m_libspdm_key_exchange_request10.session_policy =
    1839              :         SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_EVENT_ALL_POLICY;
    1840            1 :     ptr = m_libspdm_key_exchange_request10.exchange_data;
    1841            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1842            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1843              :                                   false);
    1844            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1845            1 :     ptr += dhe_key_size;
    1846            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1847            1 :     opaque_key_exchange_req_size =
    1848            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    1849            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    1850            1 :     ptr += sizeof(uint16_t);
    1851            1 :     libspdm_build_opaque_data_supported_version_data(
    1852              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    1853            1 :     ptr += opaque_key_exchange_req_size;
    1854            1 :     response_size = sizeof(response);
    1855              : 
    1856            1 :     status = libspdm_get_response_key_exchange(
    1857              :         spdm_context, m_libspdm_key_exchange_request10_size,
    1858              :         &m_libspdm_key_exchange_request10, &response_size, response);
    1859              : 
    1860            1 :     assert_int_equal(spdm_context->session_info[0].session_policy,
    1861              :                      m_libspdm_key_exchange_request10.session_policy);
    1862            1 :     spdm_response = (void *)response;
    1863            1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_13);
    1864            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1865            1 :     assert_int_equal(
    1866              :         libspdm_secured_message_get_session_state(
    1867              :             spdm_context->session_info[0].secured_message_context),
    1868              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    1869            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_KEY_EXCHANGE_RSP);
    1870            1 :     assert_int_equal(spdm_response->rsp_session_id, 0xFFFF);
    1871            1 :     assert_true(g_event_all_subscribe && !g_event_all_unsubscribe);
    1872            1 :     free(data1);
    1873              : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
    1874            1 : }
    1875              : 
    1876            1 : static void rsp_key_exchange_rsp_case23(void **state)
    1877              : {
    1878              :     libspdm_return_t status;
    1879              :     libspdm_test_context_t *spdm_test_context;
    1880              :     libspdm_context_t *spdm_context;
    1881              :     size_t response_size;
    1882              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1883              :     spdm_key_exchange_response_t *spdm_response;
    1884              :     void *data1;
    1885              :     size_t data_size1;
    1886              :     uint8_t *ptr;
    1887              :     size_t dhe_key_size;
    1888              :     void *dhe_context;
    1889              :     size_t opaque_key_exchange_req_size;
    1890              : 
    1891            1 :     spdm_test_context = *state;
    1892            1 :     spdm_context = spdm_test_context->spdm_context;
    1893            1 :     spdm_test_context->case_id = 0x17;
    1894            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1895            1 :     spdm_context->connection_info.capability.flags |=
    1896              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    1897              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1898            1 :     spdm_context->local_context.capability.flags |=
    1899              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1900              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
    1901              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP |
    1902              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1903            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1904            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1905            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1906            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1907              :         m_libspdm_use_measurement_hash_algo;
    1908            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1909            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1910            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1911              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1912            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1913              :                                                     m_libspdm_use_asym_algo, &data1,
    1914              :                                                     &data_size1, NULL, NULL);
    1915            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
    1916            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
    1917              : 
    1918            1 :     libspdm_reset_message_a(spdm_context);
    1919            1 :     g_key_exchange_start_mut_auth = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
    1920            1 :     g_mandatory_mut_auth = true;
    1921              : 
    1922            1 :     spdm_context->local_context.secured_message_version.secured_message_version_count = 1;
    1923              : 
    1924            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request1.random_data);
    1925            1 :     m_libspdm_key_exchange_request1.req_session_id = 0xFFFF;
    1926            1 :     m_libspdm_key_exchange_request1.reserved = 0;
    1927            1 :     ptr = m_libspdm_key_exchange_request1.exchange_data;
    1928            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1929            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    1930              :                                   false);
    1931            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    1932            1 :     ptr += dhe_key_size;
    1933            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1934            1 :     opaque_key_exchange_req_size =
    1935            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    1936            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    1937            1 :     ptr += sizeof(uint16_t);
    1938            1 :     libspdm_build_opaque_data_supported_version_data(
    1939              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    1940            1 :     ptr += opaque_key_exchange_req_size;
    1941            1 :     response_size = sizeof(response);
    1942            1 :     status = libspdm_get_response_key_exchange(
    1943              :         spdm_context, m_libspdm_key_exchange_request1_size,
    1944              :         &m_libspdm_key_exchange_request1, &response_size, response);
    1945            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1946            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
    1947            1 :     spdm_response = (void *)response;
    1948            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
    1949            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNSPECIFIED);
    1950            1 :     assert_int_equal(spdm_response->header.param2, 0);
    1951              : 
    1952            1 :     g_key_exchange_start_mut_auth = 0;
    1953            1 :     g_mandatory_mut_auth = false;
    1954            1 :     free(data1);
    1955            1 : }
    1956              : 
    1957              : 
    1958            1 : static void rsp_key_exchange_rsp_case24(void **state)
    1959              : {
    1960              :     libspdm_return_t status;
    1961              :     libspdm_test_context_t *spdm_test_context;
    1962              :     libspdm_context_t *spdm_context;
    1963              :     size_t response_size;
    1964              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
    1965              :     spdm_key_exchange_response_t *spdm_response;
    1966              :     void *data1;
    1967              :     size_t data_size1;
    1968              :     uint8_t *ptr;
    1969              :     size_t dhe_key_size;
    1970              :     void *dhe_context;
    1971              :     size_t opaque_key_exchange_req_size;
    1972              : 
    1973            1 :     spdm_test_context = *state;
    1974            1 :     spdm_context = spdm_test_context->spdm_context;
    1975            1 :     spdm_test_context->case_id = 0x18;
    1976            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1977            1 :     spdm_context->connection_info.capability.flags |=
    1978              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    1979              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1980            1 :     spdm_context->local_context.capability.flags |=
    1981              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    1982              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
    1983              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP |
    1984              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1985            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1986            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1987            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    1988            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    1989              :         m_libspdm_use_measurement_hash_algo;
    1990            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1991            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1992            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    1993              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1994            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1995              :                                                     m_libspdm_use_asym_algo, &data1,
    1996              :                                                     &data_size1, NULL, NULL);
    1997            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data1;
    1998            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size1;
    1999              : 
    2000            1 :     libspdm_reset_message_a(spdm_context);
    2001            1 :     g_key_exchange_start_mut_auth = SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
    2002            1 :     g_mandatory_mut_auth = true;
    2003              : 
    2004            1 :     spdm_context->local_context.secured_message_version.secured_message_version_count = 1;
    2005              : 
    2006            1 :     libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, m_libspdm_key_exchange_request10.random_data);
    2007            1 :     m_libspdm_key_exchange_request10.req_session_id = 0xFFFF;
    2008            1 :     m_libspdm_key_exchange_request10.reserved = 0;
    2009            1 :     ptr = m_libspdm_key_exchange_request10.exchange_data;
    2010            1 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    2011            1 :     dhe_context = libspdm_dhe_new(spdm_context->connection_info.version, m_libspdm_use_dhe_algo,
    2012              :                                   false);
    2013            1 :     libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    2014            1 :     ptr += dhe_key_size;
    2015            1 :     libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    2016            1 :     opaque_key_exchange_req_size =
    2017            1 :         libspdm_get_opaque_data_supported_version_data_size(spdm_context);
    2018            1 :     *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_req_size;
    2019            1 :     ptr += sizeof(uint16_t);
    2020            1 :     libspdm_build_opaque_data_supported_version_data(
    2021              :         spdm_context, &opaque_key_exchange_req_size, ptr);
    2022            1 :     ptr += opaque_key_exchange_req_size;
    2023            1 :     response_size = sizeof(response);
    2024            1 :     status = libspdm_get_response_key_exchange(
    2025              :         spdm_context, m_libspdm_key_exchange_request10_size,
    2026              :         &m_libspdm_key_exchange_request10, &response_size, response);
    2027            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    2028            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
    2029            1 :     spdm_response = (void *)response;
    2030            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
    2031            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_INVALID_POLICY);
    2032            1 :     assert_int_equal(spdm_response->header.param2, 0);
    2033              : 
    2034            1 :     g_mandatory_mut_auth = false;
    2035            1 :     g_key_exchange_start_mut_auth = 0;
    2036            1 :     free(data1);
    2037            1 : }
    2038              : 
    2039            1 : int libspdm_rsp_key_exchange_rsp_test(void)
    2040              : {
    2041            1 :     const struct CMUnitTest test_cases[] = {
    2042              :         /* Success Case*/
    2043              :         cmocka_unit_test(rsp_key_exchange_rsp_case1),
    2044              :         /* Bad request size*/
    2045              :         cmocka_unit_test(rsp_key_exchange_rsp_case2),
    2046              :         /* response_state: SPDM_RESPONSE_STATE_BUSY*/
    2047              :         cmocka_unit_test(rsp_key_exchange_rsp_case3),
    2048              :         /* response_state: SPDM_RESPONSE_STATE_NEED_RESYNC*/
    2049              :         cmocka_unit_test(rsp_key_exchange_rsp_case4),
    2050              :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
    2051              :         /* response_state: SPDM_RESPONSE_STATE_NOT_READY*/
    2052              :         cmocka_unit_test(rsp_key_exchange_rsp_case5),
    2053              :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
    2054              :         /* connection_state Check*/
    2055              :         cmocka_unit_test(rsp_key_exchange_rsp_case6),
    2056              :         /* Buffer reset*/
    2057              :         cmocka_unit_test(rsp_key_exchange_rsp_case7),
    2058              :         /* TCB measurement hash requested */
    2059              :         cmocka_unit_test(rsp_key_exchange_rsp_case8),
    2060              :         /* All measurement hash requested */
    2061              :         cmocka_unit_test(rsp_key_exchange_rsp_case9),
    2062              :         /* Reserved value in Measurement summary. Error + Invalid */
    2063              :         cmocka_unit_test(rsp_key_exchange_rsp_case10),
    2064              :         /* TCB measurement hash requested, measurement flag not set */
    2065              :         cmocka_unit_test(rsp_key_exchange_rsp_case11),
    2066              :         /* Request previously provisioned public key, slot 0xFF */
    2067              :         cmocka_unit_test(rsp_key_exchange_rsp_case14),
    2068              :         /* HANDSHAKE_IN_THE_CLEAR set for requester and responder */
    2069              :         cmocka_unit_test(rsp_key_exchange_rsp_case15),
    2070              :         /* Buffer verification*/
    2071              :         cmocka_unit_test(rsp_key_exchange_rsp_case16),
    2072              :         /* Successful response V1.2*/
    2073              :         cmocka_unit_test(rsp_key_exchange_rsp_case17),
    2074              :         /* Invalid SlotID in KEY_EXCHANGE request message*/
    2075              :         cmocka_unit_test(rsp_key_exchange_rsp_case18),
    2076              :         /* Only OpaqueDataFmt1 is supported, Bytes not aligned*/
    2077              :         cmocka_unit_test(rsp_key_exchange_rsp_case19),
    2078              :         /* OpaqueData only supports OpaqueDataFmt1, Success Case */
    2079              :         cmocka_unit_test(rsp_key_exchange_rsp_case20),
    2080              :         /* The key usage bit mask is not set, failed Case*/
    2081              :         cmocka_unit_test(rsp_key_exchange_rsp_case21),
    2082              :         cmocka_unit_test(rsp_key_exchange_rsp_case22),
    2083              :         /* The Responder requires mutual authentication, but the Requester does not support it */
    2084              :         cmocka_unit_test(rsp_key_exchange_rsp_case23),
    2085              :         cmocka_unit_test(rsp_key_exchange_rsp_case24),
    2086              :     };
    2087              : 
    2088            1 :     libspdm_test_context_t test_context = {
    2089              :         LIBSPDM_TEST_CONTEXT_VERSION,
    2090              :         false,
    2091              :     };
    2092              : 
    2093            1 :     libspdm_setup_test_context(&test_context);
    2094              : 
    2095            1 :     return cmocka_run_group_tests(test_cases,
    2096              :                                   libspdm_unit_test_group_setup,
    2097              :                                   libspdm_unit_test_group_teardown);
    2098              : }
    2099              : 
    2100              : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
        

Generated by: LCOV version 2.0-1