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 % 3596 3464
Test Date: 2026-02-22 08:11:49 Functions: 100.0 % 38 38

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

Generated by: LCOV version 2.0-1