LCOV - code coverage report
Current view: top level - unit_test/test_spdm_requester - challenge.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 89.2 % 1635 1458
Test Date: 2025-06-29 08:09:00 Functions: 96.8 % 31 30

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

Generated by: LCOV version 2.0-1