Code coverage report for DMTF/libspdm
Current view: top level - library/spdm_requester_lib - libspdm_req_negotiate_algorithms.c (source / functions) Coverage Total Hit
Test: b3f7d2e00db5b07cf17ccc0075121f9c08f2965b Lines: 87.2 % 468 408
Test Date: 2026-11-29 08:33:56 Functions: 100.0 % 2 2
Branches: 81.7 % 279 228

             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                 :             : #pragma pack(1)
      10                 :             : typedef struct {
      11                 :             :     spdm_message_header_t header;
      12                 :             :     uint16_t length;
      13                 :             :     uint8_t measurement_specification;
      14                 :             :     uint8_t other_params_support;
      15                 :             :     uint32_t base_asym_algo;
      16                 :             :     uint32_t base_hash_algo;
      17                 :             :     uint32_t pqc_asym_algo;
      18                 :             :     uint8_t reserved2[8];
      19                 :             :     uint8_t ext_asym_count;
      20                 :             :     uint8_t ext_hash_count;
      21                 :             :     uint8_t reserved3;
      22                 :             :     uint8_t mel_specification;
      23                 :             :     spdm_negotiate_algorithms_common_struct_table_t struct_table[
      24                 :             :         SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG_14];
      25                 :             : } libspdm_negotiate_algorithms_request_mine_t;
      26                 :             : 
      27                 :             : typedef struct {
      28                 :             :     spdm_message_header_t header;
      29                 :             :     uint16_t length;
      30                 :             :     uint8_t measurement_specification_sel;
      31                 :             :     uint8_t other_params_selection;
      32                 :             :     uint32_t measurement_hash_algo;
      33                 :             :     uint32_t base_asym_sel;
      34                 :             :     uint32_t base_hash_sel;
      35                 :             :     uint32_t pqc_asym_sel;
      36                 :             :     uint8_t reserved2[7];
      37                 :             :     uint8_t mel_specification_sel;
      38                 :             :     uint8_t ext_asym_sel_count;
      39                 :             :     uint8_t ext_hash_sel_count;
      40                 :             :     uint16_t reserved3;
      41                 :             :     uint32_t ext_asym_sel;
      42                 :             :     uint32_t ext_hash_sel;
      43                 :             :     spdm_negotiate_algorithms_common_struct_table_t struct_table[
      44                 :             :         SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG_14];
      45                 :             : } libspdm_algorithms_response_max_t;
      46                 :             : #pragma pack()
      47                 :             : 
      48                 :             : /**
      49                 :             :  * This function sends NEGOTIATE_ALGORITHMS and receives ALGORITHMS.
      50                 :             :  *
      51                 :             :  * @param  spdm_context A pointer to the SPDM context.
      52                 :             :  *
      53                 :             :  * @retval LIBSPDM_STATUS_SUCCESS
      54                 :             :  *         NEGOTIATE_ALGORITHMS was sent and ALGORITHMS was received.
      55                 :             :  * @retval LIBSPDM_STATUS_INVALID_STATE_LOCAL
      56                 :             :  *         Cannot send NEGOTIATE_ALGORITHMS due to Requester's state.
      57                 :             :  * @retval LIBSPDM_STATUS_INVALID_MSG_SIZE
      58                 :             :  *         The size of the ALGORITHMS response is invalid.
      59                 :             :  * @retval LIBSPDM_STATUS_INVALID_MSG_FIELD
      60                 :             :  *         The ALGORITHMS response contains one or more invalid fields.
      61                 :             :  * @retval LIBSPDM_STATUS_ERROR_PEER
      62                 :             :  *         The Responder returned an unexpected error.
      63                 :             :  * @retval LIBSPDM_STATUS_BUSY_PEER
      64                 :             :  *         The Responder continually returned Busy error messages.
      65                 :             :  * @retval LIBSPDM_STATUS_RESYNCH_PEER
      66                 :             :  *         The Responder returned a RequestResynch error message.
      67                 :             :  * @retval LIBSPDM_STATUS_BUFFER_FULL
      68                 :             :  *         The buffer used to store transcripts is exhausted.
      69                 :             :  * @retval LIBSPDM_STATUS_NEGOTIATION_FAIL
      70                 :             :  *         The Requester and Responder could not agree on mutual algorithms.
      71                 :             :  *         Note: This return value may be removed in the future.
      72                 :             :  **/
      73                 :         274 : static libspdm_return_t libspdm_try_negotiate_algorithms(libspdm_context_t *spdm_context)
      74                 :             : {
      75                 :             :     libspdm_return_t status;
      76                 :             :     libspdm_negotiate_algorithms_request_mine_t *spdm_request;
      77                 :             :     size_t spdm_request_size;
      78                 :             :     libspdm_algorithms_response_max_t *spdm_response;
      79                 :             :     size_t spdm_response_size;
      80                 :             :     uint32_t algo_size;
      81                 :             :     uint32_t pqc_algo_size;
      82                 :         274 :     size_t index = 0;
      83                 :             :     spdm_negotiate_algorithms_common_struct_table_t *struct_table;
      84                 :             :     uint8_t fixed_alg_size;
      85                 :             :     uint8_t ext_alg_count;
      86                 :             :     uint8_t *message;
      87                 :             :     size_t message_size;
      88                 :             :     size_t transport_header_size;
      89                 :             :     uint8_t alg_type_pre;
      90                 :         274 :     uint8_t req_param1 = 0;
      91                 :             : 
      92                 :             :     /* -=[Verify State Phase]=- */
      93         [ +  + ]:         274 :     if (spdm_context->connection_info.connection_state !=
      94                 :             :         LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES) {
      95                 :           6 :         return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
      96                 :             :     }
      97                 :             : 
      98                 :         268 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL, SPDM_NEGOTIATE_ALGORITHMS);
      99                 :             : 
     100                 :             :     /* -=[Construct Request Phase]=- */
     101                 :         268 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
     102                 :         268 :     status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
     103         [ +  + ]:         268 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     104                 :           2 :         return status;
     105                 :             :     }
     106                 :         266 :     LIBSPDM_ASSERT (message_size >= transport_header_size +
     107                 :             :                     spdm_context->local_context.capability.transport_tail_size);
     108                 :         266 :     spdm_request = (void *)(message + transport_header_size);
     109                 :         266 :     spdm_request_size = message_size - transport_header_size -
     110                 :         266 :                         spdm_context->local_context.capability.transport_tail_size;
     111                 :             : 
     112                 :         266 :     LIBSPDM_ASSERT(spdm_request_size >= sizeof(spdm_negotiate_algorithms_request_t));
     113                 :         266 :     libspdm_zero_mem(spdm_request, spdm_request_size);
     114                 :         266 :     spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
     115         [ +  + ]:         266 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
     116                 :             :         /* Number of Algorithms Structure Tables based on supported algorithms */
     117         [ +  + ]:         158 :         if (spdm_context->local_context.algorithm.dhe_named_group != 0) {
     118                 :         150 :             req_param1++;
     119                 :             :         }
     120         [ +  + ]:         158 :         if (spdm_context->local_context.algorithm.aead_cipher_suite != 0) {
     121                 :         150 :             req_param1++;
     122                 :             :         }
     123         [ +  + ]:         158 :         if (spdm_context->local_context.algorithm.req_base_asym_alg != 0) {
     124                 :         150 :             req_param1++;
     125                 :             :         }
     126         [ +  + ]:         158 :         if (spdm_context->local_context.algorithm.key_schedule != 0) {
     127                 :         150 :             req_param1++;
     128                 :             :         }
     129                 :         158 :         LIBSPDM_ASSERT(req_param1 <=
     130                 :             :                        SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG);
     131         [ +  + ]:         158 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_14) {
     132         [ -  + ]:           4 :             if (spdm_context->local_context.algorithm.req_pqc_asym_alg != 0) {
     133                 :           0 :                 req_param1++;
     134                 :             :             }
     135         [ -  + ]:           4 :             if (spdm_context->local_context.algorithm.kem_alg != 0) {
     136                 :           0 :                 req_param1++;
     137                 :             :             }
     138                 :           4 :             LIBSPDM_ASSERT(req_param1 <=
     139                 :             :                            SPDM_NEGOTIATE_ALGORITHMS_MAX_NUM_STRUCT_TABLE_ALG_14);
     140                 :             :         }
     141                 :         158 :         spdm_request->header.param1 = req_param1;
     142                 :         158 :         spdm_request->length =
     143                 :         158 :             offsetof(libspdm_negotiate_algorithms_request_mine_t, struct_table) +
     144                 :             :             req_param1 * sizeof(spdm_negotiate_algorithms_common_struct_table_t);
     145                 :             :     } else {
     146                 :         108 :         spdm_request->length = offsetof(libspdm_negotiate_algorithms_request_mine_t, struct_table);
     147                 :         108 :         spdm_request->header.param1 = 0;
     148                 :             :     }
     149                 :             : 
     150                 :         266 :     LIBSPDM_ASSERT(spdm_request_size >= spdm_request->length);
     151                 :         266 :     spdm_request->header.request_response_code = SPDM_NEGOTIATE_ALGORITHMS;
     152                 :         266 :     spdm_request->header.param2 = 0;
     153                 :         266 :     spdm_request->measurement_specification =
     154                 :         266 :         spdm_context->local_context.algorithm.measurement_spec;
     155         [ +  + ]:         266 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
     156                 :          94 :         spdm_request->other_params_support =
     157                 :          94 :             spdm_context->local_context.algorithm.other_params_support &
     158                 :             :             SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK;
     159         [ +  + ]:          94 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     160                 :          50 :             spdm_request->other_params_support =
     161                 :          50 :                 spdm_context->local_context.algorithm.other_params_support;
     162                 :          50 :             spdm_request->mel_specification =
     163                 :          50 :                 spdm_context->local_context.algorithm.mel_spec;
     164                 :             :         }
     165                 :             :     }
     166         [ +  + ]:         266 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     167   [ +  +  +  - ]:          50 :         switch (spdm_context->connection_info.capability.flags &
     168                 :             :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP) {
     169                 :          38 :         case 0:
     170                 :          38 :             spdm_context->connection_info.multi_key_conn_rsp = false;
     171                 :          38 :             break;
     172                 :           6 :         case SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY:
     173                 :           6 :             spdm_context->connection_info.multi_key_conn_rsp = true;
     174                 :           6 :             break;
     175                 :           6 :         case SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_NEG:
     176         [ +  + ]:           6 :             if ((spdm_context->local_context.algorithm.other_params_support &
     177                 :             :                  SPDM_ALGORITHMS_MULTI_KEY_CONN) == 0) {
     178                 :           2 :                 spdm_context->connection_info.multi_key_conn_rsp = false;
     179                 :             :             } else {
     180                 :           4 :                 spdm_context->connection_info.multi_key_conn_rsp = true;
     181                 :             :             }
     182                 :           6 :             break;
     183                 :           0 :         default:
     184                 :           0 :             LIBSPDM_ASSERT(false);
     185                 :           0 :             libspdm_release_sender_buffer(spdm_context);
     186                 :           0 :             return LIBSPDM_STATUS_INVALID_MSG_FIELD;
     187                 :             :         }
     188         [ +  + ]:          50 :         if (spdm_context->connection_info.multi_key_conn_rsp) {
     189                 :          10 :             spdm_request->other_params_support |= SPDM_ALGORITHMS_MULTI_KEY_CONN;
     190                 :             :         } else {
     191                 :          40 :             spdm_request->other_params_support &= ~SPDM_ALGORITHMS_MULTI_KEY_CONN;
     192                 :             :         }
     193                 :             :     }
     194                 :         266 :     spdm_request->base_asym_algo = spdm_context->local_context.algorithm.base_asym_algo;
     195                 :         266 :     spdm_request->base_hash_algo = spdm_context->local_context.algorithm.base_hash_algo;
     196         [ +  + ]:         266 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_14) {
     197                 :           4 :         spdm_request->pqc_asym_algo = spdm_context->local_context.algorithm.pqc_asym_algo;
     198                 :             :     }
     199                 :         266 :     spdm_request->ext_asym_count = 0;
     200                 :         266 :     spdm_request->ext_hash_count = 0;
     201         [ +  + ]:         266 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
     202                 :             :         /* ReqAlgStruct order based on by AlgType */
     203         [ +  + ]:         158 :         if (spdm_context->local_context.algorithm.dhe_named_group != 0) {
     204                 :         150 :             spdm_request->struct_table[index].alg_type =
     205                 :             :                 SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
     206                 :         150 :             spdm_request->struct_table[index].alg_count = 0x20;
     207                 :         150 :             spdm_request->struct_table[index].alg_supported =
     208                 :         150 :                 spdm_context->local_context.algorithm.dhe_named_group;
     209                 :         150 :             index++;
     210                 :             :         }
     211         [ +  + ]:         158 :         if (spdm_context->local_context.algorithm.aead_cipher_suite != 0) {
     212                 :         150 :             spdm_request->struct_table[index].alg_type =
     213                 :             :                 SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
     214                 :         150 :             spdm_request->struct_table[index].alg_count = 0x20;
     215                 :         150 :             spdm_request->struct_table[index].alg_supported =
     216                 :         150 :                 spdm_context->local_context.algorithm.aead_cipher_suite;
     217                 :         150 :             index++;
     218                 :             :         }
     219         [ +  + ]:         158 :         if (spdm_context->local_context.algorithm.req_base_asym_alg != 0) {
     220                 :         150 :             spdm_request->struct_table[index].alg_type =
     221                 :             :                 SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
     222                 :         150 :             spdm_request->struct_table[index].alg_count = 0x20;
     223                 :         150 :             spdm_request->struct_table[index].alg_supported =
     224                 :         150 :                 spdm_context->local_context.algorithm.req_base_asym_alg;
     225                 :         150 :             index++;
     226                 :             :         }
     227         [ +  + ]:         158 :         if (spdm_context->local_context.algorithm.key_schedule != 0) {
     228                 :         150 :             spdm_request->struct_table[index].alg_type =
     229                 :             :                 SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
     230                 :         150 :             spdm_request->struct_table[index].alg_count = 0x20;
     231                 :         150 :             spdm_request->struct_table[index].alg_supported =
     232                 :         150 :                 spdm_context->local_context.algorithm.key_schedule;
     233                 :         150 :             index++;
     234                 :             :         }
     235         [ +  + ]:         158 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_14) {
     236         [ -  + ]:           4 :             if (spdm_context->local_context.algorithm.req_pqc_asym_alg != 0) {
     237                 :             :                 /* Add assert to ensure it can be cast to uint16_t.
     238                 :             :                  * It is enough now and can be enlarged later. */
     239                 :           0 :                 LIBSPDM_ASSERT(spdm_context->local_context.algorithm.req_pqc_asym_alg <= UINT16_MAX);
     240                 :           0 :                 spdm_request->struct_table[index].alg_type =
     241                 :             :                     SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_PQC_ASYM_ALG;
     242                 :           0 :                 spdm_request->struct_table[index].alg_count = 0x20;
     243                 :           0 :                 spdm_request->struct_table[index].alg_supported =
     244                 :           0 :                     (uint16_t)spdm_context->local_context.algorithm.req_pqc_asym_alg;
     245                 :           0 :                 index++;
     246                 :             :             }
     247         [ -  + ]:           4 :             if (spdm_context->local_context.algorithm.kem_alg != 0) {
     248                 :             :                 /* Add assert to ensure it can be cast to uint16_t.
     249                 :             :                  * It is enough now and can be enlarged later. */
     250                 :           0 :                 LIBSPDM_ASSERT(spdm_context->local_context.algorithm.kem_alg <= UINT16_MAX);
     251                 :           0 :                 spdm_request->struct_table[index].alg_type =
     252                 :             :                     SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEM_ALG;
     253                 :           0 :                 spdm_request->struct_table[index].alg_count = 0x20;
     254                 :           0 :                 spdm_request->struct_table[index].alg_supported =
     255                 :           0 :                     (uint16_t)spdm_context->local_context.algorithm.kem_alg;
     256                 :           0 :                 index++;
     257                 :             :             }
     258                 :             :         }
     259                 :         158 :         LIBSPDM_ASSERT(index == spdm_request->header.param1);
     260                 :             :     }
     261                 :         266 :     spdm_request_size = spdm_request->length;
     262                 :             : 
     263                 :             :     /* -=[Send Request Phase]=- */
     264                 :         266 :     status = libspdm_send_spdm_request(spdm_context, NULL, spdm_request_size, spdm_request);
     265         [ +  + ]:         266 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     266                 :          26 :         libspdm_release_sender_buffer (spdm_context);
     267                 :          26 :         return status;
     268                 :             :     }
     269                 :         240 :     libspdm_release_sender_buffer (spdm_context);
     270                 :         240 :     spdm_request = (void *)spdm_context->last_spdm_request;
     271                 :             : 
     272                 :             :     /* -=[Receive Response Phase]=- */
     273                 :         240 :     status = libspdm_acquire_receiver_buffer (spdm_context, &message_size, (void **)&message);
     274         [ +  + ]:         240 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     275                 :           2 :         return status;
     276                 :             :     }
     277                 :         238 :     LIBSPDM_ASSERT (message_size >= transport_header_size);
     278                 :         238 :     spdm_response = (void *)(message);
     279                 :         238 :     spdm_response_size = message_size;
     280                 :             : 
     281                 :         238 :     status = libspdm_receive_spdm_response(spdm_context, NULL, &spdm_response_size,
     282                 :             :                                            (void **)&spdm_response);
     283         [ +  + ]:         238 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     284                 :           6 :         goto receive_done;
     285                 :             :     }
     286                 :             : 
     287                 :             :     /* -=[Validate Response Phase]=- */
     288         [ -  + ]:         232 :     if (spdm_response_size < sizeof(spdm_message_header_t)) {
     289                 :           0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     290                 :           0 :         goto receive_done;
     291                 :             :     }
     292         [ +  + ]:         232 :     if (spdm_response->header.request_response_code == SPDM_ERROR) {
     293                 :             :         /* SPDM 1.0 does not allow ResponseNotReady in response to NEGOTIATE_ALGORITHMS. */
     294         [ +  + ]:          22 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
     295                 :           4 :             status = libspdm_handle_error_response_main(
     296                 :             :                 spdm_context, NULL, &spdm_response_size,
     297                 :             :                 (void **)&spdm_response, SPDM_NEGOTIATE_ALGORITHMS, SPDM_ALGORITHMS);
     298                 :             :         } else {
     299                 :          18 :             status = libspdm_handle_simple_error_response(
     300                 :          18 :                 spdm_context, spdm_response->header.param1);
     301                 :             :         }
     302         [ +  + ]:          22 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     303                 :          20 :             goto receive_done;
     304                 :             :         }
     305         [ +  + ]:         210 :     } else if (spdm_response->header.request_response_code != SPDM_ALGORITHMS) {
     306                 :           4 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     307                 :           4 :         goto receive_done;
     308                 :             :     }
     309         [ +  + ]:         208 :     if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
     310                 :          18 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     311                 :          18 :         goto receive_done;
     312                 :             :     }
     313         [ +  + ]:         190 :     if (spdm_response_size < sizeof(spdm_algorithms_response_t)) {
     314                 :           8 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     315                 :           8 :         goto receive_done;
     316                 :             :     }
     317         [ +  + ]:         182 :     if (!libspdm_onehot0(spdm_response->measurement_specification_sel)) {
     318                 :           2 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     319                 :           2 :         goto receive_done;
     320                 :             :     }
     321         [ +  + ]:         180 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
     322         [ +  + ]:          54 :         if (!libspdm_onehot0(spdm_response->other_params_selection &
     323                 :             :                              SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK)) {
     324                 :           4 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     325                 :           4 :             goto receive_done;
     326                 :             :         }
     327                 :             :     }
     328         [ +  + ]:         176 :     if (!libspdm_onehot0(spdm_response->measurement_hash_algo)) {
     329                 :           4 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     330                 :           4 :         goto receive_done;
     331                 :             :     }
     332         [ +  + ]:         172 :     if (!libspdm_onehot0(spdm_response->base_asym_sel)) {
     333                 :           4 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     334                 :           4 :         goto receive_done;
     335                 :             :     }
     336         [ +  + ]:         168 :     if (!libspdm_onehot0(spdm_response->base_hash_sel)) {
     337                 :           4 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     338                 :           4 :         goto receive_done;
     339                 :             :     }
     340         [ +  + ]:         164 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_14) {
     341         [ -  + ]:           4 :         if (!libspdm_onehot0(spdm_response->pqc_asym_sel)) {
     342                 :           0 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     343                 :           0 :             goto receive_done;
     344                 :             :         }
     345                 :             :     }
     346         [ +  + ]:         164 :     if (spdm_response->ext_asym_sel_count > 0) {
     347                 :           4 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     348                 :           4 :         goto receive_done;
     349                 :             :     }
     350         [ +  + ]:         160 :     if (spdm_response->ext_hash_sel_count > 0) {
     351                 :           4 :         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     352                 :           4 :         goto receive_done;
     353                 :             :     }
     354                 :         156 :     if (spdm_response_size <
     355                 :             :         sizeof(spdm_algorithms_response_t) +
     356                 :         156 :         sizeof(uint32_t) * spdm_response->ext_asym_sel_count +
     357                 :         156 :         sizeof(uint32_t) * spdm_response->ext_hash_sel_count +
     358         [ -  + ]:         156 :         sizeof(spdm_negotiate_algorithms_common_struct_table_t) * spdm_response->header.param1) {
     359                 :           0 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     360                 :           0 :         goto receive_done;
     361                 :             :     }
     362                 :         156 :     struct_table =
     363                 :         156 :         (void *)((size_t)spdm_response +
     364                 :         156 :                  sizeof(spdm_algorithms_response_t) +
     365                 :         156 :                  sizeof(uint32_t) * spdm_response->ext_asym_sel_count +
     366                 :         156 :                  sizeof(uint32_t) * spdm_response->ext_hash_sel_count);
     367         [ +  + ]:         156 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
     368                 :         112 :         alg_type_pre = 0;
     369                 :             :         /* header.param1 is implicitly checked through spdm_response_size. */
     370         [ +  + ]:         368 :         for (index = 0; index < spdm_response->header.param1; index++) {
     371         [ -  + ]:         286 :             if ((size_t)spdm_response + spdm_response_size < (size_t)struct_table) {
     372                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     373                 :           0 :                 goto receive_done;
     374                 :             :             }
     375         [ -  + ]:         286 :             if ((size_t)spdm_response + spdm_response_size - (size_t)struct_table <
     376                 :             :                 sizeof(spdm_negotiate_algorithms_common_struct_table_t)) {
     377                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     378                 :           0 :                 goto receive_done;
     379                 :             :             }
     380         [ +  + ]:         286 :             if ((struct_table->alg_type < SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE) ||
     381         [ -  + ]:         282 :                 (struct_table->alg_type >
     382                 :             :                  SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEM_ALG)) {
     383                 :           4 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     384                 :           4 :                 goto receive_done;
     385                 :             :             }
     386         [ +  - ]:         282 :             if ((spdm_response->header.spdm_version < SPDM_MESSAGE_VERSION_14) &&
     387         [ +  + ]:         282 :                 (struct_table->alg_type >
     388                 :             :                  SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE)) {
     389                 :           2 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     390                 :           2 :                 goto receive_done;
     391                 :             :             }
     392                 :             :             /* AlgType shall monotonically increase for subsequent entries. */
     393   [ +  +  +  + ]:         280 :             if ((index != 0) && (struct_table->alg_type <= alg_type_pre)) {
     394                 :           4 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     395                 :           4 :                 goto receive_done;
     396                 :             :             }
     397                 :         276 :             alg_type_pre = struct_table->alg_type;
     398                 :         276 :             fixed_alg_size = (struct_table->alg_count >> 4) & 0xF;
     399                 :         276 :             ext_alg_count = struct_table->alg_count & 0xF;
     400         [ +  + ]:         276 :             if (fixed_alg_size != 2) {
     401                 :           2 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     402                 :           2 :                 goto receive_done;
     403                 :             :             }
     404         [ +  + ]:         274 :             if (ext_alg_count > 0) {
     405                 :           2 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     406                 :           2 :                 goto receive_done;
     407                 :             :             }
     408         [ +  + ]:         272 :             if (!libspdm_onehot0(struct_table->alg_supported)) {
     409                 :          16 :                 status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     410                 :          16 :                 goto receive_done;
     411                 :             :             }
     412                 :         256 :             if ((size_t)spdm_response + spdm_response_size -
     413                 :         256 :                 (size_t)struct_table - sizeof(spdm_negotiate_algorithms_common_struct_table_t) <
     414         [ -  + ]:         256 :                 sizeof(uint32_t) * ext_alg_count) {
     415                 :           0 :                 status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     416                 :           0 :                 goto receive_done;
     417                 :             :             }
     418                 :         256 :             struct_table =
     419                 :         256 :                 (void *)((size_t)struct_table +
     420                 :         256 :                          sizeof(spdm_negotiate_algorithms_common_struct_table_t) +
     421                 :         256 :                          sizeof(uint32_t) * ext_alg_count);
     422                 :             :         }
     423                 :             :     }
     424                 :             : 
     425                 :         126 :     spdm_response_size = (size_t)struct_table - (size_t)spdm_response;
     426         [ +  + ]:         126 :     if (spdm_response_size != spdm_response->length) {
     427                 :           2 :         status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
     428                 :           2 :         goto receive_done;
     429                 :             :     }
     430                 :             : 
     431                 :             :     /* -=[Process Response Phase]=- */
     432                 :         124 :     status = libspdm_append_message_a(spdm_context, spdm_request, spdm_request_size);
     433         [ -  + ]:         124 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     434                 :           0 :         goto receive_done;
     435                 :             :     }
     436                 :             : 
     437                 :         124 :     status = libspdm_append_message_a(spdm_context, spdm_response, spdm_response_size);
     438         [ -  + ]:         124 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     439                 :           0 :         goto receive_done;
     440                 :             :     }
     441                 :             : 
     442                 :         124 :     spdm_context->connection_info.algorithm.measurement_spec =
     443                 :         124 :         spdm_response->measurement_specification_sel;
     444         [ +  + ]:         124 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
     445                 :          48 :         spdm_context->connection_info.algorithm.other_params_support =
     446                 :          48 :             spdm_response->other_params_selection & SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK;
     447         [ +  + ]:          48 :         if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     448                 :          38 :             spdm_context->connection_info.algorithm.other_params_support =
     449                 :          38 :                 spdm_response->other_params_selection;
     450                 :          38 :             spdm_context->connection_info.algorithm.mel_spec =
     451                 :          38 :                 spdm_response->mel_specification_sel;
     452                 :             :         }
     453                 :             :     }
     454                 :         124 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     455                 :         124 :         spdm_response->measurement_hash_algo;
     456                 :         124 :     spdm_context->connection_info.algorithm.base_asym_algo = spdm_response->base_asym_sel;
     457                 :         124 :     spdm_context->connection_info.algorithm.base_hash_algo = spdm_response->base_hash_sel;
     458         [ +  + ]:         124 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_14) {
     459                 :           4 :         spdm_context->connection_info.algorithm.pqc_asym_algo = spdm_response->pqc_asym_sel;
     460                 :             :     }
     461                 :             : 
     462         [ +  + ]:         124 :     if (libspdm_is_capabilities_flag_supported(
     463                 :             :             spdm_context, true, 0,
     464                 :         106 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP) &&
     465         [ +  + ]:         106 :         (spdm_request->measurement_specification != 0)) {
     466         [ +  + ]:         102 :         if (spdm_context->connection_info.algorithm.measurement_spec !=
     467                 :             :             SPDM_MEASUREMENT_SPECIFICATION_DMTF) {
     468                 :           4 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     469                 :           4 :             goto receive_done;
     470                 :             :         }
     471                 :          98 :         algo_size = libspdm_get_measurement_hash_size(
     472                 :             :             spdm_context->connection_info.algorithm.measurement_hash_algo);
     473         [ +  + ]:          98 :         if (algo_size == 0) {
     474                 :           4 :             status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     475                 :           4 :             goto receive_done;
     476                 :             :         }
     477                 :             :     } else {
     478         [ +  + ]:          22 :         if (spdm_context->connection_info.algorithm.measurement_spec != 0) {
     479                 :           8 :             status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     480                 :           8 :             goto receive_done;
     481                 :             :         }
     482                 :             :     }
     483                 :             : 
     484         [ +  + ]:         108 :     if (libspdm_is_capabilities_flag_supported(
     485                 :             :             spdm_context, true, 0,
     486         [ +  + ]:          98 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP) ||
     487                 :          98 :         libspdm_is_capabilities_flag_supported(
     488                 :             :             spdm_context, true, 0,
     489         [ +  + ]:          52 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP) ||
     490                 :          52 :         libspdm_is_capabilities_flag_supported(
     491                 :             :             spdm_context, true, 0,
     492         [ +  + ]:          12 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG) ||
     493                 :          12 :         libspdm_is_capabilities_flag_supported(
     494                 :             :             spdm_context, true, 0,
     495         [ +  - ]:           6 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG) ||
     496                 :           6 :         libspdm_is_capabilities_flag_supported(
     497                 :             :             spdm_context, true,
     498                 :             :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
     499         [ -  + ]:           6 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP) ||
     500                 :           6 :         libspdm_is_capabilities_flag_supported(
     501                 :             :             spdm_context, true,
     502                 :             :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP,
     503                 :             :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP)) {
     504                 :         102 :         algo_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
     505         [ +  + ]:         102 :         if (algo_size == 0) {
     506                 :           6 :             status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     507                 :           6 :             goto receive_done;
     508                 :             :         }
     509                 :          96 :         if ((spdm_context->connection_info.algorithm.base_hash_algo &
     510         [ +  + ]:          96 :              spdm_context->local_context.algorithm.base_hash_algo) == 0) {
     511                 :           4 :             status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     512                 :           4 :             goto receive_done;
     513                 :             :         }
     514                 :             :     }
     515                 :             : 
     516         [ +  + ]:          98 :     if (libspdm_is_capabilities_flag_supported(
     517                 :             :             spdm_context, true, 0,
     518         [ +  + ]:          88 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP) ||
     519                 :          88 :         libspdm_is_capabilities_flag_supported(
     520                 :             :             spdm_context, true, 0,
     521         [ +  + ]:          50 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP) ||
     522                 :          50 :         libspdm_is_capabilities_flag_supported(
     523                 :             :             spdm_context, true, 0,
     524         [ +  + ]:          10 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG) ||
     525                 :          10 :         libspdm_is_capabilities_flag_supported(
     526                 :             :             spdm_context, true, 0,
     527         [ -  + ]:           6 :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG) ||
     528                 :           6 :         libspdm_is_capabilities_flag_supported(
     529                 :             :             spdm_context, true,
     530                 :             :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
     531                 :             :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)) {
     532                 :          92 :         algo_size = libspdm_get_asym_signature_size(
     533                 :             :             spdm_context->connection_info.algorithm.base_asym_algo);
     534         [ +  + ]:          92 :         if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_14) {
     535                 :           4 :             pqc_algo_size = libspdm_get_pqc_asym_signature_size(
     536                 :             :                 spdm_context->connection_info.algorithm.pqc_asym_algo);
     537                 :             :         } else {
     538                 :          88 :             pqc_algo_size = 0;
     539                 :             :         }
     540   [ +  +  -  +  :          92 :         if (((algo_size == 0) && (pqc_algo_size == 0)) ||
                   +  - ]
     541         [ -  + ]:          86 :             ((algo_size != 0) && (pqc_algo_size != 0))) {
     542                 :           6 :             status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     543                 :           6 :             goto receive_done;
     544                 :             :         }
     545         [ +  - ]:          86 :         if ((algo_size != 0) &&
     546                 :          86 :             ((spdm_context->connection_info.algorithm.base_asym_algo &
     547         [ +  + ]:          86 :               spdm_context->local_context.algorithm.base_asym_algo) == 0)) {
     548                 :           4 :             status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     549                 :           4 :             goto receive_done;
     550                 :             :         }
     551         [ -  + ]:          82 :         if ((pqc_algo_size != 0) &&
     552                 :           0 :             ((spdm_context->connection_info.algorithm.pqc_asym_algo &
     553         [ #  # ]:           0 :               spdm_context->local_context.algorithm.pqc_asym_algo) == 0)) {
     554                 :           0 :             status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     555                 :           0 :             goto receive_done;
     556                 :             :         }
     557                 :             :     }
     558                 :             : 
     559         [ +  + ]:          88 :     if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
     560                 :          74 :         struct_table =
     561                 :          74 :             (void *)((size_t)spdm_response +
     562                 :          74 :                      sizeof(spdm_algorithms_response_t) +
     563                 :          74 :                      sizeof(uint32_t) * spdm_response->ext_asym_sel_count +
     564                 :          74 :                      sizeof(uint32_t) * spdm_response->ext_hash_sel_count);
     565         [ +  + ]:         274 :         for (index = 0; index < spdm_response->header.param1; index++) {
     566   [ +  +  +  +  :         200 :             switch (struct_table->alg_type) {
                -  -  - ]
     567                 :          50 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE:
     568                 :          50 :                 spdm_context->connection_info.algorithm.dhe_named_group =
     569                 :          50 :                     struct_table->alg_supported;
     570                 :          50 :                 break;
     571                 :          50 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD:
     572                 :          50 :                 spdm_context->connection_info.algorithm.aead_cipher_suite =
     573                 :          50 :                     struct_table->alg_supported;
     574                 :          50 :                 break;
     575                 :          50 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG:
     576                 :          50 :                 spdm_context->connection_info.algorithm.req_base_asym_alg =
     577                 :          50 :                     struct_table->alg_supported;
     578                 :          50 :                 break;
     579                 :          50 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE:
     580                 :          50 :                 spdm_context->connection_info.algorithm.key_schedule =
     581                 :          50 :                     struct_table->alg_supported;
     582                 :          50 :                 break;
     583                 :           0 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_PQC_ASYM_ALG:
     584                 :           0 :                 spdm_context->connection_info.algorithm.req_pqc_asym_alg =
     585                 :           0 :                     struct_table->alg_supported;
     586                 :           0 :                 break;
     587                 :           0 :             case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEM_ALG:
     588                 :           0 :                 spdm_context->connection_info.algorithm.kem_alg =
     589                 :           0 :                     struct_table->alg_supported;
     590                 :           0 :                 break;
     591                 :             :             }
     592                 :         200 :             ext_alg_count = struct_table->alg_count & 0xF;
     593                 :         200 :             struct_table =
     594                 :         200 :                 (void *)((size_t)struct_table +
     595                 :         200 :                          sizeof(spdm_negotiate_algorithms_common_struct_table_t) +
     596                 :         200 :                          sizeof(uint32_t) * ext_alg_count);
     597                 :             :         }
     598                 :             : 
     599         [ +  + ]:          74 :         if (libspdm_is_capabilities_flag_supported(
     600                 :             :                 spdm_context, true,
     601                 :             :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
     602                 :             :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)) {
     603                 :          48 :             algo_size = libspdm_get_dhe_pub_key_size(
     604                 :          48 :                 spdm_context->connection_info.algorithm.dhe_named_group);
     605         [ -  + ]:          48 :             if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_14) {
     606                 :           0 :                 pqc_algo_size = libspdm_get_kem_encap_key_size(
     607                 :             :                     spdm_context->connection_info.algorithm.kem_alg);
     608                 :             :             } else {
     609                 :          48 :                 pqc_algo_size = 0;
     610                 :             :             }
     611   [ -  +  -  -  :          48 :             if (((algo_size == 0) && (pqc_algo_size == 0)) ||
                   +  - ]
     612         [ -  + ]:          48 :                 ((algo_size != 0) && (pqc_algo_size != 0))) {
     613                 :           0 :                 status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     614                 :           0 :                 goto receive_done;
     615                 :             :             }
     616         [ +  - ]:          48 :             if ((algo_size != 0) &&
     617                 :          48 :                 ((spdm_context->connection_info.algorithm.dhe_named_group &
     618         [ +  + ]:          48 :                   spdm_context->local_context.algorithm.dhe_named_group) == 0)) {
     619                 :           4 :                 status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     620                 :           4 :                 goto receive_done;
     621                 :             :             }
     622         [ -  + ]:          44 :             if ((pqc_algo_size != 0) &&
     623                 :           0 :                 ((spdm_context->connection_info.algorithm.kem_alg &
     624         [ #  # ]:           0 :                   spdm_context->local_context.algorithm.kem_alg) == 0)) {
     625                 :           0 :                 status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     626                 :           0 :                 goto receive_done;
     627                 :             :             }
     628                 :             :         }
     629         [ +  + ]:          70 :         if (libspdm_is_capabilities_flag_supported(
     630                 :             :                 spdm_context, true,
     631                 :             :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP,
     632         [ -  + ]:          26 :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP) ||
     633                 :          26 :             libspdm_is_capabilities_flag_supported(
     634                 :             :                 spdm_context, true,
     635                 :             :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP,
     636                 :             :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP)) {
     637                 :          44 :             algo_size = libspdm_get_aead_key_size(
     638                 :          44 :                 spdm_context->connection_info.algorithm.aead_cipher_suite);
     639         [ +  + ]:          44 :             if (algo_size == 0) {
     640                 :           4 :                 status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     641                 :           4 :                 goto receive_done;
     642                 :             :             }
     643                 :          40 :             if ((spdm_context->connection_info.algorithm.aead_cipher_suite &
     644         [ -  + ]:          40 :                  spdm_context->local_context.algorithm.aead_cipher_suite) == 0) {
     645                 :           0 :                 status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     646                 :           0 :                 goto receive_done;
     647                 :             :             }
     648                 :             :         }
     649         [ +  + ]:          66 :         if (libspdm_is_capabilities_flag_supported(
     650                 :             :                 spdm_context, true,
     651                 :             :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP,
     652         [ -  + ]:          26 :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP) ||
     653                 :          26 :             libspdm_is_capabilities_flag_supported(
     654                 :             :                 spdm_context, true,
     655                 :             :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_SIG, 0)) {
     656                 :          40 :             algo_size = libspdm_get_req_asym_signature_size(
     657                 :          40 :                 spdm_context->connection_info.algorithm.req_base_asym_alg);
     658         [ -  + ]:          40 :             if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_14) {
     659                 :           0 :                 pqc_algo_size = libspdm_get_req_pqc_asym_signature_size(
     660                 :             :                     spdm_context->connection_info.algorithm.req_pqc_asym_alg);
     661                 :             :             } else {
     662                 :          40 :                 pqc_algo_size = 0;
     663                 :             :             }
     664   [ +  +  -  +  :          40 :             if (((algo_size == 0) && (pqc_algo_size == 0)) ||
                   +  - ]
     665         [ -  + ]:          38 :                 ((algo_size != 0) && (pqc_algo_size != 0))) {
     666                 :           2 :                 status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     667                 :           2 :                 goto receive_done;
     668                 :             :             }
     669         [ +  - ]:          38 :             if ((algo_size != 0) &&
     670                 :          38 :                 ((spdm_context->connection_info.algorithm.req_base_asym_alg &
     671         [ +  + ]:          38 :                   spdm_context->local_context.algorithm.req_base_asym_alg) == 0)) {
     672                 :           4 :                 status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     673                 :           4 :                 goto receive_done;
     674                 :             :             }
     675         [ -  + ]:          34 :             if ((pqc_algo_size != 0) &&
     676                 :           0 :                 ((spdm_context->connection_info.algorithm.req_pqc_asym_alg &
     677         [ #  # ]:           0 :                   spdm_context->local_context.algorithm.req_pqc_asym_alg) == 0)) {
     678                 :           0 :                 status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     679                 :           0 :                 goto receive_done;
     680                 :             :             }
     681                 :             :         }
     682         [ +  + ]:          60 :         if (libspdm_is_capabilities_flag_supported(
     683                 :             :                 spdm_context, true,
     684                 :             :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP,
     685         [ -  + ]:          26 :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP) ||
     686                 :          26 :             libspdm_is_capabilities_flag_supported(
     687                 :             :                 spdm_context, true,
     688                 :             :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP,
     689                 :             :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP)) {
     690         [ +  + ]:          34 :             if (spdm_context->connection_info.algorithm.key_schedule !=
     691                 :             :                 SPDM_ALGORITHMS_KEY_SCHEDULE_SPDM) {
     692                 :           4 :                 status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     693                 :           4 :                 goto receive_done;
     694                 :             :             }
     695                 :          30 :             if ((spdm_context->connection_info.algorithm.key_schedule &
     696         [ -  + ]:          30 :                  spdm_context->local_context.algorithm.key_schedule) == 0) {
     697                 :           0 :                 status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     698                 :           0 :                 goto receive_done;
     699                 :             :             }
     700         [ +  + ]:          30 :             if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     701         [ +  + ]:          16 :                 if (libspdm_is_capabilities_flag_supported(
     702                 :             :                         spdm_context, true, 0,
     703                 :           8 :                         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP) &&
     704         [ +  + ]:           8 :                     (spdm_request->mel_specification != 0)) {
     705         [ +  + ]:           4 :                     if (spdm_context->connection_info.algorithm.mel_spec !=
     706                 :             :                         SPDM_MEL_SPECIFICATION_DMTF) {
     707                 :           2 :                         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     708                 :           2 :                         goto receive_done;
     709                 :             :                     }
     710                 :             :                 } else {
     711         [ +  + ]:          12 :                     if (spdm_context->connection_info.algorithm.mel_spec != 0) {
     712                 :           6 :                         status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
     713                 :           6 :                         goto receive_done;
     714                 :             :                     }
     715                 :             :                 }
     716                 :             :             }
     717                 :             :         }
     718                 :             : 
     719         [ +  + ]:          48 :         if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
     720         [ +  + ]:          26 :             if ((spdm_context->connection_info.algorithm.other_params_support &
     721                 :             :                  SPDM_ALGORITHMS_MULTI_KEY_CONN) == 0) {
     722         [ +  + ]:          20 :                 if ((spdm_context->local_context.capability.flags &
     723                 :             :                      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP) ==
     724                 :             :                     SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY) {
     725                 :           2 :                     status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     726                 :           2 :                     goto receive_done;
     727                 :             :                 }
     728                 :          18 :                 spdm_context->connection_info.multi_key_conn_req = false;
     729                 :             :             } else {
     730         [ +  + ]:           6 :                 if ((spdm_context->local_context.capability.flags &
     731                 :             :                      SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP) == 0) {
     732                 :           2 :                     status = LIBSPDM_STATUS_NEGOTIATION_FAIL;
     733                 :           2 :                     goto receive_done;
     734                 :             :                 }
     735                 :           4 :                 spdm_context->connection_info.multi_key_conn_req = true;
     736                 :             :             }
     737                 :             :         }
     738                 :             :     } else {
     739                 :          14 :         spdm_context->connection_info.algorithm.dhe_named_group = 0;
     740                 :          14 :         spdm_context->connection_info.algorithm.aead_cipher_suite = 0;
     741                 :          14 :         spdm_context->connection_info.algorithm.req_base_asym_alg = 0;
     742                 :          14 :         spdm_context->connection_info.algorithm.key_schedule = 0;
     743                 :          14 :         spdm_context->connection_info.algorithm.other_params_support = 0;
     744                 :          14 :         spdm_context->connection_info.algorithm.req_pqc_asym_alg = 0;
     745                 :          14 :         spdm_context->connection_info.algorithm.kem_alg = 0;
     746                 :             :     }
     747                 :             : 
     748                 :          58 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "base_hash - 0x%08x\n",
     749                 :             :                    spdm_context->connection_info.algorithm.base_hash_algo));
     750                 :          58 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "base_asym - 0x%08x\n",
     751                 :             :                    spdm_context->connection_info.algorithm.base_asym_algo));
     752                 :          58 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "dhe - 0x%04x\n",
     753                 :             :                    spdm_context->connection_info.algorithm.dhe_named_group));
     754                 :          58 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "aead - 0x%04x\n",
     755                 :             :                    spdm_context->connection_info.algorithm.aead_cipher_suite));
     756                 :          58 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "req_asym - 0x%04x\n",
     757                 :             :                    spdm_context->connection_info.algorithm.req_base_asym_alg));
     758                 :          58 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "pqc_asym - 0x%08x\n",
     759                 :             :                    spdm_context->connection_info.algorithm.pqc_asym_algo));
     760                 :          58 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "req_pqc_asym - 0x%04x\n",
     761                 :             :                    spdm_context->connection_info.algorithm.req_pqc_asym_alg));
     762                 :          58 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "kem - 0x%04x\n",
     763                 :             :                    spdm_context->connection_info.algorithm.kem_alg));
     764                 :             : 
     765                 :             :     /* -=[Update State Phase]=- */
     766                 :          58 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     767                 :             : 
     768                 :             :     /* -=[Log Message Phase]=- */
     769                 :             :     #if LIBSPDM_ENABLE_MSG_LOG
     770                 :          58 :     libspdm_append_msg_log(spdm_context, spdm_response, spdm_response_size);
     771                 :             :     #endif /* LIBSPDM_ENABLE_MSG_LOG */
     772                 :             : 
     773                 :          58 :     status = LIBSPDM_STATUS_SUCCESS;
     774                 :             : 
     775                 :         238 : receive_done:
     776                 :         238 :     libspdm_release_receiver_buffer (spdm_context);
     777                 :         238 :     return status;
     778                 :             : }
     779                 :             : 
     780                 :         272 : libspdm_return_t libspdm_negotiate_algorithms(libspdm_context_t *spdm_context)
     781                 :             : {
     782                 :             :     size_t retry;
     783                 :             :     uint64_t retry_delay_time;
     784                 :             :     libspdm_return_t status;
     785                 :             : 
     786                 :         272 :     spdm_context->crypto_request = false;
     787                 :         272 :     retry = spdm_context->retry_times;
     788                 :         272 :     retry_delay_time = spdm_context->retry_delay_time;
     789                 :             :     do {
     790                 :         274 :         status = libspdm_try_negotiate_algorithms(spdm_context);
     791         [ +  + ]:         274 :         if (status != LIBSPDM_STATUS_BUSY_PEER) {
     792                 :         268 :             return status;
     793                 :             :         }
     794                 :             : 
     795                 :           6 :         libspdm_sleep(retry_delay_time);
     796         [ +  + ]:           6 :     } while (retry-- != 0);
     797                 :             : 
     798                 :           4 :     return status;
     799                 :             : }
        

Generated by: LCOV version 2.0-1