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 % 3655 3521
Test Date: 2025-09-14 08:11:04 Functions: 100.0 % 38 38

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

Generated by: LCOV version 2.0-1