LCOV - code coverage report
Current view: top level - unit_test/test_spdm_requester - get_measurements.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.1 % 2750 2587
Test Date: 2025-10-12 08:10:56 Functions: 100.0 % 45 45

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2021-2025 DMTF. All rights reserved.
       4              :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
       5              :  **/
       6              : 
       7              : #include "spdm_unit_test.h"
       8              : #include "internal/libspdm_requester_lib.h"
       9              : #include "internal/libspdm_secured_message_lib.h"
      10              : 
      11              : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
      12              : 
      13              : #define LIBSPDM_ALTERNATIVE_DEFAULT_SLOT_ID 2
      14              : #define LIBSPDM_LARGE_MEASUREMENT_SIZE ((1 << 24) - 1)
      15              : 
      16              : static size_t m_libspdm_local_buffer_size;
      17              : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_L1L2_BUFFER_SIZE];
      18              : static uint8_t m_libspdm_msg_log_buffer[LIBSPDM_MAX_MESSAGE_L1L2_BUFFER_SIZE * 2];
      19              : 
      20              : static size_t m_libspdm_opaque_data_size;
      21              : static uint8_t m_libspdm_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
      22              : 
      23              : static uint8_t m_requester_context[SPDM_REQ_CONTEXT_SIZE];
      24              : 
      25          160 : static size_t libspdm_test_get_measurement_request_size(const void *spdm_context,
      26              :                                                         const void *buffer,
      27              :                                                         size_t buffer_size)
      28              : {
      29              :     const spdm_get_measurements_request_t *spdm_request;
      30              :     size_t message_size;
      31              : 
      32          160 :     spdm_request = buffer;
      33          160 :     message_size = sizeof(spdm_message_header_t);
      34          160 :     if (buffer_size < message_size) {
      35            0 :         return buffer_size;
      36              :     }
      37              : 
      38          160 :     if (spdm_request->header.request_response_code !=
      39              :         SPDM_GET_MEASUREMENTS) {
      40            2 :         return buffer_size;
      41              :     }
      42              : 
      43          158 :     if ((spdm_request->header.param1 &
      44              :          SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0) {
      45           42 :         if (spdm_request->header.spdm_version >=
      46              :             SPDM_MESSAGE_VERSION_11) {
      47           42 :             if (buffer_size <
      48              :                 sizeof(spdm_get_measurements_request_t)) {
      49            0 :                 return buffer_size;
      50              :             }
      51           42 :             message_size = sizeof(spdm_get_measurements_request_t);
      52              :         } else {
      53            0 :             if (buffer_size <
      54              :                 sizeof(spdm_get_measurements_request_t) -
      55              :                 sizeof(spdm_request->slot_id_param)) {
      56            0 :                 return buffer_size;
      57              :             }
      58            0 :             message_size = sizeof(spdm_get_measurements_request_t) -
      59              :                            sizeof(spdm_request->slot_id_param);
      60              :         }
      61              :     } else {
      62              :         /* already checked before if buffer_size < sizeof(spdm_message_header_t)*/
      63          116 :         message_size = sizeof(spdm_message_header_t);
      64              :     }
      65              : 
      66              :     /* Good message, return actual size*/
      67          158 :     return message_size;
      68              : }
      69              : 
      70          162 : static libspdm_return_t send_message(
      71              :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
      72              : {
      73              :     libspdm_test_context_t *spdm_test_context;
      74              :     size_t header_size;
      75              :     size_t message_size;
      76              :     uint32_t *session_id;
      77              :     libspdm_session_info_t *session_info;
      78              :     bool is_app_message;
      79              :     uint8_t *app_message;
      80              :     size_t app_message_size;
      81              :     uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
      82              : 
      83          162 :     memcpy(message_buffer, request, request_size);
      84              : 
      85          162 :     spdm_test_context = libspdm_get_test_context();
      86          162 :     header_size = sizeof(libspdm_test_message_header_t);
      87          162 :     switch (spdm_test_context->case_id) {
      88            1 :     case 0x1:
      89            1 :         return LIBSPDM_STATUS_SEND_FAIL;
      90            1 :     case 0x2:
      91            1 :         m_libspdm_local_buffer_size = 0;
      92            1 :         message_size = libspdm_test_get_measurement_request_size(
      93              :             spdm_context, (const uint8_t *)request + header_size,
      94              :             request_size - header_size);
      95            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
      96              :                          (const uint8_t *)request + header_size, message_size);
      97            1 :         m_libspdm_local_buffer_size += message_size;
      98            1 :         return LIBSPDM_STATUS_SUCCESS;
      99            1 :     case 0x3:
     100            1 :         m_libspdm_local_buffer_size = 0;
     101            1 :         message_size = libspdm_test_get_measurement_request_size(
     102              :             spdm_context, (const uint8_t *)request + header_size,
     103              :             request_size - header_size);
     104            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     105              :                          (const uint8_t *)request + header_size, message_size);
     106            1 :         m_libspdm_local_buffer_size += message_size;
     107            1 :         return LIBSPDM_STATUS_SUCCESS;
     108            1 :     case 0x4:
     109            1 :         m_libspdm_local_buffer_size = 0;
     110            1 :         message_size = libspdm_test_get_measurement_request_size(
     111              :             spdm_context, (const uint8_t *)request + header_size,
     112              :             request_size - header_size);
     113            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     114              :                          (const uint8_t *)request + header_size, message_size);
     115            1 :         m_libspdm_local_buffer_size += message_size;
     116            1 :         return LIBSPDM_STATUS_SUCCESS;
     117            1 :     case 0x5:
     118            1 :         m_libspdm_local_buffer_size = 0;
     119            1 :         message_size = libspdm_test_get_measurement_request_size(
     120              :             spdm_context, (const uint8_t *)request + header_size,
     121              :             request_size - header_size);
     122            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     123              :                          (const uint8_t *)request + header_size, message_size);
     124            1 :         m_libspdm_local_buffer_size += message_size;
     125            1 :         return LIBSPDM_STATUS_SUCCESS;
     126            2 :     case 0x6:
     127            2 :         m_libspdm_local_buffer_size = 0;
     128            2 :         message_size = libspdm_test_get_measurement_request_size(
     129              :             spdm_context, (const uint8_t *)request + header_size,
     130              :             request_size - header_size);
     131            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     132              :                          (const uint8_t *)request + header_size, message_size);
     133            2 :         m_libspdm_local_buffer_size += message_size;
     134            2 :         return LIBSPDM_STATUS_SUCCESS;
     135            1 :     case 0x7:
     136            1 :         m_libspdm_local_buffer_size = 0;
     137            1 :         message_size = libspdm_test_get_measurement_request_size(
     138              :             spdm_context, (const uint8_t *)request + header_size,
     139              :             request_size - header_size);
     140            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     141              :                          (const uint8_t *)request + header_size, message_size);
     142            1 :         m_libspdm_local_buffer_size += message_size;
     143            1 :         return LIBSPDM_STATUS_SUCCESS;
     144            2 :     case 0x8:
     145            2 :         m_libspdm_local_buffer_size = 0;
     146            2 :         message_size = libspdm_test_get_measurement_request_size(
     147              :             spdm_context, (const uint8_t *)request + header_size,
     148              :             request_size - header_size);
     149            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     150              :                          (const uint8_t *)request + header_size, message_size);
     151            2 :         m_libspdm_local_buffer_size += message_size;
     152            2 :         return LIBSPDM_STATUS_SUCCESS;
     153            2 :     case 0x9: {
     154              :         static size_t sub_index = 0;
     155            2 :         if (sub_index == 0) {
     156            1 :             m_libspdm_local_buffer_size = 0;
     157            1 :             message_size = libspdm_test_get_measurement_request_size(
     158              :                 spdm_context, (const uint8_t *)request + header_size,
     159              :                 request_size - header_size);
     160            1 :             libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     161              :                              (const uint8_t *)request + header_size,
     162              :                              message_size);
     163            1 :             m_libspdm_local_buffer_size += message_size;
     164            1 :             sub_index++;
     165              :         }
     166              :     }
     167            2 :         return LIBSPDM_STATUS_SUCCESS;
     168            1 :     case 0xA:
     169            1 :         m_libspdm_local_buffer_size = 0;
     170            1 :         message_size = libspdm_test_get_measurement_request_size(
     171              :             spdm_context, (const uint8_t *)request + header_size,
     172              :             request_size - header_size);
     173            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     174              :                          (const uint8_t *)request + header_size, message_size);
     175            1 :         m_libspdm_local_buffer_size += message_size;
     176            1 :         return LIBSPDM_STATUS_SUCCESS;
     177            1 :     case 0xB:
     178            1 :         m_libspdm_local_buffer_size = 0;
     179            1 :         message_size = libspdm_test_get_measurement_request_size(
     180              :             spdm_context, (const uint8_t *)request + header_size,
     181              :             request_size - header_size);
     182            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     183              :                          (const uint8_t *)request + header_size, message_size);
     184            1 :         m_libspdm_local_buffer_size += message_size;
     185            1 :         return LIBSPDM_STATUS_SUCCESS;
     186            1 :     case 0xC:
     187            1 :         m_libspdm_local_buffer_size = 0;
     188            1 :         message_size = libspdm_test_get_measurement_request_size(
     189              :             spdm_context, (const uint8_t *)request + header_size,
     190              :             request_size - header_size);
     191            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     192              :                          (const uint8_t *)request + header_size, message_size);
     193            1 :         m_libspdm_local_buffer_size += message_size;
     194            1 :         return LIBSPDM_STATUS_SUCCESS;
     195            1 :     case 0xD:
     196            1 :         m_libspdm_local_buffer_size = 0;
     197            1 :         message_size = libspdm_test_get_measurement_request_size(
     198              :             spdm_context, (const uint8_t *)request + header_size,
     199              :             request_size - header_size);
     200            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     201              :                          (const uint8_t *)request + header_size, message_size);
     202            1 :         m_libspdm_local_buffer_size += message_size;
     203            1 :         return LIBSPDM_STATUS_SUCCESS;
     204            1 :     case 0xE:
     205            1 :         m_libspdm_local_buffer_size = 0;
     206            1 :         message_size = libspdm_test_get_measurement_request_size(
     207              :             spdm_context, (const uint8_t *)request + header_size,
     208              :             request_size - header_size);
     209            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     210              :                          (const uint8_t *)request + header_size, message_size);
     211            1 :         m_libspdm_local_buffer_size += message_size;
     212            1 :         return LIBSPDM_STATUS_SUCCESS;
     213            1 :     case 0xF:
     214            1 :         m_libspdm_local_buffer_size = 0;
     215            1 :         message_size = libspdm_test_get_measurement_request_size(
     216              :             spdm_context, (const uint8_t *)request + header_size,
     217              :             request_size - header_size);
     218            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     219              :                          (const uint8_t *)request + header_size, message_size);
     220            1 :         m_libspdm_local_buffer_size += message_size;
     221            1 :         return LIBSPDM_STATUS_SUCCESS;
     222            4 :     case 0x10:
     223            4 :         m_libspdm_local_buffer_size = 0;
     224            4 :         message_size = libspdm_test_get_measurement_request_size(
     225              :             spdm_context, (const uint8_t *)request + header_size,
     226              :             request_size - header_size);
     227            4 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     228              :                          (const uint8_t *)request + header_size, message_size);
     229            4 :         m_libspdm_local_buffer_size += message_size;
     230            4 :         return LIBSPDM_STATUS_SUCCESS;
     231            3 :     case 0x11:
     232            3 :         m_libspdm_local_buffer_size = 0;
     233            3 :         message_size = libspdm_test_get_measurement_request_size(
     234              :             spdm_context, (const uint8_t *)request + header_size,
     235              :             request_size - header_size);
     236            3 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     237              :                          (const uint8_t *)request + header_size, message_size);
     238            3 :         m_libspdm_local_buffer_size += message_size;
     239            3 :         return LIBSPDM_STATUS_SUCCESS;
     240            0 :     case 0x12:
     241            0 :         m_libspdm_local_buffer_size = 0;
     242            0 :         message_size = libspdm_test_get_measurement_request_size(
     243              :             spdm_context, (const uint8_t *)request + header_size,
     244              :             request_size - header_size);
     245            0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     246              :                          (const uint8_t *)request + header_size, message_size);
     247            0 :         m_libspdm_local_buffer_size += message_size;
     248            0 :         return LIBSPDM_STATUS_SUCCESS;
     249            1 :     case 0x13:
     250            1 :         m_libspdm_local_buffer_size = 0;
     251            1 :         message_size = libspdm_test_get_measurement_request_size(
     252              :             spdm_context, (const uint8_t *)request + header_size,
     253              :             request_size - header_size);
     254            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     255              :                          (const uint8_t *)request + header_size, message_size);
     256            1 :         m_libspdm_local_buffer_size += message_size;
     257            1 :         return LIBSPDM_STATUS_SUCCESS;
     258            1 :     case 0x14:
     259            1 :         m_libspdm_local_buffer_size = 0;
     260            1 :         message_size = libspdm_test_get_measurement_request_size(
     261              :             spdm_context, (const uint8_t *)request + header_size,
     262              :             request_size - header_size);
     263            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     264              :                          (const uint8_t *)request + header_size, message_size);
     265            1 :         m_libspdm_local_buffer_size += message_size;
     266            1 :         return LIBSPDM_STATUS_SUCCESS;
     267            1 :     case 0x15:
     268            1 :         m_libspdm_local_buffer_size = 0;
     269            1 :         message_size = libspdm_test_get_measurement_request_size(
     270              :             spdm_context, (const uint8_t *)request + header_size,
     271              :             request_size - header_size);
     272            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     273              :                          (const uint8_t *)request + header_size, message_size);
     274            1 :         m_libspdm_local_buffer_size += message_size;
     275            1 :         return LIBSPDM_STATUS_SUCCESS;
     276          100 :     case 0x16:
     277          100 :         m_libspdm_local_buffer_size = 0;
     278          100 :         message_size = libspdm_test_get_measurement_request_size(
     279              :             spdm_context, (const uint8_t *)request + header_size,
     280              :             request_size - header_size);
     281          100 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     282              :                          (const uint8_t *)request + header_size, message_size);
     283          100 :         m_libspdm_local_buffer_size += message_size;
     284          100 :         return LIBSPDM_STATUS_SUCCESS;
     285            1 :     case 0x17:
     286            1 :         m_libspdm_local_buffer_size = 0;
     287            1 :         message_size = libspdm_test_get_measurement_request_size(
     288              :             spdm_context, (const uint8_t *)request + header_size,
     289              :             request_size - header_size);
     290            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     291              :                          (const uint8_t *)request + header_size, message_size);
     292            1 :         m_libspdm_local_buffer_size += message_size;
     293            1 :         return LIBSPDM_STATUS_SUCCESS;
     294            1 :     case 0x18:
     295            1 :         m_libspdm_local_buffer_size = 0;
     296            1 :         message_size = libspdm_test_get_measurement_request_size(
     297              :             spdm_context, (const uint8_t *)request + header_size,
     298              :             request_size - header_size);
     299            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     300              :                          (const uint8_t *)request + header_size, message_size);
     301            1 :         m_libspdm_local_buffer_size += message_size;
     302            1 :         return LIBSPDM_STATUS_SUCCESS;
     303            1 :     case 0x19:
     304            1 :         m_libspdm_local_buffer_size = 0;
     305            1 :         message_size = libspdm_test_get_measurement_request_size(
     306              :             spdm_context, (const uint8_t *)request + header_size,
     307              :             request_size - header_size);
     308            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     309              :                          (const uint8_t *)request + header_size, message_size);
     310            1 :         m_libspdm_local_buffer_size += message_size;
     311            1 :         return LIBSPDM_STATUS_SUCCESS;
     312            1 :     case 0x1A:
     313            1 :         m_libspdm_local_buffer_size = 0;
     314            1 :         message_size = libspdm_test_get_measurement_request_size(
     315              :             spdm_context, (const uint8_t *)request + header_size,
     316              :             request_size - header_size);
     317            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     318              :                          (const uint8_t *)request + header_size, message_size);
     319            1 :         m_libspdm_local_buffer_size += message_size;
     320            1 :         return LIBSPDM_STATUS_SUCCESS;
     321            1 :     case 0x1B:
     322            1 :         m_libspdm_local_buffer_size = 0;
     323            1 :         message_size = libspdm_test_get_measurement_request_size(
     324              :             spdm_context, (const uint8_t *)request + header_size,
     325              :             request_size - header_size);
     326            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     327              :                          (const uint8_t *)request + header_size, message_size);
     328            1 :         m_libspdm_local_buffer_size += message_size;
     329            1 :         return LIBSPDM_STATUS_SUCCESS;
     330            1 :     case 0x1C:
     331            1 :         m_libspdm_local_buffer_size = 0;
     332            1 :         message_size = libspdm_test_get_measurement_request_size(
     333              :             spdm_context, (const uint8_t *)request + header_size,
     334              :             request_size - header_size);
     335            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     336              :                          (const uint8_t *)request + header_size, message_size);
     337            1 :         m_libspdm_local_buffer_size += message_size;
     338            1 :         return LIBSPDM_STATUS_SUCCESS;
     339            1 :     case 0x1D:
     340            1 :         m_libspdm_local_buffer_size = 0;
     341            1 :         message_size = libspdm_test_get_measurement_request_size(
     342              :             spdm_context, (const uint8_t *)request + header_size,
     343              :             request_size - header_size);
     344            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     345              :                          (const uint8_t *)request + header_size, message_size);
     346            1 :         m_libspdm_local_buffer_size += message_size;
     347            1 :         return LIBSPDM_STATUS_SUCCESS;
     348            0 :     case 0x1E:
     349            0 :         m_libspdm_local_buffer_size = 0;
     350            0 :         message_size = libspdm_test_get_measurement_request_size(
     351              :             spdm_context, (const uint8_t *)request + header_size,
     352              :             request_size - header_size);
     353            0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     354              :                          (const uint8_t *)request + header_size, message_size);
     355            0 :         m_libspdm_local_buffer_size += message_size;
     356            0 :         return LIBSPDM_STATUS_SUCCESS;
     357            0 :     case 0x1F:
     358            0 :         m_libspdm_local_buffer_size = 0;
     359            0 :         message_size = libspdm_test_get_measurement_request_size(
     360              :             spdm_context, (const uint8_t *)request + header_size,
     361              :             request_size - header_size);
     362            0 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     363              :                          (const uint8_t *)request + header_size, message_size);
     364            0 :         m_libspdm_local_buffer_size += message_size;
     365            0 :         return LIBSPDM_STATUS_SUCCESS;
     366            1 :     case 0x20:
     367            1 :         m_libspdm_local_buffer_size = 0;
     368            1 :         message_size = libspdm_test_get_measurement_request_size(
     369              :             spdm_context, (const uint8_t *)request + header_size,
     370              :             request_size - header_size);
     371            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     372              :                          (const uint8_t *)request + header_size, message_size);
     373            1 :         m_libspdm_local_buffer_size += message_size;
     374            1 :         return LIBSPDM_STATUS_SUCCESS;
     375           18 :     case 0x21:
     376           18 :         m_libspdm_local_buffer_size = 0;
     377           18 :         message_size = libspdm_test_get_measurement_request_size(
     378              :             spdm_context, (const uint8_t *)request + header_size,
     379              :             request_size - header_size);
     380           18 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     381              :                          (const uint8_t *)request + header_size, message_size);
     382           18 :         m_libspdm_local_buffer_size += message_size;
     383           18 :         return LIBSPDM_STATUS_SUCCESS;
     384            1 :     case 0x22:
     385            1 :         m_libspdm_local_buffer_size = 0;
     386            1 :         session_id = NULL;
     387            1 :         session_info = libspdm_get_session_info_via_session_id(
     388              :             spdm_context, 0xFFFFFFFF);
     389            1 :         message_size = libspdm_test_get_measurement_request_size(
     390              :             spdm_context, (const uint8_t *)request + header_size,
     391              :             request_size - header_size);
     392            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Request (0x%zx):\n",
     393              :                        request_size));
     394            1 :         libspdm_dump_hex(request, request_size);
     395            1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&app_message, &app_message_size);
     396            1 :         libspdm_transport_test_decode_message(
     397              :             spdm_context, &session_id, &is_app_message,
     398              :             false, request_size, message_buffer,
     399              :             &app_message_size, (void **)&app_message);
     400              :         ((libspdm_secured_message_context_t
     401            1 :           *)(session_info->secured_message_context))
     402            1 :         ->application_secret.response_data_sequence_number--;
     403            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     404              :                          app_message, app_message_size);
     405            1 :         m_libspdm_local_buffer_size += app_message_size;
     406            1 :         return LIBSPDM_STATUS_SUCCESS;
     407            1 :     case 0x23:
     408              :         /* m_libspdm_local_buffer_size is set by case35 and already contains the arbitrary fill
     409              :          * data. */
     410            1 :         message_size = libspdm_test_get_measurement_request_size(
     411              :             spdm_context, (const uint8_t *)request + header_size,
     412              :             request_size - header_size);
     413            1 :         libspdm_copy_mem(m_libspdm_local_buffer + m_libspdm_local_buffer_size,
     414              :                          sizeof(m_libspdm_local_buffer),
     415              :                          (const uint8_t *)request + header_size, message_size);
     416            1 :         m_libspdm_local_buffer_size += message_size;
     417            1 :         return LIBSPDM_STATUS_SUCCESS;
     418            1 :     case 0x24:
     419            1 :         m_libspdm_local_buffer_size = 0;
     420            1 :         message_size = libspdm_test_get_measurement_request_size(
     421              :             spdm_context, (const uint8_t *)request + header_size,
     422              :             request_size - header_size);
     423            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     424              :                          (const uint8_t *)request + header_size, message_size);
     425            1 :         m_libspdm_local_buffer_size += message_size;
     426            1 :         return LIBSPDM_STATUS_SUCCESS;
     427            1 :     case 0x25:
     428            1 :         m_libspdm_local_buffer_size = 0;
     429            1 :         message_size = libspdm_test_get_measurement_request_size(
     430              :             spdm_context, (const uint8_t *)request + header_size,
     431              :             request_size - header_size);
     432            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     433              :                          (const uint8_t *)request + header_size, message_size);
     434            1 :         m_libspdm_local_buffer_size += message_size;
     435            1 :         return LIBSPDM_STATUS_SUCCESS;
     436            1 :     case 0x26:
     437            1 :         m_libspdm_local_buffer_size = 0;
     438            1 :         message_size = libspdm_test_get_measurement_request_size(
     439              :             spdm_context, (const uint8_t *)request + header_size,
     440              :             request_size - header_size);
     441            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     442              :                          (const uint8_t *)request + header_size, message_size);
     443            1 :         m_libspdm_local_buffer_size += message_size;
     444            1 :         return LIBSPDM_STATUS_SUCCESS;
     445            1 :     case 0x27:
     446            1 :         m_libspdm_local_buffer_size = 0;
     447            1 :         message_size = libspdm_test_get_measurement_request_size(
     448              :             spdm_context, (const uint8_t *)request + header_size,
     449              :             request_size - header_size);
     450            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     451              :                          (const uint8_t *)request + header_size, message_size);
     452            1 :         m_libspdm_local_buffer_size += message_size;
     453            1 :         return LIBSPDM_STATUS_SUCCESS;
     454            2 :     case 0x28:
     455              :     case 0x29:
     456            2 :         m_libspdm_local_buffer_size = 0;
     457            2 :         message_size = libspdm_test_get_measurement_request_size(
     458              :             spdm_context, (const uint8_t *)request + header_size,
     459              :             request_size - header_size);
     460            2 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
     461              :                          (const uint8_t *)request + header_size, message_size);
     462            2 :         m_libspdm_local_buffer_size += message_size;
     463            2 :         return LIBSPDM_STATUS_SUCCESS;
     464            0 :     default:
     465            0 :         return LIBSPDM_STATUS_SEND_FAIL;
     466              :     }
     467              : }
     468              : 
     469          161 : static libspdm_return_t receive_message(
     470              :     void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
     471              : {
     472              :     libspdm_test_context_t *spdm_test_context;
     473              :     libspdm_return_t status;
     474              : 
     475          161 :     spdm_test_context = libspdm_get_test_context();
     476          161 :     switch (spdm_test_context->case_id) {
     477            0 :     case 0x1:
     478            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
     479              : 
     480            1 :     case 0x2: {
     481              :         spdm_measurements_response_t *spdm_response;
     482              :         uint8_t *ptr;
     483              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     484              :         size_t sig_size;
     485              :         size_t measurment_sig_size;
     486              :         spdm_measurement_block_dmtf_t *measurment_block;
     487              :         size_t spdm_response_size;
     488              :         size_t transport_header_size;
     489              : 
     490              :         ((libspdm_context_t *)spdm_context)
     491            1 :         ->connection_info.algorithm.base_asym_algo =
     492              :             m_libspdm_use_asym_algo;
     493              :         ((libspdm_context_t *)spdm_context)
     494            1 :         ->connection_info.algorithm.base_hash_algo =
     495              :             m_libspdm_use_hash_algo;
     496              :         ((libspdm_context_t *)spdm_context)
     497            1 :         ->connection_info.algorithm.measurement_hash_algo =
     498              :             m_libspdm_use_measurement_hash_algo;
     499            1 :         measurment_sig_size =
     500              :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
     501            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     502            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
     503              :                              sizeof(spdm_measurement_block_dmtf_t) +
     504            1 :                              libspdm_get_measurement_hash_size(
     505            1 :             m_libspdm_use_measurement_hash_algo) +
     506              :                              measurment_sig_size;
     507            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     508            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     509              : 
     510            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     511            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
     512            1 :         spdm_response->header.param1 = 0;
     513            1 :         spdm_response->header.param2 = 0;
     514            1 :         spdm_response->number_of_blocks = 1;
     515            1 :         libspdm_write_uint24(
     516            1 :             spdm_response->measurement_record_length,
     517              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
     518            1 :                        libspdm_get_measurement_hash_size(
     519              :                            m_libspdm_use_measurement_hash_algo)));
     520            1 :         measurment_block = (void *)(spdm_response + 1);
     521            1 :         libspdm_set_mem(measurment_block,
     522              :                         sizeof(spdm_measurement_block_dmtf_t) +
     523            1 :                         libspdm_get_measurement_hash_size(
     524              :                             m_libspdm_use_measurement_hash_algo),
     525              :                         1);
     526              :         measurment_block->measurement_block_common_header
     527            1 :         .measurement_specification =
     528              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
     529              :         measurment_block->measurement_block_common_header
     530            1 :         .measurement_size =
     531            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
     532            1 :                        libspdm_get_measurement_hash_size(
     533              :                            m_libspdm_use_measurement_hash_algo));
     534            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
     535              :                        measurment_sig_size);
     536            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     537            1 :         ptr += SPDM_NONCE_SIZE;
     538            1 :         *(uint16_t *)ptr = 0;
     539            1 :         ptr += sizeof(uint16_t);
     540            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     541              :                          sizeof(m_libspdm_local_buffer)
     542            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     543              :                             m_libspdm_local_buffer),
     544            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
     545            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
     546            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     547              :                        m_libspdm_local_buffer_size));
     548            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     549            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     550              :                          m_libspdm_local_buffer_size, hash_data);
     551            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
     552              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
     553            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     554            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     555            1 :         libspdm_responder_data_sign(
     556              :             spdm_context,
     557            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     558              :                 SPDM_MEASUREMENTS,
     559              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     560              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
     561              :                 ptr, &sig_size);
     562            1 :         ptr += sig_size;
     563              : 
     564            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     565              :                                               false, spdm_response_size,
     566              :                                               spdm_response, response_size,
     567              :                                               response);
     568              :     }
     569            1 :         return LIBSPDM_STATUS_SUCCESS;
     570              : 
     571            1 :     case 0x3: {
     572              :         spdm_measurements_response_t *spdm_response;
     573              :         uint8_t *ptr;
     574              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     575              :         size_t sig_size;
     576              :         size_t measurment_sig_size;
     577              :         spdm_measurement_block_dmtf_t *measurment_block;
     578              :         size_t spdm_response_size;
     579              :         size_t transport_header_size;
     580              : 
     581              :         ((libspdm_context_t *)spdm_context)
     582            1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     583              :         ((libspdm_context_t *)spdm_context)
     584            1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     585              :         ((libspdm_context_t *)spdm_context)
     586            1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
     587            1 :         measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + strlen("libspdm") +
     588            1 :                               libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     589            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
     590              :                              sizeof(spdm_measurement_block_dmtf_t) +
     591            1 :                              libspdm_get_measurement_hash_size(
     592            1 :             m_libspdm_use_measurement_hash_algo) + measurment_sig_size;
     593            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     594            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     595              : 
     596            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     597            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
     598            1 :         spdm_response->header.param1 = 0;
     599            1 :         spdm_response->header.param2 = 0;
     600            1 :         spdm_response->number_of_blocks = 1;
     601            1 :         libspdm_write_uint24(
     602            1 :             spdm_response->measurement_record_length,
     603              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
     604            1 :                        libspdm_get_measurement_hash_size(
     605              :                            m_libspdm_use_measurement_hash_algo)));
     606            1 :         measurment_block = (void *)(spdm_response + 1);
     607            1 :         libspdm_set_mem(measurment_block,
     608              :                         sizeof(spdm_measurement_block_dmtf_t) +
     609            1 :                         libspdm_get_measurement_hash_size(
     610              :                             m_libspdm_use_measurement_hash_algo), 1);
     611              :         measurment_block->measurement_block_common_header
     612            1 :         .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
     613            1 :         measurment_block->measurement_block_common_header.measurement_size =
     614            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
     615            1 :                        libspdm_get_measurement_hash_size(
     616              :                            m_libspdm_use_measurement_hash_algo));
     617            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
     618            1 :         libspdm_set_mem(ptr, SPDM_NONCE_SIZE, 0x12);
     619            1 :         ptr += SPDM_NONCE_SIZE;
     620              : 
     621            1 :         *(uint16_t *)ptr = (uint16_t)strlen("libspdm");
     622            1 :         ptr += sizeof(uint16_t);
     623            1 :         libspdm_copy_mem(ptr, strlen("libspdm"), "libspdm", strlen("libspdm"));
     624              : 
     625            1 :         ptr += strlen("libspdm");
     626              : 
     627            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     628              :                          sizeof(m_libspdm_local_buffer)
     629            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     630              :                             m_libspdm_local_buffer),
     631            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
     632            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
     633            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     634              :                        m_libspdm_local_buffer_size));
     635            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     636            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     637              :                          m_libspdm_local_buffer_size, hash_data);
     638            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
     639              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
     640            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     641            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     642            1 :         libspdm_responder_data_sign(
     643              :             spdm_context,
     644            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     645              :                 SPDM_MEASUREMENTS,
     646              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
     647              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
     648              :                 ptr, &sig_size);
     649            1 :         ptr += sig_size;
     650              : 
     651            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     652              :                                               false, spdm_response_size,
     653              :                                               spdm_response, response_size,
     654              :                                               response);
     655              :     }
     656            1 :         return LIBSPDM_STATUS_SUCCESS;
     657              : 
     658            1 :     case 0x4: {
     659              :         spdm_error_response_t *spdm_response;
     660              :         size_t spdm_response_size;
     661              :         size_t transport_header_size;
     662              : 
     663            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     664            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     665            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     666              : 
     667            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     668            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     669            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
     670            1 :         spdm_response->header.param2 = 0;
     671              : 
     672            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     673              :                                               false, spdm_response_size,
     674              :                                               spdm_response,
     675              :                                               response_size, response);
     676              :     }
     677            1 :         return LIBSPDM_STATUS_SUCCESS;
     678              : 
     679            1 :     case 0x5: {
     680              :         spdm_error_response_t *spdm_response;
     681              :         size_t spdm_response_size;
     682              :         size_t transport_header_size;
     683              : 
     684            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     685            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     686            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     687              : 
     688            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     689            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     690            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     691            1 :         spdm_response->header.param2 = 0;
     692              : 
     693            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     694              :                                               false, spdm_response_size,
     695              :                                               spdm_response,
     696              :                                               response_size, response);
     697              :     }
     698            1 :         return LIBSPDM_STATUS_SUCCESS;
     699              : 
     700            2 :     case 0x6: {
     701              :         static size_t sub_index1 = 0;
     702            2 :         if (sub_index1 == 0) {
     703              :             spdm_error_response_t *spdm_response;
     704              :             size_t spdm_response_size;
     705              :             size_t transport_header_size;
     706              : 
     707            1 :             spdm_response_size = sizeof(spdm_error_response_t);
     708            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     709            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     710              : 
     711            1 :             spdm_response->header.spdm_version =
     712              :                 SPDM_MESSAGE_VERSION_11;
     713            1 :             spdm_response->header.request_response_code = SPDM_ERROR;
     714            1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     715            1 :             spdm_response->header.param2 = 0;
     716              : 
     717            1 :             libspdm_transport_test_encode_message(
     718              :                 spdm_context, NULL, false, false,
     719              :                 spdm_response_size, spdm_response,
     720              :                 response_size, response);
     721            1 :             sub_index1++;
     722            1 :         } else if (sub_index1 == 1) {
     723              :             spdm_measurements_response_t *spdm_response;
     724              :             uint8_t *ptr;
     725              :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     726              :             size_t sig_size;
     727              :             size_t measurment_sig_size;
     728              :             spdm_measurement_block_dmtf_t *measurment_block;
     729              :             size_t spdm_response_size;
     730              :             size_t transport_header_size;
     731              : 
     732              :             ((libspdm_context_t *)spdm_context)
     733            1 :             ->connection_info.algorithm.base_asym_algo =
     734              :                 m_libspdm_use_asym_algo;
     735              :             ((libspdm_context_t *)spdm_context)
     736            1 :             ->connection_info.algorithm.base_hash_algo =
     737              :                 m_libspdm_use_hash_algo;
     738              :             ((libspdm_context_t *)spdm_context)
     739              :             ->connection_info.algorithm
     740            1 :             .measurement_hash_algo =
     741              :                 m_libspdm_use_measurement_hash_algo;
     742            1 :             measurment_sig_size =
     743              :                 SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
     744            1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     745            1 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
     746              :                                  sizeof(spdm_measurement_block_dmtf_t) +
     747            1 :                                  libspdm_get_measurement_hash_size(
     748            1 :                 m_libspdm_use_measurement_hash_algo) +
     749              :                                  measurment_sig_size;
     750            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     751            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     752              : 
     753            1 :             spdm_response->header.spdm_version =
     754              :                 SPDM_MESSAGE_VERSION_11;
     755            1 :             spdm_response->header.request_response_code =
     756              :                 SPDM_MEASUREMENTS;
     757            1 :             spdm_response->header.param1 = 0;
     758            1 :             spdm_response->header.param2 = 0;
     759            1 :             spdm_response->number_of_blocks = 1;
     760            1 :             libspdm_write_uint24(
     761            1 :                 spdm_response->measurement_record_length,
     762              :                 (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
     763            1 :                            libspdm_get_measurement_hash_size(
     764              :                                m_libspdm_use_measurement_hash_algo)));
     765            1 :             measurment_block = (void *)(spdm_response + 1);
     766            1 :             libspdm_set_mem(measurment_block,
     767              :                             sizeof(spdm_measurement_block_dmtf_t) +
     768            1 :                             libspdm_get_measurement_hash_size(
     769              :                                 m_libspdm_use_measurement_hash_algo),
     770              :                             1);
     771              :             measurment_block->measurement_block_common_header
     772            1 :             .measurement_specification =
     773              :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
     774              :             measurment_block->measurement_block_common_header
     775            1 :             .measurement_size = (uint16_t)(
     776              :                 sizeof(spdm_measurement_block_dmtf_header_t) +
     777            1 :                 libspdm_get_measurement_hash_size(
     778              :                     m_libspdm_use_measurement_hash_algo));
     779            1 :             ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
     780              :                            measurment_sig_size);
     781            1 :             libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     782            1 :             ptr += SPDM_NONCE_SIZE;
     783            1 :             *(uint16_t *)ptr = 0;
     784            1 :             ptr += sizeof(uint16_t);
     785            1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     786              :                              sizeof(m_libspdm_local_buffer)
     787            1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     788              :                                 m_libspdm_local_buffer),
     789            1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
     790            1 :             m_libspdm_local_buffer_size +=
     791            1 :                 ((size_t)ptr - (size_t)spdm_response);
     792            1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     793              :                            m_libspdm_local_buffer_size));
     794            1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     795            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     796              :                              m_libspdm_local_buffer_size, hash_data);
     797            1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
     798              :                            libspdm_get_hash_size(m_libspdm_use_hash_algo)));
     799            1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     800            1 :             sig_size =
     801            1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     802            1 :             libspdm_responder_data_sign(
     803              :                 spdm_context,
     804            1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     805              :                     SPDM_MEASUREMENTS,
     806              :                     m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo,
     807              :                     m_libspdm_use_hash_algo,
     808              :                     false, m_libspdm_local_buffer,
     809              :                     m_libspdm_local_buffer_size, ptr,
     810              :                     &sig_size);
     811            1 :             ptr += sig_size;
     812              : 
     813            1 :             libspdm_transport_test_encode_message(
     814              :                 spdm_context, NULL, false, false, spdm_response_size,
     815              :                 spdm_response, response_size, response);
     816              :         }
     817              :     }
     818            2 :         return LIBSPDM_STATUS_SUCCESS;
     819              : 
     820            1 :     case 0x7: {
     821              :         spdm_error_response_t *spdm_response;
     822              :         size_t spdm_response_size;
     823              :         size_t transport_header_size;
     824              : 
     825            1 :         spdm_response_size = sizeof(spdm_error_response_t);
     826            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     827            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     828              : 
     829            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     830            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     831            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
     832            1 :         spdm_response->header.param2 = 0;
     833              : 
     834            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     835              :                                               false, spdm_response_size,
     836              :                                               spdm_response,
     837              :                                               response_size, response);
     838              :     }
     839            1 :         return LIBSPDM_STATUS_SUCCESS;
     840              : 
     841            2 :     case 0x8: {
     842              :         spdm_error_response_data_response_not_ready_t *spdm_response;
     843              :         size_t spdm_response_size;
     844              :         size_t transport_header_size;
     845              : 
     846            2 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
     847            2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     848            2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     849              : 
     850            2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     851            2 :         spdm_response->header.request_response_code = SPDM_ERROR;
     852            2 :         spdm_response->header.param1 =
     853              :             SPDM_ERROR_CODE_RESPONSE_NOT_READY;
     854            2 :         spdm_response->header.param2 = 0;
     855            2 :         spdm_response->extend_error_data.rd_exponent = 1;
     856            2 :         spdm_response->extend_error_data.rd_tm = 2;
     857            2 :         spdm_response->extend_error_data.request_code =
     858              :             SPDM_GET_MEASUREMENTS;
     859            2 :         spdm_response->extend_error_data.token = 0;
     860              : 
     861            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     862              :                                               false, spdm_response_size,
     863              :                                               spdm_response,
     864              :                                               response_size, response);
     865              :     }
     866            2 :         return LIBSPDM_STATUS_SUCCESS;
     867              : 
     868            2 :     case 0x9: {
     869              :         static size_t sub_index2 = 0;
     870            2 :         if (sub_index2 == 0) {
     871              :             spdm_error_response_data_response_not_ready_t
     872              :             *spdm_response;
     873              :             size_t spdm_response_size;
     874              :             size_t transport_header_size;
     875              : 
     876            1 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
     877            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     878            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     879              : 
     880            1 :             spdm_response->header.spdm_version =
     881              :                 SPDM_MESSAGE_VERSION_11;
     882            1 :             spdm_response->header.request_response_code = SPDM_ERROR;
     883            1 :             spdm_response->header.param1 =
     884              :                 SPDM_ERROR_CODE_RESPONSE_NOT_READY;
     885            1 :             spdm_response->header.param2 = 0;
     886            1 :             spdm_response->extend_error_data.rd_exponent = 1;
     887            1 :             spdm_response->extend_error_data.rd_tm = 2;
     888            1 :             spdm_response->extend_error_data.request_code =
     889              :                 SPDM_GET_MEASUREMENTS;
     890            1 :             spdm_response->extend_error_data.token = 1;
     891              : 
     892            1 :             libspdm_transport_test_encode_message(
     893              :                 spdm_context, NULL, false, false,
     894              :                 spdm_response_size, spdm_response,
     895              :                 response_size, response);
     896            1 :             sub_index2++;
     897            1 :         } else if (sub_index2 == 1) {
     898              :             spdm_measurements_response_t *spdm_response;
     899              :             uint8_t *ptr;
     900              :             uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
     901              :             size_t sig_size;
     902              :             size_t measurment_sig_size;
     903              :             spdm_measurement_block_dmtf_t *measurment_block;
     904              :             size_t spdm_response_size;
     905              :             size_t transport_header_size;
     906              : 
     907              :             ((libspdm_context_t *)spdm_context)
     908            1 :             ->connection_info.algorithm.base_asym_algo =
     909              :                 m_libspdm_use_asym_algo;
     910              :             ((libspdm_context_t *)spdm_context)
     911            1 :             ->connection_info.algorithm.base_hash_algo =
     912              :                 m_libspdm_use_hash_algo;
     913              :             ((libspdm_context_t *)spdm_context)
     914              :             ->connection_info.algorithm
     915            1 :             .measurement_hash_algo =
     916              :                 m_libspdm_use_measurement_hash_algo;
     917            1 :             measurment_sig_size =
     918              :                 SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
     919            1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     920            1 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
     921              :                                  sizeof(spdm_measurement_block_dmtf_t) +
     922            1 :                                  libspdm_get_measurement_hash_size(
     923            1 :                 m_libspdm_use_measurement_hash_algo) +
     924              :                                  measurment_sig_size;
     925            1 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     926            1 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     927              : 
     928            1 :             spdm_response->header.spdm_version =
     929              :                 SPDM_MESSAGE_VERSION_11;
     930            1 :             spdm_response->header.request_response_code =
     931              :                 SPDM_MEASUREMENTS;
     932            1 :             spdm_response->header.param1 = 0;
     933            1 :             spdm_response->header.param2 = 0;
     934            1 :             spdm_response->number_of_blocks = 1;
     935            1 :             libspdm_write_uint24(
     936            1 :                 spdm_response->measurement_record_length,
     937              :                 (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
     938            1 :                            libspdm_get_measurement_hash_size(
     939              :                                m_libspdm_use_measurement_hash_algo)));
     940            1 :             measurment_block = (void *)(spdm_response + 1);
     941            1 :             libspdm_set_mem(measurment_block,
     942              :                             sizeof(spdm_measurement_block_dmtf_t) +
     943            1 :                             libspdm_get_measurement_hash_size(
     944              :                                 m_libspdm_use_measurement_hash_algo),
     945              :                             1);
     946              :             measurment_block->measurement_block_common_header
     947            1 :             .measurement_specification =
     948              :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
     949              :             measurment_block->measurement_block_common_header
     950            1 :             .measurement_size = (uint16_t)(
     951              :                 sizeof(spdm_measurement_block_dmtf_header_t) +
     952            1 :                 libspdm_get_measurement_hash_size(
     953              :                     m_libspdm_use_measurement_hash_algo));
     954            1 :             ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
     955              :                            measurment_sig_size);
     956            1 :             libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     957            1 :             ptr += SPDM_NONCE_SIZE;
     958            1 :             *(uint16_t *)ptr = 0;
     959            1 :             ptr += sizeof(uint16_t);
     960            1 :             libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     961              :                              sizeof(m_libspdm_local_buffer)
     962            1 :                              - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
     963              :                                 m_libspdm_local_buffer),
     964            1 :                              spdm_response, (size_t)ptr - (size_t)spdm_response);
     965            1 :             m_libspdm_local_buffer_size +=
     966            1 :                 ((size_t)ptr - (size_t)spdm_response);
     967            1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
     968              :                            m_libspdm_local_buffer_size));
     969            1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     970            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
     971              :                              m_libspdm_local_buffer_size, hash_data);
     972            1 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
     973              :                            libspdm_get_hash_size(m_libspdm_use_hash_algo)));
     974            1 :             libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
     975            1 :             sig_size =
     976            1 :                 libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
     977            1 :             libspdm_responder_data_sign(
     978              :                 spdm_context,
     979            1 :                 spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     980              :                     SPDM_MEASUREMENTS,
     981              :                     m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo,
     982              :                     m_libspdm_use_hash_algo,
     983              :                     false, m_libspdm_local_buffer,
     984              :                     m_libspdm_local_buffer_size, ptr,
     985              :                     &sig_size);
     986            1 :             ptr += sig_size;
     987              : 
     988            1 :             libspdm_transport_test_encode_message(
     989              :                 spdm_context, NULL, false, false, spdm_response_size,
     990              :                 spdm_response, response_size, response);
     991              :         }
     992              :     }
     993            2 :         return LIBSPDM_STATUS_SUCCESS;
     994              : 
     995            1 :     case 0xA: {
     996              :         spdm_measurements_response_t *spdm_response;
     997              :         size_t spdm_response_size;
     998              :         size_t transport_header_size;
     999              :         uint8_t *ptr;
    1000            1 :         spdm_response_size =
    1001              :             sizeof(spdm_measurements_response_t)
    1002              :             + SPDM_NONCE_SIZE + sizeof(uint16_t);
    1003            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1004            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1005            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1006            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1007            1 :         spdm_response->header.param1 = 4;
    1008            1 :         spdm_response->header.param2 = 0;
    1009            1 :         spdm_response->number_of_blocks = 0;
    1010            1 :         libspdm_write_uint24(spdm_response->measurement_record_length, 0);
    1011              : 
    1012            1 :         ptr = (uint8_t *)spdm_response +
    1013              :               sizeof(spdm_measurements_response_t);
    1014            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
    1015            1 :         ptr += SPDM_NONCE_SIZE;
    1016            1 :         *(uint16_t *)ptr = 0;
    1017              : 
    1018            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1019              :                                               false, spdm_response_size,
    1020              :                                               spdm_response, response_size,
    1021              :                                               response);
    1022              :     }
    1023            1 :         return LIBSPDM_STATUS_SUCCESS;
    1024              : 
    1025            1 :     case 0xB: {
    1026              :         spdm_measurements_response_t *spdm_response;
    1027              :         spdm_measurement_block_dmtf_t *measurment_block;
    1028              :         size_t spdm_response_size;
    1029              :         size_t transport_header_size;
    1030              :         uint8_t *ptr;
    1031              :         ((libspdm_context_t *)spdm_context)
    1032            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1033              :             m_libspdm_use_measurement_hash_algo;
    1034            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1035              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1036            1 :                              libspdm_get_measurement_hash_size(
    1037              :             m_libspdm_use_measurement_hash_algo) +
    1038              :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
    1039            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1040            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1041              : 
    1042            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1043            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1044            1 :         spdm_response->header.param1 = 0;
    1045            1 :         spdm_response->header.param2 = 0;
    1046            1 :         spdm_response->number_of_blocks = 1;
    1047            1 :         libspdm_write_uint24(
    1048            1 :             spdm_response->measurement_record_length,
    1049              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1050            1 :                        libspdm_get_measurement_hash_size(
    1051              :                            m_libspdm_use_measurement_hash_algo)));
    1052            1 :         measurment_block = (void *)(spdm_response + 1);
    1053            1 :         libspdm_set_mem(measurment_block,
    1054              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1055            1 :                         libspdm_get_measurement_hash_size(
    1056              :                             m_libspdm_use_measurement_hash_algo),
    1057              :                         1);
    1058              :         measurment_block->measurement_block_common_header
    1059            1 :         .measurement_specification =
    1060              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1061              :         measurment_block->measurement_block_common_header
    1062            1 :         .measurement_size =
    1063            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1064            1 :                        libspdm_get_measurement_hash_size(
    1065              :                            m_libspdm_use_measurement_hash_algo));
    1066              : 
    1067            1 :         ptr = (uint8_t *)spdm_response +
    1068              :               sizeof(spdm_measurements_response_t) +
    1069            1 :               sizeof(spdm_measurement_block_dmtf_t) +
    1070            1 :               libspdm_get_measurement_hash_size(
    1071              :             m_libspdm_use_measurement_hash_algo);
    1072            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
    1073            1 :         *(uint16_t *)(ptr + SPDM_NONCE_SIZE) = 0;
    1074              : 
    1075            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1076              :                                               false, spdm_response_size,
    1077              :                                               spdm_response, response_size,
    1078              :                                               response);
    1079              :     }
    1080            1 :         return LIBSPDM_STATUS_SUCCESS;
    1081              : 
    1082            1 :     case 0xC: {
    1083              :         spdm_measurements_response_t *spdm_response;
    1084              :         uint8_t *ptr;
    1085              :         size_t sig_size;
    1086              :         size_t measurment_sig_size;
    1087              :         spdm_measurement_block_dmtf_t *measurment_block;
    1088              :         size_t spdm_response_size;
    1089              :         size_t transport_header_size;
    1090              : 
    1091              :         ((libspdm_context_t *)spdm_context)
    1092            1 :         ->connection_info.algorithm.base_asym_algo =
    1093              :             m_libspdm_use_asym_algo;
    1094              :         ((libspdm_context_t *)spdm_context)
    1095            1 :         ->connection_info.algorithm.base_hash_algo =
    1096              :             m_libspdm_use_hash_algo;
    1097              :         ((libspdm_context_t *)spdm_context)
    1098            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1099              :             m_libspdm_use_measurement_hash_algo;
    1100              : 
    1101            1 :         measurment_sig_size =
    1102              :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
    1103            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1104            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1105              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1106            1 :                              libspdm_get_measurement_hash_size(
    1107            1 :             m_libspdm_use_measurement_hash_algo) +
    1108              :                              measurment_sig_size;
    1109            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1110            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1111              : 
    1112            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1113            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1114            1 :         spdm_response->header.param1 = 0;
    1115            1 :         spdm_response->header.param2 = 0;
    1116            1 :         spdm_response->number_of_blocks = 1;
    1117            1 :         libspdm_write_uint24(
    1118            1 :             spdm_response->measurement_record_length,
    1119              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1120            1 :                        libspdm_get_measurement_hash_size(
    1121              :                            m_libspdm_use_measurement_hash_algo)));
    1122            1 :         measurment_block = (void *)(spdm_response + 1);
    1123            1 :         libspdm_set_mem(measurment_block,
    1124              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1125            1 :                         libspdm_get_measurement_hash_size(
    1126              :                             m_libspdm_use_measurement_hash_algo),
    1127              :                         1);
    1128              :         measurment_block->measurement_block_common_header
    1129            1 :         .measurement_specification =
    1130              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1131              :         measurment_block->measurement_block_common_header
    1132            1 :         .measurement_size =
    1133            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1134            1 :                        libspdm_get_measurement_hash_size(
    1135              :                            m_libspdm_use_measurement_hash_algo));
    1136            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    1137              :                        measurment_sig_size);
    1138            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    1139            1 :         ptr += SPDM_NONCE_SIZE;
    1140            1 :         *(uint16_t *)ptr = 0;
    1141            1 :         ptr += sizeof(uint16_t);
    1142            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1143            1 :         libspdm_set_mem(ptr, sig_size, 0);
    1144            1 :         ptr += sig_size;
    1145              : 
    1146            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1147              :                                               false, spdm_response_size,
    1148              :                                               spdm_response, response_size,
    1149              :                                               response);
    1150              :     }
    1151            1 :         return LIBSPDM_STATUS_SUCCESS;
    1152              : 
    1153            1 :     case 0xD: {
    1154              :         spdm_measurements_response_t *spdm_response;
    1155              :         uint8_t *ptr;
    1156              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1157              :         size_t sig_size;
    1158              :         size_t measurment_sig_size;
    1159              :         spdm_measurement_block_dmtf_t *measurment_block;
    1160              :         size_t spdm_response_size;
    1161              :         size_t transport_header_size;
    1162              : 
    1163              :         ((libspdm_context_t *)spdm_context)
    1164            1 :         ->connection_info.algorithm.base_asym_algo =
    1165              :             m_libspdm_use_asym_algo;
    1166              :         ((libspdm_context_t *)spdm_context)
    1167            1 :         ->connection_info.algorithm.base_hash_algo =
    1168              :             m_libspdm_use_hash_algo;
    1169              :         ((libspdm_context_t *)spdm_context)
    1170            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1171              :             m_libspdm_use_measurement_hash_algo;
    1172            1 :         measurment_sig_size =
    1173              :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
    1174            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1175            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1176              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1177            1 :                              libspdm_get_measurement_hash_size(
    1178            1 :             m_libspdm_use_measurement_hash_algo) +
    1179              :                              measurment_sig_size;
    1180            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1181            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1182              : 
    1183            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1184            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1185            1 :         spdm_response->header.param1 = 0;
    1186            1 :         spdm_response->header.param2 = 0;
    1187            1 :         spdm_response->number_of_blocks = 1;
    1188            1 :         libspdm_write_uint24(
    1189            1 :             spdm_response->measurement_record_length,
    1190              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1191            1 :                        libspdm_get_measurement_hash_size(
    1192              :                            m_libspdm_use_measurement_hash_algo)));
    1193            1 :         measurment_block = (void *)(spdm_response + 1);
    1194            1 :         libspdm_set_mem(measurment_block,
    1195              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1196            1 :                         libspdm_get_measurement_hash_size(
    1197              :                             m_libspdm_use_measurement_hash_algo),
    1198              :                         1);
    1199              :         measurment_block->measurement_block_common_header
    1200            1 :         .measurement_specification =
    1201              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1202              :         measurment_block->measurement_block_common_header
    1203            1 :         .measurement_size =
    1204            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1205            1 :                        libspdm_get_measurement_hash_size(
    1206              :                            m_libspdm_use_measurement_hash_algo));
    1207            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    1208              :                        measurment_sig_size);
    1209            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    1210            1 :         ptr += SPDM_NONCE_SIZE;
    1211            1 :         *(uint16_t *)ptr = 0;
    1212            1 :         ptr += sizeof(uint16_t);
    1213            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1214              :                          sizeof(m_libspdm_local_buffer)
    1215            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1216              :                             m_libspdm_local_buffer),
    1217            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1218            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1219            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1220              :                        m_libspdm_local_buffer_size));
    1221            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1222            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1223              :                          m_libspdm_local_buffer_size, hash_data);
    1224            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    1225              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    1226            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1227            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1228            1 :         libspdm_get_random_number(sig_size, ptr);
    1229            1 :         ptr += sig_size;
    1230              : 
    1231            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1232              :                                               false, spdm_response_size,
    1233              :                                               spdm_response, response_size,
    1234              :                                               response);
    1235              :     }
    1236            1 :         return LIBSPDM_STATUS_SUCCESS;
    1237              : 
    1238            1 :     case 0xE: {
    1239              :         spdm_measurements_response_t *spdm_response;
    1240              :         spdm_measurement_block_dmtf_t *measurment_block;
    1241              :         size_t spdm_response_size;
    1242              :         size_t transport_header_size;
    1243              : 
    1244              :         ((libspdm_context_t *)spdm_context)
    1245            1 :         ->connection_info.algorithm.base_asym_algo =
    1246              :             m_libspdm_use_asym_algo;
    1247              :         ((libspdm_context_t *)spdm_context)
    1248            1 :         ->connection_info.algorithm.base_hash_algo =
    1249              :             m_libspdm_use_hash_algo;
    1250              :         ((libspdm_context_t *)spdm_context)
    1251            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1252              :             m_libspdm_use_measurement_hash_algo;
    1253            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1254              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1255            1 :                              libspdm_get_measurement_hash_size(
    1256              :             m_libspdm_use_measurement_hash_algo) +
    1257              :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
    1258            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1259            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1260              : 
    1261            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1262            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1263            1 :         spdm_response->header.param1 = 0;
    1264            1 :         spdm_response->header.param2 = 0;
    1265            1 :         spdm_response->number_of_blocks = 1;
    1266            1 :         libspdm_write_uint24(
    1267            1 :             spdm_response->measurement_record_length,
    1268              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1269            1 :                        libspdm_get_measurement_hash_size(
    1270              :                            m_libspdm_use_measurement_hash_algo)));
    1271            1 :         measurment_block = (void *)(spdm_response + 1);
    1272            1 :         libspdm_set_mem(measurment_block,
    1273              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1274            1 :                         libspdm_get_measurement_hash_size(
    1275              :                             m_libspdm_use_measurement_hash_algo),
    1276              :                         1);
    1277              :         measurment_block->measurement_block_common_header
    1278            1 :         .measurement_specification =
    1279              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1280              :         measurment_block->measurement_block_common_header
    1281            1 :         .measurement_size =
    1282            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1283            1 :                        libspdm_get_measurement_hash_size(
    1284              :                            m_libspdm_use_measurement_hash_algo));
    1285              : 
    1286            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1287              :                                               false, spdm_response_size,
    1288              :                                               spdm_response, response_size,
    1289              :                                               response);
    1290              :     }
    1291            1 :         return LIBSPDM_STATUS_SUCCESS;
    1292              : 
    1293            1 :     case 0xF: {
    1294              :         spdm_measurements_response_t *spdm_response;
    1295              :         uint8_t *ptr;
    1296              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1297              :         size_t sig_size;
    1298              :         size_t measurment_sig_size;
    1299              :         spdm_measurement_block_dmtf_t *measurment_block;
    1300              :         size_t spdm_response_size;
    1301              :         size_t transport_header_size;
    1302              : 
    1303              :         ((libspdm_context_t *)spdm_context)
    1304            1 :         ->connection_info.algorithm.base_asym_algo =
    1305              :             m_libspdm_use_asym_algo;
    1306              :         ((libspdm_context_t *)spdm_context)
    1307            1 :         ->connection_info.algorithm.base_hash_algo =
    1308              :             m_libspdm_use_hash_algo;
    1309              :         ((libspdm_context_t *)spdm_context)
    1310            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1311              :             m_libspdm_use_measurement_hash_algo;
    1312            1 :         measurment_sig_size =
    1313              :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
    1314            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1315            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1316              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1317            1 :                              libspdm_get_measurement_hash_size(
    1318            1 :             m_libspdm_use_measurement_hash_algo) +
    1319              :                              measurment_sig_size;
    1320            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1321            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1322              : 
    1323            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1324            1 :         spdm_response->header.request_response_code =
    1325              :             SPDM_MEASUREMENTS + 1;
    1326            1 :         spdm_response->header.param1 = 0;
    1327            1 :         spdm_response->header.param2 = 0;
    1328            1 :         spdm_response->number_of_blocks = 1;
    1329            1 :         libspdm_write_uint24(
    1330            1 :             spdm_response->measurement_record_length,
    1331              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1332            1 :                        libspdm_get_measurement_hash_size(
    1333              :                            m_libspdm_use_measurement_hash_algo)));
    1334            1 :         measurment_block = (void *)(spdm_response + 1);
    1335            1 :         libspdm_set_mem(measurment_block,
    1336              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1337            1 :                         libspdm_get_measurement_hash_size(
    1338              :                             m_libspdm_use_measurement_hash_algo),
    1339              :                         1);
    1340              :         measurment_block->measurement_block_common_header
    1341            1 :         .measurement_specification =
    1342              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1343              :         measurment_block->measurement_block_common_header
    1344            1 :         .measurement_size =
    1345            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1346            1 :                        libspdm_get_measurement_hash_size(
    1347              :                            m_libspdm_use_measurement_hash_algo));
    1348            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    1349              :                        measurment_sig_size);
    1350            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    1351            1 :         ptr += SPDM_NONCE_SIZE;
    1352            1 :         *(uint16_t *)ptr = 0;
    1353            1 :         ptr += sizeof(uint16_t);
    1354            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1355              :                          sizeof(m_libspdm_local_buffer)
    1356            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1357              :                             m_libspdm_local_buffer),
    1358            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1359            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1360            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1361              :                        m_libspdm_local_buffer_size));
    1362            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1363            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1364              :                          m_libspdm_local_buffer_size, hash_data);
    1365            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    1366              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    1367            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1368            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1369            1 :         libspdm_responder_data_sign(
    1370              :             spdm_context,
    1371            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1372              :                 SPDM_MEASUREMENTS,
    1373              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1374              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    1375              :                 ptr, &sig_size);
    1376            1 :         ptr += sig_size;
    1377              : 
    1378            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1379              :                                               false, spdm_response_size,
    1380              :                                               spdm_response, response_size,
    1381              :                                               response);
    1382              :     }
    1383            1 :         return LIBSPDM_STATUS_SUCCESS;
    1384              : 
    1385            4 :     case 0x10: {
    1386              :         spdm_measurements_response_t *spdm_response;
    1387              :         uint8_t *ptr;
    1388              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1389              :         size_t sig_size;
    1390              :         size_t measurment_sig_size;
    1391              :         spdm_measurement_block_dmtf_t *measurment_block;
    1392              :         size_t spdm_response_size;
    1393              :         size_t transport_header_size;
    1394              : 
    1395              :         ((libspdm_context_t *)spdm_context)
    1396            4 :         ->connection_info.algorithm.base_asym_algo =
    1397              :             m_libspdm_use_asym_algo;
    1398              :         ((libspdm_context_t *)spdm_context)
    1399            4 :         ->connection_info.algorithm.base_hash_algo =
    1400              :             m_libspdm_use_hash_algo;
    1401              :         ((libspdm_context_t *)spdm_context)
    1402            4 :         ->connection_info.algorithm.measurement_hash_algo =
    1403              :             m_libspdm_use_measurement_hash_algo;
    1404            4 :         measurment_sig_size =
    1405              :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
    1406            4 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1407            4 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1408              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1409            4 :                              libspdm_get_measurement_hash_size(
    1410            4 :             m_libspdm_use_measurement_hash_algo) +
    1411              :                              measurment_sig_size;
    1412            4 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1413            4 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1414              : 
    1415            4 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1416            4 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1417            4 :         spdm_response->header.param1 = 0;
    1418            4 :         spdm_response->header.param2 = LIBSPDM_ALTERNATIVE_DEFAULT_SLOT_ID;
    1419            4 :         spdm_response->number_of_blocks = 1;
    1420            4 :         libspdm_write_uint24(
    1421            4 :             spdm_response->measurement_record_length,
    1422              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1423            4 :                        libspdm_get_measurement_hash_size(
    1424              :                            m_libspdm_use_measurement_hash_algo)));
    1425            4 :         measurment_block = (void *)(spdm_response + 1);
    1426            4 :         libspdm_set_mem(measurment_block,
    1427              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1428            4 :                         libspdm_get_measurement_hash_size(
    1429              :                             m_libspdm_use_measurement_hash_algo),
    1430              :                         1);
    1431              :         measurment_block->measurement_block_common_header
    1432            4 :         .measurement_specification =
    1433              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1434              :         measurment_block->measurement_block_common_header
    1435            4 :         .measurement_size =
    1436            4 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1437            4 :                        libspdm_get_measurement_hash_size(
    1438              :                            m_libspdm_use_measurement_hash_algo));
    1439            4 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    1440              :                        measurment_sig_size);
    1441            4 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    1442            4 :         ptr += SPDM_NONCE_SIZE;
    1443            4 :         *(uint16_t *)ptr = 0;
    1444            4 :         ptr += sizeof(uint16_t);
    1445            4 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    1446              :                          sizeof(m_libspdm_local_buffer)
    1447            4 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    1448              :                             m_libspdm_local_buffer),
    1449            4 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    1450            4 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    1451            4 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    1452              :                        m_libspdm_local_buffer_size));
    1453            4 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1454            4 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    1455              :                          m_libspdm_local_buffer_size, hash_data);
    1456            4 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    1457              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    1458            4 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1459            4 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1460            4 :         libspdm_responder_data_sign(
    1461              :             spdm_context,
    1462            4 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    1463              :                 SPDM_MEASUREMENTS,
    1464              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    1465              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    1466              :                 ptr, &sig_size);
    1467            4 :         ptr += sig_size;
    1468              : 
    1469            4 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1470              :                                               false, spdm_response_size,
    1471              :                                               spdm_response, response_size,
    1472              :                                               response);
    1473              :     }
    1474            4 :         return LIBSPDM_STATUS_SUCCESS;
    1475              : 
    1476            3 :     case 0x11: {
    1477              :         static size_t sub_index0x11 = 0;
    1478              : 
    1479              :         spdm_measurements_response_t *spdm_response;
    1480              :         spdm_measurement_block_dmtf_t *measurment_block;
    1481              :         size_t spdm_response_size;
    1482              :         size_t transport_header_size;
    1483            3 :         spdm_response_size = sizeof(spdm_measurements_response_t);
    1484              : 
    1485              :         ((libspdm_context_t *)spdm_context)
    1486            3 :         ->connection_info.algorithm.measurement_hash_algo =
    1487              :             m_libspdm_use_measurement_hash_algo;
    1488            3 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1489            3 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1490              : 
    1491            3 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1492            3 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1493            3 :         spdm_response->header.param1 = 1;
    1494            3 :         spdm_response->header.param2 = 0;
    1495            3 :         if (sub_index0x11 == 0) {
    1496            1 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
    1497              :                                  sizeof(spdm_measurement_block_dmtf_t) +
    1498            1 :                                  libspdm_get_measurement_hash_size(
    1499              :                 m_libspdm_use_measurement_hash_algo) +
    1500              :                                  SPDM_NONCE_SIZE + sizeof(uint16_t);
    1501            1 :             spdm_response->number_of_blocks = 1;
    1502            1 :             libspdm_write_uint24(
    1503            1 :                 spdm_response->measurement_record_length,
    1504              :                 (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1505            1 :                            libspdm_get_measurement_hash_size(
    1506              :                                m_libspdm_use_measurement_hash_algo)));
    1507            1 :             measurment_block = (void *)(spdm_response + 1);
    1508            1 :             libspdm_set_mem(measurment_block,
    1509              :                             sizeof(spdm_measurement_block_dmtf_t) +
    1510            1 :                             libspdm_get_measurement_hash_size(
    1511              :                                 m_libspdm_use_measurement_hash_algo),
    1512              :                             1);
    1513              :             measurment_block->measurement_block_common_header
    1514            1 :             .measurement_specification =
    1515              :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1516              :             measurment_block->measurement_block_common_header
    1517            1 :             .measurement_size = (uint16_t)(
    1518              :                 sizeof(spdm_measurement_block_dmtf_header_t) +
    1519            1 :                 libspdm_get_measurement_hash_size(
    1520              :                     m_libspdm_use_measurement_hash_algo));
    1521            2 :         } else if (sub_index0x11 == 1) {
    1522            1 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
    1523              :                                  SPDM_NONCE_SIZE + sizeof(uint16_t);
    1524            1 :             spdm_response->number_of_blocks = 1;
    1525            1 :             libspdm_write_uint24(
    1526            1 :                 spdm_response->measurement_record_length, 0);
    1527            1 :         } else if (sub_index0x11 == 2) {
    1528            1 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
    1529              :                                  sizeof(spdm_measurement_block_dmtf_t) +
    1530            1 :                                  libspdm_get_measurement_hash_size(
    1531              :                 m_libspdm_use_measurement_hash_algo) +
    1532              :                                  SPDM_NONCE_SIZE + sizeof(uint16_t);
    1533            1 :             spdm_response->number_of_blocks = 0;
    1534            1 :             libspdm_write_uint24(
    1535            1 :                 spdm_response->measurement_record_length,
    1536              :                 (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1537            1 :                            libspdm_get_measurement_hash_size(
    1538              :                                m_libspdm_use_measurement_hash_algo)));
    1539            1 :             measurment_block = (void *)(spdm_response + 1);
    1540            1 :             libspdm_set_mem(measurment_block,
    1541              :                             sizeof(spdm_measurement_block_dmtf_t) +
    1542            1 :                             libspdm_get_measurement_hash_size(
    1543              :                                 m_libspdm_use_measurement_hash_algo),
    1544              :                             1);
    1545              :             measurment_block->measurement_block_common_header
    1546            1 :             .measurement_specification =
    1547              :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1548              :             measurment_block->measurement_block_common_header
    1549            1 :             .measurement_size = (uint16_t)(
    1550              :                 sizeof(spdm_measurement_block_dmtf_header_t) +
    1551            1 :                 libspdm_get_measurement_hash_size(
    1552              :                     m_libspdm_use_measurement_hash_algo));
    1553              :         }
    1554            3 :         sub_index0x11++;
    1555              : 
    1556            3 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1557              :                                               false, spdm_response_size,
    1558              :                                               spdm_response, response_size,
    1559              :                                               response);
    1560              :     }
    1561            3 :         return LIBSPDM_STATUS_SUCCESS;
    1562              : 
    1563            0 :     case 0x12: {
    1564              :         spdm_measurements_response_t *spdm_response;
    1565              :         spdm_measurement_block_dmtf_t *measurment_block;
    1566              :         uint8_t *large_spdm_response;
    1567              :         size_t spdm_response_size;
    1568              :         size_t transport_header_size;
    1569              :         size_t count;
    1570              : 
    1571              :         large_spdm_response =
    1572            0 :             (uint8_t *)malloc(sizeof(spdm_measurements_response_t) +
    1573              :                               LIBSPDM_LARGE_MEASUREMENT_SIZE);
    1574              : 
    1575              :         ((libspdm_context_t *)spdm_context)
    1576            0 :         ->connection_info.algorithm.measurement_hash_algo =
    1577              :             m_libspdm_use_measurement_hash_algo;
    1578            0 :         spdm_response_size = sizeof(spdm_measurements_response_t);
    1579            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1580            0 :         spdm_response = (void *)large_spdm_response;
    1581              : 
    1582            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1583            0 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1584            0 :         spdm_response->header.param1 = 0;
    1585            0 :         spdm_response->header.param2 = 0;
    1586            0 :         spdm_response->number_of_blocks = 0xFF;
    1587            0 :         libspdm_write_uint24(spdm_response->measurement_record_length,
    1588              :                              (uint32_t)(LIBSPDM_LARGE_MEASUREMENT_SIZE));
    1589            0 :         measurment_block = (void *)(spdm_response + 1);
    1590            0 :         libspdm_set_mem(measurment_block, LIBSPDM_LARGE_MEASUREMENT_SIZE, 1);
    1591            0 :         for (count = 0; count < spdm_response->number_of_blocks;
    1592            0 :              count++) {
    1593            0 :             measurment_block->measurement_block_common_header.index =
    1594            0 :                 (uint8_t)(count + 1);
    1595              :             measurment_block->measurement_block_common_header
    1596            0 :             .measurement_specification =
    1597              :                 SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1598              :             measurment_block->measurement_block_common_header
    1599            0 :             .measurement_size = 0xFFFF;
    1600            0 :             spdm_response_size += (size_t)(
    1601              :                 sizeof(spdm_measurement_block_common_header_t) +
    1602              :                 0xFFFF);
    1603              :         }
    1604              : 
    1605            0 :         spdm_response = (void *)((uint8_t *)(*response) + transport_header_size);
    1606            0 :         if (spdm_response_size >  (size_t)(*response) + *response_size - (size_t)spdm_response) {
    1607            0 :             spdm_response_size =  (size_t)(*response) + *response_size - (size_t)spdm_response;
    1608              :         }
    1609            0 :         libspdm_copy_mem (spdm_response, spdm_response_size,
    1610              :                           large_spdm_response, spdm_response_size);
    1611              : 
    1612            0 :         status = libspdm_transport_test_encode_message(
    1613              :             spdm_context, NULL, false, false, spdm_response_size,
    1614              :             spdm_response, response_size, response);
    1615              : 
    1616            0 :         free(large_spdm_response);
    1617              :     }
    1618            0 :         return status;
    1619              : 
    1620            1 :     case 0x13: {
    1621              :         spdm_measurements_response_t *spdm_response;
    1622              :         spdm_measurement_block_dmtf_t *measurment_block;
    1623              :         size_t spdm_response_size;
    1624              :         size_t transport_header_size;
    1625              : 
    1626              :         ((libspdm_context_t *)spdm_context)
    1627            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1628              :             m_libspdm_use_measurement_hash_algo;
    1629            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1630              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1631            1 :                              libspdm_get_measurement_hash_size(
    1632              :             m_libspdm_use_measurement_hash_algo) +
    1633              :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
    1634            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1635            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1636              : 
    1637            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1638            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1639            1 :         spdm_response->header.param1 = 0;
    1640            1 :         spdm_response->header.param2 = 0;
    1641            1 :         spdm_response->number_of_blocks = 1;
    1642            1 :         libspdm_write_uint24(
    1643            1 :             spdm_response->measurement_record_length,
    1644              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1645            1 :                        libspdm_get_measurement_hash_size(
    1646              :                            m_libspdm_use_measurement_hash_algo)));
    1647            1 :         measurment_block = (void *)(spdm_response + 1);
    1648            1 :         libspdm_set_mem(measurment_block,
    1649              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1650            1 :                         libspdm_get_measurement_hash_size(
    1651              :                             m_libspdm_use_measurement_hash_algo),
    1652              :                         1);
    1653            1 :         measurment_block->measurement_block_common_header.index = 1;
    1654              :         measurment_block->measurement_block_common_header
    1655            1 :         .measurement_specification = 0x00000001 | 0x00000002;
    1656              :         measurment_block->measurement_block_common_header
    1657            1 :         .measurement_size =
    1658            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1659            1 :                        libspdm_get_measurement_hash_size(
    1660              :                            m_libspdm_use_measurement_hash_algo));
    1661              : 
    1662            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1663              :                                               false, spdm_response_size,
    1664              :                                               spdm_response, response_size,
    1665              :                                               response);
    1666              :     }
    1667            1 :         return LIBSPDM_STATUS_SUCCESS;
    1668              : 
    1669            1 :     case 0x14: {
    1670              :         spdm_measurements_response_t *spdm_response;
    1671              :         spdm_measurement_block_dmtf_t *measurment_block;
    1672              :         size_t spdm_response_size;
    1673              :         size_t transport_header_size;
    1674              : 
    1675              :         ((libspdm_context_t *)spdm_context)
    1676            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1677              :             m_libspdm_use_measurement_hash_algo;
    1678            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1679              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1680            1 :                              libspdm_get_measurement_hash_size(
    1681              :             m_libspdm_use_measurement_hash_algo) +
    1682              :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
    1683            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1684            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1685              : 
    1686            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1687            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1688            1 :         spdm_response->header.param1 = 0;
    1689            1 :         spdm_response->header.param2 = 0;
    1690            1 :         spdm_response->number_of_blocks = 1;
    1691            1 :         libspdm_write_uint24(
    1692            1 :             spdm_response->measurement_record_length,
    1693              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1694            1 :                        libspdm_get_measurement_hash_size(
    1695              :                            m_libspdm_use_measurement_hash_algo)));
    1696            1 :         measurment_block = (void *)(spdm_response + 1);
    1697            1 :         libspdm_set_mem(measurment_block,
    1698              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1699            1 :                         libspdm_get_measurement_hash_size(
    1700              :                             m_libspdm_use_measurement_hash_algo),
    1701              :                         1);
    1702            1 :         measurment_block->measurement_block_common_header.index = 1;
    1703              :         measurment_block->measurement_block_common_header
    1704            1 :         .measurement_specification = 0x00000004 | 0x00000002;
    1705              :         measurment_block->measurement_block_common_header
    1706            1 :         .measurement_size =
    1707            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1708            1 :                        libspdm_get_measurement_hash_size(
    1709              :                            m_libspdm_use_measurement_hash_algo));
    1710              : 
    1711            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1712              :                                               false, spdm_response_size,
    1713              :                                               spdm_response, response_size,
    1714              :                                               response);
    1715              :     }
    1716            1 :         return LIBSPDM_STATUS_SUCCESS;
    1717              : 
    1718            1 :     case 0x15: {
    1719              :         spdm_measurements_response_t *spdm_response;
    1720              :         spdm_measurement_block_dmtf_t *measurment_block;
    1721              :         size_t spdm_response_size;
    1722              :         size_t transport_header_size;
    1723              : 
    1724              :         ((libspdm_context_t *)spdm_context)
    1725            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1726              :             m_libspdm_use_measurement_hash_algo;
    1727            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1728              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1729            1 :                              libspdm_get_measurement_hash_size(
    1730              :             m_libspdm_use_measurement_hash_algo) +
    1731              :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
    1732            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1733            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1734              : 
    1735            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1736            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1737            1 :         spdm_response->header.param1 = 0;
    1738            1 :         spdm_response->header.param2 = 0;
    1739            1 :         spdm_response->number_of_blocks = 1;
    1740            1 :         libspdm_write_uint24(
    1741            1 :             spdm_response->measurement_record_length,
    1742              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1743            1 :                        libspdm_get_measurement_hash_size(
    1744              :                            m_libspdm_use_measurement_hash_algo)));
    1745            1 :         measurment_block = (void *)(spdm_response + 1);
    1746            1 :         libspdm_set_mem(measurment_block,
    1747              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1748            1 :                         libspdm_get_measurement_hash_size(
    1749              :                             m_libspdm_use_measurement_hash_algo),
    1750              :                         1);
    1751            1 :         measurment_block->measurement_block_common_header.index = 1;
    1752              :         measurment_block->measurement_block_common_header
    1753            1 :         .measurement_specification =
    1754            1 :             (uint8_t)(m_libspdm_use_measurement_spec << 1);
    1755              :         measurment_block->measurement_block_common_header
    1756            1 :         .measurement_size =
    1757            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1758            1 :                        libspdm_get_measurement_hash_size(
    1759              :                            m_libspdm_use_measurement_hash_algo));
    1760              : 
    1761            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1762              :                                               false, spdm_response_size,
    1763              :                                               spdm_response, response_size,
    1764              :                                               response);
    1765              :     }
    1766            1 :         return LIBSPDM_STATUS_SUCCESS;
    1767              : 
    1768          100 :     case 0x16: {
    1769              :         spdm_measurements_response_t *spdm_response;
    1770              :         spdm_measurement_block_dmtf_t *measurment_block;
    1771              :         size_t spdm_response_size;
    1772              :         size_t transport_header_size;
    1773              :         uint8_t *ptr;
    1774              :         ((libspdm_context_t *)spdm_context)
    1775          100 :         ->connection_info.algorithm.measurement_hash_algo =
    1776              :             m_libspdm_use_measurement_hash_algo;
    1777          100 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1778              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1779          100 :                              libspdm_get_measurement_hash_size(
    1780              :             m_libspdm_use_measurement_hash_algo) +
    1781              :                              SPDM_NONCE_SIZE + sizeof(uint16_t);
    1782          100 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1783          100 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1784              : 
    1785          100 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1786          100 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1787          100 :         spdm_response->header.param1 = 0;
    1788          100 :         spdm_response->header.param2 = 0;
    1789          100 :         spdm_response->number_of_blocks = 1;
    1790          100 :         libspdm_write_uint24(
    1791          100 :             spdm_response->measurement_record_length,
    1792              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1793          100 :                        libspdm_get_measurement_hash_size(
    1794              :                            m_libspdm_use_measurement_hash_algo)));
    1795          100 :         measurment_block = (void *)(spdm_response + 1);
    1796          100 :         libspdm_set_mem(measurment_block,
    1797              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1798          100 :                         libspdm_get_measurement_hash_size(
    1799              :                             m_libspdm_use_measurement_hash_algo),
    1800              :                         1);
    1801              :         measurment_block->measurement_block_common_header
    1802          100 :         .measurement_specification =
    1803              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1804              :         measurment_block->measurement_block_common_header
    1805          100 :         .measurement_size =
    1806          100 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1807          100 :                        libspdm_get_measurement_hash_size(
    1808              :                            m_libspdm_use_measurement_hash_algo));
    1809          100 :         *(uint16_t *)((uint8_t *)spdm_response +
    1810              :                       sizeof(spdm_measurements_response_t) +
    1811          100 :                       sizeof(spdm_measurement_block_dmtf_t) +
    1812          100 :                       libspdm_get_measurement_hash_size(
    1813          100 :                           m_libspdm_use_measurement_hash_algo)) = 0;
    1814          100 :         ptr = (uint8_t *)spdm_response + spdm_response_size - SPDM_NONCE_SIZE - sizeof(uint16_t);
    1815          100 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
    1816          100 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1817              :                                               false, spdm_response_size,
    1818              :                                               spdm_response, response_size,
    1819              :                                               response);
    1820              :     }
    1821          100 :         return LIBSPDM_STATUS_SUCCESS;
    1822              : 
    1823            1 :     case 0x17: {
    1824              :         spdm_measurements_response_t *spdm_response;
    1825              :         uint8_t *ptr;
    1826              :         spdm_measurement_block_dmtf_t *measurment_block;
    1827              :         size_t spdm_response_size;
    1828              :         size_t transport_header_size;
    1829              : 
    1830              :         ((libspdm_context_t *)spdm_context)
    1831            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1832              :             m_libspdm_use_measurement_hash_algo;
    1833            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1834              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1835            1 :                              libspdm_get_measurement_hash_size(
    1836              :             m_libspdm_use_measurement_hash_algo) +
    1837              :                              SPDM_NONCE_SIZE +
    1838              :                              sizeof(uint16_t) + SPDM_MAX_OPAQUE_DATA_SIZE;
    1839            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1840            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1841              : 
    1842            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1843            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1844            1 :         spdm_response->header.param1 = 0;
    1845            1 :         spdm_response->header.param2 = 0;
    1846            1 :         spdm_response->number_of_blocks = 1;
    1847            1 :         libspdm_write_uint24(
    1848            1 :             spdm_response->measurement_record_length,
    1849              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1850            1 :                        libspdm_get_measurement_hash_size(
    1851              :                            m_libspdm_use_measurement_hash_algo)));
    1852            1 :         measurment_block = (void *)(spdm_response + 1);
    1853            1 :         libspdm_set_mem(measurment_block,
    1854              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1855            1 :                         libspdm_get_measurement_hash_size(
    1856              :                             m_libspdm_use_measurement_hash_algo),
    1857              :                         1);
    1858              :         measurment_block->measurement_block_common_header
    1859            1 :         .measurement_specification =
    1860              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1861              :         measurment_block->measurement_block_common_header
    1862            1 :         .measurement_size =
    1863            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1864            1 :                        libspdm_get_measurement_hash_size(
    1865              :                            m_libspdm_use_measurement_hash_algo));
    1866              :         /* adding extra fields: opaque_length, opaque_data*/
    1867            1 :         ptr = (void *)((uint8_t *)spdm_response +
    1868              :                        sizeof(spdm_measurements_response_t) +
    1869            1 :                        sizeof(spdm_measurement_block_dmtf_t) +
    1870            1 :                        libspdm_get_measurement_hash_size(
    1871              :                            m_libspdm_use_measurement_hash_algo));
    1872            1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, ptr);
    1873            1 :         ptr += SPDM_NONCE_SIZE;
    1874            1 :         *(uint16_t *)ptr = SPDM_MAX_OPAQUE_DATA_SIZE; /* opaque_length*/
    1875            1 :         ptr += sizeof(uint16_t);
    1876            1 :         libspdm_set_mem(ptr, SPDM_MAX_OPAQUE_DATA_SIZE, 255);
    1877            1 :         ptr += SPDM_MAX_OPAQUE_DATA_SIZE;
    1878              : 
    1879            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1880              :                                               false, spdm_response_size,
    1881              :                                               spdm_response, response_size,
    1882              :                                               response);
    1883              :     }
    1884            1 :         return LIBSPDM_STATUS_SUCCESS;
    1885              : 
    1886            1 :     case 0x18: {
    1887              :         spdm_measurements_response_t *spdm_response;
    1888              :         uint8_t *ptr;
    1889              :         spdm_measurement_block_dmtf_t *measurment_block;
    1890              :         size_t spdm_response_size;
    1891              :         size_t transport_header_size;
    1892              : 
    1893              :         ((libspdm_context_t *)spdm_context)
    1894            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1895              :             m_libspdm_use_measurement_hash_algo;
    1896            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1897              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1898            1 :                              libspdm_get_measurement_hash_size(
    1899              :             m_libspdm_use_measurement_hash_algo) +
    1900              :                              SPDM_NONCE_SIZE +
    1901              :                              sizeof(uint16_t) +
    1902              :                              (SPDM_MAX_OPAQUE_DATA_SIZE + 1);
    1903            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1904            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1905              : 
    1906            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1907            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1908            1 :         spdm_response->header.param1 = 0;
    1909            1 :         spdm_response->header.param2 = 0;
    1910            1 :         spdm_response->number_of_blocks = 1;
    1911            1 :         libspdm_write_uint24(
    1912            1 :             spdm_response->measurement_record_length,
    1913              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1914            1 :                        libspdm_get_measurement_hash_size(
    1915              :                            m_libspdm_use_measurement_hash_algo)));
    1916            1 :         measurment_block = (void *)(spdm_response + 1);
    1917            1 :         libspdm_set_mem(measurment_block,
    1918              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1919            1 :                         libspdm_get_measurement_hash_size(
    1920              :                             m_libspdm_use_measurement_hash_algo),
    1921              :                         1);
    1922              :         measurment_block->measurement_block_common_header
    1923            1 :         .measurement_specification =
    1924              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    1925              :         measurment_block->measurement_block_common_header
    1926            1 :         .measurement_size =
    1927            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    1928            1 :                        libspdm_get_measurement_hash_size(
    1929              :                            m_libspdm_use_measurement_hash_algo));
    1930              :         /* adding extra fields: opaque_length, opaque_data*/
    1931            1 :         ptr = (void *)((uint8_t *)spdm_response +
    1932              :                        sizeof(spdm_measurements_response_t) +
    1933            1 :                        sizeof(spdm_measurement_block_dmtf_t) +
    1934            1 :                        libspdm_get_measurement_hash_size(
    1935              :                            m_libspdm_use_measurement_hash_algo));
    1936            1 :         ptr += SPDM_NONCE_SIZE;
    1937            1 :         *(uint16_t *)ptr =
    1938              :             (SPDM_MAX_OPAQUE_DATA_SIZE + 1); /* opaque_length*/
    1939            1 :         ptr += sizeof(uint16_t);
    1940            1 :         libspdm_set_mem(ptr, (SPDM_MAX_OPAQUE_DATA_SIZE + 1), 255);
    1941            1 :         ptr += (SPDM_MAX_OPAQUE_DATA_SIZE + 1);
    1942              : 
    1943            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1944              :                                               false, spdm_response_size,
    1945              :                                               spdm_response, response_size,
    1946              :                                               response);
    1947              :     }
    1948            1 :         return LIBSPDM_STATUS_SUCCESS;
    1949              : 
    1950            1 :     case 0x19: {
    1951              :         spdm_measurements_response_t *spdm_response;
    1952              :         uint8_t *ptr;
    1953              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    1954              :         size_t sig_size;
    1955              :         size_t measurment_sig_size;
    1956              :         spdm_measurement_block_dmtf_t *measurment_block;
    1957              :         size_t spdm_response_size;
    1958              :         size_t transport_header_size;
    1959            1 :         uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE;
    1960              : 
    1961              :         ((libspdm_context_t *)spdm_context)
    1962            1 :         ->connection_info.algorithm.base_asym_algo =
    1963              :             m_libspdm_use_asym_algo;
    1964              :         ((libspdm_context_t *)spdm_context)
    1965            1 :         ->connection_info.algorithm.base_hash_algo =
    1966              :             m_libspdm_use_hash_algo;
    1967              :         ((libspdm_context_t *)spdm_context)
    1968            1 :         ->connection_info.algorithm.measurement_hash_algo =
    1969              :             m_libspdm_use_measurement_hash_algo;
    1970            1 :         measurment_sig_size =
    1971            2 :             SPDM_NONCE_SIZE + sizeof(uint16_t) + opaque_size_test +
    1972            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    1973            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    1974              :                              sizeof(spdm_measurement_block_dmtf_t) +
    1975            1 :                              libspdm_get_measurement_hash_size(
    1976            1 :             m_libspdm_use_measurement_hash_algo) +
    1977              :                              measurment_sig_size;
    1978            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1979            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1980              : 
    1981            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    1982            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    1983            1 :         spdm_response->header.param1 = 0;
    1984            1 :         spdm_response->header.param2 = 0;
    1985            1 :         spdm_response->number_of_blocks = 1;
    1986            1 :         libspdm_write_uint24(
    1987            1 :             spdm_response->measurement_record_length,
    1988              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    1989            1 :                        libspdm_get_measurement_hash_size(
    1990              :                            m_libspdm_use_measurement_hash_algo)));
    1991            1 :         measurment_block = (void *)(spdm_response + 1);
    1992            1 :         libspdm_set_mem(measurment_block,
    1993              :                         sizeof(spdm_measurement_block_dmtf_t) +
    1994            1 :                         libspdm_get_measurement_hash_size(
    1995              :                             m_libspdm_use_measurement_hash_algo),
    1996              :                         1);
    1997              :         measurment_block->measurement_block_common_header
    1998            1 :         .measurement_specification =
    1999              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2000              :         measurment_block->measurement_block_common_header
    2001            1 :         .measurement_size =
    2002            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2003            1 :                        libspdm_get_measurement_hash_size(
    2004              :                            m_libspdm_use_measurement_hash_algo));
    2005            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    2006              :                        measurment_sig_size);
    2007            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    2008            1 :         ptr += SPDM_NONCE_SIZE;
    2009              : 
    2010            1 :         *(uint16_t *)ptr = opaque_size_test; /* opaque_length*/
    2011            1 :         ptr += sizeof(uint16_t);
    2012            1 :         libspdm_set_mem(ptr, opaque_size_test, 255);
    2013            1 :         ptr += opaque_size_test;
    2014              : 
    2015            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2016              :                          sizeof(m_libspdm_local_buffer)
    2017            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2018              :                             m_libspdm_local_buffer),
    2019            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2020            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2021            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2022              :                        m_libspdm_local_buffer_size));
    2023            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2024            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    2025              :                          m_libspdm_local_buffer_size, hash_data);
    2026            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    2027              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    2028            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2029            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2030            1 :         libspdm_responder_data_sign(
    2031              :             spdm_context,
    2032            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2033              :                 SPDM_MEASUREMENTS,
    2034              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2035              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    2036              :                 ptr, &sig_size);
    2037            1 :         ptr += sig_size;
    2038              : 
    2039            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2040              :                                               false, spdm_response_size,
    2041              :                                               spdm_response, response_size,
    2042              :                                               response);
    2043              :     }
    2044            1 :         return LIBSPDM_STATUS_SUCCESS;
    2045              : 
    2046            1 :     case 0x1A: {
    2047              :         spdm_measurements_response_t *spdm_response;
    2048              :         uint8_t *ptr;
    2049              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2050              :         size_t sig_size;
    2051              :         size_t measurment_sig_size;
    2052              :         spdm_measurement_block_dmtf_t *measurment_block;
    2053              :         size_t spdm_response_size;
    2054              :         size_t transport_header_size;
    2055              :         size_t MissingBytes;
    2056            1 :         uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE;
    2057              : 
    2058            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2059            1 :         MissingBytes = sig_size;
    2060              : 
    2061              :         ((libspdm_context_t *)spdm_context)
    2062            1 :         ->connection_info.algorithm.base_asym_algo =
    2063              :             m_libspdm_use_asym_algo;
    2064              :         ((libspdm_context_t *)spdm_context)
    2065            1 :         ->connection_info.algorithm.base_hash_algo =
    2066              :             m_libspdm_use_hash_algo;
    2067              :         ((libspdm_context_t *)spdm_context)
    2068            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2069              :             m_libspdm_use_measurement_hash_algo;
    2070            1 :         measurment_sig_size =
    2071              :             SPDM_NONCE_SIZE + sizeof(uint16_t) +
    2072            2 :             (opaque_size_test - MissingBytes) +
    2073            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2074            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2075              :                              sizeof(spdm_measurement_block_dmtf_t) +
    2076            1 :                              libspdm_get_measurement_hash_size(
    2077            1 :             m_libspdm_use_measurement_hash_algo) +
    2078              :                              measurment_sig_size;
    2079            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2080            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2081              : 
    2082            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2083            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2084            1 :         spdm_response->header.param1 = 0;
    2085            1 :         spdm_response->header.param2 = 0;
    2086            1 :         spdm_response->number_of_blocks = 1;
    2087            1 :         libspdm_write_uint24(
    2088            1 :             spdm_response->measurement_record_length,
    2089              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2090            1 :                        libspdm_get_measurement_hash_size(
    2091              :                            m_libspdm_use_measurement_hash_algo)));
    2092            1 :         measurment_block = (void *)(spdm_response + 1);
    2093            1 :         libspdm_set_mem(measurment_block,
    2094              :                         sizeof(spdm_measurement_block_dmtf_t) +
    2095            1 :                         libspdm_get_measurement_hash_size(
    2096              :                             m_libspdm_use_measurement_hash_algo),
    2097              :                         1);
    2098              :         measurment_block->measurement_block_common_header
    2099            1 :         .measurement_specification =
    2100              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2101              :         measurment_block->measurement_block_common_header
    2102            1 :         .measurement_size =
    2103            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2104            1 :                        libspdm_get_measurement_hash_size(
    2105              :                            m_libspdm_use_measurement_hash_algo));
    2106            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    2107              :                        measurment_sig_size);
    2108            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    2109            1 :         ptr += SPDM_NONCE_SIZE;
    2110              : 
    2111            1 :         *(uint16_t *)ptr = opaque_size_test; /* opaque_length*/
    2112            1 :         ptr += sizeof(uint16_t);
    2113            1 :         libspdm_set_mem(ptr, opaque_size_test - MissingBytes, 255);
    2114            1 :         ptr += (opaque_size_test - MissingBytes);
    2115              : 
    2116            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2117              :                          sizeof(m_libspdm_local_buffer)
    2118            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2119              :                             m_libspdm_local_buffer),
    2120            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2121            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2122            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2123              :                        m_libspdm_local_buffer_size));
    2124            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2125            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    2126              :                          m_libspdm_local_buffer_size, hash_data);
    2127            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    2128              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    2129            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2130            1 :         libspdm_responder_data_sign(
    2131              :             spdm_context,
    2132            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2133              :                 SPDM_MEASUREMENTS,
    2134              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2135              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    2136              :                 ptr, &sig_size);
    2137            1 :         ptr += sig_size;
    2138              : 
    2139            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2140              :                                               false, spdm_response_size,
    2141              :                                               spdm_response, response_size,
    2142              :                                               response);
    2143              :     }
    2144            1 :         return LIBSPDM_STATUS_SUCCESS;
    2145              : 
    2146            1 :     case 0x1B: {
    2147              :         spdm_measurements_response_t *spdm_response;
    2148              :         uint8_t *ptr;
    2149              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2150              :         size_t sig_size;
    2151              :         size_t measurment_sig_size;
    2152              :         spdm_measurement_block_dmtf_t *measurment_block;
    2153              :         size_t spdm_response_size;
    2154              :         size_t transport_header_size;
    2155              :         size_t MissingBytes;
    2156            1 :         uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE;
    2157              : 
    2158            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2159            1 :         MissingBytes = sig_size + 1;
    2160              : 
    2161              :         ((libspdm_context_t *)spdm_context)
    2162            1 :         ->connection_info.algorithm.base_asym_algo =
    2163              :             m_libspdm_use_asym_algo;
    2164              :         ((libspdm_context_t *)spdm_context)
    2165            1 :         ->connection_info.algorithm.base_hash_algo =
    2166              :             m_libspdm_use_hash_algo;
    2167              :         ((libspdm_context_t *)spdm_context)
    2168            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2169              :             m_libspdm_use_measurement_hash_algo;
    2170            1 :         measurment_sig_size =
    2171              :             SPDM_NONCE_SIZE + sizeof(uint16_t) +
    2172            2 :             (opaque_size_test - MissingBytes) +
    2173            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2174            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2175              :                              sizeof(spdm_measurement_block_dmtf_t) +
    2176            1 :                              libspdm_get_measurement_hash_size(
    2177            1 :             m_libspdm_use_measurement_hash_algo) +
    2178              :                              measurment_sig_size;
    2179            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2180            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2181              : 
    2182            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2183            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2184            1 :         spdm_response->header.param1 = 0;
    2185            1 :         spdm_response->header.param2 = 0;
    2186            1 :         spdm_response->number_of_blocks = 1;
    2187            1 :         libspdm_write_uint24(
    2188            1 :             spdm_response->measurement_record_length,
    2189              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2190            1 :                        libspdm_get_measurement_hash_size(
    2191              :                            m_libspdm_use_measurement_hash_algo)));
    2192            1 :         measurment_block = (void *)(spdm_response + 1);
    2193            1 :         libspdm_set_mem(measurment_block,
    2194              :                         sizeof(spdm_measurement_block_dmtf_t) +
    2195            1 :                         libspdm_get_measurement_hash_size(
    2196              :                             m_libspdm_use_measurement_hash_algo),
    2197              :                         1);
    2198              :         measurment_block->measurement_block_common_header
    2199            1 :         .measurement_specification =
    2200              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2201              :         measurment_block->measurement_block_common_header
    2202            1 :         .measurement_size =
    2203            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2204            1 :                        libspdm_get_measurement_hash_size(
    2205              :                            m_libspdm_use_measurement_hash_algo));
    2206            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    2207              :                        measurment_sig_size);
    2208            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    2209            1 :         ptr += SPDM_NONCE_SIZE;
    2210              : 
    2211            1 :         *(uint16_t *)ptr = opaque_size_test; /* opaque_length*/
    2212            1 :         ptr += sizeof(uint16_t);
    2213            1 :         libspdm_set_mem(ptr, opaque_size_test - MissingBytes, 255);
    2214            1 :         ptr += (opaque_size_test - MissingBytes);
    2215              : 
    2216            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2217              :                          sizeof(m_libspdm_local_buffer)
    2218            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2219              :                             m_libspdm_local_buffer),
    2220            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2221            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2222            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2223              :                        m_libspdm_local_buffer_size));
    2224            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2225            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    2226              :                          m_libspdm_local_buffer_size, hash_data);
    2227            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    2228              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    2229            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2230            1 :         libspdm_responder_data_sign(
    2231              :             spdm_context,
    2232            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2233              :                 SPDM_MEASUREMENTS,
    2234              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2235              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    2236              :                 ptr, &sig_size);
    2237            1 :         ptr += sig_size;
    2238              : 
    2239            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2240              :                                               false, spdm_response_size,
    2241              :                                               spdm_response, response_size,
    2242              :                                               response);
    2243              :     }
    2244            1 :         return LIBSPDM_STATUS_SUCCESS;
    2245              : 
    2246            1 :     case 0x1C: {
    2247              :         spdm_measurements_response_t *spdm_response;
    2248              :         uint8_t *ptr;
    2249              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2250              :         size_t sig_size;
    2251              :         size_t measurment_sig_size;
    2252              :         spdm_measurement_block_dmtf_t *measurment_block;
    2253              :         size_t spdm_response_size;
    2254              :         size_t transport_header_size;
    2255            1 :         uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE / 2;
    2256            1 :         uint16_t opaque_informed_size = opaque_size_test - 1;
    2257              : 
    2258            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2259              : 
    2260              :         ((libspdm_context_t *)spdm_context)
    2261            1 :         ->connection_info.algorithm.base_asym_algo =
    2262              :             m_libspdm_use_asym_algo;
    2263              :         ((libspdm_context_t *)spdm_context)
    2264            1 :         ->connection_info.algorithm.base_hash_algo =
    2265              :             m_libspdm_use_hash_algo;
    2266              :         ((libspdm_context_t *)spdm_context)
    2267            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2268              :             m_libspdm_use_measurement_hash_algo;
    2269            1 :         measurment_sig_size =
    2270            2 :             SPDM_NONCE_SIZE + sizeof(uint16_t) + opaque_size_test +
    2271            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2272            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2273              :                              sizeof(spdm_measurement_block_dmtf_t) +
    2274            1 :                              libspdm_get_measurement_hash_size(
    2275            1 :             m_libspdm_use_measurement_hash_algo) +
    2276              :                              measurment_sig_size;
    2277            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2278            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2279              : 
    2280            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2281            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2282            1 :         spdm_response->header.param1 = 0;
    2283            1 :         spdm_response->header.param2 = 0;
    2284            1 :         spdm_response->number_of_blocks = 1;
    2285            1 :         libspdm_write_uint24(
    2286            1 :             spdm_response->measurement_record_length,
    2287              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2288            1 :                        libspdm_get_measurement_hash_size(
    2289              :                            m_libspdm_use_measurement_hash_algo)));
    2290            1 :         measurment_block = (void *)(spdm_response + 1);
    2291            1 :         libspdm_set_mem(measurment_block,
    2292              :                         sizeof(spdm_measurement_block_dmtf_t) +
    2293            1 :                         libspdm_get_measurement_hash_size(
    2294              :                             m_libspdm_use_measurement_hash_algo),
    2295              :                         1);
    2296              :         measurment_block->measurement_block_common_header
    2297            1 :         .measurement_specification =
    2298              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2299              :         measurment_block->measurement_block_common_header
    2300            1 :         .measurement_size =
    2301            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2302            1 :                        libspdm_get_measurement_hash_size(
    2303              :                            m_libspdm_use_measurement_hash_algo));
    2304            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    2305              :                        measurment_sig_size);
    2306            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    2307            1 :         ptr += SPDM_NONCE_SIZE;
    2308              : 
    2309            1 :         *(uint16_t *)ptr = opaque_informed_size; /* opaque_length*/
    2310            1 :         ptr += sizeof(uint16_t);
    2311            1 :         libspdm_set_mem(ptr, opaque_size_test, 255);
    2312            1 :         ptr += (opaque_size_test);
    2313              : 
    2314            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2315              :                          sizeof(m_libspdm_local_buffer)
    2316            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2317              :                             m_libspdm_local_buffer),
    2318            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2319            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2320            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2321              :                        m_libspdm_local_buffer_size));
    2322            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2323            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    2324              :                          m_libspdm_local_buffer_size, hash_data);
    2325            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    2326              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    2327            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2328            1 :         libspdm_responder_data_sign(
    2329              :             spdm_context,
    2330            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2331              :                 SPDM_MEASUREMENTS,
    2332              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2333              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    2334              :                 ptr, &sig_size);
    2335            1 :         ptr += sig_size;
    2336              : 
    2337            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2338              :                                               false, spdm_response_size,
    2339              :                                               spdm_response, response_size,
    2340              :                                               response);
    2341              :     }
    2342            1 :         return LIBSPDM_STATUS_SUCCESS;
    2343              : 
    2344            1 :     case 0x1D: {
    2345              :         spdm_measurements_response_t *spdm_response;
    2346              :         uint8_t *ptr;
    2347              :         spdm_measurement_block_dmtf_t *measurment_block;
    2348              :         size_t spdm_response_size;
    2349              :         size_t transport_header_size;
    2350            1 :         uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE / 2;
    2351            1 :         uint16_t opaque_informed_size = opaque_size_test - 1;
    2352              : 
    2353              :         ((libspdm_context_t *)spdm_context)
    2354            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2355              :             m_libspdm_use_measurement_hash_algo;
    2356            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2357              :                              sizeof(spdm_measurement_block_dmtf_t) +
    2358            1 :                              libspdm_get_measurement_hash_size(
    2359              :             m_libspdm_use_measurement_hash_algo) +
    2360              :                              SPDM_NONCE_SIZE +
    2361            1 :                              sizeof(uint16_t) + opaque_size_test;
    2362            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2363            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2364              : 
    2365            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2366            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2367            1 :         spdm_response->header.param1 = 0;
    2368            1 :         spdm_response->header.param2 = 0;
    2369            1 :         spdm_response->number_of_blocks = 1;
    2370            1 :         libspdm_write_uint24(
    2371            1 :             spdm_response->measurement_record_length,
    2372              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2373            1 :                        libspdm_get_measurement_hash_size(
    2374              :                            m_libspdm_use_measurement_hash_algo)));
    2375            1 :         measurment_block = (void *)(spdm_response + 1);
    2376            1 :         libspdm_set_mem(measurment_block,
    2377              :                         sizeof(spdm_measurement_block_dmtf_t) +
    2378            1 :                         libspdm_get_measurement_hash_size(
    2379              :                             m_libspdm_use_measurement_hash_algo),
    2380              :                         1);
    2381              :         measurment_block->measurement_block_common_header
    2382            1 :         .measurement_specification =
    2383              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2384              :         measurment_block->measurement_block_common_header
    2385            1 :         .measurement_size =
    2386            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2387            1 :                        libspdm_get_measurement_hash_size(
    2388              :                            m_libspdm_use_measurement_hash_algo));
    2389              :         /* adding extra fields: opaque_length, opaque_data*/
    2390            1 :         ptr = (void *)((uint8_t *)spdm_response +
    2391              :                        sizeof(spdm_measurements_response_t) +
    2392            1 :                        sizeof(spdm_measurement_block_dmtf_t) +
    2393            1 :                        libspdm_get_measurement_hash_size(
    2394              :                            m_libspdm_use_measurement_hash_algo));
    2395            1 :         libspdm_get_random_number (SPDM_NONCE_SIZE, ptr);
    2396            1 :         ptr += SPDM_NONCE_SIZE;
    2397            1 :         *(uint16_t *)ptr = opaque_informed_size; /* opaque_length*/
    2398            1 :         ptr += sizeof(uint16_t);
    2399            1 :         libspdm_set_mem(ptr, opaque_size_test, 255);
    2400            1 :         ptr += opaque_size_test;
    2401              : 
    2402            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2403              :                                               false, spdm_response_size,
    2404              :                                               spdm_response, response_size,
    2405              :                                               response);
    2406              :     }
    2407            1 :         return LIBSPDM_STATUS_SUCCESS;
    2408              : 
    2409            0 :     case 0x1E: {
    2410              :         spdm_measurements_response_t *spdm_response;
    2411              :         uint8_t *ptr;
    2412              :         spdm_measurement_block_dmtf_t *measurment_block;
    2413              :         size_t spdm_response_size;
    2414              :         size_t transport_header_size;
    2415            0 :         uint16_t opaque_size_test = 0xFFFF;
    2416            0 :         uint16_t opaque_informed_size = SPDM_MAX_OPAQUE_DATA_SIZE / 2;
    2417              : 
    2418              :         ((libspdm_context_t *)spdm_context)
    2419            0 :         ->connection_info.algorithm.measurement_hash_algo =
    2420              :             m_libspdm_use_measurement_hash_algo;
    2421            0 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2422              :                              sizeof(spdm_measurement_block_dmtf_t) +
    2423            0 :                              libspdm_get_measurement_hash_size(
    2424              :             m_libspdm_use_measurement_hash_algo) +
    2425              :                              SPDM_NONCE_SIZE +
    2426            0 :                              sizeof(uint16_t) + opaque_size_test;
    2427            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2428            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2429              : 
    2430            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2431            0 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2432            0 :         spdm_response->header.param1 = 0;
    2433            0 :         spdm_response->header.param2 = 0;
    2434            0 :         spdm_response->number_of_blocks = 1;
    2435            0 :         libspdm_write_uint24(
    2436            0 :             spdm_response->measurement_record_length,
    2437              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2438            0 :                        libspdm_get_measurement_hash_size(
    2439              :                            m_libspdm_use_measurement_hash_algo)));
    2440            0 :         measurment_block = (void *)(spdm_response + 1);
    2441            0 :         libspdm_set_mem(measurment_block,
    2442              :                         sizeof(spdm_measurement_block_dmtf_t) +
    2443            0 :                         libspdm_get_measurement_hash_size(
    2444              :                             m_libspdm_use_measurement_hash_algo),
    2445              :                         1);
    2446              :         measurment_block->measurement_block_common_header
    2447            0 :         .measurement_specification =
    2448              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2449              :         measurment_block->measurement_block_common_header
    2450            0 :         .measurement_size =
    2451            0 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2452            0 :                        libspdm_get_measurement_hash_size(
    2453              :                            m_libspdm_use_measurement_hash_algo));
    2454              :         /* adding extra fields: NONCE, opaque_length, opaque_data*/
    2455            0 :         ptr = (void *)((uint8_t *)spdm_response +
    2456              :                        sizeof(spdm_measurements_response_t) +
    2457            0 :                        sizeof(spdm_measurement_block_dmtf_t) +
    2458            0 :                        libspdm_get_measurement_hash_size(
    2459              :                            m_libspdm_use_measurement_hash_algo));
    2460            0 :         ptr += SPDM_NONCE_SIZE;
    2461            0 :         *(uint16_t *)ptr = opaque_informed_size; /* opaque_length*/
    2462            0 :         ptr += sizeof(uint16_t);
    2463            0 :         libspdm_set_mem(ptr, opaque_size_test, 255);
    2464            0 :         ptr += opaque_size_test;
    2465              : 
    2466            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2467              :                                               false, spdm_response_size,
    2468              :                                               spdm_response, response_size,
    2469              :                                               response);
    2470              :     }
    2471            0 :         return LIBSPDM_STATUS_SUCCESS;
    2472              : 
    2473            0 :     case 0x1F: {
    2474              :         spdm_measurements_response_t *spdm_response;
    2475              :         uint8_t *ptr;
    2476              :         spdm_measurement_block_dmtf_t *measurment_block;
    2477              :         size_t spdm_response_size;
    2478              :         size_t transport_header_size;
    2479            0 :         uint16_t opaque_size_test = 0xFFFF;
    2480              : 
    2481              :         ((libspdm_context_t *)spdm_context)
    2482            0 :         ->connection_info.algorithm.measurement_hash_algo =
    2483              :             m_libspdm_use_measurement_hash_algo;
    2484            0 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2485              :                              sizeof(spdm_measurement_block_dmtf_t) +
    2486            0 :                              libspdm_get_measurement_hash_size(
    2487              :             m_libspdm_use_measurement_hash_algo) +
    2488            0 :                              SPDM_NONCE_SIZE + sizeof(uint16_t) +
    2489              :                              opaque_size_test;
    2490            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2491            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2492              : 
    2493            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2494            0 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2495            0 :         spdm_response->header.param1 = 0;
    2496            0 :         spdm_response->header.param2 = 0;
    2497            0 :         spdm_response->number_of_blocks = 1;
    2498            0 :         libspdm_write_uint24(
    2499            0 :             spdm_response->measurement_record_length,
    2500              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2501            0 :                        libspdm_get_measurement_hash_size(
    2502              :                            m_libspdm_use_measurement_hash_algo)));
    2503            0 :         measurment_block = (void *)(spdm_response + 1);
    2504            0 :         libspdm_set_mem(measurment_block,
    2505              :                         sizeof(spdm_measurement_block_dmtf_t) +
    2506            0 :                         libspdm_get_measurement_hash_size(
    2507              :                             m_libspdm_use_measurement_hash_algo),
    2508              :                         1);
    2509              :         measurment_block->measurement_block_common_header
    2510            0 :         .measurement_specification =
    2511              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2512              :         measurment_block->measurement_block_common_header
    2513            0 :         .measurement_size =
    2514            0 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2515            0 :                        libspdm_get_measurement_hash_size(
    2516              :                            m_libspdm_use_measurement_hash_algo));
    2517              :         /* adding extra fields: NONCE, opaque_length, opaque_data*/
    2518            0 :         ptr = (void *)((uint8_t *)spdm_response +
    2519              :                        sizeof(spdm_measurements_response_t) +
    2520            0 :                        sizeof(spdm_measurement_block_dmtf_t) +
    2521            0 :                        libspdm_get_measurement_hash_size(
    2522              :                            m_libspdm_use_measurement_hash_algo));
    2523            0 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    2524            0 :         ptr += SPDM_NONCE_SIZE;
    2525            0 :         *(uint16_t *)ptr = (opaque_size_test); /* opaque_length*/
    2526            0 :         ptr += sizeof(uint16_t);
    2527            0 :         libspdm_set_mem(ptr, (opaque_size_test), 255);
    2528            0 :         ptr += (opaque_size_test);
    2529              : 
    2530            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2531              :                                               false, spdm_response_size,
    2532              :                                               spdm_response, response_size,
    2533              :                                               response);
    2534              :     }
    2535            0 :         return LIBSPDM_STATUS_SUCCESS;
    2536              : 
    2537            1 :     case 0x20: {
    2538              :         spdm_measurements_response_t *spdm_response;
    2539              :         spdm_measurement_block_dmtf_t *measurment_block;
    2540              :         size_t spdm_response_size;
    2541              :         size_t transport_header_size;
    2542              :         uint8_t *ptr;
    2543              :         ((libspdm_context_t *)spdm_context)
    2544            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2545              :             m_libspdm_use_measurement_hash_algo;
    2546            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2547              :                              2 * (sizeof(spdm_measurement_block_dmtf_t) +
    2548            1 :                                   libspdm_get_measurement_hash_size(
    2549            1 :                                       m_libspdm_use_measurement_hash_algo)) +
    2550              :                              SPDM_NONCE_SIZE;
    2551            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2552            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2553              : 
    2554            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2555            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2556            1 :         spdm_response->header.param1 = 0;
    2557            1 :         spdm_response->header.param2 = 0;
    2558            1 :         spdm_response->number_of_blocks = 2;
    2559            1 :         *(uint32_t *)spdm_response->measurement_record_length =
    2560            1 :             2 * ((uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2561            1 :                             libspdm_get_measurement_hash_size(
    2562              :                                 m_libspdm_use_measurement_hash_algo)));
    2563            1 :         measurment_block = (void *)(spdm_response + 1);
    2564            1 :         libspdm_set_mem(measurment_block,
    2565            1 :                         2 * (sizeof(spdm_measurement_block_dmtf_t) +
    2566            1 :                              libspdm_get_measurement_hash_size(
    2567              :                                  m_libspdm_use_measurement_hash_algo)),
    2568              :                         1);
    2569            1 :         measurment_block->measurement_block_common_header.index = 1;
    2570              :         measurment_block->measurement_block_common_header
    2571            1 :         .measurement_specification =
    2572              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2573              :         measurment_block->measurement_block_common_header
    2574            1 :         .measurement_size =
    2575            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2576            1 :                        libspdm_get_measurement_hash_size(
    2577              :                            m_libspdm_use_measurement_hash_algo));
    2578            1 :         measurment_block =
    2579              :             (void *)(((uint8_t *)measurment_block) +
    2580            1 :                      (sizeof(spdm_measurement_block_dmtf_t) +
    2581            1 :                       libspdm_get_measurement_hash_size(
    2582              :                           m_libspdm_use_measurement_hash_algo)));
    2583            1 :         measurment_block->measurement_block_common_header.index = 2;
    2584              :         measurment_block->measurement_block_common_header
    2585            1 :         .measurement_specification =
    2586              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2587              :         measurment_block->measurement_block_common_header
    2588            1 :         .measurement_size =
    2589            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2590            1 :                        libspdm_get_measurement_hash_size(
    2591              :                            m_libspdm_use_measurement_hash_algo));
    2592            1 :         ptr =  (uint8_t *)spdm_response + spdm_response_size - SPDM_NONCE_SIZE;
    2593            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
    2594            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2595              :                                               false, spdm_response_size,
    2596              :                                               spdm_response, response_size,
    2597              :                                               response);
    2598              :     }
    2599            1 :         return LIBSPDM_STATUS_SUCCESS;
    2600              : 
    2601           18 :     case 0x21:
    2602              :     {
    2603              :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
    2604              : 
    2605              :         spdm_error_response_t *spdm_response;
    2606              :         size_t spdm_response_size;
    2607              :         size_t transport_header_size;
    2608              : 
    2609           18 :         spdm_response_size = sizeof(spdm_error_response_t);
    2610           18 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2611           18 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2612              : 
    2613           18 :         if(error_code <= 0xff) {
    2614           18 :             libspdm_zero_mem (spdm_response, spdm_response_size);
    2615           18 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2616           18 :             spdm_response->header.request_response_code = SPDM_ERROR;
    2617           18 :             spdm_response->header.param1 = (uint8_t) error_code;
    2618           18 :             spdm_response->header.param2 = 0;
    2619              : 
    2620           18 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
    2621              :                                                    spdm_response_size, spdm_response,
    2622              :                                                    response_size, response);
    2623              :         }
    2624              : 
    2625           18 :         error_code++;
    2626           18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
    2627            1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
    2628              :         }
    2629           18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
    2630            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
    2631              :         }
    2632           18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
    2633            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
    2634              :         }
    2635              :     }
    2636           18 :         return LIBSPDM_STATUS_SUCCESS;
    2637            1 :     case 0x22: {
    2638              :         spdm_measurements_response_t *spdm_response;
    2639              :         uint8_t *ptr;
    2640              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2641              :         size_t sig_size;
    2642              :         size_t measurment_sig_size;
    2643              :         spdm_measurement_block_dmtf_t *measurment_block;
    2644              :         size_t spdm_response_size;
    2645              :         size_t transport_header_size;
    2646              :         uint32_t session_id;
    2647              :         libspdm_session_info_t *session_info;
    2648              :         uint8_t *scratch_buffer;
    2649              :         size_t scratch_buffer_size;
    2650              : 
    2651            1 :         session_id = 0xFFFFFFFF;
    2652              :         ((libspdm_context_t *)spdm_context)
    2653            1 :         ->connection_info.algorithm.base_asym_algo =
    2654              :             m_libspdm_use_asym_algo;
    2655              :         ((libspdm_context_t *)spdm_context)
    2656            1 :         ->connection_info.algorithm.base_hash_algo =
    2657              :             m_libspdm_use_hash_algo;
    2658              :         ((libspdm_context_t *)spdm_context)
    2659            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2660              :             m_libspdm_use_measurement_hash_algo;
    2661            1 :         measurment_sig_size =
    2662              :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
    2663            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2664            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2665              :                              sizeof(spdm_measurement_block_dmtf_t) +
    2666            1 :                              libspdm_get_measurement_hash_size(
    2667            1 :             m_libspdm_use_measurement_hash_algo) +
    2668              :                              measurment_sig_size;
    2669            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2670            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2671              : 
    2672            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2673            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2674            1 :         spdm_response->header.param1 = 0;
    2675            1 :         spdm_response->header.param2 = 0;
    2676            1 :         spdm_response->number_of_blocks = 1;
    2677            1 :         libspdm_write_uint24(
    2678            1 :             spdm_response->measurement_record_length,
    2679              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2680            1 :                        libspdm_get_measurement_hash_size(
    2681              :                            m_libspdm_use_measurement_hash_algo)));
    2682            1 :         measurment_block = (void *)(spdm_response + 1);
    2683            1 :         libspdm_set_mem(measurment_block,
    2684              :                         sizeof(spdm_measurement_block_dmtf_t) +
    2685            1 :                         libspdm_get_measurement_hash_size(
    2686              :                             m_libspdm_use_measurement_hash_algo),
    2687              :                         1);
    2688              :         measurment_block->measurement_block_common_header
    2689            1 :         .measurement_specification =
    2690              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2691              :         measurment_block->measurement_block_common_header
    2692            1 :         .measurement_size =
    2693            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2694            1 :                        libspdm_get_measurement_hash_size(
    2695              :                            m_libspdm_use_measurement_hash_algo));
    2696            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    2697              :                        measurment_sig_size);
    2698            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    2699            1 :         ptr += SPDM_NONCE_SIZE;
    2700            1 :         *(uint16_t *)ptr = 0;
    2701            1 :         ptr += sizeof(uint16_t);
    2702            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2703              :                          sizeof(m_libspdm_local_buffer)
    2704            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2705              :                             m_libspdm_local_buffer),
    2706            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2707            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2708            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2709              :                        m_libspdm_local_buffer_size));
    2710            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2711            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    2712              :                          m_libspdm_local_buffer_size, hash_data);
    2713            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    2714              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    2715            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2716            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2717            1 :         libspdm_responder_data_sign(
    2718              :             spdm_context,
    2719            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2720              :                 SPDM_MEASUREMENTS,
    2721              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2722              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    2723              :                 ptr, &sig_size);
    2724            1 :         ptr += sig_size;
    2725              : 
    2726              :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
    2727              :          * transport_message is always in sender buffer. */
    2728            1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
    2729            1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
    2730              :                           scratch_buffer_size - transport_header_size,
    2731              :                           spdm_response, spdm_response_size);
    2732            1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
    2733            1 :         libspdm_transport_test_encode_message(spdm_context, &session_id, false,
    2734              :                                               false, spdm_response_size,
    2735              :                                               spdm_response, response_size,
    2736              :                                               response);
    2737            1 :         session_info = libspdm_get_session_info_via_session_id(
    2738              :             spdm_context, session_id);
    2739            1 :         if (session_info == NULL) {
    2740            0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
    2741              :         }
    2742              :         /* WALKAROUND: If just use single context to encode message and then decode message */
    2743            1 :         ((libspdm_secured_message_context_t *)(session_info->secured_message_context))
    2744            1 :         ->application_secret.response_data_sequence_number--;
    2745              :     }
    2746            1 :         return LIBSPDM_STATUS_SUCCESS;
    2747              : 
    2748            1 :     case 0x23: {
    2749              :         spdm_measurements_response_t *spdm_response;
    2750              :         spdm_measurement_block_dmtf_t *measurment_block;
    2751              :         size_t spdm_response_size;
    2752              :         size_t transport_header_size;
    2753              :         uint8_t *ptr;
    2754            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
    2755              :             m_libspdm_use_measurement_hash_algo;
    2756            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2757              :                              sizeof(spdm_measurement_block_dmtf_t) +
    2758            1 :                              libspdm_get_measurement_hash_size(
    2759              :             m_libspdm_use_measurement_hash_algo) + SPDM_NONCE_SIZE + sizeof(uint16_t);
    2760            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2761            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2762              : 
    2763            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
    2764            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2765            1 :         spdm_response->header.param1 = 0;
    2766            1 :         spdm_response->header.param2 = 0;
    2767            1 :         spdm_response->number_of_blocks = 1;
    2768            1 :         libspdm_write_uint24(
    2769            1 :             spdm_response->measurement_record_length,
    2770              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2771            1 :                        libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)));
    2772            1 :         measurment_block = (void *)(spdm_response + 1);
    2773            1 :         libspdm_set_mem(measurment_block,
    2774              :                         sizeof(spdm_measurement_block_dmtf_t) +
    2775            1 :                         libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo), 1);
    2776            1 :         measurment_block->measurement_block_common_header.measurement_specification =
    2777              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2778            1 :         measurment_block->measurement_block_common_header.measurement_size =
    2779            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2780            1 :                        libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo));
    2781              : 
    2782            1 :         ptr = (uint8_t *)spdm_response +
    2783              :               sizeof(spdm_measurements_response_t) +
    2784            1 :               sizeof(spdm_measurement_block_dmtf_t) +
    2785            1 :               libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo);
    2786            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    2787            1 :         *(uint16_t *)(ptr + SPDM_NONCE_SIZE) = 0;
    2788              : 
    2789            1 :         libspdm_copy_mem (m_libspdm_local_buffer + m_libspdm_local_buffer_size,
    2790              :                           sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
    2791              :                           spdm_response, spdm_response_size);
    2792            1 :         m_libspdm_local_buffer_size += spdm_response_size;
    2793              : 
    2794            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2795              :                                               false, spdm_response_size,
    2796              :                                               spdm_response, response_size,
    2797              :                                               response);
    2798              :     }
    2799            1 :         return LIBSPDM_STATUS_SUCCESS;
    2800              : 
    2801            1 :     case 0x24: {
    2802              :         spdm_measurements_response_t *spdm_response;
    2803              :         uint8_t *ptr;
    2804              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2805              :         size_t sig_size;
    2806              :         size_t measurment_sig_size;
    2807              :         spdm_measurement_block_dmtf_t *measurment_block;
    2808              :         size_t spdm_response_size;
    2809              :         size_t transport_header_size;
    2810              : 
    2811              :         ((libspdm_context_t *)spdm_context)
    2812            1 :         ->connection_info.algorithm.base_asym_algo =
    2813              :             m_libspdm_use_asym_algo;
    2814              :         ((libspdm_context_t *)spdm_context)
    2815            1 :         ->connection_info.algorithm.base_hash_algo =
    2816              :             m_libspdm_use_hash_algo;
    2817              :         ((libspdm_context_t *)spdm_context)
    2818            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2819              :             m_libspdm_use_measurement_hash_algo;
    2820            1 :         measurment_sig_size =
    2821              :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
    2822            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2823            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2824              :                              sizeof(spdm_measurement_block_dmtf_t) +
    2825            1 :                              libspdm_get_measurement_hash_size(
    2826            1 :             m_libspdm_use_measurement_hash_algo) +
    2827              :                              measurment_sig_size;
    2828            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2829            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2830              : 
    2831            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    2832            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2833            1 :         spdm_response->header.param1 = 0;
    2834            1 :         spdm_response->header.param2 = 0;
    2835            1 :         spdm_response->number_of_blocks = 1;
    2836            1 :         libspdm_write_uint24(
    2837            1 :             spdm_response->measurement_record_length,
    2838              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2839            1 :                        libspdm_get_measurement_hash_size(
    2840              :                            m_libspdm_use_measurement_hash_algo)));
    2841            1 :         measurment_block = (void *)(spdm_response + 1);
    2842            1 :         libspdm_set_mem(measurment_block,
    2843              :                         sizeof(spdm_measurement_block_dmtf_t) +
    2844            1 :                         libspdm_get_measurement_hash_size(
    2845              :                             m_libspdm_use_measurement_hash_algo),
    2846              :                         1);
    2847              :         measurment_block->measurement_block_common_header
    2848            1 :         .measurement_specification =
    2849              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2850              :         measurment_block->measurement_block_common_header
    2851            1 :         .measurement_size =
    2852            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2853            1 :                        libspdm_get_measurement_hash_size(
    2854              :                            m_libspdm_use_measurement_hash_algo));
    2855            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    2856              :                        measurment_sig_size);
    2857            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    2858            1 :         ptr += SPDM_NONCE_SIZE;
    2859            1 :         *(uint16_t *)ptr = 0;
    2860            1 :         ptr += sizeof(uint16_t);
    2861            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2862              :                          sizeof(m_libspdm_local_buffer)
    2863            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2864              :                             m_libspdm_local_buffer),
    2865            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2866            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2867            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2868              :                        m_libspdm_local_buffer_size));
    2869            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2870            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    2871              :                          m_libspdm_local_buffer_size, hash_data);
    2872            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    2873              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    2874            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2875            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2876            1 :         libspdm_responder_data_sign(
    2877              :             spdm_context,
    2878            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2879              :                 SPDM_MEASUREMENTS,
    2880              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    2881              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    2882              :                 ptr, &sig_size);
    2883            1 :         ptr += sig_size;
    2884              : 
    2885            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2886              :                                               false, spdm_response_size,
    2887              :                                               spdm_response, response_size,
    2888              :                                               response);
    2889              :     }
    2890            1 :         return LIBSPDM_STATUS_SUCCESS;
    2891            1 :     case 0x25: {
    2892              :         spdm_measurements_response_t *spdm_response;
    2893              :         size_t spdm_response_size;
    2894              :         size_t transport_header_size;
    2895              :         uint8_t *ptr;
    2896            1 :         spdm_response_size =
    2897              :             sizeof(spdm_measurements_response_t)
    2898              :             + SPDM_NONCE_SIZE + sizeof(uint16_t);
    2899            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2900            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2901            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    2902            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2903            1 :         spdm_response->header.param1 = 4;
    2904            1 :         spdm_response->header.param2 = 0;
    2905            1 :         spdm_response->number_of_blocks = 0;
    2906            1 :         libspdm_write_uint24(spdm_response->measurement_record_length, 0);
    2907              : 
    2908            1 :         ptr = (uint8_t *)spdm_response +
    2909              :               sizeof(spdm_measurements_response_t);
    2910            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
    2911            1 :         ptr += SPDM_NONCE_SIZE;
    2912            1 :         *(uint16_t *)ptr = 0;
    2913              : 
    2914            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    2915              :                                               false, spdm_response_size,
    2916              :                                               spdm_response, response_size,
    2917              :                                               response);
    2918              :     }
    2919            1 :         return LIBSPDM_STATUS_SUCCESS;
    2920            1 :     case 0x26: {
    2921              :         spdm_measurements_response_t *spdm_response;
    2922              :         uint8_t *ptr;
    2923              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    2924              :         size_t sig_size;
    2925              :         size_t measurment_sig_size;
    2926              :         spdm_measurement_block_dmtf_t *measurment_block;
    2927              :         size_t spdm_response_size;
    2928              :         size_t transport_header_size;
    2929              : 
    2930              :         ((libspdm_context_t *)spdm_context)
    2931            1 :         ->connection_info.algorithm.base_asym_algo =
    2932              :             m_libspdm_use_asym_algo;
    2933              :         ((libspdm_context_t *)spdm_context)
    2934            1 :         ->connection_info.algorithm.base_hash_algo =
    2935              :             m_libspdm_use_hash_algo;
    2936              :         ((libspdm_context_t *)spdm_context)
    2937            1 :         ->connection_info.algorithm.measurement_hash_algo =
    2938              :             m_libspdm_use_measurement_hash_algo;
    2939            1 :         measurment_sig_size =
    2940              :             SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
    2941            1 :             libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2942            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    2943              :                              sizeof(spdm_measurement_block_dmtf_t) +
    2944            1 :                              libspdm_get_measurement_hash_size(
    2945            1 :             m_libspdm_use_measurement_hash_algo) +
    2946              :                              measurment_sig_size;
    2947            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    2948            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    2949              : 
    2950            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    2951            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    2952            1 :         spdm_response->header.param1 = 0;
    2953            1 :         spdm_response->header.param2 = 0x0F;
    2954            1 :         spdm_response->number_of_blocks = 1;
    2955            1 :         libspdm_write_uint24(
    2956            1 :             spdm_response->measurement_record_length,
    2957              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    2958            1 :                        libspdm_get_measurement_hash_size(
    2959              :                            m_libspdm_use_measurement_hash_algo)));
    2960            1 :         measurment_block = (void *)(spdm_response + 1);
    2961            1 :         libspdm_set_mem(measurment_block,
    2962              :                         sizeof(spdm_measurement_block_dmtf_t) +
    2963            1 :                         libspdm_get_measurement_hash_size(
    2964              :                             m_libspdm_use_measurement_hash_algo),
    2965              :                         1);
    2966              :         measurment_block->measurement_block_common_header
    2967            1 :         .measurement_specification =
    2968              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    2969              :         measurment_block->measurement_block_common_header
    2970            1 :         .measurement_size =
    2971            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    2972            1 :                        libspdm_get_measurement_hash_size(
    2973              :                            m_libspdm_use_measurement_hash_algo));
    2974            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size -
    2975              :                        measurment_sig_size);
    2976            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
    2977            1 :         ptr += SPDM_NONCE_SIZE;
    2978            1 :         *(uint16_t *)ptr = 0;
    2979            1 :         ptr += sizeof(uint16_t);
    2980            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    2981              :                          sizeof(m_libspdm_local_buffer)
    2982            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    2983              :                             m_libspdm_local_buffer),
    2984            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    2985            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    2986            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    2987              :                        m_libspdm_local_buffer_size));
    2988            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2989            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    2990              :                          m_libspdm_local_buffer_size, hash_data);
    2991            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    2992              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    2993            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    2994            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    2995            1 :         libspdm_responder_data_sign(
    2996              :             spdm_context,
    2997            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    2998              :                 SPDM_MEASUREMENTS,
    2999              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    3000              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    3001              :                 ptr, &sig_size);
    3002            1 :         ptr += sig_size;
    3003              : 
    3004            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3005              :                                               false, spdm_response_size,
    3006              :                                               spdm_response, response_size,
    3007              :                                               response);
    3008              :     }
    3009            1 :         return LIBSPDM_STATUS_SUCCESS;
    3010            1 :     case 0x27: {
    3011              :         spdm_measurements_response_t *spdm_response;
    3012              :         spdm_general_opaque_data_table_header_t
    3013              :         *spdm_general_opaque_data_table_header;
    3014              :         opaque_element_table_header_t
    3015              :         *opaque_element_table_header;
    3016              :         uint8_t *ptr;
    3017              :         uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
    3018              :         size_t sig_size;
    3019              :         size_t measurment_sig_size;
    3020              :         spdm_measurement_block_dmtf_t *measurment_block;
    3021              :         size_t spdm_response_size;
    3022              :         size_t transport_header_size;
    3023              :         uint8_t element_num;
    3024              :         uint8_t element_index;
    3025              :         size_t current_element_len;
    3026              :         uint16_t opaque_element_data_len;
    3027              : 
    3028              :         ((libspdm_context_t *)spdm_context)
    3029            1 :         ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3030              :         ((libspdm_context_t *)spdm_context)
    3031            1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3032              :         ((libspdm_context_t *)spdm_context)
    3033            1 :         ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
    3034              : 
    3035            1 :         spdm_general_opaque_data_table_header = (void *)m_libspdm_opaque_data;
    3036            1 :         spdm_general_opaque_data_table_header->total_elements = 2;
    3037            1 :         opaque_element_table_header = (void *)(spdm_general_opaque_data_table_header + 1);
    3038              : 
    3039            1 :         element_num = spdm_general_opaque_data_table_header->total_elements;
    3040            1 :         m_libspdm_opaque_data_size = sizeof(spdm_general_opaque_data_table_header_t);
    3041              : 
    3042            3 :         for (element_index = 0; element_index < element_num; element_index++) {
    3043            2 :             opaque_element_table_header->id = SPDM_REGISTRY_ID_MAX;
    3044            2 :             opaque_element_table_header->vendor_len = 0;
    3045            2 :             opaque_element_data_len = (uint16_t)strlen("libspdm");
    3046              : 
    3047            2 :             ptr = (void *)(opaque_element_table_header + 1);
    3048            2 :             ptr += opaque_element_table_header->vendor_len;
    3049              : 
    3050            2 :             libspdm_copy_mem((uint16_t *)ptr,
    3051              :                              sizeof(opaque_element_data_len),
    3052              :                              &opaque_element_data_len,
    3053              :                              sizeof(opaque_element_data_len));
    3054              : 
    3055            2 :             libspdm_copy_mem(ptr + sizeof(opaque_element_data_len),
    3056              :                              SPDM_MAX_OPAQUE_DATA_SIZE -
    3057              :                              sizeof(opaque_element_table_header_t), "libspdm",
    3058              :                              strlen("libspdm"));
    3059              : 
    3060            2 :             current_element_len = sizeof(opaque_element_table_header_t) +
    3061            2 :                                   opaque_element_table_header->vendor_len +
    3062            2 :                                   sizeof(opaque_element_data_len) +
    3063              :                                   opaque_element_data_len;
    3064            2 :             current_element_len = (current_element_len + 3) & ~3;
    3065              : 
    3066              :             /*move to next element*/
    3067            2 :             opaque_element_table_header =
    3068              :                 (opaque_element_table_header_t *)
    3069              :                 ((uint8_t *)opaque_element_table_header +
    3070              :                  current_element_len);
    3071              : 
    3072            2 :             m_libspdm_opaque_data_size += current_element_len;
    3073              :         }
    3074              : 
    3075            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    3076              : 
    3077            1 :         measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) +
    3078            1 :                               m_libspdm_opaque_data_size +
    3079            1 :                               libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    3080            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    3081              :                              sizeof(spdm_measurement_block_dmtf_t) +
    3082            1 :                              libspdm_get_measurement_hash_size(
    3083            1 :             m_libspdm_use_measurement_hash_algo) + measurment_sig_size;
    3084            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    3085              : 
    3086            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
    3087            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    3088            1 :         spdm_response->header.param1 = 0;
    3089            1 :         spdm_response->header.param2 = 0;
    3090            1 :         spdm_response->number_of_blocks = 1;
    3091            1 :         libspdm_write_uint24(
    3092            1 :             spdm_response->measurement_record_length,
    3093              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    3094            1 :                        libspdm_get_measurement_hash_size(
    3095              :                            m_libspdm_use_measurement_hash_algo)));
    3096            1 :         measurment_block = (void *)(spdm_response + 1);
    3097            1 :         libspdm_set_mem(measurment_block,
    3098              :                         sizeof(spdm_measurement_block_dmtf_t) +
    3099            1 :                         libspdm_get_measurement_hash_size(
    3100              :                             m_libspdm_use_measurement_hash_algo), 1);
    3101              :         measurment_block->measurement_block_common_header
    3102            1 :         .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3103            1 :         measurment_block->measurement_block_common_header.measurement_size =
    3104            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    3105            1 :                        libspdm_get_measurement_hash_size(
    3106              :                            m_libspdm_use_measurement_hash_algo));
    3107            1 :         ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
    3108            1 :         libspdm_set_mem(ptr, SPDM_NONCE_SIZE, 0x12);
    3109            1 :         ptr += SPDM_NONCE_SIZE;
    3110              : 
    3111            1 :         *(uint16_t *)ptr = (uint16_t)m_libspdm_opaque_data_size;
    3112            1 :         ptr += sizeof(uint16_t);
    3113            1 :         libspdm_copy_mem(ptr, (size_t)(*response) + *response_size - (size_t)ptr,
    3114              :                          m_libspdm_opaque_data,
    3115              :                          m_libspdm_opaque_data_size);
    3116            1 :         ptr += m_libspdm_opaque_data_size;
    3117              : 
    3118            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
    3119              :                          sizeof(m_libspdm_local_buffer)
    3120            1 :                          - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
    3121              :                             m_libspdm_local_buffer),
    3122            1 :                          spdm_response, (size_t)ptr - (size_t)spdm_response);
    3123            1 :         m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
    3124            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
    3125              :                        m_libspdm_local_buffer_size));
    3126            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3127            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
    3128              :                          m_libspdm_local_buffer_size, hash_data);
    3129            1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
    3130              :                        libspdm_get_hash_size(m_libspdm_use_hash_algo)));
    3131            1 :         libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    3132            1 :         sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
    3133            1 :         libspdm_responder_data_sign(
    3134              :             spdm_context,
    3135            1 :             spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
    3136              :                 SPDM_MEASUREMENTS,
    3137              :                 m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
    3138              :                 false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
    3139              :                 ptr, &sig_size);
    3140            1 :         ptr += sig_size;
    3141              : 
    3142            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3143              :                                               false, spdm_response_size,
    3144              :                                               spdm_response, response_size,
    3145              :                                               response);
    3146              :     }
    3147            1 :         return LIBSPDM_STATUS_SUCCESS;
    3148            1 :     case 0x28: {
    3149              :         spdm_measurements_response_t *spdm_response;
    3150              :         spdm_measurement_block_dmtf_t *measurment_block;
    3151              :         size_t spdm_response_size;
    3152              :         size_t transport_header_size;
    3153              :         uint8_t *ptr;
    3154              :         ((libspdm_context_t *)spdm_context)
    3155            1 :         ->connection_info.algorithm.measurement_hash_algo =
    3156              :             m_libspdm_use_measurement_hash_algo;
    3157            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    3158              :                              sizeof(spdm_measurement_block_dmtf_t) +
    3159            1 :                              libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)
    3160              :                              + SPDM_NONCE_SIZE + sizeof(uint16_t) + SPDM_REQ_CONTEXT_SIZE;
    3161              : 
    3162            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    3163            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    3164              : 
    3165            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
    3166            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    3167            1 :         spdm_response->header.param1 = 0;
    3168            1 :         spdm_response->header.param2 = 0;
    3169            1 :         spdm_response->number_of_blocks = 1;
    3170            1 :         libspdm_write_uint24(
    3171            1 :             spdm_response->measurement_record_length,
    3172              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    3173            1 :                        libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
    3174              : 
    3175            1 :         measurment_block = (void *)(spdm_response + 1);
    3176            1 :         libspdm_set_mem(measurment_block,
    3177              :                         sizeof(spdm_measurement_block_dmtf_t) +
    3178            1 :                         libspdm_get_measurement_hash_size(
    3179              :                             m_libspdm_use_measurement_hash_algo),
    3180              :                         1);
    3181              : 
    3182              :         measurment_block->measurement_block_common_header
    3183            1 :         .measurement_specification =
    3184              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3185              :         measurment_block->measurement_block_common_header
    3186            1 :         .measurement_size =
    3187            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    3188            1 :                        libspdm_get_measurement_hash_size(
    3189              :                            m_libspdm_use_measurement_hash_algo));
    3190              : 
    3191            1 :         ptr = (uint8_t *)spdm_response +
    3192              :               sizeof(spdm_measurements_response_t) +
    3193            1 :               sizeof(spdm_measurement_block_dmtf_t) +
    3194            1 :               libspdm_get_measurement_hash_size(
    3195              :             m_libspdm_use_measurement_hash_algo);
    3196            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
    3197              : 
    3198            1 :         ptr += SPDM_NONCE_SIZE;
    3199            1 :         *(uint16_t *)ptr = 0;
    3200              : 
    3201            1 :         ptr += sizeof(uint16_t);
    3202            1 :         libspdm_copy_mem(ptr, SPDM_REQ_CONTEXT_SIZE, m_requester_context, SPDM_REQ_CONTEXT_SIZE);
    3203              : 
    3204            1 :         libspdm_copy_mem(m_libspdm_local_buffer + m_libspdm_local_buffer_size,
    3205              :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
    3206              :                          spdm_response, spdm_response_size);
    3207              : 
    3208            1 :         m_libspdm_local_buffer_size += spdm_response_size;
    3209              : 
    3210            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3211              :                                               false, spdm_response_size,
    3212              :                                               spdm_response, response_size,
    3213              :                                               response);
    3214              :     }
    3215            1 :         return LIBSPDM_STATUS_SUCCESS;
    3216            1 :     case 0x29: {
    3217              :         spdm_measurements_response_t *spdm_response;
    3218              :         spdm_measurement_block_dmtf_t *measurment_block;
    3219              :         size_t spdm_response_size;
    3220              :         size_t transport_header_size;
    3221              :         uint8_t *ptr;
    3222              :         ((libspdm_context_t *)spdm_context)
    3223            1 :         ->connection_info.algorithm.measurement_hash_algo =
    3224              :             m_libspdm_use_measurement_hash_algo;
    3225            1 :         spdm_response_size = sizeof(spdm_measurements_response_t) +
    3226              :                              sizeof(spdm_measurement_block_dmtf_t) +
    3227            1 :                              libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)
    3228              :                              +
    3229              :                              SPDM_NONCE_SIZE + sizeof(uint16_t) + SPDM_REQ_CONTEXT_SIZE;
    3230              : 
    3231            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    3232            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    3233              : 
    3234            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
    3235            1 :         spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
    3236            1 :         spdm_response->header.param1 = 0;
    3237            1 :         spdm_response->header.param2 = 0;
    3238            1 :         spdm_response->number_of_blocks = 1;
    3239            1 :         libspdm_write_uint24(
    3240            1 :             spdm_response->measurement_record_length,
    3241              :             (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
    3242            1 :                        libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
    3243              : 
    3244            1 :         measurment_block = (void *)(spdm_response + 1);
    3245            1 :         libspdm_set_mem(measurment_block,
    3246              :                         sizeof(spdm_measurement_block_dmtf_t) +
    3247            1 :                         libspdm_get_measurement_hash_size(
    3248              :                             m_libspdm_use_measurement_hash_algo),
    3249              :                         1);
    3250              : 
    3251              :         measurment_block->measurement_block_common_header
    3252            1 :         .measurement_specification =
    3253              :             SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3254              :         measurment_block->measurement_block_common_header
    3255            1 :         .measurement_size =
    3256            1 :             (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
    3257            1 :                        libspdm_get_measurement_hash_size(
    3258              :                            m_libspdm_use_measurement_hash_algo));
    3259              : 
    3260            1 :         ptr = (uint8_t *)spdm_response +
    3261              :               sizeof(spdm_measurements_response_t) +
    3262            1 :               sizeof(spdm_measurement_block_dmtf_t) +
    3263            1 :               libspdm_get_measurement_hash_size(
    3264              :             m_libspdm_use_measurement_hash_algo);
    3265            1 :         libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
    3266              : 
    3267            1 :         ptr += SPDM_NONCE_SIZE;
    3268            1 :         *(uint16_t *)ptr = 0;
    3269              : 
    3270            1 :         ptr += sizeof(uint16_t);
    3271            1 :         libspdm_get_random_number(SPDM_REQ_CONTEXT_SIZE,ptr);
    3272              : 
    3273            1 :         libspdm_copy_mem(m_libspdm_local_buffer + m_libspdm_local_buffer_size,
    3274              :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
    3275              :                          spdm_response, spdm_response_size);
    3276              : 
    3277            1 :         m_libspdm_local_buffer_size += spdm_response_size;
    3278              : 
    3279            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    3280              :                                               false, spdm_response_size,
    3281              :                                               spdm_response, response_size,
    3282              :                                               response);
    3283              :     }
    3284            1 :         return LIBSPDM_STATUS_SUCCESS;
    3285            0 :     default:
    3286            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
    3287              :     }
    3288              : }
    3289              : 
    3290              : /**
    3291              :  * Test 1: message could not be sent
    3292              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
    3293              :  **/
    3294            1 : static void req_get_measurements_case1(void **state)
    3295              : {
    3296              :     libspdm_return_t status;
    3297              :     libspdm_test_context_t *spdm_test_context;
    3298              :     libspdm_context_t *spdm_context;
    3299              :     uint8_t number_of_block;
    3300              :     uint32_t measurement_record_length;
    3301              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    3302              :     uint8_t request_attribute;
    3303              :     void *data;
    3304              :     size_t data_size;
    3305              :     void *hash;
    3306              :     size_t hash_size;
    3307              : 
    3308            1 :     spdm_test_context = *state;
    3309            1 :     spdm_context = spdm_test_context->spdm_context;
    3310            1 :     spdm_test_context->case_id = 0x1;
    3311            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3312              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3313            1 :     spdm_context->connection_info.connection_state =
    3314              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    3315            1 :     spdm_context->connection_info.capability.flags |=
    3316              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    3317            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3318              :                                                          m_libspdm_use_asym_algo, &data,
    3319              :                                                          &data_size, &hash, &hash_size)) {
    3320            0 :         assert(false);
    3321              :     }
    3322            1 :     libspdm_reset_message_m(spdm_context, NULL);
    3323            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    3324              :         m_libspdm_use_measurement_spec;
    3325            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    3326              :         m_libspdm_use_measurement_hash_algo;
    3327            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3328              :         m_libspdm_use_hash_algo;
    3329            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3330              :         m_libspdm_use_asym_algo;
    3331            1 :     spdm_context->local_context.algorithm.measurement_spec =
    3332              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3333              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3334              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3335              :         data_size;
    3336              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3337              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3338              :                      data, data_size);
    3339              : #else
    3340            1 :     libspdm_hash_all(
    3341              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3342              :         data, data_size,
    3343            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3344            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3345            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3346            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3347              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3348              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3349              :         data, data_size,
    3350              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3351              : #endif
    3352              : 
    3353            1 :     request_attribute =
    3354              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    3355              : 
    3356            1 :     measurement_record_length = sizeof(measurement_record);
    3357            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    3358              :                                      0, NULL, &number_of_block,
    3359              :                                      &measurement_record_length,
    3360              :                                      measurement_record);
    3361            1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
    3362              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3363              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    3364              : #endif
    3365            1 :     free(data);
    3366            1 : }
    3367              : 
    3368              : /**
    3369              :  * Test 2: Successful response to get a measurement with signature
    3370              :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, with an empty transcript.message_m
    3371              :  **/
    3372            1 : static void req_get_measurements_case2(void **state)
    3373              : {
    3374              :     libspdm_return_t status;
    3375              :     libspdm_test_context_t *spdm_test_context;
    3376              :     libspdm_context_t *spdm_context;
    3377              :     uint8_t number_of_block;
    3378              :     uint32_t measurement_record_length;
    3379              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    3380              :     uint8_t request_attribute;
    3381              :     void *data;
    3382              :     size_t data_size;
    3383              :     void *hash;
    3384              :     size_t hash_size;
    3385              : 
    3386            1 :     spdm_test_context = *state;
    3387            1 :     spdm_context = spdm_test_context->spdm_context;
    3388            1 :     spdm_test_context->case_id = 0x2;
    3389            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3390              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3391            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    3392            1 :     spdm_context->connection_info.capability.flags |=
    3393              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    3394            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3395              :                                                          m_libspdm_use_asym_algo, &data,
    3396              :                                                          &data_size, &hash, &hash_size)) {
    3397            0 :         assert(false);
    3398              :     }
    3399            1 :     libspdm_reset_message_m(spdm_context, NULL);
    3400            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    3401            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    3402              :         m_libspdm_use_measurement_hash_algo;
    3403            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3404            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3405            1 :     spdm_context->local_context.algorithm.measurement_spec =
    3406              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3407              : 
    3408              :     #if LIBSPDM_ENABLE_MSG_LOG
    3409            1 :     libspdm_init_msg_log (spdm_context, m_libspdm_msg_log_buffer, sizeof(m_libspdm_msg_log_buffer));
    3410            1 :     libspdm_set_msg_log_mode (spdm_context, LIBSPDM_MSG_LOG_MODE_ENABLE);
    3411              :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
    3412              : 
    3413              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3414              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
    3415              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3416              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3417              :                      data, data_size);
    3418              : #else
    3419            1 :     libspdm_hash_all(
    3420              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3421              :         data, data_size,
    3422            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3423            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3424            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3425            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3426              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3427              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3428              :         data, data_size,
    3429              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3430              : #endif
    3431              : 
    3432            1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    3433              : 
    3434            1 :     measurement_record_length = sizeof(measurement_record);
    3435            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    3436              :                                      0, NULL, &number_of_block,
    3437              :                                      &measurement_record_length,
    3438              :                                      measurement_record);
    3439            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3440              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3441              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    3442              : #endif
    3443            1 :     free(data);
    3444              : 
    3445              :     #if LIBSPDM_ENABLE_MSG_LOG
    3446            1 :     libspdm_reset_msg_log(spdm_context);
    3447              :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
    3448            1 : }
    3449              : 
    3450              : /**
    3451              :  * Test 3: Exercise the libspdm_get_measurement_ex function.
    3452              :  * Expected Behavior: Requester uses requester_nonce_in and returns responder_nonce.
    3453              :  **/
    3454            1 : static void req_get_measurements_case3(void **state)
    3455              : {
    3456              :     libspdm_return_t status;
    3457              :     libspdm_test_context_t *spdm_test_context;
    3458              :     libspdm_context_t *spdm_context;
    3459              :     uint8_t number_of_block;
    3460              :     uint32_t measurement_record_length;
    3461              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    3462              :     uint8_t request_attribute;
    3463              :     void *data;
    3464              :     size_t data_size;
    3465              :     void *hash;
    3466              :     size_t hash_size;
    3467              :     uint8_t requester_nonce_in[SPDM_NONCE_SIZE];
    3468              :     uint8_t requester_nonce[SPDM_NONCE_SIZE];
    3469              :     uint8_t responder_nonce[SPDM_NONCE_SIZE];
    3470              :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
    3471              :     size_t opaque_data_size;
    3472              : 
    3473            1 :     spdm_test_context = *state;
    3474            1 :     spdm_context = spdm_test_context->spdm_context;
    3475            1 :     spdm_test_context->case_id = 0x3;
    3476            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3477              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3478            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    3479            1 :     spdm_context->connection_info.capability.flags |=
    3480              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    3481            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3482              :                                                          m_libspdm_use_asym_algo, &data,
    3483              :                                                          &data_size, &hash, &hash_size)) {
    3484            0 :         assert(false);
    3485              :     }
    3486            1 :     libspdm_reset_message_m(spdm_context, NULL);
    3487            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    3488            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    3489              :         m_libspdm_use_measurement_hash_algo;
    3490            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3491            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3492            1 :     spdm_context->local_context.algorithm.measurement_spec =
    3493              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3494              : 
    3495              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3496              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
    3497              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3498              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3499              :                      data, data_size);
    3500              : #else
    3501            1 :     libspdm_hash_all(
    3502              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3503              :         data, data_size,
    3504            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3505            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3506            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3507            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3508              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3509              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3510              :         data, data_size,
    3511              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3512              : #endif
    3513              : 
    3514            1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    3515              : 
    3516            1 :     measurement_record_length = sizeof(measurement_record);
    3517              : 
    3518           33 :     for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
    3519           32 :         requester_nonce_in[index] = 0x5c;
    3520           32 :         requester_nonce[index] = 0x00;
    3521           32 :         responder_nonce[index] = 0x00;
    3522              :     }
    3523              : 
    3524            1 :     opaque_data_size = sizeof(opaque_data);
    3525              : 
    3526            1 :     status = libspdm_get_measurement_ex(spdm_context, NULL, request_attribute, 1,
    3527              :                                         0, NULL, &number_of_block,
    3528              :                                         &measurement_record_length,
    3529              :                                         measurement_record, requester_nonce_in,
    3530              :                                         requester_nonce, responder_nonce,
    3531              :                                         opaque_data, &opaque_data_size);
    3532            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3533           33 :     for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
    3534           32 :         assert_int_equal (requester_nonce_in[index], requester_nonce[index]);
    3535           32 :         assert_int_equal (responder_nonce[index], 0x12);
    3536              :     }
    3537            1 :     assert_int_equal(opaque_data_size, strlen("libspdm"));
    3538            1 :     assert_memory_equal(opaque_data, "libspdm", strlen("libspdm"));
    3539              : 
    3540              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3541              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    3542              : #endif
    3543            1 :     free(data);
    3544            1 : }
    3545              : 
    3546              : /**
    3547              :  * Test 4: Error case, always get an error response with code SPDM_ERROR_CODE_INVALID_REQUEST
    3548              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
    3549              :  **/
    3550            1 : static void req_get_measurements_case4(void **state)
    3551              : {
    3552              :     libspdm_return_t status;
    3553              :     libspdm_test_context_t *spdm_test_context;
    3554              :     libspdm_context_t *spdm_context;
    3555              :     uint8_t number_of_block;
    3556              :     uint32_t measurement_record_length;
    3557              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    3558              :     uint8_t request_attribute;
    3559              :     void *data;
    3560              :     size_t data_size;
    3561              :     void *hash;
    3562              :     size_t hash_size;
    3563              : 
    3564            1 :     spdm_test_context = *state;
    3565            1 :     spdm_context = spdm_test_context->spdm_context;
    3566            1 :     spdm_test_context->case_id = 0x4;
    3567            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3568              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3569            1 :     spdm_context->connection_info.connection_state =
    3570              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    3571            1 :     spdm_context->connection_info.capability.flags |=
    3572              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    3573            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3574              :                                                          m_libspdm_use_asym_algo, &data,
    3575              :                                                          &data_size, &hash, &hash_size)) {
    3576            0 :         assert(false);
    3577              :     }
    3578            1 :     libspdm_reset_message_m(spdm_context, NULL);
    3579            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    3580              :         m_libspdm_use_measurement_spec;
    3581            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    3582              :         m_libspdm_use_measurement_hash_algo;
    3583            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3584              :         m_libspdm_use_hash_algo;
    3585            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3586              :         m_libspdm_use_asym_algo;
    3587            1 :     spdm_context->local_context.algorithm.measurement_spec =
    3588              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3589              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3590              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3591              :         data_size;
    3592              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3593              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3594              :                      data, data_size);
    3595              : #else
    3596            1 :     libspdm_hash_all(
    3597              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3598              :         data, data_size,
    3599            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3600            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3601            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3602            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3603              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3604              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3605              :         data, data_size,
    3606              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3607              : #endif
    3608              : 
    3609            1 :     request_attribute =
    3610              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    3611              : 
    3612            1 :     measurement_record_length = sizeof(measurement_record);
    3613            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    3614              :                                      0, NULL, &number_of_block,
    3615              :                                      &measurement_record_length,
    3616              :                                      measurement_record);
    3617            1 :     assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
    3618              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3619              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    3620              : #endif
    3621            1 :     free(data);
    3622            1 : }
    3623              : 
    3624              : /**
    3625              :  * Test 5: Error case, always get an error response with code SPDM_ERROR_CODE_BUSY
    3626              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
    3627              :  **/
    3628            1 : static void req_get_measurements_case5(void **state)
    3629              : {
    3630              :     libspdm_return_t status;
    3631              :     libspdm_test_context_t *spdm_test_context;
    3632              :     libspdm_context_t *spdm_context;
    3633              :     uint8_t number_of_block;
    3634              :     uint32_t measurement_record_length;
    3635              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    3636              :     uint8_t request_attribute;
    3637              :     void *data;
    3638              :     size_t data_size;
    3639              :     void *hash;
    3640              :     size_t hash_size;
    3641              : 
    3642            1 :     spdm_test_context = *state;
    3643            1 :     spdm_context = spdm_test_context->spdm_context;
    3644            1 :     spdm_test_context->case_id = 0x5;
    3645            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3646              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3647            1 :     spdm_context->connection_info.connection_state =
    3648              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    3649            1 :     spdm_context->connection_info.capability.flags |=
    3650              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    3651            1 :     spdm_context->local_context.algorithm.measurement_spec =
    3652              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3653            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3654              :                                                          m_libspdm_use_asym_algo, &data,
    3655              :                                                          &data_size, &hash, &hash_size)) {
    3656            0 :         assert(false);
    3657              :     }
    3658            1 :     libspdm_reset_message_m(spdm_context, NULL);
    3659            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    3660              :         m_libspdm_use_measurement_spec;
    3661            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    3662              :         m_libspdm_use_measurement_hash_algo;
    3663            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3664              :         m_libspdm_use_hash_algo;
    3665            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3666              :         m_libspdm_use_asym_algo;
    3667              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3668              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3669              :         data_size;
    3670              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3671              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3672              :                      data, data_size);
    3673              : #else
    3674            1 :     libspdm_hash_all(
    3675              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3676              :         data, data_size,
    3677            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3678            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3679            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3680            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3681              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3682              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3683              :         data, data_size,
    3684              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3685              : #endif
    3686              : 
    3687            1 :     request_attribute =
    3688              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    3689              : 
    3690            1 :     measurement_record_length = sizeof(measurement_record);
    3691            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    3692              :                                      0, NULL, &number_of_block,
    3693              :                                      &measurement_record_length,
    3694              :                                      measurement_record);
    3695            1 :     assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
    3696              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3697              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    3698              : #endif
    3699            1 :     free(data);
    3700            1 : }
    3701              : 
    3702              : /**
    3703              :  * Test 6: Successfully get one measurement block (signed), after getting SPDM_ERROR_CODE_BUSY on first attempt
    3704              :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, with an empty transcript.message_m
    3705              :  **/
    3706            1 : static void req_get_measurements_case6(void **state)
    3707              : {
    3708              :     libspdm_return_t status;
    3709              :     libspdm_test_context_t *spdm_test_context;
    3710              :     libspdm_context_t *spdm_context;
    3711              :     uint8_t number_of_block;
    3712              :     uint32_t measurement_record_length;
    3713              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    3714              :     uint8_t request_attribute;
    3715              :     void *data;
    3716              :     size_t data_size;
    3717              :     void *hash;
    3718              :     size_t hash_size;
    3719              : 
    3720            1 :     spdm_test_context = *state;
    3721            1 :     spdm_context = spdm_test_context->spdm_context;
    3722            1 :     spdm_test_context->case_id = 0x6;
    3723            1 :     spdm_context->retry_times = 3;
    3724            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3725              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3726            1 :     spdm_context->connection_info.connection_state =
    3727              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    3728            1 :     spdm_context->connection_info.capability.flags |=
    3729              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    3730            1 :     spdm_context->local_context.algorithm.measurement_spec =
    3731              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3732            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3733              :                                                          m_libspdm_use_asym_algo, &data,
    3734              :                                                          &data_size, &hash, &hash_size)) {
    3735            0 :         assert(false);
    3736              :     }
    3737            1 :     libspdm_reset_message_m(spdm_context, NULL);
    3738            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    3739              :         m_libspdm_use_measurement_spec;
    3740            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    3741              :         m_libspdm_use_measurement_hash_algo;
    3742            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3743              :         m_libspdm_use_hash_algo;
    3744            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3745              :         m_libspdm_use_asym_algo;
    3746              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3747              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3748              :         data_size;
    3749              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3750              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3751              :                      data, data_size);
    3752              : #else
    3753            1 :     libspdm_hash_all(
    3754              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3755              :         data, data_size,
    3756            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3757            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3758            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3759            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3760              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3761              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3762              :         data, data_size,
    3763              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3764              : #endif
    3765              : 
    3766            1 :     request_attribute =
    3767              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    3768              : 
    3769            1 :     measurement_record_length = sizeof(measurement_record);
    3770            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    3771              :                                      0, NULL, &number_of_block,
    3772              :                                      &measurement_record_length,
    3773              :                                      measurement_record);
    3774            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    3775              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3776              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    3777              : #endif
    3778            1 :     free(data);
    3779            1 : }
    3780              : 
    3781              : /**
    3782              :  * Test 7: Error case, get an error response with code SPDM_ERROR_CODE_REQUEST_RESYNCH
    3783              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
    3784              :  **/
    3785            1 : static void req_get_measurements_case7(void **state)
    3786              : {
    3787              :     libspdm_return_t status;
    3788              :     libspdm_test_context_t *spdm_test_context;
    3789              :     libspdm_context_t *spdm_context;
    3790              :     uint8_t number_of_block;
    3791              :     uint32_t measurement_record_length;
    3792              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    3793              :     uint8_t request_attribute;
    3794              :     void *data;
    3795              :     size_t data_size;
    3796              :     void *hash;
    3797              :     size_t hash_size;
    3798              : 
    3799            1 :     spdm_test_context = *state;
    3800            1 :     spdm_context = spdm_test_context->spdm_context;
    3801            1 :     spdm_test_context->case_id = 0x7;
    3802            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3803              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3804            1 :     spdm_context->connection_info.connection_state =
    3805              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    3806            1 :     spdm_context->connection_info.capability.flags |=
    3807              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    3808            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3809              :                                                          m_libspdm_use_asym_algo, &data,
    3810              :                                                          &data_size, &hash, &hash_size)) {
    3811            0 :         assert(false);
    3812              :     }
    3813            1 :     libspdm_reset_message_m(spdm_context, NULL);
    3814            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    3815              :         m_libspdm_use_measurement_spec;
    3816            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    3817              :         m_libspdm_use_measurement_hash_algo;
    3818            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3819              :         m_libspdm_use_hash_algo;
    3820            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3821              :         m_libspdm_use_asym_algo;
    3822            1 :     spdm_context->local_context.algorithm.measurement_spec =
    3823              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3824              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3825              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3826              :         data_size;
    3827              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3828              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3829              :                      data, data_size);
    3830              : #else
    3831            1 :     libspdm_hash_all(
    3832              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3833              :         data, data_size,
    3834            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3835            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3836            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3837            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3838              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3839              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3840              :         data, data_size,
    3841              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3842              : #endif
    3843              : 
    3844            1 :     request_attribute =
    3845              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    3846              : 
    3847            1 :     measurement_record_length = sizeof(measurement_record);
    3848            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    3849              :                                      0, NULL, &number_of_block,
    3850              :                                      &measurement_record_length,
    3851              :                                      measurement_record);
    3852            1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
    3853            1 :     assert_int_equal(spdm_context->connection_info.connection_state,
    3854              :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
    3855              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3856              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    3857              : #endif
    3858            1 :     free(data);
    3859            1 : }
    3860              : 
    3861              : /**
    3862              :  * Test 8: Error case, always get an error response with code SPDM_ERROR_CODE_RESPONSE_NOT_READY
    3863              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
    3864              :  **/
    3865            1 : static void req_get_measurements_case8(void **state)
    3866              : {
    3867              :     libspdm_return_t status;
    3868              :     libspdm_test_context_t *spdm_test_context;
    3869              :     libspdm_context_t *spdm_context;
    3870              :     uint8_t number_of_block;
    3871              :     uint32_t measurement_record_length;
    3872              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    3873              :     uint8_t request_attribute;
    3874              :     void *data;
    3875              :     size_t data_size;
    3876              :     void *hash;
    3877              :     size_t hash_size;
    3878              : 
    3879            1 :     spdm_test_context = *state;
    3880            1 :     spdm_context = spdm_test_context->spdm_context;
    3881            1 :     spdm_test_context->case_id = 0x8;
    3882            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3883              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3884            1 :     spdm_context->connection_info.connection_state =
    3885              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    3886            1 :     spdm_context->connection_info.capability.flags |=
    3887              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    3888            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3889              :                                                          m_libspdm_use_asym_algo, &data,
    3890              :                                                          &data_size, &hash, &hash_size)) {
    3891            0 :         assert(false);
    3892              :     }
    3893            1 :     libspdm_reset_message_m(spdm_context, NULL);
    3894            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    3895              :         m_libspdm_use_measurement_spec;
    3896            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    3897              :         m_libspdm_use_measurement_hash_algo;
    3898            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    3899              :         m_libspdm_use_hash_algo;
    3900            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    3901              :         m_libspdm_use_asym_algo;
    3902            1 :     spdm_context->local_context.algorithm.measurement_spec =
    3903              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3904              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3905              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    3906              :         data_size;
    3907              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3908              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3909              :                      data, data_size);
    3910              : #else
    3911            1 :     libspdm_hash_all(
    3912              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3913              :         data, data_size,
    3914            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3915            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3916            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3917            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3918              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3919              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3920              :         data, data_size,
    3921              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3922              : #endif
    3923              : 
    3924            1 :     request_attribute =
    3925              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    3926              : 
    3927            1 :     measurement_record_length = sizeof(measurement_record);
    3928            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    3929              :                                      0, NULL, &number_of_block,
    3930              :                                      &measurement_record_length,
    3931              :                                      measurement_record);
    3932            1 :     assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
    3933            1 :     free(data);
    3934            1 : }
    3935              : 
    3936              : /**
    3937              :  * Test 9: Successfully get one measurement block (signed), after getting SPDM_ERROR_CODE_RESPONSE_NOT_READY on first attempt
    3938              :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, with an empty transcript.message_m
    3939              :  **/
    3940            1 : static void req_get_measurements_case9(void **state)
    3941              : {
    3942              :     libspdm_return_t status;
    3943              :     libspdm_test_context_t *spdm_test_context;
    3944              :     libspdm_context_t *spdm_context;
    3945              :     uint8_t number_of_block;
    3946              :     uint32_t measurement_record_length;
    3947              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    3948              :     uint8_t request_attribute;
    3949              :     void *data;
    3950              :     size_t data_size;
    3951              :     void *hash;
    3952              :     size_t hash_size;
    3953              : 
    3954            1 :     spdm_test_context = *state;
    3955            1 :     spdm_context = spdm_test_context->spdm_context;
    3956            1 :     spdm_test_context->case_id = 0x9;
    3957            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    3958              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    3959            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    3960            1 :     spdm_context->connection_info.capability.flags |=
    3961              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    3962            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    3963              :                                                          m_libspdm_use_asym_algo, &data,
    3964              :                                                          &data_size, &hash, &hash_size)) {
    3965            0 :         assert(false);
    3966              :     }
    3967            1 :     libspdm_reset_message_m(spdm_context, NULL);
    3968            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    3969            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    3970              :         m_libspdm_use_measurement_hash_algo;
    3971            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    3972            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    3973            1 :     spdm_context->local_context.algorithm.measurement_spec =
    3974              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    3975              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    3976              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
    3977              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    3978              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    3979              :                      data, data_size);
    3980              : #else
    3981            1 :     libspdm_hash_all(
    3982              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3983              :         data, data_size,
    3984            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    3985            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    3986            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    3987            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    3988              :         spdm_context->connection_info.algorithm.base_hash_algo,
    3989              :         spdm_context->connection_info.algorithm.base_asym_algo,
    3990              :         data, data_size,
    3991              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    3992              : #endif
    3993              : 
    3994            1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    3995              : 
    3996            1 :     measurement_record_length = sizeof(measurement_record);
    3997            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    3998              :                                      0, NULL, &number_of_block,
    3999              :                                      &measurement_record_length,
    4000              :                                      measurement_record);
    4001              :     if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
    4002            1 :         assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4003              :     } else {
    4004              :         assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
    4005              :     }
    4006              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4007              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    4008              : #endif
    4009            1 :     free(data);
    4010            1 : }
    4011              : 
    4012              : /**
    4013              :  * Test 10: Successful response to get total number of measurements, without signature
    4014              :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, correct number_of_blocks, correct transcript.message_m.buffer_size
    4015              :  **/
    4016            1 : static void req_get_measurements_case10(void **state)
    4017              : {
    4018              :     libspdm_return_t status;
    4019              :     libspdm_test_context_t *spdm_test_context;
    4020              :     libspdm_context_t *spdm_context;
    4021              :     uint8_t number_of_blocks;
    4022              :     uint8_t request_attribute;
    4023              :     void *data;
    4024              :     size_t data_size;
    4025              :     void *hash;
    4026              :     size_t hash_size;
    4027              : 
    4028            1 :     spdm_test_context = *state;
    4029            1 :     spdm_context = spdm_test_context->spdm_context;
    4030            1 :     spdm_test_context->case_id = 0xA;
    4031            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4032              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4033            1 :     spdm_context->connection_info.connection_state =
    4034              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4035            1 :     spdm_context->connection_info.capability.flags |=
    4036              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4037            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4038              :                                                          m_libspdm_use_asym_algo, &data,
    4039              :                                                          &data_size, &hash, &hash_size)) {
    4040            0 :         assert(false);
    4041              :     }
    4042            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4043            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4044              :         m_libspdm_use_measurement_spec;
    4045            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4046              :         m_libspdm_use_measurement_hash_algo;
    4047            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4048              :         m_libspdm_use_hash_algo;
    4049            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4050              :         m_libspdm_use_asym_algo;
    4051            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4052              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4053              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4054              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4055              :         data_size;
    4056              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4057              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4058              :                      data, data_size);
    4059              : #else
    4060            1 :     libspdm_hash_all(
    4061              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4062              :         data, data_size,
    4063            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4064            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4065            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4066            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4067              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4068              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4069              :         data, data_size,
    4070              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4071              : #endif
    4072              : 
    4073            1 :     request_attribute = 0;
    4074              : 
    4075            1 :     status = libspdm_get_measurement(
    4076              :         spdm_context, NULL, request_attribute,
    4077              :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS,
    4078              :         0, NULL, &number_of_blocks, NULL, NULL);
    4079            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4080            1 :     assert_int_equal(number_of_blocks, 4);
    4081              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4082              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    4083              :                      sizeof(spdm_message_header_t) +
    4084              :                      sizeof(spdm_measurements_response_t) +
    4085              :                      SPDM_NONCE_SIZE + sizeof(uint16_t));
    4086              : #endif
    4087            1 :     free(data);
    4088            1 : }
    4089              : 
    4090              : /**
    4091              :  * Test 11: Successful response to get a measurement block, without signature
    4092              :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, correct transcript.message_m.buffer_size
    4093              :  **/
    4094            1 : static void req_get_measurements_case11(void **state)
    4095              : {
    4096              :     libspdm_return_t status;
    4097              :     libspdm_test_context_t *spdm_test_context;
    4098              :     libspdm_context_t *spdm_context;
    4099              :     uint8_t number_of_block;
    4100              :     uint32_t measurement_record_length;
    4101              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    4102              :     uint8_t request_attribute;
    4103              :     void *data;
    4104              :     size_t data_size;
    4105              :     void *hash;
    4106              :     size_t hash_size;
    4107              : 
    4108            1 :     spdm_test_context = *state;
    4109            1 :     spdm_context = spdm_test_context->spdm_context;
    4110            1 :     spdm_test_context->case_id = 0xB;
    4111            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4112              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4113            1 :     spdm_context->connection_info.connection_state =
    4114              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4115            1 :     spdm_context->connection_info.capability.flags |=
    4116              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4117            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4118              :                                                          m_libspdm_use_asym_algo, &data,
    4119              :                                                          &data_size, &hash, &hash_size)) {
    4120            0 :         assert(false);
    4121              :     }
    4122            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4123            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4124              :         m_libspdm_use_measurement_spec;
    4125            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4126              :         m_libspdm_use_measurement_hash_algo;
    4127            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4128              :         m_libspdm_use_hash_algo;
    4129            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4130              :         m_libspdm_use_asym_algo;
    4131            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4132              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4133              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4134              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4135              :         data_size;
    4136              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4137              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4138              :                      data, data_size);
    4139              : #else
    4140            1 :     libspdm_hash_all(
    4141              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4142              :         data, data_size,
    4143            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4144            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4145            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4146            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4147              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4148              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4149              :         data, data_size,
    4150              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4151              : #endif
    4152              : 
    4153            1 :     request_attribute = 0;
    4154              : 
    4155            1 :     measurement_record_length = sizeof(measurement_record);
    4156            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    4157              :                                      0, NULL, &number_of_block,
    4158              :                                      &measurement_record_length,
    4159              :                                      measurement_record);
    4160            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4161              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4162              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    4163              :                      sizeof(spdm_message_header_t) +
    4164              :                      sizeof(spdm_measurements_response_t) +
    4165              :                      sizeof(spdm_measurement_block_dmtf_t) +
    4166              :                      libspdm_get_measurement_hash_size(
    4167              :                          m_libspdm_use_measurement_hash_algo) +
    4168              :                      SPDM_NONCE_SIZE + sizeof(uint16_t));
    4169              : #endif
    4170            1 :     free(data);
    4171            1 : }
    4172              : 
    4173              : /**
    4174              :  * Test 12: Error case, signature is invalid (all bytes are 0)
    4175              :  * Expected Behavior: get a RETURN_SECURITY_VIOLATION return code
    4176              :  **/
    4177            1 : static void req_get_measurements_case12(void **state)
    4178              : {
    4179              :     libspdm_return_t status;
    4180              :     libspdm_test_context_t *spdm_test_context;
    4181              :     libspdm_context_t *spdm_context;
    4182              :     uint8_t number_of_block;
    4183              :     uint32_t measurement_record_length;
    4184              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    4185              :     uint8_t request_attribute;
    4186              :     void *data;
    4187              :     size_t data_size;
    4188              :     void *hash;
    4189              :     size_t hash_size;
    4190              : 
    4191            1 :     spdm_test_context = *state;
    4192            1 :     spdm_context = spdm_test_context->spdm_context;
    4193            1 :     spdm_test_context->case_id = 0xC;
    4194              : 
    4195            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4196              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4197            1 :     spdm_context->connection_info.connection_state =
    4198              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4199            1 :     spdm_context->connection_info.capability.flags |=
    4200              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4201            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4202              :                                                          m_libspdm_use_asym_algo, &data,
    4203              :                                                          &data_size, &hash, &hash_size)) {
    4204            0 :         assert(false);
    4205              :     }
    4206            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4207            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4208              :         m_libspdm_use_measurement_spec;
    4209            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4210              :         m_libspdm_use_measurement_hash_algo;
    4211            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4212              :         m_libspdm_use_hash_algo;
    4213            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4214              :         m_libspdm_use_asym_algo;
    4215            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4216              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4217              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4218              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4219              :         data_size;
    4220              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4221              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4222              :                      data, data_size);
    4223              : #else
    4224            1 :     libspdm_hash_all(
    4225              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4226              :         data, data_size,
    4227            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4228            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4229            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4230            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4231              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4232              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4233              :         data, data_size,
    4234              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4235              : #endif
    4236              : 
    4237            1 :     request_attribute =
    4238              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    4239              : 
    4240            1 :     measurement_record_length = sizeof(measurement_record);
    4241            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    4242              :                                      0, NULL, &number_of_block,
    4243              :                                      &measurement_record_length,
    4244              :                                      measurement_record);
    4245            1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
    4246              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4247              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    4248              : #endif
    4249            1 :     free(data);
    4250            1 : }
    4251              : 
    4252              : /**
    4253              :  * Test 13: Error case, signature is invalid (random)
    4254              :  * Expected Behavior: get a RETURN_SECURITY_VIOLATION return code
    4255              :  **/
    4256            1 : static void req_get_measurements_case13(void **state)
    4257              : {
    4258              :     libspdm_return_t status;
    4259              :     libspdm_test_context_t *spdm_test_context;
    4260              :     libspdm_context_t *spdm_context;
    4261              :     uint8_t number_of_block;
    4262              :     uint32_t measurement_record_length;
    4263              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    4264              :     uint8_t request_attribute;
    4265              :     void *data;
    4266              :     size_t data_size;
    4267              :     void *hash;
    4268              :     size_t hash_size;
    4269              : 
    4270            1 :     spdm_test_context = *state;
    4271            1 :     spdm_context = spdm_test_context->spdm_context;
    4272            1 :     spdm_test_context->case_id = 0xD;
    4273              : 
    4274            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4275              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4276            1 :     spdm_context->connection_info.connection_state =
    4277              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4278            1 :     spdm_context->connection_info.capability.flags |=
    4279              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4280            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4281              :                                                          m_libspdm_use_asym_algo, &data,
    4282              :                                                          &data_size, &hash, &hash_size)) {
    4283            0 :         assert(false);
    4284              :     }
    4285            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4286            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4287              :         m_libspdm_use_measurement_spec;
    4288            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4289              :         m_libspdm_use_measurement_hash_algo;
    4290            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4291              :         m_libspdm_use_hash_algo;
    4292            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4293              :         m_libspdm_use_asym_algo;
    4294            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4295              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4296              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4297              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4298              :         data_size;
    4299              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4300              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4301              :                      data, data_size);
    4302              : #else
    4303            1 :     libspdm_hash_all(
    4304              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4305              :         data, data_size,
    4306            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4307            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4308            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4309            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4310              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4311              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4312              :         data, data_size,
    4313              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4314              : #endif
    4315              : 
    4316            1 :     request_attribute =
    4317              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    4318              : 
    4319            1 :     measurement_record_length = sizeof(measurement_record);
    4320            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    4321              :                                      0, NULL, &number_of_block,
    4322              :                                      &measurement_record_length,
    4323              :                                      measurement_record);
    4324            1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
    4325              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4326              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    4327              : #endif
    4328            1 :     free(data);
    4329            1 : }
    4330              : 
    4331              : /**
    4332              :  * Test 14: Error case, request a signed response, but response is malformed (signature absent)
    4333              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code
    4334              :  **/
    4335            1 : static void req_get_measurements_case14(void **state)
    4336              : {
    4337              :     libspdm_return_t status;
    4338              :     libspdm_test_context_t *spdm_test_context;
    4339              :     libspdm_context_t *spdm_context;
    4340              :     uint8_t number_of_block;
    4341              :     uint32_t measurement_record_length;
    4342              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    4343              :     uint8_t request_attribute;
    4344              :     void *data;
    4345              :     size_t data_size;
    4346              :     void *hash;
    4347              :     size_t hash_size;
    4348              : 
    4349            1 :     spdm_test_context = *state;
    4350            1 :     spdm_context = spdm_test_context->spdm_context;
    4351            1 :     spdm_test_context->case_id = 0xE;
    4352              : 
    4353            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4354              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4355            1 :     spdm_context->connection_info.connection_state =
    4356              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4357            1 :     spdm_context->connection_info.capability.flags |=
    4358              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4359            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4360              :                                                          m_libspdm_use_asym_algo, &data,
    4361              :                                                          &data_size, &hash, &hash_size)) {
    4362            0 :         assert(false);
    4363              :     }
    4364            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4365            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4366              :         m_libspdm_use_measurement_spec;
    4367            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4368              :         m_libspdm_use_measurement_hash_algo;
    4369            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4370              :         m_libspdm_use_hash_algo;
    4371            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4372              :         m_libspdm_use_asym_algo;
    4373            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4374              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4375              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4376              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4377              :         data_size;
    4378              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4379              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4380              :                      data, data_size);
    4381              : #else
    4382            1 :     libspdm_hash_all(
    4383              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4384              :         data, data_size,
    4385            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4386            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4387            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4388            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4389              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4390              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4391              :         data, data_size,
    4392              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4393              : #endif
    4394              : 
    4395            1 :     request_attribute =
    4396              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    4397              : 
    4398            1 :     measurement_record_length = sizeof(measurement_record);
    4399            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    4400              :                                      0, NULL, &number_of_block,
    4401              :                                      &measurement_record_length,
    4402              :                                      measurement_record);
    4403            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    4404              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4405              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    4406              : #endif
    4407            1 :     free(data);
    4408            1 : }
    4409              : 
    4410              : /**
    4411              :  * Test 15: Error case, response with wrong response code
    4412              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code
    4413              :  **/
    4414            1 : static void req_get_measurements_case15(void **state)
    4415              : {
    4416              :     libspdm_return_t status;
    4417              :     libspdm_test_context_t *spdm_test_context;
    4418              :     libspdm_context_t *spdm_context;
    4419              :     uint8_t number_of_block;
    4420              :     uint32_t measurement_record_length;
    4421              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    4422              :     uint8_t request_attribute;
    4423              :     void *data;
    4424              :     size_t data_size;
    4425              :     void *hash;
    4426              :     size_t hash_size;
    4427              : 
    4428            1 :     spdm_test_context = *state;
    4429            1 :     spdm_context = spdm_test_context->spdm_context;
    4430            1 :     spdm_test_context->case_id = 0xF;
    4431              : 
    4432            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4433              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4434            1 :     spdm_context->connection_info.connection_state =
    4435              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4436            1 :     spdm_context->connection_info.capability.flags |=
    4437              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4438            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4439              :                                                          m_libspdm_use_asym_algo, &data,
    4440              :                                                          &data_size, &hash, &hash_size)) {
    4441            0 :         assert(false);
    4442              :     }
    4443            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4444            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4445              :         m_libspdm_use_measurement_spec;
    4446            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4447              :         m_libspdm_use_measurement_hash_algo;
    4448            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4449              :         m_libspdm_use_hash_algo;
    4450            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4451              :         m_libspdm_use_asym_algo;
    4452            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4453              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4454              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4455              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4456              :         data_size;
    4457              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4458              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4459              :                      data, data_size);
    4460              : #else
    4461            1 :     libspdm_hash_all(
    4462              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4463              :         data, data_size,
    4464            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4465            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4466            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4467            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4468              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4469              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4470              :         data, data_size,
    4471              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4472              : #endif
    4473              : 
    4474            1 :     request_attribute =
    4475              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    4476              : 
    4477            1 :     measurement_record_length = sizeof(measurement_record);
    4478            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    4479              :                                      0, NULL, &number_of_block,
    4480              :                                      &measurement_record_length,
    4481              :                                      measurement_record);
    4482            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    4483              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4484              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    4485              : #endif
    4486            1 :     free(data);
    4487            1 : }
    4488              : 
    4489              : /**
    4490              :  * Test 16: SlotID verificaton, the response's SlotID should match the request
    4491              :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code if the fields match, RETURN_DEVICE_ERROR otherwise. Either way, transcript.message_m should be empty
    4492              :  **/
    4493            1 : static void req_get_measurements_case16(void **state)
    4494              : {
    4495              :     libspdm_return_t status;
    4496              :     libspdm_test_context_t *spdm_test_context;
    4497              :     libspdm_context_t *spdm_context;
    4498              :     uint8_t number_of_block;
    4499              :     uint32_t measurement_record_length;
    4500              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    4501              :     uint8_t request_attribute;
    4502              :     void *data;
    4503              :     size_t data_size;
    4504              :     void *hash;
    4505              :     size_t hash_size;
    4506            1 :     uint8_t SlotIDs[] = { 0, 1, 2, 3 };
    4507              : 
    4508            1 :     spdm_test_context = *state;
    4509            1 :     spdm_context = spdm_test_context->spdm_context;
    4510            1 :     spdm_test_context->case_id = 0x10;
    4511              : 
    4512            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4513              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4514            1 :     spdm_context->connection_info.connection_state =
    4515              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4516            1 :     spdm_context->connection_info.capability.flags |=
    4517              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4518            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4519              :                                                          m_libspdm_use_asym_algo, &data,
    4520              :                                                          &data_size, &hash, &hash_size)) {
    4521            0 :         assert(false);
    4522              :     }
    4523            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4524              :         m_libspdm_use_measurement_spec;
    4525            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4526              :         m_libspdm_use_measurement_hash_algo;
    4527            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4528              :         m_libspdm_use_hash_algo;
    4529            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4530              :         m_libspdm_use_asym_algo;
    4531            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4532              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4533              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4534              :     for (int i = 0; i < sizeof(SlotIDs) / sizeof(SlotIDs[0]); i++) {
    4535              :         spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer_size =
    4536              :             data_size;
    4537              :         libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer,
    4538              :                          sizeof(spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].
    4539              :                                 buffer),
    4540              :                          data, data_size);
    4541              :     }
    4542              : #else
    4543            5 :     for (int i = 0; i < sizeof(SlotIDs) / sizeof(SlotIDs[0]); i++) {
    4544            4 :         libspdm_hash_all(
    4545              :             spdm_context->connection_info.algorithm.base_hash_algo,
    4546              :             data, data_size,
    4547            4 :             spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer_hash);
    4548            8 :         spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer_hash_size =
    4549            4 :             libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4550            4 :         libspdm_get_leaf_cert_public_key_from_cert_chain(
    4551              :             spdm_context->connection_info.algorithm.base_hash_algo,
    4552              :             spdm_context->connection_info.algorithm.base_asym_algo,
    4553              :             data, data_size,
    4554            4 :             &spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].leaf_cert_public_key);
    4555              :     }
    4556              : #endif
    4557              : 
    4558            1 :     request_attribute =
    4559              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    4560              : 
    4561            5 :     for (int i = 0; i < sizeof(SlotIDs) / sizeof(SlotIDs[0]); i++) {
    4562            4 :         measurement_record_length = sizeof(measurement_record);
    4563            4 :         libspdm_reset_message_m(spdm_context, NULL);
    4564            4 :         status = libspdm_get_measurement(spdm_context, NULL,
    4565            4 :                                          request_attribute, 1, SlotIDs[i],
    4566              :                                          NULL, &number_of_block,
    4567              :                                          &measurement_record_length,
    4568              :                                          measurement_record);
    4569            4 :         if (SlotIDs[i] == LIBSPDM_ALTERNATIVE_DEFAULT_SLOT_ID) {
    4570            1 :             assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    4571              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4572              :             assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    4573              : #endif
    4574              :         } else {
    4575            3 :             assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    4576              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4577              :             assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    4578              : #endif
    4579              :         }
    4580              :     }
    4581            1 :     free(data);
    4582            1 : }
    4583              : 
    4584              : /**
    4585              :  * Test 17: Error case, response to get total number of measurements, but response number_of_blocks and/or measurement_record_length are non 0
    4586              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code
    4587              :  **/
    4588            1 : static void req_get_measurements_case17(void **state)
    4589              : {
    4590              :     libspdm_return_t status;
    4591              :     libspdm_test_context_t *spdm_test_context;
    4592              :     libspdm_context_t *spdm_context;
    4593              :     uint8_t number_of_blocks;
    4594              :     uint8_t request_attribute;
    4595              :     void *data;
    4596              :     size_t data_size;
    4597              :     void *hash;
    4598              :     size_t hash_size;
    4599              : 
    4600            1 :     spdm_test_context = *state;
    4601            1 :     spdm_context = spdm_test_context->spdm_context;
    4602            1 :     spdm_test_context->case_id = 0x11;
    4603              : 
    4604            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4605              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4606            1 :     spdm_context->connection_info.connection_state =
    4607              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4608            1 :     spdm_context->connection_info.capability.flags |=
    4609              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4610            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4611              :                                                          m_libspdm_use_asym_algo, &data,
    4612              :                                                          &data_size, &hash, &hash_size)) {
    4613            0 :         assert(false);
    4614              :     }
    4615            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4616            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4617              :         m_libspdm_use_measurement_spec;
    4618            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4619              :         m_libspdm_use_measurement_hash_algo;
    4620            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4621              :         m_libspdm_use_hash_algo;
    4622            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4623              :         m_libspdm_use_asym_algo;
    4624            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4625              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4626              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4627              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4628              :         data_size;
    4629              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4630              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4631              :                      data, data_size);
    4632              : #else
    4633            1 :     libspdm_hash_all(
    4634              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4635              :         data, data_size,
    4636            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4637            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4638            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4639            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4640              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4641              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4642              :         data, data_size,
    4643              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4644              : #endif
    4645              : 
    4646            1 :     request_attribute = 0;
    4647              : 
    4648            4 :     for (int i = 0; i < 3; i++) {
    4649              :         /* i=0 => both number_of_blocks and measurement_record_length are non 0
    4650              :          * i=1 => only number_of_blocks is non 0
    4651              :          * i=2 => only is measurement_record_length is non 0*/
    4652            3 :         status = libspdm_get_measurement(
    4653              :             spdm_context, NULL, request_attribute,
    4654              :             SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS,
    4655              :             0, NULL, &number_of_blocks, NULL, NULL);
    4656            3 :         assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    4657              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4658              :         assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    4659              :                          0);
    4660              : #endif
    4661              :     }
    4662            1 :     free(data);
    4663            1 : }
    4664              : 
    4665              : /**
    4666              :  * Test 18:
    4667              :  * Expected Behavior:
    4668              :  **/
    4669            1 : static void req_get_measurements_case18(void **state)
    4670              : {
    4671            1 : }
    4672              : 
    4673              : /**
    4674              :  * Test 19: Error case, measurement_specification field in response has 2 bits set (bit 0 is one of them)
    4675              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code,
    4676              :  **/
    4677            1 : static void req_get_measurements_case19(void **state)
    4678              : {
    4679              :     libspdm_return_t status;
    4680              :     libspdm_test_context_t *spdm_test_context;
    4681              :     libspdm_context_t *spdm_context;
    4682              :     uint8_t number_of_block;
    4683              :     uint32_t measurement_record_length;
    4684              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    4685              :     uint8_t request_attribute;
    4686              :     void *data;
    4687              :     size_t data_size;
    4688              :     void *hash;
    4689              :     size_t hash_size;
    4690              : 
    4691            1 :     spdm_test_context = *state;
    4692            1 :     spdm_context = spdm_test_context->spdm_context;
    4693            1 :     spdm_test_context->case_id = 0x13;
    4694              : 
    4695            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4696              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4697            1 :     spdm_context->connection_info.connection_state =
    4698              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4699            1 :     spdm_context->connection_info.capability.flags |=
    4700              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4701            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4702              :                                                          m_libspdm_use_asym_algo, &data,
    4703              :                                                          &data_size, &hash, &hash_size)) {
    4704            0 :         assert(false);
    4705              :     }
    4706            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4707            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4708              :         m_libspdm_use_measurement_spec;
    4709            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4710              :         m_libspdm_use_measurement_hash_algo;
    4711            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4712              :         m_libspdm_use_hash_algo;
    4713            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4714              :         m_libspdm_use_asym_algo;
    4715            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4716              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4717              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4718              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4719              :         data_size;
    4720              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4721              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4722              :                      data, data_size);
    4723              : #else
    4724            1 :     libspdm_hash_all(
    4725              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4726              :         data, data_size,
    4727            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4728            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4729            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4730            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4731              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4732              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4733              :         data, data_size,
    4734              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4735              : #endif
    4736              : 
    4737            1 :     request_attribute = 0;
    4738              : 
    4739            1 :     measurement_record_length = sizeof(measurement_record);
    4740            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    4741              :                                      0, NULL, &number_of_block,
    4742              :                                      &measurement_record_length,
    4743              :                                      measurement_record);
    4744            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    4745              : /* #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT*/
    4746              :     /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
    4747              : /* #endif*/
    4748            1 :     free(data);
    4749            1 : }
    4750              : 
    4751              : /**
    4752              :  * Test 20: Error case, measurement_specification field in response has 2 bits set (bit 0 is not one of them)
    4753              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code,
    4754              :  **/
    4755            1 : static void req_get_measurements_case20(void **state)
    4756              : {
    4757              :     libspdm_return_t status;
    4758              :     libspdm_test_context_t *spdm_test_context;
    4759              :     libspdm_context_t *spdm_context;
    4760              :     uint8_t number_of_block;
    4761              :     uint32_t measurement_record_length;
    4762              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    4763              :     uint8_t request_attribute;
    4764              :     void *data;
    4765              :     size_t data_size;
    4766              :     void *hash;
    4767              :     size_t hash_size;
    4768              : 
    4769            1 :     spdm_test_context = *state;
    4770            1 :     spdm_context = spdm_test_context->spdm_context;
    4771            1 :     spdm_test_context->case_id = 0x14;
    4772              : 
    4773            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4774              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4775            1 :     spdm_context->connection_info.connection_state =
    4776              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4777            1 :     spdm_context->connection_info.capability.flags |=
    4778              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4779            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4780              :                                                          m_libspdm_use_asym_algo, &data,
    4781              :                                                          &data_size, &hash, &hash_size)) {
    4782            0 :         assert(false);
    4783              :     }
    4784            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4785            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4786              :         m_libspdm_use_measurement_spec;
    4787            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4788              :         m_libspdm_use_measurement_hash_algo;
    4789            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4790              :         m_libspdm_use_hash_algo;
    4791            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4792              :         m_libspdm_use_asym_algo;
    4793            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4794              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4795              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4796              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4797              :         data_size;
    4798              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4799              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4800              :                      data, data_size);
    4801              : #else
    4802            1 :     libspdm_hash_all(
    4803              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4804              :         data, data_size,
    4805            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4806            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4807            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4808            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4809              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4810              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4811              :         data, data_size,
    4812              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4813              : #endif
    4814              : 
    4815            1 :     request_attribute = 0;
    4816              : 
    4817            1 :     measurement_record_length = sizeof(measurement_record);
    4818            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    4819              :                                      0, NULL, &number_of_block,
    4820              :                                      &measurement_record_length,
    4821              :                                      measurement_record);
    4822            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    4823              : /* #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT*/
    4824              :     /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
    4825              : /* #endif*/
    4826            1 :     free(data);
    4827            1 : }
    4828              : 
    4829              : /**
    4830              :  * Test 21: Error case, measurement_specification field in response does not "match the selected measurement specification in the ALGORITHMS message"
    4831              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code,
    4832              :  **/
    4833            1 : static void req_get_measurements_case21(void **state)
    4834              : {
    4835              :     libspdm_return_t status;
    4836              :     libspdm_test_context_t *spdm_test_context;
    4837              :     libspdm_context_t *spdm_context;
    4838              :     uint8_t number_of_block;
    4839              :     uint32_t measurement_record_length;
    4840              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    4841              :     uint8_t request_attribute;
    4842              :     void *data;
    4843              :     size_t data_size;
    4844              :     void *hash;
    4845              :     size_t hash_size;
    4846              : 
    4847            1 :     spdm_test_context = *state;
    4848            1 :     spdm_context = spdm_test_context->spdm_context;
    4849            1 :     spdm_test_context->case_id = 0x15;
    4850              : 
    4851            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4852              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4853            1 :     spdm_context->connection_info.connection_state =
    4854              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4855            1 :     spdm_context->connection_info.capability.flags |=
    4856              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4857            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4858              :                                                          m_libspdm_use_asym_algo, &data,
    4859              :                                                          &data_size, &hash, &hash_size)) {
    4860            0 :         assert(false);
    4861              :     }
    4862            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4863            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4864              :         m_libspdm_use_measurement_spec;
    4865            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4866              :         m_libspdm_use_measurement_hash_algo;
    4867            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4868              :         m_libspdm_use_hash_algo;
    4869            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4870              :         m_libspdm_use_asym_algo;
    4871            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4872              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4873              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4874              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4875              :         data_size;
    4876              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4877              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4878              :                      data, data_size);
    4879              : #else
    4880            1 :     libspdm_hash_all(
    4881              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4882              :         data, data_size,
    4883            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4884            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4885            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4886            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4887              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4888              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4889              :         data, data_size,
    4890              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4891              : #endif
    4892              : 
    4893            1 :     request_attribute = 0;
    4894              : 
    4895            1 :     measurement_record_length = sizeof(measurement_record);
    4896            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    4897              :                                      0, NULL, &number_of_block,
    4898              :                                      &measurement_record_length,
    4899              :                                      measurement_record);
    4900            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    4901              : /* #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT*/
    4902              :     /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
    4903              : /* #endif*/
    4904            1 :     free(data);
    4905            1 : }
    4906              : 
    4907              : /**
    4908              :  * Test 22: request a large number of unsigned measurements before requesting a signature
    4909              :  * Expected Behavior: LIBSPDM_STATUS_SUCCESS return code and correct transcript.message_m.buffer_size while transcript.message_m has room; RETURN_DEVICE_ERROR otherwise
    4910              :  **/
    4911            1 : static void req_get_measurements_case22(void **state)
    4912              : {
    4913              :     libspdm_return_t status;
    4914              :     libspdm_test_context_t *spdm_test_context;
    4915              :     libspdm_context_t *spdm_context;
    4916              :     uint8_t number_of_block;
    4917              :     uint32_t measurement_record_length;
    4918              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    4919              :     uint8_t request_attribute;
    4920              :     void *data;
    4921              :     size_t data_size;
    4922              :     void *hash;
    4923              :     size_t hash_size;
    4924              :     size_t NumberOfMessages;
    4925              : #define TOTAL_MESSAGES 100
    4926              : 
    4927            1 :     spdm_test_context = *state;
    4928            1 :     spdm_context = spdm_test_context->spdm_context;
    4929            1 :     spdm_test_context->case_id = 0x16;
    4930              : 
    4931            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    4932              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    4933            1 :     spdm_context->connection_info.connection_state =
    4934              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    4935            1 :     spdm_context->connection_info.capability.flags |=
    4936              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    4937            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    4938              :                                                          m_libspdm_use_asym_algo, &data,
    4939              :                                                          &data_size, &hash, &hash_size)) {
    4940            0 :         assert(false);
    4941              :     }
    4942            1 :     libspdm_reset_message_m(spdm_context, NULL);
    4943            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    4944              :         m_libspdm_use_measurement_spec;
    4945            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    4946              :         m_libspdm_use_measurement_hash_algo;
    4947            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    4948              :         m_libspdm_use_hash_algo;
    4949            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    4950              :         m_libspdm_use_asym_algo;
    4951            1 :     spdm_context->local_context.algorithm.measurement_spec =
    4952              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    4953              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4954              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    4955              :         data_size;
    4956              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    4957              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    4958              :                      data, data_size);
    4959              : #else
    4960            1 :     libspdm_hash_all(
    4961              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4962              :         data, data_size,
    4963            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    4964            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    4965            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    4966            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    4967              :         spdm_context->connection_info.algorithm.base_hash_algo,
    4968              :         spdm_context->connection_info.algorithm.base_asym_algo,
    4969              :         data, data_size,
    4970              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    4971              : #endif
    4972              : 
    4973            1 :     request_attribute = 0;
    4974              : 
    4975            1 :     measurement_record_length = sizeof(measurement_record);
    4976          101 :     for (NumberOfMessages = 1; NumberOfMessages <= TOTAL_MESSAGES;
    4977          100 :          NumberOfMessages++) {
    4978          100 :         status = libspdm_get_measurement(spdm_context, NULL,
    4979              :                                          request_attribute, 1, 0,
    4980              :                                          NULL, &number_of_block,
    4981              :                                          &measurement_record_length,
    4982              :                                          measurement_record);
    4983              :         /* It may fail due to transcript.message_m overflow*/
    4984          100 :         if (status == LIBSPDM_STATUS_SUCCESS) {
    4985              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4986              :             assert_int_equal(
    4987              :                 spdm_context->transcript.message_m.buffer_size,
    4988              :                 NumberOfMessages *
    4989              :                 (sizeof(spdm_message_header_t) +
    4990              :                  sizeof(spdm_measurements_response_t) +
    4991              :                  sizeof(spdm_measurement_block_dmtf_t) +
    4992              :                  libspdm_get_measurement_hash_size(
    4993              :                      m_libspdm_use_measurement_hash_algo) +
    4994              :                  SPDM_NONCE_SIZE +
    4995              :                  sizeof(uint16_t)));
    4996              : #endif
    4997              :         } else {
    4998              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    4999              :             assert_int_equal(
    5000              :                 spdm_context->transcript.message_m.buffer_size,
    5001              :                 0);
    5002              : #endif
    5003            0 :             break;
    5004              :         }
    5005              :     }
    5006            1 :     free(data);
    5007            1 : }
    5008              : 
    5009              : /**
    5010              :  * Test 23: Successful response to get a measurement block, without signature. response contains opaque data
    5011              :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, correct transcript.message_m.buffer_size
    5012              :  **/
    5013            1 : static void req_get_measurements_case23(void **state)
    5014              : {
    5015              :     libspdm_return_t status;
    5016              :     libspdm_test_context_t *spdm_test_context;
    5017              :     libspdm_context_t *spdm_context;
    5018              :     uint8_t number_of_block;
    5019              :     uint32_t measurement_record_length;
    5020              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5021              :     uint8_t request_attribute;
    5022              :     void *data;
    5023              :     size_t data_size;
    5024              :     void *hash;
    5025              :     size_t hash_size;
    5026              : 
    5027            1 :     spdm_test_context = *state;
    5028            1 :     spdm_context = spdm_test_context->spdm_context;
    5029            1 :     spdm_test_context->case_id = 0x17;
    5030              : 
    5031            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5032              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5033            1 :     spdm_context->connection_info.connection_state =
    5034              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5035            1 :     spdm_context->connection_info.capability.flags |=
    5036              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5037            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5038              :                                                          m_libspdm_use_asym_algo, &data,
    5039              :                                                          &data_size, &hash, &hash_size)) {
    5040            0 :         assert(false);
    5041              :     }
    5042            1 :     libspdm_reset_message_m(spdm_context, NULL);
    5043            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    5044              :         m_libspdm_use_measurement_spec;
    5045            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5046              :         m_libspdm_use_measurement_hash_algo;
    5047            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5048              :         m_libspdm_use_hash_algo;
    5049            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5050              :         m_libspdm_use_asym_algo;
    5051            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5052              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5053              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5054              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5055              :         data_size;
    5056              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5057              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5058              :                      data, data_size);
    5059              : #else
    5060            1 :     libspdm_hash_all(
    5061              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5062              :         data, data_size,
    5063            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5064            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5065            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5066            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5067              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5068              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5069              :         data, data_size,
    5070              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5071              : #endif
    5072              : 
    5073            1 :     request_attribute = 0;
    5074              : 
    5075            1 :     measurement_record_length = sizeof(measurement_record);
    5076            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    5077              :                                      0, NULL, &number_of_block,
    5078              :                                      &measurement_record_length,
    5079              :                                      measurement_record);
    5080            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    5081              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5082              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    5083              :                      sizeof(spdm_message_header_t) +
    5084              :                      sizeof(spdm_measurements_response_t) +
    5085              :                      sizeof(spdm_measurement_block_dmtf_t) +
    5086              :                      libspdm_get_measurement_hash_size(
    5087              :                          m_libspdm_use_measurement_hash_algo) +
    5088              :                      SPDM_NONCE_SIZE +
    5089              :                      sizeof(uint16_t) + SPDM_MAX_OPAQUE_DATA_SIZE);
    5090              : #endif
    5091            1 :     free(data);
    5092            1 : }
    5093              : 
    5094              : /**
    5095              :  * Test 24: Error case, response contains opaque data larger than the maximum allowed
    5096              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
    5097              :  **/
    5098            1 : static void req_get_measurements_case24(void **state)
    5099              : {
    5100              :     libspdm_return_t status;
    5101              :     libspdm_test_context_t *spdm_test_context;
    5102              :     libspdm_context_t *spdm_context;
    5103              :     uint8_t number_of_block;
    5104              :     uint32_t measurement_record_length;
    5105              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5106              :     uint8_t request_attribute;
    5107              :     void *data;
    5108              :     size_t data_size;
    5109              :     void *hash;
    5110              :     size_t hash_size;
    5111              : 
    5112            1 :     spdm_test_context = *state;
    5113            1 :     spdm_context = spdm_test_context->spdm_context;
    5114            1 :     spdm_test_context->case_id = 0x18;
    5115              : 
    5116            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5117              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5118            1 :     spdm_context->connection_info.connection_state =
    5119              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5120            1 :     spdm_context->connection_info.capability.flags |=
    5121              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5122            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5123              :                                                          m_libspdm_use_asym_algo, &data,
    5124              :                                                          &data_size, &hash, &hash_size)) {
    5125            0 :         assert(false);
    5126              :     }
    5127            1 :     libspdm_reset_message_m(spdm_context, NULL);
    5128            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    5129              :         m_libspdm_use_measurement_spec;
    5130            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5131              :         m_libspdm_use_measurement_hash_algo;
    5132            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5133              :         m_libspdm_use_hash_algo;
    5134            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5135              :         m_libspdm_use_asym_algo;
    5136            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5137              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5138              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5139              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5140              :         data_size;
    5141              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5142              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5143              :                      data, data_size);
    5144              : #else
    5145            1 :     libspdm_hash_all(
    5146              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5147              :         data, data_size,
    5148            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5149            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5150            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5151            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5152              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5153              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5154              :         data, data_size,
    5155              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5156              : #endif
    5157              : 
    5158            1 :     request_attribute = 0;
    5159              : 
    5160            1 :     measurement_record_length = sizeof(measurement_record);
    5161            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    5162              :                                      0, NULL, &number_of_block,
    5163              :                                      &measurement_record_length,
    5164              :                                      measurement_record);
    5165            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    5166              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5167              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    5168              :                      0);
    5169              : #endif
    5170            1 :     free(data);
    5171            1 : }
    5172              : 
    5173              : /**
    5174              :  * Test 25: Successful response to get a measurement block, with signature. response contains opaque data
    5175              :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, empty transcript.message_m.buffer_size
    5176              :  **/
    5177            1 : static void req_get_measurements_case25(void **state)
    5178              : {
    5179              :     libspdm_return_t status;
    5180              :     libspdm_test_context_t *spdm_test_context;
    5181              :     libspdm_context_t *spdm_context;
    5182              :     uint8_t number_of_block;
    5183              :     uint32_t measurement_record_length;
    5184              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5185              :     uint8_t request_attribute;
    5186              :     void *data;
    5187              :     size_t data_size;
    5188              :     void *hash;
    5189              :     size_t hash_size;
    5190              : 
    5191            1 :     spdm_test_context = *state;
    5192            1 :     spdm_context = spdm_test_context->spdm_context;
    5193            1 :     spdm_test_context->case_id = 0x19;
    5194              : 
    5195            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5196              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5197            1 :     spdm_context->connection_info.connection_state =
    5198              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5199            1 :     spdm_context->connection_info.capability.flags |=
    5200              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5201            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5202              :                                                          m_libspdm_use_asym_algo, &data,
    5203              :                                                          &data_size, &hash, &hash_size)) {
    5204            0 :         assert(false);
    5205              :     }
    5206            1 :     libspdm_reset_message_m(spdm_context, NULL);
    5207            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    5208              :         m_libspdm_use_measurement_spec;
    5209            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5210              :         m_libspdm_use_measurement_hash_algo;
    5211            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5212              :         m_libspdm_use_hash_algo;
    5213            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5214              :         m_libspdm_use_asym_algo;
    5215            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5216              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5217              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5218              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5219              :         data_size;
    5220              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5221              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5222              :                      data, data_size);
    5223              : #else
    5224            1 :     libspdm_hash_all(
    5225              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5226              :         data, data_size,
    5227            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5228            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5229            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5230            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5231              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5232              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5233              :         data, data_size,
    5234              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5235              : #endif
    5236              : 
    5237            1 :     request_attribute =
    5238              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    5239              : 
    5240            1 :     measurement_record_length = sizeof(measurement_record);
    5241            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    5242              :                                      0, NULL, &number_of_block,
    5243              :                                      &measurement_record_length,
    5244              :                                      measurement_record);
    5245            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    5246              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5247              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    5248              : #endif
    5249            1 :     free(data);
    5250            1 : }
    5251              : 
    5252              : /**
    5253              :  * Test 26: Error case, request with signature, but response opaque data is S bytes shorter than informed
    5254              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
    5255              :  **/
    5256            1 : static void req_get_measurements_case26(void **state)
    5257              : {
    5258              :     libspdm_return_t status;
    5259              :     libspdm_test_context_t *spdm_test_context;
    5260              :     libspdm_context_t *spdm_context;
    5261              :     uint8_t number_of_block;
    5262              :     uint32_t measurement_record_length;
    5263              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5264              :     uint8_t request_attribute;
    5265              :     void *data;
    5266              :     size_t data_size;
    5267              :     void *hash;
    5268              :     size_t hash_size;
    5269              : 
    5270            1 :     spdm_test_context = *state;
    5271            1 :     spdm_context = spdm_test_context->spdm_context;
    5272            1 :     spdm_test_context->case_id = 0x1A;
    5273              : 
    5274            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5275              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5276            1 :     spdm_context->connection_info.connection_state =
    5277              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5278            1 :     spdm_context->connection_info.capability.flags |=
    5279              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5280            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5281              :                                                          m_libspdm_use_asym_algo, &data,
    5282              :                                                          &data_size, &hash, &hash_size)) {
    5283            0 :         assert(false);
    5284              :     }
    5285            1 :     libspdm_reset_message_m(spdm_context, NULL);
    5286            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    5287              :         m_libspdm_use_measurement_spec;
    5288            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5289              :         m_libspdm_use_measurement_hash_algo;
    5290            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5291              :         m_libspdm_use_hash_algo;
    5292            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5293              :         m_libspdm_use_asym_algo;
    5294            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5295              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5296              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5297              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5298              :         data_size;
    5299              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5300              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5301              :                      data, data_size);
    5302              : #else
    5303            1 :     libspdm_hash_all(
    5304              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5305              :         data, data_size,
    5306            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5307            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5308            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5309            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5310              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5311              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5312              :         data, data_size,
    5313              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5314              : #endif
    5315              : 
    5316            1 :     request_attribute =
    5317              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    5318              : 
    5319            1 :     measurement_record_length = sizeof(measurement_record);
    5320            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    5321              :                                      0, NULL, &number_of_block,
    5322              :                                      &measurement_record_length,
    5323              :                                      measurement_record);
    5324            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    5325              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5326              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    5327              :                      0);
    5328              : #endif
    5329            1 :     free(data);
    5330            1 : }
    5331              : 
    5332              : /**
    5333              :  * Test 27: Error case, request with signature, but response opaque data is (S+1) bytes shorter than informed
    5334              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
    5335              :  **/
    5336            1 : static void req_get_measurements_case27(void **state)
    5337              : {
    5338              :     libspdm_return_t status;
    5339              :     libspdm_test_context_t *spdm_test_context;
    5340              :     libspdm_context_t *spdm_context;
    5341              :     uint8_t number_of_block;
    5342              :     uint32_t measurement_record_length;
    5343              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5344              :     uint8_t request_attribute;
    5345              :     void *data;
    5346              :     size_t data_size;
    5347              :     void *hash;
    5348              :     size_t hash_size;
    5349              : 
    5350            1 :     spdm_test_context = *state;
    5351            1 :     spdm_context = spdm_test_context->spdm_context;
    5352            1 :     spdm_test_context->case_id = 0x1B;
    5353              : 
    5354            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5355              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5356            1 :     spdm_context->connection_info.connection_state =
    5357              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5358            1 :     spdm_context->connection_info.capability.flags |=
    5359              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5360            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5361              :                                                          m_libspdm_use_asym_algo, &data,
    5362              :                                                          &data_size, &hash, &hash_size)) {
    5363            0 :         assert(false);
    5364              :     }
    5365            1 :     libspdm_reset_message_m(spdm_context, NULL);
    5366            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    5367              :         m_libspdm_use_measurement_spec;
    5368            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5369              :         m_libspdm_use_measurement_hash_algo;
    5370            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5371              :         m_libspdm_use_hash_algo;
    5372            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5373              :         m_libspdm_use_asym_algo;
    5374            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5375              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5376              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5377              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5378              :         data_size;
    5379              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5380              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5381              :                      data, data_size);
    5382              : #else
    5383            1 :     libspdm_hash_all(
    5384              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5385              :         data, data_size,
    5386            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5387            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5388            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5389            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5390              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5391              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5392              :         data, data_size,
    5393              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5394              : #endif
    5395              : 
    5396            1 :     request_attribute =
    5397              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    5398              : 
    5399            1 :     measurement_record_length = sizeof(measurement_record);
    5400            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    5401              :                                      0, NULL, &number_of_block,
    5402              :                                      &measurement_record_length,
    5403              :                                      measurement_record);
    5404            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
    5405              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5406              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    5407              :                      0);
    5408              : #endif
    5409            1 :     free(data);
    5410            1 : }
    5411              : 
    5412              : /**
    5413              :  * Test 28: Error case, request with signature, but response opaque data is 1 byte longer than informed
    5414              :  * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
    5415              :  **/
    5416            1 : static void req_get_measurements_case28(void **state)
    5417              : {
    5418              :     libspdm_return_t status;
    5419              :     libspdm_test_context_t *spdm_test_context;
    5420              :     libspdm_context_t *spdm_context;
    5421              :     uint8_t number_of_block;
    5422              :     uint32_t measurement_record_length;
    5423              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5424              :     uint8_t request_attribute;
    5425              :     void *data;
    5426              :     size_t data_size;
    5427              :     void *hash;
    5428              :     size_t hash_size;
    5429              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5430              :     size_t ExpectedBufferSize;
    5431              : #endif
    5432            1 :     spdm_test_context = *state;
    5433            1 :     spdm_context = spdm_test_context->spdm_context;
    5434            1 :     spdm_test_context->case_id = 0x1C;
    5435              : 
    5436            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5437              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5438            1 :     spdm_context->connection_info.connection_state =
    5439              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5440            1 :     spdm_context->connection_info.capability.flags |=
    5441              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5442            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5443              :                                                          m_libspdm_use_asym_algo, &data,
    5444              :                                                          &data_size, &hash, &hash_size)) {
    5445            0 :         assert(false);
    5446              :     }
    5447            1 :     libspdm_reset_message_m(spdm_context, NULL);
    5448            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    5449              :         m_libspdm_use_measurement_spec;
    5450            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5451              :         m_libspdm_use_measurement_hash_algo;
    5452            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5453              :         m_libspdm_use_hash_algo;
    5454            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5455              :         m_libspdm_use_asym_algo;
    5456            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5457              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5458              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5459              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5460              :         data_size;
    5461              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5462              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5463              :                      data, data_size);
    5464              : #else
    5465            1 :     libspdm_hash_all(
    5466              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5467              :         data, data_size,
    5468            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5469            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5470            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5471            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5472              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5473              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5474              :         data, data_size,
    5475              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5476              : #endif
    5477              : 
    5478            1 :     request_attribute =
    5479              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    5480              : 
    5481            1 :     measurement_record_length = sizeof(measurement_record);
    5482            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    5483              :                                      0, NULL, &number_of_block,
    5484              :                                      &measurement_record_length,
    5485              :                                      measurement_record);
    5486            1 :     assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
    5487              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5488              :     ExpectedBufferSize = 0;
    5489              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    5490              :                      ExpectedBufferSize);
    5491              : #endif
    5492            1 :     free(data);
    5493            1 : }
    5494              : 
    5495              : /**
    5496              :  * Test 29: request measurement without signature, but response opaque data is 1 byte longer than informed
    5497              :  * Expected Behavior: extra byte should just be ignored. Get a LIBSPDM_STATUS_SUCCESS return code, correct transcript.message_m.buffer_size
    5498              :  **/
    5499            1 : static void req_get_measurements_case29(void **state)
    5500              : {
    5501              :     libspdm_return_t status;
    5502              :     libspdm_test_context_t *spdm_test_context;
    5503              :     libspdm_context_t *spdm_context;
    5504              :     uint8_t number_of_block;
    5505              :     uint32_t measurement_record_length;
    5506              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5507              :     uint8_t request_attribute;
    5508              :     void *data;
    5509              :     size_t data_size;
    5510              :     void *hash;
    5511              :     size_t hash_size;
    5512              : 
    5513            1 :     spdm_test_context = *state;
    5514            1 :     spdm_context = spdm_test_context->spdm_context;
    5515            1 :     spdm_test_context->case_id = 0x1D;
    5516              : 
    5517            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5518              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5519            1 :     spdm_context->connection_info.connection_state =
    5520              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5521            1 :     spdm_context->connection_info.capability.flags |=
    5522              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5523            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5524              :                                                          m_libspdm_use_asym_algo, &data,
    5525              :                                                          &data_size, &hash, &hash_size)) {
    5526            0 :         assert(false);
    5527              :     }
    5528            1 :     libspdm_reset_message_m(spdm_context, NULL);
    5529            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    5530              :         m_libspdm_use_measurement_spec;
    5531            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5532              :         m_libspdm_use_measurement_hash_algo;
    5533            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5534              :         m_libspdm_use_hash_algo;
    5535            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5536              :         m_libspdm_use_asym_algo;
    5537            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5538              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5539              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5540              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5541              :         data_size;
    5542              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5543              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5544              :                      data, data_size);
    5545              : #else
    5546            1 :     libspdm_hash_all(
    5547              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5548              :         data, data_size,
    5549            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5550            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5551            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5552            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5553              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5554              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5555              :         data, data_size,
    5556              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5557              : #endif
    5558              : 
    5559            1 :     request_attribute = 0;
    5560              : 
    5561            1 :     measurement_record_length = sizeof(measurement_record);
    5562            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    5563              :                                      0, NULL, &number_of_block,
    5564              :                                      &measurement_record_length,
    5565              :                                      measurement_record);
    5566            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    5567              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5568              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    5569              :                      sizeof(spdm_message_header_t) +
    5570              :                      sizeof(spdm_measurements_response_t) +
    5571              :                      sizeof(spdm_measurement_block_dmtf_t) +
    5572              :                      libspdm_get_measurement_hash_size(
    5573              :                          m_libspdm_use_measurement_hash_algo) +
    5574              :                      SPDM_NONCE_SIZE +
    5575              :                      sizeof(uint16_t) +
    5576              :                      SPDM_MAX_OPAQUE_DATA_SIZE / 2 - 1);
    5577              : #endif
    5578            1 :     free(data);
    5579            1 : }
    5580              : 
    5581              : /**
    5582              :  * Test 30:
    5583              :  * Expected Behavior:
    5584              :  **/
    5585            1 : static void req_get_measurements_case30(void **state)
    5586              : {
    5587            1 : }
    5588              : 
    5589              : /**
    5590              :  * Test 31:
    5591              :  * Expected Behavior:
    5592              :  **/
    5593            1 : static void req_get_measurements_case31(void **state)
    5594              : {
    5595            1 : }
    5596              : 
    5597              : /**
    5598              :  * Test 32: Successful response to get all measurement blocks, without signature
    5599              :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, correct transcript.message_m.buffer_size
    5600              :  **/
    5601            1 : static void req_get_measurements_case32(void **state)
    5602              : {
    5603              :     libspdm_return_t status;
    5604              :     libspdm_test_context_t *spdm_test_context;
    5605              :     libspdm_context_t *spdm_context;
    5606              :     uint8_t number_of_block;
    5607              :     uint32_t measurement_record_length;
    5608              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5609              :     uint8_t request_attribute;
    5610              :     void *data;
    5611              :     size_t data_size;
    5612              :     void *hash;
    5613              :     size_t hash_size;
    5614              : 
    5615            1 :     spdm_test_context = *state;
    5616            1 :     spdm_context = spdm_test_context->spdm_context;
    5617            1 :     spdm_test_context->case_id = 0x20;
    5618            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5619              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5620            1 :     spdm_context->connection_info.connection_state =
    5621              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5622            1 :     spdm_context->connection_info.capability.flags |=
    5623              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5624            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5625              :                                                          m_libspdm_use_asym_algo, &data,
    5626              :                                                          &data_size, &hash, &hash_size)) {
    5627            0 :         assert(false);
    5628              :     }
    5629            1 :     libspdm_reset_message_m(spdm_context, NULL);
    5630            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    5631              :         m_libspdm_use_measurement_spec;
    5632            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5633              :         m_libspdm_use_measurement_hash_algo;
    5634            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5635              :         m_libspdm_use_hash_algo;
    5636            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5637              :         m_libspdm_use_asym_algo;
    5638            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5639              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5640              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5641              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5642              :         data_size;
    5643              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5644              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5645              :                      data, data_size);
    5646              : #else
    5647            1 :     libspdm_hash_all(
    5648              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5649              :         data, data_size,
    5650            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5651            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5652            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5653            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5654              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5655              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5656              :         data, data_size,
    5657              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5658              : #endif
    5659              : 
    5660            1 :     request_attribute = 0;
    5661              : 
    5662            1 :     measurement_record_length = sizeof(measurement_record);
    5663            1 :     status = libspdm_get_measurement(
    5664              :         spdm_context, NULL, request_attribute,
    5665              :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS,
    5666              :         0, NULL, &number_of_block, &measurement_record_length,
    5667              :         measurement_record);
    5668            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    5669              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5670              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    5671              :                      sizeof(spdm_message_header_t) +
    5672              :                      sizeof(spdm_measurements_response_t) +
    5673              :                      2 * (sizeof(spdm_measurement_block_dmtf_t) +
    5674              :                           libspdm_get_measurement_hash_size(
    5675              :                               m_libspdm_use_measurement_hash_algo)) +
    5676              :                      sizeof(uint16_t) + SPDM_NONCE_SIZE);
    5677              : #endif
    5678            1 :     free(data);
    5679            1 : }
    5680              : 
    5681              : /**
    5682              :  * Test 33: receiving an unexpected ERROR message from the responder.
    5683              :  * There are tests for all named codes, including some reserved ones
    5684              :  * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
    5685              :  * However, for having specific test cases, it is excluded from this case:
    5686              :  * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
    5687              :  * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
    5688              :  **/
    5689            1 : static void req_get_measurements_case33(void **state) {
    5690              :     libspdm_return_t status;
    5691              :     libspdm_test_context_t    *spdm_test_context;
    5692              :     libspdm_context_t  *spdm_context;
    5693              :     uint8_t number_of_block;
    5694              :     uint32_t measurement_record_length;
    5695              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5696              :     uint8_t request_attribute;
    5697              :     void                 *data;
    5698              :     size_t data_size;
    5699              :     void                 *hash;
    5700              :     size_t hash_size;
    5701              :     uint16_t error_code;
    5702              : 
    5703            1 :     spdm_test_context = *state;
    5704            1 :     spdm_context = spdm_test_context->spdm_context;
    5705            1 :     spdm_test_context->case_id = 0x21;
    5706            1 :     spdm_context->connection_info.capability.flags |=
    5707              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5708            1 :     libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
    5709              :                                                      m_libspdm_use_asym_algo,
    5710              :                                                      &data, &data_size,
    5711              :                                                      &hash, &hash_size);
    5712            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    5713            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5714              :         m_libspdm_use_measurement_hash_algo;
    5715            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    5716            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    5717            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5718              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5719              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5720              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5721              :         data_size;
    5722              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5723              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5724              :                      data, data_size);
    5725              : #else
    5726            1 :     libspdm_hash_all(
    5727              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5728              :         data, data_size,
    5729            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5730            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5731            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5732            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5733              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5734              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5735              :         data, data_size,
    5736              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5737              : #endif
    5738              : 
    5739            1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    5740              : 
    5741            1 :     error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
    5742           19 :     while(error_code <= 0xff) {
    5743           18 :         spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5744           18 :         libspdm_reset_message_m(spdm_context, NULL);
    5745              : 
    5746           18 :         measurement_record_length = sizeof(measurement_record);
    5747           18 :         status = libspdm_get_measurement (spdm_context, NULL, request_attribute, 1, 0, NULL,
    5748              :                                           &number_of_block, &measurement_record_length,
    5749              :                                           measurement_record);
    5750           18 :         LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
    5751              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5752              :         /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
    5753              :         LIBSPDM_ASSERT_INT_EQUAL_CASE (spdm_context->transcript.message_m.buffer_size, 0,
    5754              :                                        error_code);
    5755              : #endif
    5756              : 
    5757           18 :         error_code++;
    5758           18 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
    5759            1 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
    5760              :         }
    5761           18 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
    5762            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
    5763              :         }
    5764           18 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
    5765            1 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
    5766              :         }
    5767              :     }
    5768              : 
    5769            1 :     free(data);
    5770            1 : }
    5771              : 
    5772              : /**
    5773              :  * Test 34: Successful response to get a session based measurement with signature
    5774              :  * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, with an empty session_transcript.message_m
    5775              :  **/
    5776            1 : static void req_get_measurements_case34(void **state)
    5777              : {
    5778              :     libspdm_return_t status;
    5779              :     libspdm_test_context_t *spdm_test_context;
    5780              :     libspdm_context_t *spdm_context;
    5781              :     uint32_t session_id;
    5782              :     libspdm_session_info_t *session_info;
    5783              :     uint8_t number_of_block;
    5784              :     uint32_t measurement_record_length;
    5785              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5786              :     uint8_t request_attribute;
    5787              :     void *data;
    5788              :     size_t data_size;
    5789              :     void *hash;
    5790              :     size_t hash_size;
    5791              : 
    5792            1 :     spdm_test_context = *state;
    5793            1 :     spdm_context = spdm_test_context->spdm_context;
    5794            1 :     spdm_test_context->case_id = 0x22;
    5795            1 :     spdm_context->connection_info.connection_state =
    5796              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5797            1 :     spdm_context->connection_info.capability.flags |=
    5798              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5799            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5800              :                                                          m_libspdm_use_asym_algo, &data,
    5801              :                                                          &data_size, &hash, &hash_size)) {
    5802            0 :         assert(false);
    5803              :     }
    5804            1 :     spdm_context->connection_info.capability.flags |=
    5805              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
    5806            1 :     spdm_context->connection_info.capability.flags |=
    5807              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
    5808            1 :     spdm_context->connection_info.capability.flags |=
    5809              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    5810            1 :     spdm_context->local_context.capability.flags |=
    5811              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
    5812            1 :     spdm_context->local_context.capability.flags |=
    5813              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
    5814            1 :     spdm_context->local_context.capability.flags |=
    5815              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    5816            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
    5817              :         m_libspdm_use_dhe_algo;
    5818            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
    5819              :         m_libspdm_use_aead_algo;
    5820            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5821              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5822            1 :     session_id = 0xFFFFFFFF;
    5823            1 :     session_info = &spdm_context->session_info[0];
    5824            1 :     libspdm_session_info_init(spdm_context, session_info, session_id,
    5825              :                               SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT, true);
    5826            1 :     libspdm_secured_message_set_session_state(
    5827              :         session_info->secured_message_context,
    5828              :         LIBSPDM_SESSION_STATE_ESTABLISHED);
    5829              : 
    5830            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    5831              :         m_libspdm_use_measurement_spec;
    5832            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5833              :         m_libspdm_use_measurement_hash_algo;
    5834            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    5835              :         m_libspdm_use_hash_algo;
    5836            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    5837              :         m_libspdm_use_asym_algo;
    5838              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5839              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    5840              :         data_size;
    5841              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5842              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5843              :                      data, data_size);
    5844              : #else
    5845            1 :     libspdm_hash_all(
    5846              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5847              :         data, data_size,
    5848            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5849            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5850            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5851            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5852              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5853              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5854              :         data, data_size,
    5855              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5856              : #endif
    5857              : 
    5858            1 :     request_attribute =
    5859              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    5860              : 
    5861            1 :     measurement_record_length = sizeof(measurement_record);
    5862            1 :     status = libspdm_get_measurement(spdm_context, &session_id, request_attribute, 1,
    5863              :                                      0, NULL, &number_of_block,
    5864              :                                      &measurement_record_length,
    5865              :                                      measurement_record);
    5866            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    5867              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5868              :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
    5869              : #endif
    5870            1 :     free(data);
    5871            1 : }
    5872              : 
    5873              : /**
    5874              :  * Test 35: a request message is successfully sent and a response message is successfully received.
    5875              :  * Buffer M already has arbitrary data. No signature is requested.
    5876              :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a MEASUREMENTS message
    5877              :  * is received, buffer M appends the exchanged GET_MEASUREMENTS and MEASUREMENTS messages.
    5878              :  *
    5879              :  * Note that this test is only exercised when LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT is enabled.
    5880              :  **/
    5881            1 : static void req_get_measurements_case35(void **state)
    5882              : {
    5883              :     libspdm_return_t status;
    5884              :     libspdm_test_context_t *spdm_test_context;
    5885              :     libspdm_context_t *spdm_context;
    5886              :     uint8_t number_of_block;
    5887              :     uint32_t measurement_record_length;
    5888              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5889              :     uint8_t request_attribute;
    5890              :     void *data;
    5891              :     size_t data_size;
    5892              :     void *hash;
    5893              :     size_t hash_size;
    5894              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5895              :     const size_t arbitrary_fill_size = 18;
    5896              : #endif
    5897              : 
    5898            1 :     spdm_test_context = *state;
    5899            1 :     spdm_context = spdm_test_context->spdm_context;
    5900            1 :     spdm_test_context->case_id = 0x23;
    5901            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    5902              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5903            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5904            1 :     spdm_context->connection_info.capability.flags |=
    5905              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5906            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5907              :                                                          m_libspdm_use_asym_algo, &data,
    5908              :                                                          &data_size, &hash, &hash_size)) {
    5909            0 :         assert(false);
    5910              :     }
    5911            1 :     libspdm_reset_message_m(spdm_context, NULL);
    5912            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    5913            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    5914              :         m_libspdm_use_measurement_hash_algo;
    5915            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    5916            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    5917            1 :     spdm_context->local_context.algorithm.measurement_spec =
    5918              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    5919              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5920              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
    5921              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    5922              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    5923              :                      data, data_size);
    5924              : #else
    5925            1 :     libspdm_hash_all(
    5926              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5927              :         data, data_size,
    5928            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    5929            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    5930            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    5931            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    5932              :         spdm_context->connection_info.algorithm.base_hash_algo,
    5933              :         spdm_context->connection_info.algorithm.base_asym_algo,
    5934              :         data, data_size,
    5935              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    5936              : #endif
    5937              : 
    5938            1 :     request_attribute = 0; /* Do not request a signature. */
    5939              : 
    5940              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5941              :     /* Fill M buffer and local buffer with arbitrary data. */
    5942              :     libspdm_set_mem(spdm_context->transcript.message_m.buffer, arbitrary_fill_size, 0xFF);
    5943              :     libspdm_set_mem(m_libspdm_local_buffer, arbitrary_fill_size, 0xFF);
    5944              :     spdm_context->transcript.message_m.buffer_size = arbitrary_fill_size;
    5945              :     m_libspdm_local_buffer_size = arbitrary_fill_size;
    5946              : #endif
    5947              : 
    5948            1 :     measurement_record_length = sizeof(measurement_record);
    5949            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    5950              :                                      0, NULL, &number_of_block,
    5951              :                                      &measurement_record_length,
    5952              :                                      measurement_record);
    5953            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    5954              : 
    5955              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    5956              :     /* Check that the size of the two buffers are the same (fill data + request + response) */
    5957              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, m_libspdm_local_buffer_size);
    5958              :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
    5959              :                    m_libspdm_local_buffer_size));
    5960              :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    5961              :     /* Check that the contents of the two buffers are the same (fill data, request, response) */
    5962              :     assert_memory_equal(spdm_context->transcript.message_m.buffer,
    5963              :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    5964              : #endif
    5965            1 :     free(data);
    5966            1 : }
    5967              : 
    5968            1 : static void req_get_measurements_case36(void **state)
    5969              : {
    5970              :     libspdm_return_t status;
    5971              :     libspdm_test_context_t *spdm_test_context;
    5972              :     libspdm_context_t *spdm_context;
    5973              :     uint8_t number_of_block;
    5974              :     uint32_t measurement_record_length;
    5975              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    5976              :     uint8_t request_attribute;
    5977              :     void *data;
    5978              :     size_t data_size;
    5979              :     void *hash;
    5980              :     size_t hash_size;
    5981              : 
    5982            1 :     spdm_test_context = *state;
    5983            1 :     spdm_context = spdm_test_context->spdm_context;
    5984            1 :     spdm_test_context->case_id = 0x24;
    5985            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    5986              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    5987            1 :     spdm_context->connection_info.connection_state =
    5988              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    5989            1 :     spdm_context->connection_info.capability.flags |=
    5990              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    5991            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    5992              :                                                          m_libspdm_use_asym_algo, &data,
    5993              :                                                          &data_size, &hash, &hash_size)) {
    5994            0 :         assert(false);
    5995              :     }
    5996            1 :     libspdm_reset_message_m(spdm_context, NULL);
    5997            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    5998              :         m_libspdm_use_measurement_spec;
    5999            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6000              :         m_libspdm_use_measurement_hash_algo;
    6001            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6002              :         m_libspdm_use_hash_algo;
    6003            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6004              :         m_libspdm_use_asym_algo;
    6005            1 :     spdm_context->local_context.algorithm.measurement_spec =
    6006              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    6007              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6008              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6009              :         data_size;
    6010              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6011              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6012              :                      data, data_size);
    6013              : #else
    6014            1 :     libspdm_hash_all(
    6015              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6016              :         data, data_size,
    6017            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6018            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6019            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6020            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6021              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6022              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6023              :         data, data_size,
    6024              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6025              : #endif
    6026              : 
    6027            1 :     request_attribute =
    6028              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    6029              : 
    6030            1 :     measurement_record_length = sizeof(measurement_record);
    6031            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    6032              :                                      0, NULL, &number_of_block,
    6033              :                                      &measurement_record_length,
    6034              :                                      measurement_record);
    6035            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6036              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6037              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    6038              : #endif
    6039            1 :     free(data);
    6040            1 : }
    6041              : 
    6042            1 : static void req_get_measurements_case37(void **state)
    6043              : {
    6044              :     libspdm_return_t status;
    6045              :     libspdm_test_context_t *spdm_test_context;
    6046              :     libspdm_context_t *spdm_context;
    6047              :     uint8_t number_of_blocks;
    6048              :     uint8_t request_attribute;
    6049              :     void *data;
    6050              :     size_t data_size;
    6051              :     void *hash;
    6052              :     size_t hash_size;
    6053              : 
    6054            1 :     spdm_test_context = *state;
    6055            1 :     spdm_context = spdm_test_context->spdm_context;
    6056            1 :     spdm_test_context->case_id = 0x25;
    6057            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    6058              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6059            1 :     spdm_context->connection_info.connection_state =
    6060              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    6061            1 :     spdm_context->connection_info.capability.flags |=
    6062              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6063            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6064              :                                                          m_libspdm_use_asym_algo, &data,
    6065              :                                                          &data_size, &hash, &hash_size)) {
    6066            0 :         assert(false);
    6067              :     }
    6068            1 :     libspdm_reset_message_m(spdm_context, NULL);
    6069            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    6070              :         m_libspdm_use_measurement_spec;
    6071            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6072              :         m_libspdm_use_measurement_hash_algo;
    6073            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6074              :         m_libspdm_use_hash_algo;
    6075            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6076              :         m_libspdm_use_asym_algo;
    6077            1 :     spdm_context->local_context.algorithm.measurement_spec =
    6078              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    6079              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6080              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    6081              :         data_size;
    6082              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6083              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6084              :                      data, data_size);
    6085              : #else
    6086            1 :     libspdm_hash_all(
    6087              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6088              :         data, data_size,
    6089            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6090            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6091            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6092            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6093              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6094              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6095              :         data, data_size,
    6096              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6097              : #endif
    6098              : 
    6099            1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_RAW_BIT_STREAM_REQUESTED;
    6100              : 
    6101            1 :     status = libspdm_get_measurement(
    6102              :         spdm_context, NULL, request_attribute,
    6103              :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS,
    6104              :         0, NULL, &number_of_blocks, NULL, NULL);
    6105            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6106            1 :     assert_int_equal(number_of_blocks, 4);
    6107              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6108              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    6109              :                      sizeof(spdm_message_header_t) +
    6110              :                      sizeof(spdm_measurements_response_t) +
    6111              :                      SPDM_NONCE_SIZE + sizeof(uint16_t));
    6112              : #endif
    6113            1 :     free(data);
    6114            1 : }
    6115              : 
    6116            1 : static void req_get_measurements_case38(void **state)
    6117              : {
    6118              :     libspdm_return_t status;
    6119              :     libspdm_test_context_t *spdm_test_context;
    6120              :     libspdm_context_t *spdm_context;
    6121              :     uint8_t number_of_block;
    6122              :     uint32_t measurement_record_length;
    6123              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    6124              :     uint8_t request_attribute;
    6125              :     void *data;
    6126              :     size_t data_size;
    6127              : 
    6128            1 :     spdm_test_context = *state;
    6129            1 :     spdm_context = spdm_test_context->spdm_context;
    6130            1 :     spdm_test_context->case_id = 0x26;
    6131            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    6132              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6133            1 :     spdm_context->connection_info.connection_state =
    6134              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    6135            1 :     spdm_context->connection_info.capability.flags |=
    6136              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6137            1 :     spdm_context->connection_info.capability.flags |=
    6138              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
    6139            1 :     libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
    6140            1 :     spdm_context->local_context.peer_public_key_provision = data;
    6141            1 :     spdm_context->local_context.peer_public_key_provision_size = data_size;
    6142              : 
    6143            1 :     libspdm_reset_message_m(spdm_context, NULL);
    6144            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    6145              :         m_libspdm_use_measurement_spec;
    6146            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6147              :         m_libspdm_use_measurement_hash_algo;
    6148            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6149              :         m_libspdm_use_hash_algo;
    6150            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6151              :         m_libspdm_use_asym_algo;
    6152              : 
    6153            1 :     request_attribute =
    6154              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    6155              : 
    6156            1 :     measurement_record_length = sizeof(measurement_record);
    6157            1 :     status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
    6158              :                                      0xF, NULL, &number_of_block,
    6159              :                                      &measurement_record_length,
    6160              :                                      measurement_record);
    6161            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6162              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6163              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    6164              : #endif
    6165            1 :     free(data);
    6166            1 : }
    6167              : 
    6168              : /**
    6169              :  * Test 39: Exercise the libspdm_get_measurement_ex function.
    6170              :  * Expected Behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    6171              :  **/
    6172            1 : static void req_get_measurements_case39(void **state)
    6173              : {
    6174              :     libspdm_return_t status;
    6175              :     libspdm_test_context_t *spdm_test_context;
    6176              :     libspdm_context_t *spdm_context;
    6177              :     uint8_t number_of_block;
    6178              :     uint32_t measurement_record_length;
    6179              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    6180              :     uint8_t request_attribute;
    6181              :     void *data;
    6182              :     size_t data_size;
    6183              :     void *hash;
    6184              :     size_t hash_size;
    6185              :     uint8_t requester_nonce_in[SPDM_NONCE_SIZE];
    6186              :     uint8_t requester_nonce[SPDM_NONCE_SIZE];
    6187              :     uint8_t responder_nonce[SPDM_NONCE_SIZE];
    6188              :     uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
    6189              :     size_t opaque_data_size;
    6190              : 
    6191            1 :     spdm_test_context = *state;
    6192            1 :     spdm_context = spdm_test_context->spdm_context;
    6193            1 :     spdm_test_context->case_id = 0x27;
    6194            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
    6195              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6196            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    6197            1 :     spdm_context->connection_info.capability.flags |=
    6198              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6199            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6200              :                                                          m_libspdm_use_asym_algo, &data,
    6201              :                                                          &data_size, &hash, &hash_size)) {
    6202            0 :         assert(false);
    6203              :     }
    6204            1 :     libspdm_reset_message_m(spdm_context, NULL);
    6205            1 :     spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
    6206            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6207              :         m_libspdm_use_measurement_hash_algo;
    6208            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    6209            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    6210            1 :     spdm_context->local_context.algorithm.measurement_spec =
    6211              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    6212            1 :     spdm_context->connection_info.algorithm.other_params_support =
    6213              :         SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
    6214              : 
    6215              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6216              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
    6217              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6218              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6219              :                      data, data_size);
    6220              : #else
    6221            1 :     libspdm_hash_all(
    6222              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6223              :         data, data_size,
    6224            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6225            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6226            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6227            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6228              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6229              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6230              :         data, data_size,
    6231              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6232              : #endif
    6233              : 
    6234            1 :     request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
    6235              : 
    6236            1 :     measurement_record_length = sizeof(measurement_record);
    6237              : 
    6238           33 :     for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
    6239           32 :         requester_nonce_in[index] = 0x5c;
    6240           32 :         requester_nonce[index] = 0x00;
    6241           32 :         responder_nonce[index] = 0x00;
    6242              :     }
    6243              : 
    6244            1 :     opaque_data_size = sizeof(opaque_data);
    6245              : 
    6246            1 :     status = libspdm_get_measurement_ex(spdm_context, NULL, request_attribute, 1,
    6247              :                                         0, NULL, &number_of_block,
    6248              :                                         &measurement_record_length,
    6249              :                                         measurement_record, requester_nonce_in,
    6250              :                                         requester_nonce, responder_nonce,
    6251              :                                         opaque_data, &opaque_data_size);
    6252            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6253           33 :     for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
    6254           32 :         assert_int_equal (requester_nonce_in[index], requester_nonce[index]);
    6255           32 :         assert_int_equal (responder_nonce[index], 0x12);
    6256              :     }
    6257              : 
    6258            1 :     assert_int_equal(opaque_data_size, m_libspdm_opaque_data_size);
    6259            1 :     assert_memory_equal(opaque_data, m_libspdm_opaque_data, opaque_data_size);
    6260              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6261              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    6262              : #endif
    6263            1 :     free(data);
    6264            1 : }
    6265              : 
    6266              : /**
    6267              :  * Test 40: Successful case , correct measuerments context field , without signature
    6268              :  * Expected Behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
    6269              :  **/
    6270            1 : static void req_get_measurements_case40(void **state)
    6271              : {
    6272              :     libspdm_return_t status;
    6273              :     libspdm_test_context_t *spdm_test_context;
    6274              :     libspdm_context_t *spdm_context;
    6275              :     uint8_t number_of_block;
    6276              :     uint32_t measurement_record_length;
    6277              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    6278              :     uint8_t request_attribute;
    6279              :     void *data;
    6280              :     size_t data_size;
    6281              :     void *hash;
    6282              :     size_t hash_size;
    6283              : 
    6284            1 :     spdm_test_context = *state;
    6285            1 :     spdm_context = spdm_test_context->spdm_context;
    6286            1 :     spdm_test_context->case_id = 0x28;
    6287            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    6288              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6289            1 :     spdm_context->connection_info.connection_state =
    6290              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    6291            1 :     spdm_context->connection_info.capability.flags |=
    6292              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6293            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6294              :                                                          m_libspdm_use_asym_algo, &data,
    6295              :                                                          &data_size, &hash, &hash_size)) {
    6296            0 :         assert(false);
    6297              :     }
    6298            1 :     libspdm_reset_message_m(spdm_context, NULL);
    6299            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    6300              :         m_libspdm_use_measurement_spec;
    6301            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6302              :         m_libspdm_use_measurement_hash_algo;
    6303            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6304              :         m_libspdm_use_hash_algo;
    6305            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6306              :         m_libspdm_use_asym_algo;
    6307            1 :     spdm_context->local_context.algorithm.measurement_spec =
    6308              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    6309              : 
    6310              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6311              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
    6312              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6313              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6314              :                      data, data_size);
    6315              : #else
    6316            1 :     libspdm_hash_all(
    6317              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6318              :         data, data_size,
    6319            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6320            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6321            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6322            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6323              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6324              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6325              :         data, data_size,
    6326              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6327              : #endif
    6328              : 
    6329            1 :     measurement_record_length = sizeof(measurement_record);
    6330              : 
    6331            1 :     libspdm_set_mem(m_requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
    6332              : 
    6333            1 :     request_attribute = 0; /* Do not request a signature. */
    6334              : 
    6335            1 :     status = libspdm_get_measurement_ex2(spdm_context, NULL, request_attribute, 1,
    6336              :                                          0, m_requester_context, NULL, &number_of_block,
    6337              :                                          &measurement_record_length,
    6338              :                                          measurement_record, NULL, NULL, NULL, NULL, NULL);
    6339              : 
    6340            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    6341              : 
    6342              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6343              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size,
    6344              :                      sizeof(spdm_message_header_t) + SPDM_REQ_CONTEXT_SIZE +
    6345              :                      sizeof(spdm_measurements_response_t) +
    6346              :                      sizeof(spdm_measurement_block_dmtf_t) +
    6347              :                      libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo) +
    6348              :                      SPDM_NONCE_SIZE + sizeof(uint16_t) + SPDM_REQ_CONTEXT_SIZE);
    6349              : #endif
    6350            1 :     free(data);
    6351            1 : }
    6352              : 
    6353              : /**
    6354              :  * Test 41: Error case , Measurement context fields are inconsistent , without signature
    6355              :  * Expected Behavior: get a LIBSPDM_STATUS_INVALID_MSG_FIELD return code
    6356              :  **/
    6357            1 : static void req_get_measurements_case41(void **state)
    6358              : {
    6359              :     libspdm_return_t status;
    6360              :     libspdm_test_context_t *spdm_test_context;
    6361              :     libspdm_context_t *spdm_context;
    6362              :     uint8_t number_of_block;
    6363              :     uint32_t measurement_record_length;
    6364              :     uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
    6365              :     uint8_t request_attribute;
    6366              :     void *data;
    6367              :     size_t data_size;
    6368              :     void *hash;
    6369              :     size_t hash_size;
    6370              : 
    6371            1 :     spdm_test_context = *state;
    6372            1 :     spdm_context = spdm_test_context->spdm_context;
    6373            1 :     spdm_test_context->case_id = 0x29;
    6374            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    6375              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    6376            1 :     spdm_context->connection_info.connection_state =
    6377              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
    6378            1 :     spdm_context->connection_info.capability.flags |=
    6379              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
    6380            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    6381              :                                                          m_libspdm_use_asym_algo, &data,
    6382              :                                                          &data_size, &hash, &hash_size)) {
    6383            0 :         assert(false);
    6384              :     }
    6385            1 :     libspdm_reset_message_m(spdm_context, NULL);
    6386            1 :     spdm_context->connection_info.algorithm.measurement_spec =
    6387              :         m_libspdm_use_measurement_spec;
    6388            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
    6389              :         m_libspdm_use_measurement_hash_algo;
    6390            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
    6391              :         m_libspdm_use_hash_algo;
    6392            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
    6393              :         m_libspdm_use_asym_algo;
    6394            1 :     spdm_context->local_context.algorithm.measurement_spec =
    6395              :         SPDM_MEASUREMENT_SPECIFICATION_DMTF;
    6396              : 
    6397              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6398              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
    6399              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    6400              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    6401              :                      data, data_size);
    6402              : #else
    6403            1 :     libspdm_hash_all(
    6404              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6405              :         data, data_size,
    6406            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
    6407            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
    6408            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    6409            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
    6410              :         spdm_context->connection_info.algorithm.base_hash_algo,
    6411              :         spdm_context->connection_info.algorithm.base_asym_algo,
    6412              :         data, data_size,
    6413              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
    6414              : #endif
    6415              : 
    6416            1 :     measurement_record_length = sizeof(measurement_record);
    6417              : 
    6418            1 :     libspdm_set_mem(m_requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
    6419              : 
    6420            1 :     request_attribute = 0; /* Do not request a signature. */
    6421              : 
    6422            1 :     status = libspdm_get_measurement_ex2(spdm_context, NULL, request_attribute, 1,
    6423              :                                          0, m_requester_context, NULL, &number_of_block,
    6424              :                                          &measurement_record_length,
    6425              :                                          measurement_record, NULL, NULL, NULL, NULL, NULL);
    6426              : 
    6427            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    6428              : 
    6429              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    6430              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    6431              : #endif
    6432            1 :     free(data);
    6433            1 : }
    6434              : 
    6435            1 : int libspdm_req_get_measurements_test(void)
    6436              : {
    6437            1 :     const struct CMUnitTest test_cases[] = {
    6438              :         cmocka_unit_test(req_get_measurements_case1),
    6439              :         cmocka_unit_test(req_get_measurements_case2),
    6440              :         cmocka_unit_test(req_get_measurements_case3),
    6441              :         cmocka_unit_test(req_get_measurements_case4),
    6442              :         cmocka_unit_test(req_get_measurements_case5),
    6443              :         cmocka_unit_test(req_get_measurements_case6),
    6444              :         cmocka_unit_test(req_get_measurements_case7),
    6445              :         cmocka_unit_test(req_get_measurements_case8),
    6446              :         cmocka_unit_test(req_get_measurements_case9),
    6447              :         cmocka_unit_test(req_get_measurements_case10),
    6448              :         cmocka_unit_test(req_get_measurements_case11),
    6449              :         cmocka_unit_test(req_get_measurements_case12),
    6450              :         cmocka_unit_test(req_get_measurements_case13),
    6451              :         cmocka_unit_test(req_get_measurements_case14),
    6452              :         cmocka_unit_test(req_get_measurements_case15),
    6453              :         cmocka_unit_test(req_get_measurements_case16),
    6454              :         cmocka_unit_test(req_get_measurements_case17),
    6455              :         cmocka_unit_test(req_get_measurements_case18),
    6456              :         cmocka_unit_test(req_get_measurements_case19),
    6457              :         cmocka_unit_test(req_get_measurements_case20),
    6458              :         cmocka_unit_test(req_get_measurements_case21),
    6459              :         cmocka_unit_test(req_get_measurements_case22),
    6460              :         cmocka_unit_test(req_get_measurements_case23),
    6461              :         cmocka_unit_test(req_get_measurements_case24),
    6462              :         cmocka_unit_test(req_get_measurements_case25),
    6463              :         cmocka_unit_test(req_get_measurements_case26),
    6464              :         cmocka_unit_test(req_get_measurements_case27),
    6465              :         cmocka_unit_test(req_get_measurements_case28),
    6466              :         cmocka_unit_test(req_get_measurements_case29),
    6467              :         cmocka_unit_test(req_get_measurements_case30),
    6468              :         cmocka_unit_test(req_get_measurements_case31),
    6469              :         cmocka_unit_test(req_get_measurements_case32),
    6470              :         cmocka_unit_test(req_get_measurements_case33),
    6471              :         cmocka_unit_test(req_get_measurements_case34),
    6472              :         cmocka_unit_test(req_get_measurements_case35),
    6473              :         cmocka_unit_test(req_get_measurements_case36),
    6474              :         cmocka_unit_test(req_get_measurements_case37),
    6475              :         cmocka_unit_test(req_get_measurements_case38),
    6476              :         cmocka_unit_test(req_get_measurements_case39),
    6477              :         cmocka_unit_test(req_get_measurements_case40),
    6478              :         cmocka_unit_test(req_get_measurements_case41),
    6479              :     };
    6480              : 
    6481            1 :     libspdm_test_context_t test_context = {
    6482              :         LIBSPDM_TEST_CONTEXT_VERSION,
    6483              :         true,
    6484              :         send_message,
    6485              :         receive_message,
    6486              :     };
    6487              : 
    6488            1 :     libspdm_setup_test_context(&test_context);
    6489              : 
    6490            1 :     return cmocka_run_group_tests(test_cases,
    6491              :                                   libspdm_unit_test_group_setup,
    6492              :                                   libspdm_unit_test_group_teardown);
    6493              : }
    6494              : 
    6495              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
        

Generated by: LCOV version 2.0-1