LCOV - code coverage report
Current view: top level - unit_test/test_spdm_requester/error_test - get_measurements_err.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 68.0 % 2088 1419
Test Date: 2026-02-22 08:11:49 Functions: 100.0 % 41 41

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

Generated by: LCOV version 2.0-1