LCOV - code coverage report
Current view: top level - unit_test/test_spdm_requester - get_digests.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 62.0 % 882 547
Test Date: 2026-02-22 08:11:49 Functions: 100.0 % 32 32

            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_SEND_GET_CERTIFICATE_SUPPORT
      12              : 
      13              : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
      14              : 
      15              : static void *m_libspdm_local_certificate_chain_test_cert;
      16              : static size_t m_libspdm_local_certificate_chain_size;
      17              : 
      18              : static size_t m_libspdm_local_buffer_size;
      19              : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE];
      20              : 
      21              : static bool m_get_digest;
      22              : 
      23              : static spdm_key_usage_bit_mask_t m_local_key_usage_bit_mask[SPDM_MAX_SLOT_COUNT];
      24              : static spdm_certificate_info_t m_local_cert_info[SPDM_MAX_SLOT_COUNT];
      25              : static spdm_key_pair_id_t m_local_key_pair_id[SPDM_MAX_SLOT_COUNT];
      26              : 
      27           13 : static libspdm_return_t send_message(
      28              :     void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
      29              : {
      30              :     libspdm_test_context_t *spdm_test_context;
      31              : 
      32           13 :     spdm_test_context = libspdm_get_test_context();
      33           13 :     switch (spdm_test_context->case_id) {
      34            0 :     case 0x1:
      35            0 :         return LIBSPDM_STATUS_SEND_FAIL;
      36            1 :     case 0x2:
      37            1 :         return LIBSPDM_STATUS_SUCCESS;
      38            0 :     case 0x3:
      39            0 :         return LIBSPDM_STATUS_SUCCESS;
      40            0 :     case 0x4:
      41            0 :         return LIBSPDM_STATUS_SUCCESS;
      42            0 :     case 0x5:
      43            0 :         return LIBSPDM_STATUS_SUCCESS;
      44            0 :     case 0x6:
      45            0 :         return LIBSPDM_STATUS_SUCCESS;
      46            0 :     case 0x7:
      47            0 :         return LIBSPDM_STATUS_SUCCESS;
      48            0 :     case 0x8:
      49            0 :         return LIBSPDM_STATUS_SUCCESS;
      50            0 :     case 0x9:
      51            0 :         return LIBSPDM_STATUS_SUCCESS;
      52            0 :     case 0xA:
      53            0 :         return LIBSPDM_STATUS_SUCCESS;
      54            0 :     case 0xB:
      55            0 :         return LIBSPDM_STATUS_SUCCESS;
      56            0 :     case 0xC:
      57            0 :         return LIBSPDM_STATUS_SUCCESS;
      58            0 :     case 0xD:
      59            0 :         return LIBSPDM_STATUS_SUCCESS;
      60            0 :     case 0xE:
      61            0 :         return LIBSPDM_STATUS_SUCCESS;
      62            0 :     case 0xF:
      63            0 :         return LIBSPDM_STATUS_SUCCESS;
      64            0 :     case 0x10:
      65            0 :         return LIBSPDM_STATUS_SUCCESS;
      66            0 :     case 0x11:
      67            0 :         return LIBSPDM_STATUS_SUCCESS;
      68            0 :     case 0x12:
      69            0 :         return LIBSPDM_STATUS_SUCCESS;
      70            0 :     case 0x13:
      71            0 :         return LIBSPDM_STATUS_SUCCESS;
      72            0 :     case 0x14:
      73            0 :         return LIBSPDM_STATUS_SUCCESS;
      74            0 :     case 0x15:
      75            0 :         return LIBSPDM_STATUS_SUCCESS;
      76            0 :     case 0x16:
      77            0 :         return LIBSPDM_STATUS_SUCCESS;
      78            1 :     case 0x17: {
      79            1 :         const uint8_t *ptr = (const uint8_t *)request;
      80              : 
      81            1 :         m_libspdm_local_buffer_size = 0;
      82            1 :         libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
      83            1 :                          &ptr[1], request_size - 1);
      84            1 :         m_libspdm_local_buffer_size += (request_size - 1);
      85              :     }
      86            1 :         return LIBSPDM_STATUS_SUCCESS;
      87            4 :     case 0x18:
      88            4 :         return LIBSPDM_STATUS_SUCCESS;
      89            7 :     case 0x19:
      90              :     case 0x1A:
      91              :     case 0x1B:
      92              :     case 0x1C:
      93              :     case 0x1D:
      94            7 :         return LIBSPDM_STATUS_SUCCESS;
      95            0 :     default:
      96            0 :         return LIBSPDM_STATUS_SEND_FAIL;
      97              :     }
      98              : }
      99              : 
     100           13 : static libspdm_return_t receive_message(
     101              :     void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
     102              : {
     103              :     libspdm_test_context_t *spdm_test_context;
     104              : 
     105           13 :     spdm_test_context = libspdm_get_test_context();
     106           13 :     switch (spdm_test_context->case_id) {
     107            0 :     case 0x1:
     108            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
     109              : 
     110            1 :     case 0x2: {
     111              :         spdm_digest_response_t *spdm_response;
     112              :         uint8_t *digest;
     113              :         size_t spdm_response_size;
     114              :         size_t transport_header_size;
     115              : 
     116              :         ((libspdm_context_t *)spdm_context)
     117            1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     118            1 :         spdm_response_size = sizeof(spdm_digest_response_t) +
     119            1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT;
     120            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     121            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     122              : 
     123            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     124            1 :         spdm_response->header.param1 = 0;
     125            1 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     126            1 :         spdm_response->header.param2 = 0;
     127            1 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     128              :                         sizeof(m_libspdm_local_certificate_chain),
     129              :                         (uint8_t)(0xFF));
     130              : 
     131            1 :         digest = (void *)(spdm_response + 1);
     132            1 :         libspdm_zero_mem (digest,
     133            1 :                           libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
     134            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     135              :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     136            1 :         spdm_response->header.param2 |= (0x01 << 0);
     137              : 
     138            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     139              :                                               false, spdm_response_size,
     140              :                                               spdm_response, response_size,
     141              :                                               response);
     142              :     }
     143            1 :         return LIBSPDM_STATUS_SUCCESS;
     144              : 
     145            0 :     case 0x3: {
     146              :         spdm_digest_response_t *spdm_response;
     147              :         uint8_t *digest;
     148              :         size_t spdm_response_size;
     149              :         size_t transport_header_size;
     150              : 
     151              :         ((libspdm_context_t *)spdm_context)
     152            0 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     153            0 :         spdm_response_size = sizeof(spdm_digest_response_t) +
     154            0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
     155            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     156            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     157              : 
     158            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     159            0 :         spdm_response->header.param1 = 0;
     160            0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     161            0 :         spdm_response->header.param2 = 0;
     162            0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     163              :                         sizeof(m_libspdm_local_certificate_chain),
     164              :                         (uint8_t)(0xFF));
     165              : 
     166            0 :         digest = (void *)(spdm_response + 1);
     167            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     168              :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     169            0 :         spdm_response->header.param2 |= (1 << 0);
     170              : 
     171            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     172              :                                               false, spdm_response_size,
     173              :                                               spdm_response, response_size,
     174              :                                               response);
     175              :     }
     176            0 :         return LIBSPDM_STATUS_SUCCESS;
     177              : 
     178            0 :     case 0x4: {
     179              :         spdm_error_response_t *spdm_response;
     180              :         size_t spdm_response_size;
     181              :         size_t transport_header_size;
     182              : 
     183            0 :         spdm_response_size = sizeof(spdm_error_response_t);
     184            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     185            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     186              : 
     187            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     188            0 :         spdm_response->header.request_response_code = SPDM_ERROR;
     189            0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
     190            0 :         spdm_response->header.param2 = 0;
     191              : 
     192            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     193              :                                               false, spdm_response_size,
     194              :                                               spdm_response,
     195              :                                               response_size, response);
     196              :     }
     197            0 :         return LIBSPDM_STATUS_SUCCESS;
     198              : 
     199            0 :     case 0x5: {
     200              :         spdm_error_response_t *spdm_response;
     201              :         size_t spdm_response_size;
     202              :         size_t transport_header_size;
     203              : 
     204            0 :         spdm_response_size = sizeof(spdm_error_response_t);
     205            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     206            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     207              : 
     208            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     209            0 :         spdm_response->header.request_response_code = SPDM_ERROR;
     210            0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     211            0 :         spdm_response->header.param2 = 0;
     212              : 
     213            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     214              :                                               false, spdm_response_size,
     215              :                                               spdm_response,
     216              :                                               response_size, response);
     217              :     }
     218            0 :         return LIBSPDM_STATUS_SUCCESS;
     219              : 
     220            0 :     case 0x6: {
     221              :         static size_t sub_index1 = 0;
     222            0 :         if (sub_index1 == 0) {
     223              :             spdm_error_response_t *spdm_response;
     224              :             size_t spdm_response_size;
     225              :             size_t transport_header_size;
     226              : 
     227            0 :             spdm_response_size = sizeof(spdm_error_response_t);
     228            0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     229            0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     230              : 
     231            0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     232            0 :             spdm_response->header.request_response_code = SPDM_ERROR;
     233            0 :             spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
     234            0 :             spdm_response->header.param2 = 0;
     235              : 
     236            0 :             libspdm_transport_test_encode_message(
     237              :                 spdm_context, NULL, false, false,
     238              :                 spdm_response_size, spdm_response,
     239              :                 response_size, response);
     240            0 :         } else if (sub_index1 == 1) {
     241              :             spdm_digest_response_t *spdm_response;
     242              :             uint8_t *digest;
     243              :             size_t spdm_response_size;
     244              :             size_t transport_header_size;
     245              : 
     246              :             ((libspdm_context_t *)spdm_context)
     247            0 :             ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     248            0 :             spdm_response_size = sizeof(spdm_digest_response_t) +
     249            0 :                                  libspdm_get_hash_size(m_libspdm_use_hash_algo);
     250            0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     251            0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     252              : 
     253            0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     254            0 :             spdm_response->header.param1 = 0;
     255            0 :             spdm_response->header.request_response_code = SPDM_DIGESTS;
     256            0 :             spdm_response->header.param2 = 0;
     257            0 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
     258              :                             sizeof(m_libspdm_local_certificate_chain), (uint8_t)(0xFF));
     259              : 
     260            0 :             digest = (void *)(spdm_response + 1);
     261            0 :             libspdm_hash_all(m_libspdm_use_hash_algo,
     262              :                              m_libspdm_local_certificate_chain,
     263              :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     264            0 :             spdm_response->header.param2 |= (1 << 0);
     265              : 
     266            0 :             libspdm_transport_test_encode_message(
     267              :                 spdm_context, NULL, false, false, spdm_response_size,
     268              :                 spdm_response, response_size, response);
     269              :         }
     270            0 :         sub_index1++;
     271              :     }
     272            0 :         return LIBSPDM_STATUS_SUCCESS;
     273              : 
     274            0 :     case 0x7: {
     275              :         spdm_error_response_t *spdm_response;
     276              :         size_t spdm_response_size;
     277              :         size_t transport_header_size;
     278              : 
     279            0 :         spdm_response_size = sizeof(spdm_error_response_t);
     280            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     281            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     282              : 
     283            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     284            0 :         spdm_response->header.request_response_code = SPDM_ERROR;
     285            0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
     286            0 :         spdm_response->header.param2 = 0;
     287              : 
     288            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     289              :                                               false, spdm_response_size,
     290              :                                               spdm_response,
     291              :                                               response_size, response);
     292              :     }
     293            0 :         return LIBSPDM_STATUS_SUCCESS;
     294              : 
     295            0 :     case 0x8: {
     296              :         spdm_error_response_data_response_not_ready_t *spdm_response;
     297              :         size_t spdm_response_size;
     298              :         size_t transport_header_size;
     299              : 
     300            0 :         spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
     301            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     302            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     303              : 
     304            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     305            0 :         spdm_response->header.request_response_code = SPDM_ERROR;
     306            0 :         spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
     307            0 :         spdm_response->header.param2 = 0;
     308            0 :         spdm_response->extend_error_data.rd_exponent = 1;
     309            0 :         spdm_response->extend_error_data.rd_tm = 2;
     310            0 :         spdm_response->extend_error_data.request_code = SPDM_GET_DIGESTS;
     311            0 :         spdm_response->extend_error_data.token = 0;
     312              : 
     313            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     314              :                                               false, spdm_response_size,
     315              :                                               spdm_response,
     316              :                                               response_size, response);
     317              :     }
     318            0 :         return LIBSPDM_STATUS_SUCCESS;
     319              : 
     320            0 :     case 0x9: {
     321              :         static size_t sub_index2 = 0;
     322            0 :         if (sub_index2 == 0) {
     323              :             spdm_error_response_data_response_not_ready_t
     324              :             *spdm_response;
     325              :             size_t spdm_response_size;
     326              :             size_t transport_header_size;
     327              : 
     328            0 :             spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
     329            0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     330            0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     331              : 
     332            0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     333            0 :             spdm_response->header.request_response_code = SPDM_ERROR;
     334            0 :             spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
     335            0 :             spdm_response->header.param2 = 0;
     336            0 :             spdm_response->extend_error_data.rd_exponent = 1;
     337            0 :             spdm_response->extend_error_data.rd_tm = 2;
     338            0 :             spdm_response->extend_error_data.request_code = SPDM_GET_DIGESTS;
     339            0 :             spdm_response->extend_error_data.token = 1;
     340              : 
     341            0 :             libspdm_transport_test_encode_message(
     342              :                 spdm_context, NULL, false, false,
     343              :                 spdm_response_size, spdm_response,
     344              :                 response_size, response);
     345            0 :         } else if (sub_index2 == 1) {
     346              :             spdm_digest_response_t *spdm_response;
     347              :             uint8_t *digest;
     348              :             size_t spdm_response_size;
     349              :             size_t transport_header_size;
     350              : 
     351              :             ((libspdm_context_t *)spdm_context)
     352            0 :             ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     353            0 :             spdm_response_size = sizeof(spdm_digest_response_t) +
     354            0 :                                  libspdm_get_hash_size(m_libspdm_use_hash_algo);
     355            0 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     356            0 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     357              : 
     358            0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     359            0 :             spdm_response->header.param1 = 0;
     360            0 :             spdm_response->header.request_response_code = SPDM_DIGESTS;
     361            0 :             spdm_response->header.param2 = 0;
     362            0 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
     363              :                             sizeof(m_libspdm_local_certificate_chain), (uint8_t)(0xFF));
     364              : 
     365            0 :             digest = (void *)(spdm_response + 1);
     366            0 :             libspdm_hash_all(m_libspdm_use_hash_algo,
     367              :                              m_libspdm_local_certificate_chain,
     368              :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     369            0 :             spdm_response->header.param2 |= (1 << 0);
     370              : 
     371            0 :             libspdm_transport_test_encode_message(
     372              :                 spdm_context, NULL, false, false, spdm_response_size,
     373              :                 spdm_response, response_size, response);
     374              :         }
     375            0 :         sub_index2++;
     376              :     }
     377            0 :         return LIBSPDM_STATUS_SUCCESS;
     378              : 
     379            0 :     case 0xA:
     380            0 :         return LIBSPDM_STATUS_SUCCESS;
     381              : 
     382            0 :     case 0xB:
     383            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
     384              : 
     385            0 :     case 0xC: {
     386              :         spdm_digest_response_t *spdm_response;
     387              :         size_t spdm_response_size;
     388              :         size_t transport_header_size;
     389              : 
     390              :         ((libspdm_context_t *)spdm_context)
     391            0 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     392            0 :         spdm_response_size = 2;
     393            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     394            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     395              : 
     396            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     397            0 :         spdm_response->header.param1 = 0;
     398            0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     399            0 :         spdm_response->header.param2 = 0;
     400              : 
     401            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     402              :                                               false, spdm_response_size,
     403              :                                               spdm_response, response_size,
     404              :                                               response);
     405              :     }
     406            0 :         return LIBSPDM_STATUS_SUCCESS;
     407              : 
     408            0 :     case 0xD: {
     409              :         spdm_digest_response_t *spdm_response;
     410              :         uint8_t *digest;
     411              :         size_t spdm_response_size;
     412              :         size_t transport_header_size;
     413              : 
     414              :         ((libspdm_context_t *)spdm_context)
     415            0 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     416            0 :         spdm_response_size = sizeof(spdm_digest_response_t) +
     417            0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
     418            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     419            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     420              : 
     421            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     422            0 :         spdm_response->header.param1 = 0;
     423            0 :         spdm_response->header.request_response_code = SPDM_CERTIFICATE;
     424            0 :         spdm_response->header.param2 = 0;
     425            0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     426              :                         sizeof(m_libspdm_local_certificate_chain),
     427              :                         (uint8_t)(0xFF));
     428              : 
     429            0 :         digest = (void *)(spdm_response + 1);
     430            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     431              :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     432            0 :         spdm_response->header.param2 |= (1 << 0);
     433              : 
     434            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     435              :                                               false, spdm_response_size,
     436              :                                               spdm_response, response_size,
     437              :                                               response);
     438              :     }
     439            0 :         return LIBSPDM_STATUS_SUCCESS;
     440              : 
     441            0 :     case 0xE: {
     442              :         spdm_digest_response_t *spdm_response;
     443              :         size_t spdm_response_size;
     444              :         size_t transport_header_size;
     445              : 
     446            0 :         spdm_response_size = sizeof(spdm_digest_response_t);
     447            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     448            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     449              : 
     450            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     451            0 :         spdm_response->header.param1 = 0;
     452            0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     453            0 :         spdm_response->header.param2 = 0;
     454              : 
     455            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     456              :                                               false, spdm_response_size,
     457              :                                               spdm_response,
     458              :                                               response_size, response);
     459              :     }
     460            0 :         return LIBSPDM_STATUS_SUCCESS;
     461              : 
     462            0 :     case 0xF:
     463            0 :         return LIBSPDM_STATUS_SUCCESS;
     464              : 
     465            0 :     case 0x10: {
     466              :         spdm_digest_response_t *spdm_response;
     467              :         uint8_t *digest;
     468              :         size_t spdm_response_size;
     469              :         size_t transport_header_size;
     470              : 
     471              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     472              :         ((libspdm_context_t *)spdm_context)->transcript.message_b.buffer_size =
     473              :             ((libspdm_context_t *)spdm_context)->transcript.message_b.max_buffer_size -
     474              :             (sizeof(spdm_digest_response_t));
     475              : #endif
     476              : 
     477              :         ((libspdm_context_t *)spdm_context)
     478            0 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     479            0 :         spdm_response_size = sizeof(spdm_digest_response_t) +
     480            0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
     481            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     482            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     483              : 
     484            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     485            0 :         spdm_response->header.param1 = 0;
     486            0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     487            0 :         spdm_response->header.param2 = 0;
     488            0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     489              :                         sizeof(m_libspdm_local_certificate_chain),
     490              :                         (uint8_t)(0xFF));
     491              : 
     492            0 :         digest = (void *)(spdm_response + 1);
     493            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     494              :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     495            0 :         spdm_response->header.param2 |= (1 << 0);
     496              : 
     497            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     498              :                                               false, spdm_response_size,
     499              :                                               spdm_response, response_size,
     500              :                                               response);
     501              :     }
     502            0 :         return LIBSPDM_STATUS_SUCCESS;
     503              : 
     504            0 :     case 0x11: {
     505              :         spdm_digest_response_t *spdm_response;
     506              :         uint8_t *digest;
     507              :         size_t spdm_response_size;
     508              :         size_t transport_header_size;
     509              : 
     510              :         ((libspdm_context_t *)spdm_context)
     511            0 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     512            0 :         spdm_response_size = sizeof(spdm_digest_response_t) +
     513            0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
     514            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     515            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     516              : 
     517            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     518            0 :         spdm_response->header.param1 = 0;
     519            0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     520            0 :         spdm_response->header.param2 = 0;
     521            0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     522              :                         sizeof(m_libspdm_local_certificate_chain),
     523              :                         (uint8_t)(0xFF));
     524              : 
     525            0 :         digest = (void *)(spdm_response + 1);
     526            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     527              :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     528            0 :         digest[libspdm_get_hash_size(m_libspdm_use_hash_algo) - 1] = 0;
     529            0 :         spdm_response->header.param2 |= (1 << 0);
     530              : 
     531            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     532              :                                               false, spdm_response_size,
     533              :                                               spdm_response, response_size,
     534              :                                               response);
     535              :     }
     536            0 :         return LIBSPDM_STATUS_SUCCESS;
     537              : 
     538            0 :     case 0x12: {
     539              :         spdm_digest_response_t *spdm_response;
     540              :         uint8_t *digest;
     541              :         size_t digest_count;
     542              :         size_t spdm_response_size;
     543              :         size_t transport_header_size;
     544              :         size_t index;
     545              : 
     546              :         ((libspdm_context_t *)spdm_context)
     547            0 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     548            0 :         digest_count = 4;
     549            0 :         spdm_response_size = sizeof(spdm_digest_response_t) +
     550            0 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
     551            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     552            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     553              : 
     554            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     555            0 :         spdm_response->header.param1 = 0;
     556            0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     557            0 :         spdm_response->header.param2 = 0;
     558            0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     559              :                         sizeof(m_libspdm_local_certificate_chain),
     560              :                         (uint8_t)(0xFF));
     561              : 
     562            0 :         digest = (void *)(spdm_response + 1);
     563              : 
     564            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     565              :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     566            0 :         for (index = 0; index < digest_count; index++) {
     567            0 :             spdm_response->header.param2 |= (1 << index);
     568              :         }
     569              : 
     570            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     571              :                                               false, spdm_response_size,
     572              :                                               spdm_response, response_size,
     573              :                                               response);
     574              :     }
     575            0 :         return LIBSPDM_STATUS_SUCCESS;
     576              : 
     577            0 :     case 0x13: {
     578              :         spdm_digest_response_t *spdm_response;
     579              :         uint8_t *digest;
     580              :         size_t digest_count;
     581              :         size_t spdm_response_size;
     582              :         size_t transport_header_size;
     583              :         size_t index;
     584              : 
     585              :         ((libspdm_context_t *)spdm_context)
     586            0 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     587            0 :         digest_count = 4;
     588            0 :         spdm_response_size =
     589              :             sizeof(spdm_digest_response_t) +
     590            0 :             digest_count * libspdm_get_hash_size(m_libspdm_use_hash_algo);
     591            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     592            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     593              : 
     594            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     595            0 :         spdm_response->header.param1 = 0;
     596            0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     597            0 :         spdm_response->header.param2 = 0;
     598            0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     599              :                         sizeof(m_libspdm_local_certificate_chain),
     600              :                         (uint8_t)(0xFF));
     601              : 
     602            0 :         digest = (void *)(spdm_response + 1);
     603              : 
     604            0 :         for (index = 0; index < digest_count; index++) {
     605            0 :             libspdm_hash_all(
     606              :                 m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     607              :                 sizeof(m_libspdm_local_certificate_chain),
     608            0 :                 &digest[index *
     609            0 :                         libspdm_get_hash_size(m_libspdm_use_hash_algo)]);
     610            0 :             spdm_response->header.param2 |= (1 << index);
     611            0 :             if (index == 0) {
     612            0 :                 continue;
     613              :             }
     614            0 :             digest[(index + 1) * libspdm_get_hash_size(m_libspdm_use_hash_algo) -
     615            0 :                    1] = 0;
     616              :         }
     617              : 
     618            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     619              :                                               false, spdm_response_size,
     620              :                                               spdm_response, response_size,
     621              :                                               response);
     622              :     }
     623            0 :         return LIBSPDM_STATUS_SUCCESS;
     624              : 
     625            0 :     case 0x14: {
     626              :         spdm_digest_response_t *spdm_response;
     627              :         size_t spdm_response_size;
     628              :         size_t transport_header_size;
     629              : 
     630              :         ((libspdm_context_t *)spdm_context)
     631            0 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     632            0 :         spdm_response_size = 5;
     633            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     634            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     635              : 
     636            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     637            0 :         spdm_response->header.param1 = 0;
     638            0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     639            0 :         spdm_response->header.param2 = 0;
     640              : 
     641            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     642              :                                               false, spdm_response_size,
     643              :                                               spdm_response, response_size,
     644              :                                               response);
     645              :     }
     646            0 :         return LIBSPDM_STATUS_SUCCESS;
     647              : 
     648            0 :     case 0x15: {
     649              :         spdm_digest_response_t *spdm_response;
     650              :         uint8_t *digest;
     651              :         size_t spdm_response_size;
     652              :         size_t transport_header_size;
     653              : 
     654              :         ((libspdm_context_t *)spdm_context)
     655            0 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     656            0 :         spdm_response_size = sizeof(spdm_message_header_t) +
     657              :                              LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT + 1;
     658            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     659            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     660              : 
     661            0 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     662            0 :         spdm_response->header.param1 = 0;
     663            0 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     664            0 :         spdm_response->header.param2 = 0;
     665            0 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     666              :                         sizeof(m_libspdm_local_certificate_chain),
     667              :                         (uint8_t)(0xFF));
     668              : 
     669            0 :         digest = (void *)(spdm_response + 1);
     670            0 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     671              :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     672            0 :         spdm_response->header.param2 |= (1 << 0);
     673              : 
     674            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     675              :                                               false, spdm_response_size,
     676              :                                               spdm_response, response_size,
     677              :                                               response);
     678              :     }
     679            0 :         return LIBSPDM_STATUS_SUCCESS;
     680              : 
     681            0 :     case 0x16:
     682              :     {
     683              :         static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
     684              : 
     685              :         spdm_error_response_t *spdm_response;
     686              :         size_t spdm_response_size;
     687              :         size_t transport_header_size;
     688              : 
     689            0 :         spdm_response_size = sizeof(spdm_error_response_t);
     690            0 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     691            0 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     692              : 
     693            0 :         if(error_code <= 0xff) {
     694            0 :             libspdm_zero_mem (spdm_response, spdm_response_size);
     695            0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     696            0 :             spdm_response->header.request_response_code = SPDM_ERROR;
     697            0 :             spdm_response->header.param1 = (uint8_t) error_code;
     698            0 :             spdm_response->header.param2 = 0;
     699              : 
     700            0 :             libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
     701              :                                                    spdm_response_size, spdm_response,
     702              :                                                    response_size, response);
     703              :         }
     704              : 
     705            0 :         error_code++;
     706            0 :         if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
     707            0 :             error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
     708              :         }
     709              :         /* skip some reserved error codes (0d to 3e) */
     710            0 :         if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
     711            0 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
     712              :         }
     713              :         /* skip response not ready, request resync, and some reserved codes (44 to fc) */
     714            0 :         if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
     715            0 :             error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
     716              :         }
     717              :     }
     718            0 :         return LIBSPDM_STATUS_SUCCESS;
     719              : 
     720            1 :     case 0x17: {
     721              :         spdm_digest_response_t *spdm_response;
     722              :         uint8_t *digest;
     723              :         size_t spdm_response_size;
     724              :         size_t transport_header_size;
     725              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     726              :         size_t arbitrary_size;
     727              : #endif
     728              : 
     729              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     730              :         /*filling B with arbitrary data*/
     731              :         arbitrary_size = 8;
     732              :         libspdm_set_mem(((libspdm_context_t *)spdm_context)->transcript.message_b.buffer,
     733              :                         arbitrary_size, (uint8_t) 0xEE);
     734              :         ((libspdm_context_t *)spdm_context)->transcript.message_b.buffer_size = arbitrary_size;
     735              : #endif
     736              : 
     737            1 :         ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
     738              :             m_libspdm_use_hash_algo;
     739            1 :         spdm_response_size = sizeof(spdm_digest_response_t) +
     740            1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
     741            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     742            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     743              : 
     744            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     745            1 :         spdm_response->header.param1 = 0;
     746            1 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     747            1 :         spdm_response->header.param2 = 0;
     748            1 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     749              :                         sizeof(m_libspdm_local_certificate_chain),
     750              :                         (uint8_t)(0xFF));
     751              : 
     752            1 :         digest = (void *)(spdm_response + 1);
     753            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     754              :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     755            1 :         spdm_response->header.param2 |= (0x01 << 0);
     756              : 
     757            1 :         libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
     758              :                          sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
     759              :                          spdm_response, spdm_response_size);
     760            1 :         m_libspdm_local_buffer_size += spdm_response_size;
     761              : 
     762            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     763              :                                               false, spdm_response_size,
     764              :                                               spdm_response, response_size,
     765              :                                               response);
     766              :     }
     767            1 :         return LIBSPDM_STATUS_SUCCESS;
     768              : 
     769            4 :     case 0x18: {
     770            4 :         if (m_get_digest) {
     771              :             spdm_digest_response_t *spdm_response;
     772              :             uint8_t *digest;
     773              :             size_t spdm_response_size;
     774              :             size_t transport_header_size;
     775              : 
     776              :             ((libspdm_context_t *)spdm_context)
     777            2 :             ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     778            2 :             spdm_response_size = sizeof(spdm_digest_response_t) +
     779            2 :                                  libspdm_get_hash_size(m_libspdm_use_hash_algo) *
     780              :                                  SPDM_MAX_SLOT_COUNT;
     781            2 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     782            2 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     783              : 
     784            2 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     785            2 :             spdm_response->header.param1 = 0;
     786            2 :             spdm_response->header.request_response_code = SPDM_DIGESTS;
     787            2 :             spdm_response->header.param2 = 0;
     788              : 
     789            2 :             if (m_libspdm_local_certificate_chain_test_cert == NULL) {
     790            2 :                 libspdm_read_responder_public_certificate_chain(
     791              :                     m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
     792              :                     &m_libspdm_local_certificate_chain_test_cert,
     793              :                     &m_libspdm_local_certificate_chain_size, NULL, NULL);
     794              :             }
     795            2 :             if (m_libspdm_local_certificate_chain_test_cert == NULL) {
     796            0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
     797              :             }
     798            2 :             digest = (void *)(spdm_response + 1);
     799            2 :             libspdm_zero_mem(digest,
     800            2 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
     801            2 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain_test_cert,
     802              :                              m_libspdm_local_certificate_chain_size, &digest[0]);
     803            2 :             spdm_response->header.param2 |= (0x01 << 0);
     804              : 
     805            2 :             libspdm_transport_test_encode_message(spdm_context, NULL, false,
     806              :                                                   false, spdm_response_size,
     807              :                                                   spdm_response, response_size,
     808              :                                                   response);
     809              :         } else {
     810              :             spdm_certificate_response_t *spdm_response;
     811              :             size_t spdm_response_size;
     812              :             size_t transport_header_size;
     813              :             uint16_t portion_length;
     814              :             uint16_t remainder_length;
     815              :             size_t count;
     816              :             static size_t calling_index = 0;
     817              : 
     818            2 :             if (m_libspdm_local_certificate_chain_test_cert == NULL) {
     819            0 :                 libspdm_read_responder_public_certificate_chain(
     820              :                     m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
     821              :                     &m_libspdm_local_certificate_chain_test_cert,
     822              :                     &m_libspdm_local_certificate_chain_size, NULL, NULL);
     823              :             }
     824            2 :             if (m_libspdm_local_certificate_chain_test_cert == NULL) {
     825            0 :                 return LIBSPDM_STATUS_RECEIVE_FAIL;
     826              :             }
     827            2 :             count = (m_libspdm_local_certificate_chain_size +
     828            2 :                      LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN - 1) /
     829              :                     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
     830            2 :             if (calling_index != count - 1) {
     831            1 :                 portion_length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
     832            1 :                 remainder_length =
     833            1 :                     (uint16_t)(m_libspdm_local_certificate_chain_size -
     834              :                                LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN *
     835            1 :                                (calling_index + 1));
     836              :             } else {
     837            1 :                 portion_length = (uint16_t)(
     838              :                     m_libspdm_local_certificate_chain_size -
     839            1 :                     LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * (count - 1));
     840            1 :                 remainder_length = 0;
     841              :             }
     842              : 
     843            2 :             spdm_response_size = sizeof(spdm_certificate_response_t) + portion_length;
     844            2 :             transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     845            2 :             spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     846              : 
     847            2 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     848            2 :             spdm_response->header.request_response_code = SPDM_CERTIFICATE;
     849            2 :             spdm_response->header.param1 = 0;
     850            2 :             spdm_response->header.param2 = 0;
     851            2 :             spdm_response->portion_length = portion_length;
     852            2 :             spdm_response->remainder_length = remainder_length;
     853            2 :             libspdm_copy_mem(spdm_response + 1,
     854            2 :                              (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
     855            2 :                              (uint8_t *)m_libspdm_local_certificate_chain_test_cert +
     856            2 :                              LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * calling_index,
     857              :                              portion_length);
     858              : 
     859            2 :             libspdm_transport_test_encode_message(spdm_context, NULL, false,
     860              :                                                   false, spdm_response_size,
     861              :                                                   spdm_response, response_size,
     862              :                                                   response);
     863              : 
     864            2 :             calling_index++;
     865            2 :             if (calling_index == count) {
     866            1 :                 calling_index = 0;
     867            1 :                 free(m_libspdm_local_certificate_chain_test_cert);
     868            1 :                 m_libspdm_local_certificate_chain_test_cert = NULL;
     869            1 :                 m_libspdm_local_certificate_chain_size = 0;
     870              :             }
     871              :         }
     872              :     }
     873            4 :         return LIBSPDM_STATUS_SUCCESS;
     874              : 
     875            1 :     case 0x19: {
     876              :         spdm_digest_response_t *spdm_response;
     877              :         uint8_t *digest;
     878              :         size_t spdm_response_size;
     879              :         size_t transport_header_size;
     880              :         uint32_t session_id;
     881              :         libspdm_session_info_t *session_info;
     882              :         uint8_t *scratch_buffer;
     883              :         size_t scratch_buffer_size;
     884              : 
     885            1 :         session_id = 0xFFFFFFFF;
     886              : 
     887              :         ((libspdm_context_t *)spdm_context)
     888            1 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     889            1 :         spdm_response_size = sizeof(spdm_digest_response_t) +
     890            1 :                              libspdm_get_hash_size(m_libspdm_use_hash_algo);
     891            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     892            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     893              : 
     894            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     895            1 :         spdm_response->header.param1 = 0;
     896            1 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     897            1 :         spdm_response->header.param2 = 0;
     898              : 
     899              :         /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
     900              :          * transport_message is always in sender buffer. */
     901            1 :         libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
     902              : 
     903            1 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     904              :                         sizeof(m_libspdm_local_certificate_chain),
     905              :                         (uint8_t)(0xFF));
     906              : 
     907            1 :         digest = (void *)(spdm_response + 1);
     908              :         /* send certchain digest of slot 7 */
     909            1 :         libspdm_zero_mem (digest,
     910            1 :                           libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
     911            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     912              :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     913            1 :         spdm_response->header.param2 |= (0x80 << 0);
     914              : 
     915            1 :         libspdm_copy_mem (scratch_buffer + transport_header_size,
     916              :                           scratch_buffer_size - transport_header_size,
     917              :                           spdm_response, spdm_response_size);
     918            1 :         spdm_response = (void *)(scratch_buffer + transport_header_size);
     919            1 :         libspdm_transport_test_encode_message(spdm_context, &session_id, false,
     920              :                                               false, spdm_response_size,
     921              :                                               spdm_response, response_size,
     922              :                                               response);
     923              : 
     924            1 :         session_info = libspdm_get_session_info_via_session_id( spdm_context, session_id);
     925            1 :         if (session_info == NULL) {
     926            0 :             return LIBSPDM_STATUS_RECEIVE_FAIL;
     927              :         }
     928              :         /* WALKAROUND: If just use single context to encode message and then decode message */
     929              :         ((libspdm_secured_message_context_t
     930            1 :           *)(session_info->secured_message_context))
     931            1 :         ->application_secret.response_data_sequence_number--;
     932              : 
     933              :     }
     934            1 :         return LIBSPDM_STATUS_SUCCESS;
     935              : 
     936            2 :     case 0x1A: {
     937              :         spdm_digest_response_t *spdm_response;
     938              :         uint8_t *digest;
     939              :         size_t hash_size;
     940              :         size_t spdm_response_size;
     941              :         size_t transport_header_size;
     942              :         spdm_key_pair_id_t *key_pair_id;
     943              :         spdm_certificate_info_t *cert_info;
     944              :         spdm_key_usage_bit_mask_t *key_usage_bit_mask;
     945              : 
     946              :         ((libspdm_context_t *)spdm_context)
     947            2 :         ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     948            2 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
     949            2 :         spdm_response_size = sizeof(spdm_digest_response_t) +
     950              :                              hash_size + sizeof(spdm_key_pair_id_t) +
     951              :                              sizeof(spdm_certificate_info_t) + sizeof(spdm_key_usage_bit_mask_t);
     952            2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
     953            2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
     954              : 
     955            2 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
     956            2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
     957            2 :         spdm_response->header.param1 = (0x01 << 0);
     958            2 :         spdm_response->header.param2 = 0;
     959            2 :         spdm_response->header.param2 |= (0x01 << 0);
     960              : 
     961            2 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
     962              :                         sizeof(m_libspdm_local_certificate_chain),
     963              :                         (uint8_t)(0xFF));
     964              : 
     965            2 :         digest = (void *)(spdm_response + 1);
     966            2 :         libspdm_zero_mem (digest, hash_size);
     967            2 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     968              :                          sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     969            2 :         key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + hash_size);
     970            2 :         cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
     971              :                                                 sizeof(spdm_key_pair_id_t));
     972            2 :         key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
     973              :                                                            sizeof(spdm_certificate_info_t));
     974            2 :         *key_pair_id = 0;
     975            2 :         *cert_info = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
     976            2 :         *key_usage_bit_mask = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
     977              :                               SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
     978              :                               SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
     979              :                               SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
     980              : 
     981            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
     982              :                                               false, spdm_response_size,
     983              :                                               spdm_response, response_size,
     984              :                                               response);
     985              :     }
     986            2 :         return LIBSPDM_STATUS_SUCCESS;
     987            1 :     case 0x1B: {
     988              :         spdm_digest_response_t *spdm_response;
     989              :         uint8_t *digest;
     990              :         size_t spdm_response_size;
     991              :         size_t transport_header_size;
     992              :         spdm_key_pair_id_t *key_pair_id;
     993              :         spdm_certificate_info_t *cert_info;
     994              :         spdm_key_usage_bit_mask_t *key_usage_bit_mask;
     995              :         uint32_t hash_size;
     996              :         uint8_t slot_count;
     997              :         size_t additional_size;
     998              : 
     999            1 :         slot_count = SPDM_MAX_SLOT_COUNT;
    1000            1 :         additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
    1001              :                           sizeof(spdm_key_usage_bit_mask_t);
    1002            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1003              : 
    1004            1 :         spdm_response_size = sizeof(spdm_digest_response_t) +
    1005            1 :                              (hash_size + additional_size) * slot_count;
    1006            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1007            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1008              : 
    1009            1 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
    1010            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
    1011            1 :         spdm_response->header.param1 = 0;
    1012            1 :         spdm_response->header.param2 = 0;
    1013              : 
    1014            1 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
    1015              :                         sizeof(m_libspdm_local_certificate_chain),
    1016              :                         (uint8_t)(0xFF));
    1017              : 
    1018            1 :         digest = (void *)(spdm_response + 1);
    1019            1 :         libspdm_zero_mem (digest, hash_size * slot_count);
    1020            1 :         key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + (hash_size * slot_count));
    1021            1 :         cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
    1022            1 :                                                 sizeof(spdm_key_pair_id_t) * slot_count);
    1023            1 :         key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
    1024            1 :                                                            sizeof(spdm_certificate_info_t) *
    1025              :                                                            slot_count);
    1026              : 
    1027            9 :         for (uint8_t index = 0; index < slot_count; index++)
    1028              :         {
    1029            8 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
    1030            8 :                              sizeof(m_libspdm_local_certificate_chain), &digest[hash_size * index]);
    1031              : 
    1032            8 :             key_pair_id[index] = m_local_key_pair_id[index];
    1033            8 :             cert_info[index] = m_local_cert_info[index];
    1034            8 :             key_usage_bit_mask[index] = m_local_key_usage_bit_mask[index];
    1035              : 
    1036            8 :             spdm_response->header.param1 |= (1 << index);
    1037            8 :             spdm_response->header.param2 |= (1 << index);
    1038              :         }
    1039              : 
    1040            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1041              :                                               false, spdm_response_size,
    1042              :                                               spdm_response, response_size,
    1043              :                                               response);
    1044              :     }
    1045            1 :         return LIBSPDM_STATUS_SUCCESS;
    1046            2 :     case 0x1C: {
    1047              :         spdm_digest_response_t *spdm_response;
    1048              :         uint8_t *digest;
    1049              :         size_t spdm_response_size;
    1050              :         size_t transport_header_size;
    1051              :         spdm_key_pair_id_t *key_pair_id;
    1052              :         spdm_certificate_info_t *cert_info;
    1053              :         spdm_key_usage_bit_mask_t *key_usage_bit_mask;
    1054              :         uint32_t hash_size;
    1055              :         uint8_t slot_count;
    1056              :         size_t additional_size;
    1057              : 
    1058            2 :         slot_count = 1;
    1059            2 :         additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
    1060              :                           sizeof(spdm_key_usage_bit_mask_t);
    1061            2 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1062              : 
    1063            2 :         spdm_response_size = sizeof(spdm_digest_response_t) +
    1064            2 :                              (hash_size + additional_size) * slot_count;
    1065            2 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1066            2 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1067              : 
    1068            2 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
    1069            2 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
    1070            2 :         spdm_response->header.param1 = 0;
    1071            2 :         spdm_response->header.param2 = 0;
    1072              : 
    1073            2 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
    1074              :                         sizeof(m_libspdm_local_certificate_chain),
    1075              :                         (uint8_t)(0xFF));
    1076              : 
    1077            2 :         digest = (void *)(spdm_response + 1);
    1078            2 :         key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + (hash_size * slot_count));
    1079            2 :         cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
    1080            2 :                                                 sizeof(spdm_key_pair_id_t) * slot_count);
    1081            2 :         key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
    1082            2 :                                                            sizeof(spdm_certificate_info_t) *
    1083              :                                                            slot_count);
    1084              : 
    1085              :         /* Set Digest KeyUsageMask and CertificateInfo to 0*/
    1086            2 :         libspdm_zero_mem (digest, hash_size * slot_count);
    1087            2 :         key_pair_id[0] = m_local_key_pair_id[0];
    1088            2 :         cert_info[0] = m_local_cert_info[0];
    1089            2 :         key_usage_bit_mask[0] = m_local_key_usage_bit_mask[0];
    1090              : 
    1091            2 :         spdm_response->header.param1 |= (1 << 0);
    1092            2 :         spdm_response->header.param2 |= (1 << 0);
    1093              : 
    1094            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1095              :                                               false, spdm_response_size,
    1096              :                                               spdm_response, response_size,
    1097              :                                               response);
    1098              :     }
    1099            2 :         return LIBSPDM_STATUS_SUCCESS;
    1100            1 :     case 0x1D: {
    1101              :         spdm_digest_response_t *spdm_response;
    1102              :         uint8_t *digest;
    1103              :         size_t spdm_response_size;
    1104              :         size_t transport_header_size;
    1105              :         spdm_key_pair_id_t *key_pair_id;
    1106              :         spdm_certificate_info_t *cert_info;
    1107              :         spdm_key_usage_bit_mask_t *key_usage_bit_mask;
    1108              :         uint32_t hash_size;
    1109              :         uint8_t slot_count;
    1110              :         size_t additional_size;
    1111              : 
    1112            1 :         slot_count = 2;
    1113            1 :         additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
    1114              :                           sizeof(spdm_key_usage_bit_mask_t);
    1115            1 :         hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1116              : 
    1117            1 :         spdm_response_size = sizeof(spdm_digest_response_t) +
    1118            1 :                              (hash_size + additional_size) * slot_count;
    1119            1 :         transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
    1120            1 :         spdm_response = (void *)((uint8_t *)*response + transport_header_size);
    1121              : 
    1122            1 :         spdm_response->header.request_response_code = SPDM_DIGESTS;
    1123            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
    1124            1 :         spdm_response->header.param1 = 0;
    1125            1 :         spdm_response->header.param2 = 0;
    1126              : 
    1127            1 :         libspdm_set_mem(m_libspdm_local_certificate_chain,
    1128              :                         sizeof(m_libspdm_local_certificate_chain),
    1129              :                         (uint8_t)(0xFF));
    1130              : 
    1131            1 :         digest = (void *)(spdm_response + 1);
    1132            1 :         key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + (hash_size * slot_count));
    1133            1 :         cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
    1134            1 :                                                 sizeof(spdm_key_pair_id_t) * slot_count);
    1135            1 :         key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
    1136            1 :                                                            sizeof(spdm_certificate_info_t) *
    1137              :                                                            slot_count);
    1138              : 
    1139            1 :         libspdm_zero_mem (digest, hash_size * slot_count);
    1140            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
    1141              :                          sizeof(m_libspdm_local_certificate_chain), &digest[hash_size * 0]);
    1142            1 :         key_pair_id[0] = m_local_key_pair_id[0];
    1143            1 :         cert_info[0] = m_local_cert_info[0];
    1144            1 :         key_usage_bit_mask[0] = m_local_key_usage_bit_mask[0];
    1145              : 
    1146            1 :         spdm_response->header.param1 |= (1 << 0);
    1147            1 :         spdm_response->header.param2 |= (1 << 0);
    1148              : 
    1149            1 :         libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
    1150            1 :                          sizeof(m_libspdm_local_certificate_chain), &digest[hash_size * 1]);
    1151            1 :         key_pair_id[1] = m_local_key_pair_id[1];
    1152            1 :         cert_info[1] = m_local_cert_info[1];
    1153            1 :         key_usage_bit_mask[1] = m_local_key_usage_bit_mask[1];
    1154              : 
    1155            1 :         spdm_response->header.param1 |= (1 << 1);
    1156            1 :         spdm_response->header.param2 |= (1 << 1);
    1157              : 
    1158            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false,
    1159              :                                               false, spdm_response_size,
    1160              :                                               spdm_response, response_size,
    1161              :                                               response);
    1162              :     }
    1163            1 :         return LIBSPDM_STATUS_SUCCESS;
    1164            0 :     default:
    1165            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
    1166              :     }
    1167              : }
    1168              : 
    1169              : /**
    1170              :  * Test 1:
    1171              :  * Expected Behavior:
    1172              :  **/
    1173            1 : static void req_get_digests_case1(void **state)
    1174              : {
    1175            1 : }
    1176              : 
    1177              : /**
    1178              :  * Test 2: a request message is successfully sent and a response message is successfully received
    1179              :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a DIGESTS message is received
    1180              :  **/
    1181            1 : static void req_get_digests_case2(void **state)
    1182              : {
    1183              :     libspdm_return_t status;
    1184              :     libspdm_test_context_t *spdm_test_context;
    1185              :     libspdm_context_t *spdm_context;
    1186              :     libspdm_data_parameter_t parameter;
    1187              :     uint8_t slot_mask;
    1188              :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1189              :     uint8_t my_total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1190              :     uint8_t *digest;
    1191              :     size_t data_return_size;
    1192              : 
    1193            1 :     spdm_test_context = *state;
    1194            1 :     spdm_context = spdm_test_context->spdm_context;
    1195            1 :     spdm_test_context->case_id = 0x2;
    1196            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1197              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1198            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1199            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1200            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1201            1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
    1202              :                     sizeof(m_libspdm_local_certificate_chain),
    1203              :                     (uint8_t)(0xFF));
    1204            1 :     libspdm_reset_message_b(spdm_context);
    1205              : 
    1206              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1207              :     spdm_context->transcript.message_m.buffer_size =
    1208              :         spdm_context->transcript.message_m.max_buffer_size;
    1209              : #endif
    1210            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1211            1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
    1212            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1213              : 
    1214            1 :     assert_int_equal(slot_mask, 0x01);
    1215            1 :     libspdm_zero_mem(my_total_digest_buffer, sizeof(my_total_digest_buffer));
    1216            1 :     digest = my_total_digest_buffer;
    1217            1 :     libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
    1218              :                      sizeof(m_libspdm_local_certificate_chain), digest);
    1219            1 :     assert_memory_equal (total_digest_buffer, my_total_digest_buffer,
    1220              :                          sizeof(my_total_digest_buffer));
    1221              : 
    1222            1 :     parameter.location = LIBSPDM_DATA_LOCATION_CONNECTION;
    1223            1 :     data_return_size = sizeof(uint8_t);
    1224            1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_PEER_SLOT_MASK,
    1225              :                               &parameter, &slot_mask, &data_return_size);
    1226            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1227            1 :     assert_int_equal(data_return_size, sizeof(uint8_t));
    1228            1 :     assert_int_equal(slot_mask, 0x01);
    1229              : 
    1230              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1231              :     assert_int_equal(
    1232              :         spdm_context->transcript.message_b.buffer_size,
    1233              :         sizeof(spdm_get_digest_request_t) +
    1234              :         sizeof(spdm_digest_response_t) +
    1235              :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo));
    1236              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    1237              : #endif
    1238            1 : }
    1239              : 
    1240              : /**
    1241              :  * Test 3:
    1242              :  * Expected Behavior:
    1243              :  **/
    1244            1 : static void req_get_digests_case3(void **state)
    1245              : {
    1246            1 : }
    1247              : 
    1248              : /**
    1249              :  * Test 4:
    1250              :  * Expected Behavior:
    1251              :  **/
    1252            1 : static void req_get_digests_case4(void **state)
    1253              : {
    1254            1 : }
    1255              : 
    1256              : /**
    1257              :  * Test 5:
    1258              :  * Expected Behavior:
    1259              :  **/
    1260            1 : static void req_get_digests_case5(void **state)
    1261              : {
    1262            1 : }
    1263              : 
    1264              : /**
    1265              :  * Test 6:
    1266              :  * Expected Behavior:
    1267              :  **/
    1268            1 : static void req_get_digests_case6(void **state)
    1269              : {
    1270            1 : }
    1271              : 
    1272              : /**
    1273              :  * Test 7:
    1274              :  * Expected Behavior:
    1275              :  **/
    1276            1 : static void req_get_digests_case7(void **state)
    1277              : {
    1278            1 : }
    1279              : 
    1280              : /**
    1281              :  * Test 8:
    1282              :  * Expected Behavior:
    1283              :  **/
    1284            1 : static void req_get_digests_case8(void **state)
    1285              : {
    1286            1 : }
    1287              : 
    1288              : /**
    1289              :  * Test 9:
    1290              :  * Expected Behavior:
    1291              :  **/
    1292            1 : static void req_get_digests_case9(void **state)
    1293              : {
    1294            1 : }
    1295              : 
    1296              : /**
    1297              :  * Test 10:
    1298              :  * Expected Behavior:
    1299              :  **/
    1300            1 : static void req_get_digests_case10(void **state)
    1301              : {
    1302            1 : }
    1303              : 
    1304              : /**
    1305              :  * Test 11:
    1306              :  * Expected Behavior:
    1307              :  **/
    1308            1 : static void req_get_digests_case11(void **state)
    1309              : {
    1310            1 : }
    1311              : 
    1312              : /**
    1313              :  * Test 12:
    1314              :  * Expected Behavior:
    1315              :  **/
    1316            1 : static void req_get_digests_case12(void **state)
    1317              : {
    1318            1 : }
    1319              : 
    1320              : /**
    1321              :  * Test 13:
    1322              :  * Expected Behavior:
    1323              :  **/
    1324            1 : static void req_get_digests_case13(void **state)
    1325              : {
    1326            1 : }
    1327              : 
    1328              : /**
    1329              :  * Test 14:
    1330              :  * Expected Behavior:
    1331              :  **/
    1332            1 : static void req_get_digests_case14(void **state)
    1333              : {
    1334            1 : }
    1335              : 
    1336              : /**
    1337              :  * Test 15:
    1338              :  * Expected Behavior:
    1339              :  **/
    1340            1 : static void req_get_digests_case15(void **state)
    1341              : {
    1342            1 : }
    1343              : 
    1344              : /**
    1345              :  * Test 16:
    1346              :  * Expected Behavior:
    1347              :  **/
    1348            1 : static void req_get_digests_case16(void **state)
    1349              : {
    1350            1 : }
    1351              : 
    1352              : /**
    1353              :  * Test 17:
    1354              :  * Expected Behavior:
    1355              :  **/
    1356            1 : static void req_get_digests_case17(void **state)
    1357              : {
    1358            1 : }
    1359              : 
    1360              : /**
    1361              :  * Test 18:
    1362              :  * Expected Behavior:
    1363              :  **/
    1364            1 : static void req_get_digests_case18(void **state)
    1365              : {
    1366            1 : }
    1367              : 
    1368              : /**
    1369              :  * Test 19:
    1370              :  * Expected Behavior:
    1371              :  **/
    1372            1 : static void req_get_digests_case19(void **state)
    1373              : {
    1374            1 : }
    1375              : 
    1376              : /**
    1377              :  * Test 20:
    1378              :  * Expected Behavior:
    1379              :  **/
    1380            1 : static void req_get_digests_case20(void **state)
    1381              : {
    1382            1 : }
    1383              : 
    1384              : /**
    1385              :  * Test 21:
    1386              :  * Expected Behavior:
    1387              :  **/
    1388            1 : static void req_get_digests_case21(void **state)
    1389              : {
    1390            1 : }
    1391              : 
    1392              : /**
    1393              :  * Test 22:
    1394              :  * Expected behavior:.
    1395              :  **/
    1396            1 : static void req_get_digests_case22(void **state)
    1397              : {
    1398            1 : }
    1399              : 
    1400              : /**
    1401              :  * Test 23: a request message is successfully sent and a response message is successfully received.
    1402              :  * Buffer B already has arbitrary data.
    1403              :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a DIGESTS message is
    1404              :  * received, buffer B appends the exchanged GET_DIGESTS and DIGESTS messages.
    1405              :  **/
    1406            1 : static void req_get_digests_case23(void **state)
    1407              : {
    1408              :     libspdm_return_t status;
    1409              :     libspdm_test_context_t *spdm_test_context;
    1410              :     libspdm_context_t *spdm_context;
    1411              :     uint8_t slot_mask;
    1412              :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1413              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1414              :     size_t arbitrary_size;
    1415              : #endif
    1416              : 
    1417            1 :     spdm_test_context = *state;
    1418            1 :     spdm_context = spdm_test_context->spdm_context;
    1419            1 :     spdm_test_context->case_id = 0x17;
    1420            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1421              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1422            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1423            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1424            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1425            1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
    1426              :                     sizeof(m_libspdm_local_certificate_chain),
    1427              :                     (uint8_t)(0xFF));
    1428            1 :     libspdm_reset_message_b(spdm_context);
    1429              : 
    1430            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1431            1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
    1432            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1433              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1434              :     arbitrary_size = 8;
    1435              :     assert_int_equal(spdm_context->transcript.message_b.buffer_size,
    1436              :                      arbitrary_size + m_libspdm_local_buffer_size);
    1437              :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
    1438              :                    m_libspdm_local_buffer_size));
    1439              :     libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1440              :     assert_memory_equal(spdm_context->transcript.message_b.buffer + arbitrary_size,
    1441              :                         m_libspdm_local_buffer, m_libspdm_local_buffer_size);
    1442              : #endif
    1443            1 : }
    1444              : 
    1445              : /**
    1446              :  * Test 24: Test case for GetDigest, GetCert and GetDigest
    1447              :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a second GetDigest can be sent.
    1448              :  **/
    1449            1 : static void req_get_digests_case24(void **state)
    1450              : {
    1451              :     libspdm_return_t status;
    1452              :     libspdm_test_context_t *spdm_test_context;
    1453              :     libspdm_context_t *spdm_context;
    1454              :     libspdm_data_parameter_t parameter;
    1455              :     uint8_t slot_mask;
    1456              :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1457              :     uint8_t my_total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1458              :     uint8_t *digest;
    1459              :     size_t data_return_size;
    1460              :     void *data;
    1461              :     size_t data_size;
    1462              :     void *hash;
    1463              :     size_t hash_size;
    1464              :     const uint8_t *root_cert;
    1465              :     size_t root_cert_size;
    1466              :     size_t cert_chain_size;
    1467              :     uint8_t cert_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
    1468              : 
    1469            1 :     spdm_test_context = *state;
    1470            1 :     spdm_context = spdm_test_context->spdm_context;
    1471            1 :     spdm_test_context->case_id = 0x18;
    1472            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1473              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1474            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1475            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1476            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1477            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1478            1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
    1479            1 :     spdm_context->local_context.is_requester = true;
    1480              : 
    1481            1 :     if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1482              :                                                          m_libspdm_use_asym_algo, &data,
    1483              :                                                          &data_size, &hash, &hash_size)) {
    1484            0 :         assert(false);
    1485              :     }
    1486            1 :     libspdm_x509_get_cert_from_cert_chain(
    1487            1 :         (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
    1488            1 :         data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
    1489              :         &root_cert, &root_cert_size);
    1490            1 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "root cert data :\n"));
    1491            1 :     libspdm_dump_hex(root_cert, root_cert_size);
    1492            1 :     spdm_context->local_context.peer_root_cert_provision_size[0] = root_cert_size;
    1493            1 :     spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
    1494              : 
    1495            1 :     m_get_digest = true;
    1496              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1497              :     spdm_context->transcript.message_m.buffer_size =
    1498              :         spdm_context->transcript.message_m.max_buffer_size;
    1499              : #endif
    1500            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1501              :     /* first GetDigest */
    1502            1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
    1503            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1504            1 :     assert_int_equal(slot_mask, 0x01);
    1505            1 :     libspdm_zero_mem(my_total_digest_buffer, sizeof(my_total_digest_buffer));
    1506            1 :     digest = my_total_digest_buffer;
    1507            1 :     if (m_libspdm_local_certificate_chain_test_cert == NULL) {
    1508            0 :         libspdm_read_responder_public_certificate_chain(
    1509              :             m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
    1510              :             &m_libspdm_local_certificate_chain_test_cert,
    1511              :             &m_libspdm_local_certificate_chain_size, NULL, NULL);
    1512              :     }
    1513            1 :     libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain_test_cert,
    1514              :                      m_libspdm_local_certificate_chain_size, digest);
    1515            1 :     assert_memory_equal(total_digest_buffer, my_total_digest_buffer,
    1516              :                         sizeof(my_total_digest_buffer));
    1517              : 
    1518            1 :     parameter.location = LIBSPDM_DATA_LOCATION_CONNECTION;
    1519            1 :     data_return_size = sizeof(uint8_t);
    1520            1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_PEER_SLOT_MASK,
    1521              :                               &parameter, &slot_mask, &data_return_size);
    1522            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1523            1 :     assert_int_equal(data_return_size, sizeof(uint8_t));
    1524            1 :     assert_int_equal(slot_mask, 0x01);
    1525              : 
    1526              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1527              :     assert_int_equal(
    1528              :         spdm_context->transcript.message_b.buffer_size,
    1529              :         sizeof(spdm_get_digest_request_t) +
    1530              :         sizeof(spdm_digest_response_t) +
    1531              :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo));
    1532              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    1533              : #endif
    1534              : 
    1535            1 :     m_get_digest = false;
    1536              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1537              :     spdm_context->transcript.message_m.buffer_size =
    1538              :         spdm_context->transcript.message_m.max_buffer_size;
    1539              : #endif
    1540            1 :     cert_chain_size = sizeof(cert_chain);
    1541            1 :     libspdm_zero_mem(cert_chain, sizeof(cert_chain));
    1542            1 :     status = libspdm_get_certificate(spdm_context, NULL, 0, &cert_chain_size, cert_chain);
    1543            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1544              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1545              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    1546              : #endif
    1547            1 :     free(data);
    1548              : 
    1549            1 :     m_get_digest = true;
    1550              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1551              :     spdm_context->transcript.message_m.buffer_size =
    1552              :         spdm_context->transcript.message_m.max_buffer_size;
    1553              : #endif
    1554            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1555              :     /* second GetDigest */
    1556            1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
    1557            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1558            1 :     assert_int_equal(slot_mask, 0x01);
    1559            1 :     libspdm_zero_mem(my_total_digest_buffer, sizeof(my_total_digest_buffer));
    1560            1 :     digest = my_total_digest_buffer;
    1561            1 :     libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain_test_cert,
    1562              :                      m_libspdm_local_certificate_chain_size, digest);
    1563            1 :     assert_memory_equal (total_digest_buffer, my_total_digest_buffer,
    1564              :                          sizeof(my_total_digest_buffer));
    1565            1 :     data_return_size = sizeof(uint8_t);
    1566            1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_PEER_SLOT_MASK,
    1567              :                               &parameter, &slot_mask, &data_return_size);
    1568            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1569            1 :     assert_int_equal(data_return_size, sizeof(uint8_t));
    1570            1 :     assert_int_equal(slot_mask, 0x01);
    1571              : 
    1572              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1573              :     assert_int_equal(
    1574              :         spdm_context->transcript.message_b.buffer_size,
    1575              :         sizeof(spdm_get_digest_request_t) +
    1576              :         sizeof(spdm_digest_response_t) +
    1577              :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo));
    1578              :     assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
    1579              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = 0;
    1580              : #else
    1581            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size = 0;
    1582              : #endif
    1583            1 : }
    1584              : 
    1585              : /**
    1586              :  * Test 25: a request message is successfully sent and a response message is successfully received
    1587              :  * in a session.
    1588              :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a DIGESTS message is received
    1589              :  **/
    1590            1 : static void req_get_digests_case25(void **state)
    1591              : {
    1592              :     libspdm_return_t status;
    1593              :     libspdm_test_context_t *spdm_test_context;
    1594              :     libspdm_context_t *spdm_context;
    1595              :     libspdm_data_parameter_t parameter;
    1596              :     uint8_t slot_mask;
    1597              :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1598              :     uint8_t my_total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1599              :     uint8_t *digest;
    1600              :     size_t data_return_size;
    1601              :     uint32_t session_id;
    1602              :     libspdm_session_info_t *session_info;
    1603              : 
    1604            1 :     spdm_test_context = *state;
    1605            1 :     spdm_context = spdm_test_context->spdm_context;
    1606            1 :     spdm_test_context->case_id = 0x19;
    1607            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
    1608              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1609            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1610            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1611            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
    1612            1 :     spdm_context->connection_info.capability.flags |=
    1613              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
    1614            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1615            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
    1616            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
    1617            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1618            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1619            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1620              : 
    1621            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1622              : 
    1623            1 :     session_id = 0xFFFFFFFF;
    1624            1 :     session_info = &spdm_context->session_info[0];
    1625            1 :     libspdm_session_info_init(spdm_context, session_info, session_id,
    1626              :                               SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT, true);
    1627            1 :     libspdm_secured_message_set_session_state(session_info->secured_message_context,
    1628              :                                               LIBSPDM_SESSION_STATE_ESTABLISHED);
    1629              : 
    1630            1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
    1631              :                     sizeof(m_libspdm_local_certificate_chain),
    1632              :                     (uint8_t)(0xFF));
    1633            1 :     libspdm_reset_message_b(spdm_context);
    1634              : 
    1635              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1636              :     session_info->session_transcript.message_m.buffer_size =
    1637              :         session_info->session_transcript.message_m.max_buffer_size;
    1638              : #endif
    1639            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1640            1 :     status = libspdm_get_digest(spdm_context, &session_id, &slot_mask, &total_digest_buffer);
    1641            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1642              : 
    1643            1 :     assert_int_equal(slot_mask, 0x80);
    1644            1 :     libspdm_zero_mem(my_total_digest_buffer, sizeof(my_total_digest_buffer));
    1645            1 :     digest = my_total_digest_buffer;
    1646            1 :     libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
    1647              :                      sizeof(m_libspdm_local_certificate_chain), digest);
    1648            1 :     assert_memory_equal (total_digest_buffer, my_total_digest_buffer,
    1649              :                          sizeof(my_total_digest_buffer));
    1650              : 
    1651            1 :     parameter.location = LIBSPDM_DATA_LOCATION_CONNECTION;
    1652            1 :     data_return_size = sizeof(uint8_t);
    1653            1 :     status = libspdm_get_data(spdm_context, LIBSPDM_DATA_PEER_SLOT_MASK,
    1654              :                               &parameter, &slot_mask, &data_return_size);
    1655            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1656            1 :     assert_int_equal(data_return_size, sizeof(uint8_t));
    1657            1 :     assert_int_equal(slot_mask, 0x80);
    1658              : 
    1659              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1660              :     assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
    1661              : #endif
    1662            1 : }
    1663              : 
    1664              : 
    1665              : /**
    1666              :  * Test 26: a response message is successfully sent ,
    1667              :  * Set multi_key_conn_rsp to check if it responds correctly
    1668              :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS
    1669              :  **/
    1670            1 : static void req_get_digests_case26(void **state)
    1671              : {
    1672              :     libspdm_return_t status;
    1673              :     libspdm_test_context_t *spdm_test_context;
    1674              :     libspdm_context_t *spdm_context;
    1675              :     uint8_t slot_mask;
    1676              :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1677              : 
    1678            1 :     spdm_test_context = *state;
    1679            1 :     spdm_context = spdm_test_context->spdm_context;
    1680            1 :     spdm_test_context->case_id = 0x1A;
    1681            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    1682              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1683            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1684            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1685            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1686            1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
    1687              :                     sizeof(m_libspdm_local_certificate_chain),
    1688              :                     (uint8_t)(0xFF));
    1689            1 :     libspdm_reset_message_b(spdm_context);
    1690              : 
    1691              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1692              :     spdm_context->transcript.message_m.buffer_size =
    1693              :         spdm_context->transcript.message_m.max_buffer_size;
    1694              : #endif
    1695              :     /* Sub Case 1: Set multi_key_conn_rsp to true*/
    1696            1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
    1697            1 :     libspdm_reset_message_d(spdm_context);
    1698              : 
    1699            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1700            1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
    1701            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1702            1 :     assert_int_equal(
    1703              :         spdm_context->transcript.message_d.buffer_size,
    1704              :         sizeof(spdm_digest_response_t) + sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
    1705              :         sizeof(spdm_key_usage_bit_mask_t) +
    1706              :         libspdm_get_hash_size( spdm_context->connection_info.algorithm.base_hash_algo));
    1707              : 
    1708              :     /* Sub Case 2: Set multi_key_conn_rsp to false*/
    1709            1 :     spdm_context->connection_info.multi_key_conn_rsp = false;
    1710            1 :     libspdm_reset_message_d(spdm_context);
    1711              : 
    1712            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1713            1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
    1714            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1715            1 :     assert_int_equal(spdm_context->transcript.message_d.buffer_size,0);
    1716            1 : }
    1717              : 
    1718              : /**
    1719              :  * Test 27: a response message is successfully sent ,
    1720              :  * Set multi_key_conn_rsp to check if it responds correctly
    1721              :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS
    1722              :  **/
    1723            1 : static void req_get_digests_case27(void **state)
    1724              : {
    1725              :     libspdm_return_t status;
    1726              :     libspdm_test_context_t *spdm_test_context;
    1727              :     libspdm_context_t *spdm_context;
    1728              :     uint8_t slot_mask;
    1729              :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1730              :     uint32_t hash_size;
    1731              :     uint8_t slot_count;
    1732              :     size_t additional_size;
    1733              : 
    1734            1 :     spdm_test_context = *state;
    1735            1 :     spdm_context = spdm_test_context->spdm_context;
    1736            1 :     spdm_test_context->case_id = 0x1B;
    1737            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    1738              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1739            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1740            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1741            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1742            1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
    1743              :                     sizeof(m_libspdm_local_certificate_chain),
    1744              :                     (uint8_t)(0xFF));
    1745            1 :     libspdm_reset_message_b(spdm_context);
    1746              : 
    1747              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1748              :     spdm_context->transcript.message_m.buffer_size =
    1749              :         spdm_context->transcript.message_m.max_buffer_size;
    1750              : #endif
    1751            1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
    1752            1 :     libspdm_reset_message_d(spdm_context);
    1753              : 
    1754            1 :     m_local_key_pair_id[0] = 0x00;
    1755            1 :     m_local_cert_info[0] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
    1756            1 :     m_local_key_usage_bit_mask[0] = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
    1757              : 
    1758            1 :     m_local_key_pair_id[1] = 0x01;
    1759            1 :     m_local_cert_info[1] = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT;
    1760            1 :     m_local_key_usage_bit_mask[1] = SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
    1761              : 
    1762            1 :     m_local_key_pair_id[2] = 0x02;
    1763            1 :     m_local_cert_info[2] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
    1764            1 :     m_local_key_usage_bit_mask[2] = SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE;
    1765              : 
    1766            1 :     m_local_key_pair_id[3] = 0x03;
    1767            1 :     m_local_cert_info[3] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
    1768            1 :     m_local_key_usage_bit_mask[3] = SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
    1769              : 
    1770            1 :     m_local_key_pair_id[4] = 0x04;
    1771            1 :     m_local_cert_info[4] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
    1772            1 :     m_local_key_usage_bit_mask[4] = SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE;
    1773              : 
    1774            1 :     m_local_key_pair_id[5] = 0x05;
    1775            1 :     m_local_cert_info[5] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
    1776            1 :     m_local_key_usage_bit_mask[5] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
    1777              : 
    1778            1 :     m_local_key_pair_id[6] = 0x06;
    1779            1 :     m_local_cert_info[6] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
    1780            1 :     m_local_key_usage_bit_mask[6] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
    1781              : 
    1782            1 :     m_local_key_pair_id[7] = 0x07;
    1783            1 :     m_local_cert_info[7] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
    1784            1 :     m_local_key_usage_bit_mask[7] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
    1785              : 
    1786            1 :     slot_count = SPDM_MAX_SLOT_COUNT;
    1787            1 :     additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
    1788              :                       sizeof(spdm_key_usage_bit_mask_t);
    1789            1 :     hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
    1790              : 
    1791            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1792            1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
    1793            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1794            1 :     assert_int_equal(
    1795              :         spdm_context->transcript.message_d.buffer_size,
    1796              :         sizeof(spdm_digest_response_t) + (additional_size + hash_size) * slot_count);
    1797              : 
    1798            9 :     for (uint8_t index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
    1799            8 :         assert_memory_equal((void *)&m_local_key_pair_id[index],
    1800              :                             (void *)&spdm_context->connection_info.peer_key_pair_id[index],
    1801              :                             sizeof(spdm_key_pair_id_t));
    1802            8 :         assert_memory_equal((void *)&m_local_cert_info[index],
    1803              :                             (void *)&spdm_context->connection_info.peer_cert_info[index],
    1804              :                             sizeof(spdm_key_pair_id_t));
    1805            8 :         assert_memory_equal((void *)&m_local_key_usage_bit_mask[index],
    1806              :                             (void *)&spdm_context->connection_info.peer_key_usage_bit_mask[index],
    1807              :                             sizeof(spdm_key_pair_id_t));
    1808              :     }
    1809            1 : }
    1810              : 
    1811              : /**
    1812              :  * Test 28:
    1813              :  * 1.For slot 0, at least one of KeyExUse , ChallengeUse , MeasurementUse , and EndpointInfoUse shall be set. The
    1814              :  *   corresponding capability bits shall be set appropriately
    1815              :  * 2.In all cases, the certificate model for slot 0 shall be either the device certificate model or the alias certificate model.
    1816              :  * Set KeyUsageMask to 0 and Set CertificateInfo to SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT(GenericCert model)
    1817              :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_INVALID_MSG_FIELD
    1818              :  **/
    1819            1 : static void req_get_digests_case28(void **state)
    1820              : {
    1821              :     libspdm_return_t status;
    1822              :     libspdm_test_context_t *spdm_test_context;
    1823              :     libspdm_context_t *spdm_context;
    1824              :     uint8_t slot_mask;
    1825              :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1826              : 
    1827            1 :     spdm_test_context = *state;
    1828            1 :     spdm_context = spdm_test_context->spdm_context;
    1829            1 :     spdm_test_context->case_id = 0x1C;
    1830            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    1831              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1832            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1833            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1834            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1835            1 :     libspdm_set_mem(m_libspdm_local_certificate_chain,
    1836              :                     sizeof(m_libspdm_local_certificate_chain),
    1837              :                     (uint8_t)(0xFF));
    1838            1 :     libspdm_reset_message_b(spdm_context);
    1839              : 
    1840              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1841              :     spdm_context->transcript.message_m.buffer_size =
    1842              :         spdm_context->transcript.message_m.max_buffer_size;
    1843              : #endif
    1844              : 
    1845            1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
    1846            1 :     libspdm_reset_message_d(spdm_context);
    1847              : 
    1848              :     /* Sub Case 1: Set KeyUsageMask to 0*/
    1849            1 :     m_local_key_pair_id[0] = 0x00;
    1850            1 :     m_local_cert_info[0] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
    1851            1 :     m_local_key_usage_bit_mask[0] = 0;
    1852              : 
    1853            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1854            1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
    1855            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1856              : 
    1857              :     /* Sub Case 2: Set CertificateInfo to SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT*/
    1858            1 :     m_local_key_pair_id[0] = 0x00;
    1859            1 :     m_local_cert_info[0] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
    1860            1 :     m_local_key_usage_bit_mask[0] = SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
    1861              : 
    1862            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1863            1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
    1864            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1865            1 : }
    1866              : 
    1867              : /**
    1868              :  * Test 29:
    1869              :  * Digest: If a certificate chain is not present in this slot, the value of this field shall be all zeros.
    1870              :  * CertModel: Value of 0 indicates either that the certificate slot does not contain any certificates or that the corresponding
    1871              :  * MULTI_KEY_CONN_REQ or MULTI_KEY_CONN_RSP is false.
    1872              :  * Expected Behavior: requester returns the status LIBSPDM_STATUS_INVALID_MSG_FIELD
    1873              :  **/
    1874            1 : static void req_get_digests_case29(void **state)
    1875              : {
    1876              :     libspdm_return_t status;
    1877              :     libspdm_test_context_t *spdm_test_context;
    1878              :     libspdm_context_t *spdm_context;
    1879              :     uint8_t slot_mask;
    1880              :     uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
    1881              : 
    1882            1 :     spdm_test_context = *state;
    1883            1 :     spdm_context = spdm_test_context->spdm_context;
    1884            1 :     spdm_test_context->case_id = 0x1D;
    1885            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    1886              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1887            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1888            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1889            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1890            1 :     libspdm_zero_mem(m_libspdm_local_certificate_chain, sizeof(m_libspdm_local_certificate_chain));
    1891            1 :     libspdm_reset_message_b(spdm_context);
    1892              : 
    1893              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1894              :     spdm_context->transcript.message_m.buffer_size =
    1895              :         spdm_context->transcript.message_m.max_buffer_size;
    1896              : #endif
    1897              : 
    1898            1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
    1899            1 :     libspdm_reset_message_d(spdm_context);
    1900              : 
    1901            1 :     m_local_key_pair_id[0] = 0x00;
    1902            1 :     m_local_cert_info[0] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
    1903            1 :     m_local_key_usage_bit_mask[0] = SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
    1904              : 
    1905              :     /* CertModel:Value of 0 indicates either that the certificate slot does not contain any certificates or that the corresponding
    1906              :      * MULTI_KEY_CONN_REQ or MULTI_KEY_CONN_RSP is false. */
    1907            1 :     m_local_key_pair_id[1] = 0x01;
    1908            1 :     m_local_cert_info[1] = SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE;
    1909            1 :     m_local_key_usage_bit_mask[1] = SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
    1910              : 
    1911            1 :     libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
    1912            1 :     status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
    1913            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
    1914            1 : }
    1915              : 
    1916            1 : int libspdm_req_get_digests_test(void)
    1917              : {
    1918            1 :     const struct CMUnitTest test_cases[] = {
    1919              :         cmocka_unit_test(req_get_digests_case1),
    1920              :         cmocka_unit_test(req_get_digests_case2),
    1921              :         cmocka_unit_test(req_get_digests_case3),
    1922              :         cmocka_unit_test(req_get_digests_case4),
    1923              :         cmocka_unit_test(req_get_digests_case5),
    1924              :         cmocka_unit_test(req_get_digests_case6),
    1925              :         cmocka_unit_test(req_get_digests_case7),
    1926              :         cmocka_unit_test(req_get_digests_case8),
    1927              :         cmocka_unit_test(req_get_digests_case9),
    1928              :         cmocka_unit_test(req_get_digests_case10),
    1929              :         cmocka_unit_test(req_get_digests_case11),
    1930              :         cmocka_unit_test(req_get_digests_case12),
    1931              :         cmocka_unit_test(req_get_digests_case13),
    1932              :         cmocka_unit_test(req_get_digests_case14),
    1933              :         cmocka_unit_test(req_get_digests_case15),
    1934              :         cmocka_unit_test(req_get_digests_case16),
    1935              :         cmocka_unit_test(req_get_digests_case17),
    1936              :         cmocka_unit_test(req_get_digests_case18),
    1937              :         cmocka_unit_test(req_get_digests_case19),
    1938              :         cmocka_unit_test(req_get_digests_case20),
    1939              :         cmocka_unit_test(req_get_digests_case21),
    1940              :         cmocka_unit_test(req_get_digests_case22),
    1941              :         cmocka_unit_test(req_get_digests_case23),
    1942              :         cmocka_unit_test(req_get_digests_case24),
    1943              :         cmocka_unit_test(req_get_digests_case25),
    1944              :         cmocka_unit_test(req_get_digests_case26),
    1945              :         cmocka_unit_test(req_get_digests_case27),
    1946              :         cmocka_unit_test(req_get_digests_case28),
    1947              :         cmocka_unit_test(req_get_digests_case29),
    1948              :     };
    1949              : 
    1950            1 :     libspdm_test_context_t test_context = {
    1951              :         LIBSPDM_TEST_CONTEXT_VERSION,
    1952              :         true,
    1953              :         send_message,
    1954              :         receive_message,
    1955              :     };
    1956              : 
    1957            1 :     libspdm_setup_test_context(&test_context);
    1958              : 
    1959            1 :     return cmocka_run_group_tests(test_cases,
    1960              :                                   libspdm_unit_test_group_setup,
    1961              :                                   libspdm_unit_test_group_teardown);
    1962              : }
    1963              : 
    1964              : #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
        

Generated by: LCOV version 2.0-1