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: 95.3 % 2714 2587
Test Date: 2025-06-29 08:09:00 Functions: 100.0 % 45 45

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

Generated by: LCOV version 2.0-1