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

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

Generated by: LCOV version 2.0-1