Code coverage report for DMTF/libspdm
Current view: top level - library/spdm_requester_lib - libspdm_req_get_measurements.c (source / functions) Coverage Total Hit
Test: 36148b912f76d231c18d216d6dee5c0858575bb1 Lines: 76.0 % 404 307
Test Date: 2026-10-25 08:40:22 Functions: 100.0 % 5 5
Branches: 71.9 % 228 164

             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_requester_lib.h"
       8                 :             : 
       9                 :             : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
      10                 :             : 
      11                 :          48 : bool libspdm_verify_measurement_signature(libspdm_context_t *spdm_context,
      12                 :             :                                           libspdm_session_info_t *session_info,
      13                 :             :                                           uint8_t slot_id,
      14                 :             :                                           const void *sign_data,
      15                 :             :                                           size_t sign_data_size)
      16                 :             : {
      17                 :             :     bool result;
      18                 :             :     void *context;
      19                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
      20                 :             :     libspdm_l1l2_managed_buffer_t l1l2;
      21                 :             :     uint8_t *l1l2_buffer;
      22                 :             :     size_t l1l2_buffer_size;
      23                 :             : #if LIBSPDM_CERT_PARSE_SUPPORT
      24                 :             :     const uint8_t *cert_chain_data;
      25                 :             :     size_t cert_chain_data_size;
      26                 :             :     const uint8_t *cert_buffer;
      27                 :             :     size_t cert_buffer_size;
      28                 :             : #endif /* LIBSPDM_CERT_PARSE_SUPPORT */
      29                 :             : #else
      30                 :             :     uint8_t l1l2_hash[LIBSPDM_MAX_HASH_SIZE];
      31                 :             :     size_t l1l2_hash_size;
      32                 :             : #endif
      33                 :             : 
      34                 :          48 :     LIBSPDM_ASSERT((slot_id < SPDM_MAX_SLOT_COUNT) || (slot_id == 0xF));
      35                 :             : 
      36                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
      37                 :             :     result = libspdm_calculate_l1l2(spdm_context, session_info, &l1l2);
      38                 :             :     l1l2_buffer = libspdm_get_managed_buffer(&l1l2);
      39                 :             :     l1l2_buffer_size = libspdm_get_managed_buffer_size(&l1l2);
      40                 :             : #else
      41                 :          48 :     l1l2_hash_size = sizeof(l1l2_hash);
      42                 :          48 :     result = libspdm_calculate_l1l2_hash(spdm_context, session_info, &l1l2_hash_size, l1l2_hash);
      43                 :             : #endif
      44                 :             : 
      45                 :          48 :     libspdm_reset_message_m(spdm_context, session_info);
      46         [ -  + ]:          48 :     if (!result) {
      47                 :           0 :         return false;
      48                 :             :     }
      49                 :             : 
      50         [ +  + ]:          48 :     if (slot_id == 0xF) {
      51         [ -  + ]:           2 :         if (spdm_context->connection_info.algorithm.pqc_asym_algo != 0) {
      52                 :           0 :             result = libspdm_pqc_asym_get_public_key_from_der(
      53                 :             :                 spdm_context->connection_info.algorithm.pqc_asym_algo,
      54                 :           0 :                 spdm_context->local_context.peer_public_key_provision,
      55                 :             :                 spdm_context->local_context.peer_public_key_provision_size,
      56                 :             :                 &context);
      57                 :             :         } else {
      58                 :           2 :             result = libspdm_asym_get_public_key_from_der(
      59                 :             :                 spdm_context->connection_info.algorithm.base_asym_algo,
      60                 :           2 :                 spdm_context->local_context.peer_public_key_provision,
      61                 :             :                 spdm_context->local_context.peer_public_key_provision_size,
      62                 :             :                 &context);
      63                 :             :         }
      64         [ -  + ]:           2 :         if (!result) {
      65                 :           0 :             return false;
      66                 :             :         }
      67                 :             :     } else {
      68                 :             : #if (LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT) && (LIBSPDM_CERT_PARSE_SUPPORT)
      69                 :             :         libspdm_get_peer_cert_chain_data(
      70                 :             :             spdm_context, slot_id, (const void **)&cert_chain_data, &cert_chain_data_size);
      71                 :             : 
      72                 :             :         /* Get leaf cert from cert chain*/
      73                 :             :         result = libspdm_x509_get_cert_from_cert_chain(cert_chain_data,
      74                 :             :                                                        cert_chain_data_size, -1,
      75                 :             :                                                        &cert_buffer, &cert_buffer_size);
      76                 :             :         if (!result) {
      77                 :             :             return false;
      78                 :             :         }
      79                 :             : 
      80                 :             :         if (spdm_context->connection_info.algorithm.pqc_asym_algo != 0) {
      81                 :             :             result = libspdm_pqc_asym_get_public_key_from_x509(
      82                 :             :                 spdm_context->connection_info.algorithm.pqc_asym_algo,
      83                 :             :                 cert_buffer, cert_buffer_size, &context);
      84                 :             :         } else {
      85                 :             :             result = libspdm_asym_get_public_key_from_x509(
      86                 :             :                 spdm_context->connection_info.algorithm.base_asym_algo,
      87                 :             :                 cert_buffer, cert_buffer_size, &context);
      88                 :             :         }
      89                 :             :         if (!result) {
      90                 :             :             return false;
      91                 :             :         }
      92                 :             : #elif LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
      93                 :             :         return false;
      94                 :             : #else
      95                 :          46 :         context = spdm_context->connection_info.peer_used_cert_chain[slot_id].leaf_cert_public_key;
      96                 :          46 :         LIBSPDM_ASSERT(context != NULL);
      97                 :             : #endif
      98                 :             :     }
      99                 :             : 
     100                 :             : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     101                 :             :     if (spdm_context->connection_info.algorithm.pqc_asym_algo != 0) {
     102                 :             :         result = libspdm_pqc_asym_verify(
     103                 :             :             spdm_context->connection_info.version, SPDM_MEASUREMENTS,
     104                 :             :             spdm_context->connection_info.algorithm.pqc_asym_algo,
     105                 :             :             spdm_context->connection_info.algorithm.base_hash_algo,
     106                 :             :             context, l1l2_buffer, l1l2_buffer_size, sign_data, sign_data_size);
     107                 :             :         libspdm_pqc_asym_free(spdm_context->connection_info.algorithm.pqc_asym_algo, context);
     108                 :             :     } else {
     109                 :             :         result = libspdm_asym_verify_ex(
     110                 :             :             spdm_context->connection_info.version, SPDM_MEASUREMENTS,
     111                 :             :             spdm_context->connection_info.algorithm.base_asym_algo,
     112                 :             :             spdm_context->connection_info.algorithm.base_hash_algo,
     113                 :             :             context, l1l2_buffer, l1l2_buffer_size, sign_data, sign_data_size,
     114                 :             :             &spdm_context->spdm_10_11_verify_signature_endian);
     115                 :             :         libspdm_asym_free(spdm_context->connection_info.algorithm.base_asym_algo, context);
     116                 :             :     }
     117                 :             : #else
     118         [ -  + ]:          48 :     if (spdm_context->connection_info.algorithm.pqc_asym_algo != 0) {
     119                 :           0 :         result = libspdm_pqc_asym_verify_hash(
     120                 :           0 :             spdm_context->connection_info.version, SPDM_MEASUREMENTS,
     121                 :             :             spdm_context->connection_info.algorithm.pqc_asym_algo,
     122                 :             :             spdm_context->connection_info.algorithm.base_hash_algo,
     123                 :             :             context, l1l2_hash, l1l2_hash_size, sign_data, sign_data_size);
     124         [ #  # ]:           0 :         if (slot_id == 0xF) {
     125                 :           0 :             libspdm_pqc_asym_free(spdm_context->connection_info.algorithm.pqc_asym_algo, context);
     126                 :             :         }
     127                 :             :     } else {
     128                 :          48 :         result = libspdm_asym_verify_hash_ex(
     129                 :          48 :             spdm_context->connection_info.version, SPDM_MEASUREMENTS,
     130                 :             :             spdm_context->connection_info.algorithm.base_asym_algo,
     131                 :             :             spdm_context->connection_info.algorithm.base_hash_algo,
     132                 :             :             context, l1l2_hash, l1l2_hash_size, sign_data, sign_data_size,
     133                 :             :             &spdm_context->spdm_10_11_verify_signature_endian);
     134         [ +  + ]:          48 :         if (slot_id == 0xF) {
     135                 :           2 :             libspdm_asym_free(spdm_context->connection_info.algorithm.base_asym_algo, context);
     136                 :             :         }
     137                 :             :     }
     138                 :             : #endif
     139         [ +  + ]:          48 :     if (!result) {
     140                 :          18 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "!!! verify_measurement_signature - FAIL !!!\n"));
     141                 :          18 :         return false;
     142                 :             :     }
     143                 :             : 
     144                 :          30 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "!!! verify_measurement_signature - PASS !!!\n"));
     145                 :          30 :     return true;
     146                 :             : }
     147                 :             : 
     148                 :             : /**
     149                 :             :  * This function sends GET_MEASUREMENTS to get measurements from the device.
     150                 :             :  * If the signature is requested this function verifies the signature of the measurement.
     151                 :             :  *
     152                 :             :  * @param  spdm_context               A pointer to the SPDM context.
     153                 :             :  * @param  session_id                 Indicates if it is a secured message protected via SPDM session.
     154                 :             :  *                                    If session_id is NULL, it is a normal message.
     155                 :             :  *                                    If session_id is not NULL, it is a secured message.
     156                 :             :  * @param  request_attribute          The request attribute of the request message.
     157                 :             :  * @param  measurement_operation      The measurement operation of the request message.
     158                 :             :  * @param  slot_id_param              The number of slot for the certificate chain.
     159                 :             :  * @param  requester_context          If not NULL, a buffer to hold the requester context (8 bytes).
     160                 :             :  *                                    It is used only if the negotiated version >= 1.3.
     161                 :             :  * @param  content_changed            The measurement content changed output param.
     162                 :             :  * @param  number_of_blocks           The number of blocks of the measurement record.
     163                 :             :  * @param  measurement_record_length  On input, indicate the size in bytes of the destination buffer
     164                 :             :  *                                    to store the measurement record.
     165                 :             :  *                                    On output, indicate the size in bytes of the measurement record.
     166                 :             :  * @param  measurement_record         A pointer to a destination buffer to store the measurement record.
     167                 :             :  * @param  requester_nonce_in         If not NULL, a buffer that holds the requester nonce (32 bytes)
     168                 :             :  * @param  requester_nonce            If not NULL, a buffer to hold the requester nonce (32 bytes).
     169                 :             :  * @param  responder_nonce            If not NULL, a buffer to hold the responder nonce (32 bytes).
     170                 :             :  *
     171                 :             :  **/
     172                 :         634 : static libspdm_return_t libspdm_try_get_measurement(libspdm_context_t *spdm_context,
     173                 :             :                                                     const uint32_t *session_id,
     174                 :             :                                                     uint8_t request_attribute,
     175                 :             :                                                     uint8_t measurement_operation,
     176                 :             :                                                     uint8_t slot_id_param,
     177                 :             :                                                     const void *requester_context,
     178                 :             :                                                     uint8_t *content_changed,
     179                 :             :                                                     uint8_t *number_of_blocks,
     180                 :             :                                                     uint32_t *measurement_record_length,
     181                 :             :                                                     void *measurement_record,
     182                 :             :                                                     const void *requester_nonce_in,
     183                 :             :                                                     void *requester_nonce,
     184                 :             :                                                     void *responder_nonce,
     185                 :             :                                                     void *opaque_data,
     186                 :             :                                                     size_t *opaque_data_size)
     187                 :             : {
     188                 :             :     bool result;
     189                 :             :     libspdm_return_t status;
     190                 :             :     spdm_get_measurements_request_t *spdm_request;
     191                 :             :     size_t spdm_request_size;
     192                 :             :     spdm_measurements_response_t *spdm_response;
     193                 :             :     size_t spdm_response_size;
     194                 :             :     uint32_t measurement_record_data_length;
     195                 :             :     uint8_t *measurement_record_data;
     196                 :             :     spdm_measurement_block_common_header_t *measurement_block_header;
     197                 :             :     uint32_t measurement_block_size;
     198                 :             :     uint8_t measurement_block_count;
     199                 :             :     uint8_t *ptr;
     200                 :             :     void *nonce;
     201                 :             :     uint16_t opaque_length;
     202                 :             :     void *signature;
     203                 :             :     size_t signature_size;
     204                 :             :     libspdm_session_info_t *session_info;
     205                 :             :     libspdm_session_state_t session_state;
     206                 :             :     uint8_t *message;
     207                 :             :     size_t message_size;
     208                 :             :     size_t transport_header_size;
     209                 :             : 
     210                 :             :     /* -=[Check Parameters Phase]=- */
     211                 :         634 :     LIBSPDM_ASSERT((slot_id_param < SPDM_MAX_SLOT_COUNT) || (slot_id_param == 0xF));
     212                 :         634 :     LIBSPDM_ASSERT((slot_id_param != 0xf) ||
     213                 :             :                    (spdm_context->local_context.peer_public_key_provision_size != 0));
     214                 :             : 
     215                 :             :     /* -=[Verify State Phase]=- */
     216         [ +  + ]:         634 :     if (!libspdm_is_capabilities_flag_supported(
     217                 :             :             spdm_context, true, 0,
     218                 :             :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
     219                 :           2 :         return LIBSPDM_STATUS_UNSUPPORTED_CAP;
     220                 :             :     }
     221                 :             : 
     222                 :         632 :     LIBSPDM_ASSERT(spdm_context->local_context.algorithm.measurement_spec != 0);
     223                 :             : 
     224         [ +  + ]:         632 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
     225                 :           4 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
     226                 :             :     }
     227                 :             : 
     228         [ +  + ]:         628 :     if (session_id == NULL) {
     229                 :         622 :         session_info = NULL;
     230                 :             :     } else {
     231                 :           6 :         session_info = libspdm_get_session_info_via_session_id(spdm_context, *session_id);
     232         [ -  + ]:           6 :         if (session_info == NULL) {
     233                 :           0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
     234                 :             :         }
     235                 :           6 :         session_state = libspdm_secured_message_get_session_state(
     236                 :             :             session_info->secured_message_context);
     237         [ -  + ]:           6 :         if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
     238                 :           0 :             return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
     239                 :             :         }
     240                 :             :     }
     241                 :             : 
     242         [ +  + ]:         628 :     if (libspdm_is_capabilities_flag_supported(
     243                 :             :             spdm_context, true, 0,
     244                 :           6 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG) &&
     245         [ +  + ]:           6 :         ((request_attribute & SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0)) {
     246                 :           2 :         return LIBSPDM_STATUS_INVALID_PARAMETER;
     247                 :             :     }
     248                 :             : 
     249         [ +  + ]:         626 :     if ((request_attribute & SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0) {
     250         [ -  + ]:         154 :         if (spdm_context->connection_info.algorithm.pqc_asym_algo != 0) {
     251                 :           0 :             signature_size = libspdm_get_pqc_asym_signature_size(
     252                 :             :                 spdm_context->connection_info.algorithm.pqc_asym_algo);
     253                 :             :         } else {
     254                 :         154 :             signature_size = libspdm_get_asym_signature_size(
     255                 :             :                 spdm_context->connection_info.algorithm.base_asym_algo);
     256                 :             :         }
     257                 :             :     } else {
     258                 :         472 :         signature_size = 0;
     259                 :             :     }
     260                 :             : 
     261                 :         626 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL, SPDM_GET_MEASUREMENTS);
     262                 :             : 
     263                 :             :     /* -=[Construct Request Phase]=- */
     264                 :         626 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
     265                 :         626 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
     266         [ +  + ]:         626 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     267                 :           2 :         return status;
     268                 :             :     }
     269                 :         624 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
     270                 :             :                     spdm_context->local_context.capability.transport_tail_size);
     271                 :         624 :     spdm_request = (void *)(message + transport_header_size);
     272                 :         624 :     spdm_request_size = message_size - transport_header_size -
     273                 :         624 :                         spdm_context->local_context.capability.transport_tail_size;
     274                 :             : 
     275                 :         624 :     LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_request->header));
     276                 :         624 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
     277                 :         624 :     spdm_request->header.request_response_code = SPDM_GET_MEASUREMENTS;
     278                 :         624 :     spdm_request->header.param1 = request_attribute;
     279                 :         624 :     spdm_request->header.param2 = measurement_operation;
     280         [ +  + ]:         624 :     if ((request_attribute & SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0) {
     281         [ -  + ]:         154 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     282                 :           0 :             LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_get_measurements_request_t) +
     283                 :             :                             SPDM_REQ_CONTEXT_SIZE);
     284                 :           0 :             spdm_request_size = sizeof(spdm_get_measurements_request_t) + SPDM_REQ_CONTEXT_SIZE;
     285         [ +  - ]:         154 :         } else if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
     286                 :         154 :             LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_get_measurements_request_t));
     287                 :         154 :             spdm_request_size = sizeof(spdm_get_measurements_request_t);
     288                 :             :         } else {
     289                 :           0 :             LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_get_measurements_request_t) -
     290                 :             :                             sizeof(spdm_request->slot_id_param));
     291                 :           0 :             spdm_request_size = sizeof(spdm_get_measurements_request_t) -
     292                 :             :                                 sizeof(spdm_request->slot_id_param);
     293                 :             :         }
     294                 :             : 
     295         [ +  + ]:         154 :         if (requester_nonce_in == NULL) {
     296         [ -  + ]:         150 :             if (!libspdm_get_random_number(SPDM_NONCE_SIZE, spdm_request->nonce)) {
     297                 :           0 :                 libspdm_release_sender_buffer (spdm_context);
     298                 :           0 :                 return LIBSPDM_STATUS_LOW_ENTROPY;
     299                 :             :             }
     300                 :             :         } else {
     301                 :           4 :             libspdm_copy_mem(spdm_request->nonce, sizeof(spdm_request->nonce),
     302                 :             :                              requester_nonce_in, SPDM_NONCE_SIZE);
     303                 :             :         }
     304                 :         154 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterNonce - "));
     305                 :         154 :         LIBSPDM_INTERNAL_DUMP_DATA(spdm_request->nonce, SPDM_NONCE_SIZE);
     306                 :         154 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
     307                 :         154 :         spdm_request->slot_id_param = slot_id_param;
     308                 :             : 
     309         [ +  + ]:         154 :         if (requester_nonce != NULL) {
     310                 :           4 :             libspdm_copy_mem(requester_nonce, SPDM_NONCE_SIZE,
     311                 :           4 :                              spdm_request->nonce, SPDM_NONCE_SIZE);
     312                 :             :         }
     313                 :             :     } else {
     314         [ +  + ]:         470 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     315                 :           4 :             LIBSPDM_ASSERT (spdm_request_size >= sizeof(spdm_request->header) +
     316                 :             :                             SPDM_REQ_CONTEXT_SIZE);
     317                 :           4 :             spdm_request_size = sizeof(spdm_request->header) + SPDM_REQ_CONTEXT_SIZE;
     318                 :             :         } else {
     319                 :         466 :             spdm_request_size = sizeof(spdm_request->header);
     320                 :             :         }
     321                 :             : 
     322         [ -  + ]:         470 :         if (requester_nonce != NULL) {
     323                 :           0 :             libspdm_zero_mem (requester_nonce, SPDM_NONCE_SIZE);
     324                 :             :         }
     325                 :             :     }
     326         [ +  + ]:         624 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     327         [ -  + ]:           4 :         if (requester_context == NULL) {
     328                 :           0 :             libspdm_zero_mem((uint8_t *)spdm_request + spdm_request_size - SPDM_REQ_CONTEXT_SIZE,
     329                 :             :                              SPDM_REQ_CONTEXT_SIZE);
     330                 :             :         } else {
     331                 :           4 :             libspdm_copy_mem((uint8_t *)spdm_request + spdm_request_size - SPDM_REQ_CONTEXT_SIZE,
     332                 :             :                              SPDM_REQ_CONTEXT_SIZE,
     333                 :             :                              requester_context, SPDM_REQ_CONTEXT_SIZE);
     334                 :             :         }
     335                 :           4 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterContext - "));
     336                 :           4 :         LIBSPDM_INTERNAL_DUMP_DATA((uint8_t *)spdm_request + spdm_request_size -
     337                 :             :                                    SPDM_REQ_CONTEXT_SIZE,
     338                 :             :                                    SPDM_REQ_CONTEXT_SIZE);
     339                 :           4 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
     340                 :             :     }
     341                 :             : 
     342                 :             :     /* -=[Send Request Phase]=- */
     343                 :         624 :     status = libspdm_send_spdm_request(spdm_context, session_id, spdm_request_size, spdm_request);
     344         [ +  + ]:         624 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     345                 :           4 :         libspdm_release_sender_buffer (spdm_context);
     346                 :           4 :         return status;
     347                 :             :     }
     348                 :         620 :     libspdm_release_sender_buffer (spdm_context);
     349                 :         620 :     spdm_request = (void *)spdm_context->last_spdm_request;
     350                 :             : 
     351                 :             :     /* -=[Receive Response Phase]=- */
     352                 :         620 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
     353         [ +  + ]:         620 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     354                 :           2 :         return status;
     355                 :             :     }
     356                 :         618 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
     357                 :         618 :     spdm_response = (void *)(message);
     358                 :         618 :     spdm_response_size = message_size;
     359                 :             : 
     360                 :         618 :     status = libspdm_receive_spdm_response(
     361                 :             :         spdm_context, session_id, &spdm_response_size, (void **)&spdm_response);
     362         [ +  + ]:         618 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     363                 :           2 :         goto receive_done;
     364                 :             :     }
     365                 :             : 
     366                 :             :     /* -=[Validate Response Phase]=- */
     367         [ -  + ]:         616 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
     368                 :           0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     369                 :           0 :         goto receive_done;
     370                 :             :     }
     371         [ +  + ]:         616 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
     372                 :          92 :         status = libspdm_handle_error_response_main(
     373                 :             :             spdm_context, session_id,
     374                 :             :             &spdm_response_size, (void **)&spdm_response,
     375                 :             :             SPDM_GET_MEASUREMENTS, SPDM_MEASUREMENTS);
     376         [ +  + ]:          92 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     377                 :          90 :             goto receive_done;
     378                 :             :         }
     379         [ +  + ]:         524 :     } else if (spdm_response->header.request_response_code != SPDM_MEASUREMENTS) {
     380                 :           4 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     381                 :           4 :         goto receive_done;
     382                 :             :     }
     383         [ +  + ]:         522 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
     384                 :          10 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     385                 :          10 :         goto receive_done;
     386                 :             :     }
     387         [ -  + ]:         512 :     if (spdm_response_size < sizeof(spdm_measurements_response_t)) {
     388                 :           0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     389                 :           0 :         goto receive_done;
     390                 :             :     }
     391         [ +  + ]:         512 :     if (measurement_operation ==
     392                 :             :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS) {
     393         [ +  + ]:          18 :         if (spdm_response->number_of_blocks != 0) {
     394                 :           8 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     395                 :           8 :             goto receive_done;
     396                 :             :         }
     397         [ +  + ]:         494 :     } else if (measurement_operation ==
     398                 :             :                SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS) {
     399   [ +  -  -  + ]:           6 :         if ((spdm_response->number_of_blocks == 0) || (spdm_response->number_of_blocks == 0xff)) {
     400                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     401                 :           0 :             goto receive_done;
     402                 :             :         }
     403                 :             :     } else {
     404         [ -  + ]:         488 :         if (spdm_response->number_of_blocks != 1) {
     405                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     406                 :           0 :             goto receive_done;
     407                 :             :         }
     408                 :             :     }
     409                 :             : 
     410                 :         504 :     measurement_record_data_length = libspdm_read_uint24(spdm_response->measurement_record_length);
     411         [ +  + ]:         504 :     if (measurement_operation ==
     412                 :             :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS) {
     413         [ +  + ]:          10 :         if (measurement_record_data_length != 0) {
     414                 :           4 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     415                 :           4 :             goto receive_done;
     416                 :             :         }
     417                 :             :     } else {
     418                 :         494 :         if (spdm_response_size <
     419         [ -  + ]:         494 :             sizeof(spdm_measurements_response_t) +
     420                 :             :             measurement_record_data_length) {
     421                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     422                 :           0 :             goto receive_done;
     423                 :             :         }
     424                 :         494 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "measurement_record_length - 0x%06x\n",
     425                 :             :                        measurement_record_data_length));
     426                 :             :     }
     427                 :             : 
     428                 :         500 :     measurement_record_data = (void *)(spdm_response + 1);
     429                 :             : 
     430         [ +  + ]:         500 :     if ((request_attribute & SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0) {
     431                 :          52 :         if (spdm_response_size <
     432                 :             :             sizeof(spdm_measurements_response_t) +
     433         [ -  + ]:          52 :             measurement_record_data_length + SPDM_NONCE_SIZE + sizeof(uint16_t)) {
     434                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     435                 :           0 :             goto receive_done;
     436                 :             :         }
     437         [ +  - ]:          52 :         if ((spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_11) &&
     438                 :          52 :             ((spdm_response->header.param2 & SPDM_MEASUREMENTS_RESPONSE_SLOT_ID_MASK)
     439         [ +  + ]:          52 :              != slot_id_param)) {
     440                 :           6 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     441                 :           6 :             goto receive_done;
     442                 :             :         }
     443                 :          46 :         ptr = measurement_record_data + measurement_record_data_length;
     444                 :          46 :         nonce = ptr;
     445                 :          46 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "nonce (0x%x) - ", SPDM_NONCE_SIZE));
     446                 :          46 :         LIBSPDM_INTERNAL_DUMP_DATA(nonce, SPDM_NONCE_SIZE);
     447                 :          46 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
     448                 :          46 :         ptr += SPDM_NONCE_SIZE;
     449         [ +  + ]:          46 :         if (responder_nonce != NULL) {
     450                 :           4 :             libspdm_copy_mem(responder_nonce, SPDM_NONCE_SIZE, nonce, SPDM_NONCE_SIZE);
     451                 :             :         }
     452                 :             : 
     453                 :          46 :         opaque_length = libspdm_read_uint16((const uint8_t *)ptr);
     454         [ -  + ]:          46 :         if (opaque_length > SPDM_MAX_OPAQUE_DATA_SIZE) {
     455                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     456                 :           0 :             goto receive_done;
     457                 :             :         }
     458         [ +  + ]:          46 :         if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
     459         [ +  + ]:           6 :             if (((spdm_context->connection_info.algorithm.other_params_support &
     460                 :             :                   SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) ==
     461                 :             :                  SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE)
     462         [ -  + ]:           4 :                 && (opaque_length != 0)) {
     463                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     464                 :           0 :                 goto receive_done;
     465                 :             :             }
     466                 :             :         }
     467                 :          46 :         ptr += sizeof(uint16_t);
     468                 :          46 :         if (spdm_response_size <
     469                 :             :             sizeof(spdm_measurements_response_t) + measurement_record_data_length +
     470         [ +  + ]:          46 :             SPDM_NONCE_SIZE + sizeof(uint16_t) + opaque_length) {
     471                 :           4 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     472                 :           4 :             goto receive_done;
     473                 :             :         }
     474         [ +  + ]:          42 :         if (opaque_length != 0) {
     475                 :          14 :             result = libspdm_process_general_opaque_data_check(spdm_context, opaque_length, ptr);
     476         [ -  + ]:          14 :             if (!result) {
     477                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     478                 :           0 :                 goto receive_done;
     479                 :             :             }
     480                 :             :         }
     481                 :             : 
     482         [ -  + ]:          42 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     483                 :           0 :             if (spdm_response_size <
     484                 :             :                 sizeof(spdm_measurements_response_t) +
     485                 :             :                 measurement_record_data_length + SPDM_NONCE_SIZE +
     486         [ #  # ]:           0 :                 sizeof(uint16_t) + opaque_length + SPDM_REQ_CONTEXT_SIZE + signature_size) {
     487                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     488                 :           0 :                 goto receive_done;
     489                 :             :             }
     490                 :           0 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
     491                 :             :                                  measurement_record_data_length +
     492                 :           0 :                                  SPDM_NONCE_SIZE + sizeof(uint16_t) +
     493                 :           0 :                                  opaque_length + SPDM_REQ_CONTEXT_SIZE + signature_size;
     494                 :             :         } else {
     495                 :          42 :             if (spdm_response_size <
     496                 :             :                 sizeof(spdm_measurements_response_t) +
     497                 :             :                 measurement_record_data_length + SPDM_NONCE_SIZE +
     498         [ +  + ]:          42 :                 sizeof(uint16_t) + opaque_length + signature_size) {
     499                 :           8 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     500                 :           8 :                 goto receive_done;
     501                 :             :             }
     502                 :          34 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
     503                 :             :                                  measurement_record_data_length +
     504                 :          34 :                                  SPDM_NONCE_SIZE + sizeof(uint16_t) +
     505                 :          34 :                                  opaque_length + signature_size;
     506                 :             :         }
     507                 :             : 
     508   [ +  +  +  - ]:          34 :         if ((opaque_data != NULL) && (opaque_data_size != NULL)) {
     509         [ -  + ]:           4 :             if (opaque_length > *opaque_data_size) {
     510                 :           0 :                 status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
     511                 :           0 :                 goto receive_done;
     512                 :             :             }
     513                 :           4 :             libspdm_copy_mem(opaque_data, *opaque_data_size, ptr, opaque_length);
     514                 :           4 :             *opaque_data_size = opaque_length;
     515                 :             :         }
     516                 :          34 :         ptr += opaque_length;
     517         [ -  + ]:          34 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     518                 :           0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterContext - "));
     519                 :           0 :             LIBSPDM_INTERNAL_DUMP_DATA(ptr, SPDM_REQ_CONTEXT_SIZE);
     520                 :           0 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
     521         [ #  # ]:           0 :             if (!libspdm_consttime_is_mem_equal((uint8_t *)spdm_request +
     522                 :           0 :                                                 spdm_request_size - SPDM_REQ_CONTEXT_SIZE,
     523                 :             :                                                 ptr, SPDM_REQ_CONTEXT_SIZE)) {
     524                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     525                 :           0 :                 goto receive_done;
     526                 :             :             }
     527                 :           0 :             ptr += SPDM_REQ_CONTEXT_SIZE;
     528                 :             :         }
     529                 :             : 
     530                 :             :         /* -=[Process Response Phase]=- */
     531                 :          34 :         status = libspdm_append_message_m(spdm_context, session_info, spdm_request,
     532                 :             :                                           spdm_request_size);
     533         [ -  + ]:          34 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     534                 :           0 :             goto receive_done;
     535                 :             :         }
     536                 :             : 
     537                 :          34 :         status = libspdm_append_message_m(spdm_context, session_info, spdm_response,
     538                 :             :                                           spdm_response_size - signature_size);
     539         [ -  + ]:          34 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     540                 :           0 :             goto receive_done;
     541                 :             :         }
     542                 :             : 
     543                 :          34 :         signature = ptr;
     544                 :          34 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "signature (0x%zx):\n", signature_size));
     545                 :          34 :         LIBSPDM_INTERNAL_DUMP_HEX(signature, signature_size);
     546                 :             : 
     547                 :          34 :         result = libspdm_verify_measurement_signature(
     548                 :             :             spdm_context, session_info, slot_id_param, signature, signature_size);
     549         [ +  + ]:          34 :         if (!result) {
     550                 :          14 :             status = LIBSPDM_STATUS_VERIF_FAIL;
     551                 :          14 :             goto receive_done;
     552                 :             :         }
     553                 :             : 
     554                 :          20 :         libspdm_reset_message_m(spdm_context, session_info);
     555                 :             :     } else {
     556                 :         448 :         if (spdm_response_size <
     557                 :             :             sizeof(spdm_measurements_response_t) +
     558         [ -  + ]:         448 :             measurement_record_data_length + SPDM_NONCE_SIZE + sizeof(uint16_t)) {
     559                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     560                 :           0 :             goto receive_done;
     561                 :             :         }
     562                 :         448 :         ptr = measurement_record_data + measurement_record_data_length;
     563                 :             : 
     564                 :         448 :         nonce = ptr;
     565                 :         448 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "nonce (0x%x) - ", SPDM_NONCE_SIZE));
     566                 :         448 :         LIBSPDM_INTERNAL_DUMP_DATA(nonce, SPDM_NONCE_SIZE);
     567                 :         448 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
     568                 :         448 :         ptr += SPDM_NONCE_SIZE;
     569         [ -  + ]:         448 :         if (responder_nonce != NULL) {
     570                 :           0 :             libspdm_copy_mem(responder_nonce, SPDM_NONCE_SIZE, nonce, SPDM_NONCE_SIZE);
     571                 :             :         }
     572                 :             : 
     573                 :         448 :         opaque_length = libspdm_read_uint16((const uint8_t *)ptr);
     574         [ +  + ]:         448 :         if (opaque_length > SPDM_MAX_OPAQUE_DATA_SIZE) {
     575                 :           4 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     576                 :           4 :             goto receive_done;
     577                 :             :         }
     578                 :         444 :         ptr += sizeof(uint16_t);
     579                 :         444 :         if (spdm_response_size <
     580                 :             :             sizeof(spdm_measurements_response_t) + measurement_record_data_length +
     581         [ -  + ]:         444 :             SPDM_NONCE_SIZE + sizeof(uint16_t) + opaque_length) {
     582                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     583                 :           0 :             goto receive_done;
     584                 :             :         }
     585         [ +  + ]:         444 :         if (opaque_length != 0) {
     586                 :           6 :             result = libspdm_process_general_opaque_data_check(spdm_context, opaque_length, ptr);
     587         [ -  + ]:           6 :             if (!result) {
     588                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     589                 :           0 :                 goto receive_done;
     590                 :             :             }
     591                 :             :         }
     592                 :             : 
     593         [ +  + ]:         444 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     594                 :           4 :             if (spdm_response_size <
     595                 :             :                 sizeof(spdm_measurements_response_t) +
     596                 :             :                 measurement_record_data_length + SPDM_NONCE_SIZE +
     597         [ -  + ]:           4 :                 sizeof(uint16_t) + opaque_length + SPDM_REQ_CONTEXT_SIZE) {
     598                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     599                 :           0 :                 goto receive_done;
     600                 :             :             }
     601                 :           4 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
     602                 :             :                                  measurement_record_data_length +
     603                 :           4 :                                  SPDM_NONCE_SIZE + sizeof(uint16_t) +
     604                 :           4 :                                  opaque_length + SPDM_REQ_CONTEXT_SIZE;
     605                 :             :         } else {
     606                 :         440 :             if (spdm_response_size <
     607                 :             :                 sizeof(spdm_measurements_response_t) +
     608                 :             :                 measurement_record_data_length + SPDM_NONCE_SIZE +
     609         [ -  + ]:         440 :                 sizeof(uint16_t) + opaque_length) {
     610                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     611                 :           0 :                 goto receive_done;
     612                 :             :             }
     613                 :         440 :             spdm_response_size = sizeof(spdm_measurements_response_t) +
     614                 :             :                                  measurement_record_data_length +
     615                 :         440 :                                  SPDM_NONCE_SIZE + sizeof(uint16_t) +
     616                 :             :                                  opaque_length;
     617                 :             :         }
     618                 :             : 
     619   [ +  +  +  - ]:         444 :         if ((opaque_data != NULL) && (opaque_data_size != NULL)) {
     620         [ -  + ]:           6 :             if (opaque_length > *opaque_data_size) {
     621                 :           0 :                 status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
     622                 :           0 :                 goto receive_done;
     623                 :             :             }
     624                 :           6 :             libspdm_copy_mem(opaque_data, *opaque_data_size, ptr, opaque_length);
     625                 :           6 :             *opaque_data_size = opaque_length;
     626                 :             :         }
     627                 :         444 :         ptr += opaque_length;
     628         [ +  + ]:         444 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     629                 :           4 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequesterContext - "));
     630                 :           4 :             LIBSPDM_INTERNAL_DUMP_DATA(ptr, SPDM_REQ_CONTEXT_SIZE);
     631                 :           4 :             LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
     632         [ +  + ]:           4 :             if (!libspdm_consttime_is_mem_equal((uint8_t *)spdm_request +
     633                 :           4 :                                                 spdm_request_size - SPDM_REQ_CONTEXT_SIZE,
     634                 :             :                                                 ptr, SPDM_REQ_CONTEXT_SIZE)) {
     635                 :           2 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     636                 :           2 :                 goto receive_done;
     637                 :             :             }
     638                 :           2 :             ptr += SPDM_REQ_CONTEXT_SIZE;
     639                 :             :         }
     640                 :             : 
     641                 :             :         /* If a signature is not requested then content_changed must be 0. */
     642         [ +  + ]:         442 :         if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
     643         [ +  + ]:          10 :             if ((spdm_response->header.param2 & SPDM_MEASUREMENTS_RESPONSE_CONTENT_CHANGE_MASK)
     644                 :             :                 != 0) {
     645                 :           2 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     646                 :           2 :                 goto receive_done;
     647                 :             :             }
     648                 :             :         }
     649                 :             : 
     650                 :         440 :         status = libspdm_append_message_m(spdm_context, session_info, spdm_request,
     651                 :             :                                           spdm_request_size);
     652         [ -  + ]:         440 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     653                 :           0 :             goto receive_done;
     654                 :             :         }
     655                 :             : 
     656                 :         440 :         status = libspdm_append_message_m(spdm_context, session_info, spdm_response,
     657                 :             :                                           spdm_response_size);
     658         [ -  + ]:         440 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     659                 :           0 :             goto receive_done;
     660                 :             :         }
     661                 :             :     }
     662                 :             : 
     663         [ +  + ]:         460 :     if (content_changed != NULL) {
     664                 :           2 :         *content_changed = 0;
     665         [ +  - ]:           2 :         if ((spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) &&
     666         [ -  + ]:           2 :             ((request_attribute &
     667                 :             :               SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0)) {
     668                 :           0 :             *content_changed =
     669                 :           0 :                 (spdm_response->header.param2 & SPDM_MEASUREMENTS_RESPONSE_CONTENT_CHANGE_MASK);
     670                 :             :         }
     671                 :             :     }
     672         [ +  + ]:         460 :     if (measurement_operation ==
     673                 :             :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS) {
     674                 :           6 :         *number_of_blocks = spdm_response->header.param1;
     675         [ -  + ]:           6 :         if (*number_of_blocks == 0xFF) {
     676                 :             :             /* the number of block cannot be 0xFF, because index 0xFF will brings confusing.*/
     677                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     678                 :           0 :             goto receive_done;
     679                 :             :         }
     680         [ -  + ]:           6 :         if (*number_of_blocks == 0x0) {
     681                 :             :             /* the number of block cannot be 0x0, because a responder without measurement should clear capability flags.*/
     682                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     683                 :           0 :             goto receive_done;
     684                 :             :         }
     685                 :             :     } else {
     686                 :         454 :         *number_of_blocks = spdm_response->number_of_blocks;
     687         [ -  + ]:         454 :         if (*measurement_record_length < measurement_record_data_length) {
     688                 :           0 :             status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
     689                 :           0 :             goto receive_done;
     690                 :             :         }
     691         [ -  + ]:         454 :         if (measurement_record_data_length < sizeof(spdm_measurement_block_common_header_t)) {
     692                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     693                 :           0 :             goto receive_done;
     694                 :             :         }
     695                 :             : 
     696                 :         454 :         measurement_block_size = 0;
     697                 :         454 :         measurement_block_count = 1;
     698         [ +  + ]:         900 :         while (measurement_block_size < measurement_record_data_length) {
     699                 :         458 :             measurement_block_header =
     700                 :         458 :                 (spdm_measurement_block_common_header_t *)&measurement_record_data
     701                 :             :                 [measurement_block_size];
     702                 :         458 :             if (measurement_block_header->measurement_size >
     703                 :         458 :                 measurement_record_data_length -
     704         [ -  + ]:         458 :                 ((uint8_t *)measurement_block_header -
     705                 :             :                  (uint8_t *)measurement_record_data)) {
     706                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     707                 :           0 :                 goto receive_done;
     708                 :             :             }
     709         [ +  - ]:         458 :             if (measurement_block_header->measurement_specification == 0 ||
     710                 :         458 :                 (measurement_block_header->measurement_specification &
     711         [ +  + ]:         458 :                  (measurement_block_header->measurement_specification - 1))) {
     712                 :           8 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     713                 :           8 :                 goto receive_done;
     714                 :             :             }
     715                 :         450 :             if (measurement_block_header->measurement_specification !=
     716         [ +  + ]:         450 :                 spdm_context->connection_info.algorithm.measurement_spec) {
     717                 :           4 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     718                 :           4 :                 goto receive_done;
     719                 :             :             }
     720   [ +  -  -  + ]:         446 :             if (measurement_block_header->index == 0 || measurement_block_header->index == 0xFF) {
     721                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     722                 :           0 :                 goto receive_done;
     723                 :             :             }
     724         [ +  + ]:         446 :             if (measurement_operation !=
     725                 :             :                 SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS) {
     726         [ -  + ]:         436 :                 if (measurement_block_header->index != measurement_operation) {
     727                 :           0 :                     status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     728                 :           0 :                     goto receive_done;
     729                 :             :                 }
     730                 :             :             }
     731         [ -  + ]:         446 :             if (measurement_block_count > *number_of_blocks) {
     732                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     733                 :           0 :                 goto receive_done;
     734                 :             :             }
     735                 :         446 :             measurement_block_count++;
     736                 :         446 :             measurement_block_size = (uint32_t)(
     737                 :             :                 measurement_block_size +
     738                 :         446 :                 sizeof(spdm_measurement_block_common_header_t) +
     739                 :         446 :                 measurement_block_header->measurement_size);
     740                 :             :         }
     741                 :             : 
     742         [ -  + ]:         442 :         if (measurement_block_size != measurement_record_data_length) {
     743                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     744                 :           0 :             goto receive_done;
     745                 :             :         }
     746                 :             : 
     747                 :         442 :         *measurement_record_length = measurement_record_data_length;
     748                 :         442 :         libspdm_copy_mem(measurement_record,
     749                 :             :                          measurement_record_data_length,
     750                 :             :                          measurement_record_data,
     751                 :             :                          measurement_record_data_length);
     752                 :             :     }
     753                 :             : 
     754                 :         448 :     status = LIBSPDM_STATUS_SUCCESS;
     755                 :             : 
     756                 :             :     /* -=[Log Message Phase]=- */
     757                 :             :     #if LIBSPDM_ENABLE_MSG_LOG
     758                 :         448 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
     759                 :             :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
     760                 :             : 
     761                 :         618 : receive_done:
     762   [ +  +  +  + ]:         618 :     if ((status != LIBSPDM_STATUS_SUCCESS) &&
     763                 :             :         (status != LIBSPDM_STATUS_NOT_READY_PEER)) {
     764                 :         166 :         libspdm_reset_message_m(spdm_context, session_info);
     765                 :             :     }
     766                 :         618 :     libspdm_release_receiver_buffer (spdm_context);
     767                 :         618 :     return status;
     768                 :             : }
     769                 :             : 
     770                 :         614 : libspdm_return_t libspdm_get_measurement(void *spdm_context, const uint32_t *session_id,
     771                 :             :                                          uint8_t request_attribute,
     772                 :             :                                          uint8_t measurement_operation,
     773                 :             :                                          uint8_t slot_id_param,
     774                 :             :                                          uint8_t *content_changed,
     775                 :             :                                          uint8_t *number_of_blocks,
     776                 :             :                                          uint32_t *measurement_record_length,
     777                 :             :                                          void *measurement_record)
     778                 :             : {
     779                 :             :     libspdm_context_t *context;
     780                 :             :     size_t retry;
     781                 :             :     uint64_t retry_delay_time;
     782                 :             :     libspdm_return_t status;
     783                 :             : 
     784                 :         614 :     context = spdm_context;
     785                 :         614 :     context->crypto_request = true;
     786                 :         614 :     retry = context->retry_times;
     787                 :         614 :     retry_delay_time = context->retry_delay_time;
     788                 :             :     do {
     789                 :         616 :         status = libspdm_try_get_measurement(
     790                 :             :             context, session_id, request_attribute,
     791                 :             :             measurement_operation, slot_id_param, NULL, content_changed, number_of_blocks,
     792                 :             :             measurement_record_length, measurement_record,
     793                 :             :             NULL, NULL, NULL, NULL, NULL);
     794         [ +  + ]:         616 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
     795                 :         610 :             return status;
     796                 :             :         }
     797                 :             : 
     798                 :           6 :         libspdm_sleep(retry_delay_time);
     799         [ +  + ]:           6 :     } while (retry-- != 0);
     800                 :             : 
     801                 :           4 :     return status;
     802                 :             : }
     803                 :             : 
     804                 :          14 : libspdm_return_t libspdm_get_measurement_ex(void *spdm_context, const uint32_t *session_id,
     805                 :             :                                             uint8_t request_attribute,
     806                 :             :                                             uint8_t measurement_operation,
     807                 :             :                                             uint8_t slot_id_param,
     808                 :             :                                             uint8_t *content_changed,
     809                 :             :                                             uint8_t *number_of_blocks,
     810                 :             :                                             uint32_t *measurement_record_length,
     811                 :             :                                             void *measurement_record,
     812                 :             :                                             const void *requester_nonce_in,
     813                 :             :                                             void *requester_nonce,
     814                 :             :                                             void *responder_nonce,
     815                 :             :                                             void *opaque_data,
     816                 :             :                                             size_t *opaque_data_size)
     817                 :             : {
     818                 :             :     libspdm_context_t *context;
     819                 :             :     size_t retry;
     820                 :             :     uint64_t retry_delay_time;
     821                 :             :     libspdm_return_t status;
     822                 :             : 
     823                 :          14 :     context = spdm_context;
     824                 :          14 :     context->crypto_request = true;
     825                 :          14 :     retry = context->retry_times;
     826                 :          14 :     retry_delay_time = context->retry_delay_time;
     827                 :             :     do {
     828                 :          14 :         status = libspdm_try_get_measurement(
     829                 :             :             context, session_id, request_attribute,
     830                 :             :             measurement_operation, slot_id_param, NULL, content_changed, number_of_blocks,
     831                 :             :             measurement_record_length, measurement_record,
     832                 :             :             requester_nonce_in,
     833                 :             :             requester_nonce, responder_nonce,
     834                 :             :             opaque_data, opaque_data_size);
     835         [ +  - ]:          14 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
     836                 :          14 :             return status;
     837                 :             :         }
     838                 :             : 
     839                 :           0 :         libspdm_sleep(retry_delay_time);
     840         [ #  # ]:           0 :     } while (retry-- != 0);
     841                 :             : 
     842                 :           0 :     return status;
     843                 :             : }
     844                 :             : 
     845                 :           4 : libspdm_return_t libspdm_get_measurement_ex2(void *spdm_context, const uint32_t *session_id,
     846                 :             :                                              uint8_t request_attribute,
     847                 :             :                                              uint8_t measurement_operation,
     848                 :             :                                              uint8_t slot_id_param,
     849                 :             :                                              const void *requester_context,
     850                 :             :                                              uint8_t *content_changed,
     851                 :             :                                              uint8_t *number_of_blocks,
     852                 :             :                                              uint32_t *measurement_record_length,
     853                 :             :                                              void *measurement_record,
     854                 :             :                                              const void *requester_nonce_in,
     855                 :             :                                              void *requester_nonce,
     856                 :             :                                              void *responder_nonce,
     857                 :             :                                              void *opaque_data,
     858                 :             :                                              size_t *opaque_data_size)
     859                 :             : {
     860                 :             :     libspdm_context_t *context;
     861                 :             :     size_t retry;
     862                 :             :     uint64_t retry_delay_time;
     863                 :             :     libspdm_return_t status;
     864                 :             : 
     865                 :           4 :     context = spdm_context;
     866                 :           4 :     context->crypto_request = true;
     867                 :           4 :     retry = context->retry_times;
     868                 :           4 :     retry_delay_time = context->retry_delay_time;
     869                 :             :     do {
     870                 :           4 :         status = libspdm_try_get_measurement(
     871                 :             :             context, session_id, request_attribute,
     872                 :             :             measurement_operation, slot_id_param, requester_context,
     873                 :             :             content_changed, number_of_blocks,
     874                 :             :             measurement_record_length, measurement_record,
     875                 :             :             requester_nonce_in,
     876                 :             :             requester_nonce, responder_nonce,
     877                 :             :             opaque_data, opaque_data_size);
     878         [ +  - ]:           4 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
     879                 :           4 :             return status;
     880                 :             :         }
     881                 :             : 
     882                 :           0 :         libspdm_sleep(retry_delay_time);
     883         [ #  # ]:           0 :     } while (retry-- != 0);
     884                 :             : 
     885                 :           0 :     return status;
     886                 :             : }
     887                 :             : 
     888                 :             : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
        

Generated by: LCOV version 2.0-1