LCOV - code coverage report
Current view: top level - unit_test/test_spdm_requester - key_exchange.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.3 % 3649 3515
Test Date: 2025-10-12 08:10:56 Functions: 100.0 % 38 38

            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_KEY_EX_CAP
      12              : 
      13              : static size_t m_libspdm_local_buffer_size;
      14              : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
      15              : static uint8_t m_libspdm_zero_filled_buffer[LIBSPDM_MAX_HASH_SIZE];
      16              : 
      17              : static libspdm_th_managed_buffer_t th_curr;
      18              : 
      19           51 : static size_t libspdm_test_get_key_exchange_request_size(const void *spdm_context,
      20              :                                                          const void *buffer,
      21              :                                                          size_t buffer_size)
      22              : {
      23              :     const spdm_key_exchange_request_t *spdm_request;
      24              :     size_t message_size;
      25              :     size_t dhe_key_size;
      26              :     uint16_t opaque_length;
      27              : 
      28           51 :     spdm_request = buffer;
      29           51 :     message_size = sizeof(spdm_message_header_t);
      30           51 :     if (buffer_size < message_size) {
      31            0 :         return buffer_size;
      32              :     }
      33              : 
      34           51 :     if (spdm_request->header.request_response_code != SPDM_KEY_EXCHANGE) {
      35            1 :         return buffer_size;
      36              :     }
      37              : 
      38           50 :     message_size = sizeof(spdm_key_exchange_request_t);
      39           50 :     if (buffer_size < message_size) {
      40            0 :         return buffer_size;
      41              :     }
      42              : 
      43           50 :     dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
      44           50 :     message_size += dhe_key_size + sizeof(uint16_t);
      45           50 :     if (buffer_size < message_size) {
      46            0 :         return buffer_size;
      47              :     }
      48              : 
      49           50 :     opaque_length =
      50           50 :         *(uint16_t *)((size_t)buffer +
      51           50 :                       sizeof(spdm_key_exchange_request_t) + dhe_key_size);
      52           50 :     message_size += opaque_length;
      53           50 :     if (buffer_size < message_size) {
      54            0 :         return buffer_size;
      55              :     }
      56              : 
      57              :     /* Good message, return actual size*/
      58           50 :     return message_size;
      59              : }
      60              : 
      61           53 : static libspdm_return_t send_message(
      62              :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
      63              : {
      64              :     libspdm_test_context_t *spdm_test_context;
      65              :     size_t header_size;
      66              :     size_t message_size;
      67              : 
      68           53 :     spdm_test_context = libspdm_get_test_context();
      69           53 :     header_size = sizeof(libspdm_test_message_header_t);
      70           53 :     switch (spdm_test_context->case_id) {
      71            1 :     case 0x1:
      72            1 :         return LIBSPDM_STATUS_SEND_FAIL;
      73            1 :     case 0x2:
      74            1 :         m_libspdm_local_buffer_size = 0;
      75            1 :         message_size = libspdm_test_get_key_exchange_request_size(
      76              :             spdm_context, (const uint8_t *)request + header_size,
      77              :             request_size - header_size);
      78            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
      79              :                          (const uint8_t *)request + header_size, message_size);
      80            1 :         m_libspdm_local_buffer_size += message_size;
      81            1 :         return LIBSPDM_STATUS_SUCCESS;
      82            0 :     case 0x3:
      83            0 :         m_libspdm_local_buffer_size = 0;
      84            0 :         message_size = libspdm_test_get_key_exchange_request_size(
      85              :             spdm_context, (const uint8_t *)request + header_size,
      86              :             request_size - header_size);
      87            0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
      88              :                          (const uint8_t *)request + header_size, message_size);
      89            0 :         m_libspdm_local_buffer_size += message_size;
      90            0 :         return LIBSPDM_STATUS_SUCCESS;
      91            1 :     case 0x4:
      92            1 :         m_libspdm_local_buffer_size = 0;
      93            1 :         message_size = libspdm_test_get_key_exchange_request_size(
      94              :             spdm_context, (const uint8_t *)request + header_size,
      95              :             request_size - header_size);
      96            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
      97              :                          (const uint8_t *)request + header_size, message_size);
      98            1 :         m_libspdm_local_buffer_size += message_size;
      99            1 :         return LIBSPDM_STATUS_SUCCESS;
     100            1 :     case 0x5:
     101            1 :         m_libspdm_local_buffer_size = 0;
     102            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     103              :             spdm_context, (const uint8_t *)request + header_size,
     104              :             request_size - header_size);
     105            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     106              :                          (const uint8_t *)request + header_size, message_size);
     107            1 :         m_libspdm_local_buffer_size += message_size;
     108            1 :         return LIBSPDM_STATUS_SUCCESS;
     109            2 :     case 0x6:
     110            2 :         m_libspdm_local_buffer_size = 0;
     111            2 :         message_size = libspdm_test_get_key_exchange_request_size(
     112              :             spdm_context, (const uint8_t *)request + header_size,
     113              :             request_size - header_size);
     114            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     115              :                          (const uint8_t *)request + header_size, message_size);
     116            2 :         m_libspdm_local_buffer_size += message_size;
     117            2 :         return LIBSPDM_STATUS_SUCCESS;
     118            1 :     case 0x7:
     119            1 :         m_libspdm_local_buffer_size = 0;
     120            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     121              :             spdm_context, (const uint8_t *)request + header_size,
     122              :             request_size - header_size);
     123            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     124              :                          (const uint8_t *)request + header_size, message_size);
     125            1 :         m_libspdm_local_buffer_size += message_size;
     126            1 :         return LIBSPDM_STATUS_SUCCESS;
     127            2 :     case 0x8:
     128            2 :         m_libspdm_local_buffer_size = 0;
     129            2 :         message_size = libspdm_test_get_key_exchange_request_size(
     130              :             spdm_context, (const uint8_t *)request + header_size,
     131              :             request_size - header_size);
     132            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     133              :                          (const uint8_t *)request + header_size, message_size);
     134            2 :         m_libspdm_local_buffer_size += message_size;
     135            2 :         return LIBSPDM_STATUS_SUCCESS;
     136            2 :     case 0x9: {
     137              :         static size_t sub_index = 0;
     138            2 :         if (sub_index == 0) {
     139            1 :             m_libspdm_local_buffer_size = 0;
     140            1 :             message_size = libspdm_test_get_key_exchange_request_size(
     141              :                 spdm_context, (const uint8_t *)request + header_size,
     142              :                 request_size - header_size);
     143            1 :             libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     144              :                              (const uint8_t *)request + header_size, message_size);
     145            1 :             m_libspdm_local_buffer_size += message_size;
     146            1 :             sub_index++;
     147              :         }
     148              :     }
     149            2 :         return LIBSPDM_STATUS_SUCCESS;
     150           18 :     case 0xA:
     151           18 :         m_libspdm_local_buffer_size = 0;
     152           18 :         message_size = libspdm_test_get_key_exchange_request_size(
     153              :             spdm_context, (const uint8_t *)request + header_size,
     154              :             request_size - header_size);
     155           18 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     156              :                          (const uint8_t *)request + header_size, message_size);
     157           18 :         m_libspdm_local_buffer_size += message_size;
     158           18 :         return LIBSPDM_STATUS_SUCCESS;
     159            1 :     case 0xB:
     160            1 :         m_libspdm_local_buffer_size = 0;
     161            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     162              :             spdm_context, (const uint8_t *)request + header_size,
     163              :             request_size - header_size);
     164            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     165              :                          (const uint8_t *)request + header_size, message_size);
     166            1 :         m_libspdm_local_buffer_size += message_size;
     167            1 :         return LIBSPDM_STATUS_SUCCESS;
     168            1 :     case 0xC:
     169            1 :         m_libspdm_local_buffer_size = 0;
     170            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     171              :             spdm_context, (const uint8_t *)request + header_size,
     172              :             request_size - header_size);
     173            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     174              :                          (const uint8_t *)request + header_size, message_size);
     175            1 :         m_libspdm_local_buffer_size += message_size;
     176            1 :         return LIBSPDM_STATUS_SUCCESS;
     177            1 :     case 0xD:
     178            1 :         m_libspdm_local_buffer_size = 0;
     179            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     180              :             spdm_context, (const uint8_t *)request + header_size,
     181              :             request_size - header_size);
     182            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     183              :                          (const uint8_t *)request + header_size, message_size);
     184            1 :         m_libspdm_local_buffer_size += message_size;
     185            1 :         return LIBSPDM_STATUS_SUCCESS;
     186            1 :     case 0xE:
     187            1 :         m_libspdm_local_buffer_size = 0;
     188            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     189              :             spdm_context, (const uint8_t *)request + header_size,
     190              :             request_size - header_size);
     191            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     192              :                          (const uint8_t *)request + header_size, message_size);
     193            1 :         m_libspdm_local_buffer_size += message_size;
     194            1 :         return LIBSPDM_STATUS_SUCCESS;
     195            1 :     case 0xF:
     196            1 :         m_libspdm_local_buffer_size = 0;
     197            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     198              :             spdm_context, (const uint8_t *)request + header_size,
     199              :             request_size - header_size);
     200            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     201              :                          (const uint8_t *)request + header_size, message_size);
     202            1 :         m_libspdm_local_buffer_size += message_size;
     203            1 :         return LIBSPDM_STATUS_SUCCESS;
     204            1 :     case 0x10:
     205            1 :         m_libspdm_local_buffer_size = 0;
     206            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     207              :             spdm_context, (const uint8_t *)request + header_size,
     208              :             request_size - header_size);
     209            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     210              :                          (const uint8_t *)request + header_size, message_size);
     211            1 :         m_libspdm_local_buffer_size += message_size;
     212            1 :         return LIBSPDM_STATUS_SUCCESS;
     213            1 :     case 0x11:
     214            1 :         m_libspdm_local_buffer_size = 0;
     215            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     216              :             spdm_context, (const uint8_t *)request + header_size,
     217              :             request_size - header_size);
     218            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     219              :                          (const uint8_t *)request + header_size, message_size);
     220            1 :         m_libspdm_local_buffer_size += message_size;
     221            1 :         return LIBSPDM_STATUS_SUCCESS;
     222            1 :     case 0x12:
     223            1 :         m_libspdm_local_buffer_size = 0;
     224            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     225              :             spdm_context, (const uint8_t *)request + header_size,
     226              :             request_size - header_size);
     227            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     228              :                          (const uint8_t *)request + header_size, message_size);
     229            1 :         m_libspdm_local_buffer_size += message_size;
     230            1 :         return LIBSPDM_STATUS_SUCCESS;
     231            1 :     case 0x13:
     232            1 :         m_libspdm_local_buffer_size = 0;
     233            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     234              :             spdm_context, (const uint8_t *)request + header_size,
     235              :             request_size - header_size);
     236            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     237              :                          (const uint8_t *)request + header_size, message_size);
     238            1 :         m_libspdm_local_buffer_size += message_size;
     239            1 :         return LIBSPDM_STATUS_SUCCESS;
     240            1 :     case 0x14:
     241            1 :         m_libspdm_local_buffer_size = 0;
     242            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     243              :             spdm_context, (const uint8_t *)request + header_size,
     244              :             request_size - header_size);
     245            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     246              :                          (const uint8_t *)request + header_size, message_size);
     247            1 :         m_libspdm_local_buffer_size += message_size;
     248            1 :         return LIBSPDM_STATUS_SUCCESS;
     249            1 :     case 0x15:
     250            1 :         m_libspdm_local_buffer_size = 0;
     251            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     252              :             spdm_context, (const uint8_t *)request + header_size,
     253              :             request_size - header_size);
     254            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     255              :                          (const uint8_t *)request + header_size, message_size);
     256            1 :         m_libspdm_local_buffer_size += message_size;
     257            1 :         return LIBSPDM_STATUS_SUCCESS;
     258            1 :     case 0x16:
     259            1 :         m_libspdm_local_buffer_size = 0;
     260            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     261              :             spdm_context, (const uint8_t *)request + header_size,
     262              :             request_size - header_size);
     263            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     264              :                          (const uint8_t *)request + header_size, message_size);
     265            1 :         m_libspdm_local_buffer_size += message_size;
     266            1 :         return LIBSPDM_STATUS_SUCCESS;
     267            1 :     case 0x17:
     268            1 :         m_libspdm_local_buffer_size = 0;
     269            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     270              :             spdm_context, (const uint8_t *)request + header_size,
     271              :             request_size - header_size);
     272            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     273              :                          (const uint8_t *)request + header_size, message_size);
     274            1 :         m_libspdm_local_buffer_size += message_size;
     275            1 :         return LIBSPDM_STATUS_SUCCESS;
     276            1 :     case 0x18:
     277            1 :         m_libspdm_local_buffer_size = 0;
     278            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     279              :             spdm_context, (const uint8_t *)request + header_size,
     280              :             request_size - header_size);
     281            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     282              :                          (const uint8_t *)request + header_size, message_size);
     283            1 :         m_libspdm_local_buffer_size += message_size;
     284            1 :         return LIBSPDM_STATUS_SUCCESS;
     285            1 :     case 0x19:
     286            1 :         m_libspdm_local_buffer_size = 0;
     287            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     288              :             spdm_context, (const uint8_t *)request + header_size,
     289              :             request_size - header_size);
     290            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     291              :                          (const uint8_t *)request + header_size, message_size);
     292            1 :         m_libspdm_local_buffer_size += message_size;
     293            1 :         return LIBSPDM_STATUS_SUCCESS;
     294            1 :     case 0x1A:
     295            1 :         m_libspdm_local_buffer_size = 0;
     296            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     297              :             spdm_context, (const uint8_t *)request + header_size,
     298              :             request_size - header_size);
     299            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     300              :                          (const uint8_t *)request + header_size, message_size);
     301            1 :         m_libspdm_local_buffer_size += message_size;
     302            1 :         return LIBSPDM_STATUS_SUCCESS;
     303            1 :     case 0x1B:
     304            1 :         m_libspdm_local_buffer_size = 0;
     305            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     306              :             spdm_context, (const uint8_t *)request + header_size,
     307              :             request_size - header_size);
     308            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     309              :                          (const uint8_t *)request + header_size, message_size);
     310            1 :         m_libspdm_local_buffer_size += message_size;
     311            1 :         return LIBSPDM_STATUS_SUCCESS;
     312            1 :     case 0x1C:
     313            1 :         m_libspdm_local_buffer_size = 0;
     314            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     315              :             spdm_context, (const uint8_t *)request + header_size,
     316              :             request_size - header_size);
     317            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     318              :                          (const uint8_t *)request + header_size, message_size);
     319            1 :         m_libspdm_local_buffer_size += message_size;
     320            1 :         return LIBSPDM_STATUS_SUCCESS;
     321            1 :     case 0x1D:
     322            1 :         m_libspdm_local_buffer_size = 0;
     323            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     324              :             spdm_context, (const uint8_t *)request + header_size,
     325              :             request_size - header_size);
     326            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     327              :                          (const uint8_t *)request + header_size,  message_size);
     328            1 :         m_libspdm_local_buffer_size += message_size;
     329            1 :         return LIBSPDM_STATUS_SUCCESS;
     330            1 :     case 0x1E:
     331            1 :         m_libspdm_local_buffer_size = 0;
     332            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     333              :             spdm_context, (const uint8_t *)request + header_size,
     334              :             request_size - header_size);
     335            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     336              :                          (const uint8_t *)request + header_size, message_size);
     337            1 :         m_libspdm_local_buffer_size += message_size;
     338            1 :         return LIBSPDM_STATUS_SUCCESS;
     339            1 :     case 0x1F:
     340            1 :         m_libspdm_local_buffer_size = 0;
     341            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     342              :             spdm_context, (const uint8_t *)request + header_size,
     343              :             request_size - header_size);
     344            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     345              :                          (const uint8_t *)request + header_size, message_size);
     346            1 :         m_libspdm_local_buffer_size += message_size;
     347            1 :         return LIBSPDM_STATUS_SUCCESS;
     348            1 :     case 0x20:
     349            1 :         m_libspdm_local_buffer_size = 0;
     350            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     351              :             spdm_context, (const uint8_t *)request + header_size,
     352              :             request_size - header_size);
     353            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     354              :                          (const uint8_t *)request + header_size, message_size);
     355            1 :         m_libspdm_local_buffer_size += message_size;
     356            1 :         return LIBSPDM_STATUS_SUCCESS;
     357            1 :     case 0x21:
     358            1 :         m_libspdm_local_buffer_size = 0;
     359            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     360              :             spdm_context, (const uint8_t *)request + header_size,
     361              :             request_size - header_size);
     362            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     363              :                          (const uint8_t *)request + header_size, message_size);
     364            1 :         m_libspdm_local_buffer_size += message_size;
     365            1 :         return LIBSPDM_STATUS_SUCCESS;
     366            1 :     case 0x22:
     367            1 :         m_libspdm_local_buffer_size = 0;
     368            1 :         message_size = libspdm_test_get_key_exchange_request_size(
     369              :             spdm_context, (const uint8_t *)request + header_size,
     370              :             request_size - header_size);
     371            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     372              :                          (const uint8_t *)request + header_size, message_size);
     373            1 :         m_libspdm_local_buffer_size += message_size;
     374            1 :         return LIBSPDM_STATUS_SUCCESS;
     375            0 :     default:
     376            0 :         return LIBSPDM_STATUS_SEND_FAIL;
     377              :     }
     378              : }
     379              : 
     380           52 : static libspdm_return_t receive_message(
     381              :     void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
     382              : {
     383              :     libspdm_test_context_t *spdm_test_context;
     384              : 
     385           52 :     spdm_test_context = libspdm_get_test_context();
     386           52 :     switch (spdm_test_context->case_id) {
     387            0 :     case 0x1:
     388            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
     389              : 
     390            1 :     case 0x2: {
     391              :         spdm_key_exchange_response_t *spdm_response;
     392              :         size_t dhe_key_size;
     393              :         uint32_t hash_size;
     394              :         size_t signature_size;
     395              :         uint32_t hmac_size;
     396              :         uint8_t *ptr;
     397              :         void *dhe_context;
     398              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
     399              :         size_t final_key_size;
     400              :         size_t opaque_key_exchange_rsp_size;
     401              :         void *data;
     402              :         size_t data_size;
     403              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     404              :         uint8_t *cert_buffer;
     405              :         size_t cert_buffer_size;
     406              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
     407              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
     408              :         uint8_t bin_str0[128];
     409              :         size_t bin_str0_size;
     410              :         uint8_t bin_str2[128];
     411              :         size_t bin_str2_size;
     412              :         uint8_t bin_str7[128];
     413              :         size_t bin_str7_size;
     414              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
     415              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
     416              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
     417              :         size_t spdm_response_size;
     418              :         size_t transport_header_size;
     419              : 
     420              :         ((libspdm_context_t *)spdm_context)
     421            1 :         ->connection_info.algorithm.base_asym_algo =
     422              :             m_libspdm_use_asym_algo;
     423              :         ((libspdm_context_t *)spdm_context)
     424            1 :         ->connection_info.algorithm.base_hash_algo =
     425              :             m_libspdm_use_hash_algo;
     426              :         ((libspdm_context_t *)spdm_context)
     427            1 :         ->connection_info.algorithm.dhe_named_group =
     428              :             m_libspdm_use_dhe_algo;
     429              :         ((libspdm_context_t *)spdm_context)
     430            1 :         ->connection_info.algorithm.measurement_hash_algo =
     431              :             m_libspdm_use_measurement_hash_algo;
     432            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     433            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     434            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     435            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     436            1 :         opaque_key_exchange_rsp_size =
     437            1 :             libspdm_get_opaque_data_version_selection_data_size(
     438              :                 spdm_context);
     439            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
     440            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
     441            1 :                              opaque_key_exchange_rsp_size + signature_size +
     442              :                              hmac_size;
     443            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     444            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     445              : 
     446            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     447            1 :         spdm_response->header.request_response_code =
     448              :             SPDM_KEY_EXCHANGE_RSP;
     449            1 :         spdm_response->header.param1 = 0;
     450            1 :         spdm_response->rsp_session_id =
     451            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
     452            1 :         spdm_response->mut_auth_requested = 0;
     453            1 :         spdm_response->req_slot_id_param = 0;
     454            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
     455            1 :                                   spdm_response->random_data);
     456            1 :         ptr = (void *)(spdm_response + 1);
     457            1 :         dhe_context = libspdm_dhe_new(
     458            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     459              :                 m_libspdm_use_dhe_algo,
     460              :                 true);
     461            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
     462              :                                  &dhe_key_size);
     463            1 :         final_key_size = sizeof(final_key);
     464            1 :         libspdm_dhe_compute_key(
     465              :             m_libspdm_use_dhe_algo, dhe_context,
     466            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
     467              :             sizeof(spdm_key_exchange_request_t),
     468              :             dhe_key_size, final_key, &final_key_size);
     469            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     470            1 :         ptr += dhe_key_size;
     471              :         /* libspdm_zero_mem (ptr, hash_size);
     472              :          * ptr += hash_size;*/
     473            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
     474            1 :         ptr += sizeof(uint16_t);
     475            1 :         libspdm_build_opaque_data_version_selection_data(
     476              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
     477              :                 &opaque_key_exchange_rsp_size, ptr);
     478            1 :         ptr += opaque_key_exchange_rsp_size;
     479            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     480              :                                                         m_libspdm_use_asym_algo, &data,
     481              :                                                         &data_size, NULL, NULL);
     482            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     483              :                          sizeof(m_libspdm_local_buffer)
     484            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     485              :                             m_libspdm_local_buffer),
     486            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
     487            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
     488            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     489              :                        m_libspdm_local_buffer_size));
     490            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     491            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
     492            1 :         cert_buffer = (uint8_t *)data;
     493            1 :         cert_buffer_size = data_size;
     494            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
     495              :                          cert_buffer_hash);
     496              :         /* transcript.message_a size is 0*/
     497            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
     498            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
     499              :                                       m_libspdm_local_buffer_size);
     500            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     501              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
     502            1 :         free(data);
     503            1 :         libspdm_responder_data_sign(
     504              :             spdm_context,
     505            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     506              :                 SPDM_KEY_EXCHANGE_RSP,
     507              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     508            1 :                 false, libspdm_get_managed_buffer(&th_curr),
     509              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
     510              :                 &signature_size);
     511            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     512              :                          sizeof(m_libspdm_local_buffer)
     513            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     514              :                             m_libspdm_local_buffer),
     515              :                          ptr, signature_size);
     516            1 :         m_libspdm_local_buffer_size += signature_size;
     517            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
     518            1 :         ptr += signature_size;
     519            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     520              :                          libspdm_get_managed_buffer_size(&th_curr),
     521              :                          th_curr_hash_data);
     522            1 :         bin_str0_size = sizeof(bin_str0);
     523            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     524              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
     525            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
     526              :                            &bin_str0_size);
     527            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
     528              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
     529            1 :         bin_str2_size = sizeof(bin_str2);
     530            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     531              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
     532            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
     533              :                            bin_str2, &bin_str2_size);
     534            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
     535              :                             bin_str2, bin_str2_size,
     536              :                             response_handshake_secret, hash_size);
     537            1 :         bin_str7_size = sizeof(bin_str7);
     538            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     539              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
     540            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
     541              :                            &bin_str7_size);
     542            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
     543              :                             hash_size, bin_str7, bin_str7_size,
     544              :                             response_finished_key, hash_size);
     545            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     546              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
     547            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
     548              :                          response_finished_key, hash_size, ptr);
     549            1 :         ptr += hmac_size;
     550              : 
     551            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     552              :                                               false, spdm_response_size,
     553              :                                               spdm_response, response_size,
     554              :                                               response);
     555              :     }
     556            1 :         return LIBSPDM_STATUS_SUCCESS;
     557              : 
     558            0 :     case 0x3: {
     559              :         spdm_key_exchange_response_t *spdm_response;
     560              :         size_t dhe_key_size;
     561              :         uint32_t hash_size;
     562              :         size_t signature_size;
     563              :         uint32_t hmac_size;
     564              :         uint8_t *ptr;
     565              :         void *dhe_context;
     566              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
     567              :         size_t final_key_size;
     568              :         size_t opaque_key_exchange_rsp_size;
     569              :         void *data;
     570              :         size_t data_size;
     571              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     572              :         uint8_t *cert_buffer;
     573              :         size_t cert_buffer_size;
     574              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
     575              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
     576              :         uint8_t bin_str0[128];
     577              :         size_t bin_str0_size;
     578              :         uint8_t bin_str2[128];
     579              :         size_t bin_str2_size;
     580              :         uint8_t bin_str7[128];
     581              :         size_t bin_str7_size;
     582              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
     583              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
     584              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
     585              :         size_t spdm_response_size;
     586              :         size_t transport_header_size;
     587              : 
     588              :         ((libspdm_context_t *)spdm_context)
     589            0 :         ->connection_info.algorithm.base_asym_algo =
     590              :             m_libspdm_use_asym_algo;
     591              :         ((libspdm_context_t *)spdm_context)
     592            0 :         ->connection_info.algorithm.base_hash_algo =
     593              :             m_libspdm_use_hash_algo;
     594              :         ((libspdm_context_t *)spdm_context)
     595            0 :         ->connection_info.algorithm.dhe_named_group =
     596              :             m_libspdm_use_dhe_algo;
     597              :         ((libspdm_context_t *)spdm_context)
     598            0 :         ->connection_info.algorithm.measurement_hash_algo =
     599              :             m_libspdm_use_measurement_hash_algo;
     600            0 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     601            0 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     602            0 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     603            0 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     604            0 :         opaque_key_exchange_rsp_size =
     605            0 :             libspdm_get_opaque_data_version_selection_data_size(
     606              :                 spdm_context);
     607            0 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
     608            0 :                              dhe_key_size + 0 + sizeof(uint16_t) +
     609            0 :                              opaque_key_exchange_rsp_size + signature_size +
     610              :                              hmac_size;
     611            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     612            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     613              : 
     614            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     615            0 :         spdm_response->header.request_response_code =
     616              :             SPDM_KEY_EXCHANGE_RSP;
     617            0 :         spdm_response->header.param1 = 0;
     618            0 :         spdm_response->rsp_session_id =
     619            0 :             libspdm_allocate_rsp_session_id(spdm_context, false);
     620            0 :         spdm_response->mut_auth_requested = 0;
     621            0 :         spdm_response->req_slot_id_param = 0;
     622            0 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
     623            0 :                                   spdm_response->random_data);
     624            0 :         ptr = (void *)(spdm_response + 1);
     625            0 :         dhe_context = libspdm_dhe_new(
     626            0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     627              :                 m_libspdm_use_dhe_algo,
     628              :                 true);
     629            0 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
     630              :                                  &dhe_key_size);
     631            0 :         final_key_size = sizeof(final_key);
     632            0 :         libspdm_dhe_compute_key(
     633              :             m_libspdm_use_dhe_algo, dhe_context,
     634            0 :             (uint8_t *)&m_libspdm_local_buffer[0] +
     635              :             sizeof(spdm_key_exchange_request_t),
     636              :             dhe_key_size, final_key, &final_key_size);
     637            0 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     638            0 :         ptr += dhe_key_size;
     639              :         /* libspdm_zero_mem (ptr, hash_size);
     640              :          * ptr += hash_size;*/
     641            0 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
     642            0 :         ptr += sizeof(uint16_t);
     643            0 :         libspdm_build_opaque_data_version_selection_data(
     644              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
     645              :                 &opaque_key_exchange_rsp_size, ptr);
     646            0 :         ptr += opaque_key_exchange_rsp_size;
     647            0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     648              :                                                         m_libspdm_use_asym_algo, &data,
     649              :                                                         &data_size, NULL, NULL);
     650            0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     651              :                          sizeof(m_libspdm_local_buffer)
     652            0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     653              :                             m_libspdm_local_buffer),
     654            0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
     655            0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
     656            0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     657              :                        m_libspdm_local_buffer_size));
     658            0 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     659            0 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
     660            0 :         cert_buffer = (uint8_t *)data;
     661            0 :         cert_buffer_size = data_size;
     662            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
     663              :                          cert_buffer_hash);
     664              :         /* transcript.message_a size is 0*/
     665            0 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
     666            0 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
     667              :                                       m_libspdm_local_buffer_size);
     668            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     669              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
     670            0 :         free(data);
     671            0 :         libspdm_responder_data_sign(
     672              :             spdm_context,
     673            0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     674              :                 SPDM_KEY_EXCHANGE_RSP,
     675              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     676            0 :                 false, libspdm_get_managed_buffer(&th_curr),
     677              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
     678              :                 &signature_size);
     679            0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     680              :                          sizeof(m_libspdm_local_buffer)
     681            0 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     682              :                             m_libspdm_local_buffer),
     683              :                          ptr, signature_size);
     684            0 :         m_libspdm_local_buffer_size += signature_size;
     685            0 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
     686            0 :         ptr += signature_size;
     687            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     688              :                          libspdm_get_managed_buffer_size(&th_curr),
     689              :                          th_curr_hash_data);
     690            0 :         bin_str0_size = sizeof(bin_str0);
     691            0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     692              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
     693            0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
     694              :                            &bin_str0_size);
     695            0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
     696              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
     697            0 :         bin_str2_size = sizeof(bin_str2);
     698            0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     699              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
     700            0 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
     701              :                            bin_str2, &bin_str2_size);
     702            0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
     703              :                             bin_str2, bin_str2_size,
     704              :                             response_handshake_secret, hash_size);
     705            0 :         bin_str7_size = sizeof(bin_str7);
     706            0 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     707              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
     708            0 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
     709              :                            &bin_str7_size);
     710            0 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
     711              :                             hash_size, bin_str7, bin_str7_size,
     712              :                             response_finished_key, hash_size);
     713            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     714              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
     715            0 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
     716              :                          response_finished_key, hash_size, ptr);
     717            0 :         ptr += hmac_size;
     718              : 
     719            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     720              :                                               false, spdm_response_size,
     721              :                                               spdm_response, response_size,
     722              :                                               response);
     723              :     }
     724            0 :         return LIBSPDM_STATUS_SUCCESS;
     725              : 
     726            1 :     case 0x4: {
     727              :         spdm_error_response_t *spdm_response;
     728              :         size_t spdm_response_size;
     729              :         size_t transport_header_size;
     730              : 
     731            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     732            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     733            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     734              : 
     735            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     736            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     737            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
     738            1 :         spdm_response->header.param2 = 0;
     739              : 
     740            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     741              :                                               false, spdm_response_size,
     742              :                                               spdm_response,
     743              :                                               response_size, response);
     744              :     }
     745            1 :         return LIBSPDM_STATUS_SUCCESS;
     746              : 
     747            1 :     case 0x5: {
     748              :         spdm_error_response_t *spdm_response;
     749              :         size_t spdm_response_size;
     750              :         size_t transport_header_size;
     751              : 
     752            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     753            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     754            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     755              : 
     756            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     757            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     758            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     759            1 :         spdm_response->header.param2 = 0;
     760              : 
     761            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     762              :                                               false, spdm_response_size,
     763              :                                               spdm_response,
     764              :                                               response_size, response);
     765              :     }
     766            1 :         return LIBSPDM_STATUS_SUCCESS;
     767              : 
     768            2 :     case 0x6: {
     769              :         static size_t sub_index1 = 0;
     770            2 :         if (sub_index1 == 0) {
     771              :             spdm_error_response_t *spdm_response;
     772              :             size_t spdm_response_size;
     773              :             size_t transport_header_size;
     774              : 
     775            1 :             spdm_response_size = sizeof(spdm_error_response_t);
     776            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     777            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     778              : 
     779            1 :             spdm_response->header.spdm_version =
     780              :                 SPDM_MESSAGE_VERSION_11;
     781            1 :             spdm_response->header.request_response_code = SPDM_ERROR;
     782            1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     783            1 :             spdm_response->header.param2 = 0;
     784              : 
     785            1 :             libspdm_transport_test_encode_message(
     786              :                 spdm_context, NULL, false, false,
     787              :                 spdm_response_size, spdm_response,
     788              :                 response_size, response);
     789            1 :             sub_index1++;
     790            1 :         } else if (sub_index1 == 1) {
     791              :             spdm_key_exchange_response_t *spdm_response;
     792              :             size_t dhe_key_size;
     793              :             uint32_t hash_size;
     794              :             size_t signature_size;
     795              :             uint32_t hmac_size;
     796              :             uint8_t *ptr;
     797              :             void *dhe_context;
     798              :             uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
     799              :             size_t final_key_size;
     800              :             size_t opaque_key_exchange_rsp_size;
     801              :             void *data;
     802              :             size_t data_size;
     803              :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     804              :             uint8_t *cert_buffer;
     805              :             size_t cert_buffer_size;
     806              :             uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
     807              :             uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
     808              :             uint8_t bin_str0[128];
     809              :             size_t bin_str0_size;
     810              :             uint8_t bin_str2[128];
     811              :             size_t bin_str2_size;
     812              :             uint8_t bin_str7[128];
     813              :             size_t bin_str7_size;
     814              :             uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
     815              :             uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
     816              :             uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
     817              :             size_t spdm_response_size;
     818              :             size_t transport_header_size;
     819              : 
     820              :             ((libspdm_context_t *)spdm_context)
     821            1 :             ->connection_info.algorithm.base_asym_algo =
     822              :                 m_libspdm_use_asym_algo;
     823              :             ((libspdm_context_t *)spdm_context)
     824            1 :             ->connection_info.algorithm.base_hash_algo =
     825              :                 m_libspdm_use_hash_algo;
     826              :             ((libspdm_context_t *)spdm_context)
     827            1 :             ->connection_info.algorithm.dhe_named_group =
     828              :                 m_libspdm_use_dhe_algo;
     829              :             ((libspdm_context_t *)spdm_context)
     830              :             ->connection_info.algorithm
     831            1 :             .measurement_hash_algo =
     832              :                 m_libspdm_use_measurement_hash_algo;
     833            1 :             signature_size =
     834            1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     835            1 :             hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     836            1 :             hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     837            1 :             dhe_key_size =
     838            1 :                 libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
     839            1 :             opaque_key_exchange_rsp_size =
     840            1 :                 libspdm_get_opaque_data_version_selection_data_size(
     841              :                     spdm_context);
     842            1 :             spdm_response_size = sizeof(spdm_key_exchange_response_t) +
     843            1 :                                  dhe_key_size + 0 + sizeof(uint16_t) +
     844            1 :                                  opaque_key_exchange_rsp_size +
     845            1 :                                  signature_size + hmac_size;
     846            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     847            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     848              : 
     849            1 :             spdm_response->header.spdm_version =
     850              :                 SPDM_MESSAGE_VERSION_11;
     851            1 :             spdm_response->header.request_response_code =
     852              :                 SPDM_KEY_EXCHANGE_RSP;
     853            1 :             spdm_response->header.param1 = 0;
     854            1 :             spdm_response->rsp_session_id =
     855            1 :                 libspdm_allocate_rsp_session_id(spdm_context, false);
     856            1 :             spdm_response->mut_auth_requested = 0;
     857            1 :             spdm_response->req_slot_id_param = 0;
     858            1 :             libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
     859            1 :                                       spdm_response->random_data);
     860            1 :             ptr = (void *)(spdm_response + 1);
     861            1 :             dhe_context = libspdm_dhe_new(
     862            1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     863              :                     m_libspdm_use_dhe_algo, true);
     864            1 :             libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
     865              :                                      &dhe_key_size);
     866            1 :             final_key_size = sizeof(final_key);
     867            1 :             libspdm_dhe_compute_key(
     868              :                 m_libspdm_use_dhe_algo, dhe_context,
     869            1 :                 (uint8_t *)&m_libspdm_local_buffer[0] +
     870              :                 sizeof(spdm_key_exchange_request_t),
     871              :                 dhe_key_size, final_key, &final_key_size);
     872            1 :             libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
     873            1 :             ptr += dhe_key_size;
     874              :             /* libspdm_zero_mem (ptr, hash_size);
     875              :              * ptr += hash_size;*/
     876            1 :             *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
     877            1 :             ptr += sizeof(uint16_t);
     878            1 :             libspdm_build_opaque_data_version_selection_data(
     879              :                 spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
     880              :                     &opaque_key_exchange_rsp_size, ptr);
     881            1 :             ptr += opaque_key_exchange_rsp_size;
     882            1 :             libspdm_read_responder_public_certificate_chain(
     883              :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
     884              :                 &data_size, NULL, NULL);
     885            1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     886              :                              sizeof(m_libspdm_local_buffer)
     887            1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     888              :                                 m_libspdm_local_buffer),
     889            1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
     890            1 :             m_libspdm_local_buffer_size +=
     891            1 :                 ((size_t)ptr - (size_t)spdm_response);
     892            1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     893              :                            m_libspdm_local_buffer_size));
     894            1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     895            1 :             libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
     896            1 :             cert_buffer = (uint8_t *)data;
     897            1 :             cert_buffer_size = data_size;
     898            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
     899              :                              cert_buffer_size, cert_buffer_hash);
     900              :             /* transcript.message_a size is 0*/
     901            1 :             libspdm_append_managed_buffer(&th_curr, cert_buffer_hash,
     902              :                                           hash_size);
     903            1 :             libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
     904              :                                           m_libspdm_local_buffer_size);
     905            2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
     906            1 :                              libspdm_get_managed_buffer(&th_curr),
     907              :                              libspdm_get_managed_buffer_size(&th_curr),
     908              :                              hash_data);
     909            1 :             free(data);
     910            1 :             libspdm_responder_data_sign(
     911              :                 spdm_context,
     912            1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     913              :                     SPDM_KEY_EXCHANGE_RSP,
     914              :                     m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     915            1 :                     false, libspdm_get_managed_buffer(&th_curr),
     916              :                     libspdm_get_managed_buffer_size(&th_curr), ptr,
     917              :                     &signature_size);
     918            1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     919              :                              sizeof(m_libspdm_local_buffer)
     920            1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     921              :                                 m_libspdm_local_buffer),
     922              :                              ptr, signature_size);
     923            1 :             m_libspdm_local_buffer_size += signature_size;
     924            1 :             libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
     925            1 :             ptr += signature_size;
     926            2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
     927            1 :                              libspdm_get_managed_buffer(&th_curr),
     928              :                              libspdm_get_managed_buffer_size(&th_curr),
     929              :                              th_curr_hash_data);
     930            1 :             bin_str0_size = sizeof(bin_str0);
     931            1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     932              :                                SPDM_BIN_STR_0_LABEL,
     933              :                                sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
     934            1 :                                (uint16_t)hash_size, hash_size, bin_str0,
     935              :                                &bin_str0_size);
     936            1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
     937              :                              m_libspdm_zero_filled_buffer, hash_size, handshake_secret);
     938            1 :             bin_str2_size = sizeof(bin_str2);
     939            1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     940              :                                SPDM_BIN_STR_2_LABEL,
     941              :                                sizeof(SPDM_BIN_STR_2_LABEL) - 1,
     942            1 :                                th_curr_hash_data, (uint16_t)hash_size,
     943              :                                hash_size, bin_str2, &bin_str2_size);
     944            1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret,
     945              :                                 hash_size, bin_str2, bin_str2_size,
     946              :                                 response_handshake_secret, hash_size);
     947            1 :             bin_str7_size = sizeof(bin_str7);
     948            1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
     949              :                                SPDM_BIN_STR_7_LABEL,
     950              :                                sizeof(SPDM_BIN_STR_7_LABEL) - 1, NULL,
     951            1 :                                (uint16_t)hash_size, hash_size, bin_str7,
     952              :                                &bin_str7_size);
     953            1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo,
     954              :                                 response_handshake_secret, hash_size,
     955              :                                 bin_str7, bin_str7_size,
     956              :                                 response_finished_key, hash_size);
     957            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
     958              :                              libspdm_get_managed_buffer_size(&th_curr), hash_data);
     959            1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
     960              :                              response_finished_key, hash_size, ptr);
     961            1 :             ptr += hmac_size;
     962              : 
     963            1 :             libspdm_transport_test_encode_message(
     964              :                 spdm_context, NULL, false, false, spdm_response_size,
     965              :                 spdm_response, response_size, response);
     966              :         }
     967              :     }
     968            2 :         return LIBSPDM_STATUS_SUCCESS;
     969              : 
     970            1 :     case 0x7: {
     971              :         spdm_error_response_t *spdm_response;
     972              :         size_t spdm_response_size;
     973              :         size_t transport_header_size;
     974              : 
     975            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     976            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     977            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     978              : 
     979            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     980            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     981            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
     982            1 :         spdm_response->header.param2 = 0;
     983              : 
     984            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     985              :                                               false, spdm_response_size,
     986              :                                               spdm_response,
     987              :                                               response_size, response);
     988              :     }
     989            1 :         return LIBSPDM_STATUS_SUCCESS;
     990              : 
     991            2 :     case 0x8: {
     992              :         spdm_error_response_data_response_not_ready_t *spdm_response;
     993              :         size_t spdm_response_size;
     994              :         size_t transport_header_size;
     995              : 
     996            2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
     997            2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     998            2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     999              : 
    1000            2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1001            2 :         spdm_response->header.request_response_code = SPDM_ERROR;
    1002            2 :         spdm_response->header.param1 =
    1003              :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
    1004            2 :         spdm_response->header.param2 = 0;
    1005            2 :         spdm_response->extend_error_data.rd_exponent = 1;
    1006            2 :         spdm_response->extend_error_data.rd_tm = 2;
    1007            2 :         spdm_response->extend_error_data.request_code =
    1008              :             SPDM_KEY_EXCHANGE;
    1009            2 :         spdm_response->extend_error_data.token = 0;
    1010              : 
    1011            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1012              :                                               false, spdm_response_size,
    1013              :                                               spdm_response,
    1014              :                                               response_size, response);
    1015              :     }
    1016            2 :         return LIBSPDM_STATUS_SUCCESS;
    1017              : 
    1018            2 :     case 0x9: {
    1019              :         static size_t sub_index2 = 0;
    1020            2 :         if (sub_index2 == 0) {
    1021              :             spdm_error_response_data_response_not_ready_t
    1022              :             *spdm_response;
    1023              :             size_t spdm_response_size;
    1024              :             size_t transport_header_size;
    1025              : 
    1026            1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
    1027            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1028            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1029              : 
    1030            1 :             spdm_response->header.spdm_version =
    1031              :                 SPDM_MESSAGE_VERSION_11;
    1032            1 :             spdm_response->header.request_response_code = SPDM_ERROR;
    1033            1 :             spdm_response->header.param1 =
    1034              :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
    1035            1 :             spdm_response->header.param2 = 0;
    1036            1 :             spdm_response->extend_error_data.rd_exponent = 1;
    1037            1 :             spdm_response->extend_error_data.rd_tm = 2;
    1038            1 :             spdm_response->extend_error_data.request_code =
    1039              :                 SPDM_KEY_EXCHANGE;
    1040            1 :             spdm_response->extend_error_data.token = 1;
    1041              : 
    1042            1 :             libspdm_transport_test_encode_message(
    1043              :                 spdm_context, NULL, false, false,
    1044              :                 spdm_response_size, spdm_response,
    1045              :                 response_size, response);
    1046            1 :             sub_index2++;
    1047            1 :         } else if (sub_index2 == 1) {
    1048              :             spdm_key_exchange_response_t *spdm_response;
    1049              :             size_t dhe_key_size;
    1050              :             uint32_t hash_size;
    1051              :             size_t signature_size;
    1052              :             uint32_t hmac_size;
    1053              :             uint8_t *ptr;
    1054              :             void *dhe_context;
    1055              :             uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    1056              :             size_t final_key_size;
    1057              :             size_t opaque_key_exchange_rsp_size;
    1058              :             void *data;
    1059              :             size_t data_size;
    1060              :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1061              :             uint8_t *cert_buffer;
    1062              :             size_t cert_buffer_size;
    1063              :             uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1064              :             uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1065              :             uint8_t bin_str0[128];
    1066              :             size_t bin_str0_size;
    1067              :             uint8_t bin_str2[128];
    1068              :             size_t bin_str2_size;
    1069              :             uint8_t bin_str7[128];
    1070              :             size_t bin_str7_size;
    1071              :             uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1072              :             uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1073              :             uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1074              :             size_t spdm_response_size;
    1075              :             size_t transport_header_size;
    1076              : 
    1077              :             ((libspdm_context_t *)spdm_context)
    1078            1 :             ->connection_info.algorithm.base_asym_algo =
    1079              :                 m_libspdm_use_asym_algo;
    1080              :             ((libspdm_context_t *)spdm_context)
    1081            1 :             ->connection_info.algorithm.base_hash_algo =
    1082              :                 m_libspdm_use_hash_algo;
    1083              :             ((libspdm_context_t *)spdm_context)
    1084            1 :             ->connection_info.algorithm.dhe_named_group =
    1085              :                 m_libspdm_use_dhe_algo;
    1086              :             ((libspdm_context_t *)spdm_context)
    1087              :             ->connection_info.algorithm
    1088            1 :             .measurement_hash_algo =
    1089              :                 m_libspdm_use_measurement_hash_algo;
    1090            1 :             signature_size =
    1091            1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1092            1 :             hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1093            1 :             hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1094            1 :             dhe_key_size =
    1095            1 :                 libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1096            1 :             opaque_key_exchange_rsp_size =
    1097            1 :                 libspdm_get_opaque_data_version_selection_data_size(
    1098              :                     spdm_context);
    1099            1 :             spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    1100            1 :                                  dhe_key_size + 0 + sizeof(uint16_t) +
    1101            1 :                                  opaque_key_exchange_rsp_size +
    1102            1 :                                  signature_size + hmac_size;
    1103            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1104            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1105              : 
    1106            1 :             spdm_response->header.spdm_version =
    1107              :                 SPDM_MESSAGE_VERSION_11;
    1108            1 :             spdm_response->header.request_response_code =
    1109              :                 SPDM_KEY_EXCHANGE_RSP;
    1110            1 :             spdm_response->header.param1 = 0;
    1111            1 :             spdm_response->rsp_session_id =
    1112            1 :                 libspdm_allocate_rsp_session_id(spdm_context, false);
    1113            1 :             spdm_response->mut_auth_requested = 0;
    1114            1 :             spdm_response->req_slot_id_param = 0;
    1115            1 :             libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    1116            1 :                                       spdm_response->random_data);
    1117            1 :             ptr = (void *)(spdm_response + 1);
    1118            1 :             dhe_context = libspdm_dhe_new(
    1119            1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1120              :                     m_libspdm_use_dhe_algo, true);
    1121            1 :             libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    1122              :                                      &dhe_key_size);
    1123            1 :             final_key_size = sizeof(final_key);
    1124            1 :             libspdm_dhe_compute_key(
    1125              :                 m_libspdm_use_dhe_algo, dhe_context,
    1126            1 :                 (uint8_t *)&m_libspdm_local_buffer[0] +
    1127              :                 sizeof(spdm_key_exchange_request_t),
    1128              :                 dhe_key_size, final_key, &final_key_size);
    1129            1 :             libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1130            1 :             ptr += dhe_key_size;
    1131              :             /* libspdm_zero_mem (ptr, hash_size);
    1132              :              * ptr += hash_size;*/
    1133            1 :             *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    1134            1 :             ptr += sizeof(uint16_t);
    1135            1 :             libspdm_build_opaque_data_version_selection_data(
    1136              :                 spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1137              :                     &opaque_key_exchange_rsp_size, ptr);
    1138            1 :             ptr += opaque_key_exchange_rsp_size;
    1139            1 :             libspdm_read_responder_public_certificate_chain(
    1140              :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
    1141              :                 &data_size, NULL, NULL);
    1142            1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1143              :                              sizeof(m_libspdm_local_buffer)
    1144            1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1145              :                                 m_libspdm_local_buffer),
    1146            1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
    1147            1 :             m_libspdm_local_buffer_size +=
    1148            1 :                 ((size_t)ptr - (size_t)spdm_response);
    1149            1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1150              :                            m_libspdm_local_buffer_size));
    1151            1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1152            1 :             libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1153            1 :             cert_buffer = (uint8_t *)data;
    1154            1 :             cert_buffer_size = data_size;
    1155            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
    1156              :                              cert_buffer_size, cert_buffer_hash);
    1157              :             /* transcript.message_a size is 0*/
    1158            1 :             libspdm_append_managed_buffer(&th_curr, cert_buffer_hash,
    1159              :                                           hash_size);
    1160            1 :             libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1161              :                                           m_libspdm_local_buffer_size);
    1162            2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
    1163            1 :                              libspdm_get_managed_buffer(&th_curr),
    1164              :                              libspdm_get_managed_buffer_size(&th_curr),
    1165              :                              hash_data);
    1166            1 :             free(data);
    1167            1 :             libspdm_responder_data_sign(
    1168              :                 spdm_context,
    1169            1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1170              :                     SPDM_KEY_EXCHANGE_RSP,
    1171              :                     m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1172            1 :                     false, libspdm_get_managed_buffer(&th_curr),
    1173              :                     libspdm_get_managed_buffer_size(&th_curr), ptr,
    1174              :                     &signature_size);
    1175            1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1176              :                              sizeof(m_libspdm_local_buffer)
    1177            1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1178              :                                 m_libspdm_local_buffer),
    1179              :                              ptr, signature_size);
    1180            1 :             m_libspdm_local_buffer_size += signature_size;
    1181            1 :             libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    1182            1 :             ptr += signature_size;
    1183            2 :             libspdm_hash_all(m_libspdm_use_hash_algo,
    1184            1 :                              libspdm_get_managed_buffer(&th_curr),
    1185              :                              libspdm_get_managed_buffer_size(&th_curr),
    1186              :                              th_curr_hash_data);
    1187            1 :             bin_str0_size = sizeof(bin_str0);
    1188            1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1189              :                                SPDM_BIN_STR_0_LABEL,
    1190              :                                sizeof(SPDM_BIN_STR_0_LABEL) - 1, NULL,
    1191            1 :                                (uint16_t)hash_size, hash_size, bin_str0,
    1192              :                                &bin_str0_size);
    1193            1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    1194              :                              m_libspdm_zero_filled_buffer, hash_size, handshake_secret);
    1195            1 :             bin_str2_size = sizeof(bin_str2);
    1196            1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1197              :                                SPDM_BIN_STR_2_LABEL,
    1198              :                                sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1199            1 :                                th_curr_hash_data, (uint16_t)hash_size,
    1200              :                                hash_size, bin_str2, &bin_str2_size);
    1201            1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret,
    1202              :                                 hash_size, bin_str2, bin_str2_size,
    1203              :                                 response_handshake_secret, hash_size);
    1204            1 :             bin_str7_size = sizeof(bin_str7);
    1205            1 :             libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1206              :                                SPDM_BIN_STR_7_LABEL,
    1207              :                                sizeof(SPDM_BIN_STR_7_LABEL) - 1, NULL,
    1208            1 :                                (uint16_t)hash_size, hash_size, bin_str7,
    1209              :                                &bin_str7_size);
    1210            1 :             libspdm_hkdf_expand(m_libspdm_use_hash_algo,
    1211              :                                 response_handshake_secret, hash_size,
    1212              :                                 bin_str7, bin_str7_size,
    1213              :                                 response_finished_key, hash_size);
    1214            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1215              :                              libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1216            1 :             libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1217              :                              response_finished_key, hash_size, ptr);
    1218            1 :             ptr += hmac_size;
    1219              : 
    1220            1 :             libspdm_transport_test_encode_message(
    1221              :                 spdm_context, NULL, false, false, spdm_response_size,
    1222              :                 spdm_response, response_size, response);
    1223              :         }
    1224              :     }
    1225            2 :         return LIBSPDM_STATUS_SUCCESS;
    1226              : 
    1227           18 :     case 0xA:
    1228              :     {
    1229              :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
    1230              : 
    1231              :         spdm_error_response_t *spdm_response;
    1232              :         size_t spdm_response_size;
    1233              :         size_t transport_header_size;
    1234              : 
    1235           18 :         spdm_response_size = sizeof(spdm_error_response_t);
    1236           18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1237           18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1238              : 
    1239           18 :         if(error_code <= 0xff) {
    1240           18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
    1241           18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1242           18 :             spdm_response->header.request_response_code = SPDM_ERROR;
    1243           18 :             spdm_response->header.param1 = (uint8_t) error_code;
    1244           18 :             spdm_response->header.param2 = 0;
    1245              : 
    1246           18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
    1247              :                                                    spdm_response_size, spdm_response,
    1248              :                                                    response_size, response);
    1249              :         }
    1250              : 
    1251           18 :         error_code++;
    1252           18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
    1253            1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
    1254              :         }
    1255           18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
    1256            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
    1257              :         }
    1258           18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
    1259            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
    1260              :         }
    1261              :     }
    1262           18 :         return LIBSPDM_STATUS_SUCCESS;
    1263            1 :     case 0xB: {
    1264              :         spdm_key_exchange_response_t *spdm_response;
    1265              :         size_t dhe_key_size;
    1266              :         uint32_t hash_size;
    1267              :         size_t signature_size;
    1268              :         uint32_t hmac_size;
    1269              :         uint8_t *ptr;
    1270              :         void *dhe_context;
    1271              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    1272              :         size_t final_key_size;
    1273              :         size_t opaque_key_exchange_rsp_size;
    1274              :         void *data;
    1275              :         size_t data_size;
    1276              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1277              :         uint8_t *cert_buffer;
    1278              :         size_t cert_buffer_size;
    1279              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1280              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1281              :         uint8_t bin_str0[128];
    1282              :         size_t bin_str0_size;
    1283              :         uint8_t bin_str2[128];
    1284              :         size_t bin_str2_size;
    1285              :         uint8_t bin_str7[128];
    1286              :         size_t bin_str7_size;
    1287              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1288              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1289              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1290              :         size_t spdm_response_size;
    1291              :         size_t transport_header_size;
    1292              : 
    1293              :         ((libspdm_context_t *)spdm_context)
    1294            1 :         ->connection_info.algorithm.base_asym_algo =
    1295              :             m_libspdm_use_asym_algo;
    1296              :         ((libspdm_context_t *)spdm_context)
    1297            1 :         ->connection_info.algorithm.base_hash_algo =
    1298              :             m_libspdm_use_hash_algo;
    1299              :         ((libspdm_context_t *)spdm_context)
    1300            1 :         ->connection_info.algorithm.dhe_named_group =
    1301              :             m_libspdm_use_dhe_algo;
    1302              :         ((libspdm_context_t *)spdm_context)
    1303            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1304              :             m_libspdm_use_measurement_hash_algo;
    1305            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1306            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1307            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1308            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1309            1 :         opaque_key_exchange_rsp_size =
    1310            1 :             libspdm_get_opaque_data_version_selection_data_size(
    1311              :                 spdm_context);
    1312            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    1313            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    1314            1 :                              opaque_key_exchange_rsp_size + signature_size +
    1315              :                              hmac_size;
    1316            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1317            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1318              : 
    1319            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1320            1 :         spdm_response->header.request_response_code =
    1321              :             SPDM_KEY_EXCHANGE_RSP;
    1322            1 :         spdm_response->header.param1 = 0;
    1323            1 :         spdm_response->rsp_session_id =
    1324            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    1325            1 :         spdm_response->mut_auth_requested = 0;
    1326            1 :         spdm_response->req_slot_id_param = 0;
    1327            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    1328            1 :                                   spdm_response->random_data);
    1329            1 :         ptr = (void *)(spdm_response + 1);
    1330            1 :         dhe_context = libspdm_dhe_new(
    1331            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1332              :                 m_libspdm_use_dhe_algo,
    1333              :                 true);
    1334            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    1335              :                                  &dhe_key_size);
    1336            1 :         final_key_size = sizeof(final_key);
    1337            1 :         libspdm_dhe_compute_key(
    1338              :             m_libspdm_use_dhe_algo, dhe_context,
    1339            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    1340              :             sizeof(spdm_key_exchange_request_t),
    1341              :             dhe_key_size, final_key, &final_key_size);
    1342            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1343            1 :         ptr += dhe_key_size;
    1344              :         /* libspdm_zero_mem (ptr, hash_size);
    1345              :          * ptr += hash_size;*/
    1346            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    1347            1 :         ptr += sizeof(uint16_t);
    1348            1 :         libspdm_build_opaque_data_version_selection_data(
    1349              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1350              :                 &opaque_key_exchange_rsp_size, ptr);
    1351            1 :         ptr += opaque_key_exchange_rsp_size;
    1352            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1353              :                                                         m_libspdm_use_asym_algo, &data,
    1354              :                                                         &data_size, NULL, NULL);
    1355            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1356              :                          sizeof(m_libspdm_local_buffer)
    1357            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1358              :                             m_libspdm_local_buffer),
    1359            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1360            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1361            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1362              :                        m_libspdm_local_buffer_size));
    1363            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1364            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1365            1 :         cert_buffer = (uint8_t *)data;
    1366            1 :         cert_buffer_size = data_size;
    1367            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1368              :                          cert_buffer_hash);
    1369              :         /* transcript.message_a size is 0*/
    1370            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    1371            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1372              :                                       m_libspdm_local_buffer_size);
    1373            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1374              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1375            1 :         free(data);
    1376            1 :         libspdm_responder_data_sign(
    1377              :             spdm_context,
    1378            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1379              :                 SPDM_KEY_EXCHANGE_RSP,
    1380              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1381            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    1382              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    1383              :                 &signature_size);
    1384            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1385              :                          sizeof(m_libspdm_local_buffer)
    1386            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1387              :                             m_libspdm_local_buffer),
    1388              :                          ptr, signature_size);
    1389            1 :         m_libspdm_local_buffer_size += signature_size;
    1390            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    1391            1 :         ptr += signature_size;
    1392            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1393              :                          libspdm_get_managed_buffer_size(&th_curr),
    1394              :                          th_curr_hash_data);
    1395            1 :         bin_str0_size = sizeof(bin_str0);
    1396            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1397              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    1398            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    1399              :                            &bin_str0_size);
    1400            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    1401              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    1402            1 :         bin_str2_size = sizeof(bin_str2);
    1403            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1404              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1405            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    1406              :                            bin_str2, &bin_str2_size);
    1407            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    1408              :                             bin_str2, bin_str2_size,
    1409              :                             response_handshake_secret, hash_size);
    1410            1 :         bin_str7_size = sizeof(bin_str7);
    1411            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1412              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    1413            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1414              :                            &bin_str7_size);
    1415            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1416              :                             hash_size, bin_str7, bin_str7_size,
    1417              :                             response_finished_key, hash_size);
    1418            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1419              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1420            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1421              :                          response_finished_key, hash_size, ptr);
    1422            1 :         ptr += hmac_size;
    1423              : 
    1424            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1425              :                                               false, spdm_response_size,
    1426              :                                               spdm_response, response_size,
    1427              :                                               response);
    1428              :     }
    1429            1 :         return LIBSPDM_STATUS_SUCCESS;
    1430            1 :     case 0xC: {
    1431              :         spdm_key_exchange_response_t *spdm_response;
    1432              :         size_t dhe_key_size;
    1433              :         uint32_t hash_size;
    1434              :         uint32_t measurement_hash_size;
    1435              :         size_t signature_size;
    1436              :         uint32_t hmac_size;
    1437              :         uint8_t *ptr;
    1438              :         void *dhe_context;
    1439              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    1440              :         size_t final_key_size;
    1441              :         size_t opaque_key_exchange_rsp_size;
    1442              :         void *data;
    1443              :         size_t data_size;
    1444              :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1445              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1446              :         uint8_t *cert_buffer;
    1447              :         size_t cert_buffer_size;
    1448              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1449              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1450              :         uint8_t bin_str0[128];
    1451              :         size_t bin_str0_size;
    1452              :         uint8_t bin_str2[128];
    1453              :         size_t bin_str2_size;
    1454              :         uint8_t bin_str7[128];
    1455              :         size_t bin_str7_size;
    1456              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1457              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1458              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1459              :         size_t spdm_response_size;
    1460              :         size_t transport_header_size;
    1461              : 
    1462              :         ((libspdm_context_t *)spdm_context)
    1463            1 :         ->connection_info.algorithm.base_asym_algo =
    1464              :             m_libspdm_use_asym_algo;
    1465              :         ((libspdm_context_t *)spdm_context)
    1466            1 :         ->connection_info.algorithm.base_hash_algo =
    1467              :             m_libspdm_use_hash_algo;
    1468              :         ((libspdm_context_t *)spdm_context)
    1469            1 :         ->connection_info.algorithm.dhe_named_group =
    1470              :             m_libspdm_use_dhe_algo;
    1471              :         ((libspdm_context_t *)spdm_context)
    1472            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1473              :             m_libspdm_use_measurement_hash_algo;
    1474            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1475            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1476            1 :         measurement_hash_size = libspdm_get_hash_size(
    1477              :             m_libspdm_use_hash_algo);
    1478            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1479            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1480            1 :         opaque_key_exchange_rsp_size =
    1481            1 :             libspdm_get_opaque_data_version_selection_data_size(
    1482              :                 spdm_context);
    1483            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    1484            1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
    1485            1 :                              opaque_key_exchange_rsp_size + signature_size +
    1486              :                              hmac_size;
    1487            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1488            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1489            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    1490              : 
    1491            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1492            1 :         spdm_response->header.request_response_code =
    1493              :             SPDM_KEY_EXCHANGE_RSP;
    1494            1 :         spdm_response->header.param1 = 0;
    1495            1 :         spdm_response->rsp_session_id =
    1496            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    1497            1 :         spdm_response->mut_auth_requested = 0;
    1498            1 :         spdm_response->req_slot_id_param = 0;
    1499            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    1500            1 :                                   spdm_response->random_data);
    1501            1 :         ptr = (void *)(spdm_response + 1);
    1502            1 :         dhe_context = libspdm_dhe_new(
    1503            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1504              :                 m_libspdm_use_dhe_algo,
    1505              :                 true);
    1506            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    1507              :                                  &dhe_key_size);
    1508            1 :         final_key_size = sizeof(final_key);
    1509            1 :         libspdm_dhe_compute_key(
    1510              :             m_libspdm_use_dhe_algo, dhe_context,
    1511            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    1512              :             sizeof(spdm_key_exchange_request_t),
    1513              :             dhe_key_size, final_key, &final_key_size);
    1514            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1515            1 :         ptr += dhe_key_size;
    1516              :         /*Mock measurement hash as TCB*/
    1517            1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
    1518              :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
    1519            1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
    1520              :                          measurement_hash_data, measurement_hash_size);
    1521              :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
    1522            1 :         ptr += measurement_hash_size;
    1523            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    1524            1 :         ptr += sizeof(uint16_t);
    1525            1 :         libspdm_build_opaque_data_version_selection_data(
    1526              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1527              :                 &opaque_key_exchange_rsp_size, ptr);
    1528            1 :         ptr += opaque_key_exchange_rsp_size;
    1529            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1530              :                                                         m_libspdm_use_asym_algo, &data,
    1531              :                                                         &data_size, NULL, NULL);
    1532            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1533              :                          sizeof(m_libspdm_local_buffer)
    1534            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1535              :                             m_libspdm_local_buffer),
    1536            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1537            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1538            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1539              :                        m_libspdm_local_buffer_size));
    1540            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1541            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1542            1 :         cert_buffer =  (uint8_t *)data;
    1543            1 :         cert_buffer_size = data_size;
    1544            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1545              :                          cert_buffer_hash);
    1546              :         /* transcript.message_a size is 0*/
    1547            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    1548            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1549              :                                       m_libspdm_local_buffer_size);
    1550            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1551              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1552            1 :         free(data);
    1553            1 :         libspdm_responder_data_sign(
    1554              :             spdm_context,
    1555            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1556              :                 SPDM_KEY_EXCHANGE_RSP,
    1557              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1558            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    1559              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    1560              :                 &signature_size);
    1561            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1562              :                          sizeof(m_libspdm_local_buffer)
    1563            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1564              :                             m_libspdm_local_buffer),
    1565              :                          ptr, signature_size);
    1566            1 :         m_libspdm_local_buffer_size += signature_size;
    1567            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    1568            1 :         ptr += signature_size;
    1569            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1570              :                          libspdm_get_managed_buffer_size(&th_curr),
    1571              :                          th_curr_hash_data);
    1572            1 :         bin_str0_size = sizeof(bin_str0);
    1573            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1574              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    1575            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    1576              :                            &bin_str0_size);
    1577            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    1578              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    1579            1 :         bin_str2_size = sizeof(bin_str2);
    1580            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1581              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1582            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    1583              :                            bin_str2, &bin_str2_size);
    1584            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    1585              :                             bin_str2, bin_str2_size,
    1586              :                             response_handshake_secret, hash_size);
    1587            1 :         bin_str7_size = sizeof(bin_str7);
    1588            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1589              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    1590            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1591              :                            &bin_str7_size);
    1592            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1593              :                             hash_size, bin_str7, bin_str7_size,
    1594              :                             response_finished_key, hash_size);
    1595            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1596              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1597            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1598              :                          response_finished_key, hash_size, ptr);
    1599            1 :         ptr += hmac_size;
    1600              : 
    1601            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1602              :                                               false, spdm_response_size,
    1603              :                                               spdm_response, response_size,
    1604              :                                               response);
    1605              :     }
    1606            1 :         return LIBSPDM_STATUS_SUCCESS;
    1607              : 
    1608            1 :     case 0xD: {
    1609              :         spdm_key_exchange_response_t *spdm_response;
    1610              :         size_t dhe_key_size;
    1611              :         uint32_t hash_size;
    1612              :         uint32_t measurement_hash_size;
    1613              :         size_t signature_size;
    1614              :         uint32_t hmac_size;
    1615              :         uint8_t *ptr;
    1616              :         void *dhe_context;
    1617              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    1618              :         size_t final_key_size;
    1619              :         size_t opaque_key_exchange_rsp_size;
    1620              :         void *data;
    1621              :         size_t data_size;
    1622              :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1623              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1624              :         uint8_t *cert_buffer;
    1625              :         size_t cert_buffer_size;
    1626              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1627              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1628              :         uint8_t bin_str0[128];
    1629              :         size_t bin_str0_size;
    1630              :         uint8_t bin_str2[128];
    1631              :         size_t bin_str2_size;
    1632              :         uint8_t bin_str7[128];
    1633              :         size_t bin_str7_size;
    1634              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1635              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1636              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1637              :         size_t spdm_response_size;
    1638              :         size_t transport_header_size;
    1639              : 
    1640              :         ((libspdm_context_t *)spdm_context)
    1641            1 :         ->connection_info.algorithm.base_asym_algo =
    1642              :             m_libspdm_use_asym_algo;
    1643              :         ((libspdm_context_t *)spdm_context)
    1644            1 :         ->connection_info.algorithm.base_hash_algo =
    1645              :             m_libspdm_use_hash_algo;
    1646              :         ((libspdm_context_t *)spdm_context)
    1647            1 :         ->connection_info.algorithm.dhe_named_group =
    1648              :             m_libspdm_use_dhe_algo;
    1649              :         ((libspdm_context_t *)spdm_context)
    1650            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1651              :             m_libspdm_use_measurement_hash_algo;
    1652            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1653            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1654            1 :         measurement_hash_size = libspdm_get_hash_size(
    1655              :             m_libspdm_use_hash_algo);
    1656            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1657            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1658            1 :         opaque_key_exchange_rsp_size =
    1659            1 :             libspdm_get_opaque_data_version_selection_data_size(
    1660              :                 spdm_context);
    1661            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    1662            1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
    1663            1 :                              opaque_key_exchange_rsp_size + signature_size +
    1664              :                              hmac_size;
    1665            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1666            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1667            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    1668              : 
    1669            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1670            1 :         spdm_response->header.request_response_code =
    1671              :             SPDM_KEY_EXCHANGE_RSP;
    1672            1 :         spdm_response->header.param1 = 0;
    1673            1 :         spdm_response->rsp_session_id =
    1674            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    1675            1 :         spdm_response->mut_auth_requested = 0;
    1676            1 :         spdm_response->req_slot_id_param = 0;
    1677            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    1678            1 :                                   spdm_response->random_data);
    1679            1 :         ptr = (void *)(spdm_response + 1);
    1680            1 :         dhe_context = libspdm_dhe_new(
    1681            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1682              :                 m_libspdm_use_dhe_algo,
    1683              :                 true);
    1684            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    1685              :                                  &dhe_key_size);
    1686            1 :         final_key_size = sizeof(final_key);
    1687            1 :         libspdm_dhe_compute_key(
    1688              :             m_libspdm_use_dhe_algo, dhe_context,
    1689            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    1690              :             sizeof(spdm_key_exchange_request_t),
    1691              :             dhe_key_size, final_key, &final_key_size);
    1692            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1693            1 :         ptr += dhe_key_size;
    1694              :         /*Mock measurement hash as 0x00 array*/
    1695            1 :         libspdm_zero_mem(measurement_hash_data, measurement_hash_size);
    1696            1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
    1697              :                          measurement_hash_data, measurement_hash_size);
    1698              :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
    1699            1 :         ptr += measurement_hash_size;
    1700            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    1701            1 :         ptr += sizeof(uint16_t);
    1702            1 :         libspdm_build_opaque_data_version_selection_data(
    1703              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1704              :                 &opaque_key_exchange_rsp_size, ptr);
    1705            1 :         ptr += opaque_key_exchange_rsp_size;
    1706            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1707              :                                                         m_libspdm_use_asym_algo, &data,
    1708              :                                                         &data_size, NULL, NULL);
    1709            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1710              :                          sizeof(m_libspdm_local_buffer)
    1711            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1712              :                             m_libspdm_local_buffer),
    1713            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1714            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1715            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1716              :                        m_libspdm_local_buffer_size));
    1717            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1718            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1719            1 :         cert_buffer = (uint8_t *)data;
    1720            1 :         cert_buffer_size =  data_size;
    1721            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1722              :                          cert_buffer_hash);
    1723              :         /* transcript.message_a size is 0*/
    1724            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    1725            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1726              :                                       m_libspdm_local_buffer_size);
    1727            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1728              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1729            1 :         free(data);
    1730            1 :         libspdm_responder_data_sign(
    1731              :             spdm_context,
    1732            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1733              :                 SPDM_KEY_EXCHANGE_RSP,
    1734              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1735            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    1736              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    1737              :                 &signature_size);
    1738            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1739              :                          sizeof(m_libspdm_local_buffer)
    1740            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1741              :                             m_libspdm_local_buffer),
    1742              :                          ptr, signature_size);
    1743            1 :         m_libspdm_local_buffer_size += signature_size;
    1744            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    1745            1 :         ptr += signature_size;
    1746            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1747              :                          libspdm_get_managed_buffer_size(&th_curr),
    1748              :                          th_curr_hash_data);
    1749            1 :         bin_str0_size = sizeof(bin_str0);
    1750            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1751              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    1752            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    1753              :                            &bin_str0_size);
    1754            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    1755              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    1756            1 :         bin_str2_size = sizeof(bin_str2);
    1757            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1758              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1759            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    1760              :                            bin_str2, &bin_str2_size);
    1761            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    1762              :                             bin_str2, bin_str2_size,
    1763              :                             response_handshake_secret, hash_size);
    1764            1 :         bin_str7_size = sizeof(bin_str7);
    1765            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1766              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    1767            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1768              :                            &bin_str7_size);
    1769            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1770              :                             hash_size, bin_str7, bin_str7_size,
    1771              :                             response_finished_key, hash_size);
    1772            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1773              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1774            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1775              :                          response_finished_key, hash_size, ptr);
    1776            1 :         ptr += hmac_size;
    1777              : 
    1778            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1779              :                                               false, spdm_response_size,
    1780              :                                               spdm_response, response_size,
    1781              :                                               response);
    1782              :     }
    1783            1 :         return LIBSPDM_STATUS_SUCCESS;
    1784              : 
    1785            1 :     case 0xE: {
    1786              :         spdm_key_exchange_response_t *spdm_response;
    1787              :         size_t dhe_key_size;
    1788              :         uint32_t hash_size;
    1789              :         uint32_t measurement_hash_size;
    1790              :         size_t signature_size;
    1791              :         uint32_t hmac_size;
    1792              :         uint8_t *ptr;
    1793              :         void *dhe_context;
    1794              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    1795              :         size_t final_key_size;
    1796              :         size_t opaque_key_exchange_rsp_size;
    1797              :         void *data;
    1798              :         size_t data_size;
    1799              :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1800              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1801              :         uint8_t *cert_buffer;
    1802              :         size_t cert_buffer_size;
    1803              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1804              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1805              :         uint8_t bin_str0[128];
    1806              :         size_t bin_str0_size;
    1807              :         uint8_t bin_str2[128];
    1808              :         size_t bin_str2_size;
    1809              :         uint8_t bin_str7[128];
    1810              :         size_t bin_str7_size;
    1811              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1812              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1813              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1814              :         size_t spdm_response_size;
    1815              :         size_t transport_header_size;
    1816              : 
    1817              :         ((libspdm_context_t *)spdm_context)
    1818            1 :         ->connection_info.algorithm.base_asym_algo =
    1819              :             m_libspdm_use_asym_algo;
    1820              :         ((libspdm_context_t *)spdm_context)
    1821            1 :         ->connection_info.algorithm.base_hash_algo =
    1822              :             m_libspdm_use_hash_algo;
    1823              :         ((libspdm_context_t *)spdm_context)
    1824            1 :         ->connection_info.algorithm.dhe_named_group =
    1825              :             m_libspdm_use_dhe_algo;
    1826              :         ((libspdm_context_t *)spdm_context)
    1827            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1828              :             m_libspdm_use_measurement_hash_algo;
    1829            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1830            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1831            1 :         measurement_hash_size = libspdm_get_hash_size(
    1832              :             m_libspdm_use_hash_algo);
    1833            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1834            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    1835            1 :         opaque_key_exchange_rsp_size =
    1836            1 :             libspdm_get_opaque_data_version_selection_data_size(
    1837              :                 spdm_context);
    1838            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    1839            1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
    1840            1 :                              opaque_key_exchange_rsp_size + signature_size +
    1841              :                              hmac_size;
    1842            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1843            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1844            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    1845              : 
    1846            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1847            1 :         spdm_response->header.request_response_code =
    1848              :             SPDM_KEY_EXCHANGE_RSP;
    1849            1 :         spdm_response->header.param1 = 0;
    1850            1 :         spdm_response->rsp_session_id =
    1851            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    1852            1 :         spdm_response->mut_auth_requested = 0;
    1853            1 :         spdm_response->req_slot_id_param = 0;
    1854            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    1855            1 :                                   spdm_response->random_data);
    1856            1 :         ptr = (void *)(spdm_response + 1);
    1857            1 :         dhe_context = libspdm_dhe_new(
    1858            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1859              :                 m_libspdm_use_dhe_algo,
    1860              :                 true);
    1861            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    1862              :                                  &dhe_key_size);
    1863            1 :         final_key_size = sizeof(final_key);
    1864            1 :         libspdm_dhe_compute_key(
    1865              :             m_libspdm_use_dhe_algo, dhe_context,
    1866            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    1867              :             sizeof(spdm_key_exchange_request_t),
    1868              :             dhe_key_size, final_key, &final_key_size);
    1869            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    1870            1 :         ptr += dhe_key_size;
    1871              :         /*Mock measurement hash*/
    1872            1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
    1873              :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
    1874            1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
    1875              :                          measurement_hash_data, measurement_hash_size);
    1876              :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
    1877            1 :         ptr += measurement_hash_size;
    1878            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    1879            1 :         ptr += sizeof(uint16_t);
    1880            1 :         libspdm_build_opaque_data_version_selection_data(
    1881              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1882              :                 &opaque_key_exchange_rsp_size, ptr);
    1883            1 :         ptr += opaque_key_exchange_rsp_size;
    1884            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1885              :                                                         m_libspdm_use_asym_algo, &data,
    1886              :                                                         &data_size, NULL, NULL);
    1887            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1888              :                          sizeof(m_libspdm_local_buffer)
    1889            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1890              :                             m_libspdm_local_buffer),
    1891            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1892            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1893            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1894              :                        m_libspdm_local_buffer_size));
    1895            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1896            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    1897            1 :         cert_buffer =  (uint8_t *)data;
    1898            1 :         cert_buffer_size = data_size;
    1899            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    1900              :                          cert_buffer_hash);
    1901              :         /* transcript.message_a size is 0*/
    1902            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    1903            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    1904              :                                       m_libspdm_local_buffer_size);
    1905            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1906              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1907            1 :         free(data);
    1908            1 :         libspdm_responder_data_sign(
    1909              :             spdm_context,
    1910            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1911              :                 SPDM_KEY_EXCHANGE_RSP,
    1912              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1913            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    1914              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    1915              :                 &signature_size);
    1916            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1917              :                          sizeof(m_libspdm_local_buffer)
    1918            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1919              :                             m_libspdm_local_buffer),
    1920              :                          ptr, signature_size);
    1921            1 :         m_libspdm_local_buffer_size += signature_size;
    1922            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    1923            1 :         ptr += signature_size;
    1924            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1925              :                          libspdm_get_managed_buffer_size(&th_curr),
    1926              :                          th_curr_hash_data);
    1927            1 :         bin_str0_size = sizeof(bin_str0);
    1928            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1929              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    1930            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    1931              :                            &bin_str0_size);
    1932            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    1933              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    1934            1 :         bin_str2_size = sizeof(bin_str2);
    1935            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1936              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    1937            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    1938              :                            bin_str2, &bin_str2_size);
    1939            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    1940              :                             bin_str2, bin_str2_size,
    1941              :                             response_handshake_secret, hash_size);
    1942            1 :         bin_str7_size = sizeof(bin_str7);
    1943            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    1944              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    1945            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    1946              :                            &bin_str7_size);
    1947            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    1948              :                             hash_size, bin_str7, bin_str7_size,
    1949              :                             response_finished_key, hash_size);
    1950            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    1951              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    1952            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    1953              :                          response_finished_key, hash_size, ptr);
    1954            1 :         ptr += hmac_size;
    1955              : 
    1956            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1957              :                                               false, spdm_response_size,
    1958              :                                               spdm_response, response_size,
    1959              :                                               response);
    1960              :     }
    1961            1 :         return LIBSPDM_STATUS_SUCCESS;
    1962              : 
    1963            1 :     case 0xF: {
    1964              :         spdm_key_exchange_response_t *spdm_response;
    1965              :         size_t dhe_key_size;
    1966              :         uint32_t hash_size;
    1967              :         size_t signature_size;
    1968              :         uint32_t hmac_size;
    1969              :         uint8_t *ptr;
    1970              :         void *dhe_context;
    1971              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    1972              :         size_t final_key_size;
    1973              :         size_t opaque_key_exchange_rsp_size;
    1974              :         void *data;
    1975              :         size_t data_size;
    1976              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1977              :         uint8_t *cert_buffer;
    1978              :         size_t cert_buffer_size;
    1979              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1980              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    1981              :         uint8_t bin_str0[128];
    1982              :         size_t bin_str0_size;
    1983              :         uint8_t bin_str2[128];
    1984              :         size_t bin_str2_size;
    1985              :         uint8_t bin_str7[128];
    1986              :         size_t bin_str7_size;
    1987              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1988              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    1989              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    1990              :         size_t spdm_response_size;
    1991              :         size_t transport_header_size;
    1992              : 
    1993              :         ((libspdm_context_t *)spdm_context)
    1994            1 :         ->connection_info.algorithm.base_asym_algo =
    1995              :             m_libspdm_use_asym_algo;
    1996              :         ((libspdm_context_t *)spdm_context)
    1997            1 :         ->connection_info.algorithm.base_hash_algo =
    1998              :             m_libspdm_use_hash_algo;
    1999              :         ((libspdm_context_t *)spdm_context)
    2000            1 :         ->connection_info.algorithm.dhe_named_group =
    2001              :             m_libspdm_use_dhe_algo;
    2002              :         ((libspdm_context_t *)spdm_context)
    2003            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2004              :             m_libspdm_use_measurement_hash_algo;
    2005            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2006            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2007            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2008            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    2009            1 :         opaque_key_exchange_rsp_size =
    2010            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2011              :                 spdm_context);
    2012            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    2013            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    2014            1 :                              opaque_key_exchange_rsp_size + signature_size +
    2015              :                              hmac_size;
    2016            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2017            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2018            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    2019              : 
    2020            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2021            1 :         spdm_response->header.request_response_code =
    2022              :             SPDM_KEY_EXCHANGE_RSP;
    2023            1 :         spdm_response->header.param1 = 0;
    2024            1 :         spdm_response->rsp_session_id =
    2025            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    2026            1 :         spdm_response->mut_auth_requested = 0;
    2027            1 :         spdm_response->req_slot_id_param = 0;
    2028            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    2029            1 :                                   spdm_response->random_data);
    2030            1 :         ptr = (void *)(spdm_response + 1);
    2031            1 :         dhe_context = libspdm_dhe_new(
    2032            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2033              :                 m_libspdm_use_dhe_algo,
    2034              :                 true);
    2035            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    2036              :                                  &dhe_key_size);
    2037            1 :         final_key_size = sizeof(final_key);
    2038            1 :         libspdm_dhe_compute_key(
    2039              :             m_libspdm_use_dhe_algo, dhe_context,
    2040            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    2041              :             sizeof(spdm_key_exchange_request_t),
    2042              :             dhe_key_size, final_key, &final_key_size);
    2043            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    2044            1 :         ptr += dhe_key_size;
    2045              :         /* libspdm_zero_mem (ptr, hash_size);
    2046              :          * ptr += hash_size;*/
    2047            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    2048            1 :         ptr += sizeof(uint16_t);
    2049            1 :         libspdm_build_opaque_data_version_selection_data(
    2050              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2051              :                 &opaque_key_exchange_rsp_size, ptr);
    2052            1 :         ptr += opaque_key_exchange_rsp_size;
    2053            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2054              :                                                         m_libspdm_use_asym_algo, &data,
    2055              :                                                         &data_size, NULL, NULL);
    2056            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2057              :                          sizeof(m_libspdm_local_buffer)
    2058            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2059              :                             m_libspdm_local_buffer),
    2060            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2061            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2062            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2063              :                        m_libspdm_local_buffer_size));
    2064            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2065            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2066            1 :         cert_buffer =  (uint8_t *)data;
    2067            1 :         cert_buffer_size = data_size;
    2068            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2069              :                          cert_buffer_hash);
    2070              :         /* transcript.message_a size is 0*/
    2071            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    2072            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2073              :                                       m_libspdm_local_buffer_size);
    2074            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2075              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2076            1 :         free(data);
    2077            1 :         libspdm_responder_data_sign(
    2078              :             spdm_context,
    2079            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2080              :                 SPDM_KEY_EXCHANGE_RSP,
    2081              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2082            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    2083              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    2084              :                 &signature_size);
    2085            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2086              :                          sizeof(m_libspdm_local_buffer)
    2087            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2088              :                             m_libspdm_local_buffer),
    2089              :                          ptr, signature_size);
    2090            1 :         m_libspdm_local_buffer_size += signature_size;
    2091            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    2092            1 :         ptr += signature_size;
    2093            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2094              :                          libspdm_get_managed_buffer_size(&th_curr),
    2095              :                          th_curr_hash_data);
    2096            1 :         bin_str0_size = sizeof(bin_str0);
    2097            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2098              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    2099            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    2100              :                            &bin_str0_size);
    2101            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    2102              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    2103            1 :         bin_str2_size = sizeof(bin_str2);
    2104            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2105              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    2106            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    2107              :                            bin_str2, &bin_str2_size);
    2108            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    2109              :                             bin_str2, bin_str2_size,
    2110              :                             response_handshake_secret, hash_size);
    2111            1 :         bin_str7_size = sizeof(bin_str7);
    2112            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2113              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    2114            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2115              :                            &bin_str7_size);
    2116            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2117              :                             hash_size, bin_str7, bin_str7_size,
    2118              :                             response_finished_key, hash_size);
    2119            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2120              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2121            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2122              :                          response_finished_key, hash_size, ptr);
    2123            1 :         ptr += hmac_size;
    2124              : 
    2125            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2126              :                                               false, spdm_response_size,
    2127              :                                               spdm_response, response_size,
    2128              :                                               response);
    2129              :     }
    2130            1 :         return LIBSPDM_STATUS_SUCCESS;
    2131              : 
    2132            1 :     case 0x10: {
    2133              :         spdm_key_exchange_response_t *spdm_response;
    2134              :         size_t dhe_key_size;
    2135              :         uint32_t hash_size;
    2136              :         size_t signature_size;
    2137              :         uint32_t hmac_size;
    2138              :         uint8_t *ptr;
    2139              :         void *dhe_context;
    2140              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    2141              :         size_t final_key_size;
    2142              :         size_t opaque_key_exchange_rsp_size;
    2143              :         void *data;
    2144              :         size_t data_size;
    2145              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2146              :         uint8_t *cert_buffer;
    2147              :         size_t cert_buffer_size;
    2148              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2149              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    2150              :         uint8_t bin_str0[128];
    2151              :         size_t bin_str0_size;
    2152              :         uint8_t bin_str2[128];
    2153              :         size_t bin_str2_size;
    2154              :         uint8_t bin_str7[128];
    2155              :         size_t bin_str7_size;
    2156              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2157              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2158              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2159              :         size_t spdm_response_size;
    2160              :         size_t transport_header_size;
    2161              : 
    2162              :         ((libspdm_context_t *)spdm_context)
    2163            1 :         ->connection_info.algorithm.base_asym_algo =
    2164              :             m_libspdm_use_asym_algo;
    2165              :         ((libspdm_context_t *)spdm_context)
    2166            1 :         ->connection_info.algorithm.base_hash_algo =
    2167              :             m_libspdm_use_hash_algo;
    2168              :         ((libspdm_context_t *)spdm_context)
    2169            1 :         ->connection_info.algorithm.dhe_named_group =
    2170              :             m_libspdm_use_dhe_algo;
    2171              :         ((libspdm_context_t *)spdm_context)
    2172            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2173              :             m_libspdm_use_measurement_hash_algo;
    2174            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2175            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2176            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2177            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    2178            1 :         opaque_key_exchange_rsp_size =
    2179            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2180              :                 spdm_context);
    2181            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    2182            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    2183            1 :                              opaque_key_exchange_rsp_size + signature_size +
    2184              :                              hmac_size;
    2185            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2186            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2187            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    2188              : 
    2189            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2190            1 :         spdm_response->header.request_response_code =
    2191              :             SPDM_KEY_EXCHANGE_RSP;
    2192            1 :         spdm_response->header.param1 = 0;
    2193            1 :         spdm_response->rsp_session_id =
    2194            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    2195            1 :         spdm_response->mut_auth_requested = 0;
    2196            1 :         spdm_response->req_slot_id_param = 0;
    2197            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    2198            1 :                                   spdm_response->random_data);
    2199            1 :         ptr = (void *)(spdm_response + 1);
    2200            1 :         dhe_context = libspdm_dhe_new(
    2201            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2202              :                 m_libspdm_use_dhe_algo,
    2203              :                 true);
    2204            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    2205              :                                  &dhe_key_size);
    2206            1 :         final_key_size = sizeof(final_key);
    2207            1 :         libspdm_dhe_compute_key(
    2208              :             m_libspdm_use_dhe_algo, dhe_context,
    2209            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    2210              :             sizeof(spdm_key_exchange_request_t),
    2211              :             dhe_key_size, final_key, &final_key_size);
    2212            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    2213            1 :         ptr += dhe_key_size;
    2214              :         /* libspdm_zero_mem (ptr, hash_size);
    2215              :          * ptr += hash_size;*/
    2216            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    2217            1 :         ptr += sizeof(uint16_t);
    2218            1 :         libspdm_build_opaque_data_version_selection_data(
    2219              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2220              :                 &opaque_key_exchange_rsp_size, ptr);
    2221            1 :         ptr += opaque_key_exchange_rsp_size;
    2222            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2223              :                                                         m_libspdm_use_asym_algo, &data,
    2224              :                                                         &data_size, NULL, NULL);
    2225            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2226              :                          sizeof(m_libspdm_local_buffer)
    2227            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2228              :                             m_libspdm_local_buffer),
    2229            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2230            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2231            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2232              :                        m_libspdm_local_buffer_size));
    2233            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2234            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2235            1 :         cert_buffer =  (uint8_t *)data;
    2236            1 :         cert_buffer_size = data_size;
    2237            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2238              :                          cert_buffer_hash);
    2239              :         /* transcript.message_a size is 0*/
    2240            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    2241            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2242              :                                       m_libspdm_local_buffer_size);
    2243            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2244              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2245            1 :         free(data);
    2246            1 :         libspdm_responder_data_sign(
    2247              :             spdm_context,
    2248            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2249              :                 SPDM_KEY_EXCHANGE_RSP,
    2250              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2251            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    2252              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    2253              :                 &signature_size);
    2254            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2255              :                          sizeof(m_libspdm_local_buffer)
    2256            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2257              :                             m_libspdm_local_buffer),
    2258              :                          ptr, signature_size);
    2259            1 :         m_libspdm_local_buffer_size += signature_size;
    2260            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    2261            1 :         ptr += signature_size;
    2262            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2263              :                          libspdm_get_managed_buffer_size(&th_curr),
    2264              :                          th_curr_hash_data);
    2265            1 :         bin_str0_size = sizeof(bin_str0);
    2266            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2267              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    2268            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    2269              :                            &bin_str0_size);
    2270            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    2271              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    2272            1 :         bin_str2_size = sizeof(bin_str2);
    2273            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2274              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    2275            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    2276              :                            bin_str2, &bin_str2_size);
    2277            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    2278              :                             bin_str2, bin_str2_size,
    2279              :                             response_handshake_secret, hash_size);
    2280            1 :         bin_str7_size = sizeof(bin_str7);
    2281            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2282              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    2283            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2284              :                            &bin_str7_size);
    2285            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2286              :                             hash_size, bin_str7, bin_str7_size,
    2287              :                             response_finished_key, hash_size);
    2288            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2289              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2290            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2291              :                          response_finished_key, hash_size, ptr);
    2292            1 :         ptr += hmac_size;
    2293              : 
    2294            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2295              :                                               false, spdm_response_size,
    2296              :                                               spdm_response, response_size,
    2297              :                                               response);
    2298              :     }
    2299            1 :         return LIBSPDM_STATUS_SUCCESS;
    2300              : 
    2301            1 :     case 0x11: {
    2302              :         spdm_key_exchange_response_t *spdm_response;
    2303              :         size_t dhe_key_size;
    2304              :         uint32_t hash_size;
    2305              :         uint32_t measurement_hash_size;
    2306              :         size_t signature_size;
    2307              :         uint32_t hmac_size;
    2308              :         uint8_t *ptr;
    2309              :         void *dhe_context;
    2310              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    2311              :         size_t final_key_size;
    2312              :         size_t opaque_key_exchange_rsp_size;
    2313              :         void *data;
    2314              :         size_t data_size;
    2315              :         uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
    2316              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2317              :         uint8_t *cert_buffer;
    2318              :         size_t cert_buffer_size;
    2319              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2320              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    2321              :         uint8_t bin_str0[128];
    2322              :         size_t bin_str0_size;
    2323              :         uint8_t bin_str2[128];
    2324              :         size_t bin_str2_size;
    2325              :         uint8_t bin_str7[128];
    2326              :         size_t bin_str7_size;
    2327              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2328              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2329              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2330              :         size_t spdm_response_size;
    2331              :         size_t transport_header_size;
    2332              : 
    2333              :         ((libspdm_context_t *)spdm_context)
    2334            1 :         ->connection_info.algorithm.base_asym_algo =
    2335              :             m_libspdm_use_asym_algo;
    2336              :         ((libspdm_context_t *)spdm_context)
    2337            1 :         ->connection_info.algorithm.base_hash_algo =
    2338              :             m_libspdm_use_hash_algo;
    2339              :         ((libspdm_context_t *)spdm_context)
    2340            1 :         ->connection_info.algorithm.dhe_named_group =
    2341              :             m_libspdm_use_dhe_algo;
    2342              :         ((libspdm_context_t *)spdm_context)
    2343            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2344              :             m_libspdm_use_measurement_hash_algo;
    2345            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2346            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2347            1 :         measurement_hash_size = libspdm_get_hash_size(
    2348              :             m_libspdm_use_hash_algo);
    2349            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2350            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    2351            1 :         opaque_key_exchange_rsp_size =
    2352            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2353              :                 spdm_context);
    2354            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    2355            1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
    2356            1 :                              opaque_key_exchange_rsp_size + signature_size +
    2357              :                              hmac_size;
    2358            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2359            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2360            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    2361              : 
    2362            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2363            1 :         spdm_response->header.request_response_code =
    2364              :             SPDM_KEY_EXCHANGE_RSP;
    2365            1 :         spdm_response->header.param1 = 0;
    2366            1 :         spdm_response->rsp_session_id =
    2367            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    2368            1 :         spdm_response->mut_auth_requested = 0;
    2369            1 :         spdm_response->req_slot_id_param = 0;
    2370            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    2371            1 :                                   spdm_response->random_data);
    2372            1 :         ptr = (void *)(spdm_response + 1);
    2373            1 :         dhe_context = libspdm_dhe_new(
    2374            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2375              :                 m_libspdm_use_dhe_algo,
    2376              :                 true);
    2377            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    2378              :                                  &dhe_key_size);
    2379            1 :         final_key_size = sizeof(final_key);
    2380            1 :         libspdm_dhe_compute_key(
    2381              :             m_libspdm_use_dhe_algo, dhe_context,
    2382            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    2383              :             sizeof(spdm_key_exchange_request_t),
    2384              :             dhe_key_size, final_key, &final_key_size);
    2385            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    2386            1 :         ptr += dhe_key_size;
    2387              :         /*Mock measurement hash as TCB*/
    2388            1 :         libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
    2389              :                          m_libspdm_use_tcb_hash_value, measurement_hash_size);
    2390            1 :         libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
    2391              :                          measurement_hash_data, measurement_hash_size);
    2392              :         /*libspdm_zero_mem (ptr, measurement_hash_size);*/
    2393            1 :         ptr += measurement_hash_size;
    2394            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    2395            1 :         ptr += sizeof(uint16_t);
    2396            1 :         libspdm_build_opaque_data_version_selection_data(
    2397              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2398              :                 &opaque_key_exchange_rsp_size, ptr);
    2399            1 :         ptr += opaque_key_exchange_rsp_size;
    2400            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2401              :                                                         m_libspdm_use_asym_algo, &data,
    2402              :                                                         &data_size, NULL, NULL);
    2403            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2404              :                          sizeof(m_libspdm_local_buffer)
    2405            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2406              :                             m_libspdm_local_buffer),
    2407            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2408            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2409            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2410              :                        m_libspdm_local_buffer_size));
    2411            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2412            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2413            1 :         cert_buffer =  (uint8_t *)data;
    2414            1 :         cert_buffer_size = data_size;
    2415            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2416              :                          cert_buffer_hash);
    2417              :         /* transcript.message_a size is 0*/
    2418            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    2419            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2420              :                                       m_libspdm_local_buffer_size);
    2421            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2422              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2423            1 :         free(data);
    2424            1 :         libspdm_responder_data_sign(
    2425              :             spdm_context,
    2426            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2427              :                 SPDM_KEY_EXCHANGE_RSP,
    2428              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2429            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    2430              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    2431              :                 &signature_size);
    2432            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2433              :                          sizeof(m_libspdm_local_buffer)
    2434            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2435              :                             m_libspdm_local_buffer),
    2436              :                          ptr, signature_size);
    2437            1 :         m_libspdm_local_buffer_size += signature_size;
    2438            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    2439            1 :         ptr += signature_size;
    2440            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2441              :                          libspdm_get_managed_buffer_size(&th_curr),
    2442              :                          th_curr_hash_data);
    2443            1 :         bin_str0_size = sizeof(bin_str0);
    2444            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2445              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    2446            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    2447              :                            &bin_str0_size);
    2448            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    2449              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    2450            1 :         bin_str2_size = sizeof(bin_str2);
    2451            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2452              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    2453            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    2454              :                            bin_str2, &bin_str2_size);
    2455            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    2456              :                             bin_str2, bin_str2_size,
    2457              :                             response_handshake_secret, hash_size);
    2458            1 :         bin_str7_size = sizeof(bin_str7);
    2459            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2460              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    2461            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2462              :                            &bin_str7_size);
    2463            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2464              :                             hash_size, bin_str7, bin_str7_size,
    2465              :                             response_finished_key, hash_size);
    2466            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2467              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2468            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2469              :                          response_finished_key, hash_size, ptr);
    2470            1 :         ptr += hmac_size;
    2471              : 
    2472            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2473              :                                               false, spdm_response_size,
    2474              :                                               spdm_response, response_size,
    2475              :                                               response);
    2476              :     }
    2477            1 :         return LIBSPDM_STATUS_SUCCESS;
    2478              : 
    2479            1 :     case 0x12: {
    2480              :         spdm_key_exchange_response_t *spdm_response;
    2481              :         size_t dhe_key_size;
    2482              :         uint32_t hash_size;
    2483              :         uint32_t measurement_hash_size;
    2484              :         size_t signature_size;
    2485              :         uint32_t hmac_size;
    2486              :         uint8_t *ptr;
    2487              :         void *dhe_context;
    2488              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    2489              :         size_t final_key_size;
    2490              :         size_t opaque_key_exchange_rsp_size;
    2491              :         void *data;
    2492              :         size_t data_size;
    2493              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2494              :         uint8_t *cert_buffer;
    2495              :         size_t cert_buffer_size;
    2496              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2497              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    2498              :         uint8_t bin_str0[128];
    2499              :         size_t bin_str0_size;
    2500              :         uint8_t bin_str2[128];
    2501              :         size_t bin_str2_size;
    2502              :         uint8_t bin_str7[128];
    2503              :         size_t bin_str7_size;
    2504              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2505              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2506              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2507              :         size_t spdm_response_size;
    2508              :         size_t transport_header_size;
    2509              : 
    2510              :         ((libspdm_context_t *)spdm_context)
    2511            1 :         ->connection_info.algorithm.base_asym_algo =
    2512              :             m_libspdm_use_asym_algo;
    2513              :         ((libspdm_context_t *)spdm_context)
    2514            1 :         ->connection_info.algorithm.base_hash_algo =
    2515              :             m_libspdm_use_hash_algo;
    2516              :         ((libspdm_context_t *)spdm_context)
    2517            1 :         ->connection_info.algorithm.dhe_named_group =
    2518              :             m_libspdm_use_dhe_algo;
    2519              :         ((libspdm_context_t *)spdm_context)
    2520            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2521              :             m_libspdm_use_measurement_hash_algo;
    2522            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2523            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2524            1 :         measurement_hash_size = 0;
    2525            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2526            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    2527            1 :         opaque_key_exchange_rsp_size =
    2528            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2529              :                 spdm_context);
    2530            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    2531            1 :                              dhe_key_size + measurement_hash_size + sizeof(uint16_t) +
    2532            1 :                              opaque_key_exchange_rsp_size + signature_size +
    2533              :                              hmac_size;
    2534            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2535            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2536            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    2537              : 
    2538            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2539            1 :         spdm_response->header.request_response_code =
    2540              :             SPDM_KEY_EXCHANGE_RSP;
    2541            1 :         spdm_response->header.param1 = 0;
    2542            1 :         spdm_response->rsp_session_id =
    2543            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    2544            1 :         spdm_response->mut_auth_requested = 0;
    2545            1 :         spdm_response->req_slot_id_param = 0;
    2546            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    2547            1 :                                   spdm_response->random_data);
    2548            1 :         ptr = (void *)(spdm_response + 1);
    2549            1 :         dhe_context = libspdm_dhe_new(
    2550            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2551              :                 m_libspdm_use_dhe_algo,
    2552              :                 true);
    2553            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    2554              :                                  &dhe_key_size);
    2555            1 :         final_key_size = sizeof(final_key);
    2556            1 :         libspdm_dhe_compute_key(
    2557              :             m_libspdm_use_dhe_algo, dhe_context,
    2558            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    2559              :             sizeof(spdm_key_exchange_request_t),
    2560              :             dhe_key_size, final_key, &final_key_size);
    2561            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    2562            1 :         ptr += dhe_key_size;
    2563              : 
    2564            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    2565            1 :         ptr += sizeof(uint16_t);
    2566            1 :         libspdm_build_opaque_data_version_selection_data(
    2567              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2568              :                 &opaque_key_exchange_rsp_size, ptr);
    2569            1 :         ptr += opaque_key_exchange_rsp_size;
    2570            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2571              :                                                         m_libspdm_use_asym_algo, &data,
    2572              :                                                         &data_size, NULL, NULL);
    2573            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2574              :                          sizeof(m_libspdm_local_buffer)
    2575            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2576              :                             m_libspdm_local_buffer),
    2577            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2578            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2579            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2580              :                        m_libspdm_local_buffer_size));
    2581            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2582            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2583            1 :         cert_buffer =  (uint8_t *)data;
    2584            1 :         cert_buffer_size = data_size;
    2585            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2586              :                          cert_buffer_hash);
    2587              :         /* transcript.message_a size is 0*/
    2588            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    2589            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2590              :                                       m_libspdm_local_buffer_size);
    2591            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2592              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2593            1 :         free(data);
    2594            1 :         libspdm_responder_data_sign(
    2595              :             spdm_context,
    2596            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2597              :                 SPDM_KEY_EXCHANGE_RSP,
    2598              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2599            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    2600              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    2601              :                 &signature_size);
    2602            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2603              :                          sizeof(m_libspdm_local_buffer)
    2604            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2605              :                             m_libspdm_local_buffer),
    2606              :                          ptr, signature_size);
    2607            1 :         m_libspdm_local_buffer_size += signature_size;
    2608            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    2609            1 :         ptr += signature_size-1;
    2610            1 :         *ptr ^= 0xFF;
    2611            1 :         ptr++;
    2612            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2613              :                          libspdm_get_managed_buffer_size(&th_curr),
    2614              :                          th_curr_hash_data);
    2615            1 :         bin_str0_size = sizeof(bin_str0);
    2616            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2617              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    2618            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    2619              :                            &bin_str0_size);
    2620            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    2621              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    2622            1 :         bin_str2_size = sizeof(bin_str2);
    2623            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2624              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    2625            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    2626              :                            bin_str2, &bin_str2_size);
    2627            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    2628              :                             bin_str2, bin_str2_size,
    2629              :                             response_handshake_secret, hash_size);
    2630            1 :         bin_str7_size = sizeof(bin_str7);
    2631            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2632              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    2633            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2634              :                            &bin_str7_size);
    2635            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2636              :                             hash_size, bin_str7, bin_str7_size,
    2637              :                             response_finished_key, hash_size);
    2638            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2639              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2640            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2641              :                          response_finished_key, hash_size, ptr);
    2642            1 :         ptr += hmac_size;
    2643              : 
    2644            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2645              :                                               false, spdm_response_size,
    2646              :                                               spdm_response, response_size,
    2647              :                                               response);
    2648              :     }
    2649            1 :         return LIBSPDM_STATUS_SUCCESS;
    2650              : 
    2651            1 :     case 0x13: {
    2652              :         spdm_key_exchange_response_t *spdm_response;
    2653              :         size_t dhe_key_size;
    2654              :         uint32_t hash_size;
    2655              :         size_t signature_size;
    2656              :         uint32_t hmac_size;
    2657              :         uint8_t *ptr;
    2658              :         void *dhe_context;
    2659              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    2660              :         size_t final_key_size;
    2661              :         size_t opaque_key_exchange_rsp_size;
    2662              :         void *data;
    2663              :         size_t data_size;
    2664              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2665              :         uint8_t *cert_buffer;
    2666              :         size_t cert_buffer_size;
    2667              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2668              :         size_t spdm_response_size;
    2669              :         size_t transport_header_size;
    2670              : 
    2671              :         ((libspdm_context_t *)spdm_context)
    2672            1 :         ->connection_info.algorithm.base_asym_algo =
    2673              :             m_libspdm_use_asym_algo;
    2674              :         ((libspdm_context_t *)spdm_context)
    2675            1 :         ->connection_info.algorithm.base_hash_algo =
    2676              :             m_libspdm_use_hash_algo;
    2677              :         ((libspdm_context_t *)spdm_context)
    2678            1 :         ->connection_info.algorithm.dhe_named_group =
    2679              :             m_libspdm_use_dhe_algo;
    2680              :         ((libspdm_context_t *)spdm_context)
    2681            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2682              :             m_libspdm_use_measurement_hash_algo;
    2683            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2684            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2685            1 :         hmac_size = 0;
    2686            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    2687            1 :         opaque_key_exchange_rsp_size =
    2688            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2689              :                 spdm_context);
    2690            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    2691            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    2692            1 :                              opaque_key_exchange_rsp_size + signature_size +
    2693              :                              hmac_size;
    2694            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2695            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2696            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    2697              : 
    2698            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2699            1 :         spdm_response->header.request_response_code =
    2700              :             SPDM_KEY_EXCHANGE_RSP;
    2701            1 :         spdm_response->header.param1 = 0;
    2702            1 :         spdm_response->rsp_session_id =
    2703            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    2704            1 :         spdm_response->mut_auth_requested = 0;
    2705            1 :         spdm_response->req_slot_id_param = 0;
    2706            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    2707            1 :                                   spdm_response->random_data);
    2708            1 :         ptr = (void *)(spdm_response + 1);
    2709            1 :         dhe_context = libspdm_dhe_new(
    2710            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2711              :                 m_libspdm_use_dhe_algo,
    2712              :                 true);
    2713            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    2714              :                                  &dhe_key_size);
    2715            1 :         final_key_size = sizeof(final_key);
    2716            1 :         libspdm_dhe_compute_key(
    2717              :             m_libspdm_use_dhe_algo, dhe_context,
    2718            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    2719              :             sizeof(spdm_key_exchange_request_t),
    2720              :             dhe_key_size, final_key, &final_key_size);
    2721            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    2722            1 :         ptr += dhe_key_size;
    2723              :         /* libspdm_zero_mem (ptr, hash_size);
    2724              :          * ptr += hash_size;*/
    2725            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    2726            1 :         ptr += sizeof(uint16_t);
    2727            1 :         libspdm_build_opaque_data_version_selection_data(
    2728              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2729              :                 &opaque_key_exchange_rsp_size, ptr);
    2730            1 :         ptr += opaque_key_exchange_rsp_size;
    2731            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2732              :                                                         m_libspdm_use_asym_algo, &data,
    2733              :                                                         &data_size, NULL, NULL);
    2734            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2735              :                          sizeof(m_libspdm_local_buffer)
    2736            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2737              :                             m_libspdm_local_buffer),
    2738            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2739            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2740            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2741              :                        m_libspdm_local_buffer_size));
    2742            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2743            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2744            1 :         cert_buffer =  (uint8_t *)data;
    2745            1 :         cert_buffer_size = data_size;
    2746            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2747              :                          cert_buffer_hash);
    2748              :         /* transcript.message_a size is 0*/
    2749            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    2750            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2751              :                                       m_libspdm_local_buffer_size);
    2752            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2753              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2754            1 :         free(data);
    2755            1 :         libspdm_responder_data_sign(
    2756              :             spdm_context,
    2757            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2758              :                 SPDM_KEY_EXCHANGE_RSP,
    2759              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2760            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    2761              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    2762              :                 &signature_size);
    2763            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2764              :                          sizeof(m_libspdm_local_buffer)
    2765            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2766              :                             m_libspdm_local_buffer),
    2767              :                          ptr, signature_size);
    2768            1 :         m_libspdm_local_buffer_size += signature_size;
    2769            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    2770            1 :         ptr += signature_size;
    2771              : 
    2772            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2773              :                                               false, spdm_response_size,
    2774              :                                               spdm_response, response_size,
    2775              :                                               response);
    2776              :     }
    2777            1 :         return LIBSPDM_STATUS_SUCCESS;
    2778              : 
    2779            1 :     case 0x14: {
    2780              :         spdm_key_exchange_response_t *spdm_response;
    2781              :         size_t dhe_key_size;
    2782              :         uint32_t hash_size;
    2783              :         size_t signature_size;
    2784              :         uint32_t hmac_size;
    2785              :         uint8_t *ptr;
    2786              :         void *dhe_context;
    2787              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    2788              :         size_t final_key_size;
    2789              :         size_t opaque_key_exchange_rsp_size;
    2790              :         void *data;
    2791              :         size_t data_size;
    2792              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2793              :         uint8_t *cert_buffer;
    2794              :         size_t cert_buffer_size;
    2795              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2796              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    2797              :         uint8_t bin_str0[128];
    2798              :         size_t bin_str0_size;
    2799              :         uint8_t bin_str2[128];
    2800              :         size_t bin_str2_size;
    2801              :         uint8_t bin_str7[128];
    2802              :         size_t bin_str7_size;
    2803              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2804              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2805              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2806              :         size_t spdm_response_size;
    2807              :         size_t transport_header_size;
    2808              : 
    2809              :         ((libspdm_context_t *)spdm_context)
    2810            1 :         ->connection_info.algorithm.base_asym_algo =
    2811              :             m_libspdm_use_asym_algo;
    2812              :         ((libspdm_context_t *)spdm_context)
    2813            1 :         ->connection_info.algorithm.base_hash_algo =
    2814              :             m_libspdm_use_hash_algo;
    2815              :         ((libspdm_context_t *)spdm_context)
    2816            1 :         ->connection_info.algorithm.dhe_named_group =
    2817              :             m_libspdm_use_dhe_algo;
    2818              :         ((libspdm_context_t *)spdm_context)
    2819            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2820              :             m_libspdm_use_measurement_hash_algo;
    2821            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2822            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2823            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2824            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    2825            1 :         opaque_key_exchange_rsp_size =
    2826            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2827              :                 spdm_context);
    2828            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    2829            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    2830            1 :                              opaque_key_exchange_rsp_size + signature_size +
    2831              :                              hmac_size;
    2832            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2833            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2834            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    2835              : 
    2836            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2837            1 :         spdm_response->header.request_response_code =
    2838              :             SPDM_KEY_EXCHANGE_RSP;
    2839            1 :         spdm_response->header.param1 = 5;
    2840            1 :         spdm_response->rsp_session_id =
    2841            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    2842            1 :         spdm_response->mut_auth_requested = 0;
    2843            1 :         spdm_response->req_slot_id_param = 0;
    2844            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    2845            1 :                                   spdm_response->random_data);
    2846            1 :         ptr = (void *)(spdm_response + 1);
    2847            1 :         dhe_context = libspdm_dhe_new(
    2848            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2849              :                 m_libspdm_use_dhe_algo,
    2850              :                 true);
    2851            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    2852              :                                  &dhe_key_size);
    2853            1 :         final_key_size = sizeof(final_key);
    2854            1 :         libspdm_dhe_compute_key(
    2855              :             m_libspdm_use_dhe_algo, dhe_context,
    2856            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    2857              :             sizeof(spdm_key_exchange_request_t),
    2858              :             dhe_key_size, final_key, &final_key_size);
    2859            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    2860            1 :         ptr += dhe_key_size;
    2861              :         /* libspdm_zero_mem (ptr, hash_size);
    2862              :          * ptr += hash_size;*/
    2863            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    2864            1 :         ptr += sizeof(uint16_t);
    2865            1 :         libspdm_build_opaque_data_version_selection_data(
    2866              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2867              :                 &opaque_key_exchange_rsp_size, ptr);
    2868            1 :         ptr += opaque_key_exchange_rsp_size;
    2869            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2870              :                                                         m_libspdm_use_asym_algo, &data,
    2871              :                                                         &data_size, NULL, NULL);
    2872            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2873              :                          sizeof(m_libspdm_local_buffer)
    2874            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2875              :                             m_libspdm_local_buffer),
    2876            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2877            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2878            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2879              :                        m_libspdm_local_buffer_size));
    2880            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2881            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    2882            1 :         cert_buffer =  (uint8_t *)data;
    2883            1 :         cert_buffer_size = data_size;
    2884            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    2885              :                          cert_buffer_hash);
    2886              :         /* transcript.message_a size is 0*/
    2887            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    2888            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    2889              :                                       m_libspdm_local_buffer_size);
    2890            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2891              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2892            1 :         free(data);
    2893            1 :         libspdm_responder_data_sign(
    2894              :             spdm_context,
    2895            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2896              :                 SPDM_KEY_EXCHANGE_RSP,
    2897              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2898            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    2899              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    2900              :                 &signature_size);
    2901            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2902              :                          sizeof(m_libspdm_local_buffer)
    2903            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2904              :                             m_libspdm_local_buffer),
    2905              :                          ptr, signature_size);
    2906            1 :         m_libspdm_local_buffer_size += signature_size;
    2907            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    2908            1 :         ptr += signature_size;
    2909            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2910              :                          libspdm_get_managed_buffer_size(&th_curr),
    2911              :                          th_curr_hash_data);
    2912            1 :         bin_str0_size = sizeof(bin_str0);
    2913            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2914              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    2915            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    2916              :                            &bin_str0_size);
    2917            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    2918              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    2919            1 :         bin_str2_size = sizeof(bin_str2);
    2920            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2921              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    2922            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    2923              :                            bin_str2, &bin_str2_size);
    2924            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    2925              :                             bin_str2, bin_str2_size,
    2926              :                             response_handshake_secret, hash_size);
    2927            1 :         bin_str7_size = sizeof(bin_str7);
    2928            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    2929              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    2930            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    2931              :                            &bin_str7_size);
    2932            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    2933              :                             hash_size, bin_str7, bin_str7_size,
    2934              :                             response_finished_key, hash_size);
    2935            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    2936              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    2937            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    2938              :                          response_finished_key, hash_size, ptr);
    2939            1 :         ptr += hmac_size;
    2940              : 
    2941            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2942              :                                               false, spdm_response_size,
    2943              :                                               spdm_response, response_size,
    2944              :                                               response);
    2945              :     }
    2946            1 :         return LIBSPDM_STATUS_SUCCESS;
    2947              : 
    2948            1 :     case 0x15: {
    2949              :         spdm_key_exchange_response_t *spdm_response;
    2950              :         size_t dhe_key_size;
    2951              :         uint32_t hash_size;
    2952              :         size_t signature_size;
    2953              :         uint32_t hmac_size;
    2954              :         uint8_t *ptr;
    2955              :         void *dhe_context;
    2956              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    2957              :         size_t final_key_size;
    2958              :         size_t opaque_key_exchange_rsp_size;
    2959              :         void *data;
    2960              :         size_t data_size;
    2961              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2962              :         uint8_t *cert_buffer;
    2963              :         size_t cert_buffer_size;
    2964              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2965              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    2966              :         uint8_t bin_str0[128];
    2967              :         size_t bin_str0_size;
    2968              :         uint8_t bin_str2[128];
    2969              :         size_t bin_str2_size;
    2970              :         uint8_t bin_str7[128];
    2971              :         size_t bin_str7_size;
    2972              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2973              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    2974              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    2975              :         size_t spdm_response_size;
    2976              :         size_t transport_header_size;
    2977              : 
    2978              :         ((libspdm_context_t *)spdm_context)
    2979            1 :         ->connection_info.algorithm.base_asym_algo =
    2980              :             m_libspdm_use_asym_algo;
    2981              :         ((libspdm_context_t *)spdm_context)
    2982            1 :         ->connection_info.algorithm.base_hash_algo =
    2983              :             m_libspdm_use_hash_algo;
    2984              :         ((libspdm_context_t *)spdm_context)
    2985            1 :         ->connection_info.algorithm.dhe_named_group =
    2986              :             m_libspdm_use_dhe_algo;
    2987              :         ((libspdm_context_t *)spdm_context)
    2988            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2989              :             m_libspdm_use_measurement_hash_algo;
    2990            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2991            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2992            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    2993            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    2994            1 :         opaque_key_exchange_rsp_size =
    2995            1 :             libspdm_get_opaque_data_version_selection_data_size(
    2996              :                 spdm_context);
    2997            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    2998            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    2999            1 :                              opaque_key_exchange_rsp_size + signature_size +
    3000              :                              hmac_size;
    3001            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    3002            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    3003            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    3004              : 
    3005            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    3006            1 :         spdm_response->header.request_response_code =
    3007              :             SPDM_KEY_EXCHANGE_RSP;
    3008            1 :         spdm_response->header.param1 = 5;
    3009            1 :         spdm_response->rsp_session_id =
    3010            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    3011            1 :         spdm_response->mut_auth_requested = 0;
    3012            1 :         spdm_response->req_slot_id_param = 0;
    3013            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    3014            1 :                                   spdm_response->random_data);
    3015            1 :         ptr = (void *)(spdm_response + 1);
    3016            1 :         dhe_context = libspdm_dhe_new(
    3017            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3018              :                 m_libspdm_use_dhe_algo,
    3019              :                 true);
    3020            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    3021              :                                  &dhe_key_size);
    3022            1 :         final_key_size = sizeof(final_key);
    3023            1 :         libspdm_dhe_compute_key(
    3024              :             m_libspdm_use_dhe_algo, dhe_context,
    3025            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    3026              :             sizeof(spdm_key_exchange_request_t),
    3027              :             dhe_key_size, final_key, &final_key_size);
    3028            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    3029            1 :         ptr += dhe_key_size;
    3030              :         /* libspdm_zero_mem (ptr, hash_size);
    3031              :          * ptr += hash_size;*/
    3032            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    3033            1 :         ptr += sizeof(uint16_t);
    3034            1 :         libspdm_build_opaque_data_version_selection_data(
    3035              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3036              :                 &opaque_key_exchange_rsp_size, ptr);
    3037            1 :         ptr += opaque_key_exchange_rsp_size;
    3038            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3039              :                                                         m_libspdm_use_asym_algo, &data,
    3040              :                                                         &data_size, NULL, NULL);
    3041            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3042              :                          sizeof(m_libspdm_local_buffer)
    3043            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3044              :                             m_libspdm_local_buffer),
    3045            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    3046            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    3047            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    3048              :                        m_libspdm_local_buffer_size));
    3049            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3050            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    3051            1 :         cert_buffer = (uint8_t *)data;
    3052            1 :         cert_buffer_size = data_size;
    3053            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    3054              :                          cert_buffer_hash);
    3055              :         /* transcript.message_a size is 0*/
    3056            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    3057            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    3058              :                                       m_libspdm_local_buffer_size);
    3059            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3060              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3061            1 :         free(data);
    3062            1 :         libspdm_responder_data_sign(
    3063              :             spdm_context,
    3064            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3065              :                 SPDM_KEY_EXCHANGE_RSP,
    3066              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    3067            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    3068              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    3069              :                 &signature_size);
    3070            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3071              :                          sizeof(m_libspdm_local_buffer)
    3072            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3073              :                             m_libspdm_local_buffer),
    3074              :                          ptr, signature_size);
    3075            1 :         m_libspdm_local_buffer_size += signature_size;
    3076            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    3077            1 :         ptr += signature_size;
    3078            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3079              :                          libspdm_get_managed_buffer_size(&th_curr),
    3080              :                          th_curr_hash_data);
    3081            1 :         bin_str0_size = sizeof(bin_str0);
    3082            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3083              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    3084            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    3085              :                            &bin_str0_size);
    3086            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    3087              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    3088            1 :         bin_str2_size = sizeof(bin_str2);
    3089            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3090              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    3091            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    3092              :                            bin_str2, &bin_str2_size);
    3093            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    3094              :                             bin_str2, bin_str2_size,
    3095              :                             response_handshake_secret, hash_size);
    3096            1 :         bin_str7_size = sizeof(bin_str7);
    3097            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3098              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    3099            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    3100              :                            &bin_str7_size);
    3101            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    3102              :                             hash_size, bin_str7, bin_str7_size,
    3103              :                             response_finished_key, hash_size);
    3104            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3105              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3106            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    3107              :                          response_finished_key, hash_size, ptr);
    3108            1 :         ptr += hmac_size;
    3109              : 
    3110            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3111              :                                               false, spdm_response_size,
    3112              :                                               spdm_response, response_size,
    3113              :                                               response);
    3114              :     }
    3115            1 :         return LIBSPDM_STATUS_SUCCESS;
    3116              : 
    3117            1 :     case 0x16: {
    3118              :         spdm_key_exchange_response_t *spdm_response;
    3119              :         size_t dhe_key_size;
    3120              :         uint32_t hash_size;
    3121              :         size_t signature_size;
    3122              :         uint32_t hmac_size;
    3123              :         uint8_t *ptr;
    3124              :         void *dhe_context;
    3125              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    3126              :         size_t final_key_size;
    3127              :         size_t opaque_key_exchange_rsp_size;
    3128              :         void *data;
    3129              :         size_t data_size;
    3130              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    3131              :         uint8_t *cert_buffer;
    3132              :         size_t cert_buffer_size;
    3133              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    3134              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    3135              :         uint8_t bin_str0[128];
    3136              :         size_t bin_str0_size;
    3137              :         uint8_t bin_str2[128];
    3138              :         size_t bin_str2_size;
    3139              :         uint8_t bin_str7[128];
    3140              :         size_t bin_str7_size;
    3141              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3142              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3143              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    3144              :         size_t spdm_response_size;
    3145              :         size_t transport_header_size;
    3146              : 
    3147              :         ((libspdm_context_t *)spdm_context)
    3148            1 :         ->connection_info.algorithm.base_asym_algo =
    3149              :             m_libspdm_use_asym_algo;
    3150              :         ((libspdm_context_t *)spdm_context)
    3151            1 :         ->connection_info.algorithm.base_hash_algo =
    3152              :             m_libspdm_use_hash_algo;
    3153              :         ((libspdm_context_t *)spdm_context)
    3154            1 :         ->connection_info.algorithm.dhe_named_group =
    3155              :             m_libspdm_use_dhe_algo;
    3156              :         ((libspdm_context_t *)spdm_context)
    3157            1 :         ->connection_info.algorithm.measurement_hash_algo =
    3158              :             m_libspdm_use_measurement_hash_algo;
    3159            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    3160            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3161            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3162            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    3163            1 :         opaque_key_exchange_rsp_size =
    3164            1 :             libspdm_get_opaque_data_version_selection_data_size(
    3165              :                 spdm_context);
    3166            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    3167            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    3168            1 :                              opaque_key_exchange_rsp_size + signature_size +
    3169              :                              hmac_size;
    3170            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    3171            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    3172            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    3173              : 
    3174            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    3175            1 :         spdm_response->header.request_response_code =
    3176              :             SPDM_KEY_EXCHANGE_RSP;
    3177            1 :         spdm_response->header.param1 = 0;
    3178            1 :         spdm_response->rsp_session_id =
    3179            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    3180            1 :         spdm_response->mut_auth_requested = 0;
    3181            1 :         spdm_response->req_slot_id_param = 0;
    3182            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    3183            1 :                                   spdm_response->random_data);
    3184            1 :         ptr = (void *)(spdm_response + 1);
    3185            1 :         dhe_context = libspdm_dhe_new(
    3186            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3187              :                 m_libspdm_use_dhe_algo,
    3188              :                 true);
    3189            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    3190              :                                  &dhe_key_size);
    3191            1 :         final_key_size = sizeof(final_key);
    3192            1 :         libspdm_dhe_compute_key(
    3193              :             m_libspdm_use_dhe_algo, dhe_context,
    3194            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    3195              :             sizeof(spdm_key_exchange_request_t),
    3196              :             dhe_key_size, final_key, &final_key_size);
    3197            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    3198            1 :         ptr += dhe_key_size;
    3199              :         /* libspdm_zero_mem (ptr, hash_size);
    3200              :          * ptr += hash_size;*/
    3201            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    3202            1 :         ptr += sizeof(uint16_t);
    3203            1 :         libspdm_build_opaque_data_version_selection_data(
    3204              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3205              :                 &opaque_key_exchange_rsp_size, ptr);
    3206            1 :         ptr += opaque_key_exchange_rsp_size;
    3207            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3208              :                                                         m_libspdm_use_asym_algo, &data,
    3209              :                                                         &data_size, NULL, NULL);
    3210            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3211              :                          sizeof(m_libspdm_local_buffer)
    3212            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3213              :                             m_libspdm_local_buffer),
    3214            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    3215            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    3216            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    3217              :                        m_libspdm_local_buffer_size));
    3218            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3219            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    3220            1 :         cert_buffer =  (uint8_t *)data;
    3221            1 :         cert_buffer_size = data_size;
    3222            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    3223              :                          cert_buffer_hash);
    3224              :         /* transcript.message_a size is 0*/
    3225            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    3226            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    3227              :                                       m_libspdm_local_buffer_size);
    3228            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3229              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3230            1 :         free(data);
    3231            1 :         libspdm_responder_data_sign(
    3232              :             spdm_context,
    3233            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3234              :                 SPDM_KEY_EXCHANGE_RSP,
    3235              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    3236            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    3237              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    3238              :                 &signature_size);
    3239            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3240              :                          sizeof(m_libspdm_local_buffer)
    3241            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3242              :                             m_libspdm_local_buffer),
    3243              :                          ptr, signature_size);
    3244            1 :         m_libspdm_local_buffer_size += signature_size;
    3245            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    3246            1 :         ptr += signature_size;
    3247            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3248              :                          libspdm_get_managed_buffer_size(&th_curr),
    3249              :                          th_curr_hash_data);
    3250            1 :         bin_str0_size = sizeof(bin_str0);
    3251            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3252              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    3253            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    3254              :                            &bin_str0_size);
    3255            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    3256              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    3257            1 :         bin_str2_size = sizeof(bin_str2);
    3258            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3259              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    3260            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    3261              :                            bin_str2, &bin_str2_size);
    3262            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    3263              :                             bin_str2, bin_str2_size,
    3264              :                             response_handshake_secret, hash_size);
    3265            1 :         bin_str7_size = sizeof(bin_str7);
    3266            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3267              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    3268            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    3269              :                            &bin_str7_size);
    3270            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    3271              :                             hash_size, bin_str7, bin_str7_size,
    3272              :                             response_finished_key, hash_size);
    3273            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3274              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3275            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    3276              :                          response_finished_key, hash_size, ptr);
    3277            1 :         ptr += hmac_size;
    3278              : 
    3279            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3280              :                                               false, spdm_response_size,
    3281              :                                               spdm_response, response_size,
    3282              :                                               response);
    3283              :     }
    3284            1 :         return LIBSPDM_STATUS_SUCCESS;
    3285              : 
    3286            1 :     case 0x17: {
    3287              :         spdm_key_exchange_response_t *spdm_response;
    3288              :         size_t dhe_key_size;
    3289              :         uint32_t hash_size;
    3290              :         size_t signature_size;
    3291              :         uint32_t hmac_size;
    3292              :         uint8_t *ptr;
    3293              :         void *dhe_context;
    3294              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    3295              :         size_t final_key_size;
    3296              :         size_t opaque_key_exchange_rsp_size;
    3297              :         void *data;
    3298              :         size_t data_size;
    3299              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    3300              :         uint8_t *cert_buffer;
    3301              :         size_t cert_buffer_size;
    3302              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    3303              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    3304              :         uint8_t bin_str0[128];
    3305              :         size_t bin_str0_size;
    3306              :         uint8_t bin_str2[128];
    3307              :         size_t bin_str2_size;
    3308              :         uint8_t bin_str7[128];
    3309              :         size_t bin_str7_size;
    3310              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3311              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3312              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    3313              :         size_t spdm_response_size;
    3314              :         size_t transport_header_size;
    3315              : 
    3316              :         ((libspdm_context_t *)spdm_context)
    3317            1 :         ->connection_info.algorithm.base_asym_algo =
    3318              :             m_libspdm_use_asym_algo;
    3319              :         ((libspdm_context_t *)spdm_context)
    3320            1 :         ->connection_info.algorithm.base_hash_algo =
    3321              :             m_libspdm_use_hash_algo;
    3322              :         ((libspdm_context_t *)spdm_context)
    3323            1 :         ->connection_info.algorithm.dhe_named_group =
    3324              :             m_libspdm_use_dhe_algo;
    3325              :         ((libspdm_context_t *)spdm_context)
    3326            1 :         ->connection_info.algorithm.measurement_hash_algo =
    3327              :             m_libspdm_use_measurement_hash_algo;
    3328            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    3329            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3330            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3331            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    3332            1 :         opaque_key_exchange_rsp_size =
    3333            1 :             libspdm_get_opaque_data_version_selection_data_size(
    3334              :                 spdm_context);
    3335            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    3336            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    3337            1 :                              opaque_key_exchange_rsp_size + signature_size +
    3338              :                              hmac_size;
    3339            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    3340            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    3341            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    3342              : 
    3343            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    3344            1 :         spdm_response->header.request_response_code =
    3345              :             SPDM_KEY_EXCHANGE_RSP;
    3346            1 :         spdm_response->header.param1 = 0;
    3347            1 :         spdm_response->rsp_session_id =
    3348            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    3349            1 :         spdm_response->mut_auth_requested =
    3350              :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED;
    3351            1 :         spdm_response->req_slot_id_param = 0xF;
    3352            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    3353            1 :                                   spdm_response->random_data);
    3354            1 :         ptr = (void *)(spdm_response + 1);
    3355            1 :         dhe_context = libspdm_dhe_new(
    3356            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3357              :                 m_libspdm_use_dhe_algo,
    3358              :                 true);
    3359            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    3360              :                                  &dhe_key_size);
    3361            1 :         final_key_size = sizeof(final_key);
    3362            1 :         libspdm_dhe_compute_key(
    3363              :             m_libspdm_use_dhe_algo, dhe_context,
    3364            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    3365              :             sizeof(spdm_key_exchange_request_t),
    3366              :             dhe_key_size, final_key, &final_key_size);
    3367            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    3368            1 :         ptr += dhe_key_size;
    3369              :         /* libspdm_zero_mem (ptr, hash_size);
    3370              :          * ptr += hash_size;*/
    3371            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    3372            1 :         ptr += sizeof(uint16_t);
    3373            1 :         libspdm_build_opaque_data_version_selection_data(
    3374              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3375              :                 &opaque_key_exchange_rsp_size, ptr);
    3376            1 :         ptr += opaque_key_exchange_rsp_size;
    3377            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3378              :                                                         m_libspdm_use_asym_algo, &data,
    3379              :                                                         &data_size, NULL, NULL);
    3380            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3381              :                          sizeof(m_libspdm_local_buffer)
    3382            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3383              :                             m_libspdm_local_buffer),
    3384            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    3385            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    3386            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    3387              :                        m_libspdm_local_buffer_size));
    3388            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3389            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    3390            1 :         cert_buffer =  (uint8_t *)data;
    3391            1 :         cert_buffer_size = data_size;
    3392            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    3393              :                          cert_buffer_hash);
    3394              :         /* transcript.message_a size is 0*/
    3395            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    3396            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    3397              :                                       m_libspdm_local_buffer_size);
    3398            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3399              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3400            1 :         free(data);
    3401            1 :         libspdm_responder_data_sign(
    3402              :             spdm_context,
    3403            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3404              :                 SPDM_KEY_EXCHANGE_RSP,
    3405              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    3406            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    3407              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    3408              :                 &signature_size);
    3409            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3410              :                          sizeof(m_libspdm_local_buffer)
    3411            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3412              :                             m_libspdm_local_buffer),
    3413              :                          ptr, signature_size);
    3414            1 :         m_libspdm_local_buffer_size += signature_size;
    3415            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    3416            1 :         ptr += signature_size;
    3417            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3418              :                          libspdm_get_managed_buffer_size(&th_curr),
    3419              :                          th_curr_hash_data);
    3420            1 :         bin_str0_size = sizeof(bin_str0);
    3421            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3422              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    3423            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    3424              :                            &bin_str0_size);
    3425            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    3426              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    3427            1 :         bin_str2_size = sizeof(bin_str2);
    3428            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3429              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    3430            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    3431              :                            bin_str2, &bin_str2_size);
    3432            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    3433              :                             bin_str2, bin_str2_size,
    3434              :                             response_handshake_secret, hash_size);
    3435            1 :         bin_str7_size = sizeof(bin_str7);
    3436            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3437              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    3438            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    3439              :                            &bin_str7_size);
    3440            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    3441              :                             hash_size, bin_str7, bin_str7_size,
    3442              :                             response_finished_key, hash_size);
    3443            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3444              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3445            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    3446              :                          response_finished_key, hash_size, ptr);
    3447            1 :         ptr += hmac_size;
    3448              : 
    3449            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3450              :                                               false, spdm_response_size,
    3451              :                                               spdm_response, response_size,
    3452              :                                               response);
    3453              :     }
    3454            1 :         return LIBSPDM_STATUS_SUCCESS;
    3455              : 
    3456            1 :     case 0x18: {
    3457              :         spdm_key_exchange_response_t *spdm_response;
    3458              :         size_t dhe_key_size;
    3459              :         uint32_t hash_size;
    3460              :         size_t signature_size;
    3461              :         uint32_t hmac_size;
    3462              :         uint8_t *ptr;
    3463              :         void *dhe_context;
    3464              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    3465              :         size_t final_key_size;
    3466              :         size_t opaque_key_exchange_rsp_size;
    3467              :         void *data;
    3468              :         size_t data_size;
    3469              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    3470              :         uint8_t *cert_buffer;
    3471              :         size_t cert_buffer_size;
    3472              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    3473              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    3474              :         uint8_t bin_str0[128];
    3475              :         size_t bin_str0_size;
    3476              :         uint8_t bin_str2[128];
    3477              :         size_t bin_str2_size;
    3478              :         uint8_t bin_str7[128];
    3479              :         size_t bin_str7_size;
    3480              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3481              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3482              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    3483              :         size_t spdm_response_size;
    3484              :         size_t transport_header_size;
    3485              : 
    3486              :         ((libspdm_context_t *)spdm_context)
    3487            1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3488              :         ((libspdm_context_t *)spdm_context)
    3489            1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3490              :         ((libspdm_context_t *)spdm_context)
    3491            1 :         ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    3492              :         ((libspdm_context_t *)spdm_context)
    3493            1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
    3494            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    3495            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3496            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3497            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    3498            1 :         opaque_key_exchange_rsp_size =
    3499            1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
    3500            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    3501            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    3502            1 :                              opaque_key_exchange_rsp_size + signature_size +
    3503              :                              hmac_size;
    3504            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    3505            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    3506            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    3507              : 
    3508            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    3509            1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
    3510            1 :         spdm_response->header.param1 = 0x0;
    3511            1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
    3512            1 :         spdm_response->mut_auth_requested =
    3513              :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
    3514            1 :         spdm_response->req_slot_id_param = 0x0;
    3515            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
    3516            1 :         ptr = (void *)(spdm_response + 1);
    3517            1 :         dhe_context = libspdm_dhe_new(
    3518            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3519              :                 m_libspdm_use_dhe_algo, true);
    3520            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    3521            1 :         final_key_size = sizeof(final_key);
    3522            1 :         libspdm_dhe_compute_key(
    3523              :             m_libspdm_use_dhe_algo, dhe_context,
    3524            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    3525              :             sizeof(spdm_key_exchange_request_t),
    3526              :             dhe_key_size, final_key, &final_key_size);
    3527            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    3528            1 :         ptr += dhe_key_size;
    3529              :         /* libspdm_zero_mem (ptr, hash_size);
    3530              :          * ptr += hash_size;*/
    3531            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    3532            1 :         ptr += sizeof(uint16_t);
    3533            1 :         libspdm_build_opaque_data_version_selection_data(
    3534              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3535              :                 &opaque_key_exchange_rsp_size, ptr);
    3536            1 :         ptr += opaque_key_exchange_rsp_size;
    3537            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3538              :                                                         m_libspdm_use_asym_algo, &data,
    3539              :                                                         &data_size, NULL, NULL);
    3540            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3541              :                          sizeof(m_libspdm_local_buffer)
    3542            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3543              :                             m_libspdm_local_buffer),
    3544            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    3545            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    3546            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    3547              :                        m_libspdm_local_buffer_size));
    3548            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3549            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    3550            1 :         cert_buffer =  (uint8_t *)data;
    3551            1 :         cert_buffer_size = data_size;
    3552            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    3553              :                          cert_buffer_hash);
    3554              :         /* transcript.message_a size is 0*/
    3555            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    3556            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    3557              :                                       m_libspdm_local_buffer_size);
    3558            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3559              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3560            1 :         free(data);
    3561            1 :         libspdm_responder_data_sign(
    3562              :             spdm_context,
    3563            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3564              :                 SPDM_KEY_EXCHANGE_RSP,
    3565              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    3566            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    3567              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    3568              :                 &signature_size);
    3569            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3570              :                          sizeof(m_libspdm_local_buffer)
    3571            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3572              :                             m_libspdm_local_buffer),
    3573              :                          ptr, signature_size);
    3574            1 :         m_libspdm_local_buffer_size += signature_size;
    3575            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    3576            1 :         ptr += signature_size;
    3577            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3578              :                          libspdm_get_managed_buffer_size(&th_curr),
    3579              :                          th_curr_hash_data);
    3580            1 :         bin_str0_size = sizeof(bin_str0);
    3581            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3582              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    3583            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    3584              :                            &bin_str0_size);
    3585            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    3586              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    3587            1 :         bin_str2_size = sizeof(bin_str2);
    3588            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3589              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    3590            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    3591              :                            bin_str2, &bin_str2_size);
    3592            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    3593              :                             bin_str2, bin_str2_size,
    3594              :                             response_handshake_secret, hash_size);
    3595            1 :         bin_str7_size = sizeof(bin_str7);
    3596            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3597              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    3598            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    3599              :                            &bin_str7_size);
    3600            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    3601              :                             hash_size, bin_str7, bin_str7_size,
    3602              :                             response_finished_key, hash_size);
    3603            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3604              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3605            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    3606              :                          response_finished_key, hash_size, ptr);
    3607            1 :         ptr += hmac_size;
    3608              : 
    3609            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3610              :                                               false, spdm_response_size,
    3611              :                                               spdm_response, response_size,
    3612              :                                               response);
    3613              :     }
    3614            1 :         return LIBSPDM_STATUS_SUCCESS;
    3615              : 
    3616            1 :     case 0x19: {
    3617              :         spdm_key_exchange_response_t *spdm_response;
    3618              :         size_t dhe_key_size;
    3619              :         uint32_t hash_size;
    3620              :         size_t signature_size;
    3621              :         uint32_t hmac_size;
    3622              :         uint8_t *ptr;
    3623              :         void *dhe_context;
    3624              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    3625              :         size_t final_key_size;
    3626              :         size_t opaque_key_exchange_rsp_size;
    3627              :         void *data;
    3628              :         size_t data_size;
    3629              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    3630              :         uint8_t *cert_buffer;
    3631              :         size_t cert_buffer_size;
    3632              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    3633              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    3634              :         uint8_t bin_str0[128];
    3635              :         size_t bin_str0_size;
    3636              :         uint8_t bin_str2[128];
    3637              :         size_t bin_str2_size;
    3638              :         uint8_t bin_str7[128];
    3639              :         size_t bin_str7_size;
    3640              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3641              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3642              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    3643              :         size_t spdm_response_size;
    3644              :         size_t transport_header_size;
    3645              : 
    3646              :         ((libspdm_context_t *)spdm_context)
    3647            1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3648              :         ((libspdm_context_t *)spdm_context)
    3649            1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3650              :         ((libspdm_context_t *)spdm_context)
    3651            1 :         ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    3652              :         ((libspdm_context_t *)spdm_context)
    3653            1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
    3654            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    3655            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3656            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3657            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    3658            1 :         opaque_key_exchange_rsp_size =
    3659            1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
    3660            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    3661            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    3662            1 :                              opaque_key_exchange_rsp_size + signature_size +
    3663              :                              hmac_size;
    3664            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    3665            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    3666            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    3667              : 
    3668            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    3669            1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
    3670            1 :         spdm_response->header.param1 = 0;
    3671            1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
    3672            1 :         spdm_response->mut_auth_requested =
    3673              :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
    3674            1 :         spdm_response->req_slot_id_param = 0;
    3675            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    3676            1 :                                   spdm_response->random_data);
    3677            1 :         ptr = (void *)(spdm_response + 1);
    3678            1 :         dhe_context = libspdm_dhe_new(
    3679            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3680              :                 m_libspdm_use_dhe_algo, true);
    3681            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    3682            1 :         final_key_size = sizeof(final_key);
    3683            1 :         libspdm_dhe_compute_key(
    3684              :             m_libspdm_use_dhe_algo, dhe_context,
    3685            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    3686              :             sizeof(spdm_key_exchange_request_t),
    3687              :             dhe_key_size, final_key, &final_key_size);
    3688            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    3689            1 :         ptr += dhe_key_size;
    3690              :         /* libspdm_zero_mem (ptr, hash_size);
    3691              :          * ptr += hash_size;*/
    3692            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    3693            1 :         ptr += sizeof(uint16_t);
    3694            1 :         libspdm_build_opaque_data_version_selection_data(
    3695              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3696              :                 &opaque_key_exchange_rsp_size, ptr);
    3697            1 :         ptr += opaque_key_exchange_rsp_size;
    3698            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3699              :                                                         m_libspdm_use_asym_algo, &data,
    3700              :                                                         &data_size, NULL, NULL);
    3701            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3702              :                          sizeof(m_libspdm_local_buffer)
    3703            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3704              :                             m_libspdm_local_buffer),
    3705            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    3706            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    3707            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    3708              :                        m_libspdm_local_buffer_size));
    3709            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3710            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    3711            1 :         cert_buffer =  (uint8_t *)data;
    3712            1 :         cert_buffer_size = data_size;
    3713            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    3714              :                          cert_buffer_hash);
    3715              :         /* transcript.message_a size is 0*/
    3716            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    3717            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    3718              :                                       m_libspdm_local_buffer_size);
    3719            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3720              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3721            1 :         free(data);
    3722            1 :         libspdm_responder_data_sign(
    3723              :             spdm_context,
    3724            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3725              :                 SPDM_KEY_EXCHANGE_RSP,
    3726              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    3727            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    3728              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    3729              :                 &signature_size);
    3730            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3731              :                          sizeof(m_libspdm_local_buffer)
    3732            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3733              :                             m_libspdm_local_buffer),
    3734              :                          ptr, signature_size);
    3735            1 :         m_libspdm_local_buffer_size += signature_size;
    3736            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    3737            1 :         ptr += signature_size;
    3738            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3739              :                          libspdm_get_managed_buffer_size(&th_curr),
    3740              :                          th_curr_hash_data);
    3741            1 :         bin_str0_size = sizeof(bin_str0);
    3742            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3743              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    3744            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    3745              :                            &bin_str0_size);
    3746            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    3747              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    3748            1 :         bin_str2_size = sizeof(bin_str2);
    3749            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3750              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    3751            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    3752              :                            bin_str2, &bin_str2_size);
    3753            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    3754              :                             bin_str2, bin_str2_size,
    3755              :                             response_handshake_secret, hash_size);
    3756            1 :         bin_str7_size = sizeof(bin_str7);
    3757            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3758              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    3759            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    3760              :                            &bin_str7_size);
    3761            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    3762              :                             hash_size, bin_str7, bin_str7_size,
    3763              :                             response_finished_key, hash_size);
    3764            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3765              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3766            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    3767              :                          response_finished_key, hash_size, ptr);
    3768            1 :         ptr += hmac_size;
    3769              : 
    3770            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3771              :                                               false, spdm_response_size,
    3772              :                                               spdm_response, response_size,
    3773              :                                               response);
    3774              :     }
    3775            1 :         return LIBSPDM_STATUS_SUCCESS;
    3776              : 
    3777            1 :     case 0x1A: {
    3778              :         spdm_key_exchange_response_t *spdm_response;
    3779              :         size_t dhe_key_size;
    3780              :         uint32_t hash_size;
    3781              :         size_t signature_size;
    3782              :         uint32_t hmac_size;
    3783              :         uint8_t *ptr;
    3784              :         void *dhe_context;
    3785              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    3786              :         size_t final_key_size;
    3787              :         size_t opaque_key_exchange_rsp_size;
    3788              :         void *data;
    3789              :         size_t data_size;
    3790              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    3791              :         uint8_t *cert_buffer;
    3792              :         size_t cert_buffer_size;
    3793              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    3794              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    3795              :         uint8_t bin_str0[128];
    3796              :         size_t bin_str0_size;
    3797              :         uint8_t bin_str2[128];
    3798              :         size_t bin_str2_size;
    3799              :         uint8_t bin_str7[128];
    3800              :         size_t bin_str7_size;
    3801              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3802              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3803              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    3804              :         size_t spdm_response_size;
    3805              :         size_t transport_header_size;
    3806              : 
    3807              :         ((libspdm_context_t *)spdm_context)
    3808            1 :         ->connection_info.algorithm.base_asym_algo =
    3809              :             m_libspdm_use_asym_algo;
    3810              :         ((libspdm_context_t *)spdm_context)
    3811            1 :         ->connection_info.algorithm.base_hash_algo =
    3812              :             m_libspdm_use_hash_algo;
    3813              :         ((libspdm_context_t *)spdm_context)
    3814            1 :         ->connection_info.algorithm.dhe_named_group =
    3815              :             m_libspdm_use_dhe_algo;
    3816              :         ((libspdm_context_t *)spdm_context)
    3817            1 :         ->connection_info.algorithm.measurement_hash_algo =
    3818              :             m_libspdm_use_measurement_hash_algo;
    3819            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    3820            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3821            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3822            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    3823            1 :         opaque_key_exchange_rsp_size =
    3824            1 :             libspdm_get_opaque_data_version_selection_data_size(
    3825              :                 spdm_context);
    3826            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    3827            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    3828            1 :                              opaque_key_exchange_rsp_size + signature_size +
    3829              :                              hmac_size;
    3830            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    3831            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    3832            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    3833              : 
    3834            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    3835            1 :         spdm_response->header.request_response_code =
    3836              :             SPDM_KEY_EXCHANGE_RSP;
    3837            1 :         spdm_response->header.param1 = 0;
    3838            1 :         spdm_response->rsp_session_id =
    3839            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    3840            1 :         spdm_response->mut_auth_requested =
    3841              :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED |
    3842              :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST;
    3843            1 :         spdm_response->req_slot_id_param = 0xF;
    3844            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    3845            1 :                                   spdm_response->random_data);
    3846            1 :         ptr = (void *)(spdm_response + 1);
    3847            1 :         dhe_context = libspdm_dhe_new(
    3848            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3849              :                 m_libspdm_use_dhe_algo,
    3850              :                 true);
    3851            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    3852              :                                  &dhe_key_size);
    3853            1 :         final_key_size = sizeof(final_key);
    3854            1 :         libspdm_dhe_compute_key(
    3855              :             m_libspdm_use_dhe_algo, dhe_context,
    3856            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    3857              :             sizeof(spdm_key_exchange_request_t),
    3858              :             dhe_key_size, final_key, &final_key_size);
    3859            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    3860            1 :         ptr += dhe_key_size;
    3861              :         /* libspdm_zero_mem (ptr, hash_size);
    3862              :          * ptr += hash_size;*/
    3863            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    3864            1 :         ptr += sizeof(uint16_t);
    3865            1 :         libspdm_build_opaque_data_version_selection_data(
    3866              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3867              :                 &opaque_key_exchange_rsp_size, ptr);
    3868            1 :         ptr += opaque_key_exchange_rsp_size;
    3869            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3870              :                                                         m_libspdm_use_asym_algo, &data,
    3871              :                                                         &data_size, NULL, NULL);
    3872            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3873              :                          sizeof(m_libspdm_local_buffer)
    3874            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3875              :                             m_libspdm_local_buffer),
    3876            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    3877            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    3878            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    3879              :                        m_libspdm_local_buffer_size));
    3880            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3881            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    3882            1 :         cert_buffer =  (uint8_t *)data;
    3883            1 :         cert_buffer_size = data_size;
    3884            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    3885              :                          cert_buffer_hash);
    3886              :         /* transcript.message_a size is 0*/
    3887            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    3888            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    3889              :                                       m_libspdm_local_buffer_size);
    3890            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3891              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3892            1 :         free(data);
    3893            1 :         libspdm_responder_data_sign(
    3894              :             spdm_context,
    3895            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3896              :                 SPDM_KEY_EXCHANGE_RSP,
    3897              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    3898            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    3899              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    3900              :                 &signature_size);
    3901            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3902              :                          sizeof(m_libspdm_local_buffer)
    3903            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3904              :                             m_libspdm_local_buffer),
    3905              :                          ptr, signature_size);
    3906            1 :         m_libspdm_local_buffer_size += signature_size;
    3907            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    3908            1 :         ptr += signature_size;
    3909            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3910              :                          libspdm_get_managed_buffer_size(&th_curr),
    3911              :                          th_curr_hash_data);
    3912            1 :         bin_str0_size = sizeof(bin_str0);
    3913            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3914              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    3915            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    3916              :                            &bin_str0_size);
    3917            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    3918              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    3919            1 :         bin_str2_size = sizeof(bin_str2);
    3920            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3921              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    3922            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    3923              :                            bin_str2, &bin_str2_size);
    3924            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    3925              :                             bin_str2, bin_str2_size,
    3926              :                             response_handshake_secret, hash_size);
    3927            1 :         bin_str7_size = sizeof(bin_str7);
    3928            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    3929              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    3930            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    3931              :                            &bin_str7_size);
    3932            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    3933              :                             hash_size, bin_str7, bin_str7_size,
    3934              :                             response_finished_key, hash_size);
    3935            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    3936              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    3937            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    3938              :                          response_finished_key, hash_size, ptr);
    3939            1 :         ptr += hmac_size;
    3940              : 
    3941            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3942              :                                               false, spdm_response_size,
    3943              :                                               spdm_response, response_size,
    3944              :                                               response);
    3945              :     }
    3946            1 :         return LIBSPDM_STATUS_SUCCESS;
    3947              : 
    3948            1 :     case 0x1B: {
    3949              :         spdm_key_exchange_response_t *spdm_response;
    3950              :         size_t dhe_key_size;
    3951              :         uint32_t hash_size;
    3952              :         size_t signature_size;
    3953              :         uint32_t hmac_size;
    3954              :         uint8_t *ptr;
    3955              :         void *dhe_context;
    3956              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    3957              :         size_t final_key_size;
    3958              :         size_t opaque_key_exchange_rsp_size;
    3959              :         void *data;
    3960              :         size_t data_size;
    3961              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    3962              :         uint8_t *cert_buffer;
    3963              :         size_t cert_buffer_size;
    3964              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    3965              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    3966              :         uint8_t bin_str0[128];
    3967              :         size_t bin_str0_size;
    3968              :         uint8_t bin_str2[128];
    3969              :         size_t bin_str2_size;
    3970              :         uint8_t bin_str7[128];
    3971              :         size_t bin_str7_size;
    3972              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3973              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    3974              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    3975              :         size_t spdm_response_size;
    3976              :         size_t transport_header_size;
    3977              : 
    3978              :         ((libspdm_context_t *)spdm_context)
    3979            1 :         ->connection_info.algorithm.base_asym_algo =
    3980              :             m_libspdm_use_asym_algo;
    3981              :         ((libspdm_context_t *)spdm_context)
    3982            1 :         ->connection_info.algorithm.base_hash_algo =
    3983              :             m_libspdm_use_hash_algo;
    3984              :         ((libspdm_context_t *)spdm_context)
    3985            1 :         ->connection_info.algorithm.dhe_named_group =
    3986              :             m_libspdm_use_dhe_algo;
    3987              :         ((libspdm_context_t *)spdm_context)
    3988            1 :         ->connection_info.algorithm.measurement_hash_algo =
    3989              :             m_libspdm_use_measurement_hash_algo;
    3990            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    3991            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3992            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    3993            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    3994            1 :         opaque_key_exchange_rsp_size =
    3995            1 :             libspdm_get_opaque_data_version_selection_data_size(
    3996              :                 spdm_context);
    3997            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    3998            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    3999            1 :                              opaque_key_exchange_rsp_size + signature_size +
    4000              :                              hmac_size;
    4001            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    4002            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    4003            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    4004              : 
    4005            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    4006            1 :         spdm_response->header.request_response_code =
    4007              :             SPDM_KEY_EXCHANGE_RSP;
    4008            1 :         spdm_response->header.param1 = 0;
    4009            1 :         spdm_response->rsp_session_id =
    4010            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    4011            1 :         spdm_response->mut_auth_requested =
    4012              :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED |
    4013              :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
    4014            1 :         spdm_response->req_slot_id_param = 0xF;
    4015            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    4016            1 :                                   spdm_response->random_data);
    4017            1 :         ptr = (void *)(spdm_response + 1);
    4018            1 :         dhe_context = libspdm_dhe_new(
    4019            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4020              :                 m_libspdm_use_dhe_algo,
    4021              :                 true);
    4022            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    4023              :                                  &dhe_key_size);
    4024            1 :         final_key_size = sizeof(final_key);
    4025            1 :         libspdm_dhe_compute_key(
    4026              :             m_libspdm_use_dhe_algo, dhe_context,
    4027            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    4028              :             sizeof(spdm_key_exchange_request_t),
    4029              :             dhe_key_size, final_key, &final_key_size);
    4030            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    4031            1 :         ptr += dhe_key_size;
    4032              :         /* libspdm_zero_mem (ptr, hash_size);
    4033              :          * ptr += hash_size;*/
    4034            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    4035            1 :         ptr += sizeof(uint16_t);
    4036            1 :         libspdm_build_opaque_data_version_selection_data(
    4037              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4038              :                 &opaque_key_exchange_rsp_size, ptr);
    4039            1 :         ptr += opaque_key_exchange_rsp_size;
    4040            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4041              :                                                         m_libspdm_use_asym_algo, &data,
    4042              :                                                         &data_size, NULL, NULL);
    4043            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4044              :                          sizeof(m_libspdm_local_buffer)
    4045            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    4046              :                             m_libspdm_local_buffer),
    4047            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    4048            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    4049            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    4050              :                        m_libspdm_local_buffer_size));
    4051            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    4052            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    4053            1 :         cert_buffer =  (uint8_t *)data;
    4054            1 :         cert_buffer_size = data_size;
    4055            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    4056              :                          cert_buffer_hash);
    4057              :         /* transcript.message_a size is 0*/
    4058            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    4059            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    4060              :                                       m_libspdm_local_buffer_size);
    4061            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4062              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4063            1 :         free(data);
    4064            1 :         libspdm_responder_data_sign(
    4065              :             spdm_context,
    4066            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4067              :                 SPDM_KEY_EXCHANGE_RSP,
    4068              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    4069            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    4070              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    4071              :                 &signature_size);
    4072            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4073              :                          sizeof(m_libspdm_local_buffer)
    4074            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    4075              :                             m_libspdm_local_buffer),
    4076              :                          ptr, signature_size);
    4077            1 :         m_libspdm_local_buffer_size += signature_size;
    4078            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    4079            1 :         ptr += signature_size;
    4080            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4081              :                          libspdm_get_managed_buffer_size(&th_curr),
    4082              :                          th_curr_hash_data);
    4083            1 :         bin_str0_size = sizeof(bin_str0);
    4084            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4085              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    4086            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    4087              :                            &bin_str0_size);
    4088            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    4089              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    4090            1 :         bin_str2_size = sizeof(bin_str2);
    4091            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4092              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    4093            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    4094              :                            bin_str2, &bin_str2_size);
    4095            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    4096              :                             bin_str2, bin_str2_size,
    4097              :                             response_handshake_secret, hash_size);
    4098            1 :         bin_str7_size = sizeof(bin_str7);
    4099            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4100              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    4101            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    4102              :                            &bin_str7_size);
    4103            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    4104              :                             hash_size, bin_str7, bin_str7_size,
    4105              :                             response_finished_key, hash_size);
    4106            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4107              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4108            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    4109              :                          response_finished_key, hash_size, ptr);
    4110            1 :         ptr += hmac_size;
    4111              : 
    4112            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    4113              :                                               false, spdm_response_size,
    4114              :                                               spdm_response, response_size,
    4115              :                                               response);
    4116              :     }
    4117            1 :         return LIBSPDM_STATUS_SUCCESS;
    4118              : 
    4119            1 :     case 0x1C: {
    4120              :         spdm_key_exchange_response_t *spdm_response;
    4121              :         size_t dhe_key_size;
    4122              :         uint32_t hash_size;
    4123              :         size_t signature_size;
    4124              :         uint32_t hmac_size;
    4125              :         uint8_t *ptr;
    4126              :         void *dhe_context;
    4127              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    4128              :         size_t final_key_size;
    4129              :         size_t opaque_key_exchange_rsp_size;
    4130              :         void *data;
    4131              :         size_t data_size;
    4132              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    4133              :         uint8_t *cert_buffer;
    4134              :         size_t cert_buffer_size;
    4135              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    4136              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    4137              :         uint8_t bin_str0[128];
    4138              :         size_t bin_str0_size;
    4139              :         uint8_t bin_str2[128];
    4140              :         size_t bin_str2_size;
    4141              :         uint8_t bin_str7[128];
    4142              :         size_t bin_str7_size;
    4143              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4144              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4145              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    4146              :         size_t spdm_response_size;
    4147              :         size_t transport_header_size;
    4148              : 
    4149              :         ((libspdm_context_t *)spdm_context)
    4150            1 :         ->connection_info.algorithm.base_asym_algo =
    4151              :             m_libspdm_use_asym_algo;
    4152              :         ((libspdm_context_t *)spdm_context)
    4153            1 :         ->connection_info.algorithm.base_hash_algo =
    4154              :             m_libspdm_use_hash_algo;
    4155              :         ((libspdm_context_t *)spdm_context)
    4156            1 :         ->connection_info.algorithm.dhe_named_group =
    4157              :             m_libspdm_use_dhe_algo;
    4158              :         ((libspdm_context_t *)spdm_context)
    4159            1 :         ->connection_info.algorithm.measurement_hash_algo =
    4160              :             m_libspdm_use_measurement_hash_algo;
    4161            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    4162            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4163            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4164            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    4165            1 :         opaque_key_exchange_rsp_size =
    4166            1 :             libspdm_get_opaque_data_version_selection_data_size(
    4167              :                 spdm_context);
    4168            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    4169            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    4170            1 :                              opaque_key_exchange_rsp_size + signature_size +
    4171              :                              hmac_size;
    4172            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    4173            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    4174            1 :         libspdm_zero_mem(spdm_response,spdm_response_size);
    4175              : 
    4176            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    4177            1 :         spdm_response->header.request_response_code =
    4178              :             SPDM_KEY_EXCHANGE_RSP;
    4179            1 :         spdm_response->header.param1 = 0;
    4180            1 :         spdm_response->rsp_session_id =
    4181            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    4182            1 :         spdm_response->mut_auth_requested =
    4183              :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST |
    4184              :             SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS;
    4185            1 :         spdm_response->req_slot_id_param = 0xF;
    4186            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    4187            1 :                                   spdm_response->random_data);
    4188            1 :         ptr = (void *)(spdm_response + 1);
    4189            1 :         dhe_context = libspdm_dhe_new(
    4190            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4191              :                 m_libspdm_use_dhe_algo,
    4192              :                 true);
    4193            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    4194              :                                  &dhe_key_size);
    4195            1 :         final_key_size = sizeof(final_key);
    4196            1 :         libspdm_dhe_compute_key(
    4197              :             m_libspdm_use_dhe_algo, dhe_context,
    4198            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    4199              :             sizeof(spdm_key_exchange_request_t),
    4200              :             dhe_key_size, final_key, &final_key_size);
    4201            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    4202            1 :         ptr += dhe_key_size;
    4203              :         /* libspdm_zero_mem (ptr, hash_size);
    4204              :          * ptr += hash_size;*/
    4205            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    4206            1 :         ptr += sizeof(uint16_t);
    4207            1 :         libspdm_build_opaque_data_version_selection_data(
    4208              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4209              :                 &opaque_key_exchange_rsp_size, ptr);
    4210            1 :         ptr += opaque_key_exchange_rsp_size;
    4211            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4212              :                                                         m_libspdm_use_asym_algo, &data,
    4213              :                                                         &data_size, NULL, NULL);
    4214            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4215              :                          sizeof(m_libspdm_local_buffer)
    4216            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    4217              :                             m_libspdm_local_buffer),
    4218            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    4219            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    4220            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    4221              :                        m_libspdm_local_buffer_size));
    4222            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    4223            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    4224            1 :         cert_buffer =  (uint8_t *)data;
    4225            1 :         cert_buffer_size = data_size;
    4226            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    4227              :                          cert_buffer_hash);
    4228              :         /* transcript.message_a size is 0*/
    4229            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    4230            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    4231              :                                       m_libspdm_local_buffer_size);
    4232            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4233              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4234            1 :         free(data);
    4235            1 :         libspdm_responder_data_sign(
    4236              :             spdm_context,
    4237            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4238              :                 SPDM_KEY_EXCHANGE_RSP,
    4239              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    4240            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    4241              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    4242              :                 &signature_size);
    4243            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4244              :                          sizeof(m_libspdm_local_buffer)
    4245            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    4246              :                             m_libspdm_local_buffer),
    4247              :                          ptr, signature_size);
    4248            1 :         m_libspdm_local_buffer_size += signature_size;
    4249            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    4250            1 :         ptr += signature_size;
    4251            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4252              :                          libspdm_get_managed_buffer_size(&th_curr),
    4253              :                          th_curr_hash_data);
    4254            1 :         bin_str0_size = sizeof(bin_str0);
    4255            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4256              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    4257            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    4258              :                            &bin_str0_size);
    4259            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    4260              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    4261            1 :         bin_str2_size = sizeof(bin_str2);
    4262            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4263              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    4264            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    4265              :                            bin_str2, &bin_str2_size);
    4266            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    4267              :                             bin_str2, bin_str2_size,
    4268              :                             response_handshake_secret, hash_size);
    4269            1 :         bin_str7_size = sizeof(bin_str7);
    4270            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4271              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    4272            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    4273              :                            &bin_str7_size);
    4274            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    4275              :                             hash_size, bin_str7, bin_str7_size,
    4276              :                             response_finished_key, hash_size);
    4277            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4278              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4279            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    4280              :                          response_finished_key, hash_size, ptr);
    4281            1 :         ptr += hmac_size;
    4282              : 
    4283            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    4284              :                                               false, spdm_response_size,
    4285              :                                               spdm_response, response_size,
    4286              :                                               response);
    4287              :     }
    4288            1 :         return LIBSPDM_STATUS_SUCCESS;
    4289              : 
    4290            1 :     case 0x1D: {
    4291              :         spdm_key_exchange_response_t *spdm_response;
    4292              :         size_t dhe_key_size;
    4293              :         uint32_t hash_size;
    4294              :         size_t signature_size;
    4295              :         uint32_t hmac_size;
    4296              :         uint8_t *ptr;
    4297              :         void *dhe_context;
    4298              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    4299              :         size_t final_key_size;
    4300              :         size_t opaque_key_exchange_rsp_size;
    4301              :         void *data;
    4302              :         size_t data_size;
    4303              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    4304              :         uint8_t *cert_buffer;
    4305              :         size_t cert_buffer_size;
    4306              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    4307              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    4308              :         uint8_t bin_str0[128];
    4309              :         size_t bin_str0_size;
    4310              :         uint8_t bin_str2[128];
    4311              :         size_t bin_str2_size;
    4312              :         uint8_t bin_str7[128];
    4313              :         size_t bin_str7_size;
    4314              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4315              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4316              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    4317              :         size_t spdm_response_size;
    4318              :         size_t transport_header_size;
    4319              : 
    4320            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_asym_algo =
    4321              :             m_libspdm_use_asym_algo;
    4322            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
    4323              :             m_libspdm_use_hash_algo;
    4324            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.dhe_named_group =
    4325              :             m_libspdm_use_dhe_algo;
    4326            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
    4327              :             m_libspdm_use_measurement_hash_algo;
    4328            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    4329            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4330            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4331            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    4332            1 :         opaque_key_exchange_rsp_size =
    4333            1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
    4334            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    4335            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    4336            1 :                              opaque_key_exchange_rsp_size + signature_size +
    4337              :                              hmac_size;
    4338            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    4339            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    4340              : 
    4341            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    4342            1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
    4343            1 :         spdm_response->header.param1 = 0;
    4344            1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
    4345            1 :         spdm_response->mut_auth_requested = 0;
    4346            1 :         spdm_response->req_slot_id_param = 0;
    4347            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
    4348            1 :         ptr = (void *)(spdm_response + 1);
    4349            1 :         dhe_context = libspdm_dhe_new(
    4350            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4351              :                 m_libspdm_use_dhe_algo, true);
    4352            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    4353            1 :         final_key_size = sizeof(final_key);
    4354            1 :         libspdm_dhe_compute_key(
    4355              :             m_libspdm_use_dhe_algo, dhe_context,
    4356            1 :             (uint8_t *)&m_libspdm_local_buffer[0] + sizeof(spdm_key_exchange_request_t),
    4357              :             dhe_key_size, final_key, &final_key_size);
    4358            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    4359            1 :         ptr += dhe_key_size;
    4360              :         /* libspdm_zero_mem (ptr, hash_size);
    4361              :          * ptr += hash_size;*/
    4362            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    4363            1 :         ptr += sizeof(uint16_t);
    4364            1 :         libspdm_build_opaque_data_version_selection_data(
    4365              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4366              :                 &opaque_key_exchange_rsp_size, ptr);
    4367            1 :         ptr += opaque_key_exchange_rsp_size;
    4368            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4369              :                                                         m_libspdm_use_asym_algo, &data,
    4370              :                                                         &data_size, NULL, NULL);
    4371            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4372              :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
    4373            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    4374            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    4375            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
    4376              :                        m_libspdm_local_buffer_size));
    4377            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    4378            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    4379            1 :         cert_buffer = (uint8_t *)data;
    4380            1 :         cert_buffer_size = data_size;
    4381            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    4382              :                          cert_buffer_hash);
    4383              :         /* transcript.message_a size is 0*/
    4384            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    4385            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    4386              :                                       m_libspdm_local_buffer_size);
    4387            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4388              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4389            1 :         free(data);
    4390            1 :         libspdm_responder_data_sign(
    4391              :             spdm_context,
    4392            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4393              :                 SPDM_KEY_EXCHANGE_RSP,
    4394              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    4395            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    4396              :                 libspdm_get_managed_buffer_size(&th_curr), ptr, &signature_size);
    4397            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4398              :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
    4399              :                          ptr, signature_size);
    4400            1 :         m_libspdm_local_buffer_size += signature_size;
    4401            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    4402            1 :         ptr += signature_size;
    4403            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4404              :                          libspdm_get_managed_buffer_size(&th_curr), th_curr_hash_data);
    4405            1 :         bin_str0_size = sizeof(bin_str0);
    4406            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4407              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    4408            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0, &bin_str0_size);
    4409            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    4410              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    4411            1 :         bin_str2_size = sizeof(bin_str2);
    4412            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4413              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    4414            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    4415              :                            bin_str2, &bin_str2_size);
    4416            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    4417              :                             bin_str2, bin_str2_size,
    4418              :                             response_handshake_secret, hash_size);
    4419            1 :         bin_str7_size = sizeof(bin_str7);
    4420            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4421              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    4422            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    4423              :                            &bin_str7_size);
    4424            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    4425              :                             hash_size, bin_str7, bin_str7_size,
    4426              :                             response_finished_key, hash_size);
    4427            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4428              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4429            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    4430              :                          response_finished_key, hash_size, ptr);
    4431            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4432              :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
    4433              :                          ptr, hmac_size);
    4434            1 :         m_libspdm_local_buffer_size += hmac_size;
    4435            1 :         ptr += hmac_size;
    4436              : 
    4437            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    4438              :                                               false, spdm_response_size,
    4439              :                                               spdm_response, response_size,
    4440              :                                               response);
    4441              :     }
    4442            1 :         return LIBSPDM_STATUS_SUCCESS;
    4443            1 :     case 0x1E: {
    4444              :         spdm_key_exchange_response_t *spdm_response;
    4445              :         size_t dhe_key_size;
    4446              :         uint32_t hash_size;
    4447              :         size_t signature_size;
    4448              :         uint32_t hmac_size;
    4449              :         uint8_t *ptr;
    4450              :         void *dhe_context;
    4451              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    4452              :         size_t final_key_size;
    4453              :         size_t opaque_key_exchange_rsp_size;
    4454              :         void *data;
    4455              :         size_t data_size;
    4456              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    4457              :         uint8_t *cert_buffer;
    4458              :         size_t cert_buffer_size;
    4459              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    4460              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    4461              :         uint8_t bin_str0[128];
    4462              :         size_t bin_str0_size;
    4463              :         uint8_t bin_str2[128];
    4464              :         size_t bin_str2_size;
    4465              :         uint8_t bin_str7[128];
    4466              :         size_t bin_str7_size;
    4467              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4468              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4469              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    4470              :         size_t spdm_response_size;
    4471              :         size_t transport_header_size;
    4472              : 
    4473              : 
    4474              :         ((libspdm_context_t *)spdm_context)
    4475            1 :         ->connection_info.algorithm.base_asym_algo =
    4476              :             m_libspdm_use_asym_algo;
    4477              :         ((libspdm_context_t *)spdm_context)
    4478            1 :         ->connection_info.algorithm.base_hash_algo =
    4479              :             m_libspdm_use_hash_algo;
    4480              :         ((libspdm_context_t *)spdm_context)
    4481            1 :         ->connection_info.algorithm.dhe_named_group =
    4482              :             m_libspdm_use_dhe_algo;
    4483              :         ((libspdm_context_t *)spdm_context)
    4484            1 :         ->connection_info.algorithm.measurement_hash_algo =
    4485              :             m_libspdm_use_measurement_hash_algo;
    4486            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    4487            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4488            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4489            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    4490            1 :         opaque_key_exchange_rsp_size =
    4491            1 :             libspdm_get_opaque_data_version_selection_data_size(
    4492              :                 spdm_context);
    4493            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    4494            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    4495            1 :                              opaque_key_exchange_rsp_size + signature_size +
    4496              :                              hmac_size;
    4497            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    4498            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    4499              : 
    4500            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    4501            1 :         spdm_response->header.request_response_code =
    4502              :             SPDM_KEY_EXCHANGE_RSP;
    4503            1 :         spdm_response->header.param1 = 0;
    4504            1 :         spdm_response->rsp_session_id =
    4505            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    4506            1 :         spdm_response->mut_auth_requested = 0;
    4507            1 :         spdm_response->req_slot_id_param = 0;
    4508            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    4509            1 :                                   spdm_response->random_data);
    4510            1 :         ptr = (void *)(spdm_response + 1);
    4511            1 :         dhe_context = libspdm_dhe_new(
    4512            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4513              :                 m_libspdm_use_dhe_algo,
    4514              :                 true);
    4515            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    4516              :                                  &dhe_key_size);
    4517            1 :         final_key_size = sizeof(final_key);
    4518            1 :         libspdm_dhe_compute_key(
    4519              :             m_libspdm_use_dhe_algo, dhe_context,
    4520            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    4521              :             sizeof(spdm_key_exchange_request_t),
    4522              :             dhe_key_size, final_key, &final_key_size);
    4523            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    4524            1 :         ptr += dhe_key_size;
    4525              :         /* libspdm_zero_mem (ptr, hash_size);
    4526              :          * ptr += hash_size;*/
    4527            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    4528            1 :         ptr += sizeof(uint16_t);
    4529            1 :         libspdm_build_opaque_data_version_selection_data(
    4530              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4531              :                 &opaque_key_exchange_rsp_size, ptr);
    4532            1 :         ptr += opaque_key_exchange_rsp_size;
    4533            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4534              :                                                         m_libspdm_use_asym_algo, &data,
    4535              :                                                         &data_size, NULL, NULL);
    4536            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4537              :                          sizeof(m_libspdm_local_buffer)
    4538            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    4539              :                             m_libspdm_local_buffer),
    4540            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    4541            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    4542            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    4543              :                        m_libspdm_local_buffer_size));
    4544            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    4545            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    4546            1 :         cert_buffer = (uint8_t *)data;
    4547            1 :         cert_buffer_size = data_size;
    4548            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    4549              :                          cert_buffer_hash);
    4550              :         /* transcript.message_a size is 0*/
    4551            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    4552            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    4553              :                                       m_libspdm_local_buffer_size);
    4554            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4555              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4556            1 :         free(data);
    4557            1 :         libspdm_responder_data_sign(
    4558              :             spdm_context,
    4559            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4560              :                 SPDM_KEY_EXCHANGE_RSP,
    4561              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    4562            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    4563              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    4564              :                 &signature_size);
    4565            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4566              :                          sizeof(m_libspdm_local_buffer)
    4567            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    4568              :                             m_libspdm_local_buffer),
    4569              :                          ptr, signature_size);
    4570            1 :         m_libspdm_local_buffer_size += signature_size;
    4571            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    4572            1 :         ptr += signature_size;
    4573            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4574              :                          libspdm_get_managed_buffer_size(&th_curr),
    4575              :                          th_curr_hash_data);
    4576            1 :         bin_str0_size = sizeof(bin_str0);
    4577            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4578              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    4579            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    4580              :                            &bin_str0_size);
    4581            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    4582              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    4583            1 :         bin_str2_size = sizeof(bin_str2);
    4584            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4585              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    4586            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    4587              :                            bin_str2, &bin_str2_size);
    4588            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    4589              :                             bin_str2, bin_str2_size,
    4590              :                             response_handshake_secret, hash_size);
    4591            1 :         bin_str7_size = sizeof(bin_str7);
    4592            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4593              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    4594            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    4595              :                            &bin_str7_size);
    4596            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    4597              :                             hash_size, bin_str7, bin_str7_size,
    4598              :                             response_finished_key, hash_size);
    4599            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4600              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4601            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    4602              :                          response_finished_key, hash_size, ptr);
    4603            1 :         ptr += hmac_size;
    4604              : 
    4605            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    4606              :                                               false, spdm_response_size,
    4607              :                                               spdm_response, response_size,
    4608              :                                               response);
    4609              :     }
    4610            1 :         return LIBSPDM_STATUS_SUCCESS;
    4611              : 
    4612            1 :     case 0x1F: {
    4613              :         spdm_key_exchange_response_t *spdm_response;
    4614              :         size_t dhe_key_size;
    4615              :         uint32_t hash_size;
    4616              :         size_t signature_size;
    4617              :         uint32_t hmac_size;
    4618              :         uint8_t *ptr;
    4619              :         void *dhe_context;
    4620              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    4621              :         size_t final_key_size;
    4622              :         size_t opaque_key_exchange_rsp_size;
    4623              :         void *data;
    4624              :         size_t data_size;
    4625              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    4626              :         uint8_t *cert_buffer;
    4627              :         size_t cert_buffer_size;
    4628              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    4629              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    4630              :         uint8_t bin_str0[128];
    4631              :         size_t bin_str0_size;
    4632              :         uint8_t bin_str2[128];
    4633              :         size_t bin_str2_size;
    4634              :         uint8_t bin_str7[128];
    4635              :         size_t bin_str7_size;
    4636              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4637              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4638              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    4639              :         size_t spdm_response_size;
    4640              :         size_t transport_header_size;
    4641              : 
    4642              : 
    4643              :         ((libspdm_context_t *)spdm_context)
    4644            1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    4645              :         ((libspdm_context_t *)spdm_context)
    4646            1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    4647              :         ((libspdm_context_t *)spdm_context)
    4648            1 :         ->connection_info.algorithm.dhe_named_group =  m_libspdm_use_dhe_algo;
    4649              :         ((libspdm_context_t *)spdm_context)
    4650            1 :         ->connection_info.algorithm.measurement_hash_algo =
    4651              :             m_libspdm_use_measurement_hash_algo;
    4652            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    4653            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4654            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4655            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    4656            1 :         opaque_key_exchange_rsp_size =
    4657            1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
    4658            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    4659            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    4660            1 :                              opaque_key_exchange_rsp_size + signature_size +
    4661              :                              hmac_size;
    4662            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    4663            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    4664              : 
    4665            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    4666            1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
    4667            1 :         spdm_response->header.param1 = 0;
    4668            1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
    4669            1 :         spdm_response->mut_auth_requested = 0;
    4670            1 :         spdm_response->req_slot_id_param = 0;
    4671            1 :         memset(spdm_response->random_data, 0x5c, SPDM_RANDOM_DATA_SIZE);
    4672            1 :         ptr = (void *)(spdm_response + 1);
    4673            1 :         dhe_context = libspdm_dhe_new(
    4674            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4675              :                 m_libspdm_use_dhe_algo, true);
    4676            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    4677            1 :         final_key_size = sizeof(final_key);
    4678            1 :         libspdm_dhe_compute_key(
    4679              :             m_libspdm_use_dhe_algo, dhe_context,
    4680            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    4681              :             sizeof(spdm_key_exchange_request_t),
    4682              :             dhe_key_size, final_key, &final_key_size);
    4683            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    4684            1 :         ptr += dhe_key_size;
    4685              :         /* libspdm_zero_mem (ptr, hash_size);
    4686              :          * ptr += hash_size;*/
    4687            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    4688            1 :         ptr += sizeof(uint16_t);
    4689            1 :         libspdm_build_opaque_data_version_selection_data(
    4690              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4691              :                 &opaque_key_exchange_rsp_size, ptr);
    4692            1 :         ptr += opaque_key_exchange_rsp_size;
    4693            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4694              :                                                         m_libspdm_use_asym_algo, &data,
    4695              :                                                         &data_size, NULL, NULL);
    4696            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4697              :                          sizeof(m_libspdm_local_buffer)
    4698            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    4699              :                             m_libspdm_local_buffer),
    4700            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    4701            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    4702            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    4703              :                        m_libspdm_local_buffer_size));
    4704            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    4705            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    4706            1 :         cert_buffer = (uint8_t *)data;
    4707            1 :         cert_buffer_size = data_size;
    4708            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
    4709              :         /* transcript.message_a size is 0*/
    4710            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    4711            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    4712              :                                       m_libspdm_local_buffer_size);
    4713            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4714              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4715            1 :         free(data);
    4716            1 :         libspdm_responder_data_sign(
    4717              :             spdm_context,
    4718            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4719              :                 SPDM_KEY_EXCHANGE_RSP,
    4720              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    4721            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    4722              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    4723              :                 &signature_size);
    4724            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4725              :                          sizeof(m_libspdm_local_buffer)
    4726            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    4727              :                             m_libspdm_local_buffer),
    4728              :                          ptr, signature_size);
    4729            1 :         m_libspdm_local_buffer_size += signature_size;
    4730            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    4731            1 :         ptr += signature_size;
    4732            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4733              :                          libspdm_get_managed_buffer_size(&th_curr),
    4734              :                          th_curr_hash_data);
    4735            1 :         bin_str0_size = sizeof(bin_str0);
    4736            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4737              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    4738            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    4739              :                            &bin_str0_size);
    4740            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    4741              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    4742            1 :         bin_str2_size = sizeof(bin_str2);
    4743            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4744              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    4745            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    4746              :                            bin_str2, &bin_str2_size);
    4747            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    4748              :                             bin_str2, bin_str2_size,
    4749              :                             response_handshake_secret, hash_size);
    4750            1 :         bin_str7_size = sizeof(bin_str7);
    4751            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4752              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    4753            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    4754              :                            &bin_str7_size);
    4755            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    4756              :                             hash_size, bin_str7, bin_str7_size,
    4757              :                             response_finished_key, hash_size);
    4758            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4759              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4760            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    4761              :                          response_finished_key, hash_size, ptr);
    4762            1 :         ptr += hmac_size;
    4763              : 
    4764            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    4765              :                                               false, spdm_response_size,
    4766              :                                               spdm_response, response_size,
    4767              :                                               response);
    4768              :     }
    4769            1 :         return LIBSPDM_STATUS_SUCCESS;
    4770              : 
    4771            1 :     case 0x20: {
    4772              :         spdm_key_exchange_response_t *spdm_response;
    4773              :         size_t dhe_key_size;
    4774              :         uint32_t hash_size;
    4775              :         size_t signature_size;
    4776              :         uint32_t hmac_size;
    4777              :         uint8_t *ptr;
    4778              :         void *dhe_context;
    4779              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    4780              :         size_t final_key_size;
    4781              :         size_t opaque_key_exchange_rsp_size;
    4782              :         void *data;
    4783              :         size_t data_size;
    4784              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    4785              :         uint8_t *cert_buffer;
    4786              :         size_t cert_buffer_size;
    4787              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    4788              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    4789              :         uint8_t bin_str0[128];
    4790              :         size_t bin_str0_size;
    4791              :         uint8_t bin_str2[128];
    4792              :         size_t bin_str2_size;
    4793              :         uint8_t bin_str7[128];
    4794              :         size_t bin_str7_size;
    4795              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4796              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4797              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    4798              :         size_t spdm_response_size;
    4799              :         size_t transport_header_size;
    4800              : 
    4801              : 
    4802              :         ((libspdm_context_t *)spdm_context)
    4803            1 :         ->connection_info.algorithm.base_asym_algo =
    4804              :             m_libspdm_use_asym_algo;
    4805              :         ((libspdm_context_t *)spdm_context)
    4806            1 :         ->connection_info.algorithm.base_hash_algo =
    4807              :             m_libspdm_use_hash_algo;
    4808              :         ((libspdm_context_t *)spdm_context)
    4809            1 :         ->connection_info.algorithm.dhe_named_group =
    4810              :             m_libspdm_use_dhe_algo;
    4811              :         ((libspdm_context_t *)spdm_context)
    4812            1 :         ->connection_info.algorithm.measurement_hash_algo =
    4813              :             m_libspdm_use_measurement_hash_algo;
    4814            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    4815            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4816            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4817            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    4818            1 :         opaque_key_exchange_rsp_size =
    4819            1 :             libspdm_get_opaque_data_version_selection_data_size(
    4820              :                 spdm_context);
    4821            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    4822            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    4823            1 :                              opaque_key_exchange_rsp_size + signature_size +
    4824              :                              hmac_size;
    4825            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    4826            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    4827              : 
    4828            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    4829            1 :         spdm_response->header.request_response_code =
    4830              :             SPDM_KEY_EXCHANGE_RSP;
    4831            1 :         spdm_response->header.param1 = 0;
    4832            1 :         spdm_response->rsp_session_id =
    4833            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    4834            1 :         spdm_response->mut_auth_requested = 0;
    4835            1 :         spdm_response->req_slot_id_param = 0;
    4836            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    4837            1 :                                   spdm_response->random_data);
    4838            1 :         ptr = (void *)(spdm_response + 1);
    4839            1 :         dhe_context = libspdm_dhe_new(
    4840            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4841              :                 m_libspdm_use_dhe_algo,
    4842              :                 true);
    4843            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    4844              :                                  &dhe_key_size);
    4845            1 :         final_key_size = sizeof(final_key);
    4846            1 :         libspdm_dhe_compute_key(
    4847              :             m_libspdm_use_dhe_algo, dhe_context,
    4848            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    4849              :             sizeof(spdm_key_exchange_request_t),
    4850              :             dhe_key_size, final_key, &final_key_size);
    4851            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    4852            1 :         ptr += dhe_key_size;
    4853              :         /* libspdm_zero_mem (ptr, hash_size);
    4854              :          * ptr += hash_size;*/
    4855            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    4856            1 :         ptr += sizeof(uint16_t);
    4857            1 :         libspdm_build_opaque_data_version_selection_data(
    4858              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4859              :                 &opaque_key_exchange_rsp_size, ptr);
    4860            1 :         ptr += opaque_key_exchange_rsp_size;
    4861            1 :         libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
    4862            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4863              :                          sizeof(m_libspdm_local_buffer)
    4864            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    4865              :                             m_libspdm_local_buffer),
    4866            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    4867            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    4868            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    4869              :                        m_libspdm_local_buffer_size));
    4870            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    4871            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    4872            1 :         cert_buffer = (uint8_t *)data;
    4873            1 :         cert_buffer_size = data_size;
    4874            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    4875              :                          cert_buffer_hash);
    4876              :         /* transcript.message_a size is 0*/
    4877            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    4878            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    4879              :                                       m_libspdm_local_buffer_size);
    4880            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4881              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4882            1 :         free(data);
    4883            1 :         libspdm_responder_data_sign(
    4884              :             spdm_context,
    4885            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    4886              :                 SPDM_KEY_EXCHANGE_RSP,
    4887              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    4888            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    4889              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    4890              :                 &signature_size);
    4891            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    4892              :                          sizeof(m_libspdm_local_buffer)
    4893            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    4894              :                             m_libspdm_local_buffer),
    4895              :                          ptr, signature_size);
    4896            1 :         m_libspdm_local_buffer_size += signature_size;
    4897            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    4898            1 :         ptr += signature_size;
    4899            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4900              :                          libspdm_get_managed_buffer_size(&th_curr),
    4901              :                          th_curr_hash_data);
    4902            1 :         bin_str0_size = sizeof(bin_str0);
    4903            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4904              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    4905            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    4906              :                            &bin_str0_size);
    4907            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    4908              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    4909            1 :         bin_str2_size = sizeof(bin_str2);
    4910            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4911              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    4912            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    4913              :                            bin_str2, &bin_str2_size);
    4914            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    4915              :                             bin_str2, bin_str2_size,
    4916              :                             response_handshake_secret, hash_size);
    4917            1 :         bin_str7_size = sizeof(bin_str7);
    4918            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    4919              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    4920            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    4921              :                            &bin_str7_size);
    4922            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    4923              :                             hash_size, bin_str7, bin_str7_size,
    4924              :                             response_finished_key, hash_size);
    4925            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    4926              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    4927            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    4928              :                          response_finished_key, hash_size, ptr);
    4929            1 :         ptr += hmac_size;
    4930              : 
    4931            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    4932              :                                               false, spdm_response_size,
    4933              :                                               spdm_response, response_size,
    4934              :                                               response);
    4935              :     }
    4936            1 :         return LIBSPDM_STATUS_SUCCESS;
    4937            1 :     case 0x21: {
    4938              :         spdm_key_exchange_response_t *spdm_response;
    4939              :         size_t dhe_key_size;
    4940              :         uint32_t hash_size;
    4941              :         size_t signature_size;
    4942              :         uint32_t hmac_size;
    4943              :         uint8_t *ptr;
    4944              :         void *dhe_context;
    4945              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    4946              :         size_t final_key_size;
    4947              :         size_t opaque_key_exchange_rsp_size;
    4948              :         void *data;
    4949              :         size_t data_size;
    4950              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    4951              :         uint8_t *cert_buffer;
    4952              :         size_t cert_buffer_size;
    4953              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    4954              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    4955              :         uint8_t bin_str0[128];
    4956              :         size_t bin_str0_size;
    4957              :         uint8_t bin_str2[128];
    4958              :         size_t bin_str2_size;
    4959              :         uint8_t bin_str7[128];
    4960              :         size_t bin_str7_size;
    4961              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4962              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    4963              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    4964              :         size_t spdm_response_size;
    4965              :         size_t transport_header_size;
    4966              : 
    4967              : 
    4968              :         ((libspdm_context_t *)spdm_context)
    4969            1 :         ->connection_info.algorithm.base_asym_algo =
    4970              :             m_libspdm_use_asym_algo;
    4971              :         ((libspdm_context_t *)spdm_context)
    4972            1 :         ->connection_info.algorithm.base_hash_algo =
    4973              :             m_libspdm_use_hash_algo;
    4974              :         ((libspdm_context_t *)spdm_context)
    4975            1 :         ->connection_info.algorithm.dhe_named_group =
    4976              :             m_libspdm_use_dhe_algo;
    4977              :         ((libspdm_context_t *)spdm_context)
    4978            1 :         ->connection_info.algorithm.measurement_hash_algo =
    4979              :             m_libspdm_use_measurement_hash_algo;
    4980            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    4981            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4982            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    4983            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    4984            1 :         opaque_key_exchange_rsp_size =
    4985            1 :             libspdm_get_opaque_data_version_selection_data_size(
    4986              :                 spdm_context);
    4987            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    4988            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    4989            1 :                              opaque_key_exchange_rsp_size + signature_size +
    4990              :                              hmac_size;
    4991            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    4992            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    4993              : 
    4994            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    4995            1 :         spdm_response->header.request_response_code =
    4996              :             SPDM_KEY_EXCHANGE_RSP;
    4997            1 :         spdm_response->header.param1 = 0;
    4998            1 :         spdm_response->rsp_session_id =
    4999            1 :             libspdm_allocate_rsp_session_id(spdm_context, false);
    5000            1 :         spdm_response->mut_auth_requested = 0;
    5001            1 :         spdm_response->req_slot_id_param = 0;
    5002            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE,
    5003            1 :                                   spdm_response->random_data);
    5004            1 :         ptr = (void *)(spdm_response + 1);
    5005            1 :         dhe_context = libspdm_dhe_new(
    5006            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    5007              :                 m_libspdm_use_dhe_algo,
    5008              :                 true);
    5009            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr,
    5010              :                                  &dhe_key_size);
    5011            1 :         final_key_size = sizeof(final_key);
    5012            1 :         libspdm_dhe_compute_key(
    5013              :             m_libspdm_use_dhe_algo, dhe_context,
    5014            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    5015              :             sizeof(spdm_key_exchange_request_t),
    5016              :             dhe_key_size, final_key, &final_key_size);
    5017            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    5018            1 :         ptr += dhe_key_size;
    5019              :         /* libspdm_zero_mem (ptr, hash_size);
    5020              :          * ptr += hash_size;*/
    5021            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    5022            1 :         ptr += sizeof(uint16_t);
    5023            1 :         libspdm_build_opaque_data_version_selection_data(
    5024              :             spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    5025              :                 &opaque_key_exchange_rsp_size, ptr);
    5026            1 :         ptr += opaque_key_exchange_rsp_size;
    5027            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5028              :                                                         m_libspdm_use_asym_algo, &data,
    5029              :                                                         &data_size, NULL, NULL);
    5030            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    5031              :                          sizeof(m_libspdm_local_buffer)
    5032            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    5033              :                             m_libspdm_local_buffer),
    5034            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    5035            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    5036            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    5037              :                        m_libspdm_local_buffer_size));
    5038            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    5039            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    5040            1 :         cert_buffer = (uint8_t *)data;
    5041            1 :         cert_buffer_size = data_size;
    5042            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    5043              :                          cert_buffer_hash);
    5044              :         /* transcript.message_a size is 0*/
    5045            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    5046            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    5047              :                                       m_libspdm_local_buffer_size);
    5048            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    5049              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    5050            1 :         free(data);
    5051            1 :         libspdm_responder_data_sign(
    5052              :             spdm_context,
    5053            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    5054              :                 SPDM_KEY_EXCHANGE_RSP,
    5055              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    5056            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    5057              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    5058              :                 &signature_size);
    5059            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    5060              :                          sizeof(m_libspdm_local_buffer)
    5061            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    5062              :                             m_libspdm_local_buffer),
    5063              :                          ptr, signature_size);
    5064            1 :         m_libspdm_local_buffer_size += signature_size;
    5065            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    5066            1 :         ptr += signature_size;
    5067            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    5068              :                          libspdm_get_managed_buffer_size(&th_curr),
    5069              :                          th_curr_hash_data);
    5070            1 :         bin_str0_size = sizeof(bin_str0);
    5071            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    5072              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    5073            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    5074              :                            &bin_str0_size);
    5075            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    5076              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    5077            1 :         bin_str2_size = sizeof(bin_str2);
    5078            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    5079              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    5080            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    5081              :                            bin_str2, &bin_str2_size);
    5082            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    5083              :                             bin_str2, bin_str2_size,
    5084              :                             response_handshake_secret, hash_size);
    5085            1 :         bin_str7_size = sizeof(bin_str7);
    5086            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    5087              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    5088            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    5089              :                            &bin_str7_size);
    5090            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    5091              :                             hash_size, bin_str7, bin_str7_size,
    5092              :                             response_finished_key, hash_size);
    5093            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    5094              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    5095            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    5096              :                          response_finished_key, hash_size, ptr);
    5097            1 :         ptr += hmac_size;
    5098              : 
    5099            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    5100              :                                               false, spdm_response_size,
    5101              :                                               spdm_response, response_size,
    5102              :                                               response);
    5103              :     }
    5104            1 :         return LIBSPDM_STATUS_SUCCESS;
    5105            1 :     case 0x22: {
    5106              :         spdm_key_exchange_response_t *spdm_response;
    5107              :         size_t dhe_key_size;
    5108              :         uint32_t hash_size;
    5109              :         size_t signature_size;
    5110              :         uint32_t hmac_size;
    5111              :         uint8_t *ptr;
    5112              :         void *dhe_context;
    5113              :         uint8_t final_key[LIBSPDM_MAX_DHE_KEY_SIZE];
    5114              :         size_t final_key_size;
    5115              :         size_t opaque_key_exchange_rsp_size;
    5116              :         void *data;
    5117              :         size_t data_size;
    5118              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    5119              :         uint8_t *cert_buffer;
    5120              :         size_t cert_buffer_size;
    5121              :         uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    5122              :         uint8_t th_curr_hash_data[LIBSPDM_MAX_HASH_SIZE];
    5123              :         uint8_t bin_str0[128];
    5124              :         size_t bin_str0_size;
    5125              :         uint8_t bin_str2[128];
    5126              :         size_t bin_str2_size;
    5127              :         uint8_t bin_str7[128];
    5128              :         size_t bin_str7_size;
    5129              :         uint8_t handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    5130              :         uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
    5131              :         uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
    5132              :         size_t spdm_response_size;
    5133              :         size_t transport_header_size;
    5134              : 
    5135              :         ((libspdm_context_t *)spdm_context)
    5136            1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    5137              :         ((libspdm_context_t *)spdm_context)
    5138            1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    5139              :         ((libspdm_context_t *)spdm_context)
    5140            1 :         ->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    5141              :         ((libspdm_context_t *)spdm_context)
    5142            1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
    5143            1 :         signature_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    5144            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    5145            1 :         hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    5146            1 :         dhe_key_size = libspdm_get_dhe_pub_key_size(m_libspdm_use_dhe_algo);
    5147            1 :         opaque_key_exchange_rsp_size =
    5148            1 :             libspdm_get_opaque_data_version_selection_data_size(spdm_context);
    5149            1 :         spdm_response_size = sizeof(spdm_key_exchange_response_t) +
    5150            1 :                              dhe_key_size + 0 + sizeof(uint16_t) +
    5151            1 :                              opaque_key_exchange_rsp_size + signature_size +
    5152              :                              hmac_size;
    5153            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    5154            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    5155              : 
    5156            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    5157            1 :         spdm_response->header.request_response_code = SPDM_KEY_EXCHANGE_RSP;
    5158            1 :         spdm_response->header.param1 = 0;
    5159            1 :         spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, false);
    5160            1 :         spdm_response->mut_auth_requested = 0;
    5161            1 :         spdm_response->req_slot_id_param = 0;
    5162            1 :         libspdm_get_random_number(SPDM_RANDOM_DATA_SIZE, spdm_response->random_data);
    5163            1 :         ptr = (void *)(spdm_response + 1);
    5164            1 :         dhe_context = libspdm_dhe_new(
    5165            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    5166              :                 m_libspdm_use_dhe_algo, true);
    5167            1 :         libspdm_dhe_generate_key(m_libspdm_use_dhe_algo, dhe_context, ptr, &dhe_key_size);
    5168            1 :         final_key_size = sizeof(final_key);
    5169            1 :         libspdm_dhe_compute_key(
    5170              :             m_libspdm_use_dhe_algo, dhe_context,
    5171            1 :             (uint8_t *)&m_libspdm_local_buffer[0] +
    5172              :             sizeof(spdm_key_exchange_request_t),
    5173              :             dhe_key_size, final_key, &final_key_size);
    5174            1 :         libspdm_dhe_free(m_libspdm_use_dhe_algo, dhe_context);
    5175            1 :         ptr += dhe_key_size;
    5176              :         /* libspdm_zero_mem (ptr, hash_size);
    5177              :          * ptr += hash_size;*/
    5178            1 :         *(uint16_t *)ptr = (uint16_t)opaque_key_exchange_rsp_size;
    5179            1 :         ptr += sizeof(uint16_t);
    5180            1 :         libspdm_build_opaque_data_version_selection_data(
    5181              :             spdm_context, SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT,
    5182              :                 &opaque_key_exchange_rsp_size, ptr);
    5183            1 :         ptr += opaque_key_exchange_rsp_size;
    5184            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5185              :                                                         m_libspdm_use_asym_algo, &data,
    5186              :                                                         &data_size, NULL, NULL);
    5187            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    5188              :                          sizeof(m_libspdm_local_buffer)
    5189            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    5190              :                             m_libspdm_local_buffer),
    5191            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    5192            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    5193            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    5194              :                        m_libspdm_local_buffer_size));
    5195            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    5196            1 :         libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
    5197            1 :         cert_buffer = (uint8_t *)data;
    5198            1 :         cert_buffer_size = data_size;
    5199            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
    5200              :                          cert_buffer_hash);
    5201              :         /* transcript.message_a size is 0*/
    5202            1 :         libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
    5203            1 :         libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
    5204              :                                       m_libspdm_local_buffer_size);
    5205            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    5206              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    5207            1 :         free(data);
    5208            1 :         libspdm_responder_data_sign(
    5209              :             spdm_context,
    5210            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    5211              :                 SPDM_KEY_EXCHANGE_RSP,
    5212              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    5213            1 :                 false, libspdm_get_managed_buffer(&th_curr),
    5214              :                 libspdm_get_managed_buffer_size(&th_curr), ptr,
    5215              :                 &signature_size);
    5216            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    5217              :                          sizeof(m_libspdm_local_buffer)
    5218            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    5219              :                             m_libspdm_local_buffer),
    5220              :                          ptr, signature_size);
    5221            1 :         m_libspdm_local_buffer_size += signature_size;
    5222            1 :         libspdm_append_managed_buffer(&th_curr, ptr, signature_size);
    5223            1 :         ptr += signature_size;
    5224            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    5225              :                          libspdm_get_managed_buffer_size(&th_curr),
    5226              :                          th_curr_hash_data);
    5227            1 :         bin_str0_size = sizeof(bin_str0);
    5228            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    5229              :                            SPDM_BIN_STR_0_LABEL, sizeof(SPDM_BIN_STR_0_LABEL) - 1,
    5230            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str0,
    5231              :                            &bin_str0_size);
    5232            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, final_key, final_key_size,
    5233              :                          m_libspdm_zero_filled_buffer, hash_size,handshake_secret);
    5234            1 :         bin_str2_size = sizeof(bin_str2);
    5235            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    5236              :                            SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
    5237            1 :                            th_curr_hash_data, (uint16_t)hash_size, hash_size,
    5238              :                            bin_str2, &bin_str2_size);
    5239            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, handshake_secret, hash_size,
    5240              :                             bin_str2, bin_str2_size,
    5241              :                             response_handshake_secret, hash_size);
    5242            1 :         bin_str7_size = sizeof(bin_str7);
    5243            1 :         libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
    5244              :                            SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
    5245            1 :                            NULL, (uint16_t)hash_size, hash_size, bin_str7,
    5246              :                            &bin_str7_size);
    5247            1 :         libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
    5248              :                             hash_size, bin_str7, bin_str7_size,
    5249              :                             response_finished_key, hash_size);
    5250            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
    5251              :                          libspdm_get_managed_buffer_size(&th_curr), hash_data);
    5252            1 :         libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
    5253              :                          response_finished_key, hash_size, ptr);
    5254            1 :         ptr += hmac_size;
    5255              : 
    5256            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    5257              :                                               false, spdm_response_size,
    5258              :                                               spdm_response, response_size,
    5259              :                                               response);
    5260              :     }
    5261            1 :         return LIBSPDM_STATUS_SUCCESS;
    5262              : 
    5263            0 :     default:
    5264            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
    5265              :     }
    5266              : }
    5267              : 
    5268            1 : static void req_key_exchange_case1(void **state)
    5269              : {
    5270              :     libspdm_return_t status;
    5271              :     libspdm_test_context_t *spdm_test_context;
    5272              :     libspdm_context_t *spdm_context;
    5273              :     uint32_t session_id;
    5274              :     uint8_t heartbeat_period;
    5275              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5276              :     uint8_t slot_id_param;
    5277              :     void *data;
    5278              :     size_t data_size;
    5279              :     void *hash;
    5280              :     size_t hash_size;
    5281              : 
    5282            1 :     spdm_test_context = *state;
    5283            1 :     spdm_context = spdm_test_context->spdm_context;
    5284            1 :     spdm_test_context->case_id = 0x1;
    5285            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5286              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5287            1 :     spdm_context->connection_info.connection_state =
    5288              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    5289            1 :     spdm_context->connection_info.capability.flags |=
    5290              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    5291              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    5292            1 :     spdm_context->local_context.capability.flags |=
    5293              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    5294              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    5295            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5296              :                                                          m_libspdm_use_asym_algo, &data,
    5297              :                                                          &data_size, &hash, &hash_size)) {
    5298            0 :         assert(false);
    5299              :     }
    5300            1 :     libspdm_reset_message_a(spdm_context);
    5301            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5302              :         m_libspdm_use_hash_algo;
    5303            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5304              :         m_libspdm_use_asym_algo;
    5305            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5306              :         m_libspdm_use_dhe_algo;
    5307            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5308              :         m_libspdm_use_aead_algo;
    5309              : 
    5310              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5311              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5312              :         data_size;
    5313              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5314              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5315              :                      data, data_size);
    5316              : #else
    5317            1 :     libspdm_hash_all(
    5318              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5319              :         data, data_size,
    5320            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5321            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5322            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5323            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5324              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5325              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5326              :         data, data_size,
    5327              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5328              : #endif
    5329              : 
    5330            1 :     heartbeat_period = 0;
    5331            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    5332            1 :     status = libspdm_send_receive_key_exchange(
    5333              :         spdm_context,
    5334              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    5335              :         &session_id, &heartbeat_period, &slot_id_param,
    5336              :         measurement_hash);
    5337            1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
    5338            1 :     free(data);
    5339            1 : }
    5340              : 
    5341            1 : static void req_key_exchange_case2(void **state)
    5342              : {
    5343              :     libspdm_return_t status;
    5344              :     libspdm_test_context_t *spdm_test_context;
    5345              :     libspdm_context_t *spdm_context;
    5346              :     uint32_t session_id;
    5347              :     uint8_t heartbeat_period;
    5348              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5349              :     uint8_t slot_id_param;
    5350              :     void *data;
    5351              :     size_t data_size;
    5352              :     void *hash;
    5353              :     size_t hash_size;
    5354              : 
    5355            1 :     spdm_test_context = *state;
    5356            1 :     spdm_context = spdm_test_context->spdm_context;
    5357            1 :     spdm_test_context->case_id = 0x2;
    5358            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5359              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5360            1 :     spdm_context->connection_info.connection_state =
    5361              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    5362            1 :     spdm_context->connection_info.capability.flags |=
    5363              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    5364              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    5365            1 :     spdm_context->local_context.capability.flags |=
    5366              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    5367              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    5368            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    5369            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    5370              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    5371            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5372              :                                                          m_libspdm_use_asym_algo, &data,
    5373              :                                                          &data_size, &hash, &hash_size)) {
    5374            0 :         assert(false);
    5375              :     }
    5376            1 :     libspdm_reset_message_a(spdm_context);
    5377            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5378              :         m_libspdm_use_hash_algo;
    5379            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5380              :         m_libspdm_use_asym_algo;
    5381            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5382              :         m_libspdm_use_dhe_algo;
    5383            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5384              :         m_libspdm_use_aead_algo;
    5385              : 
    5386              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5387              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5388              :         data_size;
    5389              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5390              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5391              :                      data, data_size);
    5392              : #else
    5393            1 :     libspdm_hash_all(
    5394              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5395              :         data, data_size,
    5396            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5397            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5398            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5399            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5400              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5401              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5402              :         data, data_size,
    5403              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5404              : #endif
    5405              : 
    5406            1 :     heartbeat_period = 0;
    5407            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    5408            1 :     status = libspdm_send_receive_key_exchange(
    5409              :         spdm_context,
    5410              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    5411              :         &session_id, &heartbeat_period, &slot_id_param,
    5412              :         measurement_hash);
    5413            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    5414            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    5415            1 :     assert_int_equal(
    5416              :         libspdm_secured_message_get_session_state(
    5417              :             spdm_context->session_info[0].secured_message_context),
    5418              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    5419            1 :     free(data);
    5420            1 : }
    5421              : 
    5422            1 : static void req_key_exchange_case3(void **state)
    5423              : {
    5424              :     libspdm_return_t status;
    5425              :     libspdm_test_context_t *spdm_test_context;
    5426              :     libspdm_context_t *spdm_context;
    5427              :     uint32_t session_id;
    5428              :     uint8_t heartbeat_period;
    5429              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5430              :     uint8_t slot_id_param;
    5431              :     void *data;
    5432              :     size_t data_size;
    5433              :     void *hash;
    5434              :     size_t hash_size;
    5435              : 
    5436            1 :     spdm_test_context = *state;
    5437            1 :     spdm_context = spdm_test_context->spdm_context;
    5438            1 :     spdm_test_context->case_id = 0x3;
    5439            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5440              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5441            1 :     spdm_context->connection_info.connection_state =
    5442              :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
    5443            1 :     spdm_context->connection_info.capability.flags |=
    5444              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    5445              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    5446            1 :     spdm_context->local_context.capability.flags |=
    5447              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    5448              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    5449            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5450              :                                                          m_libspdm_use_asym_algo, &data,
    5451              :                                                          &data_size, &hash, &hash_size)) {
    5452            0 :         assert(false);
    5453              :     }
    5454            1 :     libspdm_reset_message_a(spdm_context);
    5455            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5456              :         m_libspdm_use_hash_algo;
    5457            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5458              :         m_libspdm_use_asym_algo;
    5459            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5460              :         m_libspdm_use_dhe_algo;
    5461            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5462              :         m_libspdm_use_aead_algo;
    5463              : 
    5464              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5465              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5466              :         data_size;
    5467              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5468              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5469              :                      data, data_size);
    5470              : #else
    5471            1 :     libspdm_hash_all(
    5472              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5473              :         data, data_size,
    5474            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5475            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5476            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5477            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5478              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5479              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5480              :         data, data_size,
    5481              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5482              : #endif
    5483              : 
    5484            1 :     heartbeat_period = 0;
    5485            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    5486            1 :     status = libspdm_send_receive_key_exchange(
    5487              :         spdm_context,
    5488              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    5489              :         &session_id, &heartbeat_period, &slot_id_param,
    5490              :         measurement_hash);
    5491            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
    5492            1 :     free(data);
    5493            1 : }
    5494              : 
    5495            1 : static void req_key_exchange_case4(void **state)
    5496              : {
    5497              :     libspdm_return_t status;
    5498              :     libspdm_test_context_t *spdm_test_context;
    5499              :     libspdm_context_t *spdm_context;
    5500              :     uint32_t session_id;
    5501              :     uint8_t heartbeat_period;
    5502              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5503              :     uint8_t slot_id_param;
    5504              :     void *data;
    5505              :     size_t data_size;
    5506              :     void *hash;
    5507              :     size_t hash_size;
    5508              : 
    5509            1 :     spdm_test_context = *state;
    5510            1 :     spdm_context = spdm_test_context->spdm_context;
    5511            1 :     spdm_test_context->case_id = 0x4;
    5512            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5513              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5514            1 :     spdm_context->connection_info.connection_state =
    5515              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    5516            1 :     spdm_context->connection_info.capability.flags |=
    5517              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    5518              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    5519            1 :     spdm_context->local_context.capability.flags |=
    5520              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    5521              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    5522            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5523              :                                                          m_libspdm_use_asym_algo, &data,
    5524              :                                                          &data_size, &hash, &hash_size)) {
    5525            0 :         assert(false);
    5526              :     }
    5527            1 :     libspdm_reset_message_a(spdm_context);
    5528            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5529              :         m_libspdm_use_hash_algo;
    5530            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5531              :         m_libspdm_use_asym_algo;
    5532            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5533              :         m_libspdm_use_dhe_algo;
    5534            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5535              :         m_libspdm_use_aead_algo;
    5536              : 
    5537              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5538              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5539              :         data_size;
    5540              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5541              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5542              :                      data, data_size);
    5543              : #else
    5544            1 :     libspdm_hash_all(
    5545              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5546              :         data, data_size,
    5547            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5548            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5549            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5550            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5551              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5552              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5553              :         data, data_size,
    5554              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5555              : #endif
    5556              : 
    5557            1 :     heartbeat_period = 0;
    5558            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    5559            1 :     status = libspdm_send_receive_key_exchange(
    5560              :         spdm_context,
    5561              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    5562              :         &session_id, &heartbeat_period, &slot_id_param,
    5563              :         measurement_hash);
    5564            1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
    5565            1 :     free(data);
    5566            1 : }
    5567              : 
    5568            1 : static void req_key_exchange_case5(void **state)
    5569              : {
    5570              :     libspdm_return_t status;
    5571              :     libspdm_test_context_t *spdm_test_context;
    5572              :     libspdm_context_t *spdm_context;
    5573              :     uint32_t session_id;
    5574              :     uint8_t heartbeat_period;
    5575              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5576              :     uint8_t slot_id_param;
    5577              :     void *data;
    5578              :     size_t data_size;
    5579              :     void *hash;
    5580              :     size_t hash_size;
    5581              : 
    5582            1 :     spdm_test_context = *state;
    5583            1 :     spdm_context = spdm_test_context->spdm_context;
    5584            1 :     spdm_test_context->case_id = 0x5;
    5585            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5586              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5587            1 :     spdm_context->connection_info.connection_state =
    5588              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    5589            1 :     spdm_context->connection_info.capability.flags |=
    5590              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    5591              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    5592            1 :     spdm_context->local_context.capability.flags |=
    5593              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    5594              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    5595            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5596              :                                                          m_libspdm_use_asym_algo, &data,
    5597              :                                                          &data_size, &hash, &hash_size)) {
    5598            0 :         assert(false);
    5599              :     }
    5600            1 :     libspdm_reset_message_a(spdm_context);
    5601            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5602              :         m_libspdm_use_hash_algo;
    5603            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5604              :         m_libspdm_use_asym_algo;
    5605            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5606              :         m_libspdm_use_dhe_algo;
    5607            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5608              :         m_libspdm_use_aead_algo;
    5609              : 
    5610              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5611              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5612              :         data_size;
    5613              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5614              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5615              :                      data, data_size);
    5616              : #else
    5617            1 :     libspdm_hash_all(
    5618              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5619              :         data, data_size,
    5620            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5621            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5622            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5623            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5624              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5625              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5626              :         data, data_size,
    5627              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5628              : #endif
    5629              : 
    5630            1 :     heartbeat_period = 0;
    5631            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    5632            1 :     status = libspdm_send_receive_key_exchange(
    5633              :         spdm_context,
    5634              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    5635              :         &session_id, &heartbeat_period, &slot_id_param,
    5636              :         measurement_hash);
    5637            1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
    5638            1 :     free(data);
    5639            1 : }
    5640              : 
    5641            1 : static void req_key_exchange_case6(void **state)
    5642              : {
    5643              :     libspdm_return_t status;
    5644              :     libspdm_test_context_t *spdm_test_context;
    5645              :     libspdm_context_t *spdm_context;
    5646              :     uint32_t session_id;
    5647              :     uint8_t heartbeat_period;
    5648              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5649              :     uint8_t slot_id_param;
    5650              :     void *data;
    5651              :     size_t data_size;
    5652              :     void *hash;
    5653              :     size_t hash_size;
    5654              : 
    5655            1 :     spdm_test_context = *state;
    5656            1 :     spdm_context = spdm_test_context->spdm_context;
    5657            1 :     spdm_test_context->case_id = 0x6;
    5658            1 :     spdm_context->retry_times = 3;
    5659            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5660              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5661            1 :     spdm_context->connection_info.connection_state =
    5662              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    5663            1 :     spdm_context->connection_info.capability.flags |=
    5664              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    5665              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    5666            1 :     spdm_context->local_context.capability.flags |=
    5667              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    5668              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    5669            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5670              :                                                          m_libspdm_use_asym_algo, &data,
    5671              :                                                          &data_size, &hash, &hash_size)) {
    5672            0 :         assert(false);
    5673              :     }
    5674            1 :     libspdm_reset_message_a(spdm_context);
    5675            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5676              :         m_libspdm_use_hash_algo;
    5677            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5678              :         m_libspdm_use_asym_algo;
    5679            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5680              :         m_libspdm_use_dhe_algo;
    5681            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5682              :         m_libspdm_use_aead_algo;
    5683              : 
    5684              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5685              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5686              :         data_size;
    5687              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5688              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5689              :                      data, data_size);
    5690              : #else
    5691            1 :     libspdm_hash_all(
    5692              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5693              :         data, data_size,
    5694            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5695            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5696            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5697            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5698              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5699              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5700              :         data, data_size,
    5701              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5702              : #endif
    5703              : 
    5704            1 :     heartbeat_period = 0;
    5705            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    5706            1 :     status = libspdm_send_receive_key_exchange(
    5707              :         spdm_context,
    5708              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    5709              :         &session_id, &heartbeat_period, &slot_id_param,
    5710              :         measurement_hash);
    5711            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    5712            1 :     assert_int_equal(session_id, 0xFFFEFFFE);
    5713            1 :     assert_int_equal(
    5714              :         libspdm_secured_message_get_session_state(
    5715              :             spdm_context->session_info[0].secured_message_context),
    5716              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    5717            1 :     free(data);
    5718            1 : }
    5719              : 
    5720            1 : static void req_key_exchange_case7(void **state)
    5721              : {
    5722              :     libspdm_return_t status;
    5723              :     libspdm_test_context_t *spdm_test_context;
    5724              :     libspdm_context_t *spdm_context;
    5725              :     uint32_t session_id;
    5726              :     uint8_t heartbeat_period;
    5727              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5728              :     uint8_t slot_id_param;
    5729              :     void *data;
    5730              :     size_t data_size;
    5731              :     void *hash;
    5732              :     size_t hash_size;
    5733              : 
    5734            1 :     spdm_test_context = *state;
    5735            1 :     spdm_context = spdm_test_context->spdm_context;
    5736            1 :     spdm_test_context->case_id = 0x7;
    5737            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5738              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5739            1 :     spdm_context->connection_info.connection_state =
    5740              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    5741            1 :     spdm_context->connection_info.capability.flags |=
    5742              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    5743              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    5744            1 :     spdm_context->local_context.capability.flags |=
    5745              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    5746              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    5747            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5748              :                                                          m_libspdm_use_asym_algo, &data,
    5749              :                                                          &data_size, &hash, &hash_size)) {
    5750            0 :         assert(false);
    5751              :     }
    5752            1 :     libspdm_reset_message_a(spdm_context);
    5753            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5754              :         m_libspdm_use_hash_algo;
    5755            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5756              :         m_libspdm_use_asym_algo;
    5757            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5758              :         m_libspdm_use_dhe_algo;
    5759            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5760              :         m_libspdm_use_aead_algo;
    5761              : 
    5762              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5763              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5764              :         data_size;
    5765              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5766              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5767              :                      data, data_size);
    5768              : #else
    5769            1 :     libspdm_hash_all(
    5770              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5771              :         data, data_size,
    5772            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5773            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5774            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5775            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5776              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5777              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5778              :         data, data_size,
    5779              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5780              : #endif
    5781              : 
    5782            1 :     heartbeat_period = 0;
    5783            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    5784            1 :     status = libspdm_send_receive_key_exchange(
    5785              :         spdm_context,
    5786              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    5787              :         &session_id, &heartbeat_period, &slot_id_param,
    5788              :         measurement_hash);
    5789            1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
    5790            1 :     assert_int_equal(spdm_context->connection_info.connection_state,
    5791              :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
    5792            1 :     free(data);
    5793            1 : }
    5794              : 
    5795            1 : static void req_key_exchange_case8(void **state)
    5796              : {
    5797              :     libspdm_return_t status;
    5798              :     libspdm_test_context_t *spdm_test_context;
    5799              :     libspdm_context_t *spdm_context;
    5800              :     uint32_t session_id;
    5801              :     uint8_t heartbeat_period;
    5802              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5803              :     uint8_t slot_id_param;
    5804              :     void *data;
    5805              :     size_t data_size;
    5806              :     void *hash;
    5807              :     size_t hash_size;
    5808              : 
    5809            1 :     spdm_test_context = *state;
    5810            1 :     spdm_context = spdm_test_context->spdm_context;
    5811            1 :     spdm_test_context->case_id = 0x8;
    5812            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5813              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5814            1 :     spdm_context->connection_info.connection_state =
    5815              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    5816            1 :     spdm_context->connection_info.capability.flags |=
    5817              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    5818              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    5819            1 :     spdm_context->local_context.capability.flags |=
    5820              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    5821              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    5822            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5823              :                                                          m_libspdm_use_asym_algo, &data,
    5824              :                                                          &data_size, &hash, &hash_size)) {
    5825            0 :         assert(false);
    5826              :     }
    5827            1 :     libspdm_reset_message_a(spdm_context);
    5828            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5829              :         m_libspdm_use_hash_algo;
    5830            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5831              :         m_libspdm_use_asym_algo;
    5832            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5833              :         m_libspdm_use_dhe_algo;
    5834            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5835              :         m_libspdm_use_aead_algo;
    5836              : 
    5837              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5838              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5839              :         data_size;
    5840              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5841              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5842              :                      data, data_size);
    5843              : #else
    5844            1 :     libspdm_hash_all(
    5845              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5846              :         data, data_size,
    5847            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5848            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5849            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5850            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5851              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5852              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5853              :         data, data_size,
    5854              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5855              : #endif
    5856              : 
    5857            1 :     heartbeat_period = 0;
    5858            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    5859            1 :     status = libspdm_send_receive_key_exchange(
    5860              :         spdm_context,
    5861              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    5862              :         &session_id, &heartbeat_period, &slot_id_param,
    5863              :         measurement_hash);
    5864            1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
    5865            1 :     free(data);
    5866            1 : }
    5867              : 
    5868            1 : static void req_key_exchange_case9(void **state)
    5869              : {
    5870              :     libspdm_return_t status;
    5871              :     libspdm_test_context_t *spdm_test_context;
    5872              :     libspdm_context_t *spdm_context;
    5873              :     uint32_t session_id;
    5874              :     uint8_t heartbeat_period;
    5875              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5876              :     uint8_t slot_id_param;
    5877              :     void *data;
    5878              :     size_t data_size;
    5879              :     void *hash;
    5880              :     size_t hash_size;
    5881              : 
    5882            1 :     spdm_test_context = *state;
    5883            1 :     spdm_context = spdm_test_context->spdm_context;
    5884            1 :     spdm_test_context->case_id = 0x9;
    5885            1 :     spdm_context->retry_times = 3;
    5886            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5887              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5888            1 :     spdm_context->connection_info.connection_state =
    5889              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    5890            1 :     spdm_context->connection_info.capability.flags |=
    5891              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    5892              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    5893            1 :     spdm_context->local_context.capability.flags |=
    5894              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    5895              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    5896            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5897              :                                                          m_libspdm_use_asym_algo, &data,
    5898              :                                                          &data_size, &hash, &hash_size)) {
    5899            0 :         assert(false);
    5900              :     }
    5901            1 :     libspdm_reset_message_a(spdm_context);
    5902            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5903              :         m_libspdm_use_hash_algo;
    5904            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5905              :         m_libspdm_use_asym_algo;
    5906            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5907              :         m_libspdm_use_dhe_algo;
    5908            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5909              :         m_libspdm_use_aead_algo;
    5910              : 
    5911              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5912              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5913              :         data_size;
    5914              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5915              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5916              :                      data, data_size);
    5917              : #else
    5918            1 :     libspdm_hash_all(
    5919              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5920              :         data, data_size,
    5921            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5922            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5923            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5924            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5925              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5926              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5927              :         data, data_size,
    5928              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5929              : #endif
    5930              : 
    5931            1 :     heartbeat_period = 0;
    5932            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    5933            1 :     status = libspdm_send_receive_key_exchange(
    5934              :         spdm_context,
    5935              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    5936              :         &session_id, &heartbeat_period, &slot_id_param,
    5937              :         measurement_hash);
    5938              :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
    5939            1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    5940            1 :         assert_int_equal(session_id, 0xFFFDFFFD);
    5941            1 :         assert_int_equal(
    5942              :             libspdm_secured_message_get_session_state(
    5943              :                 spdm_context->session_info[0].secured_message_context),
    5944              :             LIBSPDM_SESSION_STATE_HANDSHAKING);
    5945              :     } else {
    5946              :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
    5947              :     }
    5948            1 :     free(data);
    5949            1 : }
    5950              : 
    5951            1 : static void req_key_exchange_case10(void **state) {
    5952              :     libspdm_return_t status;
    5953              :     libspdm_test_context_t    *spdm_test_context;
    5954              :     libspdm_context_t  *spdm_context;
    5955              :     uint32_t session_id;
    5956              :     uint8_t heartbeat_period;
    5957              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    5958              :     uint8_t slot_id_param;
    5959              :     void                 *data;
    5960              :     size_t data_size;
    5961              :     void                 *hash;
    5962              :     size_t hash_size;
    5963              :     uint16_t error_code;
    5964              : 
    5965            1 :     spdm_test_context = *state;
    5966            1 :     spdm_context = spdm_test_context->spdm_context;
    5967            1 :     spdm_test_context->case_id = 0xA;
    5968            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5969              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5970            1 :     spdm_context->connection_info.capability.flags |=
    5971              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    5972            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    5973            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    5974              :                                                      m_libspdm_use_asym_algo,
    5975              :                                                      &data, &data_size,
    5976              :                                                      &hash, &hash_size);
    5977            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    5978            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    5979            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    5980            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    5981              : 
    5982              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5983              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5984              :         data_size;
    5985              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5986              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5987              :                      data, data_size);
    5988              : #else
    5989            1 :     libspdm_hash_all(
    5990              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5991              :         data, data_size,
    5992            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5993            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5994            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5995            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5996              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5997              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5998              :         data, data_size,
    5999              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6000              : #endif
    6001              : 
    6002            1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
    6003           19 :     while(error_code <= 0xff) {
    6004           18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6005           18 :         libspdm_reset_message_a(spdm_context);
    6006              : 
    6007           18 :         heartbeat_period = 0;
    6008           18 :         libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6009           18 :         status = libspdm_send_receive_key_exchange (spdm_context,
    6010              :                                                     SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    6011              :                                                     0, 0, &session_id, &heartbeat_period,
    6012              :                                                     &slot_id_param, measurement_hash);
    6013           18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
    6014              : 
    6015           18 :         error_code++;
    6016           18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
    6017            1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
    6018              :         }
    6019           18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
    6020            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
    6021              :         }
    6022           18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
    6023            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
    6024              :         }
    6025              :     }
    6026              : 
    6027            1 :     free(data);
    6028            1 : }
    6029              : 
    6030            1 : static void req_key_exchange_case11(void **state)
    6031              : {
    6032              :     libspdm_return_t status;
    6033              :     libspdm_test_context_t *spdm_test_context;
    6034              :     libspdm_context_t *spdm_context;
    6035              :     uint32_t session_id;
    6036              :     uint8_t heartbeat_period;
    6037              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6038              :     uint8_t slot_id_param;
    6039              :     void *data;
    6040              :     size_t data_size;
    6041              :     void *hash;
    6042              :     size_t hash_size;
    6043              : 
    6044            1 :     spdm_test_context = *state;
    6045            1 :     spdm_context = spdm_test_context->spdm_context;
    6046            1 :     spdm_test_context->case_id = 0xB;
    6047            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6048              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6049            1 :     spdm_context->connection_info.connection_state =
    6050              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6051            1 :     spdm_context->connection_info.capability.flags |=
    6052              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    6053              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    6054            1 :     spdm_context->local_context.capability.flags |=
    6055              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    6056              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    6057            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6058              :                                                          m_libspdm_use_asym_algo, &data,
    6059              :                                                          &data_size, &hash, &hash_size)) {
    6060            0 :         assert(false);
    6061              :     }
    6062            1 :     libspdm_reset_message_a(spdm_context);
    6063            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6064              :         m_libspdm_use_hash_algo;
    6065            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6066              :         m_libspdm_use_asym_algo;
    6067            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6068              :         m_libspdm_use_dhe_algo;
    6069            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6070              :         m_libspdm_use_aead_algo;
    6071              : 
    6072              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6073              :     spdm_context->transcript.message_m.buffer_size =
    6074              :         spdm_context->transcript.message_m.max_buffer_size;
    6075              :     spdm_context->transcript.message_b.buffer_size =
    6076              :         spdm_context->transcript.message_b.max_buffer_size;
    6077              :     spdm_context->transcript.message_c.buffer_size =
    6078              :         spdm_context->transcript.message_c.max_buffer_size;
    6079              :     spdm_context->transcript.message_mut_b.buffer_size =
    6080              :         spdm_context->transcript.message_mut_b.max_buffer_size;
    6081              :     spdm_context->transcript.message_mut_c.buffer_size =
    6082              :         spdm_context->transcript.message_mut_c.max_buffer_size;
    6083              : #endif
    6084              : 
    6085              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6086              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6087              :         data_size;
    6088              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6089              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6090              :                      data, data_size);
    6091              : #else
    6092            1 :     libspdm_hash_all(
    6093              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6094              :         data, data_size,
    6095            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6096            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6097            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6098            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6099              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6100              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6101              :         data, data_size,
    6102              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6103              : #endif
    6104              : 
    6105            1 :     heartbeat_period = 0;
    6106            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6107            1 :     status = libspdm_send_receive_key_exchange(
    6108              :         spdm_context,
    6109              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    6110              :         &session_id, &heartbeat_period, &slot_id_param,
    6111              :         measurement_hash);
    6112            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6113            1 :     assert_int_equal(
    6114              :         libspdm_secured_message_get_session_state(
    6115              :             spdm_context->session_info[0].secured_message_context),
    6116              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    6117              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6118              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    6119              :     assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
    6120              :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
    6121              :     assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
    6122              :     assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
    6123              : #endif
    6124            1 :     free(data);
    6125            1 : }
    6126              : 
    6127            1 : static void req_key_exchange_case12(void **state)
    6128              : {
    6129              :     libspdm_return_t status;
    6130              :     libspdm_test_context_t *spdm_test_context;
    6131              :     libspdm_context_t *spdm_context;
    6132              :     uint32_t session_id;
    6133              :     uint8_t heartbeat_period;
    6134              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6135              :     uint8_t slot_id_param;
    6136              :     void *data;
    6137              :     size_t data_size;
    6138              :     void *hash;
    6139              :     size_t hash_size;
    6140              : 
    6141            1 :     spdm_test_context = *state;
    6142            1 :     spdm_context = spdm_test_context->spdm_context;
    6143              : 
    6144            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    6145            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    6146              :     }
    6147              : 
    6148            1 :     spdm_test_context->case_id = 0xC;
    6149            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6150              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6151            1 :     spdm_context->connection_info.connection_state =
    6152              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6153            1 :     spdm_context->connection_info.capability.flags |=
    6154              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    6155            1 :     spdm_context->connection_info.capability.flags |=
    6156              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6157            1 :     spdm_context->local_context.capability.flags |=
    6158              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    6159              : 
    6160            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6161              :                                                          m_libspdm_use_asym_algo, &data,
    6162              :                                                          &data_size, &hash, &hash_size)) {
    6163            0 :         assert(false);
    6164              :     }
    6165            1 :     libspdm_reset_message_a(spdm_context);
    6166            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6167              :         m_libspdm_use_hash_algo;
    6168            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6169              :         m_libspdm_use_asym_algo;
    6170            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6171              :         m_libspdm_use_dhe_algo;
    6172            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6173              :         m_libspdm_use_aead_algo;
    6174            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6175              :         m_libspdm_use_measurement_hash_algo;
    6176              : 
    6177              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6178              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6179              :         data_size;
    6180              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6181              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6182              :                      data, data_size);
    6183              : #else
    6184            1 :     libspdm_hash_all(
    6185              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6186              :         data, data_size,
    6187            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6188            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6189            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6190            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6191              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6192              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6193              :         data, data_size,
    6194              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6195              : #endif
    6196              : 
    6197            1 :     heartbeat_period = 0;
    6198            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6199            1 :     status = libspdm_send_receive_key_exchange(
    6200              :         spdm_context,
    6201              :         SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
    6202              :         &session_id, &heartbeat_period, &slot_id_param,
    6203              :         measurement_hash);
    6204            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6205            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    6206            1 :     assert_memory_equal(
    6207              :         measurement_hash,
    6208              :         m_libspdm_use_tcb_hash_value,
    6209              :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
    6210            1 :     assert_int_equal(
    6211              :         libspdm_secured_message_get_session_state(
    6212              :             spdm_context->session_info[0].secured_message_context),
    6213              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    6214            1 :     free(data);
    6215            1 : }
    6216              : 
    6217            1 : static void req_key_exchange_case13(void **state)
    6218              : {
    6219              :     libspdm_return_t status;
    6220              :     libspdm_test_context_t *spdm_test_context;
    6221              :     libspdm_context_t *spdm_context;
    6222              :     uint32_t session_id;
    6223              :     uint8_t heartbeat_period;
    6224              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6225              :     uint8_t slot_id_param;
    6226              :     void *data;
    6227              :     size_t data_size;
    6228              :     void *hash;
    6229              :     size_t hash_size;
    6230              : 
    6231            1 :     spdm_test_context = *state;
    6232            1 :     spdm_context = spdm_test_context->spdm_context;
    6233              : 
    6234            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    6235            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    6236              :     }
    6237              : 
    6238            1 :     spdm_test_context->case_id = 0xD;
    6239            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6240              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6241            1 :     spdm_context->connection_info.connection_state =
    6242              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6243            1 :     spdm_context->connection_info.capability.flags |=
    6244              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    6245            1 :     spdm_context->connection_info.capability.flags |=
    6246              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6247            1 :     spdm_context->local_context.capability.flags |=
    6248              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    6249              : 
    6250            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6251              :                                                          m_libspdm_use_asym_algo, &data,
    6252              :                                                          &data_size, &hash, &hash_size)) {
    6253            0 :         assert(false);
    6254              :     }
    6255            1 :     libspdm_reset_message_a(spdm_context);
    6256            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6257              :         m_libspdm_use_hash_algo;
    6258            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6259              :         m_libspdm_use_asym_algo;
    6260            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6261              :         m_libspdm_use_dhe_algo;
    6262            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6263              :         m_libspdm_use_aead_algo;
    6264            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6265              :         m_libspdm_use_measurement_hash_algo;
    6266              : 
    6267              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6268              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6269              :         data_size;
    6270              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6271              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6272              :                      data, data_size);
    6273              : #else
    6274            1 :     libspdm_hash_all(
    6275              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6276              :         data, data_size,
    6277            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6278            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6279            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6280            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6281              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6282              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6283              :         data, data_size,
    6284              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6285              : #endif
    6286              : 
    6287            1 :     heartbeat_period = 0;
    6288            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6289            1 :     status = libspdm_send_receive_key_exchange(
    6290              :         spdm_context,
    6291              :         SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
    6292              :         &session_id, &heartbeat_period, &slot_id_param,
    6293              :         measurement_hash);
    6294            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6295            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    6296            1 :     assert_memory_equal(
    6297              :         measurement_hash,
    6298              :         m_libspdm_zero_filled_buffer,
    6299              :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
    6300            1 :     assert_int_equal(
    6301              :         libspdm_secured_message_get_session_state(
    6302              :             spdm_context->session_info[0].secured_message_context),
    6303              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    6304            1 :     free(data);
    6305            1 : }
    6306              : 
    6307            1 : static void req_key_exchange_case14(void **state)
    6308              : {
    6309              :     libspdm_return_t status;
    6310              :     libspdm_test_context_t *spdm_test_context;
    6311              :     libspdm_context_t *spdm_context;
    6312              :     uint32_t session_id;
    6313              :     uint8_t heartbeat_period;
    6314              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6315              :     uint8_t slot_id_param;
    6316              :     void *data;
    6317              :     size_t data_size;
    6318              :     void *hash;
    6319              :     size_t hash_size;
    6320              : 
    6321            1 :     spdm_test_context = *state;
    6322            1 :     spdm_context = spdm_test_context->spdm_context;
    6323              : 
    6324            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    6325            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    6326              :     }
    6327              : 
    6328            1 :     spdm_test_context->case_id = 0xE;
    6329            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6330              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6331            1 :     spdm_context->connection_info.connection_state =
    6332              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6333            1 :     spdm_context->connection_info.capability.flags |=
    6334              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    6335            1 :     spdm_context->connection_info.capability.flags |=
    6336              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6337            1 :     spdm_context->local_context.capability.flags |=
    6338              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    6339              : 
    6340            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6341              :                                                          m_libspdm_use_asym_algo, &data,
    6342              :                                                          &data_size, &hash, &hash_size)) {
    6343            0 :         assert(false);
    6344              :     }
    6345            1 :     libspdm_reset_message_a(spdm_context);
    6346            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6347              :         m_libspdm_use_hash_algo;
    6348            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6349              :         m_libspdm_use_asym_algo;
    6350            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6351              :         m_libspdm_use_dhe_algo;
    6352            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6353              :         m_libspdm_use_aead_algo;
    6354            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6355              :         m_libspdm_use_measurement_hash_algo;
    6356              : 
    6357              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6358              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6359              :         data_size;
    6360              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6361              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6362              :                      data, data_size);
    6363              : #else
    6364            1 :     libspdm_hash_all(
    6365              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6366              :         data, data_size,
    6367            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6368            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6369            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6370            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6371              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6372              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6373              :         data, data_size,
    6374              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6375              : #endif
    6376              : 
    6377            1 :     heartbeat_period = 0;
    6378            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6379            1 :     status = libspdm_send_receive_key_exchange(
    6380              :         spdm_context,
    6381              :         SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, 0,
    6382              :         &session_id, &heartbeat_period, &slot_id_param,
    6383              :         measurement_hash);
    6384            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6385            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    6386            1 :     assert_memory_equal(
    6387              :         measurement_hash,
    6388              :         m_libspdm_use_tcb_hash_value,
    6389              :         libspdm_get_hash_size(m_libspdm_use_hash_algo));
    6390            1 :     assert_int_equal(
    6391              :         libspdm_secured_message_get_session_state(
    6392              :             spdm_context->session_info[0].secured_message_context),
    6393              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    6394            1 :     free(data);
    6395            1 : }
    6396              : 
    6397            1 : static void req_key_exchange_case15(void **state)
    6398              : {
    6399              :     libspdm_return_t status;
    6400              :     libspdm_test_context_t *spdm_test_context;
    6401              :     libspdm_context_t *spdm_context;
    6402              :     uint32_t session_id;
    6403              :     uint8_t heartbeat_period;
    6404              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6405              :     uint8_t slot_id_param;
    6406              :     void *data;
    6407              :     size_t data_size;
    6408              :     void *hash;
    6409              :     size_t hash_size;
    6410              : 
    6411            1 :     spdm_test_context = *state;
    6412            1 :     spdm_context = spdm_test_context->spdm_context;
    6413              : 
    6414            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    6415            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    6416              :     }
    6417              : 
    6418            1 :     spdm_test_context->case_id = 0xF;
    6419            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6420              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6421            1 :     spdm_context->connection_info.connection_state =
    6422              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6423            1 :     spdm_context->connection_info.capability.flags |=
    6424              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    6425            1 :     spdm_context->connection_info.capability.flags |=
    6426              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6427            1 :     spdm_context->local_context.capability.flags |=
    6428              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    6429              : 
    6430            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6431              :                                                          m_libspdm_use_asym_algo, &data,
    6432              :                                                          &data_size, &hash, &hash_size)) {
    6433            0 :         assert(false);
    6434              :     }
    6435            1 :     libspdm_reset_message_a(spdm_context);
    6436            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6437              :         m_libspdm_use_hash_algo;
    6438            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6439              :         m_libspdm_use_asym_algo;
    6440            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6441              :         m_libspdm_use_dhe_algo;
    6442            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6443              :         m_libspdm_use_aead_algo;
    6444            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6445              :         m_libspdm_use_measurement_hash_algo;
    6446              : 
    6447              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6448              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6449              :         data_size;
    6450              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6451              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6452              :                      data, data_size);
    6453              : #else
    6454            1 :     libspdm_hash_all(
    6455              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6456              :         data, data_size,
    6457            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6458            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6459            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6460            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6461              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6462              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6463              :         data, data_size,
    6464              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6465              : #endif
    6466              : 
    6467            1 :     heartbeat_period = 0;
    6468            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6469            1 :     status = libspdm_send_receive_key_exchange(
    6470              :         spdm_context,
    6471              :         SPDM_KEY_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, 0,
    6472              :         &session_id, &heartbeat_period, &slot_id_param,
    6473              :         measurement_hash);
    6474            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    6475            1 :     free(data);
    6476            1 : }
    6477              : 
    6478            1 : static void req_key_exchange_case16(void **state)
    6479              : {
    6480              :     libspdm_return_t status;
    6481              :     libspdm_test_context_t *spdm_test_context;
    6482              :     libspdm_context_t *spdm_context;
    6483              :     uint32_t session_id;
    6484              :     uint8_t heartbeat_period;
    6485              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6486              :     uint8_t slot_id_param;
    6487              :     void *data;
    6488              :     size_t data_size;
    6489              :     void *hash;
    6490              :     size_t hash_size;
    6491              : 
    6492            1 :     spdm_test_context = *state;
    6493            1 :     spdm_context = spdm_test_context->spdm_context;
    6494              : 
    6495            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    6496            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    6497              :     }
    6498              : 
    6499            1 :     spdm_test_context->case_id = 0x10;
    6500            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6501              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6502            1 :     spdm_context->connection_info.connection_state =
    6503              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6504            1 :     spdm_context->connection_info.capability.flags |=
    6505              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    6506            1 :     spdm_context->connection_info.capability.flags |=
    6507              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6508            1 :     spdm_context->local_context.capability.flags |=
    6509              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    6510              : 
    6511            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6512              :                                                          m_libspdm_use_asym_algo, &data,
    6513              :                                                          &data_size, &hash, &hash_size)) {
    6514            0 :         assert(false);
    6515              :     }
    6516            1 :     libspdm_reset_message_a(spdm_context);
    6517            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6518              :         m_libspdm_use_hash_algo;
    6519            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6520              :         m_libspdm_use_asym_algo;
    6521            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6522              :         m_libspdm_use_dhe_algo;
    6523            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6524              :         m_libspdm_use_aead_algo;
    6525            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6526              :         m_libspdm_use_measurement_hash_algo;
    6527              : 
    6528              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6529              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6530              :         data_size;
    6531              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6532              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6533              :                      data, data_size);
    6534              : #else
    6535            1 :     libspdm_hash_all(
    6536              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6537              :         data, data_size,
    6538            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6539            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6540            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6541            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6542              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6543              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6544              :         data, data_size,
    6545              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6546              : #endif
    6547              : 
    6548            1 :     heartbeat_period = 0;
    6549            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6550            1 :     status = libspdm_send_receive_key_exchange(
    6551              :         spdm_context,
    6552              :         SPDM_KEY_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, 0,
    6553              :         &session_id, &heartbeat_period, &slot_id_param,
    6554              :         measurement_hash);
    6555            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    6556            1 :     free(data);
    6557            1 : }
    6558              : 
    6559            1 : static void req_key_exchange_case17(void **state)
    6560              : {
    6561              :     libspdm_return_t status;
    6562              :     libspdm_test_context_t *spdm_test_context;
    6563              :     libspdm_context_t *spdm_context;
    6564              :     uint32_t session_id;
    6565              :     uint8_t heartbeat_period;
    6566              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6567              :     uint8_t slot_id_param;
    6568              :     void *data;
    6569              :     size_t data_size;
    6570              :     void *hash;
    6571              :     size_t hash_size;
    6572              : 
    6573            1 :     spdm_test_context = *state;
    6574            1 :     spdm_context = spdm_test_context->spdm_context;
    6575              : 
    6576            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    6577            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    6578              :     }
    6579              : 
    6580            1 :     spdm_test_context->case_id = 0x11;
    6581            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6582              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6583            1 :     spdm_context->connection_info.connection_state =
    6584              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6585            1 :     spdm_context->connection_info.capability.flags |=
    6586              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    6587            1 :     spdm_context->connection_info.capability.flags |=
    6588              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6589            1 :     spdm_context->local_context.capability.flags |=
    6590              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    6591              : 
    6592            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6593              :                                                          m_libspdm_use_asym_algo, &data,
    6594              :                                                          &data_size, &hash, &hash_size)) {
    6595            0 :         assert(false);
    6596              :     }
    6597            1 :     libspdm_reset_message_a(spdm_context);
    6598            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6599              :         m_libspdm_use_hash_algo;
    6600            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6601              :         m_libspdm_use_asym_algo;
    6602            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6603              :         m_libspdm_use_dhe_algo;
    6604            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6605              :         m_libspdm_use_aead_algo;
    6606            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6607              :         m_libspdm_use_measurement_hash_algo;
    6608              : 
    6609              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6610              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6611              :         data_size;
    6612              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6613              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6614              :                      data, data_size);
    6615              : #else
    6616            1 :     libspdm_hash_all(
    6617              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6618              :         data, data_size,
    6619            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6620            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6621            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6622            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6623              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6624              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6625              :         data, data_size,
    6626              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6627              : #endif
    6628              : 
    6629            1 :     heartbeat_period = 0;
    6630            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6631            1 :     status = libspdm_send_receive_key_exchange(
    6632              :         spdm_context,
    6633              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    6634              :         &session_id, &heartbeat_period, &slot_id_param,
    6635              :         measurement_hash);
    6636            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    6637            1 :     free(data);
    6638            1 : }
    6639              : 
    6640            1 : static void req_key_exchange_case18(void **state)
    6641              : {
    6642              :     libspdm_return_t status;
    6643              :     libspdm_test_context_t *spdm_test_context;
    6644              :     libspdm_context_t *spdm_context;
    6645              :     uint32_t session_id;
    6646              :     uint8_t heartbeat_period;
    6647              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6648              :     uint8_t slot_id_param;
    6649              :     void *data;
    6650              :     size_t data_size;
    6651              :     void *hash;
    6652              :     size_t hash_size;
    6653              : 
    6654            1 :     spdm_test_context = *state;
    6655            1 :     spdm_context = spdm_test_context->spdm_context;
    6656              : 
    6657            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    6658            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    6659              :     }
    6660              : 
    6661            1 :     spdm_test_context->case_id = 0x12;
    6662            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6663              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6664            1 :     spdm_context->connection_info.connection_state =
    6665              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6666            1 :     spdm_context->connection_info.capability.flags |=
    6667              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    6668            1 :     spdm_context->connection_info.capability.flags |=
    6669              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6670            1 :     spdm_context->local_context.capability.flags |=
    6671              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    6672              : 
    6673            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6674              :                                                          m_libspdm_use_asym_algo, &data,
    6675              :                                                          &data_size, &hash, &hash_size)) {
    6676            0 :         assert(false);
    6677              :     }
    6678            1 :     libspdm_reset_message_a(spdm_context);
    6679            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6680              :         m_libspdm_use_hash_algo;
    6681            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6682              :         m_libspdm_use_asym_algo;
    6683            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6684              :         m_libspdm_use_dhe_algo;
    6685            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6686              :         m_libspdm_use_aead_algo;
    6687            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6688              :         m_libspdm_use_measurement_hash_algo;
    6689              : 
    6690              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6691              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6692              :         data_size;
    6693              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6694              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6695              :                      data, data_size);
    6696              : #else
    6697            1 :     libspdm_hash_all(
    6698              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6699              :         data, data_size,
    6700            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6701            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6702            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6703            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6704              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6705              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6706              :         data, data_size,
    6707              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6708              : #endif
    6709              : 
    6710            1 :     heartbeat_period = 0;
    6711            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6712            1 :     status = libspdm_send_receive_key_exchange(
    6713              :         spdm_context,
    6714              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    6715              :         &session_id, &heartbeat_period, &slot_id_param,
    6716              :         measurement_hash);
    6717            1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
    6718            1 :     free(data);
    6719            1 : }
    6720              : 
    6721            1 : static void req_key_exchange_case19(void **state)
    6722              : {
    6723              :     libspdm_return_t status;
    6724              :     libspdm_test_context_t *spdm_test_context;
    6725              :     libspdm_context_t *spdm_context;
    6726              :     uint32_t session_id;
    6727              :     uint8_t heartbeat_period;
    6728              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6729              :     uint8_t slot_id_param;
    6730              :     void *data;
    6731              :     size_t data_size;
    6732              :     void *hash;
    6733              :     size_t hash_size;
    6734              : 
    6735            1 :     spdm_test_context = *state;
    6736            1 :     spdm_context = spdm_test_context->spdm_context;
    6737            1 :     spdm_test_context->case_id = 0x13;
    6738            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6739              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6740            1 :     spdm_context->connection_info.connection_state =
    6741              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6742            1 :     spdm_context->connection_info.capability.flags |=
    6743              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    6744            1 :     spdm_context->connection_info.capability.flags |=
    6745              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6746            1 :     spdm_context->local_context.capability.flags |=
    6747              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    6748              : 
    6749            1 :     spdm_context->connection_info.capability.flags |=
    6750              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
    6751            1 :     spdm_context->local_context.capability.flags |=
    6752              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
    6753              : 
    6754            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6755              :                                                          m_libspdm_use_asym_algo, &data,
    6756              :                                                          &data_size, &hash, &hash_size)) {
    6757            0 :         assert(false);
    6758              :     }
    6759            1 :     libspdm_reset_message_a(spdm_context);
    6760            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6761              :         m_libspdm_use_hash_algo;
    6762            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6763              :         m_libspdm_use_asym_algo;
    6764            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6765              :         m_libspdm_use_dhe_algo;
    6766            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6767              :         m_libspdm_use_aead_algo;
    6768            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6769              :         m_libspdm_use_measurement_hash_algo;
    6770              : 
    6771              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6772              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6773              :         data_size;
    6774              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6775              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6776              :                      data, data_size);
    6777              : #else
    6778            1 :     libspdm_hash_all(
    6779              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6780              :         data, data_size,
    6781            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6782            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6783            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6784            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6785              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6786              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6787              :         data, data_size,
    6788              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6789              : #endif
    6790              : 
    6791            1 :     heartbeat_period = 0;
    6792            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6793            1 :     status = libspdm_send_receive_key_exchange(
    6794              :         spdm_context,
    6795              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    6796              :         &session_id, &heartbeat_period, &slot_id_param,
    6797              :         measurement_hash);
    6798              :     /* Clear Handshake in the clear flags */
    6799            1 :     spdm_context->connection_info.capability.flags &=
    6800              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
    6801            1 :     spdm_context->local_context.capability.flags &=
    6802              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
    6803            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6804            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    6805            1 :     assert_int_equal(
    6806              :         libspdm_secured_message_get_session_state(
    6807              :             spdm_context->session_info[0].secured_message_context),
    6808              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    6809            1 :     free(data);
    6810            1 : }
    6811              : 
    6812            1 : static void req_key_exchange_case20(void **state)
    6813              : {
    6814              :     libspdm_return_t status;
    6815              :     libspdm_test_context_t *spdm_test_context;
    6816              :     libspdm_context_t *spdm_context;
    6817              :     uint32_t session_id;
    6818              :     uint8_t heartbeat_period;
    6819              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6820              :     uint8_t slot_id_param;
    6821              :     void *data;
    6822              :     size_t data_size;
    6823              :     void *hash;
    6824              :     size_t hash_size;
    6825              : 
    6826            1 :     spdm_test_context = *state;
    6827            1 :     spdm_context = spdm_test_context->spdm_context;
    6828              : 
    6829            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    6830            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    6831              :     }
    6832              : 
    6833            1 :     spdm_test_context->case_id = 0x14;
    6834            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6835              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6836            1 :     spdm_context->connection_info.connection_state =
    6837              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6838            1 :     spdm_context->connection_info.capability.flags |=
    6839              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    6840            1 :     spdm_context->connection_info.capability.flags |=
    6841              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6842            1 :     spdm_context->local_context.capability.flags |=
    6843              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    6844              : 
    6845              : 
    6846            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6847              :                                                          m_libspdm_use_asym_algo, &data,
    6848              :                                                          &data_size, &hash, &hash_size)) {
    6849            0 :         assert(false);
    6850              :     }
    6851            1 :     libspdm_reset_message_a(spdm_context);
    6852            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6853              :         m_libspdm_use_hash_algo;
    6854            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6855              :         m_libspdm_use_asym_algo;
    6856            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6857              :         m_libspdm_use_dhe_algo;
    6858            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6859              :         m_libspdm_use_aead_algo;
    6860            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6861              :         m_libspdm_use_measurement_hash_algo;
    6862              : 
    6863              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6864              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6865              :         data_size;
    6866              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6867              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6868              :                      data, data_size);
    6869              : #else
    6870            1 :     libspdm_hash_all(
    6871              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6872              :         data, data_size,
    6873            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6874            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6875            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6876            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6877              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6878              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6879              :         data, data_size,
    6880              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6881              : #endif
    6882              : 
    6883            1 :     heartbeat_period = 0;
    6884            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6885            1 :     status = libspdm_send_receive_key_exchange(
    6886              :         spdm_context,
    6887              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    6888              :         &session_id, &heartbeat_period, &slot_id_param,
    6889              :         measurement_hash);
    6890            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    6891            1 :     free(data);
    6892            1 : }
    6893              : 
    6894            1 : static void req_key_exchange_case21(void **state)
    6895              : {
    6896              :     libspdm_return_t status;
    6897              :     libspdm_test_context_t *spdm_test_context;
    6898              :     libspdm_context_t *spdm_context;
    6899              :     uint32_t session_id;
    6900              :     uint8_t heartbeat_period;
    6901              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    6902              :     uint8_t slot_id_param;
    6903              :     void *data;
    6904              :     size_t data_size;
    6905              :     void *hash;
    6906              :     size_t hash_size;
    6907              : 
    6908            1 :     spdm_test_context = *state;
    6909            1 :     spdm_context = spdm_test_context->spdm_context;
    6910              : 
    6911            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    6912            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    6913              :     }
    6914              : 
    6915            1 :     spdm_test_context->case_id = 0x15;
    6916            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    6917              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6918            1 :     spdm_context->connection_info.connection_state =
    6919              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    6920            1 :     spdm_context->connection_info.capability.flags |=
    6921              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    6922            1 :     spdm_context->connection_info.capability.flags |=
    6923              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6924            1 :     spdm_context->local_context.capability.flags |=
    6925              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    6926              : 
    6927            1 :     spdm_context->connection_info.capability.flags |=
    6928              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
    6929            1 :     spdm_context->local_context.capability.flags |=
    6930              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
    6931              : 
    6932              : 
    6933            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6934              :                                                          m_libspdm_use_asym_algo, &data,
    6935              :                                                          &data_size, &hash, &hash_size)) {
    6936            0 :         assert(false);
    6937              :     }
    6938            1 :     libspdm_reset_message_a(spdm_context);
    6939            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6940              :         m_libspdm_use_hash_algo;
    6941            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6942              :         m_libspdm_use_asym_algo;
    6943            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    6944              :         m_libspdm_use_dhe_algo;
    6945            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    6946              :         m_libspdm_use_aead_algo;
    6947            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6948              :         m_libspdm_use_measurement_hash_algo;
    6949              : 
    6950              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6951              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6952              :         data_size;
    6953              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6954              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6955              :                      data, data_size);
    6956              : #else
    6957            1 :     libspdm_hash_all(
    6958              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6959              :         data, data_size,
    6960            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6961            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6962            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6963            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6964              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6965              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6966              :         data, data_size,
    6967              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6968              : #endif
    6969              : 
    6970            1 :     heartbeat_period = 0;
    6971            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    6972            1 :     status = libspdm_send_receive_key_exchange(
    6973              :         spdm_context,
    6974              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    6975              :         &session_id, &heartbeat_period, &slot_id_param,
    6976              :         measurement_hash);
    6977              :     /* clear Heartbeat flags */
    6978            1 :     spdm_context->connection_info.capability.flags &=
    6979              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
    6980            1 :     spdm_context->local_context.capability.flags &=
    6981              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
    6982            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6983            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    6984            1 :     assert_int_equal(
    6985              :         libspdm_secured_message_get_session_state(
    6986              :             spdm_context->session_info[0].secured_message_context),
    6987              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    6988            1 :     assert_int_equal(heartbeat_period,5);
    6989            1 :     free(data);
    6990            1 : }
    6991              : 
    6992            1 : static void req_key_exchange_case22(void **state)
    6993              : {
    6994              :     libspdm_return_t status;
    6995              :     libspdm_test_context_t *spdm_test_context;
    6996              :     libspdm_context_t *spdm_context;
    6997              :     uint32_t session_id;
    6998              :     uint8_t heartbeat_period;
    6999              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7000              :     uint8_t slot_id_param;
    7001              :     void *data;
    7002              :     size_t data_size;
    7003              :     void *hash;
    7004              :     size_t hash_size;
    7005              : 
    7006            1 :     spdm_test_context = *state;
    7007            1 :     spdm_context = spdm_test_context->spdm_context;
    7008              : 
    7009            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    7010            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    7011              :     }
    7012              : 
    7013            1 :     spdm_test_context->case_id = 0x16;
    7014            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    7015              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7016            1 :     spdm_context->connection_info.connection_state =
    7017              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7018            1 :     spdm_context->connection_info.capability.flags |=
    7019              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    7020            1 :     spdm_context->connection_info.capability.flags |=
    7021              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    7022            1 :     spdm_context->local_context.capability.flags |=
    7023              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    7024              : 
    7025            1 :     spdm_context->connection_info.capability.flags |=
    7026              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
    7027            1 :     spdm_context->local_context.capability.flags |=
    7028              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
    7029              : 
    7030              : 
    7031            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    7032              :                                                          m_libspdm_use_asym_algo, &data,
    7033              :                                                          &data_size, &hash, &hash_size)) {
    7034            0 :         assert(false);
    7035              :     }
    7036            1 :     libspdm_reset_message_a(spdm_context);
    7037            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    7038              :         m_libspdm_use_hash_algo;
    7039            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    7040              :         m_libspdm_use_asym_algo;
    7041            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    7042              :         m_libspdm_use_dhe_algo;
    7043            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    7044              :         m_libspdm_use_aead_algo;
    7045            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    7046              :         m_libspdm_use_measurement_hash_algo;
    7047              : 
    7048              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7049              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    7050              :         data_size;
    7051              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    7052              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    7053              :                      data, data_size);
    7054              : #else
    7055            1 :     libspdm_hash_all(
    7056              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7057              :         data, data_size,
    7058            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    7059            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    7060            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    7061            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    7062              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7063              :         spdm_context->connection_info.algorithm.base_asym_algo,
    7064              :         data, data_size,
    7065              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    7066              : #endif
    7067              : 
    7068            1 :     heartbeat_period = 0;
    7069            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    7070            1 :     status = libspdm_send_receive_key_exchange(
    7071              :         spdm_context,
    7072              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    7073              :         &session_id, &heartbeat_period, &slot_id_param,
    7074              :         measurement_hash);
    7075              : 
    7076              :     /*clear Heartbeat flags*/
    7077            1 :     spdm_context->connection_info.capability.flags &=
    7078              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
    7079            1 :     spdm_context->local_context.capability.flags &=
    7080              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
    7081              : 
    7082            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    7083            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    7084            1 :     assert_int_equal(
    7085              :         libspdm_secured_message_get_session_state(
    7086              :             spdm_context->session_info[0].secured_message_context),
    7087              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    7088            1 :     assert_int_equal(heartbeat_period,0);
    7089            1 :     free(data);
    7090            1 : }
    7091              : 
    7092            1 : static void req_key_exchange_case23(void **state)
    7093              : {
    7094              :     libspdm_return_t status;
    7095              :     libspdm_test_context_t *spdm_test_context;
    7096              :     libspdm_context_t *spdm_context;
    7097              :     uint32_t session_id;
    7098              :     uint8_t heartbeat_period;
    7099              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7100              :     uint8_t slot_id_param;
    7101              :     void *data;
    7102              :     size_t data_size;
    7103              :     void *hash;
    7104              :     size_t hash_size;
    7105              : 
    7106            1 :     spdm_test_context = *state;
    7107            1 :     spdm_context = spdm_test_context->spdm_context;
    7108              : 
    7109            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    7110            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    7111              :     }
    7112              : 
    7113            1 :     spdm_test_context->case_id = 0x17;
    7114            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    7115              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7116            1 :     spdm_context->connection_info.connection_state =
    7117              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7118            1 :     spdm_context->connection_info.capability.flags |=
    7119              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    7120            1 :     spdm_context->connection_info.capability.flags |=
    7121              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    7122            1 :     spdm_context->local_context.capability.flags |=
    7123              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    7124              : 
    7125            1 :     spdm_context->connection_info.capability.flags |=
    7126              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7127            1 :     spdm_context->local_context.capability.flags |=
    7128              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7129              : 
    7130              : 
    7131            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    7132              :                                                          m_libspdm_use_asym_algo, &data,
    7133              :                                                          &data_size, &hash, &hash_size)) {
    7134            0 :         assert(false);
    7135              :     }
    7136            1 :     libspdm_reset_message_a(spdm_context);
    7137            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    7138              :         m_libspdm_use_hash_algo;
    7139            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    7140              :         m_libspdm_use_asym_algo;
    7141            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    7142              :         m_libspdm_use_dhe_algo;
    7143            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    7144              :         m_libspdm_use_aead_algo;
    7145            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    7146              :         m_libspdm_use_measurement_hash_algo;
    7147              : 
    7148              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7149              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    7150              :         data_size;
    7151              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    7152              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    7153              :                      data, data_size);
    7154              : #else
    7155            1 :     libspdm_hash_all(
    7156              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7157              :         data, data_size,
    7158            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    7159            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    7160            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    7161            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    7162              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7163              :         spdm_context->connection_info.algorithm.base_asym_algo,
    7164              :         data, data_size,
    7165              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    7166              : #endif
    7167              : 
    7168            1 :     heartbeat_period = 0;
    7169            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    7170            1 :     status = libspdm_send_receive_key_exchange(
    7171              :         spdm_context,
    7172              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    7173              :         &session_id, &heartbeat_period, &slot_id_param,
    7174              :         measurement_hash);
    7175              :     /* Clear Mut_auth flags */
    7176            1 :     spdm_context->connection_info.capability.flags &=
    7177              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7178            1 :     spdm_context->local_context.capability.flags &=
    7179              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7180            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    7181            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    7182            1 :     assert_int_equal(
    7183              :         libspdm_secured_message_get_session_state(
    7184              :             spdm_context->session_info[0].secured_message_context),
    7185              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    7186            1 :     assert_int_equal(
    7187              :         spdm_context->session_info[0].mut_auth_requested,
    7188              :         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED);
    7189            1 :     free(data);
    7190            1 : }
    7191              : 
    7192            1 : static void req_key_exchange_case24(void **state)
    7193              : {
    7194              :     libspdm_return_t status;
    7195              :     libspdm_test_context_t *spdm_test_context;
    7196              :     libspdm_context_t *spdm_context;
    7197              :     uint32_t session_id;
    7198              :     uint8_t heartbeat_period;
    7199              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7200              :     uint8_t slot_id_param;
    7201              :     void *data;
    7202              :     size_t data_size;
    7203              :     void *hash;
    7204              :     size_t hash_size;
    7205              : 
    7206            1 :     spdm_test_context = *state;
    7207            1 :     spdm_context = spdm_test_context->spdm_context;
    7208              : 
    7209            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    7210            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    7211              :     }
    7212              : 
    7213            1 :     spdm_test_context->case_id = 0x18;
    7214            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    7215              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7216            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7217            1 :     spdm_context->connection_info.capability.flags |=
    7218              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    7219            1 :     spdm_context->connection_info.capability.flags |=
    7220              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    7221            1 :     spdm_context->local_context.capability.flags |=
    7222              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    7223              : 
    7224            1 :     spdm_context->connection_info.capability.flags |=
    7225              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7226            1 :     spdm_context->local_context.capability.flags |=
    7227              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7228              : 
    7229            1 :     spdm_context->connection_info.capability.flags |=
    7230              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
    7231            1 :     spdm_context->local_context.capability.flags |=
    7232              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
    7233              : 
    7234            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    7235              :                                                          m_libspdm_use_asym_algo, &data,
    7236              :                                                          &data_size, &hash, &hash_size)) {
    7237            0 :         assert(false);
    7238              :     }
    7239            1 :     libspdm_reset_message_a(spdm_context);
    7240            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    7241            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    7242            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    7243            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    7244            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    7245              :         m_libspdm_use_measurement_hash_algo;
    7246              : 
    7247              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7248              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    7249              :         data_size;
    7250              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    7251              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    7252              :                      data, data_size);
    7253              : #else
    7254            1 :     libspdm_hash_all(
    7255              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7256              :         data, data_size,
    7257            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    7258            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    7259            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    7260            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    7261              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7262              :         spdm_context->connection_info.algorithm.base_asym_algo,
    7263              :         data, data_size,
    7264              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    7265              : #endif
    7266              : 
    7267            1 :     heartbeat_period = 0;
    7268            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    7269            1 :     status = libspdm_send_receive_key_exchange(
    7270              :         spdm_context,
    7271              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    7272              :         &session_id, &heartbeat_period, &slot_id_param,
    7273              :         measurement_hash);
    7274              :     /* Clear Mut_auth flags */
    7275            1 :     spdm_context->connection_info.capability.flags &=
    7276              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7277            1 :     spdm_context->local_context.capability.flags &=
    7278              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7279            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    7280            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    7281            1 :     assert_int_equal(
    7282              :         libspdm_secured_message_get_session_state(
    7283              :             spdm_context->session_info[0].secured_message_context),
    7284              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    7285            1 :     assert_int_equal(
    7286              :         spdm_context->session_info[0].mut_auth_requested,
    7287              :         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_ENCAP_REQUEST);
    7288            1 :     free(data);
    7289            1 : }
    7290              : 
    7291            1 : static void req_key_exchange_case25(void **state)
    7292              : {
    7293              :     libspdm_return_t status;
    7294              :     libspdm_test_context_t *spdm_test_context;
    7295              :     libspdm_context_t *spdm_context;
    7296              :     uint32_t session_id;
    7297              :     uint8_t heartbeat_period;
    7298              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7299              :     uint8_t slot_id_param;
    7300              :     void *data;
    7301              :     size_t data_size;
    7302              :     void *hash;
    7303              :     size_t hash_size;
    7304              : 
    7305            1 :     spdm_test_context = *state;
    7306            1 :     spdm_context = spdm_test_context->spdm_context;
    7307              : 
    7308            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    7309            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    7310              :     }
    7311              : 
    7312            1 :     spdm_test_context->case_id = 0x19;
    7313            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    7314              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7315            1 :     spdm_context->connection_info.connection_state =
    7316              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7317            1 :     spdm_context->connection_info.capability.flags |=
    7318              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    7319            1 :     spdm_context->connection_info.capability.flags |=
    7320              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    7321            1 :     spdm_context->local_context.capability.flags |=
    7322              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    7323              : 
    7324            1 :     spdm_context->connection_info.capability.flags |=
    7325              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7326            1 :     spdm_context->local_context.capability.flags |=
    7327              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7328              : 
    7329            1 :     spdm_context->connection_info.capability.flags |=
    7330              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
    7331            1 :     spdm_context->local_context.capability.flags |=
    7332              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
    7333              : 
    7334            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    7335              :                                                          m_libspdm_use_asym_algo, &data,
    7336              :                                                          &data_size, &hash, &hash_size)) {
    7337            0 :         assert(false);
    7338              :     }
    7339            1 :     libspdm_reset_message_a(spdm_context);
    7340            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    7341              :         m_libspdm_use_hash_algo;
    7342            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    7343              :         m_libspdm_use_asym_algo;
    7344            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    7345              :         m_libspdm_use_dhe_algo;
    7346            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    7347              :         m_libspdm_use_aead_algo;
    7348            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    7349              :         m_libspdm_use_measurement_hash_algo;
    7350              : 
    7351              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7352              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    7353              :         data_size;
    7354              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    7355              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    7356              :                      data, data_size);
    7357              : #else
    7358            1 :     libspdm_hash_all(
    7359              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7360              :         data, data_size,
    7361            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    7362            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    7363            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    7364            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    7365              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7366              :         spdm_context->connection_info.algorithm.base_asym_algo,
    7367              :         data, data_size,
    7368              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    7369              : #endif
    7370              : 
    7371            1 :     heartbeat_period = 0;
    7372            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    7373            1 :     status = libspdm_send_receive_key_exchange(
    7374              :         spdm_context,
    7375              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    7376              :         &session_id, &heartbeat_period, &slot_id_param,
    7377              :         measurement_hash);
    7378              :     /* Clear Mut_auth flags */
    7379            1 :     spdm_context->connection_info.capability.flags &=
    7380              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7381            1 :     spdm_context->local_context.capability.flags &=
    7382              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7383            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    7384            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    7385            1 :     assert_int_equal(
    7386              :         libspdm_secured_message_get_session_state(
    7387              :             spdm_context->session_info[0].secured_message_context),
    7388              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    7389            1 :     assert_int_equal(
    7390              :         spdm_context->session_info[0].mut_auth_requested,
    7391              :         SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED_WITH_GET_DIGESTS);
    7392            1 :     free(data);
    7393            1 : }
    7394              : 
    7395            1 : static void req_key_exchange_case26(void **state)
    7396              : {
    7397              :     libspdm_return_t status;
    7398              :     libspdm_test_context_t *spdm_test_context;
    7399              :     libspdm_context_t *spdm_context;
    7400              :     uint32_t session_id;
    7401              :     uint8_t heartbeat_period;
    7402              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7403              :     uint8_t slot_id_param;
    7404              :     void *data;
    7405              :     size_t data_size;
    7406              :     void *hash;
    7407              :     size_t hash_size;
    7408              : 
    7409            1 :     spdm_test_context = *state;
    7410            1 :     spdm_context = spdm_test_context->spdm_context;
    7411              : 
    7412            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    7413            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    7414              :     }
    7415              : 
    7416            1 :     spdm_test_context->case_id = 0x1A;
    7417            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    7418              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7419            1 :     spdm_context->connection_info.connection_state =
    7420              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7421            1 :     spdm_context->connection_info.capability.flags |=
    7422              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    7423            1 :     spdm_context->connection_info.capability.flags |=
    7424              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    7425            1 :     spdm_context->local_context.capability.flags |=
    7426              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    7427              : 
    7428            1 :     spdm_context->connection_info.capability.flags |=
    7429              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7430            1 :     spdm_context->local_context.capability.flags |=
    7431              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7432              : 
    7433              : 
    7434            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    7435              :                                                          m_libspdm_use_asym_algo, &data,
    7436              :                                                          &data_size, &hash, &hash_size)) {
    7437            0 :         assert(false);
    7438              :     }
    7439            1 :     libspdm_reset_message_a(spdm_context);
    7440            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    7441              :         m_libspdm_use_hash_algo;
    7442            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    7443              :         m_libspdm_use_asym_algo;
    7444            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    7445              :         m_libspdm_use_dhe_algo;
    7446            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    7447              :         m_libspdm_use_aead_algo;
    7448            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    7449              :         m_libspdm_use_measurement_hash_algo;
    7450              : 
    7451              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7452              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    7453              :         data_size;
    7454              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    7455              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    7456              :                      data, data_size);
    7457              : #else
    7458            1 :     libspdm_hash_all(
    7459              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7460              :         data, data_size,
    7461            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    7462            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    7463            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    7464            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    7465              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7466              :         spdm_context->connection_info.algorithm.base_asym_algo,
    7467              :         data, data_size,
    7468              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    7469              : #endif
    7470              : 
    7471            1 :     heartbeat_period = 0;
    7472            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    7473            1 :     status = libspdm_send_receive_key_exchange(
    7474              :         spdm_context,
    7475              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    7476              :         &session_id, &heartbeat_period, &slot_id_param,
    7477              :         measurement_hash);
    7478              :     /* Clear Mut_auth flags */
    7479            1 :     spdm_context->connection_info.capability.flags &=
    7480              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7481            1 :     spdm_context->local_context.capability.flags &=
    7482              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7483            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    7484            1 :     free(data);
    7485            1 : }
    7486              : 
    7487            1 : static void req_key_exchange_case27(void **state)
    7488              : {
    7489              :     libspdm_return_t status;
    7490              :     libspdm_test_context_t *spdm_test_context;
    7491              :     libspdm_context_t *spdm_context;
    7492              :     uint32_t session_id;
    7493              :     uint8_t heartbeat_period;
    7494              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7495              :     uint8_t slot_id_param;
    7496              :     void *data;
    7497              :     size_t data_size;
    7498              :     void *hash;
    7499              :     size_t hash_size;
    7500              : 
    7501            1 :     spdm_test_context = *state;
    7502            1 :     spdm_context = spdm_test_context->spdm_context;
    7503              : 
    7504            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    7505            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    7506              :     }
    7507              : 
    7508            1 :     spdm_test_context->case_id = 0x1B;
    7509            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    7510              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7511            1 :     spdm_context->connection_info.connection_state =
    7512              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7513            1 :     spdm_context->connection_info.capability.flags |=
    7514              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    7515            1 :     spdm_context->connection_info.capability.flags |=
    7516              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    7517            1 :     spdm_context->local_context.capability.flags |=
    7518              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    7519              : 
    7520            1 :     spdm_context->connection_info.capability.flags |=
    7521              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7522            1 :     spdm_context->local_context.capability.flags |=
    7523              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7524              : 
    7525              : 
    7526            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    7527              :                                                          m_libspdm_use_asym_algo, &data,
    7528              :                                                          &data_size, &hash, &hash_size)) {
    7529            0 :         assert(false);
    7530              :     }
    7531            1 :     libspdm_reset_message_a(spdm_context);
    7532            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    7533              :         m_libspdm_use_hash_algo;
    7534            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    7535              :         m_libspdm_use_asym_algo;
    7536            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    7537              :         m_libspdm_use_dhe_algo;
    7538            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    7539              :         m_libspdm_use_aead_algo;
    7540            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    7541              :         m_libspdm_use_measurement_hash_algo;
    7542              : 
    7543              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7544              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    7545              :         data_size;
    7546              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    7547              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    7548              :                      data, data_size);
    7549              : #else
    7550            1 :     libspdm_hash_all(
    7551              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7552              :         data, data_size,
    7553            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    7554            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    7555            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    7556            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    7557              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7558              :         spdm_context->connection_info.algorithm.base_asym_algo,
    7559              :         data, data_size,
    7560              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    7561              : #endif
    7562              : 
    7563            1 :     heartbeat_period = 0;
    7564            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    7565            1 :     status = libspdm_send_receive_key_exchange(
    7566              :         spdm_context,
    7567              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    7568              :         &session_id, &heartbeat_period, &slot_id_param,
    7569              :         measurement_hash);
    7570              :     /*Clear Mut_auth flags*/
    7571            1 :     spdm_context->connection_info.capability.flags &=
    7572              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7573            1 :     spdm_context->local_context.capability.flags &=
    7574              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7575            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    7576            1 :     free(data);
    7577            1 : }
    7578              : 
    7579            1 : static void req_key_exchange_case28(void **state)
    7580              : {
    7581              :     libspdm_return_t status;
    7582              :     libspdm_test_context_t *spdm_test_context;
    7583              :     libspdm_context_t *spdm_context;
    7584              :     uint32_t session_id;
    7585              :     uint8_t heartbeat_period;
    7586              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7587              :     uint8_t slot_id_param;
    7588              :     void *data;
    7589              :     size_t data_size;
    7590              :     void *hash;
    7591              :     size_t hash_size;
    7592              : 
    7593            1 :     spdm_test_context = *state;
    7594            1 :     spdm_context = spdm_test_context->spdm_context;
    7595              : 
    7596            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    7597            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    7598              :     }
    7599              : 
    7600            1 :     spdm_test_context->case_id = 0x1C;
    7601            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    7602              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7603            1 :     spdm_context->connection_info.connection_state =
    7604              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7605            1 :     spdm_context->connection_info.capability.flags |=
    7606              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
    7607            1 :     spdm_context->connection_info.capability.flags |=
    7608              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    7609            1 :     spdm_context->local_context.capability.flags |=
    7610              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
    7611              : 
    7612            1 :     spdm_context->connection_info.capability.flags |=
    7613              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7614            1 :     spdm_context->local_context.capability.flags |=
    7615              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7616              : 
    7617              : 
    7618            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    7619              :                                                          m_libspdm_use_asym_algo, &data,
    7620              :                                                          &data_size, &hash, &hash_size)) {
    7621            0 :         assert(false);
    7622              :     }
    7623            1 :     libspdm_reset_message_a(spdm_context);
    7624            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    7625              :         m_libspdm_use_hash_algo;
    7626            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    7627              :         m_libspdm_use_asym_algo;
    7628            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    7629              :         m_libspdm_use_dhe_algo;
    7630            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    7631              :         m_libspdm_use_aead_algo;
    7632            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    7633              :         m_libspdm_use_measurement_hash_algo;
    7634              : 
    7635              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7636              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    7637              :         data_size;
    7638              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    7639              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    7640              :                      data, data_size);
    7641              : #else
    7642            1 :     libspdm_hash_all(
    7643              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7644              :         data, data_size,
    7645            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    7646            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    7647            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    7648            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    7649              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7650              :         spdm_context->connection_info.algorithm.base_asym_algo,
    7651              :         data, data_size,
    7652              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    7653              : #endif
    7654              : 
    7655            1 :     heartbeat_period = 0;
    7656            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    7657            1 :     status = libspdm_send_receive_key_exchange(
    7658              :         spdm_context,
    7659              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    7660              :         &session_id, &heartbeat_period, &slot_id_param,
    7661              :         measurement_hash);
    7662              :     /* Clear Mut_auth flags */
    7663            1 :     spdm_context->connection_info.capability.flags &=
    7664              :         ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
    7665            1 :     spdm_context->local_context.capability.flags &=
    7666              :         ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
    7667            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    7668            1 :     free(data);
    7669            1 : }
    7670              : 
    7671            1 : static void req_key_exchange_case29(void **state)
    7672              : {
    7673              :     libspdm_return_t status;
    7674              :     libspdm_test_context_t *spdm_test_context;
    7675              :     libspdm_context_t *spdm_context;
    7676              :     uint32_t session_id;
    7677              :     uint8_t heartbeat_period;
    7678              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7679              :     uint8_t slot_id_param;
    7680              :     void *data;
    7681              :     size_t data_size;
    7682              :     void *hash;
    7683              :     size_t hash_size;
    7684              : 
    7685            1 :     spdm_test_context = *state;
    7686            1 :     spdm_context = spdm_test_context->spdm_context;
    7687              : 
    7688            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    7689            0 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    7690              :     }
    7691              : 
    7692            1 :     spdm_test_context->case_id = 0x1D;
    7693            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    7694              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7695            1 :     spdm_context->connection_info.connection_state =
    7696              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7697            1 :     spdm_context->connection_info.capability.flags |=
    7698              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    7699              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    7700            1 :     spdm_context->local_context.capability.flags |=
    7701              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    7702              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    7703            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    7704              :                                                          m_libspdm_use_asym_algo, &data,
    7705              :                                                          &data_size, &hash, &hash_size)) {
    7706            0 :         assert(false);
    7707              :     }
    7708            1 :     libspdm_reset_message_a(spdm_context);
    7709            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    7710            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    7711            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    7712            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    7713              : 
    7714              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7715              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    7716              :         data_size;
    7717              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    7718              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    7719              :                      data, data_size);
    7720              : #else
    7721            1 :     libspdm_hash_all(
    7722              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7723              :         data, data_size,
    7724            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    7725            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    7726            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    7727            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    7728              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7729              :         spdm_context->connection_info.algorithm.base_asym_algo,
    7730              :         data, data_size,
    7731              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    7732              : #endif
    7733              : 
    7734            1 :     heartbeat_period = 0;
    7735            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    7736            1 :     status = libspdm_send_receive_key_exchange(
    7737              :         spdm_context,
    7738              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    7739              :         &session_id, &heartbeat_period, &slot_id_param,
    7740              :         measurement_hash);
    7741            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    7742            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    7743            1 :     assert_int_equal(
    7744              :         libspdm_secured_message_get_session_state(
    7745              :             spdm_context->session_info[0].secured_message_context),
    7746              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    7747              : 
    7748              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7749              :     assert_int_equal(spdm_context->session_info[0].session_transcript.message_k.buffer_size,
    7750              :                      m_libspdm_local_buffer_size);
    7751              :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
    7752              :                    m_libspdm_local_buffer_size));
    7753              :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    7754              :     assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer,
    7755              :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    7756              : #endif
    7757              : 
    7758            1 :     free(data);
    7759            1 : }
    7760              : 
    7761            1 : static void req_key_exchange_case30(void **state)
    7762              : {
    7763              :     libspdm_return_t status;
    7764              :     libspdm_test_context_t *spdm_test_context;
    7765              :     libspdm_context_t *spdm_context;
    7766              :     uint32_t session_id;
    7767              :     uint8_t heartbeat_period;
    7768              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7769              :     uint8_t slot_id_param;
    7770              :     void *data;
    7771              :     size_t data_size;
    7772              :     void *hash;
    7773              :     size_t hash_size;
    7774              : 
    7775            1 :     spdm_test_context = *state;
    7776            1 :     spdm_context = spdm_test_context->spdm_context;
    7777            1 :     spdm_test_context->case_id = 0x1e;
    7778            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    7779              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7780            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7781            1 :     spdm_context->connection_info.capability.flags |=
    7782              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    7783              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    7784            1 :     spdm_context->local_context.capability.flags |=
    7785              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    7786              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    7787            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    7788            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    7789              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    7790            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    7791              :                                                          m_libspdm_use_asym_algo, &data,
    7792              :                                                          &data_size, &hash, &hash_size)) {
    7793            0 :         assert(false);
    7794              :     }
    7795            1 :     libspdm_reset_message_a(spdm_context);
    7796            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    7797            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    7798            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    7799            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    7800            1 :     spdm_context->connection_info.algorithm.other_params_support =
    7801              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    7802            1 :     libspdm_session_info_init(spdm_context,
    7803            1 :                               spdm_context->session_info,
    7804              :                               0,
    7805              :                               INVALID_SESSION_ID, false);
    7806              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7807              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    7808              :         data_size;
    7809              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    7810              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    7811              :                      data, data_size);
    7812              : #else
    7813            1 :     libspdm_hash_all(
    7814              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7815              :         data, data_size,
    7816            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    7817            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    7818            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    7819            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    7820              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7821              :         spdm_context->connection_info.algorithm.base_asym_algo,
    7822              :         data, data_size,
    7823              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    7824              : #endif
    7825              : 
    7826            1 :     heartbeat_period = 0;
    7827            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    7828            1 :     status = libspdm_send_receive_key_exchange(
    7829              :         spdm_context,
    7830              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0,
    7831              :         SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE,
    7832              :         &session_id, &heartbeat_period, &slot_id_param,
    7833              :         measurement_hash);
    7834            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    7835            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    7836            1 :     assert_int_equal(
    7837              :         libspdm_secured_message_get_session_state(
    7838              :             spdm_context->session_info[0].secured_message_context),
    7839              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    7840            1 :     assert_int_equal(spdm_context->session_info[0].session_policy,
    7841              :                      SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE);
    7842            1 :     free(data);
    7843            1 : }
    7844              : 
    7845              : /**
    7846              :  * Test 31: Exercise the libspdm_send_receive_key_exchange_ex path
    7847              :  * Expected Behavior: requester_random_in is sent to Responder and correct responder_random is
    7848              :  *                    returned to Requester.
    7849              :  **/
    7850            1 : static void req_key_exchange_case31(void **state)
    7851              : {
    7852              :     libspdm_return_t status;
    7853              :     libspdm_test_context_t *spdm_test_context;
    7854              :     libspdm_context_t *spdm_context;
    7855              :     uint32_t session_id;
    7856              :     uint8_t heartbeat_period;
    7857              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7858              :     uint8_t slot_id_param;
    7859              :     void *data;
    7860              :     size_t data_size;
    7861              :     void *hash;
    7862              :     size_t hash_size;
    7863              :     uint8_t requester_random_in[SPDM_RANDOM_DATA_SIZE];
    7864              :     uint8_t requester_random[SPDM_RANDOM_DATA_SIZE];
    7865              :     uint8_t responder_random[SPDM_RANDOM_DATA_SIZE];
    7866              :     uint8_t responder_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
    7867              :     size_t responder_opaque_data_size;
    7868              :     uint8_t requester_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
    7869              :     size_t requester_opaque_data_size;
    7870              : 
    7871            1 :     spdm_test_context = *state;
    7872            1 :     spdm_context = spdm_test_context->spdm_context;
    7873            1 :     spdm_test_context->case_id = 0x1f;
    7874            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    7875              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7876            1 :     spdm_context->connection_info.connection_state =
    7877              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7878            1 :     spdm_context->connection_info.capability.flags |=
    7879              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    7880              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    7881            1 :     spdm_context->local_context.capability.flags |=
    7882              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    7883              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    7884            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    7885            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    7886              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    7887            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    7888              :                                                          m_libspdm_use_asym_algo, &data,
    7889              :                                                          &data_size, &hash, &hash_size)) {
    7890            0 :         assert(false);
    7891              :     }
    7892            1 :     libspdm_reset_message_a(spdm_context);
    7893            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    7894              :         m_libspdm_use_hash_algo;
    7895            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    7896              :         m_libspdm_use_asym_algo;
    7897            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    7898              :         m_libspdm_use_dhe_algo;
    7899            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    7900              :         m_libspdm_use_aead_algo;
    7901              : 
    7902            1 :     if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    7903            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    7904              :     }
    7905              : 
    7906              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    7907              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    7908              :         data_size;
    7909              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    7910              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    7911              :                      data, data_size);
    7912              : #else
    7913            1 :     libspdm_hash_all(
    7914              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7915              :         data, data_size,
    7916            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    7917            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    7918            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    7919            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    7920              :         spdm_context->connection_info.algorithm.base_hash_algo,
    7921              :         spdm_context->connection_info.algorithm.base_asym_algo,
    7922              :         data, data_size,
    7923              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    7924              : #endif
    7925              : 
    7926           33 :     for (int index = 0; index < SPDM_RANDOM_DATA_SIZE; index++) {
    7927           32 :         requester_random_in[index] = 0x12;
    7928              :     }
    7929              : 
    7930            1 :     heartbeat_period = 0;
    7931            1 :     responder_opaque_data_size = sizeof(responder_opaque_data);
    7932            1 :     requester_opaque_data_size = sizeof(requester_opaque_data);
    7933            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    7934            1 :     status = libspdm_send_receive_key_exchange_ex(
    7935              :         spdm_context,
    7936              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    7937              :         &session_id, &heartbeat_period, &slot_id_param,
    7938              :         measurement_hash, requester_random_in, requester_random, responder_random,
    7939              :         requester_opaque_data, requester_opaque_data_size,
    7940              :         responder_opaque_data, &responder_opaque_data_size);
    7941            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    7942            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    7943            1 :     assert_int_equal(
    7944              :         libspdm_secured_message_get_session_state(
    7945              :             spdm_context->session_info[0].secured_message_context),
    7946              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    7947              : 
    7948           33 :     for (int index = 0; index < SPDM_RANDOM_DATA_SIZE; index++) {
    7949           32 :         assert_int_equal(requester_random[index], requester_random_in[index]);
    7950           32 :         assert_int_equal(requester_random[index], 0x12);
    7951           32 :         assert_int_equal(responder_random[index], 0x5c);
    7952              :     }
    7953              : 
    7954            1 :     free(data);
    7955            1 : }
    7956              : 
    7957            1 : void req_key_exchange_case32(void **state)
    7958              : {
    7959              :     libspdm_return_t status;
    7960              :     libspdm_test_context_t *spdm_test_context;
    7961              :     libspdm_context_t *spdm_context;
    7962              :     uint32_t session_id;
    7963              :     uint8_t heartbeat_period;
    7964              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    7965              :     uint8_t slot_id_param;
    7966              :     void *data;
    7967              :     size_t data_size;
    7968              : 
    7969            1 :     spdm_test_context = *state;
    7970            1 :     spdm_context = spdm_test_context->spdm_context;
    7971            1 :     spdm_test_context->case_id = 0x20;
    7972            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    7973              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    7974            1 :     spdm_context->connection_info.connection_state =
    7975              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    7976            1 :     spdm_context->connection_info.capability.flags |=
    7977              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    7978              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    7979            1 :     spdm_context->local_context.capability.flags |=
    7980              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    7981              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    7982            1 :     spdm_context->connection_info.capability.flags |=
    7983              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
    7984            1 :     spdm_context->local_context.capability.flags |=
    7985              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP;
    7986            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    7987            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    7988              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    7989            1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
    7990            1 :     spdm_context->local_context.peer_public_key_provision = data;
    7991            1 :     spdm_context->local_context.peer_public_key_provision_size = data_size;
    7992              : 
    7993            1 :     libspdm_reset_message_a(spdm_context);
    7994            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    7995            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    7996            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    7997            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    7998            1 :     spdm_context->connection_info.algorithm.other_params_support =
    7999              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    8000            1 :     libspdm_session_info_init(spdm_context,
    8001            1 :                               spdm_context->session_info,
    8002              :                               0,
    8003              :                               INVALID_SESSION_ID, false);
    8004              : 
    8005            1 :     heartbeat_period = 0;
    8006            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    8007            1 :     status = libspdm_send_receive_key_exchange(
    8008              :         spdm_context,
    8009              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0xFF,
    8010              :         SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE,
    8011              :         &session_id, &heartbeat_period, &slot_id_param,
    8012              :         measurement_hash);
    8013            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    8014            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    8015            1 :     assert_int_equal(
    8016              :         libspdm_secured_message_get_session_state(
    8017              :             spdm_context->session_info[0].secured_message_context),
    8018              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    8019            1 :     assert_int_equal(spdm_context->session_info[0].session_policy,
    8020              :                      SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE);
    8021            1 :     free(data);
    8022            1 : }
    8023              : 
    8024            1 : static void req_key_exchange_case33(void **state)
    8025              : {
    8026              :     libspdm_return_t status;
    8027              :     libspdm_test_context_t *spdm_test_context;
    8028              :     libspdm_context_t *spdm_context;
    8029              :     uint32_t session_id;
    8030              :     uint8_t heartbeat_period;
    8031              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    8032              :     uint8_t slot_id_param;
    8033              :     void *data;
    8034              :     size_t data_size;
    8035              :     void *hash;
    8036              :     size_t hash_size;
    8037              : 
    8038            1 :     spdm_test_context = *state;
    8039            1 :     spdm_context = spdm_test_context->spdm_context;
    8040            1 :     spdm_test_context->case_id = 0x21;
    8041            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    8042              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    8043            1 :     spdm_context->connection_info.connection_state =
    8044              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    8045            1 :     spdm_context->connection_info.capability.flags |=
    8046              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    8047              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    8048            1 :     spdm_context->local_context.capability.flags |=
    8049              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    8050              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    8051            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    8052            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    8053              :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    8054            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    8055              :                                                          m_libspdm_use_asym_algo, &data,
    8056              :                                                          &data_size, &hash, &hash_size)) {
    8057            0 :         assert(false);
    8058              :     }
    8059            1 :     libspdm_reset_message_a(spdm_context);
    8060            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    8061              :         m_libspdm_use_hash_algo;
    8062            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    8063              :         m_libspdm_use_asym_algo;
    8064            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    8065              :         m_libspdm_use_dhe_algo;
    8066            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    8067              :         m_libspdm_use_aead_algo;
    8068            1 :     spdm_context->connection_info.algorithm.other_params_support =
    8069              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    8070            1 :     libspdm_session_info_init(spdm_context,
    8071            1 :                               spdm_context->session_info,
    8072              :                               0,
    8073              :                               INVALID_SESSION_ID, false);
    8074              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    8075              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    8076              :         data_size;
    8077              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    8078              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    8079              :                      data, data_size);
    8080              : #else
    8081            1 :     libspdm_hash_all(
    8082              :         spdm_context->connection_info.algorithm.base_hash_algo,
    8083              :         data, data_size,
    8084            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    8085            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    8086            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    8087            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    8088              :         spdm_context->connection_info.algorithm.base_hash_algo,
    8089              :         spdm_context->connection_info.algorithm.base_asym_algo,
    8090              :         data, data_size,
    8091              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    8092              : #endif
    8093              : 
    8094            1 :     heartbeat_period = 0;
    8095            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    8096            1 :     status = libspdm_send_receive_key_exchange(
    8097              :         spdm_context,
    8098              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0,
    8099              :         SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE,
    8100              :         &session_id, &heartbeat_period, &slot_id_param,
    8101              :         measurement_hash);
    8102            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    8103            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    8104            1 :     assert_int_equal(
    8105              :         libspdm_secured_message_get_session_state(
    8106              :             spdm_context->session_info[0].secured_message_context),
    8107              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    8108            1 :     assert_int_equal(spdm_context->session_info[0].session_policy,
    8109              :                      SPDM_KEY_EXCHANGE_REQUEST_SESSION_POLICY_TERMINATION_POLICY_RUNTIME_UPDATE);
    8110            1 :     free(data);
    8111            1 : }
    8112              : 
    8113              : /**
    8114              :  * Test 34: The secured message version is 1.2 and the Integrator has set the sequence number
    8115              :  *          endianness to big-endian. After key exchange the session's endianness will be
    8116              :  *          little-endian as 277 1.2 only supports little-endian.
    8117              :  * Expected Behavior: A successful key exchange with the session's endianness set to little-endian.
    8118              :  **/
    8119            1 : static void req_key_exchange_case34(void **state)
    8120              : {
    8121              :     libspdm_return_t status;
    8122              :     libspdm_test_context_t *spdm_test_context;
    8123              :     libspdm_context_t *spdm_context;
    8124              :     uint32_t session_id;
    8125              :     uint8_t heartbeat_period;
    8126              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    8127              :     uint8_t slot_id_param;
    8128              :     void *data;
    8129              :     size_t data_size;
    8130              :     void *hash;
    8131              :     size_t hash_size;
    8132              : 
    8133            1 :     spdm_test_context = *state;
    8134            1 :     spdm_context = spdm_test_context->spdm_context;
    8135              : 
    8136            1 :     if (spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
    8137            1 :         libspdm_free_session_id(spdm_context,0xFFFFFFFF);
    8138              :     }
    8139              : 
    8140            1 :     spdm_test_context->case_id = 0x22;
    8141            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    8142              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    8143            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    8144            1 :     spdm_context->connection_info.capability.flags |=
    8145              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
    8146              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    8147            1 :     spdm_context->local_context.capability.flags |=
    8148              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP |
    8149              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    8150            1 :     spdm_context->local_context.secured_message_version.spdm_version_count = 1;
    8151            1 :     spdm_context->local_context.secured_message_version.spdm_version[0] =
    8152              :         SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    8153              : 
    8154              :     /* Set 277 sequence number endianness to big-endian. */
    8155            1 :     spdm_context->sequence_number_endian = LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_BIG_DEC_BIG;
    8156              : 
    8157            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    8158              :                                                          m_libspdm_use_asym_algo, &data,
    8159              :                                                          &data_size, &hash, &hash_size)) {
    8160            0 :         assert(false);
    8161              :     }
    8162            1 :     libspdm_reset_message_a(spdm_context);
    8163            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    8164            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    8165            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    8166            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    8167              : 
    8168              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    8169              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
    8170              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    8171              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    8172              :                      data, data_size);
    8173              : #else
    8174            1 :     libspdm_hash_all(
    8175              :         spdm_context->connection_info.algorithm.base_hash_algo,
    8176              :         data, data_size,
    8177            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    8178            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    8179            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    8180            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    8181              :         spdm_context->connection_info.algorithm.base_hash_algo,
    8182              :         spdm_context->connection_info.algorithm.base_asym_algo,
    8183              :         data, data_size,
    8184              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    8185              : #endif
    8186              : 
    8187            1 :     heartbeat_period = 0;
    8188            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    8189            1 :     status = libspdm_send_receive_key_exchange(
    8190              :         spdm_context,
    8191              :         SPDM_KEY_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, 0,
    8192              :         &session_id, &heartbeat_period, &slot_id_param,
    8193              :         measurement_hash);
    8194            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    8195            1 :     assert_int_equal(session_id, 0xFFFFFFFF);
    8196            1 :     assert_int_equal(
    8197              :         libspdm_secured_message_get_session_state(
    8198              :             spdm_context->session_info[0].secured_message_context),
    8199              :         LIBSPDM_SESSION_STATE_HANDSHAKING);
    8200            1 :     assert_int_equal(((libspdm_secured_message_context_t *)spdm_context->session_info->
    8201              :                       secured_message_context)->sequence_number_endian,
    8202              :                      LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE);
    8203            1 :     free(data);
    8204            1 : }
    8205              : 
    8206            1 : int libspdm_req_key_exchange_test(void)
    8207              : {
    8208            1 :     const struct CMUnitTest test_cases[] = {
    8209              :         /* SendRequest failed*/
    8210              :         cmocka_unit_test(req_key_exchange_case1),
    8211              :         /* Successful response*/
    8212              :         cmocka_unit_test(req_key_exchange_case2),
    8213              :         /* connection_state check failed*/
    8214              :         cmocka_unit_test(req_key_exchange_case3),
    8215              :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
    8216              :         cmocka_unit_test(req_key_exchange_case4),
    8217              :         /* Always SPDM_ERROR_CODE_BUSY*/
    8218              :         cmocka_unit_test(req_key_exchange_case5),
    8219              :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
    8220              :         cmocka_unit_test(req_key_exchange_case6),
    8221              :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
    8222              :         cmocka_unit_test(req_key_exchange_case7),
    8223              :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
    8224              :         cmocka_unit_test(req_key_exchange_case8),
    8225              :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
    8226              :         cmocka_unit_test(req_key_exchange_case9),
    8227              :         /* Unexpected errors*/
    8228              :         cmocka_unit_test(req_key_exchange_case10),
    8229              :         /* Buffer reset*/
    8230              :         cmocka_unit_test(req_key_exchange_case11),
    8231              :         /* Measurement hash 1, returns a measurement hash*/
    8232              :         cmocka_unit_test(req_key_exchange_case12),
    8233              :         /* Measurement hash 1, returns a 0x00 array (no TCB components)*/
    8234              :         cmocka_unit_test(req_key_exchange_case13),
    8235              :         /* Measurement hash FF, returns a measurement_hash*/
    8236              :         cmocka_unit_test(req_key_exchange_case14),
    8237              :         /* Measurement hash 1, returns no measurement_hash*/
    8238              :         cmocka_unit_test(req_key_exchange_case15),
    8239              :         /* Measurement hash FF, returns no measurement_hash*/
    8240              :         cmocka_unit_test(req_key_exchange_case16),
    8241              :         /* Measurement hash not requested, returns a measurement_hash*/
    8242              :         cmocka_unit_test(req_key_exchange_case17),
    8243              :         /* Wrong signature*/
    8244              :         cmocka_unit_test(req_key_exchange_case18),
    8245              :         /* Requester and Responder Handshake in the clear set, no ResponderVerifyData*/
    8246              :         cmocka_unit_test(req_key_exchange_case19),
    8247              :         /* Heartbeat not supported, heartbeat period different from 0 sent*/
    8248              :         cmocka_unit_test(req_key_exchange_case20),
    8249              :         /* Heartbeat supported, heartbeat period different from 0 sent*/
    8250              :         cmocka_unit_test(req_key_exchange_case21),
    8251              :         /* Heartbeat supported, heartbeat period 0 sent NOTE: This should disable heartbeat*/
    8252              :         cmocka_unit_test(req_key_exchange_case22),
    8253              :         /* Muth Auth requested*/
    8254              :         cmocka_unit_test(req_key_exchange_case23),
    8255              :         /* Muth Auth requested with Encapsulated request*/
    8256              :         cmocka_unit_test(req_key_exchange_case24),
    8257              :         /* Muth Auth requested with implicit get digest*/
    8258              :         cmocka_unit_test(req_key_exchange_case25),
    8259              :         /* Muth Auth requested with Encapsulated request and bit 0 set*/
    8260              :         cmocka_unit_test(req_key_exchange_case26),
    8261              :         /* Muth Auth requested with implicit get digest and bit 0 set*/
    8262              :         cmocka_unit_test(req_key_exchange_case27),
    8263              :         /* Muth Auth requested with Encapsulated request and Muth Auth requested with implicit get digest simultaneously*/
    8264              :         cmocka_unit_test(req_key_exchange_case28),
    8265              :         /* Buffer verification*/
    8266              :         cmocka_unit_test(req_key_exchange_case29),
    8267              :         /* Successful response V1.2*/
    8268              :         cmocka_unit_test(req_key_exchange_case30),
    8269              :         cmocka_unit_test(req_key_exchange_case31),
    8270              :         /* Successful response using provisioned public key (slot_id 0xFF) */
    8271              :         cmocka_unit_test(req_key_exchange_case32),
    8272              :         /* OpaqueData only supports OpaqueDataFmt1, Success Case */
    8273              :         cmocka_unit_test(req_key_exchange_case33),
    8274              :         cmocka_unit_test(req_key_exchange_case34),
    8275              :     };
    8276              : 
    8277            1 :     libspdm_test_context_t test_context = {
    8278              :         LIBSPDM_TEST_CONTEXT_VERSION,
    8279              :         true,
    8280              :         send_message,
    8281              :         receive_message,
    8282              :     };
    8283              : 
    8284            1 :     libspdm_setup_test_context(&test_context);
    8285              : 
    8286            1 :     return cmocka_run_group_tests(test_cases,
    8287              :                                   libspdm_unit_test_group_setup,
    8288              :                                   libspdm_unit_test_group_teardown);
    8289              : }
    8290              : 
    8291              : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
        

Generated by: LCOV version 2.0-1