LCOV - code coverage report
Current view: top level - unit_test/test_spdm_requester - psk_exchange.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 91.6 % 2278 2087
Test Date: 2025-09-14 08:11:04 Functions: 96.8 % 31 30

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2021-2025 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_requester_lib.h"
       9              : #include "internal/libspdm_responder_lib.h"
      10              : 
      11              : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
      12              : 
      13              : #define LIBSPDM_BIN_STR_2_LABEL "rsp hs data"
      14              : #define LIBSPDM_BIN_STR_7_LABEL "finished"
      15              : 
      16              : static size_t m_libspdm_local_buffer_size;
      17              : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
      18              : static uint8_t m_libspdm_zero_filled_buffer[LIBSPDM_MAX_HASH_SIZE];
      19              : 
      20              : static libspdm_th_managed_buffer_t th_curr;
      21              : 
      22           43 : size_t libspdm_test_get_psk_exchange_request_size(const void *spdm_context,
      23              :                                                   const void *buffer,
      24              :                                                   size_t buffer_size)
      25              : {
      26              :     const spdm_psk_exchange_request_t *spdm_request;
      27              :     size_t message_size;
      28              : 
      29           43 :     spdm_request = buffer;
      30           43 :     message_size = sizeof(spdm_message_header_t);
      31           43 :     if (buffer_size < message_size) {
      32            0 :         return buffer_size;
      33              :     }
      34              : 
      35           43 :     if (spdm_request->header.request_response_code != SPDM_PSK_EXCHANGE) {
      36            1 :         return buffer_size;
      37              :     }
      38              : 
      39           42 :     message_size = sizeof(spdm_psk_exchange_request_t);
      40           42 :     if (buffer_size < message_size) {
      41            0 :         return buffer_size;
      42              :     }
      43              : 
      44           42 :     message_size += spdm_request->psk_hint_length +
      45           42 :                     spdm_request->context_length +
      46           42 :                     spdm_request->opaque_length;
      47           42 :     if (buffer_size < message_size) {
      48            0 :         return buffer_size;
      49              :     }
      50              : 
      51              :     /* Good message, return actual size*/
      52           42 :     return message_size;
      53              : }
      54              : 
      55           45 : libspdm_return_t libspdm_requester_psk_exchange_test_send_message(
      56              :     void *spdm_context, size_t request_size, const void *request,
      57              :     uint64_t timeout)
      58              : {
      59              :     libspdm_test_context_t *spdm_test_context;
      60              :     size_t header_size;
      61              :     size_t message_size;
      62              : 
      63           45 :     spdm_test_context = libspdm_get_test_context();
      64           45 :     header_size = sizeof(libspdm_test_message_header_t);
      65           45 :     switch (spdm_test_context->case_id) {
      66            1 :     case 0x1:
      67            1 :         return LIBSPDM_STATUS_SEND_FAIL;
      68            1 :     case 0x2:
      69            1 :         m_libspdm_local_buffer_size = 0;
      70            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
      71              :             spdm_context, (const uint8_t *)request + header_size,
      72              :             request_size - header_size);
      73            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
      74              :                          (const uint8_t *)request + header_size, message_size);
      75            1 :         m_libspdm_local_buffer_size += message_size;
      76            1 :         return LIBSPDM_STATUS_SUCCESS;
      77            0 :     case 0x3:
      78            0 :         m_libspdm_local_buffer_size = 0;
      79            0 :         message_size = libspdm_test_get_psk_exchange_request_size(
      80              :             spdm_context, (const uint8_t *)request + header_size,
      81              :             request_size - header_size);
      82            0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
      83              :                          (const uint8_t *)request + header_size, message_size);
      84            0 :         m_libspdm_local_buffer_size += message_size;
      85            0 :         return LIBSPDM_STATUS_SUCCESS;
      86            1 :     case 0x4:
      87            1 :         m_libspdm_local_buffer_size = 0;
      88            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
      89              :             spdm_context, (const uint8_t *)request + header_size,
      90              :             request_size - header_size);
      91            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
      92              :                          (const uint8_t *)request + header_size, message_size);
      93            1 :         m_libspdm_local_buffer_size += message_size;
      94            1 :         return LIBSPDM_STATUS_SUCCESS;
      95            1 :     case 0x5:
      96            1 :         m_libspdm_local_buffer_size = 0;
      97            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
      98              :             spdm_context, (const uint8_t *)request + header_size,
      99              :             request_size - header_size);
     100            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     101              :                          (const uint8_t *)request + header_size, message_size);
     102            1 :         m_libspdm_local_buffer_size += message_size;
     103            1 :         return LIBSPDM_STATUS_SUCCESS;
     104            2 :     case 0x6:
     105            2 :         m_libspdm_local_buffer_size = 0;
     106            2 :         message_size = libspdm_test_get_psk_exchange_request_size(
     107              :             spdm_context, (const uint8_t *)request + header_size,
     108              :             request_size - header_size);
     109            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     110              :                          (const uint8_t *)request + header_size, message_size);
     111            2 :         m_libspdm_local_buffer_size += message_size;
     112            2 :         return LIBSPDM_STATUS_SUCCESS;
     113            1 :     case 0x7:
     114            1 :         m_libspdm_local_buffer_size = 0;
     115            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     116              :             spdm_context, (const uint8_t *)request + header_size,
     117              :             request_size - header_size);
     118            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     119              :                          (const uint8_t *)request + header_size, message_size);
     120            1 :         m_libspdm_local_buffer_size += message_size;
     121            1 :         return LIBSPDM_STATUS_SUCCESS;
     122            2 :     case 0x8:
     123            2 :         m_libspdm_local_buffer_size = 0;
     124            2 :         message_size = libspdm_test_get_psk_exchange_request_size(
     125              :             spdm_context, (const uint8_t *)request + header_size,
     126              :             request_size - header_size);
     127            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     128              :                          (const uint8_t *)request + header_size, message_size);
     129            2 :         m_libspdm_local_buffer_size += message_size;
     130            2 :         return LIBSPDM_STATUS_SUCCESS;
     131            2 :     case 0x9: {
     132              :         static size_t sub_index = 0;
     133            2 :         if (sub_index == 0) {
     134            1 :             m_libspdm_local_buffer_size = 0;
     135            1 :             message_size = libspdm_test_get_psk_exchange_request_size(
     136              :                 spdm_context, (const uint8_t *)request + header_size,
     137              :                 request_size - header_size);
     138            1 :             libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     139              :                              (const uint8_t *)request + header_size, message_size);
     140            1 :             m_libspdm_local_buffer_size += message_size;
     141            1 :             sub_index++;
     142              :         }
     143              :     }
     144            2 :         return LIBSPDM_STATUS_SUCCESS;
     145           18 :     case 0xA:
     146           18 :         m_libspdm_local_buffer_size = 0;
     147           18 :         message_size = libspdm_test_get_psk_exchange_request_size(
     148              :             spdm_context, (const uint8_t *)request + header_size,
     149              :             request_size - header_size);
     150           18 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     151              :                          (const uint8_t *)request + header_size, message_size);
     152           18 :         m_libspdm_local_buffer_size += message_size;
     153           18 :         return LIBSPDM_STATUS_SUCCESS;
     154            0 :     case 0xB:
     155            0 :         m_libspdm_local_buffer_size = 0;
     156            0 :         message_size = libspdm_test_get_psk_exchange_request_size(
     157              :             spdm_context, (const uint8_t *)request + header_size,
     158              :             request_size - header_size);
     159            0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     160              :                          (const uint8_t *)request + header_size, message_size);
     161            0 :         m_libspdm_local_buffer_size += message_size;
     162            0 :         return LIBSPDM_STATUS_SUCCESS;
     163            1 :     case 0xC:
     164            1 :         m_libspdm_local_buffer_size = 0;
     165            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     166              :             spdm_context, (const uint8_t *)request + header_size, request_size - header_size);
     167            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     168              :                          (const uint8_t *)request + header_size, message_size);
     169            1 :         m_libspdm_local_buffer_size += message_size;
     170            1 :         return LIBSPDM_STATUS_SUCCESS;
     171            1 :     case 0xD:
     172            1 :         m_libspdm_local_buffer_size = 0;
     173            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     174              :             spdm_context, (const uint8_t *)request + header_size,
     175              :             request_size - header_size);
     176            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     177              :                          (const uint8_t *)request + header_size, message_size);
     178            1 :         m_libspdm_local_buffer_size += message_size;
     179            1 :         return LIBSPDM_STATUS_SUCCESS;
     180            1 :     case 0xE:
     181            1 :         m_libspdm_local_buffer_size = 0;
     182            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     183              :             spdm_context, (const uint8_t *)request + header_size,
     184              :             request_size - header_size);
     185            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     186              :                          (const uint8_t *)request + header_size, message_size);
     187            1 :         m_libspdm_local_buffer_size += message_size;
     188            1 :         return LIBSPDM_STATUS_SUCCESS;
     189            1 :     case 0xF:
     190            1 :         m_libspdm_local_buffer_size = 0;
     191            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     192              :             spdm_context, (const uint8_t *)request + header_size,
     193              :             request_size - header_size);
     194            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     195              :                          (const uint8_t *)request + header_size, message_size);
     196            1 :         m_libspdm_local_buffer_size += message_size;
     197            1 :         return LIBSPDM_STATUS_SUCCESS;
     198            1 :     case 0x10:
     199            1 :         m_libspdm_local_buffer_size = 0;
     200            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     201              :             spdm_context, (const uint8_t *)request + header_size,
     202              :             request_size - header_size);
     203            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     204              :                          (const uint8_t *)request + header_size, message_size);
     205            1 :         m_libspdm_local_buffer_size += message_size;
     206            1 :         return LIBSPDM_STATUS_SUCCESS;
     207            1 :     case 0x11:
     208            1 :         m_libspdm_local_buffer_size = 0;
     209            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     210              :             spdm_context, (const uint8_t *)request + header_size,
     211              :             request_size - header_size);
     212            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     213              :                          (const uint8_t *)request + header_size, message_size);
     214            1 :         m_libspdm_local_buffer_size += message_size;
     215            1 :         return LIBSPDM_STATUS_SUCCESS;
     216            1 :     case 0x12:
     217            1 :         m_libspdm_local_buffer_size = 0;
     218            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     219              :             spdm_context, (const uint8_t *)request + header_size,
     220              :             request_size - header_size);
     221            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     222              :                          (const uint8_t *)request + header_size, message_size);
     223            1 :         m_libspdm_local_buffer_size += message_size;
     224            1 :         return LIBSPDM_STATUS_SUCCESS;
     225            1 :     case 0x13:
     226            1 :         m_libspdm_local_buffer_size = 0;
     227            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     228              :             spdm_context, (const uint8_t *)request + header_size,
     229              :             request_size - header_size);
     230            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     231              :                          (const uint8_t *)request + header_size, message_size);
     232            1 :         m_libspdm_local_buffer_size += message_size;
     233            1 :         return LIBSPDM_STATUS_SUCCESS;
     234            1 :     case 0x14:
     235            1 :         m_libspdm_local_buffer_size = 0;
     236            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     237              :             spdm_context, (const uint8_t *)request + header_size,
     238              :             request_size - header_size);
     239            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     240              :                          (const uint8_t *)request + header_size, message_size);
     241            1 :         m_libspdm_local_buffer_size += message_size;
     242            1 :         return LIBSPDM_STATUS_SUCCESS;
     243            1 :     case 0x15:
     244            1 :         m_libspdm_local_buffer_size = 0;
     245            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     246              :             spdm_context, (const uint8_t *)request + header_size,
     247              :             request_size - header_size);
     248            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     249              :                          (const uint8_t *)request + header_size, message_size);
     250            1 :         m_libspdm_local_buffer_size += message_size;
     251            1 :         return LIBSPDM_STATUS_SUCCESS;
     252            1 :     case 0x16:
     253            1 :         m_libspdm_local_buffer_size = 0;
     254            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     255              :             spdm_context, (const uint8_t *)request + header_size,
     256              :             request_size - header_size);
     257            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     258              :                          (const uint8_t *)request + header_size, message_size);
     259            1 :         m_libspdm_local_buffer_size += message_size;
     260            1 :         return LIBSPDM_STATUS_SUCCESS;
     261            1 :     case 0x17:
     262            1 :         m_libspdm_local_buffer_size = 0;
     263            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     264              :             spdm_context, (const uint8_t *)request + header_size,
     265              :             request_size - header_size);
     266            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     267              :                          (const uint8_t *)request + header_size, message_size);
     268            1 :         m_libspdm_local_buffer_size += message_size;
     269            1 :         return LIBSPDM_STATUS_SUCCESS;
     270            1 :     case 0x18:
     271            1 :         m_libspdm_local_buffer_size = 0;
     272            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     273              :             spdm_context, (const uint8_t *)request + header_size,
     274              :             request_size - header_size);
     275            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     276              :                          (const uint8_t *)request + header_size, message_size);
     277            1 :         m_libspdm_local_buffer_size += message_size;
     278            1 :         return LIBSPDM_STATUS_SUCCESS;
     279            1 :     case 0x19:
     280            1 :         m_libspdm_local_buffer_size = 0;
     281            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     282              :             spdm_context, (const uint8_t *)request + header_size,
     283              :             request_size - header_size);
     284            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     285              :                          (const uint8_t *)request + header_size, message_size);
     286            1 :         m_libspdm_local_buffer_size += message_size;
     287            1 :         return LIBSPDM_STATUS_SUCCESS;
     288            1 :     case 0x1A:
     289            1 :         m_libspdm_local_buffer_size = 0;
     290            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     291              :             spdm_context, (const uint8_t *)request + header_size,
     292              :             request_size - header_size);
     293            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     294              :                          (const uint8_t *)request + header_size, message_size);
     295            1 :         m_libspdm_local_buffer_size += message_size;
     296            1 :         return LIBSPDM_STATUS_SUCCESS;
     297            1 :     case 0x1B:
     298            1 :         m_libspdm_local_buffer_size = 0;
     299            1 :         message_size = libspdm_test_get_psk_exchange_request_size(
     300              :             spdm_context, (const uint8_t *)request + header_size,
     301              :             request_size - header_size);
     302            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     303              :                          (const uint8_t *)request + header_size, message_size);
     304            1 :         m_libspdm_local_buffer_size += message_size;
     305            1 :         return LIBSPDM_STATUS_SUCCESS;
     306            0 :     default:
     307            0 :         return LIBSPDM_STATUS_SEND_FAIL;
     308              :     }
     309              : }
     310              : 
     311           44 : libspdm_return_t libspdm_requester_psk_exchange_test_receive_message(
     312              :     void *spdm_context, size_t *response_size,
     313              :     void **response, uint64_t timeout)
     314              : {
     315              :     libspdm_test_context_t *spdm_test_context;
     316              : 
     317           44 :     spdm_test_context = libspdm_get_test_context();
     318           44 :     switch (spdm_test_context->case_id) {
     319            0 :     case 0x1:
     320            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
     321              : 
     322            1 :     case 0x2: {
     323              :         spdm_psk_exchange_response_t *spdm_response;
     324              :         uint32_t hash_size;
     325              :         uint32_t hmac_size;
     326              :         uint8_t *ptr;
     327              :         size_t opaque_psk_exchange_rsp_size;
     328              :         void *data;
     329              :         size_t data_size;
     330              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     331              :         uint8_t *cert_buffer;
     332              :         size_t cert_buffer_size;
     333              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
     334              :         uint8_t bin_str2[128];
     335              :         size_t bin_str2_size;
     336              :         uint8_t bin_str7[128];
     337              :         size_t bin_str7_size;
     338              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
     339              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
     340              :         size_t spdm_response_size;
     341              :         size_t transport_header_size;
     342              : 
     343            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
     344              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
     345              :         ((libspdm_context_t *)spdm_context)
     346            1 :         ->connection_info.algorithm.base_asym_algo =
     347              :             m_libspdm_use_asym_algo;
     348              :         ((libspdm_context_t *)spdm_context)
     349            1 :         ->connection_info.algorithm.base_hash_algo =
     350              :             m_libspdm_use_hash_algo;
     351              :         ((libspdm_context_t *)spdm_context)
     352            1 :         ->connection_info.algorithm.dhe_named_group =
     353              :             m_libspdm_use_dhe_algo;
     354              :         ((libspdm_context_t *)spdm_context)
     355            1 :         ->connection_info.algorithm.measurement_hash_algo =
     356              :             m_libspdm_use_measurement_hash_algo;
     357            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     358            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     359            1 :         opaque_psk_exchange_rsp_size =
     360            1 :             libspdm_get_opaque_data_version_selection_data_size(
     361              :                 spdm_context);
     362            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
     363              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
     364            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
     365            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     366            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     367              : 
     368            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     369            1 :         spdm_response->header.request_response_code =
     370              :             SPDM_PSK_EXCHANGE_RSP;
     371            1 :         spdm_response->header.param1 = 0;
     372            1 :         spdm_response->header.param2 = 0;
     373            1 :         spdm_response->rsp_session_id =
     374            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
     375            1 :         spdm_response->reserved = 0;
     376            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
     377            1 :         spdm_response->opaque_length =
     378            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
     379            1 :         ptr = (void *)(spdm_response + 1);
     380              :         /* libspdm_zero_mem (ptr, hash_size);
     381              :          * ptr += hash_size;*/
     382            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
     383            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
     384            1 :         libspdm_build_opaque_data_version_selection_data(
     385              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
     386            1 :         ptr += opaque_psk_exchange_rsp_size;
     387            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     388              :                          sizeof(m_libspdm_local_buffer)
     389            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     390              :                             m_libspdm_local_buffer),
     391            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
     392            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
     393            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     394              :                        m_libspdm_local_buffer_size));
     395            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     396            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
     397            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     398              :                                                         m_libspdm_use_asym_algo, &data,
     399              :                                                         &data_size, NULL, NULL);
     400            1 :         cert_buffer =
     401            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
     402            1 :         cert_buffer_size =
     403            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
     404            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
     405              :                          cert_buffer_hash);
     406              :         /* transcript.message_a size is 0*/
     407            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
     408              :                                       m_libspdm_local_buffer_size);
     409            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     410              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
     411            1 :         free(data);
     412            1 :         bin_str2_size = sizeof(bin_str2);
     413            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     414              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
     415            1 :                            hash_data, (uint16_t)hash_size, hash_size,
     416              :                            bin_str2, &bin_str2_size);
     417            1 :         libspdm_psk_handshake_secret_hkdf_expand(
     418            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     419              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
     420              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
     421              :                 bin_str2_size,
     422              :                 response_handshake_secret, hash_size);
     423            1 :         bin_str7_size = sizeof(bin_str7);
     424            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     425              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
     426            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
     427              :                            &bin_str7_size);
     428            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
     429              :                             hash_size, bin_str7, bin_str7_size,
     430              :                             response_finished_key, hash_size);
     431            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     432              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
     433            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
     434              :                          response_finished_key, hash_size, ptr);
     435            1 :         ptr += hmac_size;
     436              : 
     437            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     438              :                                               false, spdm_response_size,
     439              :                                               spdm_response, response_size,
     440              :                                               response);
     441              :     }
     442            1 :         return LIBSPDM_STATUS_SUCCESS;
     443              : 
     444            0 :     case 0x3: {
     445              :         spdm_psk_exchange_response_t *spdm_response;
     446              :         uint32_t hash_size;
     447              :         uint32_t hmac_size;
     448              :         uint8_t *ptr;
     449              :         size_t opaque_psk_exchange_rsp_size;
     450              :         void *data;
     451              :         size_t data_size;
     452              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     453              :         uint8_t *cert_buffer;
     454              :         size_t cert_buffer_size;
     455              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
     456              :         uint8_t bin_str2[128];
     457              :         size_t bin_str2_size;
     458              :         uint8_t bin_str7[128];
     459              :         size_t bin_str7_size;
     460              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
     461              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
     462              :         size_t spdm_response_size;
     463              :         size_t transport_header_size;
     464              : 
     465              :         ((libspdm_context_t *)spdm_context)
     466            0 :         ->connection_info.algorithm.base_asym_algo =
     467              :             m_libspdm_use_asym_algo;
     468              :         ((libspdm_context_t *)spdm_context)
     469            0 :         ->connection_info.algorithm.base_hash_algo =
     470              :             m_libspdm_use_hash_algo;
     471              :         ((libspdm_context_t *)spdm_context)
     472            0 :         ->connection_info.algorithm.dhe_named_group =
     473              :             m_libspdm_use_dhe_algo;
     474              :         ((libspdm_context_t *)spdm_context)
     475            0 :         ->connection_info.algorithm.measurement_hash_algo =
     476              :             m_libspdm_use_measurement_hash_algo;
     477            0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     478            0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     479            0 :         opaque_psk_exchange_rsp_size =
     480            0 :             libspdm_get_opaque_data_version_selection_data_size(
     481              :                 spdm_context);
     482            0 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
     483              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
     484            0 :                              opaque_psk_exchange_rsp_size + hmac_size;
     485            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     486            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     487              : 
     488            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     489            0 :         spdm_response->header.request_response_code =
     490              :             SPDM_PSK_EXCHANGE_RSP;
     491            0 :         spdm_response->header.param1 = 0;
     492            0 :         spdm_response->header.param2 = 0;
     493            0 :         spdm_response->rsp_session_id =
     494            0 :             libspdm_allocate_rsp_session_id(spdm_context, true);
     495            0 :         spdm_response->reserved = 0;
     496            0 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
     497            0 :         spdm_response->opaque_length =
     498            0 :             (uint16_t)opaque_psk_exchange_rsp_size;
     499            0 :         ptr = (void *)(spdm_response + 1);
     500              :         /* libspdm_zero_mem (ptr, hash_size);
     501              :          * ptr += hash_size;*/
     502            0 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
     503            0 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
     504            0 :         libspdm_build_opaque_data_version_selection_data(
     505              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
     506            0 :         ptr += opaque_psk_exchange_rsp_size;
     507            0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     508              :                          sizeof(m_libspdm_local_buffer)
     509            0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     510              :                             m_libspdm_local_buffer),
     511            0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
     512            0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
     513            0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     514              :                        m_libspdm_local_buffer_size));
     515            0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     516            0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
     517            0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     518              :                                                         m_libspdm_use_asym_algo, &data,
     519              :                                                         &data_size, NULL, NULL);
     520            0 :         cert_buffer =
     521            0 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
     522            0 :         cert_buffer_size =
     523            0 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
     524            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
     525              :                          cert_buffer_hash);
     526              :         /* transcript.message_a size is 0*/
     527            0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
     528              :                                       m_libspdm_local_buffer_size);
     529            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     530              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
     531            0 :         free(data);
     532            0 :         bin_str2_size = sizeof(bin_str2);
     533            0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     534              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
     535            0 :                            hash_data, (uint16_t)hash_size, hash_size,
     536              :                            bin_str2, &bin_str2_size);
     537            0 :         libspdm_psk_handshake_secret_hkdf_expand(
     538            0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     539              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
     540              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
     541              :                 bin_str2_size,
     542              :                 response_handshake_secret, hash_size);
     543            0 :         bin_str7_size = sizeof(bin_str7);
     544            0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     545              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
     546            0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
     547              :                            &bin_str7_size);
     548            0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
     549              :                             hash_size, bin_str7, bin_str7_size,
     550              :                             response_finished_key, hash_size);
     551            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     552              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
     553            0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
     554              :                          response_finished_key, hash_size, ptr);
     555            0 :         ptr += hmac_size;
     556              : 
     557            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     558              :                                               false, spdm_response_size,
     559              :                                               spdm_response, response_size,
     560              :                                               response);
     561              :     }
     562            0 :         return LIBSPDM_STATUS_SUCCESS;
     563              : 
     564            1 :     case 0x4: {
     565              :         spdm_error_response_t *spdm_response;
     566              :         size_t spdm_response_size;
     567              :         size_t transport_header_size;
     568              : 
     569            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     570            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     571            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     572              : 
     573            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     574            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     575            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
     576            1 :         spdm_response->header.param2 = 0;
     577              : 
     578            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     579              :                                               false, spdm_response_size,
     580              :                                               spdm_response,
     581              :                                               response_size, response);
     582              :     }
     583            1 :         return LIBSPDM_STATUS_SUCCESS;
     584              : 
     585            1 :     case 0x5: {
     586              :         spdm_error_response_t *spdm_response;
     587              :         size_t spdm_response_size;
     588              :         size_t transport_header_size;
     589              : 
     590            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     591            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     592            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     593              : 
     594            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     595            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     596            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     597            1 :         spdm_response->header.param2 = 0;
     598              : 
     599            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     600              :                                               false, spdm_response_size,
     601              :                                               spdm_response,
     602              :                                               response_size, response);
     603              :     }
     604            1 :         return LIBSPDM_STATUS_SUCCESS;
     605              : 
     606            2 :     case 0x6: {
     607              :         static size_t sub_index1 = 0;
     608            2 :         if (sub_index1 == 0) {
     609              :             spdm_error_response_t *spdm_response;
     610              :             size_t spdm_response_size;
     611              :             size_t transport_header_size;
     612              : 
     613            1 :             spdm_response_size = sizeof(spdm_error_response_t);
     614            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     615            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     616              : 
     617            1 :             spdm_response->header.spdm_version =
     618              :                 SPDM_MESSAGE_VERSION_11;
     619            1 :             spdm_response->header.request_response_code = SPDM_ERROR;
     620            1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     621            1 :             spdm_response->header.param2 = 0;
     622              : 
     623            1 :             libspdm_transport_test_encode_message(
     624              :                 spdm_context, NULL, false, false,
     625              :                 spdm_response_size, spdm_response,
     626              :                 response_size, response);
     627            1 :             sub_index1++;
     628            1 :         } else if (sub_index1 == 1) {
     629              :             spdm_psk_exchange_response_t *spdm_response;
     630              :             uint32_t hash_size;
     631              :             uint32_t hmac_size;
     632              :             uint8_t *ptr;
     633              :             size_t opaque_psk_exchange_rsp_size;
     634              :             void *data;
     635              :             size_t data_size;
     636              :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     637              :             uint8_t *cert_buffer;
     638              :             size_t cert_buffer_size;
     639              :             uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
     640              :             uint8_t bin_str2[128];
     641              :             size_t bin_str2_size;
     642              :             uint8_t bin_str7[128];
     643              :             size_t bin_str7_size;
     644              :             uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
     645              :             uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
     646              :             size_t spdm_response_size;
     647              :             size_t transport_header_size;
     648              : 
     649              :             ((libspdm_context_t *)spdm_context)
     650            1 :             ->connection_info.algorithm.base_asym_algo =
     651              :                 m_libspdm_use_asym_algo;
     652              :             ((libspdm_context_t *)spdm_context)
     653            1 :             ->connection_info.algorithm.base_hash_algo =
     654              :                 m_libspdm_use_hash_algo;
     655              :             ((libspdm_context_t *)spdm_context)
     656            1 :             ->connection_info.algorithm.dhe_named_group =
     657              :                 m_libspdm_use_dhe_algo;
     658              :             ((libspdm_context_t *)spdm_context)
     659              :             ->connection_info.algorithm
     660            1 :             .measurement_hash_algo =
     661              :                 m_libspdm_use_measurement_hash_algo;
     662            1 :             hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     663            1 :             hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     664            1 :             opaque_psk_exchange_rsp_size =
     665            1 :                 libspdm_get_opaque_data_version_selection_data_size(
     666              :                     spdm_context);
     667            1 :             spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
     668              :                                  0 + LIBSPDM_PSK_CONTEXT_LENGTH +
     669            1 :                                  opaque_psk_exchange_rsp_size +
     670              :                                  hmac_size;
     671            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     672            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     673              : 
     674            1 :             spdm_response->header.spdm_version =
     675              :                 SPDM_MESSAGE_VERSION_11;
     676            1 :             spdm_response->header.request_response_code =
     677              :                 SPDM_PSK_EXCHANGE_RSP;
     678            1 :             spdm_response->header.param1 = 0;
     679            1 :             spdm_response->header.param2 = 0;
     680            1 :             spdm_response->rsp_session_id =
     681            1 :                 libspdm_allocate_rsp_session_id(spdm_context, true);
     682            1 :             spdm_response->reserved = 0;
     683            1 :             spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
     684            1 :             spdm_response->opaque_length =
     685            1 :                 (uint16_t)opaque_psk_exchange_rsp_size;
     686            1 :             ptr = (void *)(spdm_response + 1);
     687              :             /* libspdm_zero_mem (ptr, hash_size);
     688              :              * ptr += hash_size;*/
     689            1 :             libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
     690            1 :             ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
     691            1 :             libspdm_build_opaque_data_version_selection_data(
     692              :                 spdm_context, &opaque_psk_exchange_rsp_size,
     693              :                 ptr);
     694            1 :             ptr += opaque_psk_exchange_rsp_size;
     695            1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     696              :                              sizeof(m_libspdm_local_buffer)
     697            1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     698              :                                 m_libspdm_local_buffer),
     699            1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
     700            1 :             m_libspdm_local_buffer_size +=
     701            1 :                 ((size_t)ptr - (size_t)spdm_response);
     702            1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     703              :                            m_libspdm_local_buffer_size));
     704            1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     705            1 :             libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
     706            1 :             libspdm_read_responder_public_certificate_chain(
     707              :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
     708              :                 &data_size, NULL, NULL);
     709            1 :             cert_buffer = (uint8_t *)data +
     710            1 :                           sizeof(spdm_cert_chain_t) + hash_size;
     711            1 :             cert_buffer_size =
     712            1 :                 data_size -
     713              :                 (sizeof(spdm_cert_chain_t) + hash_size);
     714            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
     715              :                              cert_buffer_size, cert_buffer_hash);
     716              :             /* transcript.message_a size is 0*/
     717            1 :             libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
     718              :                                           m_libspdm_local_buffer_size);
     719            2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
     720            1 :                              libspdm_get_managed_buffer(&th_curr),
     721              :                              libspdm_get_managed_buffer_size(&th_curr),
     722              :                              hash_data);
     723            1 :             free(data);
     724            1 :             bin_str2_size = sizeof(bin_str2);
     725            1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     726              :                                LIBSPDM_BIN_STR_2_LABEL,
     727              :                                sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1, hash_data,
     728            1 :                                (uint16_t)hash_size, hash_size, bin_str2,
     729              :                                &bin_str2_size);
     730            1 :             libspdm_psk_handshake_secret_hkdf_expand(
     731            1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     732              :                     m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
     733              :                     sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
     734              :                     bin_str2_size, response_handshake_secret,
     735              :                     hash_size);
     736            1 :             bin_str7_size = sizeof(bin_str7);
     737            1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     738              :                                LIBSPDM_BIN_STR_7_LABEL,
     739              :                                sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1, NULL,
     740            1 :                                (uint16_t)hash_size, hash_size, bin_str7,
     741              :                                &bin_str7_size);
     742            1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo,
     743              :                                 response_handshake_secret, hash_size,
     744              :                                 bin_str7, bin_str7_size,
     745              :                                 response_finished_key, hash_size);
     746            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     747              :                              libspdm_get_managed_buffer_size(&th_curr), hash_data);
     748            1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
     749              :                              response_finished_key, hash_size, ptr);
     750            1 :             ptr += hmac_size;
     751              : 
     752            1 :             libspdm_transport_test_encode_message(
     753              :                 spdm_context, NULL, false, false, spdm_response_size,
     754              :                 spdm_response, response_size, response);
     755              :         }
     756              :     }
     757            2 :         return LIBSPDM_STATUS_SUCCESS;
     758              : 
     759            1 :     case 0x7: {
     760              :         spdm_error_response_t *spdm_response;
     761              :         size_t spdm_response_size;
     762              :         size_t transport_header_size;
     763              : 
     764            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     765            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     766            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     767              : 
     768            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     769            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     770            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
     771            1 :         spdm_response->header.param2 = 0;
     772              : 
     773            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     774              :                                               false, spdm_response_size,
     775              :                                               spdm_response,
     776              :                                               response_size, response);
     777              :     }
     778            1 :         return LIBSPDM_STATUS_SUCCESS;
     779              : 
     780            2 :     case 0x8: {
     781              :         spdm_error_response_data_response_not_ready_t *spdm_response;
     782              :         size_t spdm_response_size;
     783              :         size_t transport_header_size;
     784              : 
     785            2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
     786            2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     787            2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     788              : 
     789            2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     790            2 :         spdm_response->header.request_response_code = SPDM_ERROR;
     791            2 :         spdm_response->header.param1 =
     792              :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
     793            2 :         spdm_response->header.param2 = 0;
     794            2 :         spdm_response->extend_error_data.rd_exponent = 1;
     795            2 :         spdm_response->extend_error_data.rd_tm = 2;
     796            2 :         spdm_response->extend_error_data.request_code =
     797              :             SPDM_PSK_EXCHANGE;
     798            2 :         spdm_response->extend_error_data.token = 0;
     799              : 
     800            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     801              :                                               false, spdm_response_size,
     802              :                                               spdm_response,
     803              :                                               response_size, response);
     804              :     }
     805            2 :         return LIBSPDM_STATUS_SUCCESS;
     806              : 
     807            2 :     case 0x9: {
     808              :         static size_t sub_index2 = 0;
     809            2 :         if (sub_index2 == 0) {
     810              :             spdm_error_response_data_response_not_ready_t
     811              :             *spdm_response;
     812              :             size_t spdm_response_size;
     813              :             size_t transport_header_size;
     814              : 
     815            1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
     816            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     817            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     818              : 
     819            1 :             spdm_response->header.spdm_version =
     820              :                 SPDM_MESSAGE_VERSION_11;
     821            1 :             spdm_response->header.request_response_code = SPDM_ERROR;
     822            1 :             spdm_response->header.param1 =
     823              :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
     824            1 :             spdm_response->header.param2 = 0;
     825            1 :             spdm_response->extend_error_data.rd_exponent = 1;
     826            1 :             spdm_response->extend_error_data.rd_tm = 2;
     827            1 :             spdm_response->extend_error_data.request_code =
     828              :                 SPDM_PSK_EXCHANGE;
     829            1 :             spdm_response->extend_error_data.token = 1;
     830              : 
     831            1 :             libspdm_transport_test_encode_message(
     832              :                 spdm_context, NULL, false, false,
     833              :                 spdm_response_size, spdm_response,
     834              :                 response_size, response);
     835            1 :             sub_index2++;
     836            1 :         } else if (sub_index2 == 1) {
     837              :             spdm_psk_exchange_response_t *spdm_response;
     838              :             uint32_t hash_size;
     839              :             uint32_t hmac_size;
     840              :             uint8_t *ptr;
     841              :             size_t opaque_psk_exchange_rsp_size;
     842              :             void *data;
     843              :             size_t data_size;
     844              :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     845              :             uint8_t *cert_buffer;
     846              :             size_t cert_buffer_size;
     847              :             uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
     848              :             uint8_t bin_str2[128];
     849              :             size_t bin_str2_size;
     850              :             uint8_t bin_str7[128];
     851              :             size_t bin_str7_size;
     852              :             uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
     853              :             uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
     854              :             size_t spdm_response_size;
     855              :             size_t transport_header_size;
     856              : 
     857              :             ((libspdm_context_t *)spdm_context)
     858            1 :             ->connection_info.algorithm.base_asym_algo =
     859              :                 m_libspdm_use_asym_algo;
     860              :             ((libspdm_context_t *)spdm_context)
     861            1 :             ->connection_info.algorithm.base_hash_algo =
     862              :                 m_libspdm_use_hash_algo;
     863              :             ((libspdm_context_t *)spdm_context)
     864            1 :             ->connection_info.algorithm.dhe_named_group =
     865              :                 m_libspdm_use_dhe_algo;
     866              :             ((libspdm_context_t *)spdm_context)
     867              :             ->connection_info.algorithm
     868            1 :             .measurement_hash_algo =
     869              :                 m_libspdm_use_measurement_hash_algo;
     870            1 :             hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     871            1 :             hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     872            1 :             opaque_psk_exchange_rsp_size =
     873            1 :                 libspdm_get_opaque_data_version_selection_data_size(
     874              :                     spdm_context);
     875            1 :             spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
     876              :                                  0 + LIBSPDM_PSK_CONTEXT_LENGTH +
     877            1 :                                  opaque_psk_exchange_rsp_size +
     878              :                                  hmac_size;
     879            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     880            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     881              : 
     882            1 :             spdm_response->header.spdm_version =
     883              :                 SPDM_MESSAGE_VERSION_11;
     884            1 :             spdm_response->header.request_response_code =
     885              :                 SPDM_PSK_EXCHANGE_RSP;
     886            1 :             spdm_response->header.param1 = 0;
     887            1 :             spdm_response->header.param2 = 0;
     888            1 :             spdm_response->rsp_session_id =
     889            1 :                 libspdm_allocate_rsp_session_id(spdm_context, true);
     890            1 :             spdm_response->reserved = 0;
     891            1 :             spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
     892            1 :             spdm_response->opaque_length =
     893            1 :                 (uint16_t)opaque_psk_exchange_rsp_size;
     894            1 :             ptr = (void *)(spdm_response + 1);
     895              :             /* libspdm_zero_mem (ptr, hash_size);
     896              :              * ptr += hash_size;*/
     897            1 :             libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
     898            1 :             ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
     899            1 :             libspdm_build_opaque_data_version_selection_data(
     900              :                 spdm_context, &opaque_psk_exchange_rsp_size,
     901              :                 ptr);
     902            1 :             ptr += opaque_psk_exchange_rsp_size;
     903            1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     904              :                              sizeof(m_libspdm_local_buffer)
     905            1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     906              :                                 m_libspdm_local_buffer),
     907            1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
     908            1 :             m_libspdm_local_buffer_size +=
     909            1 :                 ((size_t)ptr - (size_t)spdm_response);
     910            1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     911              :                            m_libspdm_local_buffer_size));
     912            1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     913            1 :             libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
     914            1 :             libspdm_read_responder_public_certificate_chain(
     915              :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
     916              :                 &data_size, NULL, NULL);
     917            1 :             cert_buffer = (uint8_t *)data +
     918            1 :                           sizeof(spdm_cert_chain_t) + hash_size;
     919            1 :             cert_buffer_size =
     920            1 :                 data_size -
     921              :                 (sizeof(spdm_cert_chain_t) + hash_size);
     922            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
     923              :                              cert_buffer_size, cert_buffer_hash);
     924              :             /* transcript.message_a size is 0*/
     925            1 :             libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
     926              :                                           m_libspdm_local_buffer_size);
     927            2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
     928            1 :                              libspdm_get_managed_buffer(&th_curr),
     929              :                              libspdm_get_managed_buffer_size(&th_curr),
     930              :                              hash_data);
     931            1 :             free(data);
     932            1 :             bin_str2_size = sizeof(bin_str2);
     933            1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     934              :                                LIBSPDM_BIN_STR_2_LABEL,
     935              :                                sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1, hash_data,
     936            1 :                                (uint16_t)hash_size, hash_size, bin_str2,
     937              :                                &bin_str2_size);
     938            1 :             libspdm_psk_handshake_secret_hkdf_expand(
     939            1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     940              :                     m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
     941              :                     sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
     942              :                     bin_str2_size, response_handshake_secret,
     943              :                     hash_size);
     944            1 :             bin_str7_size = sizeof(bin_str7);
     945            1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     946              :                                LIBSPDM_BIN_STR_7_LABEL,
     947              :                                sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1, NULL,
     948            1 :                                (uint16_t)hash_size, hash_size, bin_str7,
     949              :                                &bin_str7_size);
     950            1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo,
     951              :                                 response_handshake_secret, hash_size,
     952              :                                 bin_str7, bin_str7_size,
     953              :                                 response_finished_key, hash_size);
     954            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     955              :                              libspdm_get_managed_buffer_size(&th_curr), hash_data);
     956            1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
     957              :                              response_finished_key, hash_size, ptr);
     958            1 :             ptr += hmac_size;
     959              : 
     960            1 :             libspdm_transport_test_encode_message(
     961              :                 spdm_context, NULL, false, false, spdm_response_size,
     962              :                 spdm_response, response_size, response);
     963              :         }
     964              :     }
     965            2 :         return LIBSPDM_STATUS_SUCCESS;
     966              : 
     967           18 :     case 0xA:
     968              :     {
     969              :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
     970              : 
     971              :         spdm_error_response_t *spdm_response;
     972              :         size_t spdm_response_size;
     973              :         size_t transport_header_size;
     974              : 
     975           18 :         spdm_response_size = sizeof(spdm_error_response_t);
     976           18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     977           18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     978              : 
     979           18 :         if(error_code <= 0xff) {
     980           18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
     981           18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     982           18 :             spdm_response->header.request_response_code = SPDM_ERROR;
     983           18 :             spdm_response->header.param1 = (uint8_t) error_code;
     984           18 :             spdm_response->header.param2 = 0;
     985              : 
     986           18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
     987              :                                                    spdm_response_size, spdm_response,
     988              :                                                    response_size, response);
     989              :         }
     990              : 
     991           18 :         error_code++;
     992           18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
     993            1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
     994              :         }
     995           18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
     996            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
     997              :         }
     998           18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
     999            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
    1000              :         }
    1001              :     }
    1002           18 :         return LIBSPDM_STATUS_SUCCESS;
    1003              : 
    1004            0 :     case 0xB: {
    1005              :         spdm_psk_exchange_response_t *spdm_response;
    1006              :         uint32_t hash_size;
    1007              :         uint32_t hmac_size;
    1008              :         uint8_t *ptr;
    1009              :         size_t opaque_psk_exchange_rsp_size;
    1010              :         void *data;
    1011              :         size_t data_size;
    1012              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1013              :         uint8_t *cert_buffer;
    1014              :         size_t cert_buffer_size;
    1015              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1016              :         uint8_t bin_str2[128];
    1017              :         size_t bin_str2_size;
    1018              :         uint8_t bin_str7[128];
    1019              :         size_t bin_str7_size;
    1020              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1021              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1022              :         size_t spdm_response_size;
    1023              :         size_t transport_header_size;
    1024              : 
    1025              :         ((libspdm_context_t *)spdm_context)
    1026            0 :         ->connection_info.algorithm.base_asym_algo =
    1027              :             m_libspdm_use_asym_algo;
    1028              :         ((libspdm_context_t *)spdm_context)
    1029            0 :         ->connection_info.algorithm.base_hash_algo =
    1030              :             m_libspdm_use_hash_algo;
    1031              :         ((libspdm_context_t *)spdm_context)
    1032            0 :         ->connection_info.algorithm.dhe_named_group =
    1033              :             m_libspdm_use_dhe_algo;
    1034              :         ((libspdm_context_t *)spdm_context)
    1035            0 :         ->connection_info.algorithm.measurement_hash_algo =
    1036              :             m_libspdm_use_measurement_hash_algo;
    1037            0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1038            0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1039            0 :         opaque_psk_exchange_rsp_size =
    1040            0 :             libspdm_get_opaque_data_version_selection_data_size(
    1041              :                 spdm_context);
    1042            0 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    1043              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    1044            0 :                              opaque_psk_exchange_rsp_size + hmac_size;
    1045            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1046            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1047              : 
    1048            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1049            0 :         spdm_response->header.request_response_code =
    1050              :             SPDM_PSK_EXCHANGE_RSP;
    1051            0 :         spdm_response->header.param1 = 0;
    1052            0 :         spdm_response->header.param2 = 0;
    1053            0 :         spdm_response->rsp_session_id =
    1054            0 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    1055            0 :         spdm_response->reserved = 0;
    1056            0 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    1057            0 :         spdm_response->opaque_length =
    1058            0 :             (uint16_t)opaque_psk_exchange_rsp_size;
    1059            0 :         ptr = (void *)(spdm_response + 1);
    1060              :         /* libspdm_zero_mem (ptr, hash_size);
    1061              :          * ptr += hash_size;*/
    1062            0 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    1063            0 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    1064            0 :         libspdm_build_opaque_data_version_selection_data(
    1065              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    1066            0 :         ptr += opaque_psk_exchange_rsp_size;
    1067            0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1068              :                          sizeof(m_libspdm_local_buffer)
    1069            0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1070              :                             m_libspdm_local_buffer),
    1071            0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1072            0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1073            0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1074              :                        m_libspdm_local_buffer_size));
    1075            0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1076            0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1077            0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1078              :                                                         m_libspdm_use_asym_algo, &data,
    1079              :                                                         &data_size, NULL, NULL);
    1080            0 :         cert_buffer =
    1081            0 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    1082            0 :         cert_buffer_size =
    1083            0 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    1084            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1085              :                          cert_buffer_hash);
    1086              :         /* transcript.message_a size is 0*/
    1087            0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1088              :                                       m_libspdm_local_buffer_size);
    1089            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1090              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1091            0 :         free(data);
    1092            0 :         bin_str2_size = sizeof(bin_str2);
    1093            0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1094              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
    1095            0 :                            hash_data, (uint16_t)hash_size, hash_size,
    1096              :                            bin_str2, &bin_str2_size);
    1097            0 :         libspdm_psk_handshake_secret_hkdf_expand(
    1098            0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1099              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    1100              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    1101              :                 bin_str2_size,
    1102              :                 response_handshake_secret, hash_size);
    1103            0 :         bin_str7_size = sizeof(bin_str7);
    1104            0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1105              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
    1106            0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1107              :                            &bin_str7_size);
    1108            0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1109              :                             hash_size, bin_str7, bin_str7_size,
    1110              :                             response_finished_key, hash_size);
    1111            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1112              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1113            0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1114              :                          response_finished_key, hash_size, ptr);
    1115            0 :         ptr += hmac_size;
    1116              : 
    1117            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1118              :                                               false, spdm_response_size,
    1119              :                                               spdm_response, response_size,
    1120              :                                               response);
    1121              :     }
    1122            0 :         return LIBSPDM_STATUS_SUCCESS;
    1123              : 
    1124            1 :     case 0xC: {
    1125              :         spdm_psk_exchange_response_t *spdm_response;
    1126              :         uint32_t hash_size;
    1127              :         uint32_t hmac_size;
    1128              :         uint8_t *ptr;
    1129              :         size_t opaque_psk_exchange_rsp_size;
    1130              :         void *data;
    1131              :         size_t data_size;
    1132              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1133              :         uint8_t *cert_buffer;
    1134              :         size_t cert_buffer_size;
    1135              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1136              :         uint8_t bin_str2[128];
    1137              :         size_t bin_str2_size;
    1138              :         uint8_t bin_str7[128];
    1139              :         size_t bin_str7_size;
    1140              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1141              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1142              :         size_t spdm_response_size;
    1143              :         size_t transport_header_size;
    1144              : 
    1145            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_asym_algo =
    1146              :             m_libspdm_use_asym_algo;
    1147            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
    1148              :             m_libspdm_use_hash_algo;
    1149            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.dhe_named_group =
    1150              :             m_libspdm_use_dhe_algo;
    1151            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
    1152              :             m_libspdm_use_measurement_hash_algo;
    1153            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1154            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1155            1 :         opaque_psk_exchange_rsp_size =
    1156            1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
    1157            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    1158              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    1159            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    1160            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1161            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1162              : 
    1163            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1164            1 :         spdm_response->header.request_response_code = SPDM_PSK_EXCHANGE_RSP;
    1165            1 :         spdm_response->header.param1 = 0;
    1166            1 :         spdm_response->header.param2 = 0;
    1167            1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, true);
    1168            1 :         spdm_response->reserved = 0;
    1169            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    1170            1 :         spdm_response->opaque_length = (uint16_t)opaque_psk_exchange_rsp_size;
    1171            1 :         ptr = (void *)(spdm_response + 1);
    1172              :         /* libspdm_zero_mem (ptr, hash_size);
    1173              :          * ptr += hash_size;*/
    1174            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    1175            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    1176            1 :         libspdm_build_opaque_data_version_selection_data(
    1177              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    1178            1 :         ptr += opaque_psk_exchange_rsp_size;
    1179            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1180              :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
    1181            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1182            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1183            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
    1184              :                        m_libspdm_local_buffer_size));
    1185            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1186            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1187            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1188              :                                                         m_libspdm_use_asym_algo, &data,
    1189              :                                                         &data_size, NULL, NULL);
    1190            1 :         cert_buffer = (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    1191            1 :         cert_buffer_size = data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    1192            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1193              :                          cert_buffer_hash);
    1194              :         /* transcript.message_a size is 0*/
    1195            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1196              :                                       m_libspdm_local_buffer_size);
    1197            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1198              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1199            1 :         free(data);
    1200            1 :         bin_str2_size = sizeof(bin_str2);
    1201            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1202              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1203            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    1204              :                            bin_str2, &bin_str2_size);
    1205            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    1206            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1207              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    1208              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2, bin_str2_size,
    1209              :                 response_handshake_secret, hash_size);
    1210            1 :         bin_str7_size = sizeof(bin_str7);
    1211            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1212              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    1213            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7, &bin_str7_size);
    1214            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1215              :                             hash_size, bin_str7, bin_str7_size,
    1216              :                             response_finished_key, hash_size);
    1217            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1218              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1219            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1220              :                          response_finished_key, hash_size, ptr);
    1221            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1222              :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
    1223              :                          ptr, hmac_size);
    1224            1 :         m_libspdm_local_buffer_size += hmac_size;
    1225            1 :         ptr += hmac_size;
    1226              : 
    1227            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1228              :                                               false, spdm_response_size,
    1229              :                                               spdm_response, response_size,
    1230              :                                               response);
    1231              :     }
    1232            1 :         return LIBSPDM_STATUS_SUCCESS;
    1233            1 :     case 0xD: {
    1234              :         spdm_psk_exchange_response_t *spdm_response;
    1235              :         uint32_t hash_size;
    1236              :         uint32_t hmac_size;
    1237              :         uint8_t *ptr;
    1238              :         size_t opaque_psk_exchange_rsp_size;
    1239              :         void *data;
    1240              :         size_t data_size;
    1241              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1242              :         uint8_t *cert_buffer;
    1243              :         size_t cert_buffer_size;
    1244              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1245              :         uint8_t bin_str2[128];
    1246              :         size_t bin_str2_size;
    1247              :         uint8_t bin_str7[128];
    1248              :         size_t bin_str7_size;
    1249              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1250              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1251              :         size_t spdm_response_size;
    1252              :         size_t transport_header_size;
    1253              : 
    1254            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    1255              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    1256              :         ((libspdm_context_t *)spdm_context)
    1257            1 :         ->connection_info.algorithm.base_asym_algo =
    1258              :             m_libspdm_use_asym_algo;
    1259              :         ((libspdm_context_t *)spdm_context)
    1260            1 :         ->connection_info.algorithm.base_hash_algo =
    1261              :             m_libspdm_use_hash_algo;
    1262              :         ((libspdm_context_t *)spdm_context)
    1263            1 :         ->connection_info.algorithm.dhe_named_group =
    1264              :             m_libspdm_use_dhe_algo;
    1265              :         ((libspdm_context_t *)spdm_context)
    1266            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1267              :             m_libspdm_use_measurement_hash_algo;
    1268            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1269            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1270            1 :         opaque_psk_exchange_rsp_size =
    1271            1 :             libspdm_get_opaque_data_version_selection_data_size(
    1272              :                 spdm_context);
    1273            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    1274              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    1275            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    1276            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1277            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1278              : 
    1279            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    1280            1 :         spdm_response->header.request_response_code =
    1281              :             SPDM_PSK_EXCHANGE_RSP;
    1282            1 :         spdm_response->header.param1 = 0;
    1283            1 :         spdm_response->header.param2 = 0;
    1284            1 :         spdm_response->rsp_session_id =
    1285            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    1286            1 :         spdm_response->reserved = 0;
    1287            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    1288            1 :         spdm_response->opaque_length =
    1289            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    1290            1 :         ptr = (void *)(spdm_response + 1);
    1291              :         /* libspdm_zero_mem (ptr, hash_size);
    1292              :          * ptr += hash_size;*/
    1293            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    1294            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    1295            1 :         libspdm_build_opaque_data_version_selection_data(
    1296              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    1297            1 :         ptr += opaque_psk_exchange_rsp_size;
    1298            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1299              :                          sizeof(m_libspdm_local_buffer)
    1300            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1301              :                             m_libspdm_local_buffer),
    1302            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1303            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1304            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1305              :                        m_libspdm_local_buffer_size));
    1306            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1307            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1308            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1309              :                                                         m_libspdm_use_asym_algo, &data,
    1310              :                                                         &data_size, NULL, NULL);
    1311            1 :         cert_buffer =
    1312            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    1313            1 :         cert_buffer_size =
    1314            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    1315            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1316              :                          cert_buffer_hash);
    1317              :         /* transcript.message_a size is 0*/
    1318            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1319              :                                       m_libspdm_local_buffer_size);
    1320            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1321              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1322            1 :         free(data);
    1323            1 :         bin_str2_size = sizeof(bin_str2);
    1324            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1325              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
    1326            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    1327              :                            bin_str2, &bin_str2_size);
    1328            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    1329            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1330              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    1331              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    1332              :                 bin_str2_size,
    1333              :                 response_handshake_secret, hash_size);
    1334            1 :         bin_str7_size = sizeof(bin_str7);
    1335            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1336              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
    1337            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1338              :                            &bin_str7_size);
    1339            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1340              :                             hash_size, bin_str7, bin_str7_size,
    1341              :                             response_finished_key, hash_size);
    1342            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1343              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1344            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1345              :                          response_finished_key, hash_size, ptr);
    1346            1 :         ptr += hmac_size;
    1347              : 
    1348            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1349              :                                               false, spdm_response_size,
    1350              :                                               spdm_response, response_size,
    1351              :                                               response);
    1352              :     }
    1353            1 :         return LIBSPDM_STATUS_SUCCESS;
    1354            1 :     case 0xE: {
    1355              :         spdm_psk_exchange_response_t *spdm_response;
    1356              :         uint32_t hash_size;
    1357              :         uint32_t hmac_size;
    1358              :         uint32_t measurement_hash_size;
    1359              :         uint8_t *ptr;
    1360              :         size_t opaque_psk_exchange_rsp_size;
    1361              :         void *data;
    1362              :         size_t data_size;
    1363              :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1364              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1365              :         uint8_t *cert_buffer;
    1366              :         size_t cert_buffer_size;
    1367              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1368              :         uint8_t bin_str2[128];
    1369              :         size_t bin_str2_size;
    1370              :         uint8_t bin_str7[128];
    1371              :         size_t bin_str7_size;
    1372              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1373              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1374              :         size_t spdm_response_size;
    1375              :         size_t transport_header_size;
    1376              : 
    1377            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    1378              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    1379              :         ((libspdm_context_t *)spdm_context)
    1380            1 :         ->connection_info.algorithm.base_asym_algo =
    1381              :             m_libspdm_use_asym_algo;
    1382              :         ((libspdm_context_t *)spdm_context)
    1383            1 :         ->connection_info.algorithm.base_hash_algo =
    1384              :             m_libspdm_use_hash_algo;
    1385              :         ((libspdm_context_t *)spdm_context)
    1386            1 :         ->connection_info.algorithm.dhe_named_group =
    1387              :             m_libspdm_use_dhe_algo;
    1388              :         ((libspdm_context_t *)spdm_context)
    1389            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1390              :             m_libspdm_use_measurement_hash_algo;
    1391            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1392            1 :         measurement_hash_size = libspdm_get_hash_size(
    1393              :             m_libspdm_use_hash_algo);
    1394            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1395            1 :         opaque_psk_exchange_rsp_size =
    1396            1 :             libspdm_get_opaque_data_version_selection_data_size(
    1397              :                 spdm_context);
    1398            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
    1399            1 :                              measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
    1400            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    1401            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1402            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1403              : 
    1404            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    1405              : 
    1406            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1407            1 :         spdm_response->header.request_response_code =
    1408              :             SPDM_PSK_EXCHANGE_RSP;
    1409            1 :         spdm_response->header.param1 = 0;
    1410            1 :         spdm_response->header.param2 = 0;
    1411            1 :         spdm_response->rsp_session_id =
    1412            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    1413            1 :         spdm_response->reserved = 0;
    1414            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    1415            1 :         spdm_response->opaque_length =
    1416            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    1417            1 :         ptr = (void *)(spdm_response + 1);
    1418              :         /*Mock measurement hash as TCB*/
    1419            1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
    1420              :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
    1421            1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
    1422              :                          measurement_hash_data, measurement_hash_size);
    1423              :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
    1424            1 :         ptr += measurement_hash_size;
    1425            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    1426            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    1427            1 :         libspdm_build_opaque_data_version_selection_data(
    1428              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    1429            1 :         ptr += opaque_psk_exchange_rsp_size;
    1430            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1431              :                          sizeof(m_libspdm_local_buffer)
    1432            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1433              :                             m_libspdm_local_buffer),
    1434            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1435            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1436            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1437              :                        m_libspdm_local_buffer_size));
    1438            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1439            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1440            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1441              :                                                         m_libspdm_use_asym_algo, &data,
    1442              :                                                         &data_size, NULL, NULL);
    1443            1 :         cert_buffer =
    1444            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    1445            1 :         cert_buffer_size =
    1446            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    1447            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1448              :                          cert_buffer_hash);
    1449              :         /* transcript.message_a size is 0*/
    1450            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1451              :                                       m_libspdm_local_buffer_size);
    1452            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1453              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1454            1 :         free(data);
    1455            1 :         bin_str2_size = sizeof(bin_str2);
    1456            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1457              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1458            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    1459              :                            bin_str2, &bin_str2_size);
    1460            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    1461            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1462              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    1463              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    1464              :                 bin_str2_size,
    1465              :                 response_handshake_secret, hash_size);
    1466            1 :         bin_str7_size = sizeof(bin_str7);
    1467            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1468              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    1469            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1470              :                            &bin_str7_size);
    1471            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1472              :                             hash_size, bin_str7, bin_str7_size,
    1473              :                             response_finished_key, hash_size);
    1474            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1475              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1476            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1477              :                          response_finished_key, hash_size, ptr);
    1478            1 :         ptr += hmac_size;
    1479              : 
    1480            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1481              :                                               false, spdm_response_size,
    1482              :                                               spdm_response, response_size,
    1483              :                                               response);
    1484              :     }
    1485            1 :         return LIBSPDM_STATUS_SUCCESS;
    1486              : 
    1487            1 :     case 0xF: {
    1488              :         spdm_psk_exchange_response_t *spdm_response;
    1489              :         uint32_t hash_size;
    1490              :         uint32_t hmac_size;
    1491              :         uint32_t measurement_hash_size;
    1492              :         uint8_t *ptr;
    1493              :         size_t opaque_psk_exchange_rsp_size;
    1494              :         void *data;
    1495              :         size_t data_size;
    1496              :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1497              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1498              :         uint8_t *cert_buffer;
    1499              :         size_t cert_buffer_size;
    1500              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1501              :         uint8_t bin_str2[128];
    1502              :         size_t bin_str2_size;
    1503              :         uint8_t bin_str7[128];
    1504              :         size_t bin_str7_size;
    1505              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1506              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1507              :         size_t spdm_response_size;
    1508              :         size_t transport_header_size;
    1509              : 
    1510            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    1511              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    1512              :         ((libspdm_context_t *)spdm_context)
    1513            1 :         ->connection_info.algorithm.base_asym_algo =
    1514              :             m_libspdm_use_asym_algo;
    1515              :         ((libspdm_context_t *)spdm_context)
    1516            1 :         ->connection_info.algorithm.base_hash_algo =
    1517              :             m_libspdm_use_hash_algo;
    1518              :         ((libspdm_context_t *)spdm_context)
    1519            1 :         ->connection_info.algorithm.dhe_named_group =
    1520              :             m_libspdm_use_dhe_algo;
    1521              :         ((libspdm_context_t *)spdm_context)
    1522            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1523              :             m_libspdm_use_measurement_hash_algo;
    1524            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1525            1 :         measurement_hash_size = libspdm_get_hash_size(
    1526              :             m_libspdm_use_hash_algo);
    1527            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1528            1 :         opaque_psk_exchange_rsp_size =
    1529            1 :             libspdm_get_opaque_data_version_selection_data_size(
    1530              :                 spdm_context);
    1531            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
    1532            1 :                              measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
    1533            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    1534            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1535            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1536              : 
    1537            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    1538              : 
    1539            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1540            1 :         spdm_response->header.request_response_code =
    1541              :             SPDM_PSK_EXCHANGE_RSP;
    1542            1 :         spdm_response->header.param1 = 0;
    1543            1 :         spdm_response->header.param2 = 0;
    1544            1 :         spdm_response->rsp_session_id =
    1545            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    1546            1 :         spdm_response->reserved = 0;
    1547            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    1548            1 :         spdm_response->opaque_length =
    1549            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    1550            1 :         ptr = (void *)(spdm_response + 1);
    1551              :         /*Mock measurement hash as 0x00 array*/
    1552            1 :         libspdm_zero_mem(measurement_hash_data, measurement_hash_size);
    1553            1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
    1554              :                          measurement_hash_data, measurement_hash_size);
    1555              :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
    1556            1 :         ptr += measurement_hash_size;
    1557            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    1558            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    1559            1 :         libspdm_build_opaque_data_version_selection_data(
    1560              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    1561            1 :         ptr += opaque_psk_exchange_rsp_size;
    1562            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1563              :                          sizeof(m_libspdm_local_buffer)
    1564            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1565              :                             m_libspdm_local_buffer),
    1566            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1567            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1568            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1569              :                        m_libspdm_local_buffer_size));
    1570            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1571            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1572            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1573              :                                                         m_libspdm_use_asym_algo, &data,
    1574              :                                                         &data_size, NULL, NULL);
    1575            1 :         cert_buffer =
    1576            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    1577            1 :         cert_buffer_size =
    1578            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    1579            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1580              :                          cert_buffer_hash);
    1581              :         /* transcript.message_a size is 0*/
    1582            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1583              :                                       m_libspdm_local_buffer_size);
    1584            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1585              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1586            1 :         free(data);
    1587            1 :         bin_str2_size = sizeof(bin_str2);
    1588            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1589              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1590            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    1591              :                            bin_str2, &bin_str2_size);
    1592            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    1593            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1594              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    1595              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    1596              :                 bin_str2_size,
    1597              :                 response_handshake_secret, hash_size);
    1598            1 :         bin_str7_size = sizeof(bin_str7);
    1599            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1600              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    1601            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1602              :                            &bin_str7_size);
    1603            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1604              :                             hash_size, bin_str7, bin_str7_size,
    1605              :                             response_finished_key, hash_size);
    1606            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1607              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1608            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1609              :                          response_finished_key, hash_size, ptr);
    1610            1 :         ptr += hmac_size;
    1611              : 
    1612            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1613              :                                               false, spdm_response_size,
    1614              :                                               spdm_response, response_size,
    1615              :                                               response);
    1616              :     }
    1617            1 :         return LIBSPDM_STATUS_SUCCESS;
    1618              : 
    1619            1 :     case 0x10: {
    1620              :         spdm_psk_exchange_response_t *spdm_response;
    1621              :         uint32_t hash_size;
    1622              :         uint32_t hmac_size;
    1623              :         uint32_t measurement_hash_size;
    1624              :         uint8_t *ptr;
    1625              :         size_t opaque_psk_exchange_rsp_size;
    1626              :         void *data;
    1627              :         size_t data_size;
    1628              :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1629              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1630              :         uint8_t *cert_buffer;
    1631              :         size_t cert_buffer_size;
    1632              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1633              :         uint8_t bin_str2[128];
    1634              :         size_t bin_str2_size;
    1635              :         uint8_t bin_str7[128];
    1636              :         size_t bin_str7_size;
    1637              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1638              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1639              :         size_t spdm_response_size;
    1640              :         size_t transport_header_size;
    1641              : 
    1642            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    1643              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    1644              :         ((libspdm_context_t *)spdm_context)
    1645            1 :         ->connection_info.algorithm.base_asym_algo =
    1646              :             m_libspdm_use_asym_algo;
    1647              :         ((libspdm_context_t *)spdm_context)
    1648            1 :         ->connection_info.algorithm.base_hash_algo =
    1649              :             m_libspdm_use_hash_algo;
    1650              :         ((libspdm_context_t *)spdm_context)
    1651            1 :         ->connection_info.algorithm.dhe_named_group =
    1652              :             m_libspdm_use_dhe_algo;
    1653              :         ((libspdm_context_t *)spdm_context)
    1654            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1655              :             m_libspdm_use_measurement_hash_algo;
    1656            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1657            1 :         measurement_hash_size = libspdm_get_hash_size(
    1658              :             m_libspdm_use_hash_algo);
    1659            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1660            1 :         opaque_psk_exchange_rsp_size =
    1661            1 :             libspdm_get_opaque_data_version_selection_data_size(
    1662              :                 spdm_context);
    1663            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
    1664            1 :                              measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
    1665            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    1666            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1667            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1668              : 
    1669            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    1670              : 
    1671            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1672            1 :         spdm_response->header.request_response_code =
    1673              :             SPDM_PSK_EXCHANGE_RSP;
    1674            1 :         spdm_response->header.param1 = 0;
    1675            1 :         spdm_response->header.param2 = 0;
    1676            1 :         spdm_response->rsp_session_id =
    1677            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    1678            1 :         spdm_response->reserved = 0;
    1679            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    1680            1 :         spdm_response->opaque_length =
    1681            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    1682            1 :         ptr = (void *)(spdm_response + 1);
    1683              :         /*Mock measurement hash*/
    1684            1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
    1685              :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
    1686            1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
    1687              :                          measurement_hash_data, measurement_hash_size);
    1688              :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
    1689            1 :         ptr += measurement_hash_size;
    1690            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    1691            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    1692            1 :         libspdm_build_opaque_data_version_selection_data(
    1693              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    1694            1 :         ptr += opaque_psk_exchange_rsp_size;
    1695            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1696              :                          sizeof(m_libspdm_local_buffer)
    1697            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1698              :                             m_libspdm_local_buffer),
    1699            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1700            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1701            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1702              :                        m_libspdm_local_buffer_size));
    1703            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1704            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1705            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1706              :                                                         m_libspdm_use_asym_algo, &data,
    1707              :                                                         &data_size, NULL, NULL);
    1708            1 :         cert_buffer =
    1709            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    1710            1 :         cert_buffer_size =
    1711            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    1712            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1713              :                          cert_buffer_hash);
    1714              :         /* transcript.message_a size is 0*/
    1715            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1716              :                                       m_libspdm_local_buffer_size);
    1717            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1718              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1719            1 :         free(data);
    1720            1 :         bin_str2_size = sizeof(bin_str2);
    1721            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1722              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1723            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    1724              :                            bin_str2, &bin_str2_size);
    1725            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    1726            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1727              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    1728              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    1729              :                 bin_str2_size,
    1730              :                 response_handshake_secret, hash_size);
    1731            1 :         bin_str7_size = sizeof(bin_str7);
    1732            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1733              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    1734            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1735              :                            &bin_str7_size);
    1736            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1737              :                             hash_size, bin_str7, bin_str7_size,
    1738              :                             response_finished_key, hash_size);
    1739            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1740              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1741            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1742              :                          response_finished_key, hash_size, ptr);
    1743            1 :         ptr += hmac_size;
    1744              : 
    1745            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1746              :                                               false, spdm_response_size,
    1747              :                                               spdm_response, response_size,
    1748              :                                               response);
    1749              :     }
    1750            1 :         return LIBSPDM_STATUS_SUCCESS;
    1751              : 
    1752            1 :     case 0x11: {
    1753              :         spdm_psk_exchange_response_t *spdm_response;
    1754              :         uint32_t hash_size;
    1755              :         uint32_t hmac_size;
    1756              :         uint8_t *ptr;
    1757              :         size_t opaque_psk_exchange_rsp_size;
    1758              :         void *data;
    1759              :         size_t data_size;
    1760              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1761              :         uint8_t *cert_buffer;
    1762              :         size_t cert_buffer_size;
    1763              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1764              :         uint8_t bin_str2[128];
    1765              :         size_t bin_str2_size;
    1766              :         uint8_t bin_str7[128];
    1767              :         size_t bin_str7_size;
    1768              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1769              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1770              :         size_t spdm_response_size;
    1771              :         size_t transport_header_size;
    1772              : 
    1773            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    1774              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    1775              :         ((libspdm_context_t *)spdm_context)
    1776            1 :         ->connection_info.algorithm.base_asym_algo =
    1777              :             m_libspdm_use_asym_algo;
    1778              :         ((libspdm_context_t *)spdm_context)
    1779            1 :         ->connection_info.algorithm.base_hash_algo =
    1780              :             m_libspdm_use_hash_algo;
    1781              :         ((libspdm_context_t *)spdm_context)
    1782            1 :         ->connection_info.algorithm.dhe_named_group =
    1783              :             m_libspdm_use_dhe_algo;
    1784              :         ((libspdm_context_t *)spdm_context)
    1785            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1786              :             m_libspdm_use_measurement_hash_algo;
    1787            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1788            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1789            1 :         opaque_psk_exchange_rsp_size =
    1790            1 :             libspdm_get_opaque_data_version_selection_data_size(
    1791              :                 spdm_context);
    1792            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    1793              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    1794            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    1795            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1796            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1797              : 
    1798            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    1799              : 
    1800            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1801            1 :         spdm_response->header.request_response_code =
    1802              :             SPDM_PSK_EXCHANGE_RSP;
    1803            1 :         spdm_response->header.param1 = 0;
    1804            1 :         spdm_response->header.param2 = 0;
    1805            1 :         spdm_response->rsp_session_id =
    1806            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    1807            1 :         spdm_response->reserved = 0;
    1808            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    1809            1 :         spdm_response->opaque_length =
    1810            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    1811            1 :         ptr = (void *)(spdm_response + 1);
    1812              :         /* libspdm_zero_mem (ptr, hash_size);
    1813              :          * ptr += hash_size;*/
    1814            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    1815            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    1816            1 :         libspdm_build_opaque_data_version_selection_data(
    1817              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    1818            1 :         ptr += opaque_psk_exchange_rsp_size;
    1819            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1820              :                          sizeof(m_libspdm_local_buffer)
    1821            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1822              :                             m_libspdm_local_buffer),
    1823            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1824            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1825            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1826              :                        m_libspdm_local_buffer_size));
    1827            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1828            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1829            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1830              :                                                         m_libspdm_use_asym_algo, &data,
    1831              :                                                         &data_size, NULL, NULL);
    1832            1 :         cert_buffer =
    1833            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    1834            1 :         cert_buffer_size =
    1835            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    1836            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1837              :                          cert_buffer_hash);
    1838              :         /* transcript.message_a size is 0*/
    1839            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1840              :                                       m_libspdm_local_buffer_size);
    1841            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1842              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1843            1 :         free(data);
    1844            1 :         bin_str2_size = sizeof(bin_str2);
    1845            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1846              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1847            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    1848              :                            bin_str2, &bin_str2_size);
    1849            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    1850            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1851              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    1852              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    1853              :                 bin_str2_size,
    1854              :                 response_handshake_secret, hash_size);
    1855            1 :         bin_str7_size = sizeof(bin_str7);
    1856            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1857              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    1858            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1859              :                            &bin_str7_size);
    1860            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1861              :                             hash_size, bin_str7, bin_str7_size,
    1862              :                             response_finished_key, hash_size);
    1863            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1864              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1865            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1866              :                          response_finished_key, hash_size, ptr);
    1867            1 :         ptr += hmac_size;
    1868              : 
    1869            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1870              :                                               false, spdm_response_size,
    1871              :                                               spdm_response, response_size,
    1872              :                                               response);
    1873              :     }
    1874            1 :         return LIBSPDM_STATUS_SUCCESS;
    1875              : 
    1876            1 :     case 0x12: {
    1877              :         spdm_psk_exchange_response_t *spdm_response;
    1878              :         uint32_t hash_size;
    1879              :         uint32_t hmac_size;
    1880              :         uint8_t *ptr;
    1881              :         size_t opaque_psk_exchange_rsp_size;
    1882              :         void *data;
    1883              :         size_t data_size;
    1884              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1885              :         uint8_t *cert_buffer;
    1886              :         size_t cert_buffer_size;
    1887              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1888              :         uint8_t bin_str2[128];
    1889              :         size_t bin_str2_size;
    1890              :         uint8_t bin_str7[128];
    1891              :         size_t bin_str7_size;
    1892              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1893              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1894              :         size_t spdm_response_size;
    1895              :         size_t transport_header_size;
    1896              : 
    1897            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    1898              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    1899              :         ((libspdm_context_t *)spdm_context)
    1900            1 :         ->connection_info.algorithm.base_asym_algo =
    1901              :             m_libspdm_use_asym_algo;
    1902              :         ((libspdm_context_t *)spdm_context)
    1903            1 :         ->connection_info.algorithm.base_hash_algo =
    1904              :             m_libspdm_use_hash_algo;
    1905              :         ((libspdm_context_t *)spdm_context)
    1906            1 :         ->connection_info.algorithm.dhe_named_group =
    1907              :             m_libspdm_use_dhe_algo;
    1908              :         ((libspdm_context_t *)spdm_context)
    1909            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1910              :             m_libspdm_use_measurement_hash_algo;
    1911            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1912            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1913            1 :         opaque_psk_exchange_rsp_size =
    1914            1 :             libspdm_get_opaque_data_version_selection_data_size(
    1915              :                 spdm_context);
    1916            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    1917              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    1918            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    1919            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1920            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1921              : 
    1922            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    1923              : 
    1924            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1925            1 :         spdm_response->header.request_response_code =
    1926              :             SPDM_PSK_EXCHANGE_RSP;
    1927            1 :         spdm_response->header.param1 = 0;
    1928            1 :         spdm_response->header.param2 = 0;
    1929            1 :         spdm_response->rsp_session_id =
    1930            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    1931            1 :         spdm_response->reserved = 0;
    1932            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    1933            1 :         spdm_response->opaque_length =
    1934            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    1935            1 :         ptr = (void *)(spdm_response + 1);
    1936              :         /* libspdm_zero_mem (ptr, hash_size);
    1937              :          * ptr += hash_size;*/
    1938            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    1939            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    1940            1 :         libspdm_build_opaque_data_version_selection_data(
    1941              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    1942            1 :         ptr += opaque_psk_exchange_rsp_size;
    1943            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1944              :                          sizeof(m_libspdm_local_buffer)
    1945            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1946              :                             m_libspdm_local_buffer),
    1947            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1948            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1949            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1950              :                        m_libspdm_local_buffer_size));
    1951            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1952            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1953            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1954              :                                                         m_libspdm_use_asym_algo, &data,
    1955              :                                                         &data_size, NULL, NULL);
    1956            1 :         cert_buffer =
    1957            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    1958            1 :         cert_buffer_size =
    1959            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    1960            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1961              :                          cert_buffer_hash);
    1962              :         /* transcript.message_a size is 0*/
    1963            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1964              :                                       m_libspdm_local_buffer_size);
    1965            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1966              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1967            1 :         free(data);
    1968            1 :         bin_str2_size = sizeof(bin_str2);
    1969            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1970              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1971            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    1972              :                            bin_str2, &bin_str2_size);
    1973            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    1974            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1975              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    1976              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    1977              :                 bin_str2_size,
    1978              :                 response_handshake_secret, hash_size);
    1979            1 :         bin_str7_size = sizeof(bin_str7);
    1980            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1981              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    1982            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1983              :                            &bin_str7_size);
    1984            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1985              :                             hash_size, bin_str7, bin_str7_size,
    1986              :                             response_finished_key, hash_size);
    1987            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1988              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1989            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1990              :                          response_finished_key, hash_size, ptr);
    1991            1 :         ptr += hmac_size;
    1992              : 
    1993            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1994              :                                               false, spdm_response_size,
    1995              :                                               spdm_response, response_size,
    1996              :                                               response);
    1997              :     }
    1998            1 :         return LIBSPDM_STATUS_SUCCESS;
    1999              : 
    2000            1 :     case 0x13: {
    2001              :         spdm_psk_exchange_response_t *spdm_response;
    2002              :         uint32_t hash_size;
    2003              :         uint32_t hmac_size;
    2004              :         uint32_t measurement_hash_size;
    2005              :         uint8_t *ptr;
    2006              :         size_t opaque_psk_exchange_rsp_size;
    2007              :         void *data;
    2008              :         size_t data_size;
    2009              :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
    2010              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2011              :         uint8_t *cert_buffer;
    2012              :         size_t cert_buffer_size;
    2013              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2014              :         uint8_t bin_str2[128];
    2015              :         size_t bin_str2_size;
    2016              :         uint8_t bin_str7[128];
    2017              :         size_t bin_str7_size;
    2018              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2019              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2020              :         size_t spdm_response_size;
    2021              :         size_t transport_header_size;
    2022              : 
    2023            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    2024              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2025              :         ((libspdm_context_t *)spdm_context)
    2026            1 :         ->connection_info.algorithm.base_asym_algo =
    2027              :             m_libspdm_use_asym_algo;
    2028              :         ((libspdm_context_t *)spdm_context)
    2029            1 :         ->connection_info.algorithm.base_hash_algo =
    2030              :             m_libspdm_use_hash_algo;
    2031              :         ((libspdm_context_t *)spdm_context)
    2032            1 :         ->connection_info.algorithm.dhe_named_group =
    2033              :             m_libspdm_use_dhe_algo;
    2034              :         ((libspdm_context_t *)spdm_context)
    2035            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2036              :             m_libspdm_use_measurement_hash_algo;
    2037            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2038            1 :         measurement_hash_size = libspdm_get_hash_size(
    2039              :             m_libspdm_use_hash_algo);
    2040            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2041            1 :         opaque_psk_exchange_rsp_size =
    2042            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2043              :                 spdm_context);
    2044            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
    2045            1 :                              measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
    2046            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    2047            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2048            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2049              : 
    2050            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    2051              : 
    2052            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2053            1 :         spdm_response->header.request_response_code =
    2054              :             SPDM_PSK_EXCHANGE_RSP;
    2055            1 :         spdm_response->header.param1 = 0;
    2056            1 :         spdm_response->header.param2 = 0;
    2057            1 :         spdm_response->rsp_session_id =
    2058            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    2059            1 :         spdm_response->reserved = 0;
    2060            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    2061            1 :         spdm_response->opaque_length =
    2062            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    2063            1 :         ptr = (void *)(spdm_response + 1);
    2064              :         /*Mock measurement hash as TCB*/
    2065            1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
    2066              :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
    2067            1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
    2068              :                          measurement_hash_data, measurement_hash_size);
    2069              :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
    2070            1 :         ptr += measurement_hash_size;
    2071            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    2072            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    2073            1 :         libspdm_build_opaque_data_version_selection_data(
    2074              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    2075            1 :         ptr += opaque_psk_exchange_rsp_size;
    2076            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2077              :                          sizeof(m_libspdm_local_buffer)
    2078            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2079              :                             m_libspdm_local_buffer),
    2080            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2081            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2082            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2083              :                        m_libspdm_local_buffer_size));
    2084            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2085            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2086            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2087              :                                                         m_libspdm_use_asym_algo, &data,
    2088              :                                                         &data_size, NULL, NULL);
    2089            1 :         cert_buffer =
    2090            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    2091            1 :         cert_buffer_size =
    2092            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    2093            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2094              :                          cert_buffer_hash);
    2095              :         /* transcript.message_a size is 0*/
    2096            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2097              :                                       m_libspdm_local_buffer_size);
    2098            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2099              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2100            1 :         free(data);
    2101            1 :         bin_str2_size = sizeof(bin_str2);
    2102            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2103              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    2104            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    2105              :                            bin_str2, &bin_str2_size);
    2106            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    2107            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2108              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    2109              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    2110              :                 bin_str2_size,
    2111              :                 response_handshake_secret, hash_size);
    2112            1 :         bin_str7_size = sizeof(bin_str7);
    2113            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2114              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    2115            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2116              :                            &bin_str7_size);
    2117            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2118              :                             hash_size, bin_str7, bin_str7_size,
    2119              :                             response_finished_key, hash_size);
    2120            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2121              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2122            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2123              :                          response_finished_key, hash_size, ptr);
    2124            1 :         ptr += hmac_size;
    2125              : 
    2126            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2127              :                                               false, spdm_response_size,
    2128              :                                               spdm_response, response_size,
    2129              :                                               response);
    2130              :     }
    2131            1 :         return LIBSPDM_STATUS_SUCCESS;
    2132              : 
    2133            1 :     case 0x14: {
    2134              :         spdm_psk_exchange_response_t *spdm_response;
    2135              :         uint32_t hash_size;
    2136              :         uint32_t hmac_size;
    2137              :         uint8_t *ptr;
    2138              :         size_t opaque_psk_exchange_rsp_size;
    2139              :         void *data;
    2140              :         size_t data_size;
    2141              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2142              :         uint8_t *cert_buffer;
    2143              :         size_t cert_buffer_size;
    2144              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2145              :         uint8_t bin_str2[128];
    2146              :         size_t bin_str2_size;
    2147              :         uint8_t bin_str7[128];
    2148              :         size_t bin_str7_size;
    2149              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2150              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2151              :         size_t spdm_response_size;
    2152              :         size_t transport_header_size;
    2153              : 
    2154            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    2155              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2156              :         ((libspdm_context_t *)spdm_context)
    2157            1 :         ->connection_info.algorithm.base_asym_algo =
    2158              :             m_libspdm_use_asym_algo;
    2159              :         ((libspdm_context_t *)spdm_context)
    2160            1 :         ->connection_info.algorithm.base_hash_algo =
    2161              :             m_libspdm_use_hash_algo;
    2162              :         ((libspdm_context_t *)spdm_context)
    2163            1 :         ->connection_info.algorithm.dhe_named_group =
    2164              :             m_libspdm_use_dhe_algo;
    2165              :         ((libspdm_context_t *)spdm_context)
    2166            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2167              :             m_libspdm_use_measurement_hash_algo;
    2168            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2169            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2170            1 :         opaque_psk_exchange_rsp_size =
    2171            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2172              :                 spdm_context);
    2173            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    2174              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    2175            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    2176            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2177            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2178              : 
    2179            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2180            1 :         spdm_response->header.request_response_code =
    2181              :             SPDM_PSK_EXCHANGE_RSP;
    2182            1 :         spdm_response->header.param1 = 5;
    2183            1 :         spdm_response->header.param2 = 0;
    2184            1 :         spdm_response->rsp_session_id =
    2185            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    2186            1 :         spdm_response->reserved = 0;
    2187            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    2188            1 :         spdm_response->opaque_length =
    2189            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    2190            1 :         ptr = (void *)(spdm_response + 1);
    2191              :         /* libspdm_zero_mem (ptr, hash_size);
    2192              :          * ptr += hash_size;*/
    2193            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    2194            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    2195            1 :         libspdm_build_opaque_data_version_selection_data(
    2196              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    2197            1 :         ptr += opaque_psk_exchange_rsp_size;
    2198            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2199              :                          sizeof(m_libspdm_local_buffer)
    2200            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2201              :                             m_libspdm_local_buffer),
    2202            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2203            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2204            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2205              :                        m_libspdm_local_buffer_size));
    2206            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2207            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2208            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2209              :                                                         m_libspdm_use_asym_algo, &data,
    2210              :                                                         &data_size, NULL, NULL);
    2211            1 :         cert_buffer =
    2212            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    2213            1 :         cert_buffer_size =
    2214            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    2215            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2216              :                          cert_buffer_hash);
    2217              :         /* transcript.message_a size is 0*/
    2218            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2219              :                                       m_libspdm_local_buffer_size);
    2220            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2221              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2222            1 :         free(data);
    2223            1 :         bin_str2_size = sizeof(bin_str2);
    2224            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2225              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
    2226            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    2227              :                            bin_str2, &bin_str2_size);
    2228            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    2229            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2230              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    2231              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    2232              :                 bin_str2_size,
    2233              :                 response_handshake_secret, hash_size);
    2234            1 :         bin_str7_size = sizeof(bin_str7);
    2235            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2236              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
    2237            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2238              :                            &bin_str7_size);
    2239            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2240              :                             hash_size, bin_str7, bin_str7_size,
    2241              :                             response_finished_key, hash_size);
    2242            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2243              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2244            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2245              :                          response_finished_key, hash_size, ptr);
    2246            1 :         ptr += hmac_size;
    2247              : 
    2248            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2249              :                                               false, spdm_response_size,
    2250              :                                               spdm_response, response_size,
    2251              :                                               response);
    2252              :     }
    2253            1 :         return LIBSPDM_STATUS_SUCCESS;
    2254              : 
    2255            1 :     case 0x15: {
    2256              :         spdm_psk_exchange_response_t *spdm_response;
    2257              :         uint32_t hash_size;
    2258              :         uint32_t hmac_size;
    2259              :         uint8_t *ptr;
    2260              :         size_t opaque_psk_exchange_rsp_size;
    2261              :         void *data;
    2262              :         size_t data_size;
    2263              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2264              :         uint8_t *cert_buffer;
    2265              :         size_t cert_buffer_size;
    2266              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2267              :         uint8_t bin_str2[128];
    2268              :         size_t bin_str2_size;
    2269              :         uint8_t bin_str7[128];
    2270              :         size_t bin_str7_size;
    2271              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2272              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2273              :         size_t spdm_response_size;
    2274              :         size_t transport_header_size;
    2275              : 
    2276            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    2277              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2278              :         ((libspdm_context_t *)spdm_context)
    2279            1 :         ->connection_info.algorithm.base_asym_algo =
    2280              :             m_libspdm_use_asym_algo;
    2281              :         ((libspdm_context_t *)spdm_context)
    2282            1 :         ->connection_info.algorithm.base_hash_algo =
    2283              :             m_libspdm_use_hash_algo;
    2284              :         ((libspdm_context_t *)spdm_context)
    2285            1 :         ->connection_info.algorithm.dhe_named_group =
    2286              :             m_libspdm_use_dhe_algo;
    2287              :         ((libspdm_context_t *)spdm_context)
    2288            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2289              :             m_libspdm_use_measurement_hash_algo;
    2290            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2291            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2292            1 :         opaque_psk_exchange_rsp_size =
    2293            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2294              :                 spdm_context);
    2295            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    2296              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    2297            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    2298            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2299            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2300              : 
    2301            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2302            1 :         spdm_response->header.request_response_code =
    2303              :             SPDM_PSK_EXCHANGE_RSP;
    2304            1 :         spdm_response->header.param1 = 5;
    2305            1 :         spdm_response->header.param2 = 0;
    2306            1 :         spdm_response->rsp_session_id =
    2307            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    2308            1 :         spdm_response->reserved = 0;
    2309            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    2310            1 :         spdm_response->opaque_length =
    2311            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    2312            1 :         ptr = (void *)(spdm_response + 1);
    2313              :         /* libspdm_zero_mem (ptr, hash_size);
    2314              :          * ptr += hash_size;*/
    2315            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    2316            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    2317            1 :         libspdm_build_opaque_data_version_selection_data(
    2318              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    2319            1 :         ptr += opaque_psk_exchange_rsp_size;
    2320            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2321              :                          sizeof(m_libspdm_local_buffer)
    2322            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2323              :                             m_libspdm_local_buffer),
    2324            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2325            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2326            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2327              :                        m_libspdm_local_buffer_size));
    2328            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2329            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2330            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2331              :                                                         m_libspdm_use_asym_algo, &data,
    2332              :                                                         &data_size, NULL, NULL);
    2333            1 :         cert_buffer =
    2334            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    2335            1 :         cert_buffer_size =
    2336            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    2337            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2338              :                          cert_buffer_hash);
    2339              :         /* transcript.message_a size is 0*/
    2340            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2341              :                                       m_libspdm_local_buffer_size);
    2342            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2343              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2344            1 :         free(data);
    2345            1 :         bin_str2_size = sizeof(bin_str2);
    2346            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2347              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
    2348            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    2349              :                            bin_str2, &bin_str2_size);
    2350            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    2351            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2352              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    2353              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    2354              :                 bin_str2_size,
    2355              :                 response_handshake_secret, hash_size);
    2356            1 :         bin_str7_size = sizeof(bin_str7);
    2357            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2358              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
    2359            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2360              :                            &bin_str7_size);
    2361            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2362              :                             hash_size, bin_str7, bin_str7_size,
    2363              :                             response_finished_key, hash_size);
    2364            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2365              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2366            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2367              :                          response_finished_key, hash_size, ptr);
    2368            1 :         ptr += hmac_size;
    2369              : 
    2370            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2371              :                                               false, spdm_response_size,
    2372              :                                               spdm_response, response_size,
    2373              :                                               response);
    2374              :     }
    2375            1 :         return LIBSPDM_STATUS_SUCCESS;
    2376              : 
    2377            1 :     case 0x16: {
    2378              :         spdm_psk_exchange_response_t *spdm_response;
    2379              :         uint32_t hash_size;
    2380              :         uint32_t hmac_size;
    2381              :         uint8_t *ptr;
    2382              :         size_t opaque_psk_exchange_rsp_size;
    2383              :         void *data;
    2384              :         size_t data_size;
    2385              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2386              :         uint8_t *cert_buffer;
    2387              :         size_t cert_buffer_size;
    2388              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2389              :         uint8_t bin_str2[128];
    2390              :         size_t bin_str2_size;
    2391              :         uint8_t bin_str7[128];
    2392              :         size_t bin_str7_size;
    2393              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2394              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2395              :         size_t spdm_response_size;
    2396              :         size_t transport_header_size;
    2397              : 
    2398            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    2399              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2400              :         ((libspdm_context_t *)spdm_context)
    2401            1 :         ->connection_info.algorithm.base_asym_algo =
    2402              :             m_libspdm_use_asym_algo;
    2403              :         ((libspdm_context_t *)spdm_context)
    2404            1 :         ->connection_info.algorithm.base_hash_algo =
    2405              :             m_libspdm_use_hash_algo;
    2406              :         ((libspdm_context_t *)spdm_context)
    2407            1 :         ->connection_info.algorithm.dhe_named_group =
    2408              :             m_libspdm_use_dhe_algo;
    2409              :         ((libspdm_context_t *)spdm_context)
    2410            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2411              :             m_libspdm_use_measurement_hash_algo;
    2412            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2413            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2414            1 :         opaque_psk_exchange_rsp_size =
    2415            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2416              :                 spdm_context);
    2417            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    2418              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    2419            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    2420            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2421            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2422              : 
    2423            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2424            1 :         spdm_response->header.request_response_code =
    2425              :             SPDM_PSK_EXCHANGE_RSP;
    2426            1 :         spdm_response->header.param1 = 0;
    2427            1 :         spdm_response->header.param2 = 0;
    2428            1 :         spdm_response->rsp_session_id =
    2429            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    2430            1 :         spdm_response->reserved = 0;
    2431            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    2432            1 :         spdm_response->opaque_length =
    2433            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    2434            1 :         ptr = (void *)(spdm_response + 1);
    2435              :         /* libspdm_zero_mem (ptr, hash_size);
    2436              :          * ptr += hash_size;*/
    2437            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    2438            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    2439            1 :         libspdm_build_opaque_data_version_selection_data(
    2440              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    2441            1 :         ptr += opaque_psk_exchange_rsp_size;
    2442            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2443              :                          sizeof(m_libspdm_local_buffer)
    2444            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2445              :                             m_libspdm_local_buffer),
    2446            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2447            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2448            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2449              :                        m_libspdm_local_buffer_size));
    2450            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2451            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2452            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2453              :                                                         m_libspdm_use_asym_algo, &data,
    2454              :                                                         &data_size, NULL, NULL);
    2455            1 :         cert_buffer =
    2456            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    2457            1 :         cert_buffer_size =
    2458            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    2459            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2460              :                          cert_buffer_hash);
    2461              :         /* transcript.message_a size is 0*/
    2462            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2463              :                                       m_libspdm_local_buffer_size);
    2464            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2465              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2466            1 :         free(data);
    2467            1 :         bin_str2_size = sizeof(bin_str2);
    2468            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2469              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
    2470            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    2471              :                            bin_str2, &bin_str2_size);
    2472            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    2473            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2474              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    2475              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    2476              :                 bin_str2_size,
    2477              :                 response_handshake_secret, hash_size);
    2478            1 :         bin_str7_size = sizeof(bin_str7);
    2479            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2480              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
    2481            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2482              :                            &bin_str7_size);
    2483            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2484              :                             hash_size, bin_str7, bin_str7_size,
    2485              :                             response_finished_key, hash_size);
    2486            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2487              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2488            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2489              :                          response_finished_key, hash_size, ptr);
    2490            1 :         ptr += hmac_size;
    2491              : 
    2492            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2493              :                                               false, spdm_response_size,
    2494              :                                               spdm_response, response_size,
    2495              :                                               response);
    2496              :     }
    2497            1 :         return LIBSPDM_STATUS_SUCCESS;
    2498              : 
    2499            1 :     case 0x17: {
    2500              :         spdm_psk_exchange_response_t *spdm_response;
    2501              :         uint32_t hash_size;
    2502              :         uint32_t hmac_size;
    2503              :         uint8_t *ptr;
    2504              :         size_t opaque_psk_exchange_rsp_size;
    2505              :         void *data;
    2506              :         size_t data_size;
    2507              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2508              :         uint8_t *cert_buffer;
    2509              :         size_t cert_buffer_size;
    2510              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2511              :         uint8_t bin_str2[128];
    2512              :         size_t bin_str2_size;
    2513              :         uint8_t bin_str7[128];
    2514              :         size_t bin_str7_size;
    2515              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2516              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2517              :         size_t spdm_response_size;
    2518              :         size_t transport_header_size;
    2519              : 
    2520            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    2521              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2522              :         ((libspdm_context_t *)spdm_context)
    2523            1 :         ->connection_info.algorithm.base_asym_algo =
    2524              :             m_libspdm_use_asym_algo;
    2525              :         ((libspdm_context_t *)spdm_context)
    2526            1 :         ->connection_info.algorithm.base_hash_algo =
    2527              :             m_libspdm_use_hash_algo;
    2528              :         ((libspdm_context_t *)spdm_context)
    2529            1 :         ->connection_info.algorithm.dhe_named_group =
    2530              :             m_libspdm_use_dhe_algo;
    2531              :         ((libspdm_context_t *)spdm_context)
    2532            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2533              :             m_libspdm_use_measurement_hash_algo;
    2534            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2535            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2536            1 :         opaque_psk_exchange_rsp_size =
    2537            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2538              :                 spdm_context);
    2539            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    2540              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    2541            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    2542            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2543            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2544              : 
    2545            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2546            1 :         spdm_response->header.request_response_code =
    2547              :             SPDM_PSK_EXCHANGE_RSP;
    2548            1 :         spdm_response->header.param1 = 0;
    2549            1 :         spdm_response->header.param2 = 0;
    2550            1 :         spdm_response->rsp_session_id =
    2551            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    2552            1 :         spdm_response->reserved = 0;
    2553            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    2554            1 :         spdm_response->opaque_length =
    2555            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    2556            1 :         ptr = (void *)(spdm_response + 1);
    2557              :         /* libspdm_zero_mem (ptr, hash_size);
    2558              :          * ptr += hash_size;*/
    2559            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    2560            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    2561            1 :         libspdm_build_opaque_data_version_selection_data(
    2562              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    2563            1 :         ptr += opaque_psk_exchange_rsp_size;
    2564            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2565              :                          sizeof(m_libspdm_local_buffer)
    2566            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2567              :                             m_libspdm_local_buffer),
    2568            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2569            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2570            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2571              :                        m_libspdm_local_buffer_size));
    2572            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2573            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2574            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2575              :                                                         m_libspdm_use_asym_algo, &data,
    2576              :                                                         &data_size, NULL, NULL);
    2577            1 :         cert_buffer =
    2578            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    2579            1 :         cert_buffer_size =
    2580            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    2581            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2582              :                          cert_buffer_hash);
    2583              :         /* transcript.message_a size is 0*/
    2584            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2585              :                                       m_libspdm_local_buffer_size);
    2586            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2587              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2588            1 :         free(data);
    2589            1 :         bin_str2_size = sizeof(bin_str2);
    2590            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2591              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
    2592            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    2593              :                            bin_str2, &bin_str2_size);
    2594            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    2595            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2596              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    2597              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    2598              :                 bin_str2_size,
    2599              :                 response_handshake_secret, hash_size);
    2600            1 :         bin_str7_size = sizeof(bin_str7);
    2601            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2602              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
    2603            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2604              :                            &bin_str7_size);
    2605            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2606              :                             hash_size, bin_str7, bin_str7_size,
    2607              :                             response_finished_key, hash_size);
    2608            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2609              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2610            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2611              :                          response_finished_key, hash_size, ptr);
    2612              :         /* Flip last byte of ResponderVerifyData*/
    2613            1 :         ptr += hmac_size-1;
    2614            1 :         *ptr ^= 0xFF;
    2615            1 :         ptr++;
    2616              : 
    2617            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2618              :                                               false, spdm_response_size,
    2619              :                                               spdm_response, response_size,
    2620              :                                               response);
    2621              :     }
    2622            1 :         return LIBSPDM_STATUS_SUCCESS;
    2623              : 
    2624            1 :     case 0x18: {
    2625              :         spdm_psk_exchange_response_t *spdm_response;
    2626              :         uint32_t hash_size;
    2627              :         uint32_t hmac_size;
    2628              :         uint8_t *ptr;
    2629              :         size_t opaque_psk_exchange_rsp_size;
    2630              :         void *data;
    2631              :         size_t data_size;
    2632              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2633              :         uint8_t *cert_buffer;
    2634              :         size_t cert_buffer_size;
    2635              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2636              :         uint8_t bin_str2[128];
    2637              :         size_t bin_str2_size;
    2638              :         uint8_t bin_str7[128];
    2639              :         size_t bin_str7_size;
    2640              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2641              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2642              :         size_t spdm_response_size;
    2643              :         size_t transport_header_size;
    2644              : 
    2645            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    2646              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2647              :         ((libspdm_context_t *)spdm_context)
    2648            1 :         ->connection_info.algorithm.base_asym_algo =
    2649              :             m_libspdm_use_asym_algo;
    2650              :         ((libspdm_context_t *)spdm_context)
    2651            1 :         ->connection_info.algorithm.base_hash_algo =
    2652              :             m_libspdm_use_hash_algo;
    2653              :         ((libspdm_context_t *)spdm_context)
    2654            1 :         ->connection_info.algorithm.dhe_named_group =
    2655              :             m_libspdm_use_dhe_algo;
    2656              :         ((libspdm_context_t *)spdm_context)
    2657            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2658              :             m_libspdm_use_measurement_hash_algo;
    2659            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2660            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2661            1 :         opaque_psk_exchange_rsp_size =
    2662            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2663              :                 spdm_context);
    2664            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    2665              :                              0 +
    2666            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    2667            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2668            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2669              : 
    2670            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2671            1 :         spdm_response->header.request_response_code =
    2672              :             SPDM_PSK_EXCHANGE_RSP;
    2673            1 :         spdm_response->header.param1 = 0;
    2674            1 :         spdm_response->header.param2 = 0;
    2675            1 :         spdm_response->rsp_session_id =
    2676            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    2677            1 :         spdm_response->reserved = 0;
    2678            1 :         spdm_response->context_length = 0;
    2679            1 :         spdm_response->opaque_length =
    2680            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    2681            1 :         ptr = (void *)(spdm_response + 1);
    2682              :         /* libspdm_zero_mem (ptr, hash_size);
    2683              :          * ptr += hash_size;*/
    2684              :         /* libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    2685              :          * ptr += LIBSPDM_PSK_CONTEXT_LENGTH;*/
    2686            1 :         libspdm_build_opaque_data_version_selection_data(
    2687              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    2688            1 :         ptr += opaque_psk_exchange_rsp_size;
    2689            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2690              :                          sizeof(m_libspdm_local_buffer)
    2691            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2692              :                             m_libspdm_local_buffer),
    2693            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2694            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2695            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2696              :                        m_libspdm_local_buffer_size));
    2697            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2698            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2699            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2700              :                                                         m_libspdm_use_asym_algo, &data,
    2701              :                                                         &data_size, NULL, NULL);
    2702            1 :         cert_buffer =
    2703            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    2704            1 :         cert_buffer_size =
    2705            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    2706            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2707              :                          cert_buffer_hash);
    2708              :         /* transcript.message_a size is 0*/
    2709            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2710              :                                       m_libspdm_local_buffer_size);
    2711            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2712              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2713            1 :         free(data);
    2714            1 :         bin_str2_size = sizeof(bin_str2);
    2715            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2716              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
    2717            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    2718              :                            bin_str2, &bin_str2_size);
    2719            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    2720            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2721              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    2722              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    2723              :                 bin_str2_size,
    2724              :                 response_handshake_secret, hash_size);
    2725            1 :         bin_str7_size = sizeof(bin_str7);
    2726            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2727              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
    2728            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2729              :                            &bin_str7_size);
    2730            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2731              :                             hash_size, bin_str7, bin_str7_size,
    2732              :                             response_finished_key, hash_size);
    2733            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2734              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2735            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2736              :                          response_finished_key, hash_size, ptr);
    2737            1 :         ptr += hmac_size;
    2738              : 
    2739            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2740              :                                               false, spdm_response_size,
    2741              :                                               spdm_response, response_size,
    2742              :                                               response);
    2743              :     }
    2744            1 :         return LIBSPDM_STATUS_SUCCESS;
    2745              : 
    2746            1 :     case 0x19: {
    2747              :         spdm_psk_exchange_response_t *spdm_response;
    2748              :         uint32_t hash_size;
    2749              :         uint32_t hmac_size;
    2750              :         uint8_t *ptr;
    2751              :         size_t opaque_psk_exchange_rsp_size;
    2752              :         void *data;
    2753              :         size_t data_size;
    2754              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2755              :         uint8_t *cert_buffer;
    2756              :         size_t cert_buffer_size;
    2757              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2758              :         uint8_t bin_str2[128];
    2759              :         size_t bin_str2_size;
    2760              :         uint8_t bin_str7[128];
    2761              :         size_t bin_str7_size;
    2762              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2763              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2764              :         size_t spdm_response_size;
    2765              :         size_t transport_header_size;
    2766              : 
    2767            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    2768              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2769              :         ((libspdm_context_t *)spdm_context)
    2770            1 :         ->connection_info.algorithm.base_asym_algo =
    2771              :             m_libspdm_use_asym_algo;
    2772              :         ((libspdm_context_t *)spdm_context)
    2773            1 :         ->connection_info.algorithm.base_hash_algo =
    2774              :             m_libspdm_use_hash_algo;
    2775              :         ((libspdm_context_t *)spdm_context)
    2776            1 :         ->connection_info.algorithm.dhe_named_group =
    2777              :             m_libspdm_use_dhe_algo;
    2778              :         ((libspdm_context_t *)spdm_context)
    2779            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2780              :             m_libspdm_use_measurement_hash_algo;
    2781            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2782            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2783            1 :         opaque_psk_exchange_rsp_size = 0;
    2784            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    2785              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    2786            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    2787            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2788            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2789              : 
    2790            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2791            1 :         spdm_response->header.request_response_code =
    2792              :             SPDM_PSK_EXCHANGE_RSP;
    2793            1 :         spdm_response->header.param1 = 0;
    2794            1 :         spdm_response->header.param2 = 0;
    2795            1 :         spdm_response->rsp_session_id =
    2796            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    2797            1 :         spdm_response->reserved = 0;
    2798            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    2799            1 :         spdm_response->opaque_length =
    2800            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    2801            1 :         ptr = (void *)(spdm_response + 1);
    2802              :         /* libspdm_zero_mem (ptr, hash_size);
    2803              :          * ptr += hash_size;*/
    2804            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    2805            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    2806              :         /* libspdm_build_opaque_data_version_selection_data(
    2807              :          *    spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    2808              :          * ptr += opaque_psk_exchange_rsp_size;*/
    2809            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2810              :                          sizeof(m_libspdm_local_buffer)
    2811            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2812              :                             m_libspdm_local_buffer),
    2813            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2814            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2815            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2816              :                        m_libspdm_local_buffer_size));
    2817            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2818            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2819            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2820              :                                                         m_libspdm_use_asym_algo, &data,
    2821              :                                                         &data_size, NULL, NULL);
    2822            1 :         cert_buffer =
    2823            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    2824            1 :         cert_buffer_size =
    2825            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    2826            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2827              :                          cert_buffer_hash);
    2828              :         /* transcript.message_a size is 0*/
    2829            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2830              :                                       m_libspdm_local_buffer_size);
    2831            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2832              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2833            1 :         free(data);
    2834            1 :         bin_str2_size = sizeof(bin_str2);
    2835            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2836              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
    2837            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    2838              :                            bin_str2, &bin_str2_size);
    2839            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    2840            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2841              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    2842              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    2843              :                 bin_str2_size,
    2844              :                 response_handshake_secret, hash_size);
    2845            1 :         bin_str7_size = sizeof(bin_str7);
    2846            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2847              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
    2848            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2849              :                            &bin_str7_size);
    2850            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2851              :                             hash_size, bin_str7, bin_str7_size,
    2852              :                             response_finished_key, hash_size);
    2853            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2854              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2855            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2856              :                          response_finished_key, hash_size, ptr);
    2857            1 :         ptr += hmac_size;
    2858              : 
    2859            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2860              :                                               false, spdm_response_size,
    2861              :                                               spdm_response, response_size,
    2862              :                                               response);
    2863              :     }
    2864            1 :         return LIBSPDM_STATUS_SUCCESS;
    2865              : 
    2866            1 :     case 0x1A: {
    2867              :         spdm_psk_exchange_response_t *spdm_response;
    2868              :         uint32_t hash_size;
    2869              :         uint32_t hmac_size;
    2870              :         uint8_t *ptr;
    2871              :         size_t opaque_psk_exchange_rsp_size;
    2872              :         void *data;
    2873              :         size_t data_size;
    2874              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2875              :         uint8_t *cert_buffer;
    2876              :         size_t cert_buffer_size;
    2877              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2878              :         uint8_t bin_str2[128];
    2879              :         size_t bin_str2_size;
    2880              :         uint8_t bin_str7[128];
    2881              :         size_t bin_str7_size;
    2882              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2883              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2884              :         size_t spdm_response_size;
    2885              :         size_t transport_header_size;
    2886              : 
    2887            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    2888              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2889              :         ((libspdm_context_t *)spdm_context)
    2890            1 :         ->connection_info.algorithm.base_asym_algo =
    2891              :             m_libspdm_use_asym_algo;
    2892              :         ((libspdm_context_t *)spdm_context)
    2893            1 :         ->connection_info.algorithm.base_hash_algo =
    2894              :             m_libspdm_use_hash_algo;
    2895              :         ((libspdm_context_t *)spdm_context)
    2896            1 :         ->connection_info.algorithm.dhe_named_group =
    2897              :             m_libspdm_use_dhe_algo;
    2898              :         ((libspdm_context_t *)spdm_context)
    2899            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2900              :             m_libspdm_use_measurement_hash_algo;
    2901            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2902            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2903            1 :         opaque_psk_exchange_rsp_size = 0;
    2904            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    2905              :                              0 +
    2906            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    2907            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2908            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2909              : 
    2910            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2911            1 :         spdm_response->header.request_response_code =
    2912              :             SPDM_PSK_EXCHANGE_RSP;
    2913            1 :         spdm_response->header.param1 = 0;
    2914            1 :         spdm_response->header.param2 = 0;
    2915            1 :         spdm_response->rsp_session_id =
    2916            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    2917            1 :         spdm_response->reserved = 0;
    2918            1 :         spdm_response->context_length = 0;
    2919            1 :         spdm_response->opaque_length =
    2920            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    2921            1 :         ptr = (void *)(spdm_response + 1);
    2922              :         /* libspdm_zero_mem (ptr, hash_size);
    2923              :          * ptr += hash_size;*/
    2924              :         /*libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    2925              :          * ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    2926              :          * libspdm_build_opaque_data_version_selection_data(
    2927              :          *  spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    2928              :          * ptr += opaque_psk_exchange_rsp_size;*/
    2929            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2930              :                          sizeof(m_libspdm_local_buffer)
    2931            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2932              :                             m_libspdm_local_buffer),
    2933            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2934            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2935            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2936              :                        m_libspdm_local_buffer_size));
    2937            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2938            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2939            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2940              :                                                         m_libspdm_use_asym_algo, &data,
    2941              :                                                         &data_size, NULL, NULL);
    2942            1 :         cert_buffer =
    2943            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    2944            1 :         cert_buffer_size =
    2945            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    2946            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2947              :                          cert_buffer_hash);
    2948              :         /* transcript.message_a size is 0*/
    2949            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2950              :                                       m_libspdm_local_buffer_size);
    2951            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2952              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2953            1 :         free(data);
    2954            1 :         bin_str2_size = sizeof(bin_str2);
    2955            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2956              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
    2957            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    2958              :                            bin_str2, &bin_str2_size);
    2959            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    2960            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2961              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    2962              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    2963              :                 bin_str2_size,
    2964              :                 response_handshake_secret, hash_size);
    2965            1 :         bin_str7_size = sizeof(bin_str7);
    2966            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2967              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
    2968            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2969              :                            &bin_str7_size);
    2970            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2971              :                             hash_size, bin_str7, bin_str7_size,
    2972              :                             response_finished_key, hash_size);
    2973            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2974              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2975            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2976              :                          response_finished_key, hash_size, ptr);
    2977            1 :         ptr += hmac_size;
    2978              : 
    2979            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2980              :                                               false, spdm_response_size,
    2981              :                                               spdm_response, response_size,
    2982              :                                               response);
    2983              :     }
    2984            1 :         return LIBSPDM_STATUS_SUCCESS;
    2985            1 :     case 0x1B: {
    2986              :         spdm_psk_exchange_response_t *spdm_response;
    2987              :         uint32_t hash_size;
    2988              :         uint32_t hmac_size;
    2989              :         uint8_t *ptr;
    2990              :         size_t opaque_psk_exchange_rsp_size;
    2991              :         void *data;
    2992              :         size_t data_size;
    2993              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2994              :         uint8_t *cert_buffer;
    2995              :         size_t cert_buffer_size;
    2996              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2997              :         uint8_t bin_str2[128];
    2998              :         size_t bin_str2_size;
    2999              :         uint8_t bin_str7[128];
    3000              :         size_t bin_str7_size;
    3001              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3002              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    3003              :         size_t spdm_response_size;
    3004              :         size_t transport_header_size;
    3005              : 
    3006            1 :         ((libspdm_context_t *)spdm_context)->connection_info.secured_message_version =
    3007              :             SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    3008              :         ((libspdm_context_t *)spdm_context)
    3009            1 :         ->connection_info.algorithm.base_asym_algo =
    3010              :             m_libspdm_use_asym_algo;
    3011              :         ((libspdm_context_t *)spdm_context)
    3012            1 :         ->connection_info.algorithm.base_hash_algo =
    3013              :             m_libspdm_use_hash_algo;
    3014              :         ((libspdm_context_t *)spdm_context)
    3015            1 :         ->connection_info.algorithm.dhe_named_group =
    3016              :             m_libspdm_use_dhe_algo;
    3017              :         ((libspdm_context_t *)spdm_context)
    3018            1 :         ->connection_info.algorithm.measurement_hash_algo =
    3019              :             m_libspdm_use_measurement_hash_algo;
    3020            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3021            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3022            1 :         opaque_psk_exchange_rsp_size =
    3023            1 :             libspdm_get_opaque_data_version_selection_data_size(
    3024              :                 spdm_context);
    3025            1 :         spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
    3026              :                              LIBSPDM_PSK_CONTEXT_LENGTH +
    3027            1 :                              opaque_psk_exchange_rsp_size + hmac_size;
    3028            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    3029            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    3030              : 
    3031            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    3032            1 :         spdm_response->header.request_response_code =
    3033              :             SPDM_PSK_EXCHANGE_RSP;
    3034            1 :         spdm_response->header.param1 = 0;
    3035            1 :         spdm_response->header.param2 = 0;
    3036            1 :         spdm_response->rsp_session_id =
    3037            1 :             libspdm_allocate_rsp_session_id(spdm_context, true);
    3038            1 :         spdm_response->reserved = 0;
    3039            1 :         spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
    3040            1 :         spdm_response->opaque_length =
    3041            1 :             (uint16_t)opaque_psk_exchange_rsp_size;
    3042            1 :         ptr = (void *)(spdm_response + 1);
    3043              :         /* libspdm_zero_mem (ptr, hash_size);
    3044              :          * ptr += hash_size;*/
    3045            1 :         libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
    3046            1 :         ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
    3047            1 :         libspdm_build_opaque_data_version_selection_data(
    3048              :             spdm_context, &opaque_psk_exchange_rsp_size, ptr);
    3049            1 :         ptr += opaque_psk_exchange_rsp_size;
    3050            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3051              :                          sizeof(m_libspdm_local_buffer)
    3052            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3053              :                             m_libspdm_local_buffer),
    3054            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    3055            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    3056            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    3057              :                        m_libspdm_local_buffer_size));
    3058            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3059            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    3060            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3061              :                                                         m_libspdm_use_asym_algo, &data,
    3062              :                                                         &data_size, NULL, NULL);
    3063            1 :         cert_buffer =
    3064            1 :             (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
    3065            1 :         cert_buffer_size =
    3066            1 :             data_size - (sizeof(spdm_cert_chain_t) + hash_size);
    3067            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    3068              :                          cert_buffer_hash);
    3069              :         /* transcript.message_a size is 0*/
    3070            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    3071              :                                       m_libspdm_local_buffer_size);
    3072            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3073              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3074            1 :         free(data);
    3075            1 :         bin_str2_size = sizeof(bin_str2);
    3076            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3077              :                            LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
    3078            1 :                            hash_data, (uint16_t)hash_size, hash_size,
    3079              :                            bin_str2, &bin_str2_size);
    3080            1 :         libspdm_psk_handshake_secret_hkdf_expand(
    3081            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3082              :                 m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
    3083              :                 sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
    3084              :                 bin_str2_size,
    3085              :                 response_handshake_secret, hash_size);
    3086            1 :         bin_str7_size = sizeof(bin_str7);
    3087            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3088              :                            LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
    3089            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    3090              :                            &bin_str7_size);
    3091            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    3092              :                             hash_size, bin_str7, bin_str7_size,
    3093              :                             response_finished_key, hash_size);
    3094            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3095              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3096            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    3097              :                          response_finished_key, hash_size, ptr);
    3098            1 :         ptr += hmac_size;
    3099              : 
    3100            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3101              :                                               false, spdm_response_size,
    3102              :                                               spdm_response, response_size,
    3103              :                                               response);
    3104              :     }
    3105            1 :         return LIBSPDM_STATUS_SUCCESS;
    3106              : 
    3107            0 :     default:
    3108            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
    3109              :     }
    3110              : }
    3111              : 
    3112            1 : void libspdm_test_requester_psk_exchange_case1(void **state)
    3113              : {
    3114              :     libspdm_return_t status;
    3115              :     libspdm_test_context_t *spdm_test_context;
    3116              :     libspdm_context_t *spdm_context;
    3117              :     uint32_t session_id;
    3118              :     uint8_t heartbeat_period;
    3119              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3120              :     void *data;
    3121              :     size_t data_size;
    3122              :     void *hash;
    3123              :     size_t hash_size;
    3124              : 
    3125            1 :     spdm_test_context = *state;
    3126            1 :     spdm_context = spdm_test_context->spdm_context;
    3127            1 :     spdm_test_context->case_id = 0x1;
    3128            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3129              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3130            1 :     spdm_context->connection_info.connection_state =
    3131              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3132            1 :     spdm_context->connection_info.capability.flags &=
    3133              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3134            1 :     spdm_context->connection_info.capability.flags |=
    3135              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT |
    3136              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    3137            1 :     spdm_context->local_context.capability.flags |=
    3138              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
    3139              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    3140            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3141              :                                                          m_libspdm_use_asym_algo, &data,
    3142              :                                                          &data_size, &hash, &hash_size)) {
    3143            0 :         assert(false);
    3144              :     }
    3145            1 :     libspdm_reset_message_a(spdm_context);
    3146            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3147              :         m_libspdm_use_hash_algo;
    3148            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    3149              :         m_libspdm_use_dhe_algo;
    3150            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    3151              :         m_libspdm_use_aead_algo;
    3152            1 :     spdm_context->connection_info.algorithm.key_schedule =
    3153              :         m_libspdm_use_key_schedule_algo;
    3154              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3155              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3156              :         data_size;
    3157              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3158              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3159              :                      data, data_size);
    3160              : #endif
    3161              : 
    3162            1 :     heartbeat_period = 0;
    3163            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3164            1 :     status = libspdm_send_receive_psk_exchange(
    3165              :         spdm_context, NULL, 0,
    3166              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3167              :         &heartbeat_period, measurement_hash);
    3168            1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
    3169            1 :     free(data);
    3170            1 : }
    3171              : 
    3172            1 : void libspdm_test_requester_psk_exchange_case2(void **state)
    3173              : {
    3174              :     libspdm_return_t status;
    3175              :     libspdm_test_context_t *spdm_test_context;
    3176              :     libspdm_context_t *spdm_context;
    3177              :     uint32_t session_id;
    3178              :     uint8_t heartbeat_period;
    3179              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3180              :     void *data;
    3181              :     size_t data_size;
    3182              :     void *hash;
    3183              :     size_t hash_size;
    3184              : 
    3185            1 :     spdm_test_context = *state;
    3186            1 :     spdm_context = spdm_test_context->spdm_context;
    3187            1 :     spdm_test_context->case_id = 0x2;
    3188            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3189              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3190            1 :     spdm_context->connection_info.connection_state =
    3191              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3192            1 :     spdm_context->connection_info.capability.flags &=
    3193              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3194            1 :     spdm_context->connection_info.capability.flags |=
    3195              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3196            1 :     spdm_context->local_context.capability.flags |=
    3197              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3198            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    3199            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    3200              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    3201            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3202              :                                                          m_libspdm_use_asym_algo, &data,
    3203              :                                                          &data_size, &hash, &hash_size)) {
    3204            0 :         assert(false);
    3205              :     }
    3206            1 :     libspdm_reset_message_a(spdm_context);
    3207            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3208              :         m_libspdm_use_hash_algo;
    3209            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    3210              :         m_libspdm_use_dhe_algo;
    3211            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    3212              :         m_libspdm_use_aead_algo;
    3213            1 :     spdm_context->connection_info.algorithm.key_schedule =
    3214              :         m_libspdm_use_key_schedule_algo;
    3215              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3216              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3217              :         data_size;
    3218              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3219              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3220              :                      data, data_size);
    3221              : #endif
    3222              : 
    3223            1 :     heartbeat_period = 0;
    3224            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3225            1 :     status = libspdm_send_receive_psk_exchange(
    3226              :         spdm_context,
    3227              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3228              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3229              :         &heartbeat_period, measurement_hash);
    3230            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3231            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    3232            1 :     assert_int_equal(
    3233              :         libspdm_secured_message_get_session_state(
    3234              :             spdm_context->session_info[0].secured_message_context),
    3235              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    3236            1 :     free(data);
    3237            1 : }
    3238              : 
    3239            1 : void libspdm_test_requester_psk_exchange_case3(void **state)
    3240              : {
    3241              :     libspdm_return_t status;
    3242              :     libspdm_test_context_t *spdm_test_context;
    3243              :     libspdm_context_t *spdm_context;
    3244              :     uint32_t session_id;
    3245              :     uint8_t heartbeat_period;
    3246              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3247              :     void *data;
    3248              :     size_t data_size;
    3249              :     void *hash;
    3250              :     size_t hash_size;
    3251              : 
    3252            1 :     spdm_test_context = *state;
    3253            1 :     spdm_context = spdm_test_context->spdm_context;
    3254            1 :     spdm_test_context->case_id = 0x3;
    3255            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3256              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3257            1 :     spdm_context->connection_info.connection_state =
    3258              :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
    3259            1 :     spdm_context->connection_info.capability.flags &=
    3260              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3261            1 :     spdm_context->connection_info.capability.flags |=
    3262              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3263            1 :     spdm_context->local_context.capability.flags |=
    3264              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3265            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3266              :                                                          m_libspdm_use_asym_algo, &data,
    3267              :                                                          &data_size, &hash, &hash_size)) {
    3268            0 :         assert(false);
    3269              :     }
    3270            1 :     libspdm_reset_message_a(spdm_context);
    3271            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3272              :         m_libspdm_use_hash_algo;
    3273            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    3274              :         m_libspdm_use_dhe_algo;
    3275            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    3276              :         m_libspdm_use_aead_algo;
    3277            1 :     spdm_context->connection_info.algorithm.key_schedule =
    3278              :         m_libspdm_use_key_schedule_algo;
    3279              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3280              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3281              :         data_size;
    3282              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3283              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3284              :                      data, data_size);
    3285              : #endif
    3286              : 
    3287            1 :     heartbeat_period = 0;
    3288            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3289            1 :     status = libspdm_send_receive_psk_exchange(
    3290              :         spdm_context,
    3291              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3292              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3293              :         &heartbeat_period, measurement_hash);
    3294            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
    3295            1 :     free(data);
    3296            1 : }
    3297              : 
    3298            1 : void libspdm_test_requester_psk_exchange_case4(void **state)
    3299              : {
    3300              :     libspdm_return_t status;
    3301              :     libspdm_test_context_t *spdm_test_context;
    3302              :     libspdm_context_t *spdm_context;
    3303              :     uint32_t session_id;
    3304              :     uint8_t heartbeat_period;
    3305              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3306              :     void *data;
    3307              :     size_t data_size;
    3308              :     void *hash;
    3309              :     size_t hash_size;
    3310              : 
    3311            1 :     spdm_test_context = *state;
    3312            1 :     spdm_context = spdm_test_context->spdm_context;
    3313            1 :     spdm_test_context->case_id = 0x4;
    3314            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3315              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3316            1 :     spdm_context->connection_info.connection_state =
    3317              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3318            1 :     spdm_context->connection_info.capability.flags &=
    3319              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3320            1 :     spdm_context->connection_info.capability.flags |=
    3321              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3322            1 :     spdm_context->local_context.capability.flags |=
    3323              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3324            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3325              :                                                          m_libspdm_use_asym_algo, &data,
    3326              :                                                          &data_size, &hash, &hash_size)) {
    3327            0 :         assert(false);
    3328              :     }
    3329            1 :     libspdm_reset_message_a(spdm_context);
    3330            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3331              :         m_libspdm_use_hash_algo;
    3332            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    3333              :         m_libspdm_use_dhe_algo;
    3334            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    3335              :         m_libspdm_use_aead_algo;
    3336            1 :     spdm_context->connection_info.algorithm.key_schedule =
    3337              :         m_libspdm_use_key_schedule_algo;
    3338              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3339              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3340              :         data_size;
    3341              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3342              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3343              :                      data, data_size);
    3344              : #endif
    3345              : 
    3346            1 :     heartbeat_period = 0;
    3347            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3348            1 :     status = libspdm_send_receive_psk_exchange(
    3349              :         spdm_context,
    3350              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3351              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3352              :         &heartbeat_period, measurement_hash);
    3353            1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
    3354            1 :     free(data);
    3355            1 : }
    3356              : 
    3357            1 : void libspdm_test_requester_psk_exchange_case5(void **state)
    3358              : {
    3359              :     libspdm_return_t status;
    3360              :     libspdm_test_context_t *spdm_test_context;
    3361              :     libspdm_context_t *spdm_context;
    3362              :     uint32_t session_id;
    3363              :     uint8_t heartbeat_period;
    3364              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3365              :     void *data;
    3366              :     size_t data_size;
    3367              :     void *hash;
    3368              :     size_t hash_size;
    3369              : 
    3370            1 :     spdm_test_context = *state;
    3371            1 :     spdm_context = spdm_test_context->spdm_context;
    3372            1 :     spdm_test_context->case_id = 0x5;
    3373            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3374              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3375            1 :     spdm_context->connection_info.connection_state =
    3376              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3377            1 :     spdm_context->connection_info.capability.flags &=
    3378              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3379            1 :     spdm_context->connection_info.capability.flags |=
    3380              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3381            1 :     spdm_context->local_context.capability.flags |=
    3382              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3383            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3384              :                                                          m_libspdm_use_asym_algo, &data,
    3385              :                                                          &data_size, &hash, &hash_size)) {
    3386            0 :         assert(false);
    3387              :     }
    3388            1 :     libspdm_reset_message_a(spdm_context);
    3389            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3390              :         m_libspdm_use_hash_algo;
    3391            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3392              :         m_libspdm_use_asym_algo;
    3393            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    3394              :         m_libspdm_use_dhe_algo;
    3395            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    3396              :         m_libspdm_use_aead_algo;
    3397              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3398              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3399              :         data_size;
    3400              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3401              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3402              :                      data, data_size);
    3403              : #endif
    3404              : 
    3405            1 :     heartbeat_period = 0;
    3406            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3407            1 :     status = libspdm_send_receive_psk_exchange(
    3408              :         spdm_context,
    3409              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3410              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3411              :         &heartbeat_period, measurement_hash);
    3412            1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
    3413            1 :     free(data);
    3414            1 : }
    3415              : 
    3416            1 : void libspdm_test_requester_psk_exchange_case6(void **state)
    3417              : {
    3418              :     libspdm_return_t status;
    3419              :     libspdm_test_context_t *spdm_test_context;
    3420              :     libspdm_context_t *spdm_context;
    3421              :     uint32_t session_id;
    3422              :     uint8_t heartbeat_period;
    3423              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3424              :     void *data;
    3425              :     size_t data_size;
    3426              :     void *hash;
    3427              :     size_t hash_size;
    3428              : 
    3429            1 :     spdm_test_context = *state;
    3430            1 :     spdm_context = spdm_test_context->spdm_context;
    3431            1 :     spdm_test_context->case_id = 0x6;
    3432            1 :     spdm_context->retry_times = 3;
    3433            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3434              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3435            1 :     spdm_context->connection_info.connection_state =
    3436              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3437            1 :     spdm_context->connection_info.capability.flags &=
    3438              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3439            1 :     spdm_context->connection_info.capability.flags |=
    3440              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3441            1 :     spdm_context->local_context.capability.flags |=
    3442              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3443            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3444              :                                                          m_libspdm_use_asym_algo, &data,
    3445              :                                                          &data_size, &hash, &hash_size)) {
    3446            0 :         assert(false);
    3447              :     }
    3448            1 :     libspdm_reset_message_a(spdm_context);
    3449            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3450              :         m_libspdm_use_hash_algo;
    3451            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    3452              :         m_libspdm_use_dhe_algo;
    3453            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    3454              :         m_libspdm_use_aead_algo;
    3455            1 :     spdm_context->connection_info.algorithm.key_schedule =
    3456              :         m_libspdm_use_key_schedule_algo;
    3457              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3458              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3459              :         data_size;
    3460              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3461              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3462              :                      data, data_size);
    3463              : #endif
    3464              : 
    3465            1 :     heartbeat_period = 0;
    3466            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3467            1 :     status = libspdm_send_receive_psk_exchange(
    3468              :         spdm_context,
    3469              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3470              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3471              :         &heartbeat_period, measurement_hash);
    3472            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3473            1 :     assert_int_equal(session_id, 0xFFFEFFFE);
    3474            1 :     assert_int_equal(
    3475              :         libspdm_secured_message_get_session_state(
    3476              :             spdm_context->session_info[0].secured_message_context),
    3477              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    3478            1 :     free(data);
    3479            1 : }
    3480              : 
    3481            1 : void libspdm_test_requester_psk_exchange_case7(void **state)
    3482              : {
    3483              :     libspdm_return_t status;
    3484              :     libspdm_test_context_t *spdm_test_context;
    3485              :     libspdm_context_t *spdm_context;
    3486              :     uint32_t session_id;
    3487              :     uint8_t heartbeat_period;
    3488              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3489              :     void *data;
    3490              :     size_t data_size;
    3491              :     void *hash;
    3492              :     size_t hash_size;
    3493              : 
    3494            1 :     spdm_test_context = *state;
    3495            1 :     spdm_context = spdm_test_context->spdm_context;
    3496            1 :     spdm_test_context->case_id = 0x7;
    3497            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3498              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3499            1 :     spdm_context->connection_info.connection_state =
    3500              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3501            1 :     spdm_context->connection_info.capability.flags &=
    3502              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3503            1 :     spdm_context->connection_info.capability.flags |=
    3504              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3505            1 :     spdm_context->local_context.capability.flags |=
    3506              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3507            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3508              :                                                          m_libspdm_use_asym_algo, &data,
    3509              :                                                          &data_size, &hash, &hash_size)) {
    3510            0 :         assert(false);
    3511              :     }
    3512            1 :     libspdm_reset_message_a(spdm_context);
    3513            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3514              :         m_libspdm_use_hash_algo;
    3515            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    3516              :         m_libspdm_use_dhe_algo;
    3517            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    3518              :         m_libspdm_use_aead_algo;
    3519            1 :     spdm_context->connection_info.algorithm.key_schedule =
    3520              :         m_libspdm_use_key_schedule_algo;
    3521              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3522              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3523              :         data_size;
    3524              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3525              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3526              :                      data, data_size);
    3527              : #endif
    3528              : 
    3529            1 :     heartbeat_period = 0;
    3530            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3531            1 :     status = libspdm_send_receive_psk_exchange(
    3532              :         spdm_context,
    3533              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3534              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3535              :         &heartbeat_period, measurement_hash);
    3536            1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
    3537            1 :     assert_int_equal(spdm_context->connection_info.connection_state,
    3538              :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
    3539            1 :     free(data);
    3540            1 : }
    3541              : 
    3542            1 : void libspdm_test_requester_psk_exchange_case8(void **state)
    3543              : {
    3544              :     libspdm_return_t status;
    3545              :     libspdm_test_context_t *spdm_test_context;
    3546              :     libspdm_context_t *spdm_context;
    3547              :     uint32_t session_id;
    3548              :     uint8_t heartbeat_period;
    3549              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3550              :     void *data;
    3551              :     size_t data_size;
    3552              :     void *hash;
    3553              :     size_t hash_size;
    3554              : 
    3555            1 :     spdm_test_context = *state;
    3556            1 :     spdm_context = spdm_test_context->spdm_context;
    3557            1 :     spdm_test_context->case_id = 0x8;
    3558            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3559              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3560            1 :     spdm_context->connection_info.connection_state =
    3561              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3562            1 :     spdm_context->connection_info.capability.flags &=
    3563              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3564            1 :     spdm_context->connection_info.capability.flags |=
    3565              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3566            1 :     spdm_context->local_context.capability.flags |=
    3567              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3568            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3569              :                                                          m_libspdm_use_asym_algo, &data,
    3570              :                                                          &data_size, &hash, &hash_size)) {
    3571            0 :         assert(false);
    3572              :     }
    3573            1 :     libspdm_reset_message_a(spdm_context);
    3574            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3575              :         m_libspdm_use_hash_algo;
    3576            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    3577              :         m_libspdm_use_dhe_algo;
    3578            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    3579              :         m_libspdm_use_aead_algo;
    3580            1 :     spdm_context->connection_info.algorithm.key_schedule =
    3581              :         m_libspdm_use_key_schedule_algo;
    3582              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3583              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3584              :         data_size;
    3585              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3586              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3587              :                      data, data_size);
    3588              : #endif
    3589              : 
    3590            1 :     heartbeat_period = 0;
    3591            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3592            1 :     status = libspdm_send_receive_psk_exchange(
    3593              :         spdm_context,
    3594              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3595              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3596              :         &heartbeat_period, measurement_hash);
    3597            1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
    3598            1 :     free(data);
    3599            1 : }
    3600              : 
    3601            1 : void libspdm_test_requester_psk_exchange_case9(void **state)
    3602              : {
    3603              :     libspdm_return_t status;
    3604              :     libspdm_test_context_t *spdm_test_context;
    3605              :     libspdm_context_t *spdm_context;
    3606              :     uint32_t session_id;
    3607              :     uint8_t heartbeat_period;
    3608              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3609              :     void *data;
    3610              :     size_t data_size;
    3611              :     void *hash;
    3612              :     size_t hash_size;
    3613              : 
    3614            1 :     spdm_test_context = *state;
    3615            1 :     spdm_context = spdm_test_context->spdm_context;
    3616            1 :     spdm_test_context->case_id = 0x9;
    3617            1 :     spdm_context->retry_times = 3;
    3618            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3619              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3620            1 :     spdm_context->connection_info.connection_state =
    3621              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3622            1 :     spdm_context->connection_info.capability.flags &=
    3623              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3624            1 :     spdm_context->connection_info.capability.flags |=
    3625              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3626            1 :     spdm_context->local_context.capability.flags |=
    3627              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3628            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3629              :                                                          m_libspdm_use_asym_algo, &data,
    3630              :                                                          &data_size, &hash, &hash_size)) {
    3631            0 :         assert(false);
    3632              :     }
    3633            1 :     libspdm_reset_message_a(spdm_context);
    3634            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3635              :         m_libspdm_use_hash_algo;
    3636            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    3637              :         m_libspdm_use_dhe_algo;
    3638            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    3639              :         m_libspdm_use_aead_algo;
    3640            1 :     spdm_context->connection_info.algorithm.key_schedule =
    3641              :         m_libspdm_use_key_schedule_algo;
    3642              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3643              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3644              :         data_size;
    3645              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3646              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3647              :                      data, data_size);
    3648              : #endif
    3649              : 
    3650            1 :     heartbeat_period = 0;
    3651            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3652            1 :     status = libspdm_send_receive_psk_exchange(
    3653              :         spdm_context,
    3654              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3655              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3656              :         &heartbeat_period, measurement_hash);
    3657              :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
    3658            1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3659            1 :         assert_int_equal(session_id, 0xFFFDFFFD);
    3660            1 :         assert_int_equal(
    3661              :             libspdm_secured_message_get_session_state(
    3662              :                 spdm_context->session_info[0].secured_message_context),
    3663              :             LIBSPDM_SESSION_STATE_HANDSHAKING);
    3664              :     } else {
    3665              :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
    3666              :     }
    3667              : 
    3668            1 :     free(data);
    3669            1 : }
    3670              : 
    3671            1 : void libspdm_test_requester_psk_exchange_case10(void **state) {
    3672              :     libspdm_return_t status;
    3673              :     libspdm_test_context_t    *spdm_test_context;
    3674              :     libspdm_context_t  *spdm_context;
    3675              :     uint32_t session_id;
    3676              :     uint8_t heartbeat_period;
    3677              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3678              :     void                 *data;
    3679              :     size_t data_size;
    3680              :     void                 *hash;
    3681              :     size_t hash_size;
    3682              :     uint16_t error_code;
    3683              : 
    3684            1 :     spdm_test_context = *state;
    3685            1 :     spdm_context = spdm_test_context->spdm_context;
    3686            1 :     spdm_test_context->case_id = 0xA;
    3687            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3688              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3689            1 :     spdm_context->connection_info.capability.flags |=
    3690              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3691            1 :     spdm_context->local_context.capability.flags |=
    3692              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3693            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    3694              :                                                      m_libspdm_use_asym_algo,
    3695              :                                                      &data, &data_size,
    3696              :                                                      &hash, &hash_size);
    3697            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3698            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    3699            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    3700            1 :     spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
    3701              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3702              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3703              :         data_size;
    3704              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3705              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3706              :                      data, data_size);
    3707              : #endif
    3708              : 
    3709            1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
    3710           19 :     while(error_code <= 0xff) {
    3711           18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3712           18 :         libspdm_reset_message_a(spdm_context);
    3713              : 
    3714           18 :         heartbeat_period = 0;
    3715           18 :         libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3716           18 :         status = libspdm_send_receive_psk_exchange (spdm_context,
    3717              :                                                     LIBSPDM_TEST_PSK_HINT_STRING,
    3718              :                                                     sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3719              :                                                     SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3720              :                                                     0,
    3721              :                                                     &session_id, &heartbeat_period,
    3722              :                                                     measurement_hash);
    3723           18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
    3724              : 
    3725           18 :         error_code++;
    3726           18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
    3727            1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
    3728              :         }
    3729           18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
    3730            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
    3731              :         }
    3732           18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
    3733            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
    3734              :         }
    3735              :     }
    3736              : 
    3737            1 :     free(data);
    3738            1 : }
    3739              : 
    3740            0 : void libspdm_test_requester_psk_exchange_case11(void **state)
    3741              : {
    3742              :     libspdm_return_t status;
    3743              :     libspdm_test_context_t *spdm_test_context;
    3744              :     libspdm_context_t *spdm_context;
    3745              :     uint32_t session_id;
    3746              :     uint8_t heartbeat_period;
    3747              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3748              :     void *data;
    3749              :     size_t data_size;
    3750              :     void *hash;
    3751              :     size_t hash_size;
    3752              : 
    3753            0 :     spdm_test_context = *state;
    3754            0 :     spdm_context = spdm_test_context->spdm_context;
    3755            0 :     spdm_test_context->case_id = 0xB;
    3756            0 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3757              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3758            0 :     spdm_context->connection_info.connection_state =
    3759              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3760            0 :     spdm_context->connection_info.capability.flags &=
    3761              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3762            0 :     spdm_context->connection_info.capability.flags |=
    3763              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3764            0 :     spdm_context->local_context.capability.flags |=
    3765              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3766            0 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3767              :                                                          m_libspdm_use_asym_algo, &data,
    3768              :                                                          &data_size, &hash, &hash_size)) {
    3769            0 :         assert(false);
    3770              :     }
    3771            0 :     libspdm_reset_message_a(spdm_context);
    3772            0 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3773              :         m_libspdm_use_hash_algo;
    3774            0 :     spdm_context->connection_info.algorithm.dhe_named_group =
    3775              :         m_libspdm_use_dhe_algo;
    3776            0 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    3777              :         m_libspdm_use_aead_algo;
    3778            0 :     spdm_context->connection_info.algorithm.key_schedule =
    3779              :         m_libspdm_use_key_schedule_algo;
    3780              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3781              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3782              :         data_size;
    3783              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3784              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3785              :                      data, data_size);
    3786              : #endif
    3787              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3788              :     spdm_context->transcript.message_m.buffer_size =
    3789              :         spdm_context->transcript.message_m.max_buffer_size;
    3790              :     spdm_context->transcript.message_b.buffer_size =
    3791              :         spdm_context->transcript.message_b.max_buffer_size;
    3792              :     spdm_context->transcript.message_c.buffer_size =
    3793              :         spdm_context->transcript.message_c.max_buffer_size;
    3794              :     spdm_context->transcript.message_mut_b.buffer_size =
    3795              :         spdm_context->transcript.message_mut_b.max_buffer_size;
    3796              :     spdm_context->transcript.message_mut_c.buffer_size =
    3797              :         spdm_context->transcript.message_mut_c.max_buffer_size;
    3798              : #endif
    3799              : 
    3800            0 :     heartbeat_period = 0;
    3801            0 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3802            0 :     status = libspdm_send_receive_psk_exchange(
    3803              :         spdm_context,
    3804              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3805              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3806              :         &heartbeat_period, measurement_hash);
    3807            0 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3808            0 :     assert_int_equal(session_id, 0xFFFFFFFF);
    3809            0 :     assert_int_equal(
    3810              :         libspdm_secured_message_get_session_state(
    3811              :             spdm_context->session_info[0].secured_message_context),
    3812              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    3813              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3814              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    3815              :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
    3816              :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
    3817              :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
    3818              :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
    3819              : #endif
    3820              : 
    3821            0 :     free(data);
    3822            0 : }
    3823              : 
    3824            1 : void libspdm_test_requester_psk_exchange_case12(void **state)
    3825              : {
    3826              :     libspdm_return_t status;
    3827              :     libspdm_test_context_t *spdm_test_context;
    3828              :     libspdm_context_t *spdm_context;
    3829              :     uint32_t session_id;
    3830              :     uint8_t heartbeat_period;
    3831              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3832              :     void *data;
    3833              :     size_t data_size;
    3834              :     void *hash;
    3835              :     size_t hash_size;
    3836              : 
    3837            1 :     spdm_test_context = *state;
    3838            1 :     spdm_context = spdm_test_context->spdm_context;
    3839              : 
    3840            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    3841            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    3842              :     }
    3843              : 
    3844            1 :     spdm_test_context->case_id = 0xC;
    3845            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3846              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3847            1 :     spdm_context->connection_info.connection_state =
    3848              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3849            1 :     spdm_context->connection_info.capability.flags &=
    3850              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3851            1 :     spdm_context->connection_info.capability.flags |=
    3852              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3853            1 :     spdm_context->local_context.capability.flags |=
    3854              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3855            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3856              :                                                          m_libspdm_use_asym_algo, &data,
    3857              :                                                          &data_size, &hash, &hash_size)) {
    3858            0 :         assert(false);
    3859              :     }
    3860            1 :     libspdm_reset_message_a(spdm_context);
    3861            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3862            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    3863            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    3864            1 :     spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
    3865              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3866              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3867              :         data_size;
    3868              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3869              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3870              :                      data, data_size);
    3871              : #endif
    3872              : 
    3873            1 :     heartbeat_period = 0;
    3874            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3875            1 :     status = libspdm_send_receive_psk_exchange(
    3876              :         spdm_context,
    3877              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3878              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    3879              :         &heartbeat_period, measurement_hash);
    3880            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3881            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    3882            1 :     assert_int_equal(
    3883              :         libspdm_secured_message_get_session_state(
    3884              :             spdm_context->session_info[0].secured_message_context),
    3885              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    3886              : 
    3887              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3888              :     assert_int_equal(spdm_context->session_info[0].session_transcript.message_k.buffer_size,
    3889              :                      m_libspdm_local_buffer_size);
    3890              :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
    3891              :                    m_libspdm_local_buffer_size));
    3892              :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3893              :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer,
    3894              :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3895              : #endif
    3896            1 :     free(data);
    3897            1 : }
    3898              : 
    3899            1 : void libspdm_test_requester_psk_exchange_case13(void **state)
    3900              : {
    3901              :     libspdm_return_t status;
    3902              :     libspdm_test_context_t *spdm_test_context;
    3903              :     libspdm_context_t *spdm_context;
    3904              :     uint32_t session_id;
    3905              :     uint8_t heartbeat_period;
    3906              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3907              :     void *data;
    3908              :     size_t data_size;
    3909              :     void *hash;
    3910              :     size_t hash_size;
    3911              : 
    3912            1 :     spdm_test_context = *state;
    3913            1 :     spdm_context = spdm_test_context->spdm_context;
    3914            1 :     spdm_test_context->case_id = 0xD;
    3915            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    3916              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3917            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3918            1 :     spdm_context->connection_info.capability.flags &=
    3919              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3920            1 :     spdm_context->connection_info.capability.flags |=
    3921              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3922            1 :     spdm_context->local_context.capability.flags |=
    3923              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    3924            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    3925            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    3926              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    3927            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3928              :                                                          m_libspdm_use_asym_algo, &data,
    3929              :                                                          &data_size, &hash, &hash_size)) {
    3930            0 :         assert(false);
    3931              :     }
    3932            1 :     libspdm_reset_message_a(spdm_context);
    3933            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3934            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    3935            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    3936            1 :     spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
    3937            1 :     spdm_context->connection_info.algorithm.other_params_support =
    3938              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    3939            1 :     libspdm_session_info_init(spdm_context,
    3940            1 :                               spdm_context->session_info,
    3941              :                               INVALID_SESSION_ID, false);
    3942              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3943              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3944              :         data_size;
    3945              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3946              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3947              :                      data, data_size);
    3948              : #endif
    3949              : 
    3950            1 :     heartbeat_period = 0;
    3951            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3952            1 :     status = libspdm_send_receive_psk_exchange(
    3953              :         spdm_context,
    3954              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    3955              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3956              :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, &session_id,
    3957              :         &heartbeat_period, measurement_hash);
    3958            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3959            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    3960            1 :     assert_int_equal(
    3961              :         libspdm_secured_message_get_session_state(
    3962              :             spdm_context->session_info[0].secured_message_context),
    3963              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    3964            1 :     assert_int_equal(
    3965              :         spdm_context->session_info[0].session_policy,
    3966              :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH);
    3967            1 :     free(data);
    3968            1 : }
    3969              : 
    3970            1 : void libspdm_test_requester_psk_exchange_case14(void **state)
    3971              : {
    3972              :     libspdm_return_t status;
    3973              :     libspdm_test_context_t *spdm_test_context;
    3974              :     libspdm_context_t *spdm_context;
    3975              :     uint32_t session_id;
    3976              :     uint8_t heartbeat_period;
    3977              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3978              :     void *data;
    3979              :     size_t data_size;
    3980              :     void *hash;
    3981              :     size_t hash_size;
    3982              : 
    3983            1 :     spdm_test_context = *state;
    3984            1 :     spdm_context = spdm_test_context->spdm_context;
    3985              : 
    3986            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    3987            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    3988              :     }
    3989              : 
    3990            1 :     spdm_test_context->case_id = 0xE;
    3991            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3992              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3993            1 :     spdm_context->connection_info.connection_state =
    3994              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3995            1 :     spdm_context->connection_info.capability.flags &=
    3996              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    3997            1 :     spdm_context->connection_info.capability.flags |=
    3998              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    3999            1 :     spdm_context->local_context.capability.flags |=
    4000              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4001            1 :     spdm_context->connection_info.capability.flags |=
    4002              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
    4003            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4004              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4005            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4006            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4007              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4008              : 
    4009            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4010              :                                                          m_libspdm_use_asym_algo, &data,
    4011              :                                                          &data_size, &hash, &hash_size)) {
    4012            0 :         assert(false);
    4013              :     }
    4014            1 :     libspdm_reset_message_a(spdm_context);
    4015            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4016              :         m_libspdm_use_hash_algo;
    4017            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4018              :         m_libspdm_use_dhe_algo;
    4019            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4020              :         m_libspdm_use_aead_algo;
    4021            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4022              :         m_libspdm_use_measurement_hash_algo;
    4023            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4024              :         m_libspdm_use_key_schedule_algo;
    4025              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4026              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4027              :         data_size;
    4028              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4029              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4030              :                      data, data_size);
    4031              : 
    4032              : #endif
    4033              : 
    4034            1 :     heartbeat_period = 0;
    4035            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4036            1 :     status = libspdm_send_receive_psk_exchange(
    4037              :         spdm_context,
    4038              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4039              :         SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, &session_id,
    4040              :         &heartbeat_period, measurement_hash);
    4041            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4042            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    4043            1 :     assert_memory_equal(
    4044              :         measurement_hash,
    4045              :         m_libspdm_use_tcb_hash_value,
    4046              :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
    4047            1 :     assert_int_equal(
    4048              :         libspdm_secured_message_get_session_state(
    4049              :             spdm_context->session_info[0].secured_message_context),
    4050              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    4051            1 :     free(data);
    4052            1 : }
    4053              : 
    4054            1 : void libspdm_test_requester_psk_exchange_case15(void **state)
    4055              : {
    4056              :     libspdm_return_t status;
    4057              :     libspdm_test_context_t *spdm_test_context;
    4058              :     libspdm_context_t *spdm_context;
    4059              :     uint32_t session_id;
    4060              :     uint8_t heartbeat_period;
    4061              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4062              :     void *data;
    4063              :     size_t data_size;
    4064              :     void *hash;
    4065              :     size_t hash_size;
    4066              : 
    4067            1 :     spdm_test_context = *state;
    4068            1 :     spdm_context = spdm_test_context->spdm_context;
    4069              : 
    4070            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4071            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4072              :     }
    4073              : 
    4074            1 :     spdm_test_context->case_id = 0xF;
    4075            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4076              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4077            1 :     spdm_context->connection_info.connection_state =
    4078              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4079            1 :     spdm_context->connection_info.capability.flags &=
    4080              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4081            1 :     spdm_context->connection_info.capability.flags |=
    4082              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    4083            1 :     spdm_context->connection_info.capability.flags |=
    4084              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
    4085            1 :     spdm_context->local_context.capability.flags |=
    4086              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4087            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4088              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4089            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4090            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4091              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4092              : 
    4093            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4094              :                                                          m_libspdm_use_asym_algo, &data,
    4095              :                                                          &data_size, &hash, &hash_size)) {
    4096            0 :         assert(false);
    4097              :     }
    4098            1 :     libspdm_reset_message_a(spdm_context);
    4099            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4100              :         m_libspdm_use_hash_algo;
    4101            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4102              :         m_libspdm_use_dhe_algo;
    4103            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4104              :         m_libspdm_use_aead_algo;
    4105            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4106              :         m_libspdm_use_measurement_hash_algo;
    4107            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4108              :         m_libspdm_use_key_schedule_algo;
    4109              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4110              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4111              :         data_size;
    4112              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4113              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4114              :                      data, data_size);
    4115              : 
    4116              : #endif
    4117              : 
    4118            1 :     heartbeat_period = 0;
    4119            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4120            1 :     status = libspdm_send_receive_psk_exchange(
    4121              :         spdm_context,
    4122              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4123              :         SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, &session_id,
    4124              :         &heartbeat_period, measurement_hash);
    4125            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4126            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    4127            1 :     assert_memory_equal(
    4128              :         measurement_hash,
    4129              :         m_libspdm_zero_filled_buffer,
    4130              :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
    4131            1 :     assert_int_equal(
    4132              :         libspdm_secured_message_get_session_state(
    4133              :             spdm_context->session_info[0].secured_message_context),
    4134              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    4135            1 :     free(data);
    4136            1 : }
    4137              : 
    4138            1 : void libspdm_test_requester_psk_exchange_case16(void **state)
    4139              : {
    4140              :     libspdm_return_t status;
    4141              :     libspdm_test_context_t *spdm_test_context;
    4142              :     libspdm_context_t *spdm_context;
    4143              :     uint32_t session_id;
    4144              :     uint8_t heartbeat_period;
    4145              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4146              :     void *data;
    4147              :     size_t data_size;
    4148              :     void *hash;
    4149              :     size_t hash_size;
    4150              : 
    4151            1 :     spdm_test_context = *state;
    4152            1 :     spdm_context = spdm_test_context->spdm_context;
    4153              : 
    4154            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4155            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4156              :     }
    4157              : 
    4158            1 :     spdm_test_context->case_id = 0x10;
    4159            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4160              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4161            1 :     spdm_context->connection_info.connection_state =
    4162              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4163            1 :     spdm_context->connection_info.capability.flags &=
    4164              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4165            1 :     spdm_context->connection_info.capability.flags |=
    4166              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    4167            1 :     spdm_context->connection_info.capability.flags |=
    4168              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
    4169            1 :     spdm_context->local_context.capability.flags |=
    4170              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4171            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4172              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4173            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4174            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4175              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4176              : 
    4177            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4178              :                                                          m_libspdm_use_asym_algo, &data,
    4179              :                                                          &data_size, &hash, &hash_size)) {
    4180            0 :         assert(false);
    4181              :     }
    4182            1 :     libspdm_reset_message_a(spdm_context);
    4183            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4184              :         m_libspdm_use_hash_algo;
    4185            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4186              :         m_libspdm_use_dhe_algo;
    4187            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4188              :         m_libspdm_use_aead_algo;
    4189            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4190              :         m_libspdm_use_measurement_hash_algo;
    4191            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4192              :         m_libspdm_use_key_schedule_algo;
    4193              : 
    4194              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4195              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4196              :         data_size;
    4197              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4198              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4199              :                      data, data_size);
    4200              : 
    4201              : #endif
    4202              : 
    4203            1 :     heartbeat_period = 0;
    4204            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4205            1 :     status = libspdm_send_receive_psk_exchange(
    4206              :         spdm_context,
    4207              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4208              :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, &session_id,
    4209              :         &heartbeat_period, measurement_hash);
    4210            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4211            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    4212            1 :     assert_memory_equal(
    4213              :         measurement_hash,
    4214              :         m_libspdm_use_tcb_hash_value,
    4215              :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
    4216            1 :     assert_int_equal(
    4217              :         libspdm_secured_message_get_session_state(
    4218              :             spdm_context->session_info[0].secured_message_context),
    4219              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    4220            1 :     free(data);
    4221            1 : }
    4222              : 
    4223            1 : void libspdm_test_requester_psk_exchange_case17(void **state)
    4224              : {
    4225              :     libspdm_return_t status;
    4226              :     libspdm_test_context_t *spdm_test_context;
    4227              :     libspdm_context_t *spdm_context;
    4228              :     uint32_t session_id;
    4229              :     uint8_t heartbeat_period;
    4230              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4231              :     void *data;
    4232              :     size_t data_size;
    4233              :     void *hash;
    4234              :     size_t hash_size;
    4235              : 
    4236            1 :     spdm_test_context = *state;
    4237            1 :     spdm_context = spdm_test_context->spdm_context;
    4238              : 
    4239            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4240            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4241              :     }
    4242              : 
    4243            1 :     spdm_test_context->case_id = 0x11;
    4244            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4245              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4246            1 :     spdm_context->connection_info.connection_state =
    4247              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4248            1 :     spdm_context->connection_info.capability.flags &=
    4249              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4250            1 :     spdm_context->connection_info.capability.flags |=
    4251              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    4252            1 :     spdm_context->connection_info.capability.flags |=
    4253              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
    4254            1 :     spdm_context->local_context.capability.flags |=
    4255              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4256            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4257              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4258            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4259            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4260              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4261              : 
    4262            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4263              :                                                          m_libspdm_use_asym_algo, &data,
    4264              :                                                          &data_size, &hash, &hash_size)) {
    4265            0 :         assert(false);
    4266              :     }
    4267            1 :     libspdm_reset_message_a(spdm_context);
    4268            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4269              :         m_libspdm_use_hash_algo;
    4270            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4271              :         m_libspdm_use_dhe_algo;
    4272            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4273              :         m_libspdm_use_aead_algo;
    4274            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4275              :         m_libspdm_use_measurement_hash_algo;
    4276            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4277              :         m_libspdm_use_key_schedule_algo;
    4278              : 
    4279              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4280              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4281              :         data_size;
    4282              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4283              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4284              :                      data, data_size);
    4285              : 
    4286              : #endif
    4287              : 
    4288            1 :     heartbeat_period = 0;
    4289            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4290            1 :     status = libspdm_send_receive_psk_exchange(
    4291              :         spdm_context,
    4292              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4293              :         SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, &session_id,
    4294              :         &heartbeat_period, measurement_hash);
    4295            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    4296            1 :     free(data);
    4297            1 : }
    4298              : 
    4299            1 : void libspdm_test_requester_psk_exchange_case18(void **state)
    4300              : {
    4301              :     libspdm_return_t status;
    4302              :     libspdm_test_context_t *spdm_test_context;
    4303              :     libspdm_context_t *spdm_context;
    4304              :     uint32_t session_id;
    4305              :     uint8_t heartbeat_period;
    4306              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4307              :     void *data;
    4308              :     size_t data_size;
    4309              :     void *hash;
    4310              :     size_t hash_size;
    4311              : 
    4312            1 :     spdm_test_context = *state;
    4313            1 :     spdm_context = spdm_test_context->spdm_context;
    4314              : 
    4315            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4316            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4317              :     }
    4318              : 
    4319            1 :     spdm_test_context->case_id = 0x12;
    4320            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4321              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4322            1 :     spdm_context->connection_info.connection_state =
    4323              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4324            1 :     spdm_context->connection_info.capability.flags &=
    4325              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4326            1 :     spdm_context->connection_info.capability.flags |=
    4327              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    4328            1 :     spdm_context->connection_info.capability.flags |=
    4329              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
    4330            1 :     spdm_context->local_context.capability.flags |=
    4331              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4332            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4333              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4334            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4335            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4336              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4337              : 
    4338            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4339              :                                                          m_libspdm_use_asym_algo, &data,
    4340              :                                                          &data_size, &hash, &hash_size)) {
    4341            0 :         assert(false);
    4342              :     }
    4343            1 :     libspdm_reset_message_a(spdm_context);
    4344            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4345              :         m_libspdm_use_hash_algo;
    4346            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4347              :         m_libspdm_use_dhe_algo;
    4348            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4349              :         m_libspdm_use_aead_algo;
    4350            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4351              :         m_libspdm_use_measurement_hash_algo;
    4352            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4353              :         m_libspdm_use_key_schedule_algo;
    4354              : 
    4355              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4356              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4357              :         data_size;
    4358              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4359              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4360              :                      data, data_size);
    4361              : 
    4362              : #endif
    4363              : 
    4364            1 :     heartbeat_period = 0;
    4365            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4366            1 :     status = libspdm_send_receive_psk_exchange(
    4367              :         spdm_context,
    4368              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4369              :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, &session_id,
    4370              :         &heartbeat_period, measurement_hash);
    4371            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    4372            1 :     free(data);
    4373            1 : }
    4374              : 
    4375            1 : void libspdm_test_requester_psk_exchange_case19(void **state)
    4376              : {
    4377              :     libspdm_return_t status;
    4378              :     libspdm_test_context_t *spdm_test_context;
    4379              :     libspdm_context_t *spdm_context;
    4380              :     uint32_t session_id;
    4381              :     uint8_t heartbeat_period;
    4382              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4383              :     void *data;
    4384              :     size_t data_size;
    4385              :     void *hash;
    4386              :     size_t hash_size;
    4387              : 
    4388            1 :     spdm_test_context = *state;
    4389            1 :     spdm_context = spdm_test_context->spdm_context;
    4390              : 
    4391            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4392            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4393              :     }
    4394              : 
    4395            1 :     spdm_test_context->case_id = 0x13;
    4396            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4397              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4398            1 :     spdm_context->connection_info.connection_state =
    4399              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4400            1 :     spdm_context->connection_info.capability.flags &=
    4401              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4402            1 :     spdm_context->connection_info.capability.flags |=
    4403              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    4404            1 :     spdm_context->connection_info.capability.flags |=
    4405              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
    4406            1 :     spdm_context->local_context.capability.flags |=
    4407              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4408            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4409              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4410            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4411            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4412              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4413              : 
    4414            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4415              :                                                          m_libspdm_use_asym_algo, &data,
    4416              :                                                          &data_size, &hash, &hash_size)) {
    4417            0 :         assert(false);
    4418              :     }
    4419            1 :     libspdm_reset_message_a(spdm_context);
    4420            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4421              :         m_libspdm_use_hash_algo;
    4422            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4423              :         m_libspdm_use_dhe_algo;
    4424            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4425              :         m_libspdm_use_aead_algo;
    4426            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4427              :         m_libspdm_use_measurement_hash_algo;
    4428            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4429              :         m_libspdm_use_key_schedule_algo;
    4430              : 
    4431              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4432              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4433              :         data_size;
    4434              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4435              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4436              :                      data, data_size);
    4437              : 
    4438              : #endif
    4439              : 
    4440            1 :     heartbeat_period = 0;
    4441            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4442            1 :     status = libspdm_send_receive_psk_exchange(
    4443              :         spdm_context,
    4444              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4445              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    4446              :         &heartbeat_period, measurement_hash);
    4447            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    4448            1 :     free(data);
    4449            1 : }
    4450              : 
    4451            1 : void libspdm_test_requester_psk_exchange_case20(void **state)
    4452              : {
    4453              :     libspdm_return_t status;
    4454              :     libspdm_test_context_t *spdm_test_context;
    4455              :     libspdm_context_t *spdm_context;
    4456              :     uint32_t session_id;
    4457              :     uint8_t heartbeat_period;
    4458              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4459              :     void *data;
    4460              :     size_t data_size;
    4461              :     void *hash;
    4462              :     size_t hash_size;
    4463              : 
    4464            1 :     spdm_test_context = *state;
    4465            1 :     spdm_context = spdm_test_context->spdm_context;
    4466              : 
    4467            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4468            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4469              :     }
    4470              : 
    4471            1 :     spdm_test_context->case_id = 0x14;
    4472            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4473              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4474            1 :     spdm_context->connection_info.connection_state =
    4475              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4476            1 :     spdm_context->connection_info.capability.flags &=
    4477              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4478            1 :     spdm_context->connection_info.capability.flags |=
    4479              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    4480            1 :     spdm_context->connection_info.capability.flags |=
    4481              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
    4482            1 :     spdm_context->local_context.capability.flags |=
    4483              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4484            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4485              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4486            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4487            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4488              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4489              : 
    4490              : 
    4491            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4492              :                                                          m_libspdm_use_asym_algo, &data,
    4493              :                                                          &data_size, &hash, &hash_size)) {
    4494            0 :         assert(false);
    4495              :     }
    4496            1 :     libspdm_reset_message_a(spdm_context);
    4497            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4498              :         m_libspdm_use_hash_algo;
    4499            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4500              :         m_libspdm_use_dhe_algo;
    4501            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4502              :         m_libspdm_use_aead_algo;
    4503            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4504              :         m_libspdm_use_measurement_hash_algo;
    4505            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4506              :         m_libspdm_use_key_schedule_algo;
    4507              : 
    4508              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4509              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4510              :         data_size;
    4511              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4512              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4513              :                      data, data_size);
    4514              : 
    4515              : #endif
    4516              : 
    4517            1 :     heartbeat_period = 0;
    4518            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4519            1 :     status = libspdm_send_receive_psk_exchange(
    4520              :         spdm_context,
    4521              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4522              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    4523              :         &heartbeat_period, measurement_hash);
    4524            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    4525            1 :     free(data);
    4526            1 : }
    4527              : 
    4528            1 : void libspdm_test_requester_psk_exchange_case21(void **state)
    4529              : {
    4530              :     libspdm_return_t status;
    4531              :     libspdm_test_context_t *spdm_test_context;
    4532              :     libspdm_context_t *spdm_context;
    4533              :     uint32_t session_id;
    4534              :     uint8_t heartbeat_period;
    4535              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4536              :     void *data;
    4537              :     size_t data_size;
    4538              :     void *hash;
    4539              :     size_t hash_size;
    4540              : 
    4541            1 :     spdm_test_context = *state;
    4542            1 :     spdm_context = spdm_test_context->spdm_context;
    4543              : 
    4544            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4545            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4546              :     }
    4547              : 
    4548            1 :     spdm_test_context->case_id = 0x15;
    4549            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4550              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4551            1 :     spdm_context->connection_info.connection_state =
    4552              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4553            1 :     spdm_context->connection_info.capability.flags &=
    4554              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4555            1 :     spdm_context->connection_info.capability.flags |=
    4556              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    4557            1 :     spdm_context->connection_info.capability.flags |=
    4558              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
    4559            1 :     spdm_context->local_context.capability.flags |=
    4560              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4561              : 
    4562            1 :     spdm_context->connection_info.capability.flags |=
    4563              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
    4564            1 :     spdm_context->local_context.capability.flags |=
    4565              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
    4566              : 
    4567            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4568              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4569            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4570            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4571              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4572              : 
    4573              : 
    4574            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4575              :                                                          m_libspdm_use_asym_algo, &data,
    4576              :                                                          &data_size, &hash, &hash_size)) {
    4577            0 :         assert(false);
    4578              :     }
    4579            1 :     libspdm_reset_message_a(spdm_context);
    4580            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4581              :         m_libspdm_use_hash_algo;
    4582            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4583              :         m_libspdm_use_dhe_algo;
    4584            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4585              :         m_libspdm_use_aead_algo;
    4586            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4587              :         m_libspdm_use_measurement_hash_algo;
    4588            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4589              :         m_libspdm_use_key_schedule_algo;
    4590              : 
    4591              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4592              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4593              :         data_size;
    4594              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4595              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4596              :                      data, data_size);
    4597              : 
    4598              : #endif
    4599              : 
    4600            1 :     heartbeat_period = 0;
    4601            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4602            1 :     status = libspdm_send_receive_psk_exchange(
    4603              :         spdm_context,
    4604              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4605              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    4606              :         &heartbeat_period, measurement_hash);
    4607              :     /* clear Heartbeat flags */
    4608            1 :     spdm_context->connection_info.capability.flags &=
    4609              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
    4610            1 :     spdm_context->local_context.capability.flags &=
    4611              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
    4612            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4613            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    4614            1 :     assert_int_equal(
    4615              :         libspdm_secured_message_get_session_state(
    4616              :             spdm_context->session_info[0].secured_message_context),
    4617              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    4618            1 :     assert_int_equal(heartbeat_period,5);
    4619            1 :     free(data);
    4620            1 : }
    4621              : 
    4622            1 : void libspdm_test_requester_psk_exchange_case22(void **state)
    4623              : {
    4624              :     libspdm_return_t status;
    4625              :     libspdm_test_context_t *spdm_test_context;
    4626              :     libspdm_context_t *spdm_context;
    4627              :     uint32_t session_id;
    4628              :     uint8_t heartbeat_period;
    4629              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4630              :     void *data;
    4631              :     size_t data_size;
    4632              :     void *hash;
    4633              :     size_t hash_size;
    4634              : 
    4635            1 :     spdm_test_context = *state;
    4636            1 :     spdm_context = spdm_test_context->spdm_context;
    4637              : 
    4638            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4639            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4640              :     }
    4641              : 
    4642            1 :     spdm_test_context->case_id = 0x16;
    4643            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4644              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4645            1 :     spdm_context->connection_info.connection_state =
    4646              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4647            1 :     spdm_context->connection_info.capability.flags &=
    4648              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4649            1 :     spdm_context->connection_info.capability.flags |=
    4650              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    4651            1 :     spdm_context->connection_info.capability.flags |=
    4652              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
    4653            1 :     spdm_context->local_context.capability.flags |=
    4654              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4655              : 
    4656            1 :     spdm_context->connection_info.capability.flags |=
    4657              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
    4658            1 :     spdm_context->local_context.capability.flags |=
    4659              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
    4660              : 
    4661            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4662              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4663            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4664            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4665              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4666              : 
    4667              : 
    4668            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4669              :                                                          m_libspdm_use_asym_algo, &data,
    4670              :                                                          &data_size, &hash, &hash_size)) {
    4671            0 :         assert(false);
    4672              :     }
    4673            1 :     libspdm_reset_message_a(spdm_context);
    4674            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4675              :         m_libspdm_use_hash_algo;
    4676            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4677              :         m_libspdm_use_dhe_algo;
    4678            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4679              :         m_libspdm_use_aead_algo;
    4680            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4681              :         m_libspdm_use_measurement_hash_algo;
    4682            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4683              :         m_libspdm_use_key_schedule_algo;
    4684              : 
    4685              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4686              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4687              :         data_size;
    4688              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4689              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4690              :                      data, data_size);
    4691              : 
    4692              : #endif
    4693              : 
    4694            1 :     heartbeat_period = 0;
    4695            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4696            1 :     status = libspdm_send_receive_psk_exchange(
    4697              :         spdm_context,
    4698              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4699              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    4700              :         &heartbeat_period, measurement_hash);
    4701              : 
    4702              :     /*clear Heartbeat flags*/
    4703            1 :     spdm_context->connection_info.capability.flags &=
    4704              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
    4705            1 :     spdm_context->local_context.capability.flags &=
    4706              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
    4707              : 
    4708            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4709            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    4710            1 :     assert_int_equal(
    4711              :         libspdm_secured_message_get_session_state(
    4712              :             spdm_context->session_info[0].secured_message_context),
    4713              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    4714            1 :     assert_int_equal(heartbeat_period,0);
    4715            1 :     free(data);
    4716            1 : }
    4717              : 
    4718            1 : void libspdm_test_requester_psk_exchange_case23(void **state)
    4719              : {
    4720              :     libspdm_return_t status;
    4721              :     libspdm_test_context_t *spdm_test_context;
    4722              :     libspdm_context_t *spdm_context;
    4723              :     uint32_t session_id;
    4724              :     uint8_t heartbeat_period;
    4725              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4726              :     void *data;
    4727              :     size_t data_size;
    4728              :     void *hash;
    4729              :     size_t hash_size;
    4730              : 
    4731            1 :     spdm_test_context = *state;
    4732            1 :     spdm_context = spdm_test_context->spdm_context;
    4733              : 
    4734            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4735            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4736              :     }
    4737              : 
    4738            1 :     spdm_test_context->case_id = 0x17;
    4739            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4740              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4741            1 :     spdm_context->connection_info.connection_state =
    4742              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4743            1 :     spdm_context->connection_info.capability.flags &=
    4744              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4745            1 :     spdm_context->connection_info.capability.flags |=
    4746              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    4747            1 :     spdm_context->local_context.capability.flags |=
    4748              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4749            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4750            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4751              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4752            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4753              :                                                          m_libspdm_use_asym_algo, &data,
    4754              :                                                          &data_size, &hash, &hash_size)) {
    4755            0 :         assert(false);
    4756              :     }
    4757            1 :     libspdm_reset_message_a(spdm_context);
    4758            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4759              :         m_libspdm_use_hash_algo;
    4760            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4761              :         m_libspdm_use_dhe_algo;
    4762            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4763              :         m_libspdm_use_aead_algo;
    4764            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4765              :         m_libspdm_use_key_schedule_algo;
    4766              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4767              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4768              :         data_size;
    4769              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4770              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4771              :                      data, data_size);
    4772              : #endif
    4773              : 
    4774            1 :     heartbeat_period = 0;
    4775            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4776            1 :     status = libspdm_send_receive_psk_exchange(
    4777              :         spdm_context,
    4778              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4779              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    4780              :         &heartbeat_period, measurement_hash);
    4781            1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
    4782            1 :     free(data);
    4783            1 : }
    4784              : 
    4785            1 : void libspdm_test_requester_psk_exchange_case24(void **state)
    4786              : {
    4787              :     libspdm_return_t status;
    4788              :     libspdm_test_context_t *spdm_test_context;
    4789              :     libspdm_context_t *spdm_context;
    4790              :     uint32_t session_id;
    4791              :     uint8_t heartbeat_period;
    4792              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4793              :     void *data;
    4794              :     size_t data_size;
    4795              :     void *hash;
    4796              :     size_t hash_size;
    4797              : 
    4798            1 :     spdm_test_context = *state;
    4799            1 :     spdm_context = spdm_test_context->spdm_context;
    4800              : 
    4801            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4802            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4803              :     }
    4804              : 
    4805            1 :     spdm_test_context->case_id = 0x18;
    4806            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4807              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4808            1 :     spdm_context->connection_info.connection_state =
    4809              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4810            1 :     spdm_context->connection_info.capability.flags &=
    4811              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4812            1 :     spdm_context->connection_info.capability.flags |=
    4813              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER;
    4814            1 :     spdm_context->local_context.capability.flags |=
    4815              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4816            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4817            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4818              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4819            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4820              :                                                          m_libspdm_use_asym_algo, &data,
    4821              :                                                          &data_size, &hash, &hash_size)) {
    4822            0 :         assert(false);
    4823              :     }
    4824            1 :     libspdm_reset_message_a(spdm_context);
    4825            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4826              :         m_libspdm_use_hash_algo;
    4827            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4828              :         m_libspdm_use_dhe_algo;
    4829            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4830              :         m_libspdm_use_aead_algo;
    4831            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4832              :         m_libspdm_use_key_schedule_algo;
    4833              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4834              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4835              :         data_size;
    4836              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4837              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4838              :                      data, data_size);
    4839              : #endif
    4840              : 
    4841            1 :     heartbeat_period = 0;
    4842            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4843            1 :     status = libspdm_send_receive_psk_exchange(
    4844              :         spdm_context,
    4845              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4846              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    4847              :         &heartbeat_period, measurement_hash);
    4848            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4849            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    4850            1 :     assert_int_equal(
    4851              :         libspdm_secured_message_get_session_state(
    4852              :             spdm_context->session_info[0].secured_message_context),
    4853              :         LIBSPDM_SESSION_STATE_ESTABLISHED);
    4854            1 :     free(data);
    4855            1 : }
    4856              : 
    4857            1 : void libspdm_test_requester_psk_exchange_case25(void **state)
    4858              : {
    4859              :     libspdm_return_t status;
    4860              :     libspdm_test_context_t *spdm_test_context;
    4861              :     libspdm_context_t *spdm_context;
    4862              :     uint32_t session_id;
    4863              :     uint8_t heartbeat_period;
    4864              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4865              :     void *data;
    4866              :     size_t data_size;
    4867              :     void *hash;
    4868              :     size_t hash_size;
    4869              : 
    4870            1 :     spdm_test_context = *state;
    4871            1 :     spdm_context = spdm_test_context->spdm_context;
    4872              : 
    4873            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4874            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4875              :     }
    4876              : 
    4877            1 :     spdm_test_context->case_id = 0x19;
    4878            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4879              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4880            1 :     spdm_context->connection_info.connection_state =
    4881              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4882            1 :     spdm_context->connection_info.capability.flags &=
    4883              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4884            1 :     spdm_context->connection_info.capability.flags |=
    4885              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    4886            1 :     spdm_context->local_context.capability.flags |=
    4887              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4888            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4889            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4890              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4891            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4892              :                                                          m_libspdm_use_asym_algo, &data,
    4893              :                                                          &data_size, &hash, &hash_size)) {
    4894            0 :         assert(false);
    4895              :     }
    4896            1 :     libspdm_reset_message_a(spdm_context);
    4897            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4898              :         m_libspdm_use_hash_algo;
    4899            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4900              :         m_libspdm_use_dhe_algo;
    4901            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4902              :         m_libspdm_use_aead_algo;
    4903            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4904              :         m_libspdm_use_key_schedule_algo;
    4905              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4906              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4907              :         data_size;
    4908              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4909              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4910              :                      data, data_size);
    4911              : #endif
    4912              : 
    4913            1 :     heartbeat_period = 0;
    4914            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4915            1 :     status = libspdm_send_receive_psk_exchange(
    4916              :         spdm_context,
    4917              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4918              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    4919              :         &heartbeat_period, measurement_hash);
    4920            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4921            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    4922            1 :     assert_int_equal(
    4923              :         libspdm_secured_message_get_session_state(
    4924              :             spdm_context->session_info[0].secured_message_context),
    4925              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    4926            1 :     free(data);
    4927            1 : }
    4928              : 
    4929            1 : void libspdm_test_requester_psk_exchange_case26(void **state)
    4930              : {
    4931              :     libspdm_return_t status;
    4932              :     libspdm_test_context_t *spdm_test_context;
    4933              :     libspdm_context_t *spdm_context;
    4934              :     uint32_t session_id;
    4935              :     uint8_t heartbeat_period;
    4936              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    4937              :     void *data;
    4938              :     size_t data_size;
    4939              :     void *hash;
    4940              :     size_t hash_size;
    4941              : 
    4942            1 :     spdm_test_context = *state;
    4943            1 :     spdm_context = spdm_test_context->spdm_context;
    4944              : 
    4945            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    4946            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    4947              :     }
    4948              : 
    4949            1 :     spdm_test_context->case_id = 0x1A;
    4950            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4951              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4952            1 :     spdm_context->connection_info.connection_state =
    4953              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    4954            1 :     spdm_context->connection_info.capability.flags &=
    4955              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    4956            1 :     spdm_context->connection_info.capability.flags |=
    4957              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER;
    4958            1 :     spdm_context->local_context.capability.flags |=
    4959              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    4960            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    4961            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    4962              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    4963            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4964              :                                                          m_libspdm_use_asym_algo, &data,
    4965              :                                                          &data_size, &hash, &hash_size)) {
    4966            0 :         assert(false);
    4967              :     }
    4968            1 :     libspdm_reset_message_a(spdm_context);
    4969            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4970              :         m_libspdm_use_hash_algo;
    4971            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    4972              :         m_libspdm_use_dhe_algo;
    4973            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    4974              :         m_libspdm_use_aead_algo;
    4975            1 :     spdm_context->connection_info.algorithm.key_schedule =
    4976              :         m_libspdm_use_key_schedule_algo;
    4977              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4978              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4979              :         data_size;
    4980              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4981              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4982              :                      data, data_size);
    4983              : #endif
    4984              : 
    4985            1 :     heartbeat_period = 0;
    4986            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    4987            1 :     status = libspdm_send_receive_psk_exchange(
    4988              :         spdm_context,
    4989              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    4990              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
    4991              :         &heartbeat_period, measurement_hash);
    4992            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4993            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    4994            1 :     assert_int_equal(
    4995              :         libspdm_secured_message_get_session_state(
    4996              :             spdm_context->session_info[0].secured_message_context),
    4997              :         LIBSPDM_SESSION_STATE_ESTABLISHED);
    4998            1 :     free(data);
    4999            1 : }
    5000              : 
    5001            1 : void libspdm_test_requester_psk_exchange_case27(void **state)
    5002              : {
    5003              :     libspdm_return_t status;
    5004              :     libspdm_test_context_t *spdm_test_context;
    5005              :     libspdm_context_t *spdm_context;
    5006              :     uint32_t session_id;
    5007              :     uint8_t heartbeat_period;
    5008              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5009              :     void *data;
    5010              :     size_t data_size;
    5011              :     void *hash;
    5012              :     size_t hash_size;
    5013              : 
    5014            1 :     spdm_test_context = *state;
    5015            1 :     spdm_context = spdm_test_context->spdm_context;
    5016            1 :     spdm_test_context->case_id = 0x1B;
    5017            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    5018              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5019            1 :     spdm_context->connection_info.connection_state =
    5020              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    5021            1 :     spdm_context->connection_info.capability.flags &=
    5022              :         ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
    5023            1 :     spdm_context->connection_info.capability.flags |=
    5024              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
    5025            1 :     spdm_context->local_context.capability.flags |=
    5026              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
    5027            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    5028            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    5029              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    5030            1 :     spdm_context->connection_info.algorithm.other_params_support =
    5031              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    5032            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5033              :                                                          m_libspdm_use_asym_algo, &data,
    5034              :                                                          &data_size, &hash, &hash_size)) {
    5035            0 :         assert(false);
    5036              :     }
    5037            1 :     libspdm_reset_message_a(spdm_context);
    5038            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5039              :         m_libspdm_use_hash_algo;
    5040            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5041              :         m_libspdm_use_dhe_algo;
    5042            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5043              :         m_libspdm_use_aead_algo;
    5044            1 :     spdm_context->connection_info.algorithm.key_schedule =
    5045              :         m_libspdm_use_key_schedule_algo;
    5046            1 :     libspdm_session_info_init(spdm_context,
    5047            1 :                               spdm_context->session_info,
    5048              :                               INVALID_SESSION_ID, false);
    5049              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5050              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5051              :         data_size;
    5052              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5053              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5054              :                      data, data_size);
    5055              : #endif
    5056              : 
    5057            1 :     heartbeat_period = 0;
    5058            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    5059            1 :     status = libspdm_send_receive_psk_exchange(
    5060              :         spdm_context,
    5061              :         LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
    5062              :         SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    5063              :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, &session_id,
    5064              :         &heartbeat_period, measurement_hash);
    5065            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    5066            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    5067            1 :     assert_int_equal(
    5068              :         libspdm_secured_message_get_session_state(
    5069              :             spdm_context->session_info[0].secured_message_context),
    5070              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    5071            1 :     assert_int_equal(
    5072              :         spdm_context->session_info[0].session_policy,
    5073              :         SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH);
    5074            1 :     free(data);
    5075            1 : }
    5076              : 
    5077            1 : int libspdm_requester_psk_exchange_test_main(void)
    5078              : {
    5079            1 :     const struct CMUnitTest spdm_requester_psk_exchange_tests[] = {
    5080              :         /* SendRequest failed*/
    5081              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case1),
    5082              :         /* Successful response*/
    5083              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case2),
    5084              :         /* connection_state check failed*/
    5085              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case3),
    5086              :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
    5087              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case4),
    5088              :         /* Always SPDM_ERROR_CODE_BUSY*/
    5089              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case5),
    5090              :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
    5091              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case6),
    5092              :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
    5093              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case7),
    5094              :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
    5095              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case8),
    5096              :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
    5097              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case9),
    5098              :         /* Unexpected errors*/
    5099              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case10),
    5100              :         /* Buffer verification*/
    5101              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case12),
    5102              :         /* Successful response V1.2*/
    5103              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case13),
    5104              :         /* Measurement hash 1, returns a measurement hash*/
    5105              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case14),
    5106              :         /* Measurement hash 1, returns a 0x00 array (no TCB components)*/
    5107              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case15),
    5108              :         /* Measurement hash FF, returns a measurement_hash*/
    5109              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case16),
    5110              :         /* Measurement hash 1, returns no measurement_hash*/
    5111              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case17),
    5112              :         /* Measurement hash FF, returns no measurement_hash*/
    5113              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case18),
    5114              :         /* Measurement hash not requested, returns a measurement_hash*/
    5115              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case19),
    5116              :         /* Heartbeat not supported, heartbeat period different from 0 sent*/
    5117              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case20),
    5118              :         /* Heartbeat supported, heartbeat period different from 0 sent*/
    5119              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case21),
    5120              :         /* Heartbeat supported, heartbeat period 0 sent NOTE: This should disable heartbeat*/
    5121              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case22),
    5122              :         /* Wrong ResponderVerifyData*/
    5123              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case23),
    5124              :         /* No ResponderContext*/
    5125              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case24),
    5126              :         /* No OpaqueData*/
    5127              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case25),
    5128              :         /* No ResponderContext and OpaqueData*/
    5129              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case26),
    5130              :         /* OpaqueData only supports OpaqueDataFmt1, Success Case */
    5131              :         cmocka_unit_test(libspdm_test_requester_psk_exchange_case27),
    5132              :     };
    5133              : 
    5134            1 :     libspdm_test_context_t test_context = {
    5135              :         LIBSPDM_TEST_CONTEXT_VERSION,
    5136              :         true,
    5137              :         libspdm_requester_psk_exchange_test_send_message,
    5138              :         libspdm_requester_psk_exchange_test_receive_message,
    5139              :     };
    5140              : 
    5141            1 :     libspdm_setup_test_context(&test_context);
    5142              : 
    5143            1 :     return cmocka_run_group_tests(spdm_requester_psk_exchange_tests,
    5144              :                                   libspdm_unit_test_group_setup,
    5145              :                                   libspdm_unit_test_group_teardown);
    5146              : }
    5147              : 
    5148              : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
        

Generated by: LCOV version 2.0-1