LCOV - code coverage report
Current view: top level - spdm_common_lib - libspdm_com_context_data.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 49.9 % 1676 836
Test Date: 2026-10-01 20:56:25 Functions: 88.6 % 79 70
Branches: 40.2 % 894 359

             Branch data     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 "internal/libspdm_common_lib.h"
       8                 :             : #include "internal/libspdm_secured_message_lib.h"
       9                 :             : #include "internal/libspdm_fips_lib.h"
      10                 :             : 
      11                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
      12                 :             : /* first section */
      13                 :       68546 : uint32_t libspdm_get_scratch_buffer_secure_message_offset(void) {
      14                 :       68546 :     return 0;
      15                 :             : }
      16                 :             : 
      17                 :      425214 : uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context) {
      18                 :      425214 :     return spdm_context->local_context.capability.max_spdm_msg_size +
      19                 :      850428 :            spdm_context->local_context.capability.transport_header_size +
      20                 :      425214 :            spdm_context->local_context.capability.transport_tail_size;
      21                 :             : }
      22                 :             : 
      23                 :             : /* second section */
      24                 :          65 : uint32_t libspdm_get_scratch_buffer_large_message_offset(libspdm_context_t *spdm_context) {
      25                 :          65 :     return libspdm_get_scratch_buffer_secure_message_capacity(spdm_context);
      26                 :             : }
      27                 :             : 
      28                 :      356638 : uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context) {
      29                 :      356638 :     return spdm_context->local_context.capability.max_spdm_msg_size;
      30                 :             : }
      31                 :             : #endif
      32                 :             : 
      33                 :             : /* third section */
      34                 :      202885 : uint32_t libspdm_get_scratch_buffer_sender_receiver_offset(libspdm_context_t *spdm_context) {
      35                 :      202885 :     return 0 +
      36                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
      37                 :             :            libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
      38                 :      202885 :            libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
      39                 :             : #endif
      40                 :             :            0;
      41                 :             : }
      42                 :             : 
      43                 :      287987 : uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context) {
      44                 :      287987 :     return spdm_context->local_context.capability.max_spdm_msg_size +
      45                 :      575974 :            spdm_context->local_context.capability.transport_header_size +
      46                 :      287987 :            spdm_context->local_context.capability.transport_tail_size;
      47                 :             : }
      48                 :             : 
      49                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
      50                 :             : /* fourth section */
      51                 :       14870 : uint32_t libspdm_get_scratch_buffer_large_sender_receiver_offset(libspdm_context_t *spdm_context) {
      52                 :       14870 :     return libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
      53                 :       29740 :            libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
      54                 :       14870 :            libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context);
      55                 :             : }
      56                 :             : 
      57                 :      150742 : uint32_t libspdm_get_scratch_buffer_large_sender_receiver_capacity(libspdm_context_t *spdm_context)
      58                 :             : {
      59                 :      150742 :     return spdm_context->local_context.capability.max_spdm_msg_size +
      60                 :      301484 :            spdm_context->local_context.capability.transport_header_size +
      61                 :      150742 :            spdm_context->local_context.capability.transport_tail_size;
      62                 :             : }
      63                 :             : #endif
      64                 :             : 
      65                 :             : /* fifth section */
      66                 :         313 : uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context) {
      67                 :         313 :     return 0 +
      68                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
      69                 :         313 :            libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
      70                 :         313 :            libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
      71                 :             : #endif
      72                 :         313 :            libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
      73                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
      74                 :         313 :            libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
      75                 :             : #endif
      76                 :             :            0;
      77                 :             : }
      78                 :             : 
      79                 :      279191 : uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context) {
      80                 :      279191 :     return spdm_context->local_context.capability.max_spdm_msg_size;
      81                 :             : }
      82                 :             : 
      83                 :             : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
      84                 :             : /* sixth section */
      85                 :         313 : uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context) {
      86                 :         313 :     return 0 +
      87                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
      88                 :         313 :            libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
      89                 :         313 :            libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
      90                 :             : #endif
      91                 :         313 :            libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
      92                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
      93                 :         313 :            libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
      94                 :             : #endif
      95                 :         313 :            libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
      96                 :             :            0;
      97                 :             : }
      98                 :             : 
      99                 :      275838 : uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context) {
     100                 :      275838 :     return spdm_context->local_context.capability.max_spdm_msg_size;
     101                 :             : }
     102                 :             : #endif
     103                 :             : 
     104                 :             : /* combination */
     105                 :      138216 : uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context) {
     106                 :      138216 :     return 0 +
     107                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
     108                 :      138216 :            libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
     109                 :      138216 :            libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
     110                 :             : #endif
     111                 :      138216 :            libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
     112                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
     113                 :      138216 :            libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
     114                 :             : #endif
     115                 :      138216 :            libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
     116                 :             : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
     117                 :      138216 :            libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context) +
     118                 :             : #endif
     119                 :             :            0;
     120                 :             : }
     121                 :             : 
     122                 :             : /**
     123                 :             :  * Returns if an SPDM data_type requires session info.
     124                 :             :  *
     125                 :             :  * @param data_type  SPDM data type.
     126                 :             :  *
     127                 :             :  * @retval true  session info is required.
     128                 :             :  * @retval false session info is not required.
     129                 :             :  **/
     130                 :         216 : static bool need_session_info_for_data(libspdm_data_type_t data_type)
     131                 :             : {
     132         [ +  + ]:         216 :     switch (data_type) {
     133                 :          10 :     case LIBSPDM_DATA_SESSION_SECURED_MESSAGE_VERSION:
     134                 :             :     case LIBSPDM_DATA_SESSION_USE_PSK:
     135                 :             :     case LIBSPDM_DATA_SESSION_MUT_AUTH_REQUESTED:
     136                 :             :     case LIBSPDM_DATA_SESSION_END_SESSION_ATTRIBUTES:
     137                 :             :     case LIBSPDM_DATA_SESSION_POLICY:
     138                 :             :     case LIBSPDM_DATA_SESSION_SEQUENCE_NUMBER_RSP_DIR:
     139                 :             :     case LIBSPDM_DATA_SESSION_SEQUENCE_NUMBER_REQ_DIR:
     140                 :             :     case LIBSPDM_DATA_SESSION_SEQUENCE_NUMBER_ENDIAN:
     141                 :             : #if (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP)
     142                 :             :     case LIBSPDM_DATA_SESSION_ENCAP_REQ_SLOT_ID:
     143                 :             : #endif
     144                 :          10 :         return true;
     145                 :         206 :     default:
     146                 :         206 :         return false;
     147                 :             :     }
     148                 :             : }
     149                 :             : 
     150                 :         195 : libspdm_return_t libspdm_set_data(void *spdm_context, libspdm_data_type_t data_type,
     151                 :             :                                   const libspdm_data_parameter_t *parameter, const void *data,
     152                 :             :                                   size_t data_size)
     153                 :             : {
     154                 :             :     libspdm_context_t *context;
     155                 :             :     uint32_t session_id;
     156                 :             :     uint32_t data32;
     157                 :             :     libspdm_session_info_t *session_info;
     158                 :             :     uint8_t slot_id;
     159                 :             :     uint8_t root_cert_index;
     160                 :             :     uint16_t data16;
     161                 :             : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) && LIBSPDM_CERT_PARSE_SUPPORT
     162                 :             :     bool status;
     163                 :             :     uint32_t peer_base_asym_algo;
     164                 :             :     uint32_t peer_pqc_asym_algo;
     165                 :             : #endif
     166                 :             : 
     167   [ +  -  -  + ]:         195 :     if (spdm_context == NULL || data_type >= LIBSPDM_DATA_MAX) {
     168                 :           0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
     169                 :             :     }
     170                 :             : 
     171                 :         195 :     context = spdm_context;
     172                 :             : 
     173         [ +  + ]:         195 :     if (need_session_info_for_data(data_type)) {
     174         [ +  + ]:          10 :         if (parameter->location != LIBSPDM_DATA_LOCATION_SESSION) {
     175                 :           1 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     176                 :             :         }
     177                 :           9 :         session_id = libspdm_read_uint32(parameter->additional_data);
     178                 :           9 :         session_info = libspdm_get_session_info_via_session_id(context, session_id);
     179         [ +  + ]:           9 :         if (session_info == NULL) {
     180                 :           1 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     181                 :             :         }
     182                 :             :     } else {
     183                 :         185 :         session_info = NULL;
     184                 :             :     }
     185                 :             : 
     186   [ -  -  -  -  :         193 :     switch (data_type) {
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  +  
          +  -  -  -  -  
          +  -  -  -  +  
          -  -  +  -  -  
          +  +  +  +  -  
             -  -  +  - ]
     187                 :           0 :     case LIBSPDM_DATA_SPDM_VERSION:
     188         [ #  # ]:           0 :         LIBSPDM_ASSERT (data_size <= sizeof(spdm_version_number_t) * SPDM_MAX_VERSION_COUNT);
     189         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     190                 :             :             /* Only have one connected version */
     191         [ #  # ]:           0 :             LIBSPDM_ASSERT (data_size == sizeof(spdm_version_number_t));
     192                 :           0 :             libspdm_copy_mem(&(context->connection_info.version),
     193                 :             :                              sizeof(context->connection_info.version),
     194                 :             :                              data,
     195                 :             :                              sizeof(spdm_version_number_t));
     196         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     197                 :           0 :             context->local_context.version.spdm_version_count =
     198                 :           0 :                 (uint8_t)(data_size / sizeof(spdm_version_number_t));
     199                 :           0 :             libspdm_copy_mem(context->local_context.version.spdm_version,
     200                 :             :                              sizeof(context->local_context.version.spdm_version),
     201                 :             :                              data,
     202                 :           0 :                              context->local_context.version.spdm_version_count *
     203                 :             :                              sizeof(spdm_version_number_t));
     204                 :             :         } else {
     205                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     206                 :             :         }
     207                 :           0 :         break;
     208                 :           0 :     case LIBSPDM_DATA_SECURED_MESSAGE_VERSION:
     209         [ #  # ]:           0 :         LIBSPDM_ASSERT (data_size <=
     210                 :             :                         sizeof(spdm_version_number_t) * SECURED_SPDM_MAX_VERSION_COUNT);
     211         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     212                 :           0 :             context->local_context.secured_message_version.secured_message_version_count =
     213                 :           0 :                 (uint8_t)(data_size / sizeof(spdm_version_number_t));
     214                 :           0 :             libspdm_copy_mem(context->local_context.secured_message_version.secured_message_version,
     215                 :             :                              sizeof(context->local_context.secured_message_version.secured_message_version),
     216                 :             :                              data,
     217                 :           0 :                              context->local_context.secured_message_version.
     218                 :             :                              secured_message_version_count * sizeof(spdm_version_number_t));
     219                 :             :         } else {
     220                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     221                 :             :         }
     222                 :           0 :         break;
     223                 :           0 :     case LIBSPDM_DATA_CAPABILITY_FLAGS:
     224         [ #  # ]:           0 :         if (data_size != sizeof(uint32_t)) {
     225                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     226                 :             :         }
     227                 :             : 
     228                 :           0 :         data32 = libspdm_read_uint32((const uint8_t *)data);
     229                 :             : 
     230         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     231                 :             :             #if !(LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
     232                 :             :             LIBSPDM_ASSERT((data32 & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP) == 0);
     233                 :             :             #endif /* !LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
     234                 :             : 
     235                 :             :             #if !(LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP)
     236                 :             :             LIBSPDM_ASSERT((data32 & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP) == 0);
     237                 :             :             #endif /* !LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP */
     238                 :             : 
     239                 :             :             #if !(LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP)
     240                 :             :             LIBSPDM_ASSERT((data32 & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP) == 0);
     241                 :             :             #endif /* !LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
     242                 :             : 
     243                 :             :             #if !(LIBSPDM_ENABLE_CAPABILITY_MEL_CAP)
     244                 :             :             LIBSPDM_ASSERT((data32 & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP) == 0);
     245                 :             :             #endif /* !LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */
     246                 :             : 
     247                 :             :             #if !(LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP)
     248                 :             :             LIBSPDM_ASSERT((data32 & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP) == 0);
     249                 :             :             #endif /* !LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP */
     250                 :             : 
     251                 :             :             #if !(LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
     252                 :             :             LIBSPDM_ASSERT((data32 & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP) == 0);
     253                 :             :             #endif /* !LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
     254                 :             : 
     255                 :             :             #if !(LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP)
     256                 :             :             LIBSPDM_ASSERT((data32 & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP) == 0);
     257                 :             :             #endif /* !LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP */
     258                 :             : 
     259                 :           0 :             context->local_context.capability.flags = data32;
     260         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     261                 :           0 :             context->connection_info.capability.flags = data32;
     262                 :             :         } else {
     263                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     264                 :             :         }
     265                 :           0 :         break;
     266                 :           0 :     case LIBSPDM_DATA_CAPABILITY_EXT_FLAGS:
     267         [ #  # ]:           0 :         if (data_size != sizeof(uint16_t)) {
     268                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     269                 :             :         }
     270                 :             : 
     271                 :           0 :         data16 = libspdm_read_uint16((const uint8_t *)data);
     272                 :             : 
     273         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     274                 :           0 :             context->local_context.capability.ext_flags = data16;
     275         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     276                 :           0 :             context->connection_info.capability.ext_flags = data16;
     277                 :             :         } else {
     278                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     279                 :             :         }
     280                 :           0 :         break;
     281                 :           0 :     case LIBSPDM_DATA_CAPABILITY_CT_EXPONENT:
     282         [ #  # ]:           0 :         if (data_size != sizeof(uint8_t)) {
     283                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     284                 :             :         }
     285         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     286                 :           0 :             context->connection_info.capability.ct_exponent = *(const uint8_t *)data;
     287         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     288                 :           0 :             context->local_context.capability.ct_exponent = *(const uint8_t *)data;
     289                 :             :         } else {
     290                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     291                 :             :         }
     292                 :           0 :         break;
     293                 :           0 :     case LIBSPDM_DATA_CAPABILITY_RTT_US:
     294         [ #  # ]:           0 :         if (data_size != sizeof(uint64_t)) {
     295                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     296                 :             :         }
     297         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     298                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     299                 :             :         }
     300                 :           0 :         context->local_context.capability.rtt = libspdm_read_uint64((const uint8_t *)data);
     301                 :           0 :         break;
     302                 :           0 :     case LIBSPDM_DATA_CAPABILITY_MAX_SPDM_MSG_SIZE:
     303         [ #  # ]:           0 :         if (data_size != sizeof(uint32_t)) {
     304                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     305                 :             :         }
     306                 :             :         /* The local max_spdm_msg_size is set by libspdm_register_transport_layer_func.
     307                 :             :          * Only the connection's max_spdm_msg_size is settable here. */
     308         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     309                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     310                 :             :         }
     311                 :           0 :         data32 = libspdm_read_uint32((const uint8_t *)data);
     312         [ #  # ]:           0 :         LIBSPDM_ASSERT (data32 >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
     313                 :           0 :         context->connection_info.capability.max_spdm_msg_size = data32;
     314                 :           0 :         break;
     315                 :           0 :     case LIBSPDM_DATA_MEASUREMENT_SPEC:
     316         [ #  # ]:           0 :         if (data_size != sizeof(uint8_t)) {
     317                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     318                 :             :         }
     319         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     320                 :           0 :             context->connection_info.algorithm.measurement_spec = *(const uint8_t *)data;
     321         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     322                 :           0 :             context->local_context.algorithm.measurement_spec = *(const uint8_t *)data;
     323                 :             :         } else {
     324                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     325                 :             :         }
     326                 :           0 :         break;
     327                 :           0 :     case LIBSPDM_DATA_MEASUREMENT_HASH_ALGO:
     328         [ #  # ]:           0 :         if (data_size != sizeof(uint32_t)) {
     329                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     330                 :             :         }
     331                 :           0 :         data32 = libspdm_read_uint32((const uint8_t *)data);
     332         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     333                 :           0 :             context->connection_info.algorithm.measurement_hash_algo = data32;
     334         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     335                 :           0 :             context->local_context.algorithm.measurement_hash_algo = data32;
     336                 :             :         } else {
     337                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     338                 :             :         }
     339                 :           0 :         break;
     340                 :           0 :     case LIBSPDM_DATA_BASE_ASYM_ALGO:
     341         [ #  # ]:           0 :         if (data_size != sizeof(uint32_t)) {
     342                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     343                 :             :         }
     344                 :           0 :         data32 = libspdm_read_uint32((const uint8_t *)data);
     345         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     346                 :           0 :             context->connection_info.algorithm.base_asym_algo = data32;
     347         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     348                 :           0 :             context->local_context.algorithm.base_asym_algo = data32;
     349                 :             :         } else {
     350                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     351                 :             :         }
     352                 :           0 :         break;
     353                 :           0 :     case LIBSPDM_DATA_BASE_HASH_ALGO:
     354         [ #  # ]:           0 :         if (data_size != sizeof(uint32_t)) {
     355                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     356                 :             :         }
     357                 :           0 :         data32 = libspdm_read_uint32((const uint8_t *)data);
     358         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     359                 :           0 :             context->connection_info.algorithm.base_hash_algo = data32;
     360         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     361                 :           0 :             context->local_context.algorithm.base_hash_algo = data32;
     362                 :             :         } else {
     363                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     364                 :             :         }
     365                 :           0 :         break;
     366                 :           0 :     case LIBSPDM_DATA_DHE_NAME_GROUP:
     367         [ #  # ]:           0 :         if (data_size != sizeof(uint16_t)) {
     368                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     369                 :             :         }
     370                 :           0 :         data16 = libspdm_read_uint16((const uint8_t *)data);
     371         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     372                 :           0 :             context->connection_info.algorithm.dhe_named_group = data16;
     373         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     374                 :           0 :             context->local_context.algorithm.dhe_named_group = data16;
     375                 :             :         } else {
     376                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     377                 :             :         }
     378                 :           0 :         break;
     379                 :           0 :     case LIBSPDM_DATA_AEAD_CIPHER_SUITE:
     380         [ #  # ]:           0 :         if (data_size != sizeof(uint16_t)) {
     381                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     382                 :             :         }
     383                 :           0 :         data16 = libspdm_read_uint16((const uint8_t *)data);
     384         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     385                 :           0 :             context->connection_info.algorithm.aead_cipher_suite = data16;
     386         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     387                 :           0 :             context->local_context.algorithm.aead_cipher_suite = data16;
     388                 :             :         } else {
     389                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     390                 :             :         }
     391                 :           0 :         break;
     392                 :           0 :     case LIBSPDM_DATA_REQ_BASE_ASYM_ALG:
     393         [ #  # ]:           0 :         if (data_size != sizeof(uint16_t)) {
     394                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     395                 :             :         }
     396                 :           0 :         data16 = libspdm_read_uint16((const uint8_t *)data);
     397         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     398                 :           0 :             context->connection_info.algorithm.req_base_asym_alg = data16;
     399         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     400                 :           0 :             context->local_context.algorithm.req_base_asym_alg = data16;
     401                 :             :         } else {
     402                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     403                 :             :         }
     404                 :           0 :         break;
     405                 :           0 :     case LIBSPDM_DATA_KEY_SCHEDULE:
     406         [ #  # ]:           0 :         if (data_size != sizeof(uint16_t)) {
     407                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     408                 :             :         }
     409                 :           0 :         data16 = libspdm_read_uint16((const uint8_t *)data);
     410         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     411                 :           0 :             context->connection_info.algorithm.key_schedule = data16;
     412         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     413                 :           0 :             context->local_context.algorithm.key_schedule = data16;
     414                 :             :         } else {
     415                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     416                 :             :         }
     417                 :           0 :         break;
     418                 :           0 :     case LIBSPDM_DATA_OTHER_PARAMS_SUPPORT:
     419         [ #  # ]:           0 :         if (data_size != sizeof(uint8_t)) {
     420                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     421                 :             :         }
     422         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     423                 :           0 :             context->connection_info.algorithm.other_params_support = *(const uint8_t *)data;
     424         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     425                 :           0 :             context->local_context.algorithm.other_params_support = *(const uint8_t *)data;
     426                 :             :         } else {
     427                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     428                 :             :         }
     429                 :           0 :         break;
     430                 :           0 :     case LIBSPDM_DATA_MEL_SPEC:
     431         [ #  # ]:           0 :         if (data_size != sizeof(uint8_t)) {
     432                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     433                 :             :         }
     434         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     435                 :           0 :             context->connection_info.algorithm.mel_spec = *(const uint8_t *)data;
     436         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     437                 :           0 :             context->local_context.algorithm.mel_spec = *(const uint8_t *)data;
     438                 :             :         } else {
     439                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     440                 :             :         }
     441                 :           0 :         break;
     442                 :           0 :     case LIBSPDM_DATA_PQC_ASYM_ALGO:
     443         [ #  # ]:           0 :         if (data_size != sizeof(uint32_t)) {
     444                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     445                 :             :         }
     446                 :           0 :         data32 = libspdm_read_uint32((const uint8_t *)data);
     447         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     448                 :           0 :             context->connection_info.algorithm.pqc_asym_algo = data32;
     449         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     450                 :           0 :             context->local_context.algorithm.pqc_asym_algo = data32;
     451                 :             :         } else {
     452                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     453                 :             :         }
     454                 :           0 :         break;
     455                 :           0 :     case LIBSPDM_DATA_REQ_PQC_ASYM_ALG:
     456         [ #  # ]:           0 :         if (data_size != sizeof(uint32_t)) {
     457                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     458                 :             :         }
     459                 :           0 :         data32 = libspdm_read_uint32((const uint8_t *)data);
     460         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     461                 :           0 :             context->connection_info.algorithm.req_pqc_asym_alg = data32;
     462         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     463                 :           0 :             context->local_context.algorithm.req_pqc_asym_alg = data32;
     464                 :             :         } else {
     465                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     466                 :             :         }
     467                 :           0 :         break;
     468                 :           0 :     case LIBSPDM_DATA_KEM_ALG:
     469         [ #  # ]:           0 :         if (data_size != sizeof(uint32_t)) {
     470                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     471                 :             :         }
     472                 :           0 :         data32 = libspdm_read_uint32((const uint8_t *)data);
     473         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     474                 :           0 :             context->connection_info.algorithm.kem_alg = data32;
     475         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     476                 :           0 :             context->local_context.algorithm.kem_alg = data32;
     477                 :             :         } else {
     478                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     479                 :             :         }
     480                 :           0 :         break;
     481                 :           0 :     case LIBSPDM_DATA_ALGO_PRIORITY_PQC_FIRST:
     482         [ #  # ]:           0 :         if (data_size != sizeof(bool)) {
     483                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     484                 :             :         }
     485         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     486                 :           0 :             context->local_context.algorithm.pqc_first = *(const bool *)data;
     487                 :             :         } else {
     488                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     489                 :             :         }
     490                 :           0 :         break;
     491                 :           0 :     case LIBSPDM_DATA_CONNECTION_STATE:
     492         [ #  # ]:           0 :         if (data_size != sizeof(libspdm_connection_state_t)) {
     493                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     494                 :             :         }
     495         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     496                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     497                 :             :         }
     498                 :           0 :         context->connection_info.connection_state = libspdm_read_uint32((const uint8_t *)data);
     499                 :           0 :         break;
     500                 :           0 :     case LIBSPDM_DATA_RESPONSE_STATE:
     501         [ #  # ]:           0 :         if (data_size != sizeof(libspdm_response_state_t)) {
     502                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     503                 :             :         }
     504         [ #  # ]:           0 :         if (libspdm_read_uint32((const uint8_t *)data) >= LIBSPDM_RESPONSE_STATE_MAX) {
     505                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     506                 :             :         }
     507                 :           0 :         context->response_state = libspdm_read_uint32((const uint8_t *)data);
     508                 :           0 :         break;
     509                 :           2 :     case LIBSPDM_DATA_PEER_PUBLIC_ROOT_CERT:
     510         [ -  + ]:           2 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     511                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     512                 :             :         }
     513                 :           2 :         root_cert_index = 0;
     514         [ +  + ]:          11 :         while (context->local_context.peer_root_cert_provision[root_cert_index] != NULL) {
     515                 :          10 :             root_cert_index++;
     516         [ +  + ]:          10 :             if (root_cert_index >= LIBSPDM_MAX_ROOT_CERT_SUPPORT) {
     517                 :           1 :                 return LIBSPDM_STATUS_BUFFER_FULL;
     518                 :             :             }
     519                 :             :         }
     520                 :           1 :         context->local_context.peer_root_cert_provision_size[root_cert_index] = data_size;
     521                 :           1 :         context->local_context.peer_root_cert_provision[root_cert_index] = data;
     522                 :           1 :         break;
     523                 :          11 :     case LIBSPDM_DATA_LOCAL_PUBLIC_CERT_CHAIN:
     524         [ -  + ]:          11 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     525                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     526                 :             :         }
     527                 :          11 :         slot_id = parameter->additional_data[0];
     528         [ -  + ]:          11 :         if (slot_id >= SPDM_MAX_SLOT_COUNT) {
     529                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     530                 :             :         }
     531                 :          11 :         context->local_context.local_cert_chain_provision_size[slot_id] = data_size;
     532                 :          11 :         context->local_context.local_cert_chain_provision[slot_id] = data;
     533                 :          11 :         break;
     534                 :           0 :     case LIBSPDM_DATA_LOCAL_SUPPORTED_SLOT_MASK:
     535         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     536                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     537                 :             :         }
     538         [ #  # ]:           0 :         if (data_size != sizeof(uint8_t)) {
     539                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     540                 :             :         }
     541                 :           0 :         context->local_context.local_supported_slot_mask = *(const uint8_t *)data;
     542                 :           0 :         break;
     543                 :           0 :     case LIBSPDM_DATA_LOCAL_KEY_PAIR_ID:
     544         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     545                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     546                 :             :         }
     547                 :           0 :         slot_id = parameter->additional_data[0];
     548         [ #  # ]:           0 :         if (slot_id >= SPDM_MAX_SLOT_COUNT) {
     549                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     550                 :             :         }
     551         [ #  # ]:           0 :         if (data_size != sizeof(spdm_key_pair_id_t)) {
     552                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     553                 :             :         }
     554                 :           0 :         context->local_context.local_key_pair_id[slot_id] = *(const spdm_key_pair_id_t *)data;
     555                 :           0 :         break;
     556                 :           0 :     case LIBSPDM_DATA_LOCAL_CERT_INFO:
     557         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     558                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     559                 :             :         }
     560                 :           0 :         slot_id = parameter->additional_data[0];
     561         [ #  # ]:           0 :         if (slot_id >= SPDM_MAX_SLOT_COUNT) {
     562                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     563                 :             :         }
     564         [ #  # ]:           0 :         if (data_size != sizeof(spdm_certificate_info_t)) {
     565                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     566                 :             :         }
     567                 :           0 :         context->local_context.local_cert_info[slot_id] = *(const spdm_certificate_info_t *)data;
     568                 :           0 :         break;
     569                 :           0 :     case LIBSPDM_DATA_LOCAL_KEY_USAGE_BIT_MASK:
     570         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     571                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     572                 :             :         }
     573                 :           0 :         slot_id = parameter->additional_data[0];
     574         [ #  # ]:           0 :         if (slot_id >= SPDM_MAX_SLOT_COUNT) {
     575                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     576                 :             :         }
     577         [ #  # ]:           0 :         if (data_size != sizeof(spdm_key_usage_bit_mask_t)) {
     578                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     579                 :             :         }
     580                 :           0 :         context->local_context.local_key_usage_bit_mask[slot_id] =
     581                 :           0 :             libspdm_read_uint16((const uint8_t *)data);
     582                 :           0 :         break;
     583                 :           5 :     case LIBSPDM_DATA_PEER_USED_CERT_CHAIN_BUFFER:
     584         [ -  + ]:           5 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     585                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     586                 :             :         }
     587                 :           5 :         slot_id = parameter->additional_data[0];
     588         [ -  + ]:           5 :         if (slot_id >= SPDM_MAX_SLOT_COUNT) {
     589                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     590                 :             :         }
     591                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     592                 :             :         if (data_size > LIBSPDM_MAX_CERT_CHAIN_SIZE) {
     593                 :             :             return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
     594                 :             :         }
     595                 :             :         context->connection_info.peer_used_cert_chain[slot_id].buffer_size = data_size;
     596                 :             :         libspdm_copy_mem(context->connection_info.peer_used_cert_chain[slot_id].buffer,
     597                 :             :                          sizeof(context->connection_info.peer_used_cert_chain[slot_id].buffer),
     598                 :             :                          data, data_size);
     599                 :             : #else
     600                 :             : #if LIBSPDM_CERT_PARSE_SUPPORT
     601                 :           5 :         status = libspdm_hash_all(
     602                 :             :             context->connection_info.algorithm.base_hash_algo,
     603                 :             :             data, data_size,
     604                 :           5 :             context->connection_info.peer_used_cert_chain[slot_id].buffer_hash);
     605         [ -  + ]:           5 :         if (!status) {
     606                 :           0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
     607                 :             :         }
     608                 :             : 
     609                 :          10 :         context->connection_info.peer_used_cert_chain[slot_id].buffer_hash_size =
     610                 :           5 :             libspdm_get_hash_size(context->connection_info.algorithm.base_hash_algo);
     611                 :             : 
     612                 :           5 :         libspdm_free_peer_leaf_cert_public_key(context, slot_id);
     613         [ +  + ]:           5 :         if (context->local_context.is_requester) {
     614                 :           4 :             peer_base_asym_algo = context->connection_info.algorithm.base_asym_algo;
     615                 :           4 :             peer_pqc_asym_algo = context->connection_info.algorithm.pqc_asym_algo;
     616                 :             :         } else {
     617                 :           1 :             peer_base_asym_algo = context->connection_info.algorithm.req_base_asym_alg;
     618                 :           1 :             peer_pqc_asym_algo = context->connection_info.algorithm.req_pqc_asym_alg;
     619                 :             :         }
     620                 :             : 
     621         [ -  + ]:           5 :         if (peer_pqc_asym_algo != 0) {
     622                 :           0 :             status = libspdm_get_pqc_leaf_cert_public_key_from_cert_chain(
     623                 :             :                 context->connection_info.algorithm.base_hash_algo,
     624                 :             :                 peer_pqc_asym_algo,
     625                 :             :                 (uint8_t *)(size_t)data, data_size,
     626                 :           0 :                 &context->connection_info.peer_used_cert_chain[slot_id].leaf_cert_public_key);
     627                 :             :         } else {
     628                 :           5 :             status = libspdm_get_leaf_cert_public_key_from_cert_chain(
     629                 :             :                 context->connection_info.algorithm.base_hash_algo,
     630                 :             :                 peer_base_asym_algo,
     631                 :             :                 (uint8_t *)(size_t)data, data_size,
     632                 :           5 :                 &context->connection_info.peer_used_cert_chain[slot_id].leaf_cert_public_key);
     633                 :             :         }
     634         [ -  + ]:           5 :         if (!status) {
     635                 :           0 :             return LIBSPDM_STATUS_INVALID_CERT;
     636                 :             :         }
     637                 :             : #else
     638                 :             :         LIBSPDM_ASSERT (false);
     639                 :             : #endif /* LIBSPDM_CERT_PARSE_SUPPORT */
     640                 :             : #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
     641                 :           5 :         break;
     642                 :           0 :     case LIBSPDM_DATA_PEER_PUBLIC_KEY:
     643         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     644                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     645                 :             :         }
     646                 :           0 :         context->local_context.peer_public_key_provision_size = data_size;
     647                 :           0 :         context->local_context.peer_public_key_provision = data;
     648                 :           0 :         break;
     649                 :           0 :     case LIBSPDM_DATA_LOCAL_PUBLIC_KEY:
     650         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     651                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     652                 :             :         }
     653                 :           0 :         context->local_context.local_public_key_provision_size = data_size;
     654                 :           0 :         context->local_context.local_public_key_provision = data;
     655                 :           0 :         break;
     656                 :           0 :     case LIBSPDM_DATA_HEARTBEAT_PERIOD:
     657         [ #  # ]:           0 :         if (data_size != sizeof(uint8_t)) {
     658                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     659                 :             :         }
     660         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     661                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     662                 :             :         }
     663                 :           0 :         context->local_context.heartbeat_period = *(const uint8_t *)data;
     664                 :           0 :         break;
     665                 :           4 :     case LIBSPDM_DATA_APP_CONTEXT_DATA:
     666   [ +  +  +  + ]:           4 :         if (data_size != sizeof(void *) || *(void *const *)data == NULL) {
     667                 :           2 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     668                 :             :         }
     669                 :           2 :         context->app_context_data_ptr = *(void *const *)data;
     670                 :           2 :         break;
     671                 :           0 :     case LIBSPDM_DATA_HANDLE_ERROR_RETURN_POLICY:
     672         [ #  # ]:           0 :         if (data_size != sizeof(uint8_t)) {
     673                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     674                 :             :         }
     675                 :           0 :         context->handle_error_return_policy = *(const uint8_t *)data;
     676                 :           0 :         break;
     677                 :           0 :     case LIBSPDM_DATA_VCA_CACHE:
     678         [ #  # ]:           0 :         if (data_size > sizeof(context->transcript.message_a.buffer)) {
     679                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     680                 :             :         }
     681                 :           0 :         context->transcript.message_a.buffer_size = data_size;
     682                 :           0 :         libspdm_copy_mem(context->transcript.message_a.buffer,
     683                 :             :                          sizeof(context->transcript.message_a.buffer),
     684                 :             :                          data, data_size);
     685                 :           0 :         break;
     686                 :         151 :     case LIBSPDM_DATA_IS_REQUESTER:
     687         [ -  + ]:         151 :         if (data_size != sizeof(bool)) {
     688                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     689                 :             :         }
     690         [ -  + ]:         151 :         if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
     691                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     692                 :             :         }
     693                 :         151 :         context->local_context.is_requester = *(const bool *)data;
     694                 :         151 :         break;
     695                 :           0 :     case LIBSPDM_DATA_REQUEST_RETRY_TIMES:
     696         [ #  # ]:           0 :         if (data_size != sizeof(uint8_t)) {
     697                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     698                 :             :         }
     699                 :           0 :         context->retry_times = *(const uint8_t *)data;
     700                 :           0 :         break;
     701                 :           0 :     case LIBSPDM_DATA_REQUEST_RETRY_DELAY_TIME:
     702         [ #  # ]:           0 :         if (data_size != sizeof(uint64_t)) {
     703                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     704                 :             :         }
     705                 :           0 :         context->retry_delay_time = *(const uint64_t *)data;
     706                 :           0 :         break;
     707                 :           5 :     case LIBSPDM_DATA_MAX_DHE_SESSION_COUNT:
     708         [ -  + ]:           5 :         if (data_size != sizeof(uint32_t)) {
     709                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     710                 :             :         }
     711         [ -  + ]:           5 :         if (*(const uint32_t *)data > LIBSPDM_MAX_SESSION_COUNT - context->max_psk_session_count) {
     712                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     713                 :             :         }
     714                 :           5 :         context->max_dhe_session_count = *(const uint32_t *)data;
     715                 :           5 :         break;
     716                 :           5 :     case LIBSPDM_DATA_MAX_PSK_SESSION_COUNT:
     717         [ -  + ]:           5 :         if (data_size != sizeof(uint32_t)) {
     718                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     719                 :             :         }
     720         [ -  + ]:           5 :         if (*(const uint32_t *)data > LIBSPDM_MAX_SESSION_COUNT - context->max_dhe_session_count) {
     721                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     722                 :             :         }
     723                 :           5 :         context->max_psk_session_count = *(const uint32_t *)data;
     724                 :           5 :         break;
     725                 :           1 :     case LIBSPDM_DATA_MAX_SPDM_SESSION_SEQUENCE_NUMBER:
     726         [ -  + ]:           1 :         if (data_size != sizeof(uint64_t)) {
     727                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     728                 :             :         }
     729                 :             :         /* This is a context-level integrator cap only. A per-session value is not settable: a
     730                 :             :          * session's effective cap is derived once at establishment from min(this cap, negotiated
     731                 :             :          * DSP0277 1.3 AEAD limit) and must not be overridden afterwards. The per-session value is
     732                 :             :          * read-only via get_data(LIBSPDM_DATA_LOCATION_SESSION). */
     733         [ +  - ]:           1 :         if (parameter->location == LIBSPDM_DATA_LOCATION_SESSION) {
     734                 :           1 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     735                 :             :         }
     736                 :           0 :         context->max_spdm_session_sequence_number = *(const uint64_t *)data;
     737         [ #  # ]:           0 :         if (context->max_spdm_session_sequence_number == 0) {
     738                 :           0 :             context->max_spdm_session_sequence_number = LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER;
     739                 :             :         }
     740                 :           0 :         break;
     741                 :           1 :     case LIBSPDM_DATA_SPDM_VERSION_10_11_VERIFY_SIGNATURE_ENDIAN:
     742         [ -  + ]:           1 :         if (data_size != sizeof(uint8_t)) {
     743                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     744                 :             :         }
     745         [ +  - ]:           1 :         if (*(const uint8_t*)data != LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_ONLY &&
     746         [ +  - ]:           1 :             *(const uint8_t*)data != LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_LITTLE_ONLY &&
     747         [ -  + ]:           1 :             *(const uint8_t*)data != LIBSPDM_SPDM_10_11_VERIFY_SIGNATURE_ENDIAN_BIG_OR_LITTLE) {
     748                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     749                 :             :         }
     750                 :           1 :         context->spdm_10_11_verify_signature_endian = *(const uint8_t*)data;
     751                 :           1 :         context->spdm_10_11_verify_signature_endian_setting = *(const uint8_t*)data;
     752                 :           1 :         break;
     753                 :           0 :     case LIBSPDM_DATA_SEQUENCE_NUMBER_ENDIAN:
     754         [ #  # ]:           0 :         if (data_size != sizeof(uint8_t)) {
     755                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     756                 :             :         }
     757                 :           0 :         context->sequence_number_endian = *(const uint8_t *)data;
     758                 :           0 :         break;
     759                 :           0 :     case LIBSPDM_DATA_MULTI_KEY_CONN_REQ:
     760         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     761                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     762                 :             :         }
     763         [ #  # ]:           0 :         if (data_size != sizeof(bool)) {
     764                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     765                 :             :         }
     766                 :           0 :         context->connection_info.multi_key_conn_req = *(const bool *)data;
     767                 :           0 :         break;
     768                 :           0 :     case LIBSPDM_DATA_MULTI_KEY_CONN_RSP:
     769         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     770                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     771                 :             :         }
     772         [ #  # ]:           0 :         if (data_size != sizeof(bool)) {
     773                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     774                 :             :         }
     775                 :           0 :         context->connection_info.multi_key_conn_rsp = *(const bool *)data;
     776                 :           0 :         break;
     777                 :             : #if (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP)
     778                 :           8 :     case LIBSPDM_DATA_SESSION_ENCAP_REQ_SLOT_ID:
     779         [ +  + ]:           8 :         if (data_size != sizeof(uint8_t)) {
     780                 :           1 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     781                 :             :         }
     782         [ +  + ]:           7 :         if (*(const uint8_t *)data >= SPDM_MAX_SLOT_COUNT) {
     783                 :           1 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     784                 :             :         }
     785                 :             :         /* The slot is only meaningful while session-based mutual authentication is in progress. */
     786         [ +  + ]:           6 :         if (session_info->encap_context.flow_type != LIBSPDM_ENCAP_FLOW_SESS_MUT_AUTH) {
     787                 :           2 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
     788                 :             :         }
     789                 :             :         /* The encapsulated context conveys the slot to the Requester in the final
     790                 :             :          * ENCAPSULATED_RESPONSE_ACK, and the session's peer slot is what FINISH verification
     791                 :             :          * reads. The two must agree, as the Requester signs FINISH with the designated slot. */
     792                 :           4 :         session_info->encap_context.mut_auth_req_slot_id = *(const uint8_t *)data;
     793                 :           4 :         session_info->peer_used_cert_chain_slot_id = *(const uint8_t *)data;
     794                 :           4 :         break;
     795                 :             : #endif /* (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) */
     796                 :           0 :     default:
     797                 :           0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
     798                 :             :         break;
     799                 :             :     }
     800                 :             : 
     801                 :         185 :     return LIBSPDM_STATUS_SUCCESS;
     802                 :             : }
     803                 :             : 
     804                 :          21 : libspdm_return_t libspdm_get_data(void *spdm_context, libspdm_data_type_t data_type,
     805                 :             :                                   const libspdm_data_parameter_t *parameter,
     806                 :             :                                   void *data, size_t *data_size)
     807                 :             : {
     808                 :             :     libspdm_context_t *context;
     809                 :          21 :     libspdm_secured_message_context_t *secured_context = NULL;
     810                 :             :     size_t target_data_size;
     811                 :             :     void *target_data;
     812                 :             :     uint32_t session_id;
     813                 :             :     libspdm_session_info_t *session_info;
     814                 :             :     uint8_t slot_id;
     815                 :             : 
     816   [ +  -  +  -  :          21 :     if (spdm_context == NULL || data == NULL || data_size == NULL ||
             +  -  -  + ]
     817                 :             :         data_type >= LIBSPDM_DATA_MAX) {
     818                 :           0 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
     819                 :             :     }
     820                 :             : 
     821                 :          21 :     context = spdm_context;
     822                 :             : 
     823         [ -  + ]:          21 :     if (data_type == LIBSPDM_DATA_SESSION_END_SESSION_ATTRIBUTES) {
     824                 :             :         /* end_session_attributes is present in both a session context as well as an
     825                 :             :          * spdm context. */
     826                 :           0 :         session_id = libspdm_read_uint32(parameter->additional_data);
     827                 :           0 :         session_info = libspdm_get_session_info_via_session_id(context, session_id);
     828         [ -  + ]:          21 :     } else if (need_session_info_for_data(data_type)) {
     829         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_SESSION) {
     830                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     831                 :             :         }
     832                 :           0 :         session_id = libspdm_read_uint32(parameter->additional_data);
     833                 :           0 :         session_info = libspdm_get_session_info_via_session_id(context, session_id);
     834         [ #  # ]:           0 :         if (session_info == NULL) {
     835                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     836                 :             :         }
     837                 :           0 :         secured_context = session_info->secured_message_context;
     838                 :             :     } else {
     839                 :          21 :         session_info = NULL;
     840                 :             :     }
     841                 :             : 
     842   [ -  -  -  -  :          21 :     switch (data_type) {
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  +  
          -  -  -  -  -  
          -  -  -  +  -  
          -  -  -  -  +  
          -  -  -  -  -  
                -  -  - ]
     843                 :           0 :     case LIBSPDM_DATA_SPDM_VERSION:
     844         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     845                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     846                 :             :         }
     847                 :           0 :         target_data_size = sizeof(spdm_version_number_t);
     848                 :           0 :         target_data = &(context->connection_info.version);
     849                 :           0 :         break;
     850                 :           0 :     case LIBSPDM_DATA_SESSION_SECURED_MESSAGE_VERSION:
     851                 :           0 :         target_data_size = sizeof(spdm_version_number_t);
     852                 :           0 :         target_data = &(secured_context->secured_message_version);
     853                 :           0 :         break;
     854                 :           0 :     case LIBSPDM_DATA_CAPABILITY_FLAGS:
     855                 :           0 :         target_data_size = sizeof(uint32_t);
     856         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     857                 :           0 :             target_data = &context->connection_info.capability.flags;
     858         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     859                 :           0 :             target_data = &context->local_context.capability.flags;
     860                 :             :         } else {
     861                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     862                 :             :         }
     863                 :           0 :         break;
     864                 :           0 :     case LIBSPDM_DATA_CAPABILITY_EXT_FLAGS:
     865                 :           0 :         target_data_size = sizeof(uint16_t);
     866         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     867                 :           0 :             target_data = &context->connection_info.capability.ext_flags;
     868         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     869                 :           0 :             target_data = &context->local_context.capability.ext_flags;
     870                 :             :         } else {
     871                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     872                 :             :         }
     873                 :           0 :         break;
     874                 :           0 :     case LIBSPDM_DATA_CAPABILITY_CT_EXPONENT:
     875                 :           0 :         target_data_size = sizeof(uint8_t);
     876         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     877                 :           0 :             target_data = &context->connection_info.capability.ct_exponent;
     878         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     879                 :           0 :             target_data = &context->local_context.capability.ct_exponent;
     880                 :             :         } else {
     881                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     882                 :             :         }
     883                 :           0 :         break;
     884                 :           0 :     case LIBSPDM_DATA_CAPABILITY_DATA_TRANSFER_SIZE:
     885                 :           0 :         target_data_size = sizeof(uint32_t);
     886         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     887                 :           0 :             target_data = &context->connection_info.capability.data_transfer_size;
     888         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     889                 :           0 :             target_data = &context->local_context.capability.data_transfer_size;
     890                 :             :         } else {
     891                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     892                 :             :         }
     893                 :           0 :         break;
     894                 :           0 :     case LIBSPDM_DATA_CAPABILITY_MAX_SPDM_MSG_SIZE:
     895                 :           0 :         target_data_size = sizeof(uint32_t);
     896         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     897                 :           0 :             target_data = &context->connection_info.capability.max_spdm_msg_size;
     898         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     899                 :           0 :             target_data = &context->local_context.capability.max_spdm_msg_size;
     900                 :             :         } else {
     901                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     902                 :             :         }
     903                 :           0 :         break;
     904                 :           0 :     case LIBSPDM_DATA_CAPABILITY_SENDER_DATA_TRANSFER_SIZE:
     905                 :           0 :         target_data_size = sizeof(uint32_t);
     906         [ #  # ]:           0 :         if (parameter->location == LIBSPDM_DATA_LOCATION_CONNECTION) {
     907                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     908         [ #  # ]:           0 :         } else if (parameter->location == LIBSPDM_DATA_LOCATION_LOCAL) {
     909                 :           0 :             target_data = &context->local_context.capability.sender_data_transfer_size;
     910                 :             :         } else {
     911                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     912                 :             :         }
     913                 :           0 :         break;
     914                 :           0 :     case LIBSPDM_DATA_MEASUREMENT_SPEC:
     915         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     916                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     917                 :             :         }
     918                 :           0 :         target_data_size = sizeof(uint8_t);
     919                 :           0 :         target_data = &context->connection_info.algorithm.measurement_spec;
     920                 :           0 :         break;
     921                 :           0 :     case LIBSPDM_DATA_MEASUREMENT_HASH_ALGO:
     922         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     923                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     924                 :             :         }
     925                 :           0 :         target_data_size = sizeof(uint32_t);
     926                 :           0 :         target_data = &context->connection_info.algorithm.measurement_hash_algo;
     927                 :           0 :         break;
     928                 :           0 :     case LIBSPDM_DATA_BASE_ASYM_ALGO:
     929         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     930                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     931                 :             :         }
     932                 :           0 :         target_data_size = sizeof(uint32_t);
     933                 :           0 :         target_data = &context->connection_info.algorithm.base_asym_algo;
     934                 :           0 :         break;
     935                 :           0 :     case LIBSPDM_DATA_BASE_HASH_ALGO:
     936         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     937                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     938                 :             :         }
     939                 :           0 :         target_data_size = sizeof(uint32_t);
     940                 :           0 :         target_data = &context->connection_info.algorithm.base_hash_algo;
     941                 :           0 :         break;
     942                 :           0 :     case LIBSPDM_DATA_DHE_NAME_GROUP:
     943         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     944                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     945                 :             :         }
     946                 :           0 :         target_data_size = sizeof(uint16_t);
     947                 :           0 :         target_data = &context->connection_info.algorithm.dhe_named_group;
     948                 :           0 :         break;
     949                 :           0 :     case LIBSPDM_DATA_AEAD_CIPHER_SUITE:
     950         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     951                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     952                 :             :         }
     953                 :           0 :         target_data_size = sizeof(uint16_t);
     954                 :           0 :         target_data = &context->connection_info.algorithm.aead_cipher_suite;
     955                 :           0 :         break;
     956                 :           0 :     case LIBSPDM_DATA_REQ_BASE_ASYM_ALG:
     957         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     958                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     959                 :             :         }
     960                 :           0 :         target_data_size = sizeof(uint16_t);
     961                 :           0 :         target_data = &context->connection_info.algorithm.req_base_asym_alg;
     962                 :           0 :         break;
     963                 :           0 :     case LIBSPDM_DATA_KEY_SCHEDULE:
     964         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     965                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     966                 :             :         }
     967                 :           0 :         target_data_size = sizeof(uint16_t);
     968                 :           0 :         target_data = &context->connection_info.algorithm.key_schedule;
     969                 :           0 :         break;
     970                 :           0 :     case LIBSPDM_DATA_OTHER_PARAMS_SUPPORT:
     971         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     972                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     973                 :             :         }
     974                 :           0 :         target_data_size = sizeof(uint8_t);
     975                 :           0 :         target_data = &context->connection_info.algorithm.other_params_support;
     976                 :           0 :         break;
     977                 :           0 :     case LIBSPDM_DATA_MEL_SPEC:
     978         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     979                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     980                 :             :         }
     981                 :           0 :         target_data_size = sizeof(uint8_t);
     982                 :           0 :         target_data = &context->connection_info.algorithm.mel_spec;
     983                 :           0 :         break;
     984                 :           0 :     case LIBSPDM_DATA_PQC_ASYM_ALGO:
     985         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     986                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     987                 :             :         }
     988                 :           0 :         target_data_size = sizeof(uint32_t);
     989                 :           0 :         target_data = &context->connection_info.algorithm.pqc_asym_algo;
     990                 :           0 :         break;
     991                 :           0 :     case LIBSPDM_DATA_REQ_PQC_ASYM_ALG:
     992         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
     993                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
     994                 :             :         }
     995                 :           0 :         target_data_size = sizeof(uint32_t);
     996                 :           0 :         target_data = &context->connection_info.algorithm.req_pqc_asym_alg;
     997                 :           0 :         break;
     998                 :           0 :     case LIBSPDM_DATA_KEM_ALG:
     999         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
    1000                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1001                 :             :         }
    1002                 :           0 :         target_data_size = sizeof(uint32_t);
    1003                 :           0 :         target_data = &context->connection_info.algorithm.kem_alg;
    1004                 :           0 :         break;
    1005                 :           0 :     case LIBSPDM_DATA_CONNECTION_STATE:
    1006         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
    1007                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1008                 :             :         }
    1009                 :           0 :         target_data_size = sizeof(libspdm_connection_state_t);
    1010                 :           0 :         target_data = &context->connection_info.connection_state;
    1011                 :           0 :         break;
    1012                 :           0 :     case LIBSPDM_DATA_RESPONSE_STATE:
    1013                 :           0 :         target_data_size = sizeof(libspdm_response_state_t);
    1014                 :           0 :         target_data = &context->response_state;
    1015                 :           0 :         break;
    1016                 :           6 :     case LIBSPDM_DATA_PEER_PROVISIONED_SLOT_MASK:
    1017         [ -  + ]:           6 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
    1018                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1019                 :             :         }
    1020                 :           6 :         target_data_size = sizeof(uint8_t);
    1021                 :           6 :         target_data = &context->connection_info.peer_provisioned_slot_mask;
    1022                 :           6 :         break;
    1023                 :           0 :     case LIBSPDM_DATA_PEER_SUPPORTED_SLOT_MASK:
    1024         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
    1025                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1026                 :             :         }
    1027                 :           0 :         target_data_size = sizeof(uint8_t);
    1028                 :           0 :         target_data = &context->connection_info.peer_supported_slot_mask;
    1029                 :           0 :         break;
    1030                 :           0 :     case LIBSPDM_DATA_PEER_KEY_PAIR_ID:
    1031         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
    1032                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1033                 :             :         }
    1034                 :           0 :         slot_id = parameter->additional_data[0];
    1035         [ #  # ]:           0 :         if (slot_id >= SPDM_MAX_SLOT_COUNT) {
    1036                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1037                 :             :         }
    1038                 :           0 :         target_data_size = sizeof(spdm_key_pair_id_t);
    1039                 :           0 :         target_data = &context->connection_info.peer_key_pair_id[slot_id];
    1040                 :           0 :         break;
    1041                 :           0 :     case LIBSPDM_DATA_PEER_CERT_INFO:
    1042         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
    1043                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1044                 :             :         }
    1045                 :           0 :         slot_id = parameter->additional_data[0];
    1046         [ #  # ]:           0 :         if (slot_id >= SPDM_MAX_SLOT_COUNT) {
    1047                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1048                 :             :         }
    1049                 :           0 :         target_data_size = sizeof(spdm_certificate_info_t);
    1050                 :           0 :         target_data = &context->connection_info.peer_cert_info[slot_id];
    1051                 :           0 :         break;
    1052                 :           0 :     case LIBSPDM_DATA_PEER_KEY_USAGE_BIT_MASK:
    1053         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
    1054                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1055                 :             :         }
    1056                 :           0 :         slot_id = parameter->additional_data[0];
    1057         [ #  # ]:           0 :         if (slot_id >= SPDM_MAX_SLOT_COUNT) {
    1058                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1059                 :             :         }
    1060                 :           0 :         target_data_size = sizeof(spdm_key_usage_bit_mask_t);
    1061                 :           0 :         target_data = &context->connection_info.peer_key_usage_bit_mask[slot_id];
    1062                 :           0 :         break;
    1063                 :           0 :     case LIBSPDM_DATA_SESSION_USE_PSK:
    1064                 :           0 :         target_data_size = sizeof(bool);
    1065                 :           0 :         target_data = &session_info->use_psk;
    1066                 :           0 :         break;
    1067                 :           0 :     case LIBSPDM_DATA_SESSION_MUT_AUTH_REQUESTED:
    1068                 :           0 :         target_data_size = sizeof(uint8_t);
    1069                 :           0 :         target_data = &session_info->mut_auth_requested;
    1070                 :           0 :         break;
    1071                 :           0 :     case LIBSPDM_DATA_SESSION_END_SESSION_ATTRIBUTES:
    1072         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
    1073                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1074                 :             :         }
    1075                 :           0 :         target_data_size = sizeof(uint8_t);
    1076         [ #  # ]:           0 :         if (session_info == NULL) {
    1077                 :           0 :             target_data = &context->connection_info.end_session_attributes;
    1078                 :             :         } else {
    1079                 :           0 :             target_data = &session_info->end_session_attributes;
    1080                 :             :         }
    1081                 :           0 :         break;
    1082                 :           0 :     case LIBSPDM_DATA_SESSION_POLICY:
    1083                 :           0 :         target_data_size = sizeof(uint8_t);
    1084                 :           0 :         target_data = &session_info->session_policy;
    1085                 :           0 :         break;
    1086                 :           6 :     case LIBSPDM_DATA_APP_CONTEXT_DATA:
    1087                 :           6 :         target_data_size = sizeof(void *);
    1088                 :           6 :         target_data = &context->app_context_data_ptr;
    1089                 :           6 :         break;
    1090                 :           0 :     case LIBSPDM_DATA_HANDLE_ERROR_RETURN_POLICY:
    1091                 :           0 :         target_data_size = sizeof(uint8_t);
    1092                 :           0 :         target_data = &context->handle_error_return_policy;
    1093                 :           0 :         break;
    1094                 :           0 :     case LIBSPDM_DATA_MAX_DHE_SESSION_COUNT:
    1095                 :           0 :         target_data_size = sizeof(uint32_t);
    1096                 :           0 :         target_data = &context->max_dhe_session_count;
    1097                 :           0 :         break;
    1098                 :           0 :     case LIBSPDM_DATA_MAX_PSK_SESSION_COUNT:
    1099                 :           0 :         target_data_size = sizeof(uint32_t);
    1100                 :           0 :         target_data = &context->max_psk_session_count;
    1101                 :           0 :         break;
    1102                 :           0 :     case LIBSPDM_DATA_SESSION_SEQUENCE_NUMBER_REQ_DIR:
    1103                 :           0 :         target_data_size = sizeof(uint64_t);
    1104                 :           0 :         target_data = &secured_context->application_secret.request_data_sequence_number;
    1105                 :           0 :         break;
    1106                 :           0 :     case LIBSPDM_DATA_SESSION_SEQUENCE_NUMBER_RSP_DIR:
    1107                 :           0 :         target_data_size = sizeof(uint64_t);
    1108                 :           0 :         target_data = &secured_context->application_secret.response_data_sequence_number;
    1109                 :           0 :         break;
    1110                 :           9 :     case LIBSPDM_DATA_MAX_SPDM_SESSION_SEQUENCE_NUMBER:
    1111                 :           9 :         target_data_size = sizeof(uint64_t);
    1112                 :             :         /* When a session is addressed (LIBSPDM_DATA_LOCATION_SESSION), return that session's
    1113                 :             :          * effective maximum sequence number, i.e. the value negotiated via the DSP0277 1.3 AEAD
    1114                 :             :          * limit (min of the integrator-configured cap and the negotiated AEAD limit). Otherwise
    1115                 :             :          * return the context-level integrator-configured value. */
    1116         [ +  - ]:           9 :         if (parameter->location == LIBSPDM_DATA_LOCATION_SESSION) {
    1117                 :           9 :             session_id = libspdm_read_uint32(parameter->additional_data);
    1118                 :           9 :             session_info = libspdm_get_session_info_via_session_id(context, session_id);
    1119         [ -  + ]:           9 :             if (session_info == NULL) {
    1120                 :           0 :                 return LIBSPDM_STATUS_INVALID_PARAMETER;
    1121                 :             :             }
    1122                 :           9 :             secured_context = session_info->secured_message_context;
    1123                 :           9 :             target_data = &secured_context->max_spdm_session_sequence_number;
    1124                 :             :         } else {
    1125                 :           0 :             target_data = &context->max_spdm_session_sequence_number;
    1126                 :             :         }
    1127                 :           9 :         break;
    1128                 :           0 :     case LIBSPDM_DATA_VCA_CACHE:
    1129                 :           0 :         target_data_size = context->transcript.message_a.buffer_size;
    1130                 :           0 :         target_data = context->transcript.message_a.buffer;
    1131                 :           0 :         break;
    1132                 :           0 :     case LIBSPDM_DATA_REQUEST_AND_SIZE:
    1133                 :           0 :         target_data_size = context->last_spdm_request_size;
    1134                 :           0 :         target_data = context->last_spdm_request;
    1135                 :           0 :         break;
    1136                 :           0 :     case LIBSPDM_DATA_SPDM_VERSION_10_11_VERIFY_SIGNATURE_ENDIAN:
    1137                 :           0 :         target_data_size = sizeof(uint8_t);
    1138                 :           0 :         target_data = &context->spdm_10_11_verify_signature_endian;
    1139                 :           0 :         break;
    1140                 :           0 :     case LIBSPDM_DATA_SEQUENCE_NUMBER_ENDIAN:
    1141                 :           0 :         target_data_size = sizeof(uint8_t);
    1142                 :           0 :         target_data = &context->sequence_number_endian;
    1143                 :           0 :         break;
    1144                 :           0 :     case LIBSPDM_DATA_SESSION_SEQUENCE_NUMBER_ENDIAN:
    1145                 :           0 :         target_data_size = sizeof(uint8_t);
    1146                 :           0 :         target_data = &secured_context->sequence_number_endian;
    1147                 :           0 :         break;
    1148                 :           0 :     case LIBSPDM_DATA_MULTI_KEY_CONN_REQ:
    1149         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
    1150                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1151                 :             :         }
    1152                 :           0 :         target_data_size = sizeof(bool);
    1153                 :           0 :         target_data = &context->connection_info.multi_key_conn_req;
    1154                 :           0 :         break;
    1155                 :           0 :     case LIBSPDM_DATA_MULTI_KEY_CONN_RSP:
    1156         [ #  # ]:           0 :         if (parameter->location != LIBSPDM_DATA_LOCATION_CONNECTION) {
    1157                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    1158                 :             :         }
    1159                 :           0 :         target_data_size = sizeof(bool);
    1160                 :           0 :         target_data = &context->connection_info.multi_key_conn_rsp;
    1161                 :           0 :         break;
    1162                 :           0 :     default:
    1163                 :           0 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
    1164                 :             :         break;
    1165                 :             :     }
    1166                 :             : 
    1167         [ +  + ]:          21 :     if (*data_size < target_data_size) {
    1168                 :           1 :         *data_size = target_data_size;
    1169                 :           1 :         return LIBSPDM_STATUS_BUFFER_TOO_SMALL;
    1170                 :             :     }
    1171                 :          20 :     libspdm_copy_mem(data, *data_size, target_data, target_data_size);
    1172                 :          20 :     *data_size = target_data_size;
    1173                 :             : 
    1174                 :          20 :     return LIBSPDM_STATUS_SUCCESS;
    1175                 :             : }
    1176                 :             : 
    1177                 :             : #if LIBSPDM_CHECK_SPDM_CONTEXT
    1178                 :           3 : bool libspdm_check_context (void *spdm_context)
    1179                 :             : {
    1180                 :             :     libspdm_context_t *context;
    1181                 :             :     size_t index;
    1182                 :             : 
    1183                 :           3 :     context = spdm_context;
    1184                 :             : 
    1185         [ +  + ]:           3 :     if (context->local_context.capability.data_transfer_size <
    1186                 :             :         SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) {
    1187                 :           1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
    1188                 :             :                        "data_transfer_size must be greater than or equal "
    1189                 :             :                        "to SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12 (%d).\n",
    1190                 :             :                        SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12));
    1191                 :           1 :         return false;
    1192                 :             :     }
    1193                 :             : 
    1194                 :           2 :     if (context->local_context.capability.max_spdm_msg_size <
    1195         [ +  + ]:           2 :         context->local_context.capability.data_transfer_size) {
    1196                 :           1 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
    1197                 :             :                        "max_spdm_msg_size (%d) must be greater than or "
    1198                 :             :                        "equal to data_transfer_size (%d).\n",
    1199                 :             :                        context->local_context.capability.max_spdm_msg_size,
    1200                 :             :                        context->local_context.capability.data_transfer_size));
    1201                 :           1 :         return false;
    1202                 :             :     }
    1203                 :             : 
    1204         [ -  + ]:           1 :     if (context->local_context.capability.sender_data_transfer_size <
    1205                 :             :         SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12) {
    1206                 :           0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
    1207                 :             :                        "sender_data_transfer_size must be greater than or equal "
    1208                 :             :                        "to %d.\n", SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12));
    1209                 :           0 :         return false;
    1210                 :             :     }
    1211                 :             : 
    1212                 :           1 :     if (context->local_context.capability.max_spdm_msg_size <
    1213         [ -  + ]:           1 :         context->local_context.capability.sender_data_transfer_size) {
    1214                 :           0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
    1215                 :             :                        "max_spdm_msg_size (%d) must be greater than or "
    1216                 :             :                        "equal to sender_data_transfer_size (%d).\n",
    1217                 :             :                        context->local_context.capability.max_spdm_msg_size,
    1218                 :             :                        context->local_context.capability.sender_data_transfer_size));
    1219                 :           0 :         return false;
    1220                 :             :     }
    1221                 :             : 
    1222         [ -  + ]:           1 :     if (((context->local_context.capability.flags &
    1223                 :           0 :           SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP) != 0) &&
    1224         [ #  # ]:           0 :         (context->local_context.capability.max_spdm_msg_size != 0)) {
    1225         [ #  # ]:           0 :         for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
    1226         [ #  # ]:           0 :             if ((context->local_context.local_cert_chain_provision_size[index] != 0) &&
    1227                 :           0 :                 (context->local_context.local_cert_chain_provision_size[index] +
    1228                 :             :                  sizeof(spdm_certificate_response_t) >
    1229         [ #  # ]:           0 :                  context->local_context.capability.max_spdm_msg_size)) {
    1230                 :           0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
    1231                 :             :                                "max_spdm_msg_size (%d) must be greater than or "
    1232                 :             :                                "equal to local_cert_chain_provision_size[%zu] (%zu).\n",
    1233                 :             :                                context->local_context.capability.max_spdm_msg_size, index,
    1234                 :             :                                context->local_context.local_cert_chain_provision_size[index]));
    1235                 :           0 :                 return false;
    1236                 :             :             }
    1237                 :             :         }
    1238                 :             :     }
    1239                 :             : 
    1240                 :           1 :     return true;
    1241                 :             : }
    1242                 :             : #endif /* LIBSPDM_CHECK_SPDM_CONTEXT */
    1243                 :             : 
    1244                 :        1233 : void libspdm_reset_message_a(libspdm_context_t *spdm_context)
    1245                 :             : {
    1246                 :        1233 :     libspdm_reset_managed_buffer(&spdm_context->transcript.message_a);
    1247                 :        1233 : }
    1248                 :             : 
    1249                 :         422 : void libspdm_reset_message_d(libspdm_context_t *spdm_context)
    1250                 :             : {
    1251                 :         422 :     libspdm_reset_managed_buffer(&spdm_context->transcript.message_d);
    1252                 :             :     /* Restarting the DIGESTS transcript reopens the "immediately follows VCA" window. */
    1253                 :         422 :     spdm_context->connection_info.digest_transcript_window_closed = false;
    1254                 :         422 : }
    1255                 :             : 
    1256                 :        1648 : void libspdm_reset_message_b(libspdm_context_t *spdm_context)
    1257                 :             : {
    1258                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1259                 :             :     libspdm_reset_managed_buffer(&spdm_context->transcript.message_b);
    1260                 :             : #else
    1261         [ +  + ]:        1648 :     if (spdm_context->transcript.digest_context_m1m2 != NULL) {
    1262                 :         210 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1263                 :             :                            spdm_context->transcript.digest_context_m1m2);
    1264                 :         210 :         spdm_context->transcript.digest_context_m1m2 = NULL;
    1265                 :             :     }
    1266                 :             : #endif
    1267                 :        1648 : }
    1268                 :             : 
    1269                 :        1157 : void libspdm_reset_message_c(libspdm_context_t *spdm_context)
    1270                 :             : {
    1271                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1272                 :             :     libspdm_reset_managed_buffer(&spdm_context->transcript.message_c);
    1273                 :             : #else
    1274         [ -  + ]:        1157 :     if (spdm_context->transcript.digest_context_m1m2 != NULL) {
    1275                 :           0 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1276                 :             :                            spdm_context->transcript.digest_context_m1m2);
    1277                 :           0 :         spdm_context->transcript.digest_context_m1m2 = NULL;
    1278                 :             :     }
    1279                 :             : #endif
    1280                 :        1157 : }
    1281                 :             : 
    1282                 :        1078 : void libspdm_reset_message_mut_b(libspdm_context_t *spdm_context)
    1283                 :             : {
    1284                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1285                 :             :     libspdm_reset_managed_buffer(&spdm_context->transcript.message_mut_b);
    1286                 :             : #else
    1287         [ +  + ]:        1078 :     if (spdm_context->transcript.digest_context_mut_m1m2 != NULL) {
    1288                 :          61 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1289                 :             :                            spdm_context->transcript.digest_context_mut_m1m2);
    1290                 :          61 :         spdm_context->transcript.digest_context_mut_m1m2 = NULL;
    1291                 :             :     }
    1292                 :             : #endif
    1293                 :        1078 : }
    1294                 :             : 
    1295                 :        1045 : void libspdm_reset_message_mut_c(libspdm_context_t *spdm_context)
    1296                 :             : {
    1297                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1298                 :             :     libspdm_reset_managed_buffer(&spdm_context->transcript.message_mut_c);
    1299                 :             : #else
    1300         [ +  + ]:        1045 :     if (spdm_context->transcript.digest_context_mut_m1m2 != NULL) {
    1301                 :           5 :         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1302                 :             :                            spdm_context->transcript.digest_context_mut_m1m2);
    1303                 :           5 :         spdm_context->transcript.digest_context_mut_m1m2 = NULL;
    1304                 :             :     }
    1305                 :             : #endif
    1306                 :        1045 : }
    1307                 :             : 
    1308                 :        6275 : void libspdm_reset_message_m(libspdm_context_t *spdm_context, void *session_info)
    1309                 :             : {
    1310                 :             :     libspdm_session_info_t *spdm_session_info;
    1311                 :             : 
    1312                 :        6275 :     spdm_session_info = session_info;
    1313                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1314                 :             :     if (spdm_session_info == NULL) {
    1315                 :             :         libspdm_reset_managed_buffer(&spdm_context->transcript.message_m);
    1316                 :             :     } else {
    1317                 :             :         libspdm_reset_managed_buffer(&spdm_session_info->session_transcript.message_m);
    1318                 :             :     }
    1319                 :             : #else
    1320         [ +  + ]:        6275 :     if (spdm_session_info == NULL) {
    1321         [ +  + ]:        4731 :         if (spdm_context->transcript.digest_context_l1l2 != NULL) {
    1322                 :          67 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1323                 :             :                                spdm_context->transcript.digest_context_l1l2);
    1324                 :          67 :             spdm_context->transcript.digest_context_l1l2 = NULL;
    1325                 :             :         }
    1326                 :             :     } else {
    1327         [ +  + ]:        1544 :         if (spdm_session_info->session_transcript.digest_context_l1l2 != NULL) {
    1328                 :           4 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1329                 :             :                                spdm_session_info->session_transcript.digest_context_l1l2);
    1330                 :           4 :             spdm_session_info->session_transcript.digest_context_l1l2 = NULL;
    1331                 :             :         }
    1332                 :             :     }
    1333                 :             : #endif
    1334                 :             : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
    1335         [ +  + ]:        6275 :     if (spdm_context->spdm_meas_log_reset_callback != NULL) {
    1336         [ +  + ]:          85 :         spdm_context->spdm_meas_log_reset_callback(
    1337                 :             :             spdm_context, spdm_session_info == NULL ? NULL : &spdm_session_info->session_id);
    1338                 :             :     }
    1339                 :             : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
    1340                 :        6275 : }
    1341                 :             : 
    1342                 :        1240 : void libspdm_reset_message_k(libspdm_context_t *spdm_context, void *session_info)
    1343                 :             : {
    1344                 :             :     libspdm_session_info_t *spdm_session_info;
    1345                 :             : 
    1346                 :        1240 :     spdm_session_info = session_info;
    1347                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1348                 :             :     libspdm_reset_managed_buffer(&spdm_session_info->session_transcript.message_k);
    1349                 :             : #else
    1350                 :             :     {
    1351         [ +  + ]:        1240 :         if (spdm_session_info->session_transcript.digest_context_th != NULL) {
    1352                 :          30 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1353                 :             :                                spdm_session_info->session_transcript.digest_context_th);
    1354                 :          30 :             spdm_session_info->session_transcript.digest_context_th = NULL;
    1355                 :             :         }
    1356         [ +  + ]:        1240 :         if (spdm_session_info->session_transcript.digest_context_th_backup != NULL) {
    1357                 :          19 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1358                 :             :                                spdm_session_info->session_transcript.digest_context_th_backup);
    1359                 :          19 :             spdm_session_info->session_transcript.digest_context_th_backup = NULL;
    1360                 :             :         }
    1361                 :             :     }
    1362                 :             : #endif
    1363                 :        1240 : }
    1364                 :             : 
    1365                 :        1240 : void libspdm_reset_message_encap_d(void *session_info)
    1366                 :             : {
    1367                 :             :     libspdm_session_info_t *spdm_session_info;
    1368                 :             : 
    1369                 :        1240 :     spdm_session_info = session_info;
    1370                 :        1240 :     libspdm_reset_managed_buffer(&spdm_session_info->session_transcript.message_encap_d);
    1371                 :             :     /* Restarting the encapsulated DIGESTS transcript reopens the "first encapsulated response"
    1372                 :             :      * window. */
    1373                 :        1240 :     spdm_session_info->session_transcript.encap_digest_window_closed = false;
    1374                 :        1240 : }
    1375                 :             : 
    1376                 :        1260 : void libspdm_reset_message_f(libspdm_context_t *spdm_context, void *session_info)
    1377                 :             : {
    1378                 :             :     libspdm_session_info_t *spdm_session_info;
    1379                 :             : 
    1380                 :        1260 :     spdm_session_info = session_info;
    1381                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1382                 :             :     libspdm_reset_managed_buffer(&spdm_session_info->session_transcript.message_f);
    1383                 :             : #else
    1384                 :             :     {
    1385         [ +  + ]:        1260 :         if (spdm_session_info->session_transcript.digest_context_th != NULL) {
    1386                 :          22 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1387                 :             :                                spdm_session_info->session_transcript.digest_context_th);
    1388                 :          22 :             spdm_session_info->session_transcript.digest_context_th =
    1389                 :          22 :                 spdm_session_info->session_transcript.digest_context_th_backup;
    1390                 :          22 :             spdm_session_info->session_transcript.digest_context_th_backup = NULL;
    1391                 :             :         }
    1392                 :        1260 :         spdm_session_info->session_transcript.message_f_initialized = false;
    1393                 :             :     }
    1394                 :             : #endif
    1395                 :        1260 : }
    1396                 :             : 
    1397                 :        1786 : void libspdm_reset_message_e(libspdm_context_t *spdm_context, void *session_info)
    1398                 :             : {
    1399                 :             :     libspdm_session_info_t *spdm_session_info;
    1400                 :             : 
    1401                 :        1786 :     spdm_session_info = session_info;
    1402                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1403                 :             :     if (spdm_session_info == NULL) {
    1404                 :             :         libspdm_reset_managed_buffer(&spdm_context->transcript.message_e);
    1405                 :             :     } else {
    1406                 :             :         libspdm_reset_managed_buffer(&spdm_session_info->session_transcript.message_e);
    1407                 :             :     }
    1408                 :             : #else
    1409         [ +  + ]:        1786 :     if (spdm_session_info == NULL) {
    1410         [ +  + ]:         546 :         if (spdm_context->transcript.digest_context_il1il2 != NULL) {
    1411                 :          14 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1412                 :             :                                spdm_context->transcript.digest_context_il1il2);
    1413                 :          14 :             spdm_context->transcript.digest_context_il1il2 = NULL;
    1414                 :             :         }
    1415                 :             :     } else {
    1416         [ +  + ]:        1240 :         if (spdm_session_info->session_transcript.digest_context_il1il2 != NULL) {
    1417                 :           3 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1418                 :             :                                spdm_session_info->session_transcript.digest_context_il1il2);
    1419                 :           3 :             spdm_session_info->session_transcript.digest_context_il1il2 = NULL;
    1420                 :             :         }
    1421                 :             :     }
    1422                 :             : #endif
    1423                 :        1786 : }
    1424                 :             : 
    1425                 :        1751 : void libspdm_reset_message_encap_e(libspdm_context_t *spdm_context, void *session_info)
    1426                 :             : {
    1427                 :             :     libspdm_session_info_t *spdm_session_info;
    1428                 :             : 
    1429                 :        1751 :     spdm_session_info = session_info;
    1430                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1431                 :             :     if (spdm_session_info == NULL) {
    1432                 :             :         libspdm_reset_managed_buffer(&spdm_context->transcript.message_encap_e);
    1433                 :             :     } else {
    1434                 :             :         libspdm_reset_managed_buffer(&spdm_session_info->session_transcript.message_encap_e);
    1435                 :             :     }
    1436                 :             : #else
    1437         [ +  + ]:        1751 :     if (spdm_session_info == NULL) {
    1438         [ +  + ]:         511 :         if (spdm_context->transcript.digest_context_encap_il1il2 != NULL) {
    1439                 :          14 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1440                 :             :                                spdm_context->transcript.digest_context_encap_il1il2);
    1441                 :          14 :             spdm_context->transcript.digest_context_encap_il1il2 = NULL;
    1442                 :             :         }
    1443                 :             :     } else {
    1444         [ +  + ]:        1240 :         if (spdm_session_info->session_transcript.digest_context_encap_il1il2 != NULL) {
    1445                 :           2 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1446                 :             :                                spdm_session_info->session_transcript.digest_context_encap_il1il2);
    1447                 :           2 :             spdm_session_info->session_transcript.digest_context_encap_il1il2 = NULL;
    1448                 :             :         }
    1449                 :             :     }
    1450                 :             : #endif
    1451                 :        1751 : }
    1452                 :             : 
    1453                 :        4753 : void libspdm_reset_message_buffer_via_request_code(void *context, void *session_info,
    1454                 :             :                                                    uint8_t request_code)
    1455                 :             : {
    1456                 :             :     libspdm_context_t *spdm_context;
    1457                 :             : 
    1458                 :        4753 :     spdm_context = context;
    1459                 :             :     /* Close the DIGESTS transcript window once a non-GET_DIGESTS request is processed after
    1460                 :             :      * NEGOTIATED (the state check excludes the VCA messages). */
    1461         [ +  + ]:        4753 :     if ((request_code != SPDM_GET_DIGESTS) &&
    1462         [ +  + ]:        4678 :         (spdm_context->connection_info.connection_state >= LIBSPDM_CONNECTION_STATE_NEGOTIATED)) {
    1463                 :        4346 :         spdm_context->connection_info.digest_transcript_window_closed = true;
    1464                 :             :     }
    1465                 :             :     /**
    1466                 :             :      * Any request other than SPDM_GET_MEASUREMENTS resets L1/L2
    1467                 :             :      */
    1468         [ +  + ]:        4753 :     if (request_code != SPDM_GET_MEASUREMENTS) {
    1469                 :        4320 :         libspdm_reset_message_m(spdm_context, session_info);
    1470                 :             :     }
    1471                 :             :     /**
    1472                 :             :      * If the Requester issued GET_MEASUREMENTS or KEY_EXCHANGE or FINISH or PSK_EXCHANGE
    1473                 :             :      * or PSK_FINISH or KEY_UPDATE or HEARTBEAT or GET_ENCAPSULATED_REQUEST or DELIVER_ENCAPSULATED_RESPONSE
    1474                 :             :      * or END_SESSION request(s) or SPDM_GET_MEASUREMENT_EXTENSION_LOG and skipped CHALLENGE completion, M1 and M2 are reset to null.
    1475                 :             :      */
    1476   [ +  +  +  +  :        4753 :     switch (request_code)
                      + ]
    1477                 :             :     {
    1478                 :        1028 :     case SPDM_KEY_EXCHANGE:
    1479                 :             :     case SPDM_GET_MEASUREMENTS:
    1480                 :             :     case SPDM_FINISH:
    1481                 :             :     case SPDM_PSK_EXCHANGE:
    1482                 :             :     case SPDM_PSK_FINISH:
    1483                 :             :     case SPDM_KEY_UPDATE:
    1484                 :             :     case SPDM_HEARTBEAT:
    1485                 :             :     case SPDM_GET_ENCAPSULATED_REQUEST:
    1486                 :             :     case SPDM_END_SESSION:
    1487                 :             :     case SPDM_GET_MEASUREMENT_EXTENSION_LOG:
    1488         [ +  + ]:        1028 :         if (spdm_context->connection_info.connection_state <
    1489                 :             :             LIBSPDM_CONNECTION_STATE_AUTHENTICATED) {
    1490                 :         573 :             libspdm_reset_message_b(spdm_context);
    1491                 :         573 :             libspdm_reset_message_c(spdm_context);
    1492                 :         573 :             libspdm_reset_message_mut_b(spdm_context);
    1493                 :         573 :             libspdm_reset_message_mut_c(spdm_context);
    1494                 :             :         }
    1495                 :        1028 :         break;
    1496                 :          42 :     case SPDM_DELIVER_ENCAPSULATED_RESPONSE:
    1497         [ +  - ]:          42 :         if (spdm_context->connection_info.connection_state <
    1498                 :             :             LIBSPDM_CONNECTION_STATE_AUTHENTICATED) {
    1499                 :          42 :             libspdm_reset_message_b(spdm_context);
    1500                 :          42 :             libspdm_reset_message_c(spdm_context);
    1501                 :             :         }
    1502                 :          42 :         break;
    1503                 :          75 :     case SPDM_GET_DIGESTS:
    1504                 :          75 :         libspdm_reset_message_b(spdm_context);
    1505                 :          75 :         break;
    1506                 :          56 :     case SPDM_GET_ENDPOINT_INFO:
    1507                 :          56 :         libspdm_reset_message_e(spdm_context, session_info);
    1508                 :          56 :         libspdm_reset_message_encap_e(spdm_context, session_info);
    1509                 :          56 :         break;
    1510                 :        3552 :     default:
    1511                 :        3552 :         break;
    1512                 :             :     }
    1513                 :        4753 : }
    1514                 :             : 
    1515                 :          34 : void libspdm_reset_message_buffer_via_encap_request_code(void *context, void *session_info,
    1516                 :             :                                                          uint8_t request_code)
    1517                 :             : {
    1518                 :             :     libspdm_session_info_t *spdm_session_info;
    1519                 :             : 
    1520                 :             :     /* The encapsulated flow only affects the session transcript. */
    1521         [ +  + ]:          34 :     if (session_info == NULL) {
    1522                 :          20 :         return;
    1523                 :             :     }
    1524                 :          14 :     spdm_session_info = session_info;
    1525                 :             : 
    1526                 :             :     /* Close the encapsulated DIGESTS window if the first encapsulated request is not GET_DIGESTS.
    1527                 :             :      * Enforced here (not from a fixed local sequence) so it holds for whatever order the peer drives,
    1528                 :             :      * for both the Requester and Responder encapsulated flows. */
    1529   [ +  +  +  - ]:          22 :     if ((request_code != SPDM_GET_DIGESTS) &&
    1530                 :           8 :         (libspdm_get_managed_buffer_size(
    1531                 :           8 :              &spdm_session_info->session_transcript.message_encap_d) == 0)) {
    1532                 :           8 :         spdm_session_info->session_transcript.encap_digest_window_closed = true;
    1533                 :             :     }
    1534                 :             : }
    1535                 :             : 
    1536                 :         304 : libspdm_return_t libspdm_append_message_a(libspdm_context_t *spdm_context, const void *message,
    1537                 :             :                                           size_t message_size)
    1538                 :             : {
    1539                 :         304 :     return libspdm_append_managed_buffer(&spdm_context->transcript.message_a,
    1540                 :             :                                          message, message_size);
    1541                 :             : }
    1542                 :             : 
    1543                 :           9 : libspdm_return_t libspdm_append_message_d(libspdm_context_t *spdm_context, const void *message,
    1544                 :             :                                           size_t message_size)
    1545                 :             : {
    1546                 :             :     /* Window closed: the GET_DIGESTS did not immediately follow the VCA, so no DIGESTS is added. */
    1547         [ +  + ]:           9 :     if (spdm_context->connection_info.digest_transcript_window_closed) {
    1548                 :           1 :         return LIBSPDM_STATUS_SUCCESS;
    1549                 :             :     }
    1550                 :             :     /* Only the first message D after VCA in connection counts  */
    1551         [ +  + ]:           8 :     if (libspdm_get_managed_buffer_size(&spdm_context->transcript.message_d) != 0) {
    1552                 :           1 :         return LIBSPDM_STATUS_SUCCESS;
    1553                 :             :     }
    1554                 :           7 :     return libspdm_append_managed_buffer(&spdm_context->transcript.message_d,
    1555                 :             :                                          message, message_size);
    1556                 :             : }
    1557                 :             : 
    1558                 :        6236 : libspdm_return_t libspdm_append_message_b(libspdm_context_t *spdm_context, const void *message,
    1559                 :             :                                           size_t message_size)
    1560                 :             : {
    1561                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1562                 :             :     return libspdm_append_managed_buffer(&spdm_context->transcript.message_b,
    1563                 :             :                                          message, message_size);
    1564                 :             : #else
    1565                 :             :     {
    1566                 :             :         bool result;
    1567                 :             : 
    1568         [ +  + ]:        6236 :         if (spdm_context->transcript.digest_context_m1m2 == NULL) {
    1569                 :         181 :             spdm_context->transcript.digest_context_m1m2 = libspdm_hash_new (
    1570                 :             :                 spdm_context->connection_info.algorithm.base_hash_algo);
    1571         [ -  + ]:         181 :             if (spdm_context->transcript.digest_context_m1m2 == NULL) {
    1572                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1573                 :             :             }
    1574                 :         181 :             result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    1575                 :             :                                         spdm_context->transcript.digest_context_m1m2);
    1576         [ -  + ]:         181 :             if (!result) {
    1577                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1578                 :             :                                    spdm_context->transcript.digest_context_m1m2);
    1579                 :           0 :                 spdm_context->transcript.digest_context_m1m2 = NULL;
    1580                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1581                 :             :             }
    1582                 :         181 :             result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    1583                 :             :                                           spdm_context->transcript.digest_context_m1m2,
    1584                 :         181 :                                           libspdm_get_managed_buffer(&spdm_context->transcript.
    1585                 :             :                                                                      message_a),
    1586                 :         181 :                                           libspdm_get_managed_buffer_size(&spdm_context->transcript.
    1587                 :             :                                                                           message_a));
    1588         [ -  + ]:         181 :             if (!result) {
    1589                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1590                 :             :                                    spdm_context->transcript.digest_context_m1m2);
    1591                 :           0 :                 spdm_context->transcript.digest_context_m1m2 = NULL;
    1592                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1593                 :             :             }
    1594                 :             :         }
    1595                 :             : 
    1596                 :        6236 :         result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    1597                 :             :                                       spdm_context->transcript.digest_context_m1m2, message,
    1598                 :             :                                       message_size);
    1599         [ -  + ]:        6236 :         if (!result) {
    1600                 :           0 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1601                 :             :                                spdm_context->transcript.digest_context_m1m2);
    1602                 :           0 :             spdm_context->transcript.digest_context_m1m2 = NULL;
    1603                 :           0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
    1604                 :             :         }
    1605                 :             : 
    1606                 :        6236 :         return LIBSPDM_STATUS_SUCCESS;
    1607                 :             :     }
    1608                 :             : #endif
    1609                 :             : }
    1610                 :             : 
    1611                 :          60 : libspdm_return_t libspdm_append_message_c(libspdm_context_t *spdm_context, const void *message,
    1612                 :             :                                           size_t message_size)
    1613                 :             : {
    1614                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1615                 :             :     return libspdm_append_managed_buffer(&spdm_context->transcript.message_c,
    1616                 :             :                                          message, message_size);
    1617                 :             : #else
    1618                 :             :     {
    1619                 :             :         bool result;
    1620                 :             : 
    1621         [ +  + ]:          60 :         if (spdm_context->transcript.digest_context_m1m2 == NULL) {
    1622                 :          29 :             spdm_context->transcript.digest_context_m1m2 = libspdm_hash_new (
    1623                 :             :                 spdm_context->connection_info.algorithm.base_hash_algo);
    1624         [ -  + ]:          29 :             if (spdm_context->transcript.digest_context_m1m2 == NULL) {
    1625                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1626                 :             :             }
    1627                 :          29 :             result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    1628                 :             :                                         spdm_context->transcript.digest_context_m1m2);
    1629         [ -  + ]:          29 :             if (!result) {
    1630                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1631                 :             :                                    spdm_context->transcript.digest_context_m1m2);
    1632                 :           0 :                 spdm_context->transcript.digest_context_m1m2 = NULL;
    1633                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1634                 :             :             }
    1635                 :          29 :             result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    1636                 :             :                                           spdm_context->transcript.digest_context_m1m2,
    1637                 :          29 :                                           libspdm_get_managed_buffer(&spdm_context->transcript.
    1638                 :             :                                                                      message_a),
    1639                 :          29 :                                           libspdm_get_managed_buffer_size(&spdm_context->transcript.
    1640                 :             :                                                                           message_a));
    1641         [ -  + ]:          29 :             if (!result) {
    1642                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1643                 :             :                                    spdm_context->transcript.digest_context_m1m2);
    1644                 :           0 :                 spdm_context->transcript.digest_context_m1m2 = NULL;
    1645                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1646                 :             :             }
    1647                 :             :         }
    1648                 :             : 
    1649                 :          60 :         result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    1650                 :             :                                       spdm_context->transcript.digest_context_m1m2, message,
    1651                 :             :                                       message_size);
    1652         [ -  + ]:          60 :         if (!result) {
    1653                 :           0 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1654                 :             :                                spdm_context->transcript.digest_context_m1m2);
    1655                 :           0 :             spdm_context->transcript.digest_context_m1m2 = NULL;
    1656                 :           0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
    1657                 :             :         }
    1658                 :             : 
    1659                 :          60 :         return LIBSPDM_STATUS_SUCCESS;
    1660                 :             :     }
    1661                 :             : #endif
    1662                 :             : }
    1663                 :             : 
    1664                 :        3025 : libspdm_return_t libspdm_append_message_mut_b(libspdm_context_t *spdm_context, const void *message,
    1665                 :             :                                               size_t message_size)
    1666                 :             : {
    1667                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1668                 :             :     return libspdm_append_managed_buffer(&spdm_context->transcript.message_mut_b,
    1669                 :             :                                          message, message_size);
    1670                 :             : #else
    1671                 :             :     {
    1672                 :             :         bool result;
    1673                 :             : 
    1674         [ +  + ]:        3025 :         if (spdm_context->transcript.digest_context_mut_m1m2 == NULL) {
    1675                 :          53 :             spdm_context->transcript.digest_context_mut_m1m2 = libspdm_hash_new (
    1676                 :             :                 spdm_context->connection_info.algorithm.base_hash_algo);
    1677         [ -  + ]:          53 :             if (spdm_context->transcript.digest_context_mut_m1m2 == NULL) {
    1678                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1679                 :             :             }
    1680                 :          53 :             result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    1681                 :             :                                         spdm_context->transcript.digest_context_mut_m1m2);
    1682         [ -  + ]:          53 :             if (!result) {
    1683                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1684                 :             :                                    spdm_context->transcript.digest_context_mut_m1m2);
    1685                 :           0 :                 spdm_context->transcript.digest_context_mut_m1m2 = NULL;
    1686                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1687                 :             :             }
    1688         [ +  + ]:          53 :             if ((spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >
    1689                 :             :                 SPDM_MESSAGE_VERSION_11) {
    1690                 :             : 
    1691                 :             :                 /* Need append VCA since 1.2 script */
    1692                 :           7 :                 result = libspdm_hash_update (
    1693                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo,
    1694                 :             :                     spdm_context->transcript.digest_context_mut_m1m2,
    1695                 :           7 :                     libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
    1696                 :           7 :                     libspdm_get_managed_buffer_size(&spdm_context->transcript.
    1697                 :             :                                                     message_a));
    1698         [ -  + ]:           7 :                 if (!result) {
    1699                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1700                 :             :                                        spdm_context->transcript.digest_context_mut_m1m2);
    1701                 :           0 :                     spdm_context->transcript.digest_context_mut_m1m2 = NULL;
    1702                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    1703                 :             :                 }
    1704                 :             :             }
    1705                 :             :         }
    1706                 :             : 
    1707                 :        3025 :         result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    1708                 :             :                                       spdm_context->transcript.digest_context_mut_m1m2, message,
    1709                 :             :                                       message_size);
    1710         [ -  + ]:        3025 :         if (!result) {
    1711                 :           0 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1712                 :             :                                spdm_context->transcript.digest_context_mut_m1m2);
    1713                 :           0 :             spdm_context->transcript.digest_context_mut_m1m2 = NULL;
    1714                 :           0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
    1715                 :             :         }
    1716                 :             : 
    1717                 :        3025 :         return LIBSPDM_STATUS_SUCCESS;
    1718                 :             :     }
    1719                 :             : #endif
    1720                 :             : }
    1721                 :             : 
    1722                 :          17 : libspdm_return_t libspdm_append_message_mut_c(libspdm_context_t *spdm_context, const void *message,
    1723                 :             :                                               size_t message_size)
    1724                 :             : {
    1725                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1726                 :             :     return libspdm_append_managed_buffer(&spdm_context->transcript.message_mut_c,
    1727                 :             :                                          message, message_size);
    1728                 :             : #else
    1729                 :             :     {
    1730                 :             :         bool result;
    1731                 :             : 
    1732         [ +  + ]:          17 :         if (spdm_context->transcript.digest_context_mut_m1m2 == NULL) {
    1733                 :          13 :             spdm_context->transcript.digest_context_mut_m1m2 = libspdm_hash_new (
    1734                 :             :                 spdm_context->connection_info.algorithm.base_hash_algo);
    1735         [ -  + ]:          13 :             if (spdm_context->transcript.digest_context_mut_m1m2 == NULL) {
    1736                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1737                 :             :             }
    1738                 :          13 :             result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    1739                 :             :                                         spdm_context->transcript.digest_context_mut_m1m2);
    1740         [ -  + ]:          13 :             if (!result) {
    1741                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1742                 :             :                                    spdm_context->transcript.digest_context_mut_m1m2);
    1743                 :           0 :                 spdm_context->transcript.digest_context_mut_m1m2 = NULL;
    1744                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1745                 :             :             }
    1746         [ +  + ]:          13 :             if ((spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >
    1747                 :             :                 SPDM_MESSAGE_VERSION_11) {
    1748                 :             : 
    1749                 :             :                 /* Need append VCA since 1.2 script */
    1750                 :           6 :                 result = libspdm_hash_update (
    1751                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo,
    1752                 :             :                     spdm_context->transcript.digest_context_mut_m1m2,
    1753                 :           6 :                     libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
    1754                 :           6 :                     libspdm_get_managed_buffer_size(&spdm_context->transcript.
    1755                 :             :                                                     message_a));
    1756         [ -  + ]:           6 :                 if (!result) {
    1757                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1758                 :             :                                        spdm_context->transcript.digest_context_mut_m1m2);
    1759                 :           0 :                     spdm_context->transcript.digest_context_mut_m1m2 = NULL;
    1760                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    1761                 :             :                 }
    1762                 :             :             }
    1763                 :             :         }
    1764                 :             : 
    1765                 :          17 :         result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    1766                 :             :                                       spdm_context->transcript.digest_context_mut_m1m2, message,
    1767                 :             :                                       message_size);
    1768         [ -  + ]:          17 :         if (!result) {
    1769                 :           0 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1770                 :             :                                spdm_context->transcript.digest_context_mut_m1m2);
    1771                 :           0 :             spdm_context->transcript.digest_context_mut_m1m2 = NULL;
    1772                 :           0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
    1773                 :             :         }
    1774                 :             : 
    1775                 :          17 :         return LIBSPDM_STATUS_SUCCESS;
    1776                 :             :     }
    1777                 :             : #endif
    1778                 :             : }
    1779                 :             : 
    1780                 :         734 : libspdm_return_t libspdm_append_message_m(libspdm_context_t *spdm_context, void *session_info,
    1781                 :             :                                           const void *message, size_t message_size)
    1782                 :             : {
    1783                 :             :     libspdm_session_info_t *spdm_session_info;
    1784                 :             : 
    1785                 :         734 :     spdm_session_info = session_info;
    1786                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1787                 :             :     if (spdm_session_info == NULL) {
    1788                 :             :         return libspdm_append_managed_buffer(&spdm_context->transcript.message_m,
    1789                 :             :                                              message, message_size);
    1790                 :             :     } else {
    1791                 :             :         return libspdm_append_managed_buffer(&spdm_session_info->session_transcript.message_m,
    1792                 :             :                                              message, message_size);
    1793                 :             :     }
    1794                 :             : #else
    1795                 :             :     {
    1796                 :             :         bool result;
    1797                 :             : 
    1798         [ +  + ]:         734 :         if (spdm_session_info == NULL) {
    1799         [ +  + ]:         726 :             if (spdm_context->transcript.digest_context_l1l2 == NULL) {
    1800                 :          66 :                 spdm_context->transcript.digest_context_l1l2 = libspdm_hash_new (
    1801                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo);
    1802         [ -  + ]:          66 :                 if (spdm_context->transcript.digest_context_l1l2 == NULL) {
    1803                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    1804                 :             :                 }
    1805                 :          66 :                 result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    1806                 :             :                                             spdm_context->transcript.digest_context_l1l2);
    1807         [ -  + ]:          66 :                 if (!result) {
    1808                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1809                 :             :                                        spdm_context->transcript.digest_context_l1l2);
    1810                 :           0 :                     spdm_context->transcript.digest_context_l1l2 = NULL;
    1811                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    1812                 :             :                 }
    1813         [ +  + ]:          66 :                 if ((spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >
    1814                 :             :                     SPDM_MESSAGE_VERSION_11) {
    1815                 :             : 
    1816                 :             :                     /* Need append VCA since 1.2 script */
    1817                 :          13 :                     result = libspdm_hash_update (
    1818                 :             :                         spdm_context->connection_info.algorithm.base_hash_algo,
    1819                 :             :                         spdm_context->transcript.digest_context_l1l2,
    1820                 :          13 :                         libspdm_get_managed_buffer(
    1821                 :          13 :                             &spdm_context->transcript.message_a),
    1822                 :          13 :                         libspdm_get_managed_buffer_size(&spdm_context->transcript.
    1823                 :             :                                                         message_a));
    1824         [ -  + ]:          13 :                     if (!result) {
    1825                 :           0 :                         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1826                 :             :                                            spdm_context->transcript.digest_context_l1l2);
    1827                 :           0 :                         spdm_context->transcript.digest_context_l1l2 = NULL;
    1828                 :           0 :                         return LIBSPDM_STATUS_CRYPTO_ERROR;
    1829                 :             :                     }
    1830                 :             :                 }
    1831                 :             :             }
    1832                 :         726 :             result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    1833                 :             :                                           spdm_context->transcript.digest_context_l1l2, message,
    1834                 :             :                                           message_size);
    1835         [ -  + ]:         726 :             if (!result) {
    1836                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1837                 :             :                                    spdm_context->transcript.digest_context_l1l2);
    1838                 :           0 :                 spdm_context->transcript.digest_context_l1l2 = NULL;
    1839                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1840                 :             :             }
    1841                 :             :         } else {
    1842         [ +  + ]:           8 :             if (spdm_session_info->session_transcript.digest_context_l1l2 == NULL) {
    1843                 :           4 :                 spdm_session_info->session_transcript.digest_context_l1l2 = libspdm_hash_new (
    1844                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo);
    1845         [ -  + ]:           4 :                 if (spdm_session_info->session_transcript.digest_context_l1l2 == NULL) {
    1846                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    1847                 :             :                 }
    1848                 :           4 :                 result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    1849                 :             :                                             spdm_session_info->session_transcript.digest_context_l1l2);
    1850         [ -  + ]:           4 :                 if (!result) {
    1851                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1852                 :             :                                        spdm_session_info->session_transcript.digest_context_l1l2);
    1853                 :           0 :                     spdm_session_info->session_transcript.digest_context_l1l2 = NULL;
    1854                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    1855                 :             :                 }
    1856         [ -  + ]:           4 :                 if ((spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >
    1857                 :             :                     SPDM_MESSAGE_VERSION_11) {
    1858                 :             : 
    1859                 :             :                     /* Need append VCA since 1.2 script*/
    1860                 :             : 
    1861                 :           0 :                     result = libspdm_hash_update (
    1862                 :             :                         spdm_context->connection_info.algorithm.base_hash_algo,
    1863                 :             :                         spdm_session_info->session_transcript.digest_context_l1l2,
    1864                 :           0 :                         libspdm_get_managed_buffer(
    1865                 :           0 :                             &spdm_context->transcript.message_a),
    1866                 :           0 :                         libspdm_get_managed_buffer_size(&spdm_context->transcript.
    1867                 :             :                                                         message_a));
    1868         [ #  # ]:           0 :                     if (!result) {
    1869                 :           0 :                         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1870                 :             :                                            spdm_session_info->session_transcript.digest_context_l1l2);
    1871                 :           0 :                         spdm_session_info->session_transcript.digest_context_l1l2 = NULL;
    1872                 :           0 :                         return LIBSPDM_STATUS_CRYPTO_ERROR;
    1873                 :             :                     }
    1874                 :             :                 }
    1875                 :             :             }
    1876                 :           8 :             result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    1877                 :             :                                           spdm_session_info->session_transcript.digest_context_l1l2,
    1878                 :             :                                           message, message_size);
    1879         [ -  + ]:           8 :             if (!result) {
    1880                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1881                 :             :                                    spdm_session_info->session_transcript.digest_context_l1l2);
    1882                 :           0 :                 spdm_session_info->session_transcript.digest_context_l1l2 = NULL;
    1883                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1884                 :             :             }
    1885                 :             :         }
    1886                 :             : 
    1887                 :         734 :         return LIBSPDM_STATUS_SUCCESS;
    1888                 :             :     }
    1889                 :             : #endif
    1890                 :             : }
    1891                 :             : 
    1892                 :         381 : libspdm_return_t libspdm_append_message_k(libspdm_context_t *spdm_context,
    1893                 :             :                                           void *session_info,
    1894                 :             :                                           bool is_requester, const void *message,
    1895                 :             :                                           size_t message_size)
    1896                 :             : {
    1897                 :             :     libspdm_session_info_t *spdm_session_info;
    1898                 :             : 
    1899                 :         381 :     spdm_session_info = session_info;
    1900                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1901                 :             :     return libspdm_append_managed_buffer(
    1902                 :             :         &spdm_session_info->session_transcript.message_k, message,
    1903                 :             :         message_size);
    1904                 :             : #else
    1905                 :             :     {
    1906                 :             :         const uint8_t *cert_chain_buffer;
    1907                 :             :         size_t cert_chain_buffer_size;
    1908                 :             :         bool result;
    1909                 :             :         uint8_t cert_chain_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    1910                 :             :         uint32_t hash_size;
    1911                 :             :         uint8_t slot_id;
    1912                 :             : 
    1913                 :         381 :         hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    1914                 :             : 
    1915         [ +  + ]:         381 :         if (spdm_session_info->session_transcript.digest_context_th == NULL) {
    1916         [ +  + ]:         192 :             if (!spdm_session_info->use_psk) {
    1917         [ +  + ]:         109 :                 if (is_requester) {
    1918                 :          63 :                     slot_id = spdm_session_info->peer_used_cert_chain_slot_id;
    1919   [ +  +  -  + ]:          63 :                     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
    1920         [ +  + ]:          63 :                     if (slot_id == 0xFF) {
    1921                 :           2 :                         result = libspdm_get_peer_public_key_buffer(
    1922                 :             :                             spdm_context, (const void **)&cert_chain_buffer,
    1923                 :             :                             &cert_chain_buffer_size);
    1924         [ -  + ]:           2 :                         if (!result) {
    1925                 :           0 :                             return LIBSPDM_STATUS_INVALID_STATE_PEER;
    1926                 :             :                         }
    1927                 :             : 
    1928                 :           2 :                         result = libspdm_hash_all(
    1929                 :             :                             spdm_context->connection_info.algorithm.base_hash_algo,
    1930                 :             :                             cert_chain_buffer, cert_chain_buffer_size,
    1931                 :             :                             cert_chain_buffer_hash);
    1932         [ -  + ]:           2 :                         if (!result) {
    1933                 :           0 :                             return LIBSPDM_STATUS_CRYPTO_ERROR;
    1934                 :             :                         }
    1935                 :             :                     } else {
    1936         [ -  + ]:          61 :                         LIBSPDM_ASSERT(
    1937                 :             :                             hash_size ==
    1938                 :             :                             spdm_context->connection_info
    1939                 :             :                             .peer_used_cert_chain[slot_id].buffer_hash_size);
    1940                 :             : 
    1941                 :          61 :                         libspdm_copy_mem(cert_chain_buffer_hash,
    1942                 :             :                                          sizeof(cert_chain_buffer_hash),
    1943                 :             :                                          spdm_context->connection_info
    1944                 :          61 :                                          .peer_used_cert_chain[slot_id].buffer_hash,
    1945                 :             :                                          hash_size);
    1946                 :             :                     }
    1947                 :             :                 } else {
    1948                 :          46 :                     slot_id = spdm_session_info->local_used_cert_chain_slot_id;
    1949   [ +  +  -  + ]:          46 :                     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
    1950         [ +  + ]:          46 :                     if (slot_id == 0xFF) {
    1951                 :           2 :                         result = libspdm_get_local_public_key_buffer(
    1952                 :             :                             spdm_context, (const void **)&cert_chain_buffer,
    1953                 :             :                             &cert_chain_buffer_size);
    1954         [ -  + ]:           2 :                         if (!result) {
    1955                 :           0 :                             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
    1956                 :             :                         }
    1957                 :             :                     } else {
    1958                 :          44 :                         libspdm_get_local_cert_chain_buffer(
    1959                 :             :                             spdm_context, slot_id, (const void **)&cert_chain_buffer,
    1960                 :             :                             &cert_chain_buffer_size);
    1961                 :             :                     }
    1962                 :             : 
    1963                 :          46 :                     result = libspdm_hash_all(
    1964                 :             :                         spdm_context->connection_info.algorithm.base_hash_algo,
    1965                 :             :                         cert_chain_buffer, cert_chain_buffer_size,
    1966                 :             :                         cert_chain_buffer_hash);
    1967         [ -  + ]:          46 :                     if (!result) {
    1968                 :           0 :                         return LIBSPDM_STATUS_CRYPTO_ERROR;
    1969                 :             :                     }
    1970                 :             :                 }
    1971                 :             :             }
    1972                 :             :         }
    1973                 :             : 
    1974                 :             : 
    1975                 :             :         /* prepare digest_context_th*/
    1976                 :             : 
    1977         [ +  + ]:         381 :         if (spdm_session_info->session_transcript.digest_context_th == NULL) {
    1978                 :         192 :             spdm_session_info->session_transcript.digest_context_th = libspdm_hash_new (
    1979                 :             :                 spdm_context->connection_info.algorithm.base_hash_algo);
    1980         [ -  + ]:         192 :             if (spdm_session_info->session_transcript.digest_context_th == NULL) {
    1981                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1982                 :             :             }
    1983                 :         192 :             result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    1984                 :             :                                         spdm_session_info->session_transcript.digest_context_th);
    1985         [ -  + ]:         192 :             if (!result) {
    1986                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1987                 :             :                                    spdm_session_info->session_transcript.digest_context_th);
    1988                 :           0 :                 spdm_session_info->session_transcript.digest_context_th = NULL;
    1989                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    1990                 :             :             }
    1991                 :         192 :             result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    1992                 :             :                                           spdm_session_info->session_transcript.digest_context_th,
    1993                 :         192 :                                           libspdm_get_managed_buffer(&spdm_context->transcript.
    1994                 :             :                                                                      message_a),
    1995                 :             :                                           libspdm_get_managed_buffer_size(
    1996                 :         192 :                                               &spdm_context->transcript.message_a));
    1997         [ -  + ]:         192 :             if (!result) {
    1998                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    1999                 :             :                                    spdm_session_info->session_transcript.digest_context_th);
    2000                 :           0 :                 spdm_session_info->session_transcript.digest_context_th = NULL;
    2001                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    2002                 :             :             }
    2003         [ +  + ]:         192 :             if (!spdm_session_info->use_psk) {
    2004         [ -  + ]:         109 :                 if (spdm_context->connection_info.multi_key_conn_rsp) {
    2005                 :           0 :                     result = libspdm_hash_update (
    2006                 :             :                         spdm_context->connection_info.algorithm.base_hash_algo,
    2007                 :             :                         spdm_session_info->session_transcript.digest_context_th,
    2008                 :           0 :                         libspdm_get_managed_buffer(&spdm_context->transcript.message_d),
    2009                 :           0 :                         libspdm_get_managed_buffer_size(&spdm_context->transcript.message_d));
    2010         [ #  # ]:           0 :                     if (!result) {
    2011                 :           0 :                         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2012                 :             :                                            spdm_session_info->session_transcript.digest_context_th);
    2013                 :           0 :                         spdm_session_info->session_transcript.digest_context_th = NULL;
    2014                 :           0 :                         return LIBSPDM_STATUS_CRYPTO_ERROR;
    2015                 :             :                     }
    2016                 :             :                 }
    2017                 :             : 
    2018                 :         109 :                 result = libspdm_hash_update (
    2019                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo,
    2020                 :             :                     spdm_session_info->session_transcript.digest_context_th,
    2021                 :             :                     cert_chain_buffer_hash, hash_size);
    2022         [ -  + ]:         109 :                 if (!result) {
    2023                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2024                 :             :                                        spdm_session_info->session_transcript.digest_context_th);
    2025                 :           0 :                     spdm_session_info->session_transcript.digest_context_th = NULL;
    2026                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2027                 :             :                 }
    2028                 :             :             }
    2029                 :             :         }
    2030                 :         381 :         result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    2031                 :             :                                       spdm_session_info->session_transcript.digest_context_th,
    2032                 :             :                                       message,
    2033                 :             :                                       message_size);
    2034         [ -  + ]:         381 :         if (!result) {
    2035                 :           0 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2036                 :             :                                spdm_session_info->session_transcript.digest_context_th);
    2037                 :           0 :             spdm_session_info->session_transcript.digest_context_th = NULL;
    2038                 :           0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
    2039                 :             :         }
    2040                 :         381 :         return LIBSPDM_STATUS_SUCCESS;
    2041                 :             :     }
    2042                 :             : #endif
    2043                 :             : }
    2044                 :             : 
    2045                 :           6 : libspdm_return_t libspdm_append_message_encap_d(void *session_info,
    2046                 :             :                                                 const void *message,
    2047                 :             :                                                 size_t message_size)
    2048                 :             : {
    2049                 :             :     libspdm_session_info_t *spdm_session_info;
    2050                 :             : 
    2051                 :           6 :     spdm_session_info = session_info;
    2052                 :             :     /* Window closed: the encapsulated DIGESTS is not the first encap response, so it is not added. */
    2053         [ +  + ]:           6 :     if (spdm_session_info->session_transcript.encap_digest_window_closed) {
    2054                 :           1 :         return LIBSPDM_STATUS_SUCCESS;
    2055                 :             :     }
    2056                 :             :     /* Only the first message EncapD in current session counts  */
    2057         [ -  + ]:           5 :     if (libspdm_get_managed_buffer_size(&spdm_session_info->session_transcript.message_encap_d) !=
    2058                 :             :         0) {
    2059                 :           0 :         return LIBSPDM_STATUS_SUCCESS;
    2060                 :             :     }
    2061                 :           5 :     return libspdm_append_managed_buffer(
    2062                 :           5 :         &spdm_session_info->session_transcript.message_encap_d, message,
    2063                 :             :         message_size);
    2064                 :             : }
    2065                 :             : 
    2066                 :         314 : libspdm_return_t libspdm_append_message_f(libspdm_context_t *spdm_context,
    2067                 :             :                                           void *session_info,
    2068                 :             :                                           bool is_requester, const void *message,
    2069                 :             :                                           size_t message_size)
    2070                 :             : {
    2071                 :             :     libspdm_session_info_t *spdm_session_info;
    2072                 :             : 
    2073                 :         314 :     spdm_session_info = session_info;
    2074                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2075                 :             :     return libspdm_append_managed_buffer(
    2076                 :             :         &spdm_session_info->session_transcript.message_f, message,
    2077                 :             :         message_size);
    2078                 :             : #else
    2079                 :             :     {
    2080                 :             :         const uint8_t *mut_cert_chain_buffer;
    2081                 :             :         size_t mut_cert_chain_buffer_size;
    2082                 :             :         bool result;
    2083                 :             :         uint8_t mut_cert_chain_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
    2084                 :             :         uint32_t hash_size;
    2085                 :             :         libspdm_return_t status;
    2086                 :             :         uint8_t slot_id;
    2087                 :             : 
    2088                 :         314 :         hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
    2089                 :             : 
    2090         [ +  + ]:         314 :         if (!spdm_session_info->session_transcript.message_f_initialized) {
    2091                 :             :             /* digest_context_th might be NULL in unit test, where message_k is hardcoded. */
    2092         [ +  + ]:         117 :             if (spdm_session_info->session_transcript.digest_context_th == NULL) {
    2093                 :             :                 status =
    2094                 :         114 :                     libspdm_append_message_k (spdm_context, session_info, is_requester, NULL, 0);
    2095         [ -  + ]:         114 :                 if (LIBSPDM_STATUS_IS_ERROR(status)) {
    2096                 :           0 :                     return status;
    2097                 :             :                 }
    2098                 :             :             }
    2099                 :             : 
    2100   [ +  +  +  + ]:         117 :             if (!spdm_session_info->use_psk && (spdm_session_info->mut_auth_requested != 0)) {
    2101         [ +  + ]:          19 :                 if (is_requester) {
    2102                 :           6 :                     slot_id = spdm_session_info->local_used_cert_chain_slot_id;
    2103   [ -  +  -  - ]:           6 :                     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
    2104         [ -  + ]:           6 :                     if (slot_id == 0xFF) {
    2105                 :           0 :                         result = libspdm_get_local_public_key_buffer(
    2106                 :             :                             spdm_context,
    2107                 :             :                             (const void **)&mut_cert_chain_buffer,
    2108                 :             :                             &mut_cert_chain_buffer_size);
    2109         [ #  # ]:           0 :                         if (!result) {
    2110                 :           0 :                             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
    2111                 :             :                         }
    2112                 :             :                     } else {
    2113                 :           6 :                         libspdm_get_local_cert_chain_buffer(
    2114                 :             :                             spdm_context,
    2115                 :             :                             slot_id,
    2116                 :             :                             (const void **)&mut_cert_chain_buffer,
    2117                 :             :                             &mut_cert_chain_buffer_size);
    2118                 :             :                     }
    2119                 :             : 
    2120                 :           6 :                     result = libspdm_hash_all(
    2121                 :             :                         spdm_context->connection_info.algorithm.base_hash_algo,
    2122                 :             :                         mut_cert_chain_buffer, mut_cert_chain_buffer_size,
    2123                 :             :                         mut_cert_chain_buffer_hash);
    2124         [ -  + ]:           6 :                     if (!result) {
    2125                 :           0 :                         return LIBSPDM_STATUS_CRYPTO_ERROR;
    2126                 :             :                     }
    2127                 :             :                 } else {
    2128                 :          13 :                     slot_id = spdm_session_info->peer_used_cert_chain_slot_id;
    2129   [ +  +  -  + ]:          13 :                     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xFF));
    2130         [ +  + ]:          13 :                     if (slot_id == 0xFF) {
    2131                 :           1 :                         result = libspdm_get_peer_public_key_buffer(
    2132                 :             :                             spdm_context,
    2133                 :             :                             (const void **)&mut_cert_chain_buffer,
    2134                 :             :                             &mut_cert_chain_buffer_size);
    2135         [ -  + ]:           1 :                         if (!result) {
    2136                 :           0 :                             return LIBSPDM_STATUS_INVALID_STATE_PEER;
    2137                 :             :                         }
    2138                 :             : 
    2139                 :           1 :                         result = libspdm_hash_all(
    2140                 :             :                             spdm_context->connection_info.algorithm.base_hash_algo,
    2141                 :             :                             mut_cert_chain_buffer, mut_cert_chain_buffer_size,
    2142                 :             :                             mut_cert_chain_buffer_hash);
    2143         [ -  + ]:           1 :                         if (!result) {
    2144                 :           0 :                             return LIBSPDM_STATUS_CRYPTO_ERROR;
    2145                 :             :                         }
    2146                 :             :                     } else {
    2147         [ -  + ]:          12 :                         LIBSPDM_ASSERT(
    2148                 :             :                             hash_size ==
    2149                 :             :                             spdm_context->connection_info
    2150                 :             :                             .peer_used_cert_chain[slot_id].buffer_hash_size);
    2151                 :             : 
    2152                 :          12 :                         libspdm_copy_mem(mut_cert_chain_buffer_hash,
    2153                 :             :                                          sizeof(mut_cert_chain_buffer_hash),
    2154                 :             :                                          spdm_context->connection_info
    2155                 :          12 :                                          .peer_used_cert_chain[slot_id].buffer_hash,
    2156                 :             :                                          hash_size);
    2157                 :             :                     }
    2158                 :             :                 }
    2159                 :             :             }
    2160                 :             : 
    2161                 :             :             /* It is first time call, backup current message_k context
    2162                 :             :              * this backup will be used in reset_message_f.*/
    2163                 :             : 
    2164         [ -  + ]:         117 :             LIBSPDM_ASSERT (spdm_session_info->session_transcript.digest_context_th != NULL);
    2165                 :         117 :             spdm_session_info->session_transcript.digest_context_th_backup = libspdm_hash_new (
    2166                 :             :                 spdm_context->connection_info.algorithm.base_hash_algo);
    2167         [ -  + ]:         117 :             if (spdm_session_info->session_transcript.digest_context_th_backup == NULL) {
    2168                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    2169                 :             :             }
    2170                 :         117 :             result = libspdm_hash_duplicate (spdm_context->connection_info.algorithm.base_hash_algo,
    2171                 :         117 :                                              spdm_session_info->session_transcript.digest_context_th,
    2172                 :             :                                              spdm_session_info->session_transcript.digest_context_th_backup);
    2173         [ -  + ]:         117 :             if (!result) {
    2174                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2175                 :             :                                    spdm_session_info->session_transcript.digest_context_th_backup);
    2176                 :           0 :                 spdm_session_info->session_transcript.digest_context_th_backup = NULL;
    2177                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    2178                 :             :             }
    2179                 :             :         }
    2180                 :             : 
    2181                 :             : 
    2182                 :             :         /* prepare digest_context_th*/
    2183                 :             : 
    2184         [ -  + ]:         314 :         LIBSPDM_ASSERT (spdm_session_info->session_transcript.digest_context_th != NULL);
    2185         [ +  + ]:         314 :         if (!spdm_session_info->session_transcript.message_f_initialized) {
    2186   [ +  +  +  + ]:         117 :             if (!spdm_session_info->use_psk && (spdm_session_info->mut_auth_requested != 0)) {
    2187         [ -  + ]:          19 :                 if (spdm_context->connection_info.multi_key_conn_req) {
    2188                 :           0 :                     result = libspdm_hash_update (
    2189                 :             :                         spdm_context->connection_info.algorithm.base_hash_algo,
    2190                 :             :                         spdm_session_info->session_transcript.digest_context_th,
    2191                 :           0 :                         libspdm_get_managed_buffer(&spdm_session_info->session_transcript.
    2192                 :             :                                                    message_encap_d),
    2193                 :           0 :                         libspdm_get_managed_buffer_size(&spdm_session_info->session_transcript.
    2194                 :             :                                                         message_encap_d));
    2195         [ #  # ]:           0 :                     if (!result) {
    2196                 :           0 :                         libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2197                 :             :                                            spdm_session_info->session_transcript.digest_context_th);
    2198                 :           0 :                         spdm_session_info->session_transcript.digest_context_th = NULL;
    2199                 :           0 :                         return LIBSPDM_STATUS_CRYPTO_ERROR;
    2200                 :             :                     }
    2201                 :             :                 }
    2202                 :             : 
    2203                 :          19 :                 result = libspdm_hash_update (
    2204                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo,
    2205                 :             :                     spdm_session_info->session_transcript.digest_context_th,
    2206                 :             :                     mut_cert_chain_buffer_hash, hash_size);
    2207         [ -  + ]:          19 :                 if (!result) {
    2208                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2209                 :             :                                        spdm_session_info->session_transcript.digest_context_th);
    2210                 :           0 :                     spdm_session_info->session_transcript.digest_context_th = NULL;
    2211                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2212                 :             :                 }
    2213                 :             :             }
    2214                 :             :         }
    2215                 :         314 :         result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    2216                 :             :                                       spdm_session_info->session_transcript.digest_context_th,
    2217                 :             :                                       message,
    2218                 :             :                                       message_size);
    2219         [ -  + ]:         314 :         if (!result) {
    2220                 :           0 :             libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2221                 :             :                                spdm_session_info->session_transcript.digest_context_th);
    2222                 :           0 :             spdm_session_info->session_transcript.digest_context_th = NULL;
    2223                 :           0 :             return LIBSPDM_STATUS_CRYPTO_ERROR;
    2224                 :             :         }
    2225                 :             : 
    2226                 :         314 :         spdm_session_info->session_transcript.message_f_initialized = true;
    2227                 :         314 :         return LIBSPDM_STATUS_SUCCESS;
    2228                 :             :     }
    2229                 :             : #endif
    2230                 :             : }
    2231                 :             : 
    2232                 :          34 : libspdm_return_t libspdm_append_message_e(libspdm_context_t *spdm_context, void *session_info,
    2233                 :             :                                           const void *message, size_t message_size)
    2234                 :             : {
    2235                 :             :     libspdm_session_info_t *spdm_session_info;
    2236                 :             : 
    2237                 :          34 :     spdm_session_info = session_info;
    2238                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2239                 :             :     if (spdm_session_info == NULL) {
    2240                 :             :         return libspdm_append_managed_buffer(&spdm_context->transcript.message_e,
    2241                 :             :                                              message, message_size);
    2242                 :             :     } else {
    2243                 :             :         return libspdm_append_managed_buffer(&spdm_session_info->session_transcript.message_e,
    2244                 :             :                                              message, message_size);
    2245                 :             :     }
    2246                 :             : #else
    2247                 :             :     {
    2248                 :             :         bool result;
    2249                 :             : 
    2250         [ +  + ]:          34 :         if (spdm_session_info == NULL) {
    2251         [ +  + ]:          28 :             if (spdm_context->transcript.digest_context_il1il2 == NULL) {
    2252                 :          14 :                 spdm_context->transcript.digest_context_il1il2 = libspdm_hash_new (
    2253                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo);
    2254         [ -  + ]:          14 :                 if (spdm_context->transcript.digest_context_il1il2 == NULL) {
    2255                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2256                 :             :                 }
    2257                 :          14 :                 result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    2258                 :             :                                             spdm_context->transcript.digest_context_il1il2);
    2259         [ -  + ]:          14 :                 if (!result) {
    2260                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2261                 :             :                                        spdm_context->transcript.digest_context_il1il2);
    2262                 :           0 :                     spdm_context->transcript.digest_context_il1il2 = NULL;
    2263                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2264                 :             :                 }
    2265                 :             : 
    2266                 :          14 :                 result = libspdm_hash_update (
    2267                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo,
    2268                 :             :                     spdm_context->transcript.digest_context_il1il2,
    2269                 :          14 :                     libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
    2270                 :          14 :                     libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
    2271                 :             : 
    2272         [ -  + ]:          14 :                 if (!result) {
    2273                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2274                 :             :                                        spdm_context->transcript.digest_context_il1il2);
    2275                 :           0 :                     spdm_context->transcript.digest_context_il1il2 = NULL;
    2276                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2277                 :             :                 }
    2278                 :             :             }
    2279                 :          28 :             result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    2280                 :             :                                           spdm_context->transcript.digest_context_il1il2, message,
    2281                 :             :                                           message_size);
    2282         [ -  + ]:          28 :             if (!result) {
    2283                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2284                 :             :                                    spdm_context->transcript.digest_context_il1il2);
    2285                 :           0 :                 spdm_context->transcript.digest_context_il1il2 = NULL;
    2286                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    2287                 :             :             }
    2288                 :             :         } else {
    2289         [ +  + ]:           6 :             if (spdm_session_info->session_transcript.digest_context_il1il2 == NULL) {
    2290                 :           3 :                 spdm_session_info->session_transcript.digest_context_il1il2 = libspdm_hash_new (
    2291                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo);
    2292         [ -  + ]:           3 :                 if (spdm_session_info->session_transcript.digest_context_il1il2 == NULL) {
    2293                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2294                 :             :                 }
    2295                 :           3 :                 result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    2296                 :             :                                             spdm_session_info->session_transcript.digest_context_il1il2);
    2297         [ -  + ]:           3 :                 if (!result) {
    2298                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2299                 :             :                                        spdm_session_info->session_transcript.digest_context_il1il2);
    2300                 :           0 :                     spdm_session_info->session_transcript.digest_context_il1il2 = NULL;
    2301                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2302                 :             :                 }
    2303                 :             : 
    2304                 :           3 :                 result = libspdm_hash_update (
    2305                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo,
    2306                 :             :                     spdm_session_info->session_transcript.digest_context_il1il2,
    2307                 :           3 :                     libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
    2308                 :           3 :                     libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
    2309                 :             : 
    2310         [ -  + ]:           3 :                 if (!result) {
    2311                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2312                 :             :                                        spdm_session_info->session_transcript.digest_context_il1il2);
    2313                 :           0 :                     spdm_session_info->session_transcript.digest_context_il1il2 = NULL;
    2314                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2315                 :             :                 }
    2316                 :             :             }
    2317                 :           6 :             result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    2318                 :             :                                           spdm_session_info->session_transcript.digest_context_il1il2,
    2319                 :             :                                           message, message_size);
    2320         [ -  + ]:           6 :             if (!result) {
    2321                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2322                 :             :                                    spdm_session_info->session_transcript.digest_context_il1il2);
    2323                 :           0 :                 spdm_session_info->session_transcript.digest_context_il1il2 = NULL;
    2324                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    2325                 :             :             }
    2326                 :             :         }
    2327                 :             : 
    2328                 :          34 :         return LIBSPDM_STATUS_SUCCESS;
    2329                 :             :     }
    2330                 :             : #endif
    2331                 :             : }
    2332                 :             : 
    2333                 :          26 : libspdm_return_t libspdm_append_message_encap_e(libspdm_context_t *spdm_context, void *session_info,
    2334                 :             :                                                 const void *message, size_t message_size)
    2335                 :             : {
    2336                 :             :     libspdm_session_info_t *spdm_session_info;
    2337                 :             : 
    2338                 :          26 :     spdm_session_info = session_info;
    2339                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2340                 :             :     if (spdm_session_info == NULL) {
    2341                 :             :         return libspdm_append_managed_buffer(&spdm_context->transcript.message_encap_e,
    2342                 :             :                                              message, message_size);
    2343                 :             :     } else {
    2344                 :             :         return libspdm_append_managed_buffer(&spdm_session_info->session_transcript.message_encap_e,
    2345                 :             :                                              message, message_size);
    2346                 :             :     }
    2347                 :             : #else
    2348                 :             :     {
    2349                 :             :         bool result;
    2350                 :             : 
    2351         [ +  + ]:          26 :         if (spdm_session_info == NULL) {
    2352         [ +  + ]:          21 :             if (spdm_context->transcript.digest_context_encap_il1il2 == NULL) {
    2353                 :          14 :                 spdm_context->transcript.digest_context_encap_il1il2 = libspdm_hash_new (
    2354                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo);
    2355         [ -  + ]:          14 :                 if (spdm_context->transcript.digest_context_encap_il1il2 == NULL) {
    2356                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2357                 :             :                 }
    2358                 :          14 :                 result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    2359                 :             :                                             spdm_context->transcript.digest_context_encap_il1il2);
    2360         [ -  + ]:          14 :                 if (!result) {
    2361                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2362                 :             :                                        spdm_context->transcript.digest_context_encap_il1il2);
    2363                 :           0 :                     spdm_context->transcript.digest_context_encap_il1il2 = NULL;
    2364                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2365                 :             :                 }
    2366                 :             : 
    2367                 :          14 :                 result = libspdm_hash_update (
    2368                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo,
    2369                 :             :                     spdm_context->transcript.digest_context_encap_il1il2,
    2370                 :          14 :                     libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
    2371                 :          14 :                     libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
    2372                 :             : 
    2373         [ -  + ]:          14 :                 if (!result) {
    2374                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2375                 :             :                                        spdm_context->transcript.digest_context_encap_il1il2);
    2376                 :           0 :                     spdm_context->transcript.digest_context_encap_il1il2 = NULL;
    2377                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2378                 :             :                 }
    2379                 :             :             }
    2380                 :          21 :             result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    2381                 :             :                                           spdm_context->transcript.digest_context_encap_il1il2,
    2382                 :             :                                           message,
    2383                 :             :                                           message_size);
    2384         [ -  + ]:          21 :             if (!result) {
    2385                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2386                 :             :                                    spdm_context->transcript.digest_context_encap_il1il2);
    2387                 :           0 :                 spdm_context->transcript.digest_context_encap_il1il2 = NULL;
    2388                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    2389                 :             :             }
    2390                 :             :         } else {
    2391         [ +  + ]:           5 :             if (spdm_session_info->session_transcript.digest_context_encap_il1il2 == NULL) {
    2392                 :           3 :                 spdm_session_info->session_transcript.digest_context_encap_il1il2 =
    2393                 :           3 :                     libspdm_hash_new (spdm_context->connection_info.algorithm.base_hash_algo);
    2394         [ -  + ]:           3 :                 if (spdm_session_info->session_transcript.digest_context_encap_il1il2 == NULL) {
    2395                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2396                 :             :                 }
    2397                 :           3 :                 result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
    2398                 :             :                                             spdm_session_info->session_transcript.digest_context_encap_il1il2);
    2399         [ -  + ]:           3 :                 if (!result) {
    2400                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2401                 :             :                                        spdm_session_info->session_transcript.digest_context_encap_il1il2);
    2402                 :           0 :                     spdm_session_info->session_transcript.digest_context_encap_il1il2 = NULL;
    2403                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2404                 :             :                 }
    2405                 :             : 
    2406                 :           3 :                 result = libspdm_hash_update (
    2407                 :             :                     spdm_context->connection_info.algorithm.base_hash_algo,
    2408                 :             :                     spdm_session_info->session_transcript.digest_context_encap_il1il2,
    2409                 :           3 :                     libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
    2410                 :           3 :                     libspdm_get_managed_buffer_size(&spdm_context->transcript.message_a));
    2411                 :             : 
    2412         [ -  + ]:           3 :                 if (!result) {
    2413                 :           0 :                     libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2414                 :             :                                        spdm_session_info->session_transcript.digest_context_encap_il1il2);
    2415                 :           0 :                     spdm_session_info->session_transcript.digest_context_encap_il1il2 = NULL;
    2416                 :           0 :                     return LIBSPDM_STATUS_CRYPTO_ERROR;
    2417                 :             :                 }
    2418                 :             :             }
    2419                 :           5 :             result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
    2420                 :             :                                           spdm_session_info->session_transcript.digest_context_encap_il1il2,
    2421                 :             :                                           message, message_size);
    2422         [ -  + ]:           5 :             if (!result) {
    2423                 :           0 :                 libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
    2424                 :             :                                    spdm_session_info->session_transcript.digest_context_encap_il1il2);
    2425                 :           0 :                 spdm_session_info->session_transcript.digest_context_encap_il1il2 = NULL;
    2426                 :           0 :                 return LIBSPDM_STATUS_CRYPTO_ERROR;
    2427                 :             :             }
    2428                 :             :         }
    2429                 :             : 
    2430                 :          26 :         return LIBSPDM_STATUS_SUCCESS;
    2431                 :             :     }
    2432                 :             : #endif
    2433                 :             : }
    2434                 :           0 : bool libspdm_is_version_supported(const libspdm_context_t *spdm_context, uint8_t version)
    2435                 :             : {
    2436         [ #  # ]:           0 :     if (version == (spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT)) {
    2437                 :           0 :         return true;
    2438                 :             :     }
    2439                 :             : 
    2440                 :           0 :     return false;
    2441                 :             : }
    2442                 :             : 
    2443                 :      276448 : uint8_t libspdm_get_connection_version(const libspdm_context_t *spdm_context)
    2444                 :             : {
    2445                 :      276448 :     return (uint8_t)(spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT);
    2446                 :             : }
    2447                 :             : 
    2448                 :       80467 : bool libspdm_is_capabilities_flag_supported(const libspdm_context_t *spdm_context,
    2449                 :             :                                             bool is_requester,
    2450                 :             :                                             uint32_t requester_capabilities_flag,
    2451                 :             :                                             uint32_t responder_capabilities_flag)
    2452                 :             : {
    2453                 :             :     uint32_t negotiated_requester_capabilities_flag;
    2454                 :             :     uint32_t negotiated_responder_capabilities_flag;
    2455                 :             : 
    2456         [ +  + ]:       80467 :     if (is_requester) {
    2457                 :       74964 :         negotiated_requester_capabilities_flag = spdm_context->local_context.capability.flags;
    2458                 :       74964 :         negotiated_responder_capabilities_flag = spdm_context->connection_info.capability.flags;
    2459                 :             :     } else {
    2460                 :        5503 :         negotiated_requester_capabilities_flag = spdm_context->connection_info.capability.flags;
    2461                 :        5503 :         negotiated_responder_capabilities_flag = spdm_context->local_context.capability.flags;
    2462                 :             :     }
    2463                 :             : 
    2464         [ +  + ]:       80467 :     if (((requester_capabilities_flag == 0) ||
    2465         [ +  + ]:       76055 :          ((negotiated_requester_capabilities_flag &
    2466         [ +  + ]:       73147 :            requester_capabilities_flag) != 0)) &&
    2467                 :       71484 :         ((responder_capabilities_flag == 0) ||
    2468         [ +  + ]:       71484 :          ((negotiated_responder_capabilities_flag &
    2469                 :             :            responder_capabilities_flag) != 0))) {
    2470                 :       71888 :         return true;
    2471                 :             :     } else {
    2472                 :        8579 :         return false;
    2473                 :             :     }
    2474                 :             : }
    2475                 :             : 
    2476                 :           0 : bool libspdm_is_capabilities_ext_flag_supported(const libspdm_context_t *spdm_context,
    2477                 :             :                                                 bool is_requester,
    2478                 :             :                                                 uint16_t requester_capabilities_ext_flag,
    2479                 :             :                                                 uint16_t responder_capabilities_ext_flag)
    2480                 :             : {
    2481                 :             :     uint16_t negotiated_requester_capabilities_ext_flag;
    2482                 :             :     uint16_t negotiated_responder_capabilities_ext_flag;
    2483                 :             : 
    2484         [ #  # ]:           0 :     if (is_requester) {
    2485                 :           0 :         negotiated_requester_capabilities_ext_flag = spdm_context->local_context.capability.ext_flags;
    2486                 :           0 :         negotiated_responder_capabilities_ext_flag = spdm_context->connection_info.capability.ext_flags;
    2487                 :             :     } else {
    2488                 :           0 :         negotiated_requester_capabilities_ext_flag = spdm_context->connection_info.capability.ext_flags;
    2489                 :           0 :         negotiated_responder_capabilities_ext_flag = spdm_context->local_context.capability.ext_flags;
    2490                 :             :     }
    2491                 :             : 
    2492         [ #  # ]:           0 :     if (((requester_capabilities_ext_flag == 0) ||
    2493                 :             :          ((negotiated_requester_capabilities_ext_flag &
    2494   [ #  #  #  # ]:           0 :            requester_capabilities_ext_flag) != 0)) &&
    2495                 :           0 :         ((responder_capabilities_ext_flag == 0) ||
    2496                 :             :          ((negotiated_responder_capabilities_ext_flag &
    2497         [ #  # ]:           0 :            responder_capabilities_ext_flag) != 0))) {
    2498                 :           0 :         return true;
    2499                 :             :     } else {
    2500                 :           0 :         return false;
    2501                 :             :     }
    2502                 :             : }
    2503                 :             : 
    2504                 :         136 : bool libspdm_is_encap_supported(const libspdm_context_t *spdm_context)
    2505                 :             : {
    2506         [ -  + ]:         136 :     if (libspdm_get_connection_version(spdm_context) == SPDM_MESSAGE_VERSION_10) {
    2507                 :           0 :         return false;
    2508         [ +  + ]:         136 :     } else if (libspdm_get_connection_version(spdm_context) == SPDM_MESSAGE_VERSION_12) {
    2509                 :             :         /* ENCAP_CAP was erroneously deprecated in SPDM 1.2.0 and 1.2.1, and MUT_AUTH_CAP
    2510                 :             :          * was used in its place. In SPDM 1.2.2 and later ENCAP_CAP is undeprecated. Since
    2511                 :             :          * UpdateVersionNumber must be ignored when checking interoperability libspdm will check
    2512                 :             :          * if ENCAP_CAP or MUT_AUTH_CAP is set. */
    2513                 :          18 :         const bool is_req_encap_cap_supported = libspdm_is_capabilities_flag_supported(
    2514                 :          18 :             spdm_context, spdm_context->local_context.is_requester,
    2515                 :             :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP, 0);
    2516                 :          18 :         const bool is_req_mut_auth_cap_supported = libspdm_is_capabilities_flag_supported(
    2517                 :          18 :             spdm_context, spdm_context->local_context.is_requester,
    2518                 :             :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP, 0);
    2519                 :          18 :         const bool is_rsp_encap_cap_supported = libspdm_is_capabilities_flag_supported(
    2520                 :          18 :             spdm_context, spdm_context->local_context.is_requester,
    2521                 :             :             0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP);
    2522                 :          18 :         const bool is_rsp_mut_auth_cap_supported = libspdm_is_capabilities_flag_supported(
    2523                 :          18 :             spdm_context, spdm_context->local_context.is_requester,
    2524                 :             :             0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP);
    2525                 :             : 
    2526   [ -  +  -  -  :          18 :         return ((is_req_encap_cap_supported || is_req_mut_auth_cap_supported) &&
                   -  + ]
    2527         [ #  # ]:           0 :                 (is_rsp_encap_cap_supported || is_rsp_mut_auth_cap_supported));
    2528                 :             :     } else {
    2529                 :             :         /* For SPDM 1.1 and 1.3 and later only check ENCAP_CAP. */
    2530                 :         118 :         return libspdm_is_capabilities_flag_supported(
    2531                 :         118 :             spdm_context, spdm_context->local_context.is_requester,
    2532                 :             :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP,
    2533                 :             :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP);
    2534                 :             :     }
    2535                 :             : }
    2536                 :             : 
    2537                 :         308 : void libspdm_register_device_io_func(
    2538                 :             :     void *spdm_context, libspdm_device_send_message_func send_message,
    2539                 :             :     libspdm_device_receive_message_func receive_message)
    2540                 :             : {
    2541                 :             :     libspdm_context_t *context;
    2542                 :             : 
    2543                 :         308 :     context = spdm_context;
    2544                 :         308 :     context->send_message = send_message;
    2545                 :         308 :     context->receive_message = receive_message;
    2546                 :         308 : }
    2547                 :             : 
    2548                 :         309 : void libspdm_register_device_buffer_func(
    2549                 :             :     void *spdm_context,
    2550                 :             :     uint32_t sender_buffer_size,
    2551                 :             :     uint32_t receiver_buffer_size,
    2552                 :             :     libspdm_device_acquire_sender_buffer_func acquire_sender_buffer,
    2553                 :             :     libspdm_device_release_sender_buffer_func release_sender_buffer,
    2554                 :             :     libspdm_device_acquire_receiver_buffer_func acquire_receiver_buffer,
    2555                 :             :     libspdm_device_release_receiver_buffer_func release_receiver_buffer)
    2556                 :             : {
    2557                 :             :     libspdm_context_t *context;
    2558                 :             : 
    2559                 :         309 :     context = spdm_context;
    2560                 :         309 :     context->sender_buffer_size = sender_buffer_size;
    2561                 :         309 :     context->receiver_buffer_size = receiver_buffer_size;
    2562                 :         309 :     context->acquire_sender_buffer = acquire_sender_buffer;
    2563                 :         309 :     context->release_sender_buffer = release_sender_buffer;
    2564                 :         309 :     context->acquire_receiver_buffer = acquire_receiver_buffer;
    2565                 :         309 :     context->release_receiver_buffer = release_receiver_buffer;
    2566                 :             : 
    2567         [ -  + ]:         309 :     LIBSPDM_ASSERT (sender_buffer_size >=
    2568                 :             :                     context->local_context.capability.transport_header_size +
    2569                 :             :                     context->local_context.capability.transport_tail_size);
    2570                 :         309 :     sender_buffer_size -= (context->local_context.capability.transport_header_size +
    2571                 :         309 :                            context->local_context.capability.transport_tail_size);
    2572         [ -  + ]:         309 :     LIBSPDM_ASSERT (sender_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
    2573                 :         309 :     context->local_context.capability.sender_data_transfer_size = sender_buffer_size;
    2574                 :             : 
    2575         [ -  + ]:         309 :     LIBSPDM_ASSERT(receiver_buffer_size >=
    2576                 :             :                    context->local_context.capability.transport_header_size +
    2577                 :             :                    context->local_context.capability.transport_tail_size);
    2578                 :         309 :     receiver_buffer_size -= (context->local_context.capability.transport_header_size +
    2579                 :         309 :                              context->local_context.capability.transport_tail_size);
    2580         [ -  + ]:         309 :     LIBSPDM_ASSERT (receiver_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
    2581                 :         309 :     context->local_context.capability.data_transfer_size = receiver_buffer_size;
    2582                 :         309 : }
    2583                 :             : 
    2584                 :         310 : void libspdm_register_transport_layer_func(
    2585                 :             :     void *spdm_context,
    2586                 :             :     uint32_t max_spdm_msg_size,
    2587                 :             :     uint32_t transport_header_size,
    2588                 :             :     uint32_t transport_tail_size,
    2589                 :             :     libspdm_transport_encode_message_func transport_encode_message,
    2590                 :             :     libspdm_transport_decode_message_func transport_decode_message)
    2591                 :             : {
    2592                 :             :     libspdm_context_t *context;
    2593                 :             : 
    2594                 :         310 :     context = spdm_context;
    2595                 :             : 
    2596                 :             :     /* fix the data_transfer_size if it is set before */
    2597         [ +  + ]:         310 :     if ((context->local_context.capability.data_transfer_size != 0) &&
    2598                 :           1 :         (context->local_context.capability.data_transfer_size ==
    2599         [ -  + ]:           1 :          context->receiver_buffer_size)) {
    2600                 :           0 :         context->local_context.capability.data_transfer_size =
    2601                 :           0 :             (uint32_t)(context->receiver_buffer_size -
    2602                 :           0 :                        (transport_header_size + transport_tail_size));
    2603                 :             :     }
    2604         [ +  + ]:         310 :     if ((context->local_context.capability.sender_data_transfer_size != 0) &&
    2605                 :           1 :         (context->local_context.capability.sender_data_transfer_size ==
    2606         [ -  + ]:           1 :          context->sender_buffer_size)) {
    2607                 :           0 :         context->local_context.capability.sender_data_transfer_size =
    2608                 :           0 :             (uint32_t)(context->sender_buffer_size -
    2609                 :           0 :                        (transport_header_size + transport_tail_size));
    2610                 :             :     }
    2611                 :             : 
    2612                 :         310 :     context->local_context.capability.max_spdm_msg_size = max_spdm_msg_size;
    2613                 :         310 :     context->local_context.capability.transport_header_size = transport_header_size;
    2614                 :         310 :     context->local_context.capability.transport_tail_size = transport_tail_size;
    2615                 :         310 :     context->transport_encode_message = transport_encode_message;
    2616                 :         310 :     context->transport_decode_message = transport_decode_message;
    2617                 :         310 : }
    2618                 :             : 
    2619                 :           3 : void libspdm_register_verify_spdm_cert_chain_func(
    2620                 :             :     void *spdm_context,
    2621                 :             :     const libspdm_verify_spdm_cert_chain_func verify_spdm_cert_chain)
    2622                 :             : {
    2623                 :             :     libspdm_context_t *context;
    2624                 :             : 
    2625                 :           3 :     context = spdm_context;
    2626                 :           3 :     context->local_context.verify_peer_spdm_cert_chain = verify_spdm_cert_chain;
    2627                 :           3 : }
    2628                 :             : 
    2629                 :         313 : size_t libspdm_get_sizeof_required_scratch_buffer (void *spdm_context)
    2630                 :             : {
    2631                 :             :     libspdm_context_t *context;
    2632                 :             :     size_t scratch_buffer_size;
    2633                 :             : 
    2634                 :         313 :     context = spdm_context;
    2635         [ -  + ]:         313 :     LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
    2636                 :             : 
    2637                 :         313 :     scratch_buffer_size = libspdm_get_scratch_buffer_capacity(context);
    2638                 :         313 :     return scratch_buffer_size;
    2639                 :             : }
    2640                 :             : 
    2641                 :         313 : void libspdm_set_scratch_buffer (
    2642                 :             :     void *spdm_context,
    2643                 :             :     void *scratch_buffer,
    2644                 :             :     size_t scratch_buffer_size)
    2645                 :             : {
    2646                 :             :     libspdm_context_t *context;
    2647                 :             : 
    2648                 :         313 :     context = spdm_context;
    2649         [ -  + ]:         313 :     LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
    2650         [ -  + ]:         313 :     LIBSPDM_ASSERT (scratch_buffer_size >= libspdm_get_scratch_buffer_capacity(spdm_context));
    2651                 :         313 :     context->scratch_buffer = scratch_buffer;
    2652                 :         313 :     context->scratch_buffer_size = scratch_buffer_size;
    2653                 :         313 :     context->last_spdm_request = (uint8_t *)scratch_buffer +
    2654                 :         313 :                                  libspdm_get_scratch_buffer_last_spdm_request_offset(spdm_context);
    2655                 :             : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
    2656                 :         313 :     context->cache_spdm_request = (uint8_t *)scratch_buffer +
    2657                 :         313 :                                   libspdm_get_scratch_buffer_cache_spdm_request_offset(spdm_context);
    2658                 :             : #endif
    2659                 :         313 : }
    2660                 :             : 
    2661                 :      137590 : void libspdm_get_scratch_buffer (
    2662                 :             :     void *spdm_context,
    2663                 :             :     void **scratch_buffer,
    2664                 :             :     size_t *scratch_buffer_size)
    2665                 :             : {
    2666                 :             :     libspdm_context_t *context;
    2667                 :             : 
    2668                 :      137590 :     context = spdm_context;
    2669         [ -  + ]:      137590 :     LIBSPDM_ASSERT (context->scratch_buffer != NULL);
    2670         [ -  + ]:      137590 :     LIBSPDM_ASSERT (context->scratch_buffer_size >=
    2671                 :             :                     libspdm_get_scratch_buffer_capacity(spdm_context));
    2672                 :      137590 :     *scratch_buffer = context->scratch_buffer;
    2673                 :      137590 :     *scratch_buffer_size = context->scratch_buffer_size;
    2674                 :             :     /* need to remove last 2 sections, because they are for libspdm internal state track. */
    2675                 :      137590 :     *scratch_buffer_size -= libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context);
    2676                 :             : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
    2677                 :      137590 :     *scratch_buffer_size -= libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context);
    2678                 :             : #endif
    2679                 :      137590 : }
    2680                 :             : 
    2681                 :        3042 : libspdm_return_t libspdm_acquire_sender_buffer (
    2682                 :             :     libspdm_context_t *spdm_context, size_t *max_msg_size, void **msg_buf_ptr)
    2683                 :             : {
    2684                 :             :     libspdm_return_t status;
    2685                 :             : 
    2686         [ -  + ]:        3042 :     LIBSPDM_ASSERT (spdm_context->sender_buffer == NULL);
    2687         [ -  + ]:        3042 :     LIBSPDM_ASSERT (spdm_context->sender_buffer_size != 0);
    2688                 :        3042 :     status = spdm_context->acquire_sender_buffer (spdm_context, msg_buf_ptr);
    2689         [ +  + ]:        3042 :     if (status != LIBSPDM_STATUS_SUCCESS) {
    2690                 :          17 :         return status;
    2691                 :             :     }
    2692                 :        3025 :     spdm_context->sender_buffer = *msg_buf_ptr;
    2693                 :        3025 :     *max_msg_size = spdm_context->sender_buffer_size;
    2694                 :             :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
    2695                 :             :     /* it return scratch buffer, because the requester need build message there.*/
    2696                 :        6050 :     *msg_buf_ptr = (uint8_t *)spdm_context->scratch_buffer +
    2697                 :        3025 :                    libspdm_get_scratch_buffer_large_sender_receiver_offset(spdm_context);
    2698                 :        3025 :     *max_msg_size = libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context);
    2699                 :             :     #endif
    2700                 :        3025 :     return LIBSPDM_STATUS_SUCCESS;
    2701                 :             : }
    2702                 :             : 
    2703                 :        3025 : void libspdm_release_sender_buffer (libspdm_context_t *spdm_context)
    2704                 :             : {
    2705         [ -  + ]:        3025 :     LIBSPDM_ASSERT(spdm_context->sender_buffer != NULL);
    2706         [ -  + ]:        3025 :     LIBSPDM_ASSERT(spdm_context->sender_buffer_size != 0);
    2707                 :             : 
    2708                 :        3025 :     spdm_context->release_sender_buffer (spdm_context, spdm_context->sender_buffer);
    2709                 :        3025 :     spdm_context->sender_buffer = NULL;
    2710                 :        3025 : }
    2711                 :             : 
    2712                 :       68610 : void libspdm_get_sender_buffer (
    2713                 :             :     libspdm_context_t *spdm_context,
    2714                 :             :     void **sender_buffer,
    2715                 :             :     size_t *sender_buffer_size)
    2716                 :             : {
    2717                 :       68610 :     *sender_buffer = spdm_context->sender_buffer;
    2718                 :       68610 :     *sender_buffer_size = spdm_context->sender_buffer_size;
    2719                 :       68610 : }
    2720                 :             : 
    2721                 :        2952 : libspdm_return_t libspdm_acquire_receiver_buffer (
    2722                 :             :     libspdm_context_t *spdm_context, size_t *max_msg_size, void **msg_buf_ptr)
    2723                 :             : {
    2724                 :             :     libspdm_return_t status;
    2725                 :             : 
    2726         [ -  + ]:        2952 :     LIBSPDM_ASSERT (spdm_context->receiver_buffer == NULL);
    2727         [ -  + ]:        2952 :     LIBSPDM_ASSERT (spdm_context->receiver_buffer_size != 0);
    2728                 :        2952 :     status = spdm_context->acquire_receiver_buffer (spdm_context, msg_buf_ptr);
    2729         [ +  + ]:        2952 :     if (status != LIBSPDM_STATUS_SUCCESS) {
    2730                 :          17 :         return status;
    2731                 :             :     }
    2732                 :        2935 :     spdm_context->receiver_buffer = *msg_buf_ptr;
    2733                 :        2935 :     *max_msg_size = spdm_context->receiver_buffer_size;
    2734                 :             :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
    2735                 :             :     /* it return scratch buffer, because the requester need build message there.*/
    2736                 :        5870 :     *msg_buf_ptr = (uint8_t *)spdm_context->scratch_buffer +
    2737                 :        2935 :                    libspdm_get_scratch_buffer_large_sender_receiver_offset(spdm_context);
    2738                 :        2935 :     *max_msg_size = libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context);
    2739                 :             :     #endif
    2740                 :        2935 :     return LIBSPDM_STATUS_SUCCESS;
    2741                 :             : }
    2742                 :             : 
    2743                 :        2935 : void libspdm_release_receiver_buffer (libspdm_context_t *spdm_context)
    2744                 :             : {
    2745         [ -  + ]:        2935 :     LIBSPDM_ASSERT(spdm_context->receiver_buffer != NULL);
    2746         [ -  + ]:        2935 :     LIBSPDM_ASSERT(spdm_context->receiver_buffer_size != 0);
    2747                 :             : 
    2748                 :        2935 :     spdm_context->release_receiver_buffer (spdm_context, spdm_context->receiver_buffer);
    2749                 :        2935 :     spdm_context->receiver_buffer = NULL;
    2750                 :        2935 : }
    2751                 :             : 
    2752                 :           0 : void libspdm_get_receiver_buffer (
    2753                 :             :     libspdm_context_t *spdm_context,
    2754                 :             :     void **receiver_buffer,
    2755                 :             :     size_t *receiver_buffer_size)
    2756                 :             : {
    2757                 :           0 :     *receiver_buffer = spdm_context->receiver_buffer;
    2758                 :           0 :     *receiver_buffer_size = spdm_context->receiver_buffer_size;
    2759                 :           0 : }
    2760                 :             : 
    2761                 :           0 : void libspdm_get_last_spdm_error_struct(void *spdm_context, libspdm_error_struct_t *last_spdm_error)
    2762                 :             : {
    2763                 :             :     libspdm_context_t *context;
    2764                 :             : 
    2765                 :           0 :     context = spdm_context;
    2766                 :           0 :     libspdm_copy_mem(last_spdm_error, sizeof(libspdm_error_struct_t),
    2767                 :           0 :                      &context->last_spdm_error,sizeof(libspdm_error_struct_t));
    2768                 :           0 : }
    2769                 :             : 
    2770                 :       68739 : void libspdm_set_last_spdm_error_struct(void *spdm_context, libspdm_error_struct_t *last_spdm_error)
    2771                 :             : {
    2772                 :             :     libspdm_context_t *context;
    2773                 :             : 
    2774                 :       68739 :     context = spdm_context;
    2775                 :       68739 :     libspdm_copy_mem(&context->last_spdm_error, sizeof(context->last_spdm_error),
    2776                 :             :                      last_spdm_error, sizeof(libspdm_error_struct_t));
    2777                 :       68739 : }
    2778                 :             : 
    2779                 :             : #if LIBSPDM_FIPS_MODE
    2780                 :           0 : libspdm_return_t libspdm_init_fips_selftest_context(void *fips_selftest_context,
    2781                 :             :                                                     size_t buffer_size,
    2782                 :             :                                                     void *buffer)
    2783                 :             : {
    2784                 :             :     libspdm_fips_selftest_context_t *context;
    2785         [ #  # ]:           0 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
    2786                 :             :     LIBSPDM_ASSERT(buffer_size >= LIBSPDM_FIPS_REQUIRED_BUFFER_SIZE);
    2787         [ #  # ]:           0 :     if (buffer_size > 0) {
    2788         [ #  # ]:           0 :         LIBSPDM_ASSERT(buffer != NULL);
    2789                 :             :     }
    2790                 :             : 
    2791                 :           0 :     context = fips_selftest_context;
    2792                 :             : 
    2793                 :             :     /*Not tested for every used algo*/
    2794                 :           0 :     context->tested_algo = 0;
    2795                 :             :     /*self_test result is false for every used algo*/
    2796                 :           0 :     context->self_test_result = 0;
    2797                 :             :     /*The buffer provided by integrator to hold large intermediate results*/
    2798                 :           0 :     context->selftest_buffer_size = buffer_size;
    2799                 :           0 :     context->selftest_buffer = buffer;
    2800                 :             : 
    2801                 :           0 :     return LIBSPDM_STATUS_SUCCESS;
    2802                 :             : }
    2803                 :             : 
    2804                 :           0 : size_t libspdm_get_fips_selftest_context_size(void)
    2805                 :             : {
    2806                 :             :     size_t size;
    2807                 :             : 
    2808                 :           0 :     size = sizeof(libspdm_fips_selftest_context_t);
    2809                 :           0 :     return size;
    2810                 :             : }
    2811                 :             : 
    2812                 :           0 : size_t libspdm_get_fips_selftest_buffer_size(void)
    2813                 :             : {
    2814                 :           0 :     return LIBSPDM_FIPS_REQUIRED_BUFFER_SIZE;
    2815                 :             : }
    2816                 :             : 
    2817                 :           0 : bool libspdm_import_fips_selftest_context_to_spdm_context(void *spdm_context,
    2818                 :             :                                                           void *fips_selftest_context,
    2819                 :             :                                                           size_t fips_selftest_context_size)
    2820                 :             : {
    2821                 :             :     libspdm_fips_selftest_context_t *libspdm_fips_selftest_context;
    2822                 :             :     libspdm_context_t *libspdm_context;
    2823                 :             : 
    2824                 :           0 :     libspdm_context = spdm_context;
    2825                 :           0 :     libspdm_fips_selftest_context = fips_selftest_context;
    2826                 :             : 
    2827   [ #  #  #  # ]:           0 :     if ((libspdm_context == NULL) || (libspdm_fips_selftest_context == NULL)) {
    2828                 :           0 :         return false;
    2829                 :             :     }
    2830         [ #  # ]:           0 :     if (fips_selftest_context_size != sizeof(libspdm_fips_selftest_context_t)) {
    2831                 :           0 :         return false;
    2832                 :             :     }
    2833                 :             : 
    2834                 :           0 :     libspdm_copy_mem(&(libspdm_context->fips_selftest_context),
    2835                 :             :                      sizeof(libspdm_fips_selftest_context_t),
    2836                 :             :                      libspdm_fips_selftest_context, sizeof(libspdm_fips_selftest_context_t));
    2837                 :           0 :     return true;
    2838                 :             : }
    2839                 :             : 
    2840                 :           0 : bool libspdm_export_fips_selftest_context_from_spdm_context(void *spdm_context,
    2841                 :             :                                                             void *fips_selftest_context,
    2842                 :             :                                                             size_t fips_selftest_context_size)
    2843                 :             : {
    2844                 :             :     libspdm_fips_selftest_context_t *libspdm_fips_selftest_context;
    2845                 :             :     libspdm_context_t *libspdm_context;
    2846                 :             : 
    2847                 :           0 :     libspdm_context = spdm_context;
    2848                 :           0 :     libspdm_fips_selftest_context = fips_selftest_context;
    2849                 :             : 
    2850   [ #  #  #  # ]:           0 :     if ((libspdm_context == NULL) || (libspdm_fips_selftest_context == NULL)) {
    2851                 :           0 :         return false;
    2852                 :             :     }
    2853         [ #  # ]:           0 :     if (fips_selftest_context_size != sizeof(libspdm_fips_selftest_context_t)) {
    2854                 :           0 :         return false;
    2855                 :             :     }
    2856                 :             : 
    2857                 :           0 :     libspdm_copy_mem(libspdm_fips_selftest_context,
    2858                 :             :                      sizeof(libspdm_fips_selftest_context_t),
    2859                 :           0 :                      &(libspdm_context->fips_selftest_context),
    2860                 :             :                      sizeof(libspdm_fips_selftest_context_t));
    2861                 :           0 :     return true;
    2862                 :             : }
    2863                 :             : 
    2864                 :             : #endif /* LIBSPDM_FIPS_MODE */
    2865                 :             : 
    2866                 :         316 : libspdm_return_t libspdm_init_context_with_secured_context(void *spdm_context,
    2867                 :             :                                                            void **secured_contexts,
    2868                 :             :                                                            size_t num_secured_contexts)
    2869                 :             : {
    2870                 :             :     libspdm_context_t *context;
    2871                 :             :     size_t index;
    2872                 :             : 
    2873         [ -  + ]:         316 :     LIBSPDM_ASSERT(spdm_context != NULL);
    2874         [ -  + ]:         316 :     LIBSPDM_ASSERT(secured_contexts != NULL);
    2875         [ -  + ]:         316 :     LIBSPDM_ASSERT(num_secured_contexts == LIBSPDM_MAX_SESSION_COUNT);
    2876                 :             : 
    2877                 :         316 :     context = spdm_context;
    2878                 :         316 :     libspdm_zero_mem(context, sizeof(libspdm_context_t));
    2879                 :         316 :     context->version = LIBSPDM_CONTEXT_STRUCT_VERSION;
    2880                 :         316 :     context->transcript.message_a.max_buffer_size =
    2881                 :             :         sizeof(context->transcript.message_a.buffer);
    2882                 :         316 :     context->transcript.message_d.max_buffer_size =
    2883                 :             :         sizeof(context->transcript.message_d.buffer);
    2884                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    2885                 :             :     context->transcript.message_b.max_buffer_size =
    2886                 :             :         sizeof(context->transcript.message_b.buffer);
    2887                 :             :     context->transcript.message_c.max_buffer_size =
    2888                 :             :         sizeof(context->transcript.message_c.buffer);
    2889                 :             :     context->transcript.message_mut_b.max_buffer_size =
    2890                 :             :         sizeof(context->transcript.message_mut_b.buffer);
    2891                 :             :     context->transcript.message_mut_c.max_buffer_size =
    2892                 :             :         sizeof(context->transcript.message_mut_c.buffer);
    2893                 :             :     context->transcript.message_m.max_buffer_size =
    2894                 :             :         sizeof(context->transcript.message_m.buffer);
    2895                 :             :     context->transcript.message_e.max_buffer_size =
    2896                 :             :         sizeof(context->transcript.message_e.buffer);
    2897                 :             :     context->transcript.message_encap_e.max_buffer_size =
    2898                 :             :         sizeof(context->transcript.message_encap_e.buffer);
    2899                 :             : #endif
    2900                 :         316 :     context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
    2901                 :         316 :     context->local_context.version.spdm_version_count = SPDM_MAX_VERSION_COUNT;
    2902                 :         316 :     context->local_context.version.spdm_version[0] = SPDM_MESSAGE_VERSION_10 <<
    2903                 :             :                                                      SPDM_VERSION_NUMBER_SHIFT_BIT;
    2904                 :         316 :     context->local_context.version.spdm_version[1] = SPDM_MESSAGE_VERSION_11 <<
    2905                 :             :                                                      SPDM_VERSION_NUMBER_SHIFT_BIT;
    2906                 :         316 :     context->local_context.version.spdm_version[2] = SPDM_MESSAGE_VERSION_12 <<
    2907                 :             :                                                      SPDM_VERSION_NUMBER_SHIFT_BIT;
    2908                 :         316 :     context->local_context.version.spdm_version[3] = SPDM_MESSAGE_VERSION_13 <<
    2909                 :             :                                                      SPDM_VERSION_NUMBER_SHIFT_BIT;
    2910                 :         316 :     context->local_context.version.spdm_version[4] = SPDM_MESSAGE_VERSION_14 <<
    2911                 :             :                                                      SPDM_VERSION_NUMBER_SHIFT_BIT;
    2912                 :         316 :     context->local_context.secured_message_version.secured_message_version_count =
    2913                 :             :         SECURED_SPDM_MAX_VERSION_COUNT;
    2914                 :         316 :     context->local_context.secured_message_version.secured_message_version[0] =
    2915                 :             :         SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2916                 :         316 :     context->local_context.secured_message_version.secured_message_version[1] =
    2917                 :             :         SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2918                 :         316 :     context->local_context.secured_message_version.secured_message_version[2] =
    2919                 :             :         SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2920                 :         316 :     context->local_context.secured_message_version.secured_message_version[3] =
    2921                 :             :         SECURED_SPDM_VERSION_13 << SPDM_VERSION_NUMBER_SHIFT_BIT;
    2922                 :         316 :     context->local_context.capability.st1 = SPDM_ST1_VALUE_US;
    2923                 :             : 
    2924                 :             :     /* DSP0277 1.3 AEAD limit: max_spdm_session_sequence_number is the single source of truth for
    2925                 :             :      * the AEAD limit. The default 0xFFFFFFFFFFFFFFFF encodes the spec-default exponent of 64. */
    2926                 :         316 :     context->max_spdm_session_sequence_number = LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER;
    2927                 :             : 
    2928                 :         316 :     context->latest_session_id = INVALID_SESSION_ID;
    2929                 :         316 :     context->last_spdm_request_session_id = INVALID_SESSION_ID;
    2930                 :         316 :     context->last_spdm_request_session_id_valid = false;
    2931                 :         316 :     context->last_spdm_request_size = 0;
    2932                 :             : 
    2933                 :             :     /* To be updated in libspdm_register_device_buffer_func */
    2934                 :         316 :     context->local_context.capability.data_transfer_size = 0;
    2935                 :         316 :     context->local_context.capability.sender_data_transfer_size = 0;
    2936                 :         316 :     context->local_context.capability.max_spdm_msg_size = 0;
    2937                 :             : 
    2938         [ +  + ]:        1580 :     for (index = 0; index < num_secured_contexts; index++) {
    2939         [ -  + ]:        1264 :         if (secured_contexts[index] == NULL) {
    2940                 :           0 :             return LIBSPDM_STATUS_INVALID_PARAMETER;
    2941                 :             :         }
    2942                 :             : 
    2943                 :        1264 :         context->session_info[index].secured_message_context = secured_contexts[index];
    2944                 :        1264 :         libspdm_secured_message_init_context(
    2945                 :             :             context->session_info[index].secured_message_context);
    2946                 :             :     }
    2947                 :             : 
    2948                 :         316 :     return LIBSPDM_STATUS_SUCCESS;
    2949                 :             : }
    2950                 :             : 
    2951                 :         315 : libspdm_return_t libspdm_init_context(void *spdm_context)
    2952                 :             : {
    2953                 :             :     libspdm_context_t *context;
    2954                 :             :     void *secured_context;
    2955                 :             :     void *secured_contexts[LIBSPDM_MAX_SESSION_COUNT];
    2956                 :             :     size_t secured_context_size;
    2957                 :             :     size_t index;
    2958                 :             : 
    2959         [ -  + ]:         315 :     LIBSPDM_ASSERT(spdm_context != NULL);
    2960                 :             : 
    2961                 :             :     /* libspdm_get_context_size() allocates space for all secured message
    2962                 :             :      * contexts. They are appended to the general SPDM context. */
    2963                 :         315 :     context = spdm_context;
    2964                 :         315 :     secured_context = (void *)((size_t)(context + 1));
    2965                 :         315 :     secured_context_size = libspdm_secured_message_get_context_size();
    2966                 :             : 
    2967         [ +  + ]:        1575 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
    2968                 :             :     {
    2969                 :        1260 :         secured_contexts[index] = (uint8_t *)secured_context + secured_context_size * index;
    2970                 :             :     }
    2971                 :             : 
    2972                 :         315 :     return libspdm_init_context_with_secured_context(spdm_context,
    2973                 :             :                                                      secured_contexts,
    2974                 :             :                                                      LIBSPDM_MAX_SESSION_COUNT);
    2975                 :             : }
    2976                 :             : 
    2977                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
    2978                 :         206 : static void libspdm_reset_chunk_info(libspdm_chunk_info_t *chunk_info)
    2979                 :             : {
    2980         [ +  + ]:         206 :     if (chunk_info->large_message != NULL) {
    2981                 :           4 :         libspdm_zero_mem(chunk_info->large_message, chunk_info->large_message_capacity);
    2982                 :             :     }
    2983                 :         206 :     chunk_info->chunk_in_use = false;
    2984                 :         206 :     chunk_info->chunk_seq_no = 0;
    2985                 :         206 :     chunk_info->chunk_bytes_transferred = 0;
    2986                 :         206 :     chunk_info->large_message = NULL;
    2987                 :         206 :     chunk_info->large_message_size = 0;
    2988                 :         206 :     chunk_info->large_message_capacity = 0;
    2989                 :         206 : }
    2990                 :             : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
    2991                 :             : 
    2992                 :         103 : void libspdm_reset_context(void *spdm_context)
    2993                 :             : {
    2994                 :             :     libspdm_context_t *context;
    2995                 :             :     size_t index;
    2996                 :             : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
    2997                 :             :     uint8_t slot_index;
    2998                 :             : #endif
    2999                 :             : 
    3000                 :         103 :     context = spdm_context;
    3001                 :             : 
    3002                 :             :     /* Clear all information about previous connection. Local context information is preserved. */
    3003                 :             : 
    3004                 :             :     /* Need to clear session information and message transcripts before negotiated algorithm
    3005                 :             :      * information is cleared. */
    3006         [ +  + ]:         515 :     for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
    3007                 :             :     {
    3008                 :         412 :         libspdm_session_info_init(context,
    3009                 :             :                                   &context->session_info[index],
    3010                 :             :                                   INVALID_SESSION_ID,
    3011                 :             :                                   0,
    3012                 :             :                                   false);
    3013                 :             :     }
    3014                 :             : 
    3015                 :         103 :     libspdm_reset_message_a(spdm_context);
    3016                 :         103 :     libspdm_reset_message_d(spdm_context);
    3017                 :         103 :     libspdm_reset_message_b(spdm_context);
    3018                 :         103 :     libspdm_reset_message_c(spdm_context);
    3019                 :         103 :     libspdm_reset_message_mut_b(spdm_context);
    3020                 :         103 :     libspdm_reset_message_mut_c(spdm_context);
    3021                 :         103 :     libspdm_reset_message_m(spdm_context, NULL);
    3022                 :         103 :     libspdm_reset_message_e(spdm_context, NULL);
    3023                 :         103 :     libspdm_reset_message_encap_e(spdm_context, NULL);
    3024                 :             : 
    3025                 :             : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
    3026                 :             :     /* Free the peer leaf certificate public key contexts while the negotiated
    3027                 :             :      * algorithm they were parsed under is still known; that algorithm is cleared
    3028                 :             :      * below, and these contexts are otherwise only released in
    3029                 :             :      * libspdm_deinit_context, so they leak across every re-connection. */
    3030         [ +  + ]:         927 :     for (slot_index = 0; slot_index < SPDM_MAX_SLOT_COUNT; slot_index++) {
    3031                 :         824 :         libspdm_free_peer_leaf_cert_public_key(context, slot_index);
    3032                 :             :     }
    3033                 :         103 :     libspdm_zero_mem(context->connection_info.peer_used_cert_chain,
    3034                 :             :                      sizeof(context->connection_info.peer_used_cert_chain));
    3035                 :             : #endif
    3036                 :             : 
    3037                 :         103 :     context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
    3038                 :         103 :     libspdm_zero_mem(&context->connection_info.version, sizeof(spdm_version_number_t));
    3039                 :         103 :     libspdm_zero_mem(&context->connection_info.capability,
    3040                 :             :                      sizeof(libspdm_device_capability_t));
    3041                 :         103 :     libspdm_zero_mem(&context->connection_info.algorithm, sizeof(libspdm_device_algorithm_t));
    3042                 :         103 :     libspdm_zero_mem(&context->last_spdm_error, sizeof(libspdm_error_struct_t));
    3043                 :             : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
    3044                 :         103 :     libspdm_zero_mem(&context->encap_context, sizeof(libspdm_encap_context_t));
    3045                 :             : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
    3046                 :             : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
    3047                 :         103 :     libspdm_reset_chunk_info(&context->chunk_context.get);
    3048                 :         103 :     libspdm_reset_chunk_info(&context->chunk_context.send);
    3049                 :             : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
    3050                 :         103 :     context->connection_info.multi_key_conn_req = false;
    3051                 :         103 :     context->connection_info.multi_key_conn_rsp = false;
    3052                 :             : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
    3053                 :         103 :     context->cache_spdm_request_size = 0;
    3054                 :             : #endif
    3055                 :         103 :     context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
    3056                 :         103 :     context->current_token = 0;
    3057                 :         103 :     context->latest_session_id = INVALID_SESSION_ID;
    3058                 :         103 :     context->last_spdm_request_session_id = INVALID_SESSION_ID;
    3059                 :         103 :     context->last_spdm_request_session_id_valid = false;
    3060                 :         103 :     context->last_spdm_request_size = 0;
    3061                 :             : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
    3062                 :         103 :     context->encap_context.payload_buffer_size = 0;
    3063                 :             : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
    3064                 :         103 :     context->current_dhe_session_count = 0;
    3065                 :         103 :     context->current_psk_session_count = 0;
    3066                 :         103 :     context->spdm_10_11_verify_signature_endian =
    3067                 :         103 :         context->spdm_10_11_verify_signature_endian_setting;
    3068                 :         103 : }
    3069                 :             : 
    3070                 :         308 : void libspdm_deinit_context(void *spdm_context)
    3071                 :             : {
    3072                 :             :     uint32_t session_id;
    3073                 :             :     libspdm_context_t *context;
    3074                 :             :     libspdm_session_info_t *session_info;
    3075                 :             : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
    3076                 :             :     uint8_t slot_index;
    3077                 :             : #endif
    3078                 :             : 
    3079                 :         308 :     context = spdm_context;
    3080                 :             : 
    3081                 :             : #if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
    3082         [ +  + ]:        2772 :     for (slot_index = 0; slot_index < SPDM_MAX_SLOT_COUNT; slot_index++) {
    3083                 :        2464 :         libspdm_free_peer_leaf_cert_public_key(context, slot_index);
    3084                 :             :     }
    3085                 :             : #endif
    3086                 :             : 
    3087                 :         308 :     libspdm_reset_message_a(context);
    3088                 :         308 :     libspdm_reset_message_d(context);
    3089                 :         308 :     libspdm_reset_message_b(context);
    3090                 :         308 :     libspdm_reset_message_c(context);
    3091                 :         308 :     libspdm_reset_message_mut_b(context);
    3092                 :         308 :     libspdm_reset_message_mut_c(context);
    3093                 :         308 :     libspdm_reset_message_m(spdm_context, NULL);
    3094                 :         308 :     libspdm_reset_message_e(spdm_context, NULL);
    3095                 :         308 :     libspdm_reset_message_encap_e(spdm_context, NULL);
    3096         [ +  + ]:        1540 :     for (session_id = 0; session_id < LIBSPDM_MAX_SESSION_COUNT; session_id++) {
    3097                 :        1232 :         session_info = &context->session_info[session_id];
    3098                 :        1232 :         libspdm_reset_message_m(context, session_info);
    3099                 :        1232 :         libspdm_reset_message_e(context, session_info);
    3100                 :        1232 :         libspdm_reset_message_encap_e(context, session_info);
    3101                 :        1232 :         libspdm_reset_message_encap_d(session_info);
    3102                 :        1232 :         libspdm_reset_message_k(context, session_info);
    3103                 :        1232 :         libspdm_reset_message_f(context, session_info);
    3104                 :             :     }
    3105                 :         308 : }
    3106                 :             : 
    3107                 :         315 : size_t libspdm_get_context_size(void)
    3108                 :             : {
    3109                 :             :     size_t size;
    3110                 :             : 
    3111                 :         315 :     size = sizeof(libspdm_context_t) +
    3112                 :         315 :            libspdm_secured_message_get_context_size() * LIBSPDM_MAX_SESSION_COUNT;
    3113         [ -  + ]:         315 :     LIBSPDM_ASSERT (size == LIBSPDM_CONTEXT_SIZE_ALL);
    3114                 :         315 :     return size;
    3115                 :             : }
    3116                 :             : 
    3117                 :           1 : size_t libspdm_get_context_size_without_secured_context(void)
    3118                 :             : {
    3119                 :             :     size_t size;
    3120                 :             : 
    3121                 :           1 :     size = sizeof(libspdm_context_t);
    3122         [ -  + ]:           1 :     LIBSPDM_ASSERT (size == LIBSPDM_CONTEXT_SIZE_WITHOUT_SECURED_CONTEXT);
    3123                 :           1 :     return size;
    3124                 :             : }
    3125                 :             : 
    3126                 :        1452 : uint8_t libspdm_get_version_from_version_number(spdm_version_number_t ver)
    3127                 :             : {
    3128                 :        1452 :     return (uint8_t)(ver >> SPDM_VERSION_NUMBER_SHIFT_BIT);
    3129                 :             : }
    3130                 :             : 
    3131                 :         131 : void libspdm_version_number_sort(spdm_version_number_t *ver_set, size_t ver_num)
    3132                 :             : {
    3133                 :             :     size_t index;
    3134                 :             :     size_t index_sort;
    3135                 :             :     size_t index_max;
    3136                 :             :     spdm_version_number_t version;
    3137                 :             : 
    3138                 :             :     /* Selection sort */
    3139         [ +  + ]:         131 :     if (ver_num > 1) {
    3140         [ +  + ]:         272 :         for (index_sort = 0; index_sort < ver_num; index_sort++) {
    3141                 :         218 :             index_max = index_sort;
    3142         [ +  + ]:         574 :             for (index = index_sort + 1; index < ver_num; index++) {
    3143                 :             :                 /* if ver_set[index] higher than ver_set[index_max] */
    3144         [ +  + ]:         356 :                 if (ver_set[index] > ver_set[index_max]) {
    3145                 :         209 :                     index_max = index;
    3146                 :             :                 }
    3147                 :             :             }
    3148                 :             :             /* swap ver_set[index_max] and ver_set[index_sort] */
    3149                 :         218 :             version = ver_set[index_sort];
    3150                 :         218 :             ver_set[index_sort] = ver_set[index_max];
    3151                 :         218 :             ver_set[index_max] = version;
    3152                 :             :         }
    3153                 :             :     }
    3154                 :         131 : }
    3155                 :             : 
    3156                 :          65 : bool libspdm_negotiate_connection_version(spdm_version_number_t *common_version,
    3157                 :             :                                           spdm_version_number_t *req_ver_set,
    3158                 :             :                                           size_t req_ver_num,
    3159                 :             :                                           const spdm_version_number_t *res_ver_set,
    3160                 :             :                                           size_t res_ver_num)
    3161                 :             : {
    3162                 :             :     spdm_version_number_t req_version_list[LIBSPDM_MAX_VERSION_COUNT];
    3163                 :             :     spdm_version_number_t res_version_list[LIBSPDM_MAX_VERSION_COUNT];
    3164                 :             :     size_t req_index;
    3165                 :             :     size_t res_index;
    3166                 :             : 
    3167   [ +  -  -  + ]:          65 :     if (req_ver_num > LIBSPDM_MAX_VERSION_COUNT || res_ver_num > LIBSPDM_MAX_VERSION_COUNT) {
    3168                 :           0 :         return false;
    3169                 :             :     }
    3170                 :             : 
    3171   [ +  -  +  -  :          65 :     if (req_ver_set == NULL || req_ver_num == 0 || res_ver_set == NULL || res_ver_num == 0) {
             +  -  -  + ]
    3172                 :           0 :         return false;
    3173                 :             :     }
    3174                 :             : 
    3175                 :          65 :     libspdm_zero_mem(req_version_list, sizeof(spdm_version_number_t) * LIBSPDM_MAX_VERSION_COUNT);
    3176                 :          65 :     libspdm_zero_mem(res_version_list, sizeof(spdm_version_number_t) * LIBSPDM_MAX_VERSION_COUNT);
    3177                 :             : 
    3178                 :          65 :     libspdm_copy_mem(req_version_list, sizeof(spdm_version_number_t) * LIBSPDM_MAX_VERSION_COUNT,
    3179                 :             :                      req_ver_set, sizeof(spdm_version_number_t) * req_ver_num);
    3180                 :          65 :     libspdm_copy_mem(res_version_list, sizeof(spdm_version_number_t) * LIBSPDM_MAX_VERSION_COUNT,
    3181                 :             :                      res_ver_set, sizeof(spdm_version_number_t) * res_ver_num);
    3182                 :             : 
    3183                 :             :     /* Sort SPDMversion in descending order. */
    3184                 :          65 :     libspdm_version_number_sort(req_version_list, req_ver_num);
    3185                 :          65 :     libspdm_version_number_sort(res_version_list, res_ver_num);
    3186                 :             : 
    3187                 :             :     /**
    3188                 :             :      * Find highest same version and make req_index point to it.
    3189                 :             :      * If not found, return false.
    3190                 :             :      **/
    3191         [ +  + ]:          75 :     for (res_index = 0; res_index < res_ver_num; res_index++) {
    3192         [ +  + ]:         155 :         for (req_index = 0; req_index < req_ver_num; req_index++) {
    3193         [ +  + ]:         290 :             if (libspdm_get_version_from_version_number(req_version_list[req_index]) ==
    3194                 :         145 :                 libspdm_get_version_from_version_number(res_version_list[res_index])) {
    3195                 :          63 :                 *common_version = req_version_list[req_index];
    3196                 :          63 :                 return true;
    3197                 :             :             }
    3198                 :             :         }
    3199                 :             :     }
    3200                 :           2 :     return false;
    3201                 :             : }
    3202                 :             : 
    3203                 :             : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
    3204                 :          20 : void libspdm_register_event_callback(void *context,
    3205                 :             :                                      libspdm_process_event_func process_event_func)
    3206                 :             : {
    3207                 :             :     libspdm_context_t *spdm_context;
    3208                 :             : 
    3209                 :          20 :     spdm_context = context;
    3210                 :          20 :     spdm_context->process_event = process_event_func;
    3211                 :          20 : }
    3212                 :             : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
        

Generated by: LCOV version 2.0-1