LCOV - code coverage report
Current view: top level - unit_test/test_spdm_requester - challenge.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 92.2 % 1648 1519
Test Date: 2025-10-12 08:10:56 Functions: 100.0 % 31 31

            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              : 
      10              : #if LIBSPDM_SEND_CHALLENGE_SUPPORT
      11              : 
      12              : static size_t m_libspdm_local_buffer_size;
      13              : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE];
      14              : 
      15              : static size_t m_libspdm_opaque_data_size;
      16              : static uint8_t m_libspdm_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
      17              : 
      18              : static uint8_t m_requester_context[SPDM_REQ_CONTEXT_SIZE];
      19              : 
      20           46 : static libspdm_return_t send_message(
      21              :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
      22              : {
      23              :     libspdm_test_context_t *spdm_test_context;
      24              :     const uint8_t *ptr;
      25              : 
      26           46 :     spdm_test_context = libspdm_get_test_context();
      27           46 :     ptr = (const uint8_t *)request;
      28           46 :     switch (spdm_test_context->case_id) {
      29            1 :     case 0x1:
      30            1 :         return LIBSPDM_STATUS_SEND_FAIL;
      31            1 :     case 0x2:
      32            1 :         m_libspdm_local_buffer_size = 0;
      33            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
      34              :                          request_size - 1);
      35            1 :         m_libspdm_local_buffer_size += (request_size - 1);
      36            1 :         return LIBSPDM_STATUS_SUCCESS;
      37            0 :     case 0x3:
      38            0 :         m_libspdm_local_buffer_size = 0;
      39            0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
      40              :                          request_size - 1);
      41            0 :         m_libspdm_local_buffer_size += (request_size - 1);
      42            0 :         return LIBSPDM_STATUS_SUCCESS;
      43            1 :     case 0x4:
      44            1 :         m_libspdm_local_buffer_size = 0;
      45            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
      46              :                          request_size - 1);
      47            1 :         m_libspdm_local_buffer_size += (request_size - 1);
      48            1 :         return LIBSPDM_STATUS_SUCCESS;
      49            1 :     case 0x5:
      50            1 :         m_libspdm_local_buffer_size = 0;
      51            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
      52              :                          request_size - 1);
      53            1 :         m_libspdm_local_buffer_size += (request_size - 1);
      54            1 :         return LIBSPDM_STATUS_SUCCESS;
      55            2 :     case 0x6:
      56            2 :         m_libspdm_local_buffer_size = 0;
      57            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
      58              :                          request_size - 1);
      59            2 :         m_libspdm_local_buffer_size += (request_size - 1);
      60            2 :         return LIBSPDM_STATUS_SUCCESS;
      61            1 :     case 0x7:
      62            1 :         m_libspdm_local_buffer_size = 0;
      63            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
      64              :                          request_size - 1);
      65            1 :         m_libspdm_local_buffer_size += (request_size - 1);
      66            1 :         return LIBSPDM_STATUS_SUCCESS;
      67            2 :     case 0x8:
      68            2 :         m_libspdm_local_buffer_size = 0;
      69            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
      70              :                          request_size - 1);
      71            2 :         m_libspdm_local_buffer_size += (request_size - 1);
      72            2 :         return LIBSPDM_STATUS_SUCCESS;
      73            2 :     case 0x9: {
      74              :         static size_t sub_index = 0;
      75            2 :         if (sub_index == 0) {
      76            1 :             m_libspdm_local_buffer_size = 0;
      77            1 :             libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
      78              :                              request_size - 1);
      79            1 :             m_libspdm_local_buffer_size += (request_size - 1);
      80            1 :             sub_index++;
      81              :         }
      82              :     }
      83            2 :         return LIBSPDM_STATUS_SUCCESS;
      84           27 :     case 0xA:
      85              :     case 0xB:
      86              :     case 0xC:
      87              :     case 0xD:
      88              :     case 0xE:
      89              :     case 0xF:
      90              :     case 0x10:
      91              :     case 0x11:
      92              :     case 0x12:
      93              :     case 0x13:
      94              :     case 0x14:
      95              :     case 0x15:
      96           27 :         m_libspdm_local_buffer_size = 0;
      97           27 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
      98              :                          request_size - 1);
      99           27 :         m_libspdm_local_buffer_size += (request_size - 1);
     100           27 :         return LIBSPDM_STATUS_SUCCESS;
     101            1 :     case 0x16: {
     102              :         /* arbitrary data must be inserted in the message buffer for computing
     103              :          * the response hash */
     104            1 :         m_libspdm_local_buffer_size = 0;
     105              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     106              :         libspdm_set_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size], 10, (uint8_t) 0xFF);
     107              :         m_libspdm_local_buffer_size += 10;
     108              :         libspdm_set_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size], 8, (uint8_t) 0xEE);
     109              :         m_libspdm_local_buffer_size += 8;
     110              :         libspdm_set_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size], 12, (uint8_t) 0xDD);
     111              :         m_libspdm_local_buffer_size += 12;
     112              : #endif
     113            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     114              :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
     115            1 :                          &ptr[1], request_size - 1);
     116            1 :         m_libspdm_local_buffer_size += (request_size - 1);
     117              :     }
     118            1 :         return LIBSPDM_STATUS_SUCCESS;
     119            2 :     case 0x17:
     120            2 :         m_libspdm_local_buffer_size = 0;
     121            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
     122              :                          request_size - 1);
     123            2 :         m_libspdm_local_buffer_size += (request_size - 1);
     124            2 :         return LIBSPDM_STATUS_SUCCESS;
     125            3 :     case 0x18:
     126              :     case 0x19:
     127              :     case 0x1A:
     128            3 :         m_libspdm_local_buffer_size = 0;
     129            3 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
     130              :                          request_size - 1);
     131            3 :         m_libspdm_local_buffer_size += (request_size - 1);
     132            3 :         return LIBSPDM_STATUS_SUCCESS;
     133            2 :     case 0x1B:
     134              :     case 0x1C:
     135            2 :         m_libspdm_local_buffer_size = 0;
     136            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
     137              :                          request_size - 1);
     138            2 :         m_libspdm_local_buffer_size += (request_size - 1);
     139            2 :         return LIBSPDM_STATUS_SUCCESS;
     140            0 :     default:
     141            0 :         return LIBSPDM_STATUS_SEND_FAIL;
     142              :     }
     143              : }
     144              : 
     145           45 : static libspdm_return_t receive_message(
     146              :     void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
     147              : {
     148              :     libspdm_test_context_t *spdm_test_context;
     149              : 
     150           45 :     spdm_test_context = libspdm_get_test_context();
     151           45 :     switch (spdm_test_context->case_id) {
     152            0 :     case 0x1:
     153            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
     154              : 
     155            1 :     case 0x2: { /*correct CHALLENGE_AUTH message*/
     156              :         spdm_challenge_auth_response_t *spdm_response;
     157              :         void *data;
     158              :         size_t data_size;
     159              :         uint8_t *ptr;
     160              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     161              :         size_t sig_size;
     162              :         size_t spdm_response_size;
     163              :         size_t transport_header_size;
     164              : 
     165            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     166              :                                                         m_libspdm_use_asym_algo, &data,
     167              :                                                         &data_size, NULL, NULL);
     168              :         ((libspdm_context_t *)spdm_context)
     169            1 :         ->local_context.local_cert_chain_provision_size[0] =
     170              :             data_size;
     171              :         ((libspdm_context_t *)spdm_context)
     172            1 :         ->local_context.local_cert_chain_provision[0] = data;
     173              :         ((libspdm_context_t *)spdm_context)
     174            1 :         ->connection_info.algorithm.base_asym_algo =
     175              :             m_libspdm_use_asym_algo;
     176              :         ((libspdm_context_t *)spdm_context)
     177            1 :         ->connection_info.algorithm.base_hash_algo =
     178              :             m_libspdm_use_hash_algo;
     179            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
     180            1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo) +
     181            1 :                              SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
     182            1 :                              libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     183            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     184            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     185              : 
     186            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     187            1 :         spdm_response->header.request_response_code =
     188              :             SPDM_CHALLENGE_AUTH;
     189            1 :         spdm_response->header.param1 = 0;
     190            1 :         spdm_response->header.param2 = (1 << 0);
     191            1 :         ptr = (void *)(spdm_response + 1);
     192            1 :         libspdm_hash_all(
     193              :             m_libspdm_use_hash_algo,
     194              :             ((libspdm_context_t *)spdm_context)
     195              :             ->local_context.local_cert_chain_provision[0],
     196              :             ((libspdm_context_t *)spdm_context)
     197              :             ->local_context
     198              :             .local_cert_chain_provision_size[0],
     199              :             ptr);
     200            1 :         free(data);
     201            1 :         ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
     202            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     203            1 :         ptr += SPDM_NONCE_SIZE;
     204              :         /* libspdm_zero_mem (ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
     205              :          * ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
     206            1 :         *(uint16_t *)ptr = 0;
     207            1 :         ptr += sizeof(uint16_t);
     208            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     209              :                          sizeof(m_libspdm_local_buffer) -
     210            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     211              :                           m_libspdm_local_buffer),
     212            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
     213            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
     214            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     215              :                        m_libspdm_local_buffer_size));
     216            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     217            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     218              :                          m_libspdm_local_buffer_size, hash_data);
     219            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
     220              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
     221            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     222            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     223            1 :         libspdm_responder_data_sign(
     224              :             spdm_context,
     225            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     226              :                 SPDM_CHALLENGE_AUTH,
     227              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     228              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
     229              :                 ptr, &sig_size);
     230            1 :         ptr += sig_size;
     231              : 
     232            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     233              :                                               false, spdm_response_size,
     234              :                                               spdm_response, response_size,
     235              :                                               response);
     236              :     }
     237            1 :         return LIBSPDM_STATUS_SUCCESS;
     238              : 
     239            0 :     case 0x3: { /*correct CHALLENGE_AUTH message*/
     240              :         spdm_challenge_auth_response_t *spdm_response;
     241              :         void *data;
     242              :         size_t data_size;
     243              :         uint8_t *ptr;
     244              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     245              :         size_t sig_size;
     246              :         size_t spdm_response_size;
     247              :         size_t transport_header_size;
     248              : 
     249            0 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     250              :                                                         m_libspdm_use_asym_algo, &data,
     251              :                                                         &data_size, NULL, NULL);
     252              :         ((libspdm_context_t *)spdm_context)
     253            0 :         ->local_context.local_cert_chain_provision_size[0] =
     254              :             data_size;
     255              :         ((libspdm_context_t *)spdm_context)
     256            0 :         ->local_context.local_cert_chain_provision[0] = data;
     257              :         ((libspdm_context_t *)spdm_context)
     258            0 :         ->connection_info.algorithm.base_asym_algo =
     259              :             m_libspdm_use_asym_algo;
     260              :         ((libspdm_context_t *)spdm_context)
     261            0 :         ->connection_info.algorithm.base_hash_algo =
     262              :             m_libspdm_use_hash_algo;
     263            0 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
     264            0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo) +
     265            0 :                              SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
     266            0 :                              libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     267            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     268            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     269              : 
     270            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     271            0 :         spdm_response->header.request_response_code =
     272              :             SPDM_CHALLENGE_AUTH;
     273            0 :         spdm_response->header.param1 = 0;
     274            0 :         spdm_response->header.param2 = (1 << 0);
     275            0 :         ptr = (void *)(spdm_response + 1);
     276            0 :         libspdm_hash_all(
     277              :             m_libspdm_use_hash_algo,
     278              :             ((libspdm_context_t *)spdm_context)
     279              :             ->local_context.local_cert_chain_provision[0],
     280              :             ((libspdm_context_t *)spdm_context)
     281              :             ->local_context
     282              :             .local_cert_chain_provision_size[0],
     283              :             ptr);
     284            0 :         free(data);
     285            0 :         ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
     286            0 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     287            0 :         ptr += SPDM_NONCE_SIZE;
     288              :         /* libspdm_zero_mem (ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
     289              :          * ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
     290            0 :         *(uint16_t *)ptr = 0;
     291            0 :         ptr += sizeof(uint16_t);
     292            0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     293              :                          sizeof(m_libspdm_local_buffer) -
     294            0 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     295              :                           m_libspdm_local_buffer),
     296            0 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
     297            0 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
     298            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     299              :                          m_libspdm_local_buffer_size, hash_data);
     300            0 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     301            0 :         libspdm_responder_data_sign(
     302              :             spdm_context,
     303            0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     304              :                 SPDM_CHALLENGE_AUTH,
     305              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     306              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
     307              :                 ptr, &sig_size);
     308            0 :         ptr += sig_size;
     309              : 
     310            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     311              :                                               false, spdm_response_size,
     312              :                                               spdm_response, response_size,
     313              :                                               response);
     314              :     }
     315            0 :         return LIBSPDM_STATUS_SUCCESS;
     316              : 
     317            1 :     case 0x4: { /*correct ERROR message (invalid request)*/
     318              :         spdm_error_response_t *spdm_response;
     319              :         size_t spdm_response_size;
     320              :         size_t transport_header_size;
     321              : 
     322            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     323            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     324            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     325              : 
     326            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     327            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     328            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
     329            1 :         spdm_response->header.param2 = 0;
     330              : 
     331            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     332              :                                               false, spdm_response_size,
     333              :                                               spdm_response,
     334              :                                               response_size, response);
     335              :     }
     336            1 :         return LIBSPDM_STATUS_SUCCESS;
     337              : 
     338            1 :     case 0x5: { /*correct ERROR message (busy)*/
     339              :         spdm_error_response_t *spdm_response;
     340              :         size_t spdm_response_size;
     341              :         size_t transport_header_size;
     342              : 
     343            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     344            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     345            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     346              : 
     347            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     348            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     349            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     350            1 :         spdm_response->header.param2 = 0;
     351              : 
     352            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     353              :                                               false, spdm_response_size,
     354              :                                               spdm_response,
     355              :                                               response_size, response);
     356              :     }
     357            1 :         return LIBSPDM_STATUS_SUCCESS;
     358              : 
     359            2 :     case 0x6: { /*correct ERROR message (busy) + correct CHALLENGE_AUTH message*/
     360              :         static size_t sub_index1 = 0;
     361            2 :         if (sub_index1 == 0) {
     362              :             spdm_error_response_t *spdm_response;
     363              :             size_t spdm_response_size;
     364              :             size_t transport_header_size;
     365              : 
     366            1 :             spdm_response_size = sizeof(spdm_error_response_t);
     367            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     368            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     369              : 
     370            1 :             spdm_response->header.spdm_version =
     371              :                 SPDM_MESSAGE_VERSION_11;
     372            1 :             spdm_response->header.request_response_code = SPDM_ERROR;
     373            1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     374            1 :             spdm_response->header.param2 = 0;
     375              : 
     376            1 :             libspdm_transport_test_encode_message(
     377              :                 spdm_context, NULL, false, false,
     378              :                 spdm_response_size, spdm_response,
     379              :                 response_size, response);
     380            1 :             sub_index1++;
     381            1 :         } else if (sub_index1 == 1) {
     382              :             spdm_challenge_auth_response_t *spdm_response;
     383              :             void *data;
     384              :             size_t data_size;
     385              :             uint8_t *ptr;
     386              :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     387              :             size_t sig_size;
     388              :             size_t spdm_response_size;
     389              :             size_t transport_header_size;
     390              : 
     391            1 :             libspdm_read_responder_public_certificate_chain(
     392              :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
     393              :                 &data_size, NULL, NULL);
     394              :             ((libspdm_context_t *)spdm_context)
     395              :             ->local_context
     396            1 :             .local_cert_chain_provision_size[0] = data_size;
     397              :             ((libspdm_context_t *)spdm_context)
     398            1 :             ->local_context.local_cert_chain_provision[0] =
     399              :                 data;
     400              :             ((libspdm_context_t *)spdm_context)
     401            1 :             ->connection_info.algorithm.base_asym_algo =
     402              :                 m_libspdm_use_asym_algo;
     403              :             ((libspdm_context_t *)spdm_context)
     404            1 :             ->connection_info.algorithm.base_hash_algo =
     405              :                 m_libspdm_use_hash_algo;
     406            1 :             spdm_response_size =
     407              :                 sizeof(spdm_challenge_auth_response_t) +
     408            1 :                 libspdm_get_hash_size(m_libspdm_use_hash_algo) +
     409            1 :                 SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
     410            1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     411            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     412            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     413              : 
     414            1 :             spdm_response->header.spdm_version =
     415              :                 SPDM_MESSAGE_VERSION_11;
     416            1 :             spdm_response->header.request_response_code =
     417              :                 SPDM_CHALLENGE_AUTH;
     418            1 :             spdm_response->header.param1 = 0;
     419            1 :             spdm_response->header.param2 = (1 << 0);
     420            1 :             ptr = (void *)(spdm_response + 1);
     421            1 :             libspdm_hash_all(
     422              :                 m_libspdm_use_hash_algo,
     423              :                 ((libspdm_context_t *)spdm_context)
     424              :                 ->local_context
     425              :                 .local_cert_chain_provision[0],
     426              :                 ((libspdm_context_t *)spdm_context)
     427              :                 ->local_context
     428              :                 .local_cert_chain_provision_size[0],
     429              :                 ptr);
     430            1 :             free(data);
     431            1 :             ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
     432            1 :             libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     433            1 :             ptr += SPDM_NONCE_SIZE;
     434              :             /* libspdm_zero_mem (ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
     435              :              * ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
     436            1 :             *(uint16_t *)ptr = 0;
     437            1 :             ptr += sizeof(uint16_t);
     438            1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     439              :                              sizeof(m_libspdm_local_buffer)
     440            1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     441              :                                 m_libspdm_local_buffer),
     442              :                              spdm_response,
     443            1 :                              (size_t)ptr - (size_t)spdm_response);
     444            1 :             m_libspdm_local_buffer_size +=
     445            1 :                 ((size_t)ptr - (size_t)spdm_response);
     446            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     447              :                              m_libspdm_local_buffer_size, hash_data);
     448            1 :             sig_size =
     449            1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     450            1 :             libspdm_responder_data_sign(
     451              :                 spdm_context,
     452            1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     453              :                     SPDM_CHALLENGE_AUTH,
     454              :                     m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo,
     455              :                     m_libspdm_use_hash_algo,
     456              :                     false, m_libspdm_local_buffer,
     457              :                     m_libspdm_local_buffer_size, ptr,
     458              :                     &sig_size);
     459            1 :             ptr += sig_size;
     460              : 
     461            1 :             libspdm_transport_test_encode_message(
     462              :                 spdm_context, NULL, false, false, spdm_response_size,
     463              :                 spdm_response, response_size, response);
     464              :         }
     465              :     }
     466            2 :         return LIBSPDM_STATUS_SUCCESS;
     467              : 
     468            1 :     case 0x7: { /*correct ERROR message (request resync)*/
     469              :         spdm_error_response_t *spdm_response;
     470              :         size_t spdm_response_size;
     471              :         size_t transport_header_size;
     472              : 
     473            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     474            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     475            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     476              : 
     477            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     478            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     479            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
     480            1 :         spdm_response->header.param2 = 0;
     481              : 
     482            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     483              :                                               false, spdm_response_size,
     484              :                                               spdm_response,
     485              :                                               response_size, response);
     486              :     }
     487            1 :         return LIBSPDM_STATUS_SUCCESS;
     488              : 
     489            2 :     case 0x8: { /*correct ERROR message (response net ready)*/
     490              :         spdm_error_response_data_response_not_ready_t *spdm_response;
     491              :         size_t spdm_response_size;
     492              :         size_t transport_header_size;
     493              : 
     494            2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
     495            2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     496            2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     497              : 
     498            2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     499            2 :         spdm_response->header.request_response_code = SPDM_ERROR;
     500            2 :         spdm_response->header.param1 =
     501              :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
     502            2 :         spdm_response->header.param2 = 0;
     503            2 :         spdm_response->extend_error_data.rd_exponent = 1;
     504            2 :         spdm_response->extend_error_data.rd_tm = 2;
     505            2 :         spdm_response->extend_error_data.request_code = SPDM_CHALLENGE;
     506            2 :         spdm_response->extend_error_data.token = 0;
     507              : 
     508            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     509              :                                               false, spdm_response_size,
     510              :                                               spdm_response,
     511              :                                               response_size, response);
     512              :     }
     513            2 :         return LIBSPDM_STATUS_SUCCESS;
     514              : 
     515            2 :     case 0x9: { /*correct ERROR message (response not ready) + correct CHALLENGE_AUTH message*/
     516              :         static size_t sub_index2 = 0;
     517            2 :         if (sub_index2 == 0) {
     518              :             spdm_error_response_data_response_not_ready_t
     519              :             *spdm_response;
     520              :             size_t spdm_response_size;
     521              :             size_t transport_header_size;
     522              : 
     523            1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
     524            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     525            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     526              : 
     527            1 :             spdm_response->header.spdm_version =
     528              :                 SPDM_MESSAGE_VERSION_11;
     529            1 :             spdm_response->header.request_response_code = SPDM_ERROR;
     530            1 :             spdm_response->header.param1 =
     531              :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
     532            1 :             spdm_response->header.param2 = 0;
     533            1 :             spdm_response->extend_error_data.rd_exponent = 1;
     534            1 :             spdm_response->extend_error_data.rd_tm = 2;
     535            1 :             spdm_response->extend_error_data.request_code =
     536              :                 SPDM_CHALLENGE;
     537            1 :             spdm_response->extend_error_data.token = 1;
     538              : 
     539            1 :             libspdm_transport_test_encode_message(
     540              :                 spdm_context, NULL, false, false,
     541              :                 spdm_response_size, spdm_response,
     542              :                 response_size, response);
     543            1 :             sub_index2++;
     544            1 :         } else if (sub_index2 == 1) {
     545              :             spdm_challenge_auth_response_t *spdm_response;
     546              :             void *data;
     547              :             size_t data_size;
     548              :             uint8_t *ptr;
     549              :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     550              :             size_t sig_size;
     551              :             size_t spdm_response_size;
     552              :             size_t transport_header_size;
     553              : 
     554            1 :             libspdm_read_responder_public_certificate_chain(
     555              :                 m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
     556              :                 &data_size, NULL, NULL);
     557              :             ((libspdm_context_t *)spdm_context)
     558              :             ->local_context
     559            1 :             .local_cert_chain_provision_size[0] = data_size;
     560              :             ((libspdm_context_t *)spdm_context)
     561            1 :             ->local_context.local_cert_chain_provision[0] =
     562              :                 data;
     563              :             ((libspdm_context_t *)spdm_context)
     564            1 :             ->connection_info.algorithm.base_asym_algo =
     565              :                 m_libspdm_use_asym_algo;
     566              :             ((libspdm_context_t *)spdm_context)
     567            1 :             ->connection_info.algorithm.base_hash_algo =
     568              :                 m_libspdm_use_hash_algo;
     569            1 :             spdm_response_size =
     570              :                 sizeof(spdm_challenge_auth_response_t) +
     571            1 :                 libspdm_get_hash_size(m_libspdm_use_hash_algo) +
     572            1 :                 SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
     573            1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     574            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     575            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     576              : 
     577            1 :             spdm_response->header.spdm_version =
     578              :                 SPDM_MESSAGE_VERSION_11;
     579            1 :             spdm_response->header.request_response_code =
     580              :                 SPDM_CHALLENGE_AUTH;
     581            1 :             spdm_response->header.param1 = 0;
     582            1 :             spdm_response->header.param2 = (1 << 0);
     583            1 :             ptr = (void *)(spdm_response + 1);
     584            1 :             libspdm_hash_all(
     585              :                 m_libspdm_use_hash_algo,
     586              :                 ((libspdm_context_t *)spdm_context)
     587              :                 ->local_context
     588              :                 .local_cert_chain_provision[0],
     589              :                 ((libspdm_context_t *)spdm_context)
     590              :                 ->local_context
     591              :                 .local_cert_chain_provision_size[0],
     592              :                 ptr);
     593            1 :             free(data);
     594            1 :             ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
     595            1 :             libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     596            1 :             ptr += SPDM_NONCE_SIZE;
     597              :             /* libspdm_zero_mem (ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
     598              :              * ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
     599            1 :             *(uint16_t *)ptr = 0;
     600            1 :             ptr += sizeof(uint16_t);
     601            1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     602              :                              sizeof(m_libspdm_local_buffer)
     603            1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     604              :                                 m_libspdm_local_buffer),
     605              :                              spdm_response,
     606            1 :                              (size_t)ptr - (size_t)spdm_response);
     607            1 :             m_libspdm_local_buffer_size +=
     608            1 :                 ((size_t)ptr - (size_t)spdm_response);
     609            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     610              :                              m_libspdm_local_buffer_size, hash_data);
     611            1 :             sig_size =
     612            1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     613            1 :             libspdm_responder_data_sign(
     614              :                 spdm_context,
     615            1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     616              :                     SPDM_CHALLENGE_AUTH,
     617              :                     m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo,
     618              :                     m_libspdm_use_hash_algo,
     619              :                     false, m_libspdm_local_buffer,
     620              :                     m_libspdm_local_buffer_size, ptr,
     621              :                     &sig_size);
     622            1 :             ptr += sig_size;
     623              : 
     624            1 :             libspdm_transport_test_encode_message(
     625              :                 spdm_context, NULL, false, false, spdm_response_size,
     626              :                 spdm_response, response_size, response);
     627              :         }
     628              :     }
     629            2 :         return LIBSPDM_STATUS_SUCCESS;
     630              : 
     631            0 :     case 0xA: /*correct CHALLENGE_AUTH message*/
     632              :     {
     633              :         spdm_challenge_auth_response_t  *spdm_response;
     634              :         void                          *data;
     635              :         size_t data_size;
     636              :         uint8_t                         *Ptr;
     637              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     638              :         size_t sig_size;
     639              :         size_t spdm_response_size;
     640              :         size_t transport_header_size;
     641              : 
     642            0 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
     643              :                                                          m_libspdm_use_asym_algo,
     644              :                                                          &data,
     645              :                                                          &data_size, NULL, NULL);
     646            0 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
     647              :             data_size;
     648            0 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
     649            0 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
     650              :             m_libspdm_use_asym_algo;
     651            0 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
     652              :             m_libspdm_use_hash_algo;
     653            0 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
     654            0 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
     655              :                              SPDM_NONCE_SIZE +
     656              :                              0 +
     657            0 :                              sizeof(uint16_t) + 0 +
     658            0 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
     659            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     660            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     661              : 
     662            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     663            0 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
     664            0 :         spdm_response->header.param1 = 0;
     665            0 :         spdm_response->header.param2 = (1 << 0);
     666            0 :         Ptr = (void *)(spdm_response + 1);
     667            0 :         libspdm_hash_all (m_libspdm_use_hash_algo,
     668              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
     669              :                               0],
     670              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
     671              :                               0],
     672              :                           Ptr);
     673            0 :         free(data);
     674            0 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
     675            0 :         libspdm_get_random_number (SPDM_NONCE_SIZE, Ptr);
     676            0 :         Ptr += SPDM_NONCE_SIZE;
     677              :         /* libspdm_zero_mem (Ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
     678              :          * Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
     679            0 :         *(uint16_t *)Ptr = 0;
     680            0 :         Ptr += sizeof(uint16_t);
     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              :                          spdm_response,
     686            0 :                          (size_t)Ptr - (size_t)spdm_response);
     687            0 :         m_libspdm_local_buffer_size += ((size_t)Ptr - (size_t)spdm_response);
     688            0 :         libspdm_hash_all (m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     689              :                           m_libspdm_local_buffer_size, hash_data);
     690            0 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
     691            0 :         libspdm_responder_data_sign(
     692              :             spdm_context,
     693            0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     694              :                 SPDM_CHALLENGE_AUTH,
     695              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     696              :                 false, m_libspdm_local_buffer,
     697              :                 m_libspdm_local_buffer_size, Ptr, &sig_size);
     698            0 :         Ptr += sig_size;
     699              : 
     700            0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
     701              :                                                spdm_response, response_size, response);
     702              :     }
     703            0 :         return LIBSPDM_STATUS_SUCCESS;
     704              : 
     705            1 :     case 0xB: /*CHALLENGE_AUTH message smaller than a SPDM header*/
     706              :     {
     707              :         spdm_challenge_auth_response_t  *spdm_response;
     708              :         size_t spdm_response_size;
     709              :         size_t transport_header_size;
     710              : 
     711            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     712            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     713            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) - 1; /*smaller than standard message size*/
     714              : 
     715            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     716            1 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
     717            1 :         spdm_response->header.param1 = 0;
     718            1 :         spdm_response->header.param2 = (1 << 0);
     719              : 
     720            1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
     721              :                                                spdm_response, response_size, response);
     722              :     }
     723            1 :         return LIBSPDM_STATUS_SUCCESS;
     724              : 
     725            1 :     case 0xC: /*CHALLENGE_AUTH message with wrong version (1.0)*/
     726              :     {
     727              :         spdm_challenge_auth_response_t  *spdm_response;
     728              :         void                          *data;
     729              :         size_t data_size;
     730              :         uint8_t                         *Ptr;
     731              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     732              :         size_t sig_size;
     733              :         size_t spdm_response_size;
     734              :         size_t transport_header_size;
     735              : 
     736            1 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
     737              :                                                          m_libspdm_use_asym_algo,
     738              :                                                          &data,
     739              :                                                          &data_size, NULL, NULL);
     740            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
     741              :             data_size;
     742            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
     743            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
     744              :             m_libspdm_use_asym_algo;
     745            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
     746              :             m_libspdm_use_hash_algo;
     747            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
     748            1 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
     749            1 :                              SPDM_NONCE_SIZE +
     750            1 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
     751            1 :                              sizeof(uint16_t) + 0 +
     752            1 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
     753            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     754            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     755              : 
     756            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10; /*wrong version*/
     757            1 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
     758            1 :         spdm_response->header.param1 = 0;
     759            1 :         spdm_response->header.param2 = (1 << 0);
     760            1 :         Ptr = (void *)(spdm_response + 1);
     761            1 :         libspdm_hash_all (m_libspdm_use_hash_algo,
     762              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
     763              :                               0],
     764              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
     765              :                               0],
     766              :                           Ptr);
     767            1 :         free(data);
     768            1 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
     769            1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, Ptr);
     770            1 :         Ptr += SPDM_NONCE_SIZE;
     771              :         /* libspdm_zero_mem (Ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
     772              :          * Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
     773            1 :         *(uint16_t *)Ptr = 0;
     774            1 :         Ptr += sizeof(uint16_t);
     775            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     776              :                          sizeof(m_libspdm_local_buffer) -
     777            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     778              :                           m_libspdm_local_buffer),
     779              :                          spdm_response,
     780            1 :                          (size_t)Ptr - (size_t)spdm_response);
     781            1 :         m_libspdm_local_buffer_size += ((size_t)Ptr - (size_t)spdm_response);
     782            1 :         libspdm_hash_all (m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     783              :                           m_libspdm_local_buffer_size, hash_data);
     784            1 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
     785            1 :         libspdm_responder_data_sign(
     786              :             spdm_context,
     787            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     788              :                 SPDM_CHALLENGE_AUTH,
     789              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     790              :                 false, m_libspdm_local_buffer,
     791              :                 m_libspdm_local_buffer_size, Ptr, &sig_size);
     792            1 :         Ptr += sig_size;
     793              : 
     794            1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
     795              :                                                spdm_response, response_size, response);
     796              :     }
     797            1 :         return LIBSPDM_STATUS_SUCCESS;
     798              : 
     799            1 :     case 0xD: /*SPDM (mostly CHALLENGE_AUTH) message with wrong response code (0x83)*/
     800              :     {
     801              :         spdm_challenge_auth_response_t  *spdm_response;
     802              :         void                          *data;
     803              :         size_t data_size;
     804              :         uint8_t                         *Ptr;
     805              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     806              :         size_t sig_size;
     807              :         size_t spdm_response_size;
     808              :         size_t transport_header_size;
     809              : 
     810            1 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
     811              :                                                          m_libspdm_use_asym_algo,
     812              :                                                          &data,
     813              :                                                          &data_size, NULL, NULL);
     814            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
     815              :             data_size;
     816            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
     817            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
     818              :             m_libspdm_use_asym_algo;
     819            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
     820              :             m_libspdm_use_hash_algo;
     821            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
     822            1 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
     823              :                              SPDM_NONCE_SIZE +
     824              :                              0 +
     825            1 :                              sizeof(uint16_t) + 0 +
     826            1 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
     827            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     828            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     829              : 
     830            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     831            1 :         spdm_response->header.request_response_code = SPDM_CHALLENGE; /*wrong response code*/
     832            1 :         spdm_response->header.param1 = 0;
     833            1 :         spdm_response->header.param2 = (1 << 0);
     834            1 :         Ptr = (void *)(spdm_response + 1);
     835            1 :         libspdm_hash_all (m_libspdm_use_hash_algo,
     836              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
     837              :                               0],
     838              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
     839              :                               0],
     840              :                           Ptr);
     841            1 :         free(data);
     842            1 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
     843            1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, Ptr);
     844            1 :         Ptr += SPDM_NONCE_SIZE;
     845              :         /* libspdm_zero_mem (Ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
     846              :          * Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
     847            1 :         *(uint16_t *)Ptr = 0;
     848            1 :         Ptr += sizeof(uint16_t);
     849            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     850              :                          sizeof(m_libspdm_local_buffer) -
     851            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     852              :                           m_libspdm_local_buffer),
     853              :                          spdm_response,
     854            1 :                          (size_t)Ptr - (size_t)spdm_response);
     855            1 :         m_libspdm_local_buffer_size += ((size_t)Ptr - (size_t)spdm_response);
     856            1 :         libspdm_hash_all (m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     857              :                           m_libspdm_local_buffer_size, hash_data);
     858            1 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
     859            1 :         libspdm_responder_data_sign(
     860              :             spdm_context,
     861            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     862              :                 SPDM_CHALLENGE_AUTH,
     863              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     864              :                 false, m_libspdm_local_buffer,
     865              :                 m_libspdm_local_buffer_size, Ptr, &sig_size);
     866            1 :         Ptr += sig_size;
     867              : 
     868            1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
     869              :                                                spdm_response, response_size, response);
     870              :     }
     871            1 :         return LIBSPDM_STATUS_SUCCESS;
     872              : 
     873            1 :     case 0xE: /*correct CHALLENGE_AUTH message with wrong slot number*/
     874              :     {
     875              :         spdm_challenge_auth_response_t  *spdm_response;
     876              :         void                          *data;
     877              :         size_t data_size;
     878              :         uint8_t                         *Ptr;
     879              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     880              :         size_t sig_size;
     881              :         size_t spdm_response_size;
     882              :         size_t transport_header_size;
     883              : 
     884            1 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
     885              :                                                          m_libspdm_use_asym_algo,
     886              :                                                          &data,
     887              :                                                          &data_size, NULL, NULL);
     888            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
     889              :             data_size;
     890            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
     891            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
     892              :             m_libspdm_use_asym_algo;
     893            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
     894              :             m_libspdm_use_hash_algo;
     895            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
     896            1 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
     897              :                              SPDM_NONCE_SIZE +
     898              :                              0 +
     899            1 :                              sizeof(uint16_t) + 0 +
     900            1 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
     901            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     902            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     903              : 
     904            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     905            1 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
     906            1 :         spdm_response->header.param1 = 1;
     907            1 :         spdm_response->header.param2 = (1 << 1); /*wrong slot number*/
     908            1 :         Ptr = (void *)(spdm_response + 1);
     909            1 :         libspdm_hash_all (m_libspdm_use_hash_algo,
     910              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
     911              :                               0],
     912              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
     913              :                               0],
     914              :                           Ptr);
     915            1 :         free(data);
     916            1 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
     917            1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, Ptr);
     918            1 :         Ptr += SPDM_NONCE_SIZE;
     919              :         /* libspdm_zero_mem (Ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
     920              :          * Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
     921            1 :         *(uint16_t *)Ptr = 0;
     922            1 :         Ptr += sizeof(uint16_t);
     923            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     924              :                          sizeof(m_libspdm_local_buffer) -
     925            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     926              :                           m_libspdm_local_buffer),
     927              :                          spdm_response,
     928            1 :                          (size_t)Ptr - (size_t)spdm_response);
     929            1 :         m_libspdm_local_buffer_size += ((size_t)Ptr - (size_t)spdm_response);
     930            1 :         libspdm_hash_all (m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     931              :                           m_libspdm_local_buffer_size, hash_data);
     932            1 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
     933            1 :         libspdm_responder_data_sign(
     934              :             spdm_context,
     935            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     936              :                 SPDM_CHALLENGE_AUTH,
     937              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     938              :                 false, m_libspdm_local_buffer,
     939              :                 m_libspdm_local_buffer_size, Ptr, &sig_size);
     940            1 :         Ptr += sig_size;
     941              : 
     942            1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
     943              :                                                spdm_response, response_size, response);
     944              :     }
     945            1 :         return LIBSPDM_STATUS_SUCCESS;
     946              : 
     947            0 :     case 0xF: /*CHALLENGE_AUTH message with slot number overflow*/
     948              :     {
     949              :         spdm_challenge_auth_response_t  *spdm_response;
     950              :         void                          *data;
     951              :         size_t data_size;
     952              :         uint8_t                         *Ptr;
     953              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     954              :         size_t sig_size;
     955              :         size_t spdm_response_size;
     956              :         size_t transport_header_size;
     957              : 
     958            0 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
     959              :                                                          m_libspdm_use_asym_algo,
     960              :                                                          &data,
     961              :                                                          &data_size, NULL, NULL);
     962            0 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
     963              :             data_size;
     964            0 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
     965            0 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
     966              :             m_libspdm_use_asym_algo;
     967            0 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
     968              :             m_libspdm_use_hash_algo;
     969            0 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
     970            0 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
     971              :                              SPDM_NONCE_SIZE +
     972              :                              0 +
     973            0 :                              sizeof(uint16_t) + 0 +
     974            0 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
     975            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     976            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     977              : 
     978            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     979            0 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
     980            0 :         spdm_response->header.param1 = 8; /*slot number overflow*/
     981            0 :         spdm_response->header.param2 = (1 << 0);
     982            0 :         Ptr = (void *)(spdm_response + 1);
     983            0 :         libspdm_hash_all (m_libspdm_use_hash_algo,
     984              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
     985              :                               0],
     986              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
     987              :                               0],
     988              :                           Ptr);
     989            0 :         free(data);
     990            0 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
     991            0 :         libspdm_get_random_number (SPDM_NONCE_SIZE, Ptr);
     992            0 :         Ptr += SPDM_NONCE_SIZE;
     993              :         /* libspdm_zero_mem (Ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
     994              :          * Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
     995            0 :         *(uint16_t *)Ptr = 0;
     996            0 :         Ptr += sizeof(uint16_t);
     997            0 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     998              :                          sizeof(m_libspdm_local_buffer) -
     999            0 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1000              :                           m_libspdm_local_buffer),
    1001              :                          spdm_response,
    1002            0 :                          (size_t)Ptr - (size_t)spdm_response);
    1003            0 :         m_libspdm_local_buffer_size += ((size_t)Ptr - (size_t)spdm_response);
    1004            0 :         libspdm_hash_all (m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1005              :                           m_libspdm_local_buffer_size, hash_data);
    1006            0 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1007            0 :         libspdm_responder_data_sign(
    1008              :             spdm_context,
    1009            0 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1010              :                 SPDM_CHALLENGE_AUTH,
    1011              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1012              :                 false, m_libspdm_local_buffer,
    1013              :                 m_libspdm_local_buffer_size, Ptr, &sig_size);
    1014            0 :         Ptr += sig_size;
    1015              : 
    1016            0 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
    1017              :                                                spdm_response, response_size, response);
    1018              :     }
    1019            0 :         return LIBSPDM_STATUS_SUCCESS;
    1020              : 
    1021            1 :     case 0x10: /*correct CHALLENGE_AUTH message with "libspdm" opaque data*/
    1022              :     {
    1023              :         spdm_challenge_auth_response_t  *spdm_response;
    1024              :         void                          *data;
    1025              :         size_t data_size;
    1026              :         uint8_t                         *Ptr;
    1027              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1028              :         size_t sig_size;
    1029              :         size_t spdm_response_size;
    1030              :         size_t transport_header_size;
    1031              : 
    1032            1 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    1033              :                                                          m_libspdm_use_asym_algo,
    1034              :                                                          &data,
    1035              :                                                          &data_size, NULL, NULL);
    1036            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
    1037              :             data_size;
    1038            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
    1039            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
    1040              :             m_libspdm_use_asym_algo;
    1041            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
    1042              :             m_libspdm_use_hash_algo;
    1043            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1044            1 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
    1045              :                              SPDM_NONCE_SIZE +
    1046              :                              0 +
    1047            1 :                              sizeof(uint16_t) + 8 +
    1048            1 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1049            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1050            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1051              : 
    1052            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1053            1 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
    1054            1 :         spdm_response->header.param1 = 0;
    1055            1 :         spdm_response->header.param2 = (1 << 0);
    1056            1 :         Ptr = (void *)(spdm_response + 1);
    1057            1 :         libspdm_hash_all (m_libspdm_use_hash_algo,
    1058              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
    1059              :                               0],
    1060              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
    1061              :                               0],
    1062              :                           Ptr);
    1063            1 :         free(data);
    1064            1 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
    1065            1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, Ptr);
    1066            1 :         Ptr += SPDM_NONCE_SIZE;
    1067              :         /* libspdm_zero_mem (Ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
    1068              :          * Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
    1069            1 :         *(uint16_t *)Ptr = (uint16_t)strlen("libspdm");
    1070            1 :         Ptr += sizeof(uint16_t);
    1071            1 :         libspdm_copy_mem(Ptr, (size_t)(*response) + *response_size - (size_t)Ptr, "libspdm",
    1072              :                          strlen("libspdm"));
    1073            1 :         Ptr += strlen("libspdm");
    1074            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1075              :                          sizeof(m_libspdm_local_buffer) -
    1076            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1077              :                           m_libspdm_local_buffer),
    1078              :                          spdm_response,
    1079            1 :                          (size_t)Ptr - (size_t)spdm_response);
    1080            1 :         m_libspdm_local_buffer_size += ((size_t)Ptr - (size_t)spdm_response);
    1081            1 :         libspdm_hash_all (m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1082              :                           m_libspdm_local_buffer_size, hash_data);
    1083            1 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1084            1 :         libspdm_responder_data_sign(
    1085              :             spdm_context,
    1086            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1087              :                 SPDM_CHALLENGE_AUTH,
    1088              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1089              :                 false, m_libspdm_local_buffer,
    1090              :                 m_libspdm_local_buffer_size, Ptr, &sig_size);
    1091            1 :         Ptr += sig_size;
    1092              : 
    1093            1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
    1094              :                                                spdm_response, response_size, response);
    1095              :     }
    1096            1 :         return LIBSPDM_STATUS_SUCCESS;
    1097              : 
    1098            1 :     case 0x11: /*correct CHALLENGE_AUTH message with invalid signature*/
    1099              :     {
    1100              :         spdm_challenge_auth_response_t  *spdm_response;
    1101              :         void                          *data;
    1102              :         size_t data_size;
    1103              :         uint8_t                         *Ptr;
    1104              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1105              :         size_t sig_size;
    1106              :         size_t spdm_response_size;
    1107              :         size_t transport_header_size;
    1108              : 
    1109            1 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    1110              :                                                          m_libspdm_use_asym_algo,
    1111              :                                                          &data,
    1112              :                                                          &data_size, NULL, NULL);
    1113            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
    1114              :             data_size;
    1115            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
    1116            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
    1117              :             m_libspdm_use_asym_algo;
    1118            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
    1119              :             m_libspdm_use_hash_algo;
    1120            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1121            1 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
    1122              :                              SPDM_NONCE_SIZE +
    1123              :                              0 +
    1124            1 :                              sizeof(uint16_t) + 0 +
    1125            1 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1126            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1127            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1128              : 
    1129            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1130            1 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
    1131            1 :         spdm_response->header.param1 = 0;
    1132            1 :         spdm_response->header.param2 = (1 << 0);
    1133            1 :         Ptr = (void *)(spdm_response + 1);
    1134            1 :         libspdm_hash_all (m_libspdm_use_hash_algo,
    1135              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
    1136              :                               0],
    1137              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
    1138              :                               0],
    1139              :                           Ptr);
    1140            1 :         free(data);
    1141            1 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
    1142            1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, Ptr);
    1143            1 :         Ptr += SPDM_NONCE_SIZE;
    1144              :         /* libspdm_zero_mem (Ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
    1145              :          * Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
    1146            1 :         *(uint16_t *)Ptr = 0;
    1147            1 :         Ptr += sizeof(uint16_t);
    1148            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1149              :                          sizeof(m_libspdm_local_buffer) -
    1150            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1151              :                           m_libspdm_local_buffer),
    1152              :                          spdm_response,
    1153            1 :                          (size_t)Ptr - (size_t)spdm_response);
    1154            1 :         m_libspdm_local_buffer_size += ((size_t)Ptr - (size_t)spdm_response);
    1155            1 :         libspdm_hash_all (m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1156              :                           m_libspdm_local_buffer_size, hash_data);
    1157            1 :         libspdm_hash_all (m_libspdm_use_hash_algo, hash_data, libspdm_get_hash_size (
    1158              :                               m_libspdm_use_hash_algo), hash_data);
    1159            1 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1160            1 :         libspdm_responder_data_sign(
    1161              :             spdm_context,
    1162            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1163              :                 SPDM_CHALLENGE_AUTH,
    1164              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1165            1 :                 false, hash_data, libspdm_get_hash_size (
    1166              :                 m_libspdm_use_hash_algo), Ptr, &sig_size);
    1167            1 :         Ptr += sig_size;
    1168              : 
    1169            1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
    1170              :                                                spdm_response, response_size, response);
    1171              :     }
    1172            1 :         return LIBSPDM_STATUS_SUCCESS;
    1173              : 
    1174            2 :     case 0x12: /*correct CHALLENGE_AUTH message*/
    1175              :     case 0x13: /*correct CHALLENGE_AUTH message*/
    1176              :     {
    1177              :         spdm_challenge_auth_response_t  *spdm_response;
    1178              :         void                          *data;
    1179              :         size_t data_size;
    1180              :         uint8_t                         *Ptr;
    1181              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1182              :         size_t sig_size;
    1183              :         size_t spdm_response_size;
    1184              :         size_t transport_header_size;
    1185              : 
    1186            2 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    1187              :                                                          m_libspdm_use_asym_algo,
    1188              :                                                          &data,
    1189              :                                                          &data_size, NULL, NULL);
    1190            2 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
    1191              :             data_size;
    1192            2 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
    1193            2 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
    1194              :             m_libspdm_use_asym_algo;
    1195            2 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
    1196              :             m_libspdm_use_hash_algo;
    1197            2 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1198            2 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
    1199            2 :                              SPDM_NONCE_SIZE +
    1200            2 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
    1201            2 :                              sizeof(uint16_t) + 0 +
    1202            2 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1203            2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1204            2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1205              : 
    1206            2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1207            2 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
    1208            2 :         spdm_response->header.param1 = 0;
    1209            2 :         spdm_response->header.param2 = (1 << 0);
    1210            2 :         Ptr = (void *)(spdm_response + 1);
    1211            2 :         libspdm_hash_all (m_libspdm_use_hash_algo,
    1212              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
    1213              :                               0],
    1214              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
    1215              :                               0],
    1216              :                           Ptr);
    1217            2 :         free(data);
    1218            2 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
    1219            2 :         libspdm_get_random_number (SPDM_NONCE_SIZE, Ptr);
    1220            2 :         Ptr += SPDM_NONCE_SIZE;
    1221            2 :         libspdm_zero_mem (Ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
    1222            2 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
    1223            2 :         *(uint16_t *)Ptr = 0;
    1224            2 :         Ptr += sizeof(uint16_t);
    1225            2 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1226              :                          sizeof(m_libspdm_local_buffer) -
    1227            2 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1228              :                           m_libspdm_local_buffer),
    1229              :                          spdm_response,
    1230            2 :                          (size_t)Ptr - (size_t)spdm_response);
    1231            2 :         m_libspdm_local_buffer_size += ((size_t)Ptr - (size_t)spdm_response);
    1232            2 :         libspdm_hash_all (m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1233              :                           m_libspdm_local_buffer_size, hash_data);
    1234            2 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1235            2 :         libspdm_responder_data_sign(
    1236              :             spdm_context,
    1237            2 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1238              :                 SPDM_CHALLENGE_AUTH,
    1239              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1240              :                 false, m_libspdm_local_buffer,
    1241              :                 m_libspdm_local_buffer_size, Ptr, &sig_size);
    1242            2 :         Ptr += sig_size;
    1243              : 
    1244            2 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
    1245              :                                                spdm_response, response_size, response);
    1246              :     }
    1247            2 :         return LIBSPDM_STATUS_SUCCESS;
    1248              : 
    1249           18 :     case 0x14:
    1250              :     {
    1251              :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
    1252              : 
    1253              :         spdm_error_response_t *spdm_response;
    1254              :         size_t spdm_response_size;
    1255              :         size_t transport_header_size;
    1256              : 
    1257           18 :         if(error_code <= 0xff) {
    1258           18 :             spdm_response_size = sizeof(spdm_error_response_t);
    1259           18 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1260           18 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1261              : 
    1262           18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1263           18 :             spdm_response->header.request_response_code = SPDM_ERROR;
    1264           18 :             spdm_response->header.param1 = (uint8_t) error_code;
    1265           18 :             spdm_response->header.param2 = 0;
    1266              : 
    1267           18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
    1268              :                                                    spdm_response_size, spdm_response,
    1269              :                                                    response_size, response);
    1270              :         }
    1271              : 
    1272           18 :         error_code++;
    1273           18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
    1274            1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
    1275              :         }
    1276           18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
    1277            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
    1278              :         }
    1279           18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
    1280            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
    1281              :         }
    1282              :     }
    1283           18 :         return LIBSPDM_STATUS_SUCCESS;
    1284              : 
    1285            1 :     case 0x15: /*correct CHALLENGE_AUTH message with multiple slot numbers */
    1286              :     {
    1287              :         spdm_challenge_auth_response_t  *spdm_response;
    1288              :         void                          *data;
    1289              :         size_t data_size;
    1290              :         uint8_t                       *ptr;
    1291              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1292              :         size_t sig_size;
    1293              :         size_t spdm_response_size;
    1294              :         size_t transport_header_size;
    1295              : 
    1296            1 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    1297              :                                                          m_libspdm_use_asym_algo,
    1298              :                                                          &data,
    1299              :                                                          &data_size, NULL, NULL);
    1300            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
    1301              :             data_size;
    1302            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
    1303            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
    1304              :             m_libspdm_use_asym_algo;
    1305            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
    1306              :             m_libspdm_use_hash_algo;
    1307            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1308            1 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
    1309              :                              SPDM_NONCE_SIZE +
    1310              :                              0 +
    1311            1 :                              sizeof(uint16_t) + 0 +
    1312            1 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1313            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1314            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1315              : 
    1316            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1317            1 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
    1318            1 :         spdm_response->header.param1 = 0;
    1319            1 :         spdm_response->header.param2 = 0x71; /*multiple slot numbers */
    1320            1 :         ptr = (void *)(spdm_response + 1);
    1321            1 :         libspdm_hash_all (m_libspdm_use_hash_algo,
    1322              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
    1323              :                               0],
    1324              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
    1325              :                               0],
    1326              :                           ptr);
    1327            1 :         free(data);
    1328            1 :         ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
    1329            1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, ptr);
    1330            1 :         ptr += SPDM_NONCE_SIZE;
    1331            1 :         *(uint16_t *)ptr = 0;
    1332            1 :         ptr += sizeof(uint16_t);
    1333            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1334              :                          sizeof(m_libspdm_local_buffer) -
    1335            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1336              :                           m_libspdm_local_buffer),
    1337              :                          spdm_response,
    1338            1 :                          (size_t)ptr - (size_t)spdm_response);
    1339            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1340            1 :         libspdm_hash_all (m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1341              :                           m_libspdm_local_buffer_size, hash_data);
    1342            1 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1343            1 :         libspdm_responder_data_sign(
    1344              :             spdm_context,
    1345            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1346              :                 SPDM_CHALLENGE_AUTH,
    1347              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1348              :                 false, m_libspdm_local_buffer,
    1349              :                 m_libspdm_local_buffer_size, ptr, &sig_size);
    1350            1 :         ptr += sig_size;
    1351            1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
    1352              :                                                spdm_response, response_size, response);
    1353              :     }
    1354            1 :         return LIBSPDM_STATUS_SUCCESS;
    1355              : 
    1356            1 :     case 0x16: { /*correct CHALLENGE_AUTH message*/
    1357              :         spdm_challenge_auth_response_t *spdm_response;
    1358              :         void *data;
    1359              :         size_t data_size;
    1360              :         uint8_t *ptr;
    1361              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1362              :         size_t sig_size;
    1363              :         size_t spdm_response_size;
    1364              :         size_t transport_header_size;
    1365              : 
    1366            1 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    1367              :                                                          m_libspdm_use_asym_algo,
    1368              :                                                          &data,
    1369              :                                                          &data_size, NULL, NULL);
    1370            1 :         ((libspdm_context_t *)spdm_context)->local_context.local_cert_chain_provision_size[0] =
    1371              :             data_size;
    1372            1 :         ((libspdm_context_t *)spdm_context)->local_context.local_cert_chain_provision[0] = data;
    1373            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_asym_algo =
    1374              :             m_libspdm_use_asym_algo;
    1375            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
    1376              :             m_libspdm_use_hash_algo;
    1377            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1378            1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo) +
    1379            1 :                              SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
    1380            1 :                              libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1381            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1382            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1383              : 
    1384            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1385            1 :         spdm_response->header.request_response_code =SPDM_CHALLENGE_AUTH;
    1386            1 :         spdm_response->header.param1 = 0;
    1387            1 :         spdm_response->header.param2 = (1 << 0);
    1388            1 :         ptr = (void *)(spdm_response + 1);
    1389            1 :         libspdm_hash_all(m_libspdm_use_hash_algo,
    1390              :                          ((libspdm_context_t *)spdm_context)
    1391              :                          ->local_context.local_cert_chain_provision[0],
    1392              :                          ((libspdm_context_t *)spdm_context)
    1393              :                          ->local_context.local_cert_chain_provision_size[0],
    1394              :                          ptr);
    1395            1 :         free(data);
    1396            1 :         ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1397            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    1398            1 :         ptr += SPDM_NONCE_SIZE;
    1399              :         /* libspdm_zero_mem (ptr, spdm_get_hash_size (m_libspdm_use_hash_algo));
    1400              :          * ptr += spdm_get_hash_size (m_libspdm_use_hash_algo);*/
    1401            1 :         *(uint16_t *)ptr = 0;
    1402            1 :         ptr += sizeof(uint16_t);
    1403            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1404              :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
    1405            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1406            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1407            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
    1408              :                        m_libspdm_local_buffer_size));
    1409            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1410            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1411              :                          m_libspdm_local_buffer_size, hash_data);
    1412            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    1413              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    1414            1 :         libspdm_dump_hex(hash_data, libspdm_get_hash_size(m_libspdm_use_hash_algo));
    1415            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1416            1 :         libspdm_responder_data_sign(
    1417              :             spdm_context,
    1418            1 :             spdm_response->header.spdm_version <<
    1419              :                 SPDM_VERSION_NUMBER_SHIFT_BIT,
    1420              :                 SPDM_CHALLENGE_AUTH,
    1421              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1422              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    1423              :                 ptr, &sig_size);
    1424            1 :         ptr += sig_size;
    1425              : 
    1426            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1427              :                                               false, spdm_response_size,
    1428              :                                               spdm_response, response_size,
    1429              :                                               response);
    1430              :     }
    1431            1 :         return LIBSPDM_STATUS_SUCCESS;
    1432              : 
    1433            2 :     case 0x17: { /*correct CHALLENGE_AUTH message*/
    1434              :         spdm_challenge_auth_response_t *spdm_response;
    1435              :         void *data;
    1436              :         size_t data_size;
    1437              :         uint8_t *ptr;
    1438              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1439              :         size_t sig_size;
    1440              :         size_t spdm_response_size;
    1441              :         size_t transport_header_size;
    1442              :         static uint8_t slot_id = 0;
    1443              : 
    1444            2 :         if (slot_id == 0) {
    1445            1 :             libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1446              :                                                             m_libspdm_use_asym_algo, &data,
    1447              :                                                             &data_size, NULL, NULL);
    1448              :         } else {
    1449            1 :             libspdm_read_responder_public_certificate_chain_per_slot(1,
    1450              :                                                                      m_libspdm_use_hash_algo,
    1451              :                                                                      m_libspdm_use_asym_algo, &data,
    1452              :                                                                      &data_size, NULL, NULL);
    1453              :         }
    1454              :         ((libspdm_context_t *)spdm_context)
    1455            2 :         ->local_context.local_cert_chain_provision_size[slot_id] =
    1456              :             data_size;
    1457              :         ((libspdm_context_t *)spdm_context)
    1458            2 :         ->local_context.local_cert_chain_provision[slot_id] = data;
    1459              :         ((libspdm_context_t *)spdm_context)
    1460            2 :         ->connection_info.algorithm.base_asym_algo =
    1461              :             m_libspdm_use_asym_algo;
    1462              :         ((libspdm_context_t *)spdm_context)
    1463            2 :         ->connection_info.algorithm.base_hash_algo =
    1464              :             m_libspdm_use_hash_algo;
    1465            2 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1466            2 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo) +
    1467            2 :                              SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
    1468            2 :                              libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1469            2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1470            2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1471              : 
    1472            2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1473            2 :         spdm_response->header.request_response_code =
    1474              :             SPDM_CHALLENGE_AUTH;
    1475            2 :         spdm_response->header.param1 = slot_id & 0xF;
    1476            2 :         spdm_response->header.param2 = (1 << slot_id);
    1477            2 :         ptr = (void *)(spdm_response + 1);
    1478            2 :         libspdm_hash_all(
    1479              :             m_libspdm_use_hash_algo,
    1480              :             ((libspdm_context_t *)spdm_context)
    1481              :             ->local_context.local_cert_chain_provision[slot_id],
    1482              :             ((libspdm_context_t *)spdm_context)
    1483              :             ->local_context
    1484              :             .local_cert_chain_provision_size[slot_id],
    1485              :             ptr);
    1486            2 :         free(data);
    1487            2 :         ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1488            2 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    1489            2 :         ptr += SPDM_NONCE_SIZE;
    1490              :         /* libspdm_zero_mem (ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
    1491              :          * ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
    1492            2 :         *(uint16_t *)ptr = 0;
    1493            2 :         ptr += sizeof(uint16_t);
    1494            2 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1495              :                          sizeof(m_libspdm_local_buffer) -
    1496            2 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1497              :                           m_libspdm_local_buffer),
    1498            2 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1499            2 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1500            2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1501              :                        m_libspdm_local_buffer_size));
    1502            2 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1503            2 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1504              :                          m_libspdm_local_buffer_size, hash_data);
    1505            2 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    1506              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    1507            2 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1508            2 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1509            2 :         libspdm_responder_data_sign(
    1510              :             spdm_context,
    1511            2 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1512              :                 SPDM_CHALLENGE_AUTH,
    1513              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1514              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    1515              :                 ptr, &sig_size);
    1516            2 :         ptr += sig_size;
    1517              : 
    1518            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1519              :                                               false, spdm_response_size,
    1520              :                                               spdm_response, response_size,
    1521              :                                               response);
    1522            2 :         slot_id++;
    1523              :     }
    1524            2 :         return LIBSPDM_STATUS_SUCCESS;
    1525              : 
    1526            1 :     case 0x18: { /* correct CHALLENGE_AUTH message using slot 0xFF */
    1527              :         spdm_challenge_auth_response_t *spdm_response;
    1528              :         void *data;
    1529              :         size_t data_size;
    1530              :         uint8_t *ptr;
    1531              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1532              :         size_t sig_size;
    1533              :         size_t spdm_response_size;
    1534              :         size_t transport_header_size;
    1535              : 
    1536            1 :         libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
    1537              :         ((libspdm_context_t *)spdm_context)
    1538            1 :         ->local_context.local_public_key_provision_size = data_size;
    1539              :         ((libspdm_context_t *)spdm_context)
    1540            1 :         ->local_context.local_public_key_provision = data;
    1541              :         ((libspdm_context_t *)spdm_context)
    1542            1 :         ->connection_info.algorithm.base_asym_algo =
    1543              :             m_libspdm_use_asym_algo;
    1544              :         ((libspdm_context_t *)spdm_context)
    1545            1 :         ->connection_info.algorithm.base_hash_algo =
    1546              :             m_libspdm_use_hash_algo;
    1547            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1548            1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo) +
    1549            1 :                              SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
    1550            1 :                              libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1551            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1552            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1553              : 
    1554            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1555            1 :         spdm_response->header.request_response_code =
    1556              :             SPDM_CHALLENGE_AUTH;
    1557            1 :         spdm_response->header.param1 = 0x0F;
    1558            1 :         spdm_response->header.param2 = 0;
    1559            1 :         ptr = (void *)(spdm_response + 1);
    1560            1 :         libspdm_hash_all(
    1561              :             m_libspdm_use_hash_algo,
    1562              :             ((libspdm_context_t *)spdm_context)
    1563              :             ->local_context.local_public_key_provision,
    1564              :             ((libspdm_context_t *)spdm_context)
    1565              :             ->local_context
    1566              :             .local_public_key_provision_size,
    1567              :             ptr);
    1568            1 :         free(data);
    1569            1 :         ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1570            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    1571            1 :         ptr += SPDM_NONCE_SIZE;
    1572              :         /* libspdm_zero_mem (ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
    1573              :          * ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
    1574            1 :         *(uint16_t *)ptr = 0;
    1575            1 :         ptr += sizeof(uint16_t);
    1576            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1577              :                          sizeof(m_libspdm_local_buffer) -
    1578            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1579              :                           m_libspdm_local_buffer),
    1580            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1581            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1582            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1583              :                        m_libspdm_local_buffer_size));
    1584            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1585            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1586              :                          m_libspdm_local_buffer_size, hash_data);
    1587            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    1588              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    1589            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1590            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1591            1 :         libspdm_responder_data_sign(
    1592              :             spdm_context,
    1593            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1594              :                 SPDM_CHALLENGE_AUTH,
    1595              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1596              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    1597              :                 ptr, &sig_size);
    1598            1 :         ptr += sig_size;
    1599              : 
    1600            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1601              :                                               false, spdm_response_size,
    1602              :                                               spdm_response, response_size,
    1603              :                                               response);
    1604              :     }
    1605            1 :         return LIBSPDM_STATUS_SUCCESS;
    1606              : 
    1607            1 :     case 0x19: /*CHALLENGE_AUTH message contains opaque_length greater than the maximum allowed*/
    1608              :     {
    1609              :         spdm_challenge_auth_response_t  *spdm_response;
    1610              :         void                          *data;
    1611              :         size_t data_size;
    1612              :         uint8_t                         *Ptr;
    1613              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1614              :         size_t sig_size;
    1615              :         size_t spdm_response_size;
    1616              :         size_t transport_header_size;
    1617              :         uint16_t opaque_length;
    1618            1 :         opaque_length = SPDM_MAX_OPAQUE_DATA_SIZE + 1;  /*opaque_length greater than the maximum allowed*/
    1619              : 
    1620            1 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    1621              :                                                          m_libspdm_use_asym_algo,
    1622              :                                                          &data,
    1623              :                                                          &data_size, NULL, NULL);
    1624            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
    1625              :             data_size;
    1626            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
    1627            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
    1628              :             m_libspdm_use_asym_algo;
    1629            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
    1630              :             m_libspdm_use_hash_algo;
    1631            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1632            1 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
    1633              :                              SPDM_NONCE_SIZE +
    1634              :                              0 +
    1635            1 :                              sizeof(uint16_t) +
    1636            1 :                              opaque_length +
    1637            1 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1638            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1639            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1640              : 
    1641            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1642            1 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
    1643            1 :         spdm_response->header.param1 = 0;
    1644            1 :         spdm_response->header.param2 = (1 << 0);
    1645            1 :         Ptr = (void *)(spdm_response + 1);
    1646            1 :         libspdm_hash_all (m_libspdm_use_hash_algo,
    1647              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
    1648              :                               0],
    1649              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
    1650              :                               0],
    1651              :                           Ptr);
    1652            1 :         free(data);
    1653            1 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
    1654            1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, Ptr);
    1655            1 :         Ptr += SPDM_NONCE_SIZE;
    1656              :         /* libspdm_zero_mem (Ptr, libspdm_get_hash_size (m_libspdm_use_hash_algo));
    1657              :          * Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);*/
    1658            1 :         *(uint16_t *)Ptr = opaque_length;
    1659            1 :         Ptr += sizeof(uint16_t);
    1660            1 :         libspdm_set_mem(Ptr, opaque_length, 255);
    1661            1 :         Ptr += opaque_length;
    1662            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1663              :                          sizeof(m_libspdm_local_buffer) -
    1664            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1665              :                           m_libspdm_local_buffer),
    1666              :                          spdm_response,
    1667            1 :                          (size_t)Ptr - (size_t)spdm_response);
    1668            1 :         m_libspdm_local_buffer_size += ((size_t)Ptr - (size_t)spdm_response);
    1669            1 :         libspdm_hash_all (m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1670              :                           m_libspdm_local_buffer_size, hash_data);
    1671            1 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1672            1 :         libspdm_responder_data_sign(
    1673              :             spdm_context,
    1674            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1675              :                 SPDM_CHALLENGE_AUTH,
    1676              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1677              :                 false, m_libspdm_local_buffer,
    1678              :                 m_libspdm_local_buffer_size, Ptr, &sig_size);
    1679            1 :         Ptr += sig_size;
    1680              : 
    1681            1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
    1682              :                                                spdm_response, response_size, response);
    1683              :     }
    1684            1 :         return LIBSPDM_STATUS_SUCCESS;
    1685              : 
    1686            1 :     case 0x1A:
    1687              :     {
    1688              :         spdm_challenge_auth_response_t  *spdm_response;
    1689              :         spdm_general_opaque_data_table_header_t
    1690              :         *spdm_general_opaque_data_table_header;
    1691              :         opaque_element_table_header_t
    1692              :         *opaque_element_table_header;
    1693              :         void *data;
    1694              :         size_t data_size;
    1695              :         uint8_t *Ptr;
    1696              :         size_t sig_size;
    1697              :         size_t spdm_response_size;
    1698              :         size_t transport_header_size;
    1699              :         uint8_t element_num;
    1700              :         uint8_t element_index;
    1701              :         size_t current_element_len;
    1702              :         uint16_t opaque_element_data_len;
    1703              : 
    1704            1 :         libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    1705              :                                                          m_libspdm_use_asym_algo,
    1706              :                                                          &data,
    1707              :                                                          &data_size, NULL, NULL);
    1708            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[0] =
    1709              :             data_size;
    1710            1 :         ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[0] = data;
    1711            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_asym_algo =
    1712              :             m_libspdm_use_asym_algo;
    1713            1 :         ((libspdm_context_t*)spdm_context)->connection_info.algorithm.base_hash_algo =
    1714              :             m_libspdm_use_hash_algo;
    1715              : 
    1716              : 
    1717            1 :         spdm_general_opaque_data_table_header = (void *)m_libspdm_opaque_data;
    1718            1 :         spdm_general_opaque_data_table_header->total_elements = 4;
    1719            1 :         opaque_element_table_header = (void *)(spdm_general_opaque_data_table_header + 1);
    1720              : 
    1721            1 :         element_num = spdm_general_opaque_data_table_header->total_elements;
    1722            1 :         m_libspdm_opaque_data_size = sizeof(spdm_general_opaque_data_table_header_t);
    1723              : 
    1724            5 :         for (element_index = 0; element_index < element_num; element_index++) {
    1725            4 :             opaque_element_table_header->id = SPDM_REGISTRY_ID_MAX;
    1726            4 :             opaque_element_table_header->vendor_len = 0;
    1727            4 :             opaque_element_data_len = (uint16_t)strlen("libspdm");
    1728              : 
    1729            4 :             Ptr = (void *)(opaque_element_table_header + 1);
    1730            4 :             Ptr += opaque_element_table_header->vendor_len;
    1731              : 
    1732            4 :             libspdm_copy_mem((uint16_t *)Ptr,
    1733              :                              sizeof(opaque_element_data_len),
    1734              :                              &opaque_element_data_len,
    1735              :                              sizeof(opaque_element_data_len));
    1736              : 
    1737            4 :             libspdm_copy_mem(Ptr + sizeof(opaque_element_data_len),
    1738              :                              SPDM_MAX_OPAQUE_DATA_SIZE -
    1739              :                              sizeof(opaque_element_table_header_t), "libspdm",
    1740              :                              strlen("libspdm"));
    1741              : 
    1742            4 :             current_element_len = sizeof(opaque_element_table_header_t) +
    1743            4 :                                   opaque_element_table_header->vendor_len +
    1744            4 :                                   sizeof(opaque_element_data_len) +
    1745              :                                   opaque_element_data_len;
    1746            4 :             current_element_len = (current_element_len + 3) & ~3;
    1747              : 
    1748              :             /*move to next element*/
    1749            4 :             opaque_element_table_header =
    1750              :                 (opaque_element_table_header_t *)
    1751              :                 ((uint8_t *)opaque_element_table_header +
    1752              :                  current_element_len);
    1753              : 
    1754            4 :             m_libspdm_opaque_data_size += current_element_len;
    1755              :         }
    1756              : 
    1757            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1758            1 :                              libspdm_get_hash_size (m_libspdm_use_hash_algo) +
    1759              :                              SPDM_NONCE_SIZE +
    1760              :                              0 +
    1761            2 :                              sizeof(uint16_t) + m_libspdm_opaque_data_size +
    1762            1 :                              libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1763            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1764            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1765              : 
    1766            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    1767            1 :         spdm_response->header.request_response_code = SPDM_CHALLENGE_AUTH;
    1768            1 :         spdm_response->header.param1 = 0;
    1769            1 :         spdm_response->header.param2 = (1 << 0);
    1770            1 :         Ptr = (void *)(spdm_response + 1);
    1771            1 :         libspdm_hash_all (m_libspdm_use_hash_algo,
    1772              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision[
    1773              :                               0],
    1774              :                           ((libspdm_context_t*)spdm_context)->local_context.local_cert_chain_provision_size[
    1775              :                               0],
    1776              :                           Ptr);
    1777            1 :         free(data);
    1778            1 :         Ptr += libspdm_get_hash_size (m_libspdm_use_hash_algo);
    1779            1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, Ptr);
    1780            1 :         Ptr += SPDM_NONCE_SIZE;
    1781            1 :         *(uint16_t *)Ptr = (uint16_t)m_libspdm_opaque_data_size;
    1782            1 :         Ptr += sizeof(uint16_t);
    1783            1 :         libspdm_copy_mem(Ptr, (size_t)(*response) + *response_size - (size_t)Ptr,
    1784              :                          m_libspdm_opaque_data,
    1785              :                          m_libspdm_opaque_data_size);
    1786            1 :         Ptr += m_libspdm_opaque_data_size;
    1787              : 
    1788            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1789              :                          sizeof(m_libspdm_local_buffer) -
    1790            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1791              :                           m_libspdm_local_buffer),
    1792              :                          spdm_response,
    1793            1 :                          (size_t)Ptr - (size_t)spdm_response);
    1794            1 :         m_libspdm_local_buffer_size += ((size_t)Ptr - (size_t)spdm_response);
    1795            1 :         sig_size = libspdm_get_asym_signature_size (m_libspdm_use_asym_algo);
    1796            1 :         libspdm_responder_data_sign(
    1797              :             spdm_context,
    1798            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1799              :                 SPDM_CHALLENGE_AUTH,
    1800              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1801              :                 false, m_libspdm_local_buffer,
    1802              :                 m_libspdm_local_buffer_size, Ptr, &sig_size);
    1803            1 :         Ptr += sig_size;
    1804              : 
    1805            1 :         libspdm_transport_test_encode_message (spdm_context, NULL, false, false, spdm_response_size,
    1806              :                                                spdm_response, response_size, response);
    1807              :     }
    1808            1 :         return LIBSPDM_STATUS_SUCCESS;
    1809            1 :     case 0x1B: {
    1810              :         spdm_challenge_auth_response_t *spdm_response;
    1811              :         void *data;
    1812              :         size_t data_size;
    1813              :         uint8_t *ptr;
    1814              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1815              :         size_t sig_size;
    1816              :         size_t spdm_response_size;
    1817              :         size_t transport_header_size;
    1818            1 :         uint8_t slot_id = 0;
    1819              : 
    1820            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1821              :                                                         m_libspdm_use_asym_algo, &data,
    1822              :                                                         &data_size, NULL, NULL);
    1823              :         ((libspdm_context_t *)spdm_context)
    1824            1 :         ->local_context.local_cert_chain_provision_size[0] =
    1825              :             data_size;
    1826              :         ((libspdm_context_t *)spdm_context)
    1827            1 :         ->local_context.local_cert_chain_provision[0] = data;
    1828              :         ((libspdm_context_t *)spdm_context)
    1829            1 :         ->connection_info.algorithm.base_asym_algo =
    1830              :             m_libspdm_use_asym_algo;
    1831              :         ((libspdm_context_t *)spdm_context)
    1832            1 :         ->connection_info.algorithm.base_hash_algo =
    1833              :             m_libspdm_use_hash_algo;
    1834            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1835            1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo) +
    1836            1 :                              SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
    1837            1 :                              libspdm_get_asym_signature_size(m_libspdm_use_asym_algo) +
    1838              :                              SPDM_REQ_CONTEXT_SIZE;
    1839            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1840            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1841              : 
    1842            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
    1843            1 :         spdm_response->header.request_response_code =
    1844              :             SPDM_CHALLENGE_AUTH;
    1845            1 :         spdm_response->header.param1 = slot_id;
    1846            1 :         spdm_response->header.param2 = (1 << slot_id);
    1847            1 :         ptr = (void *)(spdm_response + 1);
    1848            1 :         libspdm_hash_all(
    1849              :             m_libspdm_use_hash_algo,
    1850              :             ((libspdm_context_t *)spdm_context)
    1851              :             ->local_context.local_cert_chain_provision[slot_id],
    1852              :             ((libspdm_context_t *)spdm_context)
    1853              :             ->local_context
    1854              :             .local_cert_chain_provision_size[slot_id],
    1855              :             ptr);
    1856            1 :         free(data);
    1857            1 :         ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1858            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    1859            1 :         ptr += SPDM_NONCE_SIZE;
    1860            1 :         *(uint16_t *)ptr = 0;
    1861            1 :         ptr += sizeof(uint16_t);
    1862            1 :         libspdm_copy_mem(ptr, SPDM_REQ_CONTEXT_SIZE, m_requester_context, SPDM_REQ_CONTEXT_SIZE);
    1863            1 :         ptr += SPDM_REQ_CONTEXT_SIZE;
    1864            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1865              :                          sizeof(m_libspdm_local_buffer) -
    1866            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1867              :                           m_libspdm_local_buffer),
    1868            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1869            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1870            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1871              :                        m_libspdm_local_buffer_size));
    1872            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1873            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1874              :                          m_libspdm_local_buffer_size, hash_data);
    1875            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    1876              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    1877            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1878            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1879            1 :         libspdm_responder_data_sign(
    1880              :             spdm_context,
    1881            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1882              :                 SPDM_CHALLENGE_AUTH,
    1883              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1884              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    1885              :                 ptr, &sig_size);
    1886            1 :         ptr += sig_size;
    1887              : 
    1888            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1889              :                                               false, spdm_response_size,
    1890              :                                               spdm_response, response_size,
    1891              :                                               response);
    1892              :     }
    1893            1 :         return LIBSPDM_STATUS_SUCCESS;
    1894            1 :     case 0x1C: {
    1895              :         spdm_challenge_auth_response_t *spdm_response;
    1896              :         void *data;
    1897              :         size_t data_size;
    1898              :         uint8_t *ptr;
    1899              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1900              :         size_t sig_size;
    1901              :         size_t spdm_response_size;
    1902              :         size_t transport_header_size;
    1903            1 :         uint8_t slot_id = 0;
    1904              : 
    1905            1 :         libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1906              :                                                         m_libspdm_use_asym_algo, &data,
    1907              :                                                         &data_size, NULL, NULL);
    1908              :         ((libspdm_context_t *)spdm_context)
    1909            1 :         ->local_context.local_cert_chain_provision_size[0] =
    1910              :             data_size;
    1911              :         ((libspdm_context_t *)spdm_context)
    1912            1 :         ->local_context.local_cert_chain_provision[0] = data;
    1913              :         ((libspdm_context_t *)spdm_context)
    1914            1 :         ->connection_info.algorithm.base_asym_algo =
    1915              :             m_libspdm_use_asym_algo;
    1916              :         ((libspdm_context_t *)spdm_context)
    1917            1 :         ->connection_info.algorithm.base_hash_algo =
    1918              :             m_libspdm_use_hash_algo;
    1919            1 :         spdm_response_size = sizeof(spdm_challenge_auth_response_t) +
    1920            1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo) +
    1921            1 :                              SPDM_NONCE_SIZE + 0 + sizeof(uint16_t) + 0 +
    1922            1 :                              libspdm_get_asym_signature_size(m_libspdm_use_asym_algo) +
    1923              :                              SPDM_REQ_CONTEXT_SIZE;
    1924            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1925            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1926              : 
    1927            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
    1928            1 :         spdm_response->header.request_response_code =
    1929              :             SPDM_CHALLENGE_AUTH;
    1930            1 :         spdm_response->header.param1 = slot_id;
    1931            1 :         spdm_response->header.param2 = (1 << slot_id);
    1932            1 :         ptr = (void *)(spdm_response + 1);
    1933            1 :         libspdm_hash_all(
    1934              :             m_libspdm_use_hash_algo,
    1935              :             ((libspdm_context_t *)spdm_context)
    1936              :             ->local_context.local_cert_chain_provision[slot_id],
    1937              :             ((libspdm_context_t *)spdm_context)
    1938              :             ->local_context
    1939              :             .local_cert_chain_provision_size[slot_id],
    1940              :             ptr);
    1941            1 :         free(data);
    1942            1 :         ptr += libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1943            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    1944            1 :         ptr += SPDM_NONCE_SIZE;
    1945            1 :         *(uint16_t *)ptr = 0;
    1946            1 :         ptr += sizeof(uint16_t);
    1947            1 :         libspdm_get_random_number(SPDM_REQ_CONTEXT_SIZE,ptr);
    1948            1 :         ptr += SPDM_REQ_CONTEXT_SIZE;
    1949              : 
    1950            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1951              :                          sizeof(m_libspdm_local_buffer) -
    1952            1 :                          (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1953              :                           m_libspdm_local_buffer),
    1954            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1955            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1956            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1957              :                        m_libspdm_local_buffer_size));
    1958            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1959            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1960              :                          m_libspdm_local_buffer_size, hash_data);
    1961            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    1962              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    1963            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1964            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1965            1 :         libspdm_responder_data_sign(
    1966              :             spdm_context,
    1967            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1968              :                 SPDM_CHALLENGE_AUTH,
    1969              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1970              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    1971              :                 ptr, &sig_size);
    1972            1 :         ptr += sig_size;
    1973              : 
    1974            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1975              :                                               false, spdm_response_size,
    1976              :                                               spdm_response, response_size,
    1977              :                                               response);
    1978              :     }
    1979            1 :         return LIBSPDM_STATUS_SUCCESS;
    1980            0 :     default:
    1981            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
    1982              :     }
    1983              : }
    1984              : 
    1985              : /**
    1986              :  * Test 1: when no CHALLENGE_AUTH message is received, and the client returns a
    1987              :  * device error.
    1988              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
    1989              :  **/
    1990            1 : static void req_challenge_case1(void **state)
    1991              : {
    1992              :     libspdm_return_t status;
    1993              :     libspdm_test_context_t *spdm_test_context;
    1994              :     libspdm_context_t *spdm_context;
    1995              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    1996              :     void *data;
    1997              :     size_t data_size;
    1998              :     void *hash;
    1999              :     size_t hash_size;
    2000              : 
    2001            1 :     spdm_test_context = *state;
    2002            1 :     spdm_context = spdm_test_context->spdm_context;
    2003            1 :     spdm_test_context->case_id = 0x1;
    2004            1 :     spdm_context->connection_info.connection_state =
    2005              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2006            1 :     spdm_context->connection_info.capability.flags = 0;
    2007            1 :     spdm_context->connection_info.capability.flags |=
    2008              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2009            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2010              :                                                          m_libspdm_use_asym_algo, &data,
    2011              :                                                          &data_size, &hash, &hash_size)) {
    2012            0 :         assert(false);
    2013              :     }
    2014            1 :     libspdm_reset_message_a(spdm_context);
    2015            1 :     libspdm_reset_message_b(spdm_context);
    2016            1 :     libspdm_reset_message_c(spdm_context);
    2017            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    2018              :         m_libspdm_use_hash_algo;
    2019            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    2020              :         m_libspdm_use_asym_algo;
    2021              : 
    2022            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2023              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2024              : 
    2025              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2026              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2027              :         data_size;
    2028              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2029              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2030              :                      data, data_size);
    2031              : #else
    2032            1 :     libspdm_hash_all(
    2033              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2034              :         data, data_size,
    2035            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2036            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2037            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2038            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2039              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2040              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2041              :         data, data_size,
    2042              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2043              : #endif
    2044              : 
    2045            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    2046            1 :     status = libspdm_challenge(
    2047              :         spdm_context, NULL, 0,
    2048              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2049              :         measurement_hash, NULL);
    2050            1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
    2051              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2052              :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
    2053              : #endif
    2054            1 :     free(data);
    2055            1 : }
    2056              : 
    2057              : /**
    2058              :  * Test 2: the requester is setup correctly to send a CHALLENGE message:
    2059              :  * - it has flags indicating that the previous messages were sent
    2060              :  * (GET_CAPABILITIES, NEGOTIATE_ALGORITHMS, and GET_DIGESTS).
    2061              :  * - it received the CAPABILITIES message, allowing the use of hash and digital
    2062              :  * signature algorithms, and the use of challenges.
    2063              :  * - it has the responder's certificate chain.
    2064              :  * The CHALLENGE message requests usage of the first certificate in the chain
    2065              :  * (param1=0) and do not request measurements (param2=0).
    2066              :  * The received CHALLENGE_AUTH message correctly responds to the challenge, with
    2067              :  * no opaque data and a signature on the sent nonce.
    2068              :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    2069              :  **/
    2070            1 : static void req_challenge_case2(void **state)
    2071              : {
    2072              :     libspdm_return_t status;
    2073              :     libspdm_test_context_t *spdm_test_context;
    2074              :     libspdm_context_t *spdm_context;
    2075              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2076              :     void *data;
    2077              :     size_t data_size;
    2078              :     void *hash;
    2079              :     size_t hash_size;
    2080              : 
    2081            1 :     spdm_test_context = *state;
    2082            1 :     spdm_context = spdm_test_context->spdm_context;
    2083            1 :     spdm_test_context->case_id = 0x2;
    2084            1 :     spdm_context->connection_info.connection_state =
    2085              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2086            1 :     spdm_context->connection_info.capability.flags = 0;
    2087            1 :     spdm_context->connection_info.capability.flags |=
    2088              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2089            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2090              :                                                          m_libspdm_use_asym_algo, &data,
    2091              :                                                          &data_size, &hash, &hash_size)) {
    2092            0 :         assert(false);
    2093              :     }
    2094            1 :     libspdm_reset_message_a(spdm_context);
    2095            1 :     libspdm_reset_message_b(spdm_context);
    2096            1 :     libspdm_reset_message_c(spdm_context);
    2097            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    2098              :         m_libspdm_use_hash_algo;
    2099            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    2100              :         m_libspdm_use_asym_algo;
    2101              : 
    2102            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2103              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2104              : 
    2105              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2106              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2107              :         data_size;
    2108              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2109              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2110              :                      data, data_size);
    2111              : #else
    2112            1 :     libspdm_hash_all(
    2113              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2114              :         data, data_size,
    2115            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2116            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2117            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2118            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2119              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2120              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2121              :         data, data_size,
    2122              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2123              : #endif
    2124              : 
    2125            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    2126            1 :     status = libspdm_challenge(
    2127              :         spdm_context, NULL, 0,
    2128              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2129              :         measurement_hash, NULL);
    2130            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    2131              : 
    2132              :     /* Completion of CHALLENGE sets M1/M2 to null. */
    2133              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2134              :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
    2135              : #else
    2136            1 :     assert_null(spdm_context->transcript.digest_context_m1m2);
    2137              : #endif
    2138            1 :     free(data);
    2139            1 : }
    2140              : 
    2141              : /**
    2142              :  * Test 3: the requester is not setup correctly to send a CHALLENGE message:
    2143              :  * - it has *no* flags indicating that the previous messages were sent
    2144              :  * (GET_CAPABILITIES, NEGOTIATE_ALGORITHMS, GET_DIGESTS); but
    2145              :  * - it received the CAPABILITIES message, allowing the use of hash and digital
    2146              :  * signature algorithms, and the use of challenges.
    2147              :  * - it has the responder's certificate chain.
    2148              :  * The CHALLENGE message requests usage of the first certificate in the chain
    2149              :  * (param1=0) and do not request measurements (param2=0).
    2150              :  * The received CHALLENGE_AUTH message correctly responds to the challenge, with
    2151              :  * no opaque data and a signature on the sent nonce.
    2152              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR, and the "C"
    2153              :  * transcript buffer is not set.
    2154              :  **/
    2155            1 : static void req_challenge_case3(void **state)
    2156              : {
    2157              :     libspdm_return_t status;
    2158              :     libspdm_test_context_t *spdm_test_context;
    2159              :     libspdm_context_t *spdm_context;
    2160              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2161              :     void *data;
    2162              :     size_t data_size;
    2163              :     void *hash;
    2164              :     size_t hash_size;
    2165              : 
    2166            1 :     spdm_test_context = *state;
    2167            1 :     spdm_context = spdm_test_context->spdm_context;
    2168            1 :     spdm_test_context->case_id = 0x3;
    2169            1 :     spdm_context->connection_info.connection_state =
    2170              :         LIBSPDM_CONNECTION_STATE_NOT_STARTED;
    2171            1 :     spdm_context->connection_info.capability.flags = 0;
    2172            1 :     spdm_context->connection_info.capability.flags |=
    2173              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2174            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2175              :                                                          m_libspdm_use_asym_algo, &data,
    2176              :                                                          &data_size, &hash, &hash_size)) {
    2177            0 :         assert(false);
    2178              :     }
    2179            1 :     libspdm_reset_message_a(spdm_context);
    2180            1 :     libspdm_reset_message_b(spdm_context);
    2181            1 :     libspdm_reset_message_c(spdm_context);
    2182            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    2183              :         m_libspdm_use_hash_algo;
    2184            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    2185              :         m_libspdm_use_asym_algo;
    2186              : 
    2187            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2188              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2189              : 
    2190              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2191              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2192              :         data_size;
    2193              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2194              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2195              :                      data, data_size);
    2196              : #else
    2197            1 :     libspdm_hash_all(
    2198              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2199              :         data, data_size,
    2200            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2201            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2202            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2203            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2204              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2205              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2206              :         data, data_size,
    2207              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2208              : #endif
    2209              : 
    2210            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    2211            1 :     status = libspdm_challenge(
    2212              :         spdm_context, NULL, 0,
    2213              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2214              :         measurement_hash, NULL);
    2215            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
    2216              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2217              :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
    2218              : #endif
    2219            1 :     free(data);
    2220            1 : }
    2221              : 
    2222              : /**
    2223              :  * Test 4: the requester is setup correctly (see Test 2), but receives an ERROR
    2224              :  * message indicating InvalidParameters.
    2225              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR, and the "C"
    2226              :  * transcript buffer is reset.
    2227              :  **/
    2228            1 : static void req_challenge_case4(void **state)
    2229              : {
    2230              :     libspdm_return_t status;
    2231              :     libspdm_test_context_t *spdm_test_context;
    2232              :     libspdm_context_t *spdm_context;
    2233              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2234              :     void *data;
    2235              :     size_t data_size;
    2236              :     void *hash;
    2237              :     size_t hash_size;
    2238              : 
    2239            1 :     spdm_test_context = *state;
    2240            1 :     spdm_context = spdm_test_context->spdm_context;
    2241            1 :     spdm_test_context->case_id = 0x4;
    2242            1 :     spdm_context->connection_info.connection_state =
    2243              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2244            1 :     spdm_context->connection_info.capability.flags = 0;
    2245            1 :     spdm_context->connection_info.capability.flags |=
    2246              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2247            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2248              :                                                          m_libspdm_use_asym_algo, &data,
    2249              :                                                          &data_size, &hash, &hash_size)) {
    2250            0 :         assert(false);
    2251              :     }
    2252            1 :     libspdm_reset_message_a(spdm_context);
    2253            1 :     libspdm_reset_message_b(spdm_context);
    2254            1 :     libspdm_reset_message_c(spdm_context);
    2255            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    2256              :         m_libspdm_use_hash_algo;
    2257            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    2258              :         m_libspdm_use_asym_algo;
    2259              : 
    2260            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2261              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2262              : 
    2263              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2264              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2265              :         data_size;
    2266              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2267              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2268              :                      data, data_size);
    2269              : #else
    2270            1 :     libspdm_hash_all(
    2271              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2272              :         data, data_size,
    2273            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2274            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2275            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2276            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2277              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2278              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2279              :         data, data_size,
    2280              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2281              : #endif
    2282              : 
    2283            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    2284            1 :     status = libspdm_challenge(
    2285              :         spdm_context, NULL, 0,
    2286              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2287              :         measurement_hash, NULL);
    2288            1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
    2289              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2290              :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
    2291              : #endif
    2292            1 :     free(data);
    2293            1 : }
    2294              : 
    2295              : /**
    2296              :  * Test 5: the requester is setup correctly (see Test 2), but receives an ERROR
    2297              :  * message indicating the Busy status of the responder.
    2298              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR, and the "C"
    2299              :  * transcript buffer is reset.
    2300              :  **/
    2301            1 : static void req_challenge_case5(void **state)
    2302              : {
    2303              :     libspdm_return_t status;
    2304              :     libspdm_test_context_t *spdm_test_context;
    2305              :     libspdm_context_t *spdm_context;
    2306              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2307              :     void *data;
    2308              :     size_t data_size;
    2309              :     void *hash;
    2310              :     size_t hash_size;
    2311              : 
    2312            1 :     spdm_test_context = *state;
    2313            1 :     spdm_context = spdm_test_context->spdm_context;
    2314            1 :     spdm_test_context->case_id = 0x5;
    2315            1 :     spdm_context->connection_info.connection_state =
    2316              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2317            1 :     spdm_context->connection_info.capability.flags = 0;
    2318            1 :     spdm_context->connection_info.capability.flags |=
    2319              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2320            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2321              :                                                          m_libspdm_use_asym_algo, &data,
    2322              :                                                          &data_size, &hash, &hash_size)) {
    2323            0 :         assert(false);
    2324              :     }
    2325            1 :     libspdm_reset_message_a(spdm_context);
    2326            1 :     libspdm_reset_message_b(spdm_context);
    2327            1 :     libspdm_reset_message_c(spdm_context);
    2328            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    2329              :         m_libspdm_use_hash_algo;
    2330            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    2331              :         m_libspdm_use_asym_algo;
    2332              : 
    2333            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2334              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2335              : 
    2336              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2337              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2338              :         data_size;
    2339              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2340              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2341              :                      data, data_size);
    2342              : #else
    2343            1 :     libspdm_hash_all(
    2344              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2345              :         data, data_size,
    2346            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2347            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2348            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2349            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2350              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2351              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2352              :         data, data_size,
    2353              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2354              : #endif
    2355              : 
    2356            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    2357            1 :     status = libspdm_challenge(
    2358              :         spdm_context, NULL, 0,
    2359              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2360              :         measurement_hash, NULL);
    2361            1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
    2362              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2363              :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
    2364              : #endif
    2365            1 :     free(data);
    2366            1 : }
    2367              : 
    2368              : /**
    2369              :  * Test 6: the requester is setup correctly (see Test 2), but, on the first try,
    2370              :  * receiving a Busy ERROR message, and on retry, receiving a correct CHALLENGE_AUTH
    2371              :  * message to the challenge, with no opaque data and a signature on the sent nonce.
    2372              :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    2373              :  **/
    2374            1 : static void req_challenge_case6(void **state)
    2375              : {
    2376              :     libspdm_return_t status;
    2377              :     libspdm_test_context_t *spdm_test_context;
    2378              :     libspdm_context_t *spdm_context;
    2379              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2380              :     void *data;
    2381              :     size_t data_size;
    2382              :     void *hash;
    2383              :     size_t hash_size;
    2384              : 
    2385            1 :     spdm_test_context = *state;
    2386            1 :     spdm_context = spdm_test_context->spdm_context;
    2387            1 :     spdm_test_context->case_id = 0x6;
    2388            1 :     spdm_context->retry_times = 3;
    2389            1 :     spdm_context->connection_info.connection_state =
    2390              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2391            1 :     spdm_context->connection_info.capability.flags = 0;
    2392            1 :     spdm_context->connection_info.capability.flags |=
    2393              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2394            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2395              :                                                          m_libspdm_use_asym_algo, &data,
    2396              :                                                          &data_size, &hash, &hash_size)) {
    2397            0 :         assert(false);
    2398              :     }
    2399            1 :     libspdm_reset_message_a(spdm_context);
    2400            1 :     libspdm_reset_message_b(spdm_context);
    2401            1 :     libspdm_reset_message_c(spdm_context);
    2402            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    2403              :         m_libspdm_use_hash_algo;
    2404            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    2405              :         m_libspdm_use_asym_algo;
    2406              : 
    2407            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2408              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2409              : 
    2410              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2411              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2412              :         data_size;
    2413              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2414              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2415              :                      data, data_size);
    2416              : #else
    2417            1 :     libspdm_hash_all(
    2418              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2419              :         data, data_size,
    2420            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2421            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2422            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2423            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2424              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2425              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2426              :         data, data_size,
    2427              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2428              : #endif
    2429              : 
    2430            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    2431            1 :     status = libspdm_challenge(
    2432              :         spdm_context, NULL, 0,
    2433              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2434              :         measurement_hash, NULL);
    2435            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    2436            1 :     free(data);
    2437            1 : }
    2438              : 
    2439              : /**
    2440              :  * Test 7: the requester is setup correctly (see Test 2), but receives an ERROR
    2441              :  * message indicating the RequestResynch status of the responder.
    2442              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR, the "C"
    2443              :  * transcript buffer is reset, and the communication is reset to expect a new
    2444              :  * GET_VERSION message.
    2445              :  **/
    2446            1 : static void req_challenge_case7(void **state)
    2447              : {
    2448              :     libspdm_return_t status;
    2449              :     libspdm_test_context_t *spdm_test_context;
    2450              :     libspdm_context_t *spdm_context;
    2451              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2452              :     void *data;
    2453              :     size_t data_size;
    2454              :     void *hash;
    2455              :     size_t hash_size;
    2456              : 
    2457            1 :     spdm_test_context = *state;
    2458            1 :     spdm_context = spdm_test_context->spdm_context;
    2459            1 :     spdm_test_context->case_id = 0x7;
    2460            1 :     spdm_context->connection_info.connection_state =
    2461              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2462            1 :     spdm_context->connection_info.capability.flags = 0;
    2463            1 :     spdm_context->connection_info.capability.flags |=
    2464              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2465            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2466              :                                                          m_libspdm_use_asym_algo, &data,
    2467              :                                                          &data_size, &hash, &hash_size)) {
    2468            0 :         assert(false);
    2469              :     }
    2470            1 :     libspdm_reset_message_a(spdm_context);
    2471            1 :     libspdm_reset_message_b(spdm_context);
    2472            1 :     libspdm_reset_message_c(spdm_context);
    2473            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    2474              :         m_libspdm_use_hash_algo;
    2475            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    2476              :         m_libspdm_use_asym_algo;
    2477              : 
    2478            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2479              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2480              : 
    2481              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2482              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2483              :         data_size;
    2484              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2485              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2486              :                      data, data_size);
    2487              : #else
    2488            1 :     libspdm_hash_all(
    2489              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2490              :         data, data_size,
    2491            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2492            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2493            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2494            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2495              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2496              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2497              :         data, data_size,
    2498              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2499              : #endif
    2500              : 
    2501            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    2502            1 :     status = libspdm_challenge(
    2503              :         spdm_context, NULL, 0,
    2504              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2505              :         measurement_hash, NULL);
    2506            1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
    2507            1 :     assert_int_equal(spdm_context->connection_info.connection_state,
    2508              :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
    2509              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2510              :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
    2511              : #endif
    2512            1 :     free(data);
    2513            1 : }
    2514              : 
    2515              : /**
    2516              :  * Test 8: the requester is setup correctly (see Test 2), but receives an ERROR
    2517              :  * message indicating the ResponseNotReady status of the responder.
    2518              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR, and the "C"
    2519              :  * buffer stores nothing.
    2520              :  **/
    2521            1 : static void req_challenge_case8(void **state)
    2522              : {
    2523              :     libspdm_return_t status;
    2524              :     libspdm_test_context_t *spdm_test_context;
    2525              :     libspdm_context_t *spdm_context;
    2526              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2527              :     void *data;
    2528              :     size_t data_size;
    2529              :     void *hash;
    2530              :     size_t hash_size;
    2531              : 
    2532            1 :     spdm_test_context = *state;
    2533            1 :     spdm_context = spdm_test_context->spdm_context;
    2534            1 :     spdm_test_context->case_id = 0x8;
    2535            1 :     spdm_context->connection_info.connection_state =
    2536              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2537            1 :     spdm_context->connection_info.capability.flags = 0;
    2538            1 :     spdm_context->connection_info.capability.flags |=
    2539              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2540            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2541              :                                                          m_libspdm_use_asym_algo, &data,
    2542              :                                                          &data_size, &hash, &hash_size)) {
    2543            0 :         assert(false);
    2544              :     }
    2545            1 :     libspdm_reset_message_a(spdm_context);
    2546            1 :     libspdm_reset_message_b(spdm_context);
    2547            1 :     libspdm_reset_message_c(spdm_context);
    2548            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    2549              :         m_libspdm_use_hash_algo;
    2550            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    2551              :         m_libspdm_use_asym_algo;
    2552              : 
    2553            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2554              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2555              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2556              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2557              :         data_size;
    2558              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2559              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2560              :                      data, data_size);
    2561              : #else
    2562            1 :     libspdm_hash_all(
    2563              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2564              :         data, data_size,
    2565            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2566            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2567            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2568            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2569              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2570              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2571              :         data, data_size,
    2572              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2573              : #endif
    2574              : 
    2575            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    2576              : 
    2577            1 :     status = libspdm_challenge(
    2578              :         spdm_context, NULL, 0,
    2579              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2580              :         measurement_hash, NULL);
    2581            1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
    2582              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2583              :     assert_int_equal (spdm_context->transcript.message_c.buffer_size, 0);
    2584              : #endif
    2585            1 :     free(data);
    2586            1 : }
    2587              : 
    2588              : /**
    2589              :  * Test 9: the requester is setup correctly (see Test 2), but, on the first try,
    2590              :  * receiving a ResponseNotReady ERROR message, and on retry, receiving a correct
    2591              :  * CHALLENGE_AUTH message to the challenge, with no opaque data and a signature
    2592              :  * on the sent nonce.
    2593              :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    2594              :  **/
    2595            1 : static void req_challenge_case9(void **state)
    2596              : {
    2597              :     libspdm_return_t status;
    2598              :     libspdm_test_context_t *spdm_test_context;
    2599              :     libspdm_context_t *spdm_context;
    2600              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2601              :     void *data;
    2602              :     size_t data_size;
    2603              :     void *hash;
    2604              :     size_t hash_size;
    2605              : 
    2606            1 :     spdm_test_context = *state;
    2607            1 :     spdm_context = spdm_test_context->spdm_context;
    2608            1 :     spdm_test_context->case_id = 0x9;
    2609            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2610            1 :     spdm_context->connection_info.capability.flags = 0;
    2611            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2612            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    2613              :                                                          m_libspdm_use_asym_algo, &data,
    2614              :                                                          &data_size, &hash, &hash_size)) {
    2615            0 :         assert(false);
    2616              :     }
    2617            1 :     libspdm_reset_message_a(spdm_context);
    2618            1 :     libspdm_reset_message_b(spdm_context);
    2619            1 :     libspdm_reset_message_c(spdm_context);
    2620            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    2621            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    2622              : 
    2623            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2624              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2625              : 
    2626              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2627              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
    2628              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2629              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2630              :                      data, data_size);
    2631              : #else
    2632            1 :     libspdm_hash_all(
    2633              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2634              :         data, data_size,
    2635            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2636            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2637            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2638            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2639              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2640              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2641              :         data, data_size,
    2642              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2643              : #endif
    2644              : 
    2645            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    2646            1 :     status = libspdm_challenge(
    2647              :         spdm_context, NULL, 0,
    2648              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2649              :         measurement_hash, NULL);
    2650              :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
    2651            1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    2652              :     } else {
    2653              :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
    2654              :     }
    2655            1 :     free(data);
    2656            1 : }
    2657              : 
    2658              : /**
    2659              :  * Test 10: the requester is not setup correctly to send a CHALLENGE message.
    2660              :  * Specifically, it has *not* received the capability for challenge, although it
    2661              :  * has received capability for executing both hash and signature algorithms.
    2662              :  * The remaining setup and message exchange were executed correctly (see Test 2).
    2663              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR, and the "C"
    2664              :  * transcript buffer is not set.
    2665              :  **/
    2666            1 : static void req_challenge_case10(void **state) {
    2667              :     libspdm_return_t status;
    2668              :     libspdm_test_context_t    *spdm_test_context;
    2669              :     libspdm_context_t  *spdm_context;
    2670              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2671              :     void                 *data;
    2672              :     size_t data_size;
    2673              :     void                 *hash;
    2674              :     size_t hash_size;
    2675              : 
    2676            1 :     spdm_test_context = *state;
    2677            1 :     spdm_context = spdm_test_context->spdm_context;
    2678            1 :     spdm_test_context->case_id = 0xA;
    2679            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2680            1 :     spdm_context->connection_info.capability.flags = 0;
    2681              :     /* spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;*/
    2682            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    2683              :                                                      m_libspdm_use_asym_algo,
    2684              :                                                      &data, &data_size,
    2685              :                                                      &hash, &hash_size);
    2686            1 :     libspdm_reset_message_a(spdm_context);
    2687            1 :     libspdm_reset_message_b(spdm_context);
    2688            1 :     libspdm_reset_message_c(spdm_context);
    2689            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    2690            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    2691              : 
    2692            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2693              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2694              : 
    2695              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2696              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2697              :         data_size;
    2698              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2699              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2700              :                      data, data_size);
    2701              : #else
    2702            1 :     libspdm_hash_all(
    2703              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2704              :         data, data_size,
    2705            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2706            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2707            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2708            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2709              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2710              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2711              :         data, data_size,
    2712              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2713              : #endif
    2714              : 
    2715            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    2716            1 :     status = libspdm_challenge (spdm_context, NULL, 0,
    2717              :                                 SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2718              :                                 measurement_hash, NULL);
    2719            1 :     assert_int_equal (status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
    2720              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2721              :     assert_int_equal (spdm_context->transcript.message_c.buffer_size, 0);
    2722              : #endif
    2723            1 :     free(data);
    2724            1 : }
    2725              : 
    2726              : /**
    2727              :  * Test 11: the requester is setup correctly (see Test 2), but receives a malformed
    2728              :  * response message, smaller then a standard SPDM message header.
    2729              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR,.
    2730              :  **/
    2731            1 : static void req_challenge_case11(void **state) {
    2732              :     libspdm_return_t status;
    2733              :     libspdm_test_context_t    *spdm_test_context;
    2734              :     libspdm_context_t  *spdm_context;
    2735              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2736              :     void                 *data;
    2737              :     size_t data_size;
    2738              :     void                 *hash;
    2739              :     size_t hash_size;
    2740              : 
    2741            1 :     spdm_test_context = *state;
    2742            1 :     spdm_context = spdm_test_context->spdm_context;
    2743            1 :     spdm_test_context->case_id = 0xB;
    2744            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2745            1 :     spdm_context->connection_info.capability.flags = 0;
    2746            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2747            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    2748              :                                                      m_libspdm_use_asym_algo,
    2749              :                                                      &data, &data_size,
    2750              :                                                      &hash, &hash_size);
    2751            1 :     libspdm_reset_message_a(spdm_context);
    2752            1 :     libspdm_reset_message_b(spdm_context);
    2753            1 :     libspdm_reset_message_c(spdm_context);
    2754            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    2755            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    2756              : 
    2757            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2758              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2759              : 
    2760              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2761              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2762              :         data_size;
    2763              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2764              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2765              :                      data, data_size);
    2766              : #else
    2767            1 :     libspdm_hash_all(
    2768              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2769              :         data, data_size,
    2770            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2771            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2772            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2773            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2774              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2775              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2776              :         data, data_size,
    2777              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2778              : #endif
    2779              : 
    2780            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    2781            1 :     status = libspdm_challenge (spdm_context, NULL, 0,
    2782              :                                 SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2783              :                                 measurement_hash, NULL);
    2784            1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    2785            1 :     free(data);
    2786            1 : }
    2787              : 
    2788              : /**
    2789              :  * Test 12: the requester is setup correctly (see Test 2), but receives a malformed
    2790              :  * response message, with version (1.0) different from the request (1.1).
    2791              :  * The remaining message data is as a correct CHALLENGE_AUTH message.
    2792              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
    2793              :  **/
    2794            1 : static void req_challenge_case12(void **state) {
    2795              :     libspdm_return_t status;
    2796              :     libspdm_test_context_t    *spdm_test_context;
    2797              :     libspdm_context_t  *spdm_context;
    2798              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2799              :     void                 *data;
    2800              :     size_t data_size;
    2801              :     void                 *hash;
    2802              :     size_t hash_size;
    2803              : 
    2804            1 :     spdm_test_context = *state;
    2805            1 :     spdm_context = spdm_test_context->spdm_context;
    2806            1 :     spdm_test_context->case_id = 0xC;
    2807            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2808            1 :     spdm_context->connection_info.capability.flags = 0;
    2809            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2810            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    2811              :                                                      m_libspdm_use_asym_algo,
    2812              :                                                      &data, &data_size,
    2813              :                                                      &hash, &hash_size);
    2814            1 :     libspdm_reset_message_a(spdm_context);
    2815            1 :     libspdm_reset_message_b(spdm_context);
    2816            1 :     libspdm_reset_message_c(spdm_context);
    2817            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    2818            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    2819              : 
    2820            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2821              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2822              : 
    2823              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2824              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2825              :         data_size;
    2826              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2827              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2828              :                      data, data_size);
    2829              : #else
    2830            1 :     libspdm_hash_all(
    2831              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2832              :         data, data_size,
    2833            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2834            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2835            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2836            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2837              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2838              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2839              :         data, data_size,
    2840              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2841              : #endif
    2842              : 
    2843            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    2844            1 :     status = libspdm_challenge (spdm_context, NULL, 0,
    2845              :                                 SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2846              :                                 measurement_hash, NULL);
    2847            1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    2848            1 :     free(data);
    2849            1 : }
    2850              : 
    2851              : /**
    2852              :  * Test 13: the requester is setup correctly (see Test 2), but receives a malformed
    2853              :  * response message, with wrong request_response_code (CHALLENGE 0x83 instead of
    2854              :  * CHALLENGE_AUTH 0x03).
    2855              :  * The remaining message data is as a correct CHALLENGE_AUTH message.
    2856              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
    2857              :  **/
    2858            1 : static void req_challenge_case13(void **state) {
    2859              :     libspdm_return_t status;
    2860              :     libspdm_test_context_t    *spdm_test_context;
    2861              :     libspdm_context_t  *spdm_context;
    2862              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2863              :     void                 *data;
    2864              :     size_t data_size;
    2865              :     void                 *hash;
    2866              :     size_t hash_size;
    2867              : 
    2868            1 :     spdm_test_context = *state;
    2869            1 :     spdm_context = spdm_test_context->spdm_context;
    2870            1 :     spdm_test_context->case_id = 0xD;
    2871            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2872            1 :     spdm_context->connection_info.capability.flags = 0;
    2873            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2874            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    2875              :                                                      m_libspdm_use_asym_algo,
    2876              :                                                      &data, &data_size,
    2877              :                                                      &hash, &hash_size);
    2878            1 :     libspdm_reset_message_a(spdm_context);
    2879            1 :     libspdm_reset_message_b(spdm_context);
    2880            1 :     libspdm_reset_message_c(spdm_context);
    2881            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    2882            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    2883              : 
    2884            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2885              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2886              : 
    2887              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2888              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2889              :         data_size;
    2890              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2891              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2892              :                      data, data_size);
    2893              : #else
    2894            1 :     libspdm_hash_all(
    2895              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2896              :         data, data_size,
    2897            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2898            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2899            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2900            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2901              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2902              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2903              :         data, data_size,
    2904              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2905              : #endif
    2906              : 
    2907            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    2908            1 :     status = libspdm_challenge (spdm_context, NULL, 0,
    2909              :                                 SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2910              :                                 measurement_hash, NULL);
    2911            1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    2912            1 :     free(data);
    2913            1 : }
    2914              : 
    2915              : /**
    2916              :  * Test 14: the requester is setup correctly (see Test 2), but receives a malformed
    2917              :  * response message, with a slot number different from the requested.
    2918              :  * The remaining message data is as a correct CHALLENGE_AUTH message.
    2919              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
    2920              :  **/
    2921            1 : static void req_challenge_case14(void **state) {
    2922              :     libspdm_return_t status;
    2923              :     libspdm_test_context_t    *spdm_test_context;
    2924              :     libspdm_context_t  *spdm_context;
    2925              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    2926              :     void                 *data;
    2927              :     size_t data_size;
    2928              :     void                 *hash;
    2929              :     size_t hash_size;
    2930              : 
    2931            1 :     spdm_test_context = *state;
    2932            1 :     spdm_context = spdm_test_context->spdm_context;
    2933            1 :     spdm_test_context->case_id = 0xE;
    2934            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    2935            1 :     spdm_context->connection_info.capability.flags = 0;
    2936            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    2937            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    2938              :                                                      m_libspdm_use_asym_algo,
    2939              :                                                      &data, &data_size,
    2940              :                                                      &hash, &hash_size);
    2941            1 :     libspdm_reset_message_a(spdm_context);
    2942            1 :     libspdm_reset_message_b(spdm_context);
    2943            1 :     libspdm_reset_message_c(spdm_context);
    2944            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    2945            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    2946              : 
    2947            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    2948              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    2949              : 
    2950              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2951              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    2952              :         data_size;
    2953              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    2954              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    2955              :                      data, data_size);
    2956              : #else
    2957            1 :     libspdm_hash_all(
    2958              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2959              :         data, data_size,
    2960            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    2961            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    2962            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2963            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    2964              :         spdm_context->connection_info.algorithm.base_hash_algo,
    2965              :         spdm_context->connection_info.algorithm.base_asym_algo,
    2966              :         data, data_size,
    2967              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    2968              : #endif
    2969              : 
    2970            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    2971            1 :     status = libspdm_challenge (spdm_context, NULL, 0,
    2972              :                                 SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    2973              :                                 measurement_hash, NULL);
    2974            1 :     assert_int_equal (status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    2975            1 :     free(data);
    2976            1 : }
    2977              : 
    2978              : /**
    2979              :  * Test 15: free to be populated by test.
    2980              :  **/
    2981            1 : static void req_challenge_case15(void **state) {
    2982            1 : }
    2983              : 
    2984              : /**
    2985              :  * Test 16: the requester is setup correctly to send a CHALLENGE message:
    2986              :  * - it has flags indicating that the previous messages were sent
    2987              :  * (GET_CAPABILITIES, NEGOTIATE_ALGORITHMS, and GET_DIGESTS).
    2988              :  * - it received the CAPABILITIES message, allowing the use of hash and digital
    2989              :  * signature algorithms, and the use of challenges.
    2990              :  * - it has the responder's certificate chain.
    2991              :  * The CHALLENGE message requests usage of the first certificate in the chain
    2992              :  * (param1=0) and do not request measurements (param2=0).
    2993              :  * The received CHALLENGE_AUTH message correctly responds to the challenge, opaque
    2994              :  * data with bytes from the string "libspdm", and a signature on the sent nonce.
    2995              :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    2996              :  **/
    2997            1 : static void req_challenge_case16(void **state) {
    2998              :     libspdm_return_t status;
    2999              :     libspdm_test_context_t    *spdm_test_context;
    3000              :     libspdm_context_t  *spdm_context;
    3001              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3002              :     void                 *data;
    3003              :     size_t data_size;
    3004              :     void                 *hash;
    3005              :     size_t hash_size;
    3006              :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
    3007              :     size_t opaque_data_size;
    3008              : 
    3009            1 :     spdm_test_context = *state;
    3010            1 :     spdm_context = spdm_test_context->spdm_context;
    3011            1 :     spdm_test_context->case_id = 0x10;
    3012            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3013            1 :     spdm_context->connection_info.capability.flags = 0;
    3014            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3015            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    3016              :                                                      m_libspdm_use_asym_algo,
    3017              :                                                      &data, &data_size,
    3018              :                                                      &hash, &hash_size);
    3019            1 :     libspdm_reset_message_a(spdm_context);
    3020            1 :     libspdm_reset_message_b(spdm_context);
    3021            1 :     libspdm_reset_message_c(spdm_context);
    3022            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3023            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3024              : 
    3025            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3026              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3027              : 
    3028              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3029              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3030              :         data_size;
    3031              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3032              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3033              :                      data, data_size);
    3034              : #else
    3035            1 :     libspdm_hash_all(
    3036              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3037              :         data, data_size,
    3038            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3039            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3040            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3041            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3042              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3043              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3044              :         data, data_size,
    3045              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3046              : #endif
    3047              : 
    3048            1 :     opaque_data_size = sizeof(opaque_data);
    3049              : 
    3050            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    3051            1 :     status = libspdm_challenge_ex (spdm_context, NULL, 0,
    3052              :                                    SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3053              :                                    measurement_hash, NULL, NULL, NULL, NULL,
    3054              :                                    opaque_data, &opaque_data_size);
    3055            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3056            1 :     assert_int_equal(opaque_data_size, strlen("libspdm"));
    3057            1 :     assert_memory_equal(opaque_data, "libspdm", opaque_data_size);
    3058            1 :     free(data);
    3059            1 : }
    3060              : 
    3061              : /**
    3062              :  * Test 17: the requester is setup correctly to send a CHALLENGE message:
    3063              :  * - it has flags indicating that the previous messages were sent
    3064              :  * (GET_CAPABILITIES, NEGOTIATE_ALGORITHMS, and GET_DIGESTS).
    3065              :  * - it received the CAPABILITIES message, allowing the use of hash and digital
    3066              :  * signature algorithms, and the use of challenges.
    3067              :  * - it has the responder's certificate chain.
    3068              :  * The CHALLENGE message requests usage of the first certificate in the chain
    3069              :  * (param1=0) and do not request measurements (param2=0).
    3070              :  * The received CHALLENGE_AUTH message correctly responds to the challenge,
    3071              :  * but with an invalid signature.
    3072              :  * Expected behavior: client returns a status of RETURN_SECURITY_VIOLATION.
    3073              :  **/
    3074            1 : static void req_challenge_case17(void **state) {
    3075              :     libspdm_return_t status;
    3076              :     libspdm_test_context_t    *spdm_test_context;
    3077              :     libspdm_context_t  *spdm_context;
    3078              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3079              :     void                 *data;
    3080              :     size_t data_size;
    3081              :     void                 *hash;
    3082              :     size_t hash_size;
    3083              : 
    3084            1 :     spdm_test_context = *state;
    3085            1 :     spdm_context = spdm_test_context->spdm_context;
    3086            1 :     spdm_test_context->case_id = 0x11;
    3087            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3088            1 :     spdm_context->connection_info.capability.flags = 0;
    3089            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3090            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    3091              :                                                      m_libspdm_use_asym_algo,
    3092              :                                                      &data, &data_size,
    3093              :                                                      &hash, &hash_size);
    3094            1 :     libspdm_reset_message_a(spdm_context);
    3095            1 :     libspdm_reset_message_b(spdm_context);
    3096            1 :     libspdm_reset_message_c(spdm_context);
    3097            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3098            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3099              : 
    3100            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3101              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3102              : 
    3103              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3104              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3105              :         data_size;
    3106              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3107              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3108              :                      data, data_size);
    3109              : #else
    3110            1 :     libspdm_hash_all(
    3111              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3112              :         data, data_size,
    3113            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3114            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3115            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3116            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3117              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3118              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3119              :         data, data_size,
    3120              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3121              : #endif
    3122              : 
    3123            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    3124            1 :     status = libspdm_challenge (spdm_context, NULL, 0,
    3125              :                                 SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3126              :                                 measurement_hash, NULL);
    3127            1 :     assert_int_equal (status, LIBSPDM_STATUS_VERIF_FAIL);
    3128            1 :     free(data);
    3129            1 : }
    3130              : 
    3131              : /**
    3132              :  * Test 18: the requester is setup correctly to send a CHALLENGE message:
    3133              :  * - it has flags indicating that the previous messages were sent
    3134              :  * (GET_CAPABILITIES, NEGOTIATE_ALGORITHMS, and GET_DIGESTS).
    3135              :  * - it received the CAPABILITIES message, allowing the use of hash and digital
    3136              :  * signature algorithms, the use of challenges, and of measurements.
    3137              :  * - it has the responder's certificate chain.
    3138              :  * The CHALLENGE message requests usage of the first certificate in the chain
    3139              :  * (param1=0) and request TCB measurements (param2=1).
    3140              :  * The received CHALLENGE_AUTH message correctly responds to the challenge, with
    3141              :  * no opaque data and a signature on the sent nonce.
    3142              :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    3143              :  **/
    3144            1 : static void req_challenge_case18(void **state) {
    3145              :     libspdm_return_t status;
    3146              :     libspdm_test_context_t    *spdm_test_context;
    3147              :     libspdm_context_t  *spdm_context;
    3148              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3149              :     void                 *data;
    3150              :     size_t data_size;
    3151              :     void                 *hash;
    3152              :     size_t hash_size;
    3153              : 
    3154            1 :     spdm_test_context = *state;
    3155            1 :     spdm_context = spdm_test_context->spdm_context;
    3156            1 :     spdm_test_context->case_id = 0x12;
    3157            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3158            1 :     spdm_context->connection_info.capability.flags = 0;
    3159            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3160            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP; /*additional measurement capability*/
    3161            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    3162              :                                                      m_libspdm_use_asym_algo,
    3163              :                                                      &data, &data_size,
    3164              :                                                      &hash, &hash_size);
    3165            1 :     libspdm_reset_message_a(spdm_context);
    3166            1 :     libspdm_reset_message_b(spdm_context);
    3167            1 :     libspdm_reset_message_c(spdm_context);
    3168            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3169            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3170              : 
    3171            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3172              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3173              : 
    3174              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3175              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3176              :         data_size;
    3177              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3178              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3179              :                      data, data_size);
    3180              : #else
    3181            1 :     libspdm_hash_all(
    3182              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3183              :         data, data_size,
    3184            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3185            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3186            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3187            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3188              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3189              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3190              :         data, data_size,
    3191              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3192              : #endif
    3193              : 
    3194            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    3195            1 :     status = libspdm_challenge (spdm_context, NULL, 0,
    3196              :                                 SPDM_CHALLENGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH,
    3197              :                                 measurement_hash, NULL);
    3198            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3199            1 : }
    3200              : 
    3201              : /**
    3202              :  * Test 19: the requester is setup correctly to send a CHALLENGE message:
    3203              :  * - it has flags indicating that the previous messages were sent
    3204              :  * (GET_CAPABILITIES, NEGOTIATE_ALGORITHMS, and GET_DIGESTS).
    3205              :  * - it received the CAPABILITIES message, allowing the use of hash and digital
    3206              :  * signature algorithms, the use of challenges, and of measurements.
    3207              :  * - it has the responder's certificate chain.
    3208              :  * The CHALLENGE message requests usage of the first certificate in the chain
    3209              :  * (param1=0) and request TCB measurements (param2=1).
    3210              :  * The received CHALLENGE_AUTH message correctly responds to the challenge, with
    3211              :  * no opaque data and a signature on the sent nonce.
    3212              :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    3213              :  **/
    3214            1 : static void req_challenge_case19(void **state) {
    3215              :     libspdm_return_t status;
    3216              :     libspdm_test_context_t    *spdm_test_context;
    3217              :     libspdm_context_t  *spdm_context;
    3218              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3219              :     void                 *data;
    3220              :     size_t data_size;
    3221              :     void                 *hash;
    3222              :     size_t hash_size;
    3223              : 
    3224            1 :     spdm_test_context = *state;
    3225            1 :     spdm_context = spdm_test_context->spdm_context;
    3226            1 :     spdm_test_context->case_id = 0x13;
    3227            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3228            1 :     spdm_context->connection_info.capability.flags = 0;
    3229            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3230            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP; /*additional measurement capability*/
    3231            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    3232              :                                                      m_libspdm_use_asym_algo,
    3233              :                                                      &data, &data_size,
    3234              :                                                      &hash, &hash_size);
    3235            1 :     libspdm_reset_message_a(spdm_context);
    3236            1 :     libspdm_reset_message_b(spdm_context);
    3237            1 :     libspdm_reset_message_c(spdm_context);
    3238            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3239            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3240              : 
    3241            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3242              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3243              : 
    3244              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3245              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3246              :         data_size;
    3247              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3248              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3249              :                      data, data_size);
    3250              : #else
    3251            1 :     libspdm_hash_all(
    3252              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3253              :         data, data_size,
    3254            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3255            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3256            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3257            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3258              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3259              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3260              :         data, data_size,
    3261              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3262              : #endif
    3263              : 
    3264            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    3265            1 :     status = libspdm_challenge (spdm_context, NULL, 0,
    3266              :                                 SPDM_CHALLENGE_REQUEST_ALL_MEASUREMENTS_HASH,
    3267              :                                 measurement_hash, NULL);
    3268            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3269            1 : }
    3270              : 
    3271              : /**
    3272              :  * Test 20: receiving an unexpected ERROR message from the responder.
    3273              :  * There are tests for all named codes, including some reserved ones
    3274              :  * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
    3275              :  * However, for having specific test cases, it is excluded from this case:
    3276              :  * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
    3277              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
    3278              :  **/
    3279            1 : static void req_challenge_case20(void **state) {
    3280              :     libspdm_return_t status;
    3281              :     libspdm_test_context_t    *spdm_test_context;
    3282              :     libspdm_context_t  *spdm_context;
    3283              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3284              :     void                 *data;
    3285              :     size_t data_size;
    3286              :     void                 *hash;
    3287              :     size_t hash_size;
    3288              :     uint16_t error_code;
    3289              : 
    3290            1 :     spdm_test_context = *state;
    3291            1 :     spdm_context = spdm_test_context->spdm_context;
    3292            1 :     spdm_test_context->case_id = 0x14;
    3293            1 :     spdm_context->connection_info.capability.flags = 0;
    3294            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3295            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    3296              :                                                      m_libspdm_use_asym_algo,
    3297              :                                                      &data, &data_size,
    3298              :                                                      &hash, &hash_size);
    3299            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3300            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3301              : 
    3302            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3303              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3304              : 
    3305              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3306              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3307              :         data_size;
    3308              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3309              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3310              :                      data, data_size);
    3311              : #else
    3312            1 :     libspdm_hash_all(
    3313              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3314              :         data, data_size,
    3315            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3316            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3317            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3318            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3319              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3320              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3321              :         data, data_size,
    3322              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3323              : #endif
    3324              : 
    3325            1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
    3326           19 :     while(error_code <= 0xff) {
    3327           18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3328           18 :         libspdm_reset_message_a(spdm_context);
    3329           18 :         libspdm_reset_message_b(spdm_context);
    3330           18 :         libspdm_reset_message_c(spdm_context);
    3331              : 
    3332           18 :         libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    3333           18 :         status = libspdm_challenge (spdm_context, NULL, 0,
    3334              :                                     SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3335              :                                     measurement_hash, NULL);
    3336           18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
    3337              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3338              :         /* assert_int_equal (spdm_context->transcript.message_c.buffer_size, 0);*/
    3339              :         LIBSPDM_ASSERT_INT_EQUAL_CASE (spdm_context->transcript.message_c.buffer_size, 0,
    3340              :                                        error_code);
    3341              : #endif
    3342              : 
    3343           18 :         error_code++;
    3344           18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
    3345            1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
    3346              :         }
    3347           18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
    3348            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
    3349              :         }
    3350           18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
    3351            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
    3352              :         }
    3353              :     }
    3354              : 
    3355            1 :     free(data);
    3356            1 : }
    3357              : 
    3358              : /**
    3359              :  * Test 21: test correct CHALLENGE_AUTH message with multiple slot numbers
    3360              :  * Expected behavior: success and slot_id is included in slot_mask.
    3361              :  **/
    3362            1 : static void req_challenge_case21(void **state) {
    3363              :     libspdm_return_t status;
    3364              :     libspdm_test_context_t    *spdm_test_context;
    3365              :     libspdm_context_t  *spdm_context;
    3366              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3367              :     void                 *data;
    3368              :     size_t data_size;
    3369              :     void                 *hash;
    3370              :     size_t hash_size;
    3371              :     uint8_t slot_id;
    3372              :     uint8_t slot_mask;
    3373              : 
    3374            1 :     spdm_test_context = *state;
    3375            1 :     spdm_context = spdm_test_context->spdm_context;
    3376            1 :     spdm_test_context->case_id = 0x15;
    3377            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3378            1 :     spdm_context->connection_info.capability.flags = 0;
    3379            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3380            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    3381              :                                                      m_libspdm_use_asym_algo,
    3382              :                                                      &data, &data_size,
    3383              :                                                      &hash, &hash_size);
    3384            1 :     libspdm_reset_message_a(spdm_context);
    3385            1 :     libspdm_reset_message_b(spdm_context);
    3386            1 :     libspdm_reset_message_c(spdm_context);
    3387            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3388            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3389            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3390              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3391              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3392              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3393              :         data_size;
    3394              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3395              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3396              :                      data, data_size);
    3397              : #else
    3398            1 :     libspdm_hash_all(
    3399              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3400              :         data, data_size,
    3401            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3402            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3403            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3404            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3405              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3406              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3407              :         data, data_size,
    3408              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3409              : #endif
    3410              : 
    3411            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    3412              : 
    3413            1 :     slot_id = 0;
    3414            1 :     status = libspdm_challenge (spdm_context, NULL, slot_id,
    3415              :                                 SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3416              :                                 measurement_hash, &slot_mask);
    3417            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3418            1 :     assert_int_equal(1<<slot_id, slot_mask & (1<<slot_id));
    3419            1 :     free(data);
    3420            1 : }
    3421              : 
    3422              : /**
    3423              :  * Test 22: a request message is successfully sent and a response message is successfully received.
    3424              :  * Buffer C already has arbitrary data.
    3425              :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a CHALLENGE_AUTH message is
    3426              :  * received, buffer C appends the exchanged CHALLENGE and CHALLENGE_AUTH messages.
    3427              :  **/
    3428            1 : static void req_challenge_case22(void **state)
    3429              : {
    3430              :     libspdm_return_t status;
    3431              :     libspdm_test_context_t *spdm_test_context;
    3432              :     libspdm_context_t *spdm_context;
    3433              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3434              :     void *data;
    3435              :     size_t data_size;
    3436              :     void *hash;
    3437              :     size_t hash_size;
    3438              : 
    3439            1 :     spdm_test_context = *state;
    3440            1 :     spdm_context = spdm_test_context->spdm_context;
    3441            1 :     spdm_test_context->case_id = 0x16;
    3442            1 :     spdm_context->connection_info.connection_state =
    3443              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3444            1 :     spdm_context->connection_info.capability.flags = 0;
    3445            1 :     spdm_context->connection_info.capability.flags |=
    3446              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3447            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3448              :                                                          m_libspdm_use_asym_algo, &data,
    3449              :                                                          &data_size, &hash, &hash_size)) {
    3450            0 :         assert(false);
    3451              :     }
    3452            1 :     libspdm_reset_message_a(spdm_context);
    3453            1 :     libspdm_reset_message_b(spdm_context);
    3454            1 :     libspdm_reset_message_c(spdm_context);
    3455            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3456              :         m_libspdm_use_hash_algo;
    3457            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3458              :         m_libspdm_use_asym_algo;
    3459              : 
    3460              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3461              :     /*filling all buffers with arbitrary data*/
    3462              :     libspdm_set_mem(spdm_context->transcript.message_a.buffer, 10, (uint8_t) 0xFF);
    3463              :     spdm_context->transcript.message_a.buffer_size = 10;
    3464              :     libspdm_set_mem(spdm_context->transcript.message_b.buffer, 8, (uint8_t) 0xEE);
    3465              :     spdm_context->transcript.message_b.buffer_size = 8;
    3466              :     libspdm_set_mem(spdm_context->transcript.message_c.buffer, 12, (uint8_t) 0xDD);
    3467              :     spdm_context->transcript.message_c.buffer_size = 12;
    3468              : #endif
    3469              : 
    3470            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3471              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3472              : 
    3473              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3474              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3475              :         data_size;
    3476              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3477              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3478              :                      data, data_size);
    3479              : #else
    3480            1 :     libspdm_hash_all(
    3481              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3482              :         data, data_size,
    3483            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3484            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3485            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3486            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3487              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3488              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3489              :         data, data_size,
    3490              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3491              : #endif
    3492              : 
    3493            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3494            1 :     status = libspdm_challenge(
    3495              :         spdm_context, NULL, 0,
    3496              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3497              :         measurement_hash, NULL);
    3498            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3499              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3500              :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
    3501              :                    m_libspdm_local_buffer_size));
    3502              :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3503              : #endif
    3504            1 :     free(data);
    3505            1 : }
    3506              : 
    3507              : /**
    3508              :  * Test 23: GetCert (Slot 0), GetCert (Slot 1), then Challenge (Slot 0), (Slot1):
    3509              :  * - it has flags indicating that the previous messages were sent
    3510              :  * (GET_CAPABILITIES, NEGOTIATE_ALGORITHMS, and GET_DIGESTS).
    3511              :  * - it received the CAPABILITIES message, allowing the use of hash and digital
    3512              :  * signature algorithms, and the use of challenges.
    3513              :  * - it has the responder's certificate chain.
    3514              :  * The CHALLENGE message requests usage of the first certificate in the chain
    3515              :  * (param1=0) and do not request measurements (param2=0).
    3516              :  * The received CHALLENGE_AUTH message correctly responds to the challenge, with
    3517              :  * no opaque data and a signature on the sent nonce.
    3518              :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    3519              :  **/
    3520            1 : static void req_challenge_case23(void **state)
    3521              : {
    3522              :     libspdm_return_t status;
    3523              :     libspdm_test_context_t *spdm_test_context;
    3524              :     libspdm_context_t *spdm_context;
    3525              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3526              :     void *data;
    3527              :     void *data1;
    3528              :     size_t data_size;
    3529              :     size_t data1_size;
    3530              :     void *hash;
    3531              :     void *hash1;
    3532              :     size_t hash_size;
    3533              :     size_t hash1_size;
    3534              :     uint8_t slot_id;
    3535              : 
    3536            1 :     spdm_test_context = *state;
    3537            1 :     spdm_context = spdm_test_context->spdm_context;
    3538            1 :     spdm_test_context->case_id = 0x17;
    3539            1 :     spdm_context->connection_info.connection_state =
    3540              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3541            1 :     spdm_context->connection_info.capability.flags = 0;
    3542            1 :     spdm_context->connection_info.capability.flags |=
    3543              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3544              : 
    3545            1 :     libspdm_reset_message_a(spdm_context);
    3546            1 :     libspdm_reset_message_b(spdm_context);
    3547            1 :     libspdm_reset_message_c(spdm_context);
    3548            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3549              :         m_libspdm_use_hash_algo;
    3550            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3551              :         m_libspdm_use_asym_algo;
    3552              : 
    3553            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3554              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3555              : 
    3556            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3557              :                                                          m_libspdm_use_asym_algo, &data,
    3558              :                                                          &data_size, &hash, &hash_size)) {
    3559            0 :         assert(false);
    3560              :     }
    3561              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3562              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3563              :         data_size;
    3564              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3565              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3566              :                      data, data_size);
    3567              : #else
    3568            1 :     libspdm_hash_all(
    3569              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3570              :         data, data_size,
    3571            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3572            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3573            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3574            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3575              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3576              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3577              :         data, data_size,
    3578              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3579              : #endif
    3580              : 
    3581            1 :     libspdm_read_responder_public_certificate_chain_per_slot(
    3582              :         1,
    3583              :         m_libspdm_use_hash_algo,
    3584              :         m_libspdm_use_asym_algo, &data1,
    3585              :         &data1_size, &hash1, &hash1_size);
    3586              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3587              :     spdm_context->connection_info.peer_used_cert_chain[1].buffer_size =
    3588              :         data1_size;
    3589              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[1].buffer,
    3590              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[1].buffer),
    3591              :                      data1, data1_size);
    3592              : #else
    3593            1 :     libspdm_hash_all(
    3594              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3595              :         data1, data1_size,
    3596            1 :         spdm_context->connection_info.peer_used_cert_chain[1].buffer_hash);
    3597            1 :     spdm_context->connection_info.peer_used_cert_chain[1].buffer_hash_size =
    3598            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3599            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3600              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3601              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3602              :         data1, data1_size,
    3603              :         &spdm_context->connection_info.peer_used_cert_chain[1].leaf_cert_public_key);
    3604              : #endif
    3605              : 
    3606            3 :     for (slot_id = 0; slot_id < 2; slot_id++) {
    3607            2 :         libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3608            2 :         status = libspdm_challenge(
    3609              :             spdm_context, NULL, slot_id,
    3610              :             SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3611              :             measurement_hash, NULL);
    3612            2 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3613              :     }
    3614            1 :     free(data);
    3615            1 :     free(data1);
    3616            1 : }
    3617              : 
    3618              : /**
    3619              :  * Test 24: Challenge using provisioned public key (slot_id 0xFF)
    3620              :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    3621              :  **/
    3622            1 : static void req_challenge_case24(void **state)
    3623              : {
    3624              :     libspdm_return_t status;
    3625              :     libspdm_test_context_t *spdm_test_context;
    3626              :     libspdm_context_t *spdm_context;
    3627              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3628              :     void *data;
    3629              :     size_t data_size;
    3630              : 
    3631            1 :     spdm_test_context = *state;
    3632            1 :     spdm_context = spdm_test_context->spdm_context;
    3633            1 :     spdm_test_context->case_id = 0x18;
    3634            1 :     spdm_context->connection_info.connection_state =
    3635              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3636            1 :     spdm_context->connection_info.capability.flags = 0;
    3637            1 :     spdm_context->connection_info.capability.flags |=
    3638              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3639            1 :     spdm_context->connection_info.capability.flags |=
    3640              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
    3641            1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
    3642            1 :     spdm_context->local_context.peer_public_key_provision = data;
    3643            1 :     spdm_context->local_context.peer_public_key_provision_size = data_size;
    3644              : 
    3645            1 :     libspdm_reset_message_a(spdm_context);
    3646            1 :     libspdm_reset_message_b(spdm_context);
    3647            1 :     libspdm_reset_message_c(spdm_context);
    3648            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3649              :         m_libspdm_use_hash_algo;
    3650            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3651              :         m_libspdm_use_asym_algo;
    3652              : 
    3653            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3654              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3655              : 
    3656            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3657            1 :     status = libspdm_challenge(
    3658              :         spdm_context, NULL, 0xFF,
    3659              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3660              :         measurement_hash, NULL);
    3661            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3662            1 :     free(data);
    3663            1 : }
    3664              : 
    3665              : /**
    3666              :  * Test 25: Error case, CHALLENGE_AUTH message contains opaque_length greater than the maximum allowed.
    3667              :  * Expected Behavior: get a LIBSPDM_STATUS_INVALID_MSG_FIELD return code.
    3668              :  **/
    3669            1 : static void req_challenge_case25(void **state) {
    3670              :     libspdm_return_t status;
    3671              :     libspdm_test_context_t    *spdm_test_context;
    3672              :     libspdm_context_t  *spdm_context;
    3673              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3674              :     void                 *data;
    3675              :     size_t data_size;
    3676              :     void                 *hash;
    3677              :     size_t hash_size;
    3678              : 
    3679            1 :     spdm_test_context = *state;
    3680            1 :     spdm_context = spdm_test_context->spdm_context;
    3681            1 :     spdm_test_context->case_id = 0x19;
    3682            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3683            1 :     spdm_context->connection_info.capability.flags = 0;
    3684            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3685            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    3686              :                                                      m_libspdm_use_asym_algo,
    3687              :                                                      &data, &data_size,
    3688              :                                                      &hash, &hash_size);
    3689            1 :     libspdm_reset_message_a(spdm_context);
    3690            1 :     libspdm_reset_message_b(spdm_context);
    3691            1 :     libspdm_reset_message_c(spdm_context);
    3692            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3693            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3694              : 
    3695            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3696              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3697              : 
    3698              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3699              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3700              :         data_size;
    3701              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3702              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3703              :                      data, data_size);
    3704              : #else
    3705            1 :     libspdm_hash_all(
    3706              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3707              :         data, data_size,
    3708            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3709            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3710            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3711            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3712              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3713              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3714              :         data, data_size,
    3715              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3716              : #endif
    3717              : 
    3718            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    3719            1 :     status = libspdm_challenge (spdm_context, NULL, 0,
    3720              :                                 SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3721              :                                 measurement_hash, NULL);
    3722            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    3723            1 :     free(data);
    3724            1 : }
    3725              : 
    3726              : /**
    3727              :  * Test 26: the requester is setup correctly to send a CHALLENGE message:
    3728              :  * - it has flags indicating that the previous messages were sent
    3729              :  * The received CHALLENGE_AUTH message correctly responds to the challenge, opaque
    3730              :  * data with bytes from the string "libspdm", and a signature on the sent nonce.
    3731              :  * Expected behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    3732              :  **/
    3733            1 : static void req_challenge_case26(void **state) {
    3734              :     libspdm_return_t status;
    3735              :     libspdm_test_context_t    *spdm_test_context;
    3736              :     libspdm_context_t  *spdm_context;
    3737              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3738              :     void                 *data;
    3739              :     size_t data_size;
    3740              :     void                 *hash;
    3741              :     size_t hash_size;
    3742              :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
    3743              :     size_t opaque_data_size;
    3744              : 
    3745            1 :     spdm_test_context = *state;
    3746            1 :     spdm_context = spdm_test_context->spdm_context;
    3747            1 :     spdm_test_context->case_id = 0x1A;
    3748            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3749            1 :     spdm_context->connection_info.capability.flags = 0;
    3750            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3751            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    3752              :                                                      m_libspdm_use_asym_algo,
    3753              :                                                      &data, &data_size,
    3754              :                                                      &hash, &hash_size);
    3755            1 :     libspdm_reset_message_a(spdm_context);
    3756            1 :     libspdm_reset_message_b(spdm_context);
    3757            1 :     libspdm_reset_message_c(spdm_context);
    3758            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3759            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3760              : 
    3761            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    3762              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3763              : 
    3764              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3765              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3766              :         data_size;
    3767              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3768              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3769              :                      data, data_size);
    3770              : #else
    3771            1 :     libspdm_hash_all(
    3772              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3773              :         data, data_size,
    3774            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3775            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3776            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3777            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3778              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3779              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3780              :         data, data_size,
    3781              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3782              : #endif
    3783            1 :     spdm_context->connection_info.algorithm.other_params_support =
    3784              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    3785            1 :     opaque_data_size = sizeof(opaque_data);
    3786              : 
    3787            1 :     libspdm_zero_mem (measurement_hash, sizeof(measurement_hash));
    3788            1 :     status = libspdm_challenge_ex (spdm_context, NULL, 0,
    3789              :                                    SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3790              :                                    measurement_hash, NULL, NULL, NULL, NULL,
    3791              :                                    opaque_data, &opaque_data_size);
    3792            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3793            1 :     assert_int_equal(opaque_data_size, m_libspdm_opaque_data_size);
    3794            1 :     assert_memory_equal(opaque_data, m_libspdm_opaque_data, opaque_data_size);
    3795            1 :     free(data);
    3796            1 : }
    3797              : 
    3798              : /**
    3799              :  * Test 27: Successful case , With the correct challenge context field
    3800              :  * Expected Behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    3801              :  **/
    3802            1 : static void req_challenge_case27(void **state)
    3803              : {
    3804              :     libspdm_return_t status;
    3805              :     libspdm_test_context_t *spdm_test_context;
    3806              :     libspdm_context_t *spdm_context;
    3807              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3808              :     void *data;
    3809              :     size_t data_size;
    3810              :     void *hash;
    3811              :     size_t hash_size;
    3812              : 
    3813            1 :     spdm_test_context = *state;
    3814            1 :     spdm_context = spdm_test_context->spdm_context;
    3815            1 :     spdm_test_context->case_id = 0x1B;
    3816            1 :     spdm_context->connection_info.connection_state =
    3817              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3818            1 :     spdm_context->connection_info.capability.flags = 0;
    3819            1 :     spdm_context->connection_info.capability.flags |=
    3820              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3821            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3822              :                                                          m_libspdm_use_asym_algo, &data,
    3823              :                                                          &data_size, &hash, &hash_size)) {
    3824            0 :         assert(false);
    3825              :     }
    3826            1 :     libspdm_reset_message_a(spdm_context);
    3827            1 :     libspdm_reset_message_b(spdm_context);
    3828            1 :     libspdm_reset_message_c(spdm_context);
    3829            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3830              :         m_libspdm_use_hash_algo;
    3831            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3832              :         m_libspdm_use_asym_algo;
    3833              : 
    3834            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    3835              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3836              : 
    3837              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3838              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3839              :         data_size;
    3840              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3841              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3842              :                      data, data_size);
    3843              : #else
    3844            1 :     libspdm_hash_all(
    3845              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3846              :         data, data_size,
    3847            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3848            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3849            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3850            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3851              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3852              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3853              :         data, data_size,
    3854              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3855              : #endif
    3856              : 
    3857            1 :     libspdm_set_mem(m_requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
    3858              : 
    3859            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3860              : 
    3861            1 :     status = libspdm_challenge_ex2(
    3862              :         spdm_context, NULL, 0, m_requester_context,
    3863              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3864              :         measurement_hash, NULL, NULL, NULL, NULL, NULL, NULL);
    3865            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3866              : 
    3867              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3868              :     assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
    3869              : #else
    3870            1 :     assert_null(spdm_context->transcript.digest_context_m1m2);
    3871              : #endif
    3872            1 :     free(data);
    3873            1 : }
    3874              : 
    3875              : /**
    3876              :  * Test 28: Error case , challenge context fields are inconsistent
    3877              :  * Expected Behavior: get a LIBSPDM_STATUS_INVALID_MSG_FIELD return code
    3878              :  **/
    3879            1 : static void req_challenge_case28(void **state)
    3880              : {
    3881              :     libspdm_return_t status;
    3882              :     libspdm_test_context_t *spdm_test_context;
    3883              :     libspdm_context_t *spdm_context;
    3884              :     uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
    3885              :     void *data;
    3886              :     size_t data_size;
    3887              :     void *hash;
    3888              :     size_t hash_size;
    3889              : 
    3890            1 :     spdm_test_context = *state;
    3891            1 :     spdm_context = spdm_test_context->spdm_context;
    3892            1 :     spdm_test_context->case_id = 0x1C;
    3893            1 :     spdm_context->connection_info.connection_state =
    3894              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    3895            1 :     spdm_context->connection_info.capability.flags = 0;
    3896            1 :     spdm_context->connection_info.capability.flags |=
    3897              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
    3898            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3899              :                                                          m_libspdm_use_asym_algo, &data,
    3900              :                                                          &data_size, &hash, &hash_size)) {
    3901            0 :         assert(false);
    3902              :     }
    3903            1 :     libspdm_reset_message_a(spdm_context);
    3904            1 :     libspdm_reset_message_b(spdm_context);
    3905            1 :     libspdm_reset_message_c(spdm_context);
    3906            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3907              :         m_libspdm_use_hash_algo;
    3908            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3909              :         m_libspdm_use_asym_algo;
    3910              : 
    3911            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    3912              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3913              : 
    3914              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3915              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3916              :         data_size;
    3917              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3918              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3919              :                      data, data_size);
    3920              : #else
    3921            1 :     libspdm_hash_all(
    3922              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3923              :         data, data_size,
    3924            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3925            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3926            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3927            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3928              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3929              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3930              :         data, data_size,
    3931              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3932              : #endif
    3933              : 
    3934            1 :     libspdm_set_mem(m_requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
    3935              : 
    3936            1 :     libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
    3937              : 
    3938            1 :     status = libspdm_challenge_ex2(
    3939              :         spdm_context, NULL, 0, m_requester_context,
    3940              :         SPDM_CHALLENGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
    3941              :         measurement_hash, NULL, NULL, NULL, NULL, NULL, NULL);
    3942            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    3943              : 
    3944            1 :     free(data);
    3945            1 : }
    3946              : 
    3947            1 : int libspdm_req_challenge_test(void)
    3948              : {
    3949            1 :     const struct CMUnitTest test_cases[] = {
    3950              :         /* SendRequest failed*/
    3951              :         cmocka_unit_test(req_challenge_case1),
    3952              :         /* Successful response*/
    3953              :         cmocka_unit_test(req_challenge_case2),
    3954              :         /* connection_state check failed*/
    3955              :         cmocka_unit_test(req_challenge_case3),
    3956              :         /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
    3957              :         cmocka_unit_test(req_challenge_case4),
    3958              :         /* Always SPDM_ERROR_CODE_BUSY*/
    3959              :         cmocka_unit_test(req_challenge_case5),
    3960              :         /* SPDM_ERROR_CODE_BUSY + Successful response*/
    3961              :         cmocka_unit_test(req_challenge_case6),
    3962              :         /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
    3963              :         cmocka_unit_test(req_challenge_case7),
    3964              :         /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
    3965              :         cmocka_unit_test(req_challenge_case8),
    3966              :         /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
    3967              :         cmocka_unit_test(req_challenge_case9),
    3968              :         /* SpdmCmdReceiveState check failed*/
    3969              :         cmocka_unit_test(req_challenge_case10),
    3970              :         /* Successful response + device error*/
    3971              :         cmocka_unit_test(req_challenge_case11),
    3972              :         cmocka_unit_test(req_challenge_case12),
    3973              :         cmocka_unit_test(req_challenge_case13),
    3974              :         cmocka_unit_test(req_challenge_case14),
    3975              :         /* Invalid parameter*/
    3976              :         cmocka_unit_test(req_challenge_case15),
    3977              :         /* Successful response*/
    3978              :         cmocka_unit_test(req_challenge_case16),
    3979              :         /* Signature check failed*/
    3980              :         cmocka_unit_test(req_challenge_case17),
    3981              :         /* Successful response*/
    3982              :         cmocka_unit_test(req_challenge_case18),
    3983              :         cmocka_unit_test(req_challenge_case19),
    3984              :         /* Unexpected errors*/
    3985              :         cmocka_unit_test(req_challenge_case20),
    3986              :         cmocka_unit_test(req_challenge_case21),
    3987              :         /* Buffer verification*/
    3988              :         cmocka_unit_test(req_challenge_case22),
    3989              :         /* Challeng differenr slot with GetCert*/
    3990              :         cmocka_unit_test(req_challenge_case23),
    3991              :         /* Challeng using provisioned public key (slot_id 0xFF) */
    3992              :         cmocka_unit_test(req_challenge_case24),
    3993              :         /* opaque_length greater than the maximum allowed */
    3994              :         cmocka_unit_test(req_challenge_case25),
    3995              :         /* the OpaqueDataFmt1 bit is selected in OtherParamsSelection of ALGORITHMS*/
    3996              :         cmocka_unit_test(req_challenge_case26),
    3997              :         /* Successful response, With the correct challenge context field*/
    3998              :         cmocka_unit_test(req_challenge_case27),
    3999              :         /* Error response: challenge context fields are inconsistent*/
    4000              :         cmocka_unit_test(req_challenge_case28),
    4001              :     };
    4002              : 
    4003            1 :     libspdm_test_context_t test_context = {
    4004              :         LIBSPDM_TEST_CONTEXT_VERSION,
    4005              :         true,
    4006              :         send_message,
    4007              :         receive_message,
    4008              :     };
    4009              : 
    4010            1 :     libspdm_setup_test_context(&test_context);
    4011              : 
    4012            1 :     return cmocka_run_group_tests(test_cases,
    4013              :                                   libspdm_unit_test_group_setup,
    4014              :                                   libspdm_unit_test_group_teardown);
    4015              : }
    4016              : 
    4017              : #endif /* LIBSPDM_SEND_CHALLENGE_SUPPORT */
        

Generated by: LCOV version 2.0-1